1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 ############################################################################
25 # This Python script is testing the merge and the intersection of
27 ############################################################################
29 from libMEDMEM_Swig import *
33 #befor running this script, please be sure about the path the file fileName
35 filePath=os.environ["MED_ROOT_DIR"]
36 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
38 medFile = os.path.join( filePath, "pointe.med" )
50 md = MEDFILEBROWSER(medFile)
51 nbMeshes = md.getNumberOfMeshes()
53 print "The med file", medFile, "contains", nbMeshes, "mesh(es)"
55 mesh_name = md.getMeshName(0)
56 mesh = MESH(MED_DRIVER,medFile,mesh_name)
57 spaceDim = mesh.getSpaceDimension()
58 meshDim = mesh.getMeshDimension()
59 nbNodes = mesh.getNumberOfNodes()
60 print "The mesh",mesh_name,"is a",spaceDim,"D mesh on a",meshDim,"D geometry and has",nbNodes,"Nodes"
63 print "Mesh Families analysis:"
66 for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
67 nbFam = mesh.getNumberOfFamilies(entity)
68 if (entity == MED_NODE) & (nbFam > 0):
69 print "This mesh has",nbFam,"Node Family(ies)"
70 elif (entity == MED_NODE) & (nbFam == 0):
71 print "This mesh has no Node Family(ies)"
72 elif (entity == MED_CELL) & (nbFam > 0):
73 print "This mesh has",nbFam,"Cell Family(ies)"
74 elif (entity == MED_CELL) & (nbFam == 0):
75 print "This mesh has no Cell Family(ies)"
76 elif (entity == MED_FACE) & (nbFam > 0):
77 print "This mesh has",nbFam,"Face Family(ies)"
78 elif (entity == MED_FACE) & (nbFam == 0):
79 print "This mesh has no Face Family(ies)"
80 elif (entity == MED_EDGE) & (nbFam > 0):
81 print "This mesh has",nbFam,"Edge Family(ies)"
82 elif (entity == MED_EDGE) & (nbFam == 0):
83 print "This mesh has no Edge Family(ies)"
87 for j in range(nbFam):
88 family = mesh.getFamily(entity,j+1)
89 familyName = family.getName()
90 familyDescription = family.getDescription()
91 familyEntity = family.getEntity()
92 familyBool = family.isOnAllElements()
93 print " -Name:",familyName
94 print " -Description:",familyDescription
95 print " -Entity:",familyEntity
96 familyIdentifier = family.getIdentifier()
97 nbOfAtt = family.getNumberOfAttributes()
98 print " -Identifier:",familyIdentifier
99 print " -Number Of Attributes:",nbOfAtt
100 attributesids = family.getAttributesIdentifiers()
101 attributesvals = family.getAttributesValues()
102 for k in range(nbOfAtt):
103 print " * Attributes:",attributesids[k],":",attributesvals[k],",",family.getAttributeDescription(k+1)
104 nbOfGrp = family.getNumberOfGroups()
105 print " -Number Of Groups:",nbOfGrp
106 for k in range(nbOfGrp):
107 print " * Group:",family.getGroupName(k+1)
108 print " -Entities list:"
110 print " -Is on all entities"
112 nbOfTypes = family.getNumberOfTypes()
113 types = family.getTypes()
114 print " -Number Of Types:",nbOfTypes
115 for k in range(nbOfTypes):
117 nbOfElmtsOfType = family.getNumberOfElements(type)
118 number = family.getNumber(type)
120 print " * Number",number[0:nbOfElmtsOfType]
123 print "we are going to do some operation on Node families"
124 print "by definition families have no intersection"
127 familyNode1 = mesh.getFamily(entity,1)
128 familyNode2 = mesh.getFamily(entity,2)
129 familyNode3 = mesh.getFamily(entity,3)
130 familyNode4 = mesh.getFamily(entity,4)
133 listOfSupports.append(familyNode1)
134 listOfSupports.append(familyNode2)
136 support = mesh.mergeSupports(listOfSupports)
138 supportName = support.getName()
139 supportDescription = support.getDescription()
140 supportMeshname = support.getMesh().getName()
141 supportEntity = support.getEntity()
142 supportBool = support.isOnAllElements()
143 print " -Name:",supportName
144 print " -Description:",supportDescription
145 print " -Entity:",supportEntity
147 print " -Is on all entities"
149 nbOfTypes = support.getNumberOfTypes()
150 types = support.getTypes()
151 print " -Number Of Types:",nbOfTypes
152 for k in range(nbOfTypes):
154 nbOfElmtsOfType = support.getNumberOfElements(type)
155 number = support.getNumber(type)
157 print " * Number",number[0:nbOfElmtsOfType]
160 support = mesh.intersectSupports(listOfSupports)
162 supportName = support.getName()
163 supportDescription = support.getDescription()
164 supportMeshname = support.getMesh().getName()
165 supportEntity = support.getEntity()
166 supportBool = support.isOnAllElements()
167 print " -Name:",supportName
168 print " -Description:",supportDescription
169 print " -Entity:",supportEntity
171 print " -Is on all entities"
173 nbOfTypes = support.getNumberOfTypes()
174 types = support.getTypes()
175 print " -Number Of Types:",nbOfTypes
176 for k in range(nbOfTypes):
178 nbOfElmtsOfType = support.getNumberOfElements(type)
179 number = support.getNumber(type)
181 print " * Number",number[0:nbOfElmtsOfType]
184 listOfSupports.append(familyNode3)
186 support = mesh.mergeSupports(listOfSupports)
188 supportName = support.getName()
189 supportDescription = support.getDescription()
190 supportMeshname = support.getMesh().getName()
191 supportEntity = support.getEntity()
192 supportBool = support.isOnAllElements()
193 print " -Name:",supportName
194 print " -Description:",supportDescription
195 print " -Entity:",supportEntity
197 print " -Is on all entities"
199 nbOfTypes = support.getNumberOfTypes()
200 types = support.getTypes()
201 print " -Number Of Types:",nbOfTypes
202 for k in range(nbOfTypes):
204 nbOfElmtsOfType = support.getNumberOfElements(type)
205 number = support.getNumber(type)
207 print " * Number",number[0:nbOfElmtsOfType]
210 print "we are going to do some operation on Cell families"
211 print "by definition families have no intersection"
214 familyCell1 = mesh.getFamily(entity,1)
215 familyCell2 = mesh.getFamily(entity,2)
216 familyCell3 = mesh.getFamily(entity,3)
219 listOfSupports.append(familyCell1)
220 listOfSupports.append(familyCell2)
222 support = mesh.mergeSupports(listOfSupports)
224 supportName = support.getName()
225 supportDescription = support.getDescription()
226 supportMeshname = support.getMesh().getName()
227 supportEntity = support.getEntity()
228 supportBool = support.isOnAllElements()
229 print " -Name:",supportName
230 print " -Description:",supportDescription
231 print " -Entity:",supportEntity
233 print " -Is on all entities"
235 nbOfTypes = support.getNumberOfTypes()
236 types = support.getTypes()
237 print " -Number Of Types:",nbOfTypes
238 for k in range(nbOfTypes):
240 nbOfElmtsOfType = support.getNumberOfElements(type)
241 number = support.getNumber(type)
243 print " * Number",number[0:nbOfElmtsOfType]
246 support = mesh.intersectSupports(listOfSupports)
248 supportName = support.getName()
249 supportDescription = support.getDescription()
250 supportMeshname = support.getMesh().getName()
251 supportEntity = support.getEntity()
252 supportBool = support.isOnAllElements()
253 print " -Name:",supportName
254 print " -Description:",supportDescription
255 print " -Entity:",supportEntity
257 print " -Is on all entities"
259 nbOfTypes = support.getNumberOfTypes()
260 types = support.getTypes()
261 print " -Number Of Types:",nbOfTypes
262 for k in range(nbOfTypes):
264 nbOfElmtsOfType = support.getNumberOfElements(type)
265 number = support.getNumber(type)
267 print " * Number",number[0:nbOfElmtsOfType]
270 listOfSupports.append(familyCell3)
272 support = mesh.mergeSupports(listOfSupports)
274 supportName = support.getName()
275 supportDescription = support.getDescription()
276 supportMeshname = support.getMesh().getName()
277 supportEntity = support.getEntity()
278 supportBool = support.isOnAllElements()
279 print " -Name:",supportName
280 print " -Description:",supportDescription
281 print " -Entity:",supportEntity
283 print " -Is on all entities"
285 nbOfTypes = support.getNumberOfTypes()
286 types = support.getTypes()
287 print " -Number Of Types:",nbOfTypes
288 for k in range(nbOfTypes):
290 nbOfElmtsOfType = support.getNumberOfElements(type)
291 number = support.getNumber(type)
293 print " * Number",number[0:nbOfElmtsOfType]
296 print "Let's now do an example of union and intersection of two supports with a non empty intersection"
299 support1.setMesh(mesh)
300 support1.setName("Partial_Support_1")
301 support1Description = "Partial Support 1"
302 support1NbOfTypes = 3
304 support1GeoType = [MED_TETRA4,MED_HEXA8,MED_PYRA5]
305 support1NbOfElm = [4,2,2]
306 support1NbValue = [1,2,3,4,15,16,13,14]
308 support1.setpartial(support1Description,support1NbOfTypes,support1TotNbElm,
309 support1GeoType,support1NbOfElm,support1NbValue)
311 supportName = support1.getName()
312 supportDescription = support1.getDescription()
313 supportMeshname = support1.getMesh().getName()
314 supportEntity = support1.getEntity()
315 supportBool = support1.isOnAllElements()
316 print " -Name:",supportName
317 print " -Description:",supportDescription
318 print " -Entity:",supportEntity
320 print " -Is on all entities"
322 nbOfTypes = support1.getNumberOfTypes()
323 types = support1.getTypes()
324 print " -Number Of Types:",nbOfTypes
325 for k in range(nbOfTypes):
327 nbOfElmtsOfType = support1.getNumberOfElements(type)
328 number = support1.getNumber(type)
330 print " * Number",number[0:nbOfElmtsOfType]
334 support2.setMesh(mesh)
335 support2.setName("Partial_Support_2")
336 support2Description = "Partial Support 2"
337 support2NbOfTypes = 3
339 support2GeoType = [MED_TETRA4,MED_HEXA8,MED_PYRA5]
340 support2NbOfElm = [6,1,1]
341 support2NbValue = [3,4,9,10,11,12,16,14]
343 support2.setpartial(support2Description,support2NbOfTypes,support2TotNbElm,
344 support2GeoType,support2NbOfElm,support2NbValue)
346 supportName = support2.getName()
347 supportDescription = support2.getDescription()
348 supportMeshname = support2.getMesh().getName()
349 supportEntity = support2.getEntity()
350 supportBool = support2.isOnAllElements()
351 print " -Name:",supportName
352 print " -Description:",supportDescription
353 print " -Entity:",supportEntity
355 print " -Is on all entities"
357 nbOfTypes = support2.getNumberOfTypes()
358 types = support2.getTypes()
359 print " -Number Of Types:",nbOfTypes
360 for k in range(nbOfTypes):
362 nbOfElmtsOfType = support2.getNumberOfElements(type)
363 number = support2.getNumber(type)
365 print " * Number",number[0:nbOfElmtsOfType]
369 listOfSupports.append(support1)
370 listOfSupports.append(support2)
375 support = mesh.mergeSupports(listOfSupports)
377 supportName = support.getName()
378 supportDescription = support.getDescription()
379 supportMeshname = support.getMesh().getName()
380 supportEntity = support.getEntity()
381 supportBool = support.isOnAllElements()
382 print " -Name:",supportName
383 print " -Description:",supportDescription
384 print " -Entity:",supportEntity
386 print " -Is on all entities"
388 nbOfTypes = support.getNumberOfTypes()
389 types = support.getTypes()
390 print " -Number Of Types:",nbOfTypes
391 for k in range(nbOfTypes):
393 nbOfElmtsOfType = support.getNumberOfElements(type)
394 number = support.getNumber(type)
396 print " * Number",number[0:nbOfElmtsOfType]
399 print "The intersection"
402 support = mesh.intersectSupports(listOfSupports)
404 supportName = support.getName()
405 supportDescription = support.getDescription()
406 supportMeshname = support.getMesh().getName()
407 supportEntity = support.getEntity()
408 supportBool = support.isOnAllElements()
409 print " -Name:",supportName
410 print " -Description:",supportDescription
411 print " -Entity:",supportEntity
413 print " -Is on all entities"
415 nbOfTypes = support.getNumberOfTypes()
416 types = support.getTypes()
417 print " -Number Of Types:",nbOfTypes
418 for k in range(nbOfTypes):
420 nbOfElmtsOfType = support.getNumberOfElements(type)
421 number = support.getNumber(type)
423 print " * Number",number[0:nbOfElmtsOfType]
426 print "END of the Pyhton script ..... Ctrl D to exit"