Back to index

salome-med  6.5.0
med_opsupp_test.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 ############################################################################
00025 # This Python script is testing the merge and the intersection of
00026 # several SUPPORTs
00027 ############################################################################
00028 #
00029 from libMEDMEM_Swig import *
00030 from random import *
00031 import os
00032 #
00033 #befor running this script, please be sure about the path the file fileName
00034 #
00035 filePath=os.environ["MED_ROOT_DIR"]
00036 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
00037 
00038 medFile = os.path.join( filePath, "pointe.med" )
00039 
00040 def print_ord(i):
00041     if i == 0:
00042         return 'first'
00043     elif i == 1:
00044         return 'second'
00045     elif i == 2:
00046         return 'third'
00047     else:
00048         return `i`+'th'
00049 
00050 md = MEDFILEBROWSER(medFile)
00051 nbMeshes = md.getNumberOfMeshes()
00052 
00053 print "The med file", medFile, "contains", nbMeshes, "mesh(es)"
00054 
00055 mesh_name = md.getMeshName(0)
00056 mesh = MESH(MED_DRIVER,medFile,mesh_name)
00057 spaceDim = mesh.getSpaceDimension()
00058 meshDim = mesh.getMeshDimension()
00059 nbNodes = mesh.getNumberOfNodes()
00060 print "The mesh",mesh_name,"is a",spaceDim,"D mesh on a",meshDim,"D geometry and has",nbNodes,"Nodes"
00061 
00062 print ""
00063 print "Mesh Families analysis:"
00064 print ""
00065 
00066 for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
00067     nbFam = mesh.getNumberOfFamilies(entity)
00068     if (entity == MED_NODE) & (nbFam > 0):
00069         print "This mesh has",nbFam,"Node Family(ies)"
00070     elif (entity == MED_NODE) & (nbFam == 0):
00071         print "This mesh has no Node Family(ies)"
00072     elif (entity == MED_CELL) & (nbFam > 0):
00073         print "This mesh has",nbFam,"Cell Family(ies)"
00074     elif (entity == MED_CELL) & (nbFam == 0):
00075         print "This mesh has no Cell Family(ies)"
00076     elif (entity == MED_FACE) & (nbFam > 0):
00077         print "This mesh has",nbFam,"Face Family(ies)"
00078     elif (entity == MED_FACE) & (nbFam == 0):
00079         print "This mesh has no Face Family(ies)"
00080     elif (entity == MED_EDGE) & (nbFam > 0):
00081         print "This mesh has",nbFam,"Edge Family(ies)"
00082     elif (entity == MED_EDGE) & (nbFam == 0):
00083         print "This mesh has no Edge Family(ies)"
00084     print ""
00085     
00086     if nbFam > 0:
00087         for j in range(nbFam):
00088             family = mesh.getFamily(entity,j+1)
00089             familyName = family.getName()
00090             familyDescription = family.getDescription()
00091             familyEntity = family.getEntity()
00092             familyBool = family.isOnAllElements()
00093             print "  -Name:",familyName
00094             print "  -Description:",familyDescription
00095             print "  -Entity:",familyEntity
00096             familyIdentifier = family.getIdentifier()
00097             nbOfAtt = family.getNumberOfAttributes()
00098             print "  -Identifier:",familyIdentifier
00099             print "  -Number Of Attributes:",nbOfAtt
00100             attributesids = family.getAttributesIdentifiers()
00101             attributesvals = family.getAttributesValues()
00102             for k in range(nbOfAtt):
00103                 print "    * Attributes:",attributesids[k],":",attributesvals[k],",",family.getAttributeDescription(k+1)
00104             nbOfGrp = family.getNumberOfGroups()
00105             print "  -Number Of Groups:",nbOfGrp
00106             for k in range(nbOfGrp):
00107                 print "    * Group:",family.getGroupName(k+1)
00108             print "  -Entities list:"
00109             if (familyBool):
00110                 print "  -Is on all entities"
00111             else:
00112                 nbOfTypes = family.getNumberOfTypes()
00113                 types = family.getTypes()
00114                 print "  -Number Of Types:",nbOfTypes
00115                 for k in range(nbOfTypes):
00116                     type = types[k]
00117                     nbOfElmtsOfType = family.getNumberOfElements(type)
00118                     number = family.getNumber(type)
00119                     print "    * Type",type
00120                     print "    * Number",number[0:nbOfElmtsOfType]
00121                 print ""
00122 
00123 print "we are going to do some operation on Node families"
00124 print "by definition families have no intersection"
00125 print ""
00126 entity = MED_NODE
00127 familyNode1 = mesh.getFamily(entity,1)
00128 familyNode2 = mesh.getFamily(entity,2)
00129 familyNode3 = mesh.getFamily(entity,3)
00130 familyNode4 = mesh.getFamily(entity,4)
00131 
00132 listOfSupports = []
00133 listOfSupports.append(familyNode1)
00134 listOfSupports.append(familyNode2)
00135 
00136 support = mesh.mergeSupports(listOfSupports)
00137 
00138 supportName = support.getName()
00139 supportDescription = support.getDescription()
00140 supportMeshname = support.getMesh().getName()
00141 supportEntity = support.getEntity()
00142 supportBool = support.isOnAllElements()
00143 print "  -Name:",supportName
00144 print "  -Description:",supportDescription
00145 print "  -Entity:",supportEntity
00146 if (supportBool):
00147     print "  -Is on all entities"
00148 else:
00149     nbOfTypes = support.getNumberOfTypes()
00150     types = support.getTypes()
00151     print "  -Number Of Types:",nbOfTypes
00152     for k in range(nbOfTypes):
00153         type = types[k]
00154         nbOfElmtsOfType = support.getNumberOfElements(type)
00155         number = support.getNumber(type)
00156         print "    * Type",type
00157         print "    * Number",number[0:nbOfElmtsOfType]
00158     print ""
00159 
00160 support = mesh.intersectSupports(listOfSupports)
00161 
00162 supportName = support.getName()
00163 supportDescription = support.getDescription()
00164 supportMeshname = support.getMesh().getName()
00165 supportEntity = support.getEntity()
00166 supportBool = support.isOnAllElements()
00167 print "  -Name:",supportName
00168 print "  -Description:",supportDescription
00169 print "  -Entity:",supportEntity
00170 if (supportBool):
00171     print "  -Is on all entities"
00172 else:
00173     nbOfTypes = support.getNumberOfTypes()
00174     types = support.getTypes()
00175     print "  -Number Of Types:",nbOfTypes
00176     for k in range(nbOfTypes):
00177         type = types[k]
00178         nbOfElmtsOfType = support.getNumberOfElements(type)
00179         number = support.getNumber(type)
00180         print "    * Type",type
00181         print "    * Number",number[0:nbOfElmtsOfType]
00182     print ""
00183 
00184 listOfSupports.append(familyNode3)
00185 
00186 support = mesh.mergeSupports(listOfSupports)
00187 
00188 supportName = support.getName()
00189 supportDescription = support.getDescription()
00190 supportMeshname = support.getMesh().getName()
00191 supportEntity = support.getEntity()
00192 supportBool = support.isOnAllElements()
00193 print "  -Name:",supportName
00194 print "  -Description:",supportDescription
00195 print "  -Entity:",supportEntity
00196 if (supportBool):
00197     print "  -Is on all entities"
00198 else:
00199     nbOfTypes = support.getNumberOfTypes()
00200     types = support.getTypes()
00201     print "  -Number Of Types:",nbOfTypes
00202     for k in range(nbOfTypes):
00203         type = types[k]
00204         nbOfElmtsOfType = support.getNumberOfElements(type)
00205         number = support.getNumber(type)
00206         print "    * Type",type
00207         print "    * Number",number[0:nbOfElmtsOfType]
00208     print ""
00209 
00210 print "we are going to do some operation on Cell families"
00211 print "by definition families have no intersection"
00212 print ""
00213 entity = MED_CELL
00214 familyCell1 = mesh.getFamily(entity,1)
00215 familyCell2 = mesh.getFamily(entity,2)
00216 familyCell3 = mesh.getFamily(entity,3)
00217 
00218 listOfSupports = []
00219 listOfSupports.append(familyCell1)
00220 listOfSupports.append(familyCell2)
00221 
00222 support = mesh.mergeSupports(listOfSupports)
00223 
00224 supportName = support.getName()
00225 supportDescription = support.getDescription()
00226 supportMeshname = support.getMesh().getName()
00227 supportEntity = support.getEntity()
00228 supportBool = support.isOnAllElements()
00229 print "  -Name:",supportName
00230 print "  -Description:",supportDescription
00231 print "  -Entity:",supportEntity
00232 if (supportBool):
00233     print "  -Is on all entities"
00234 else:
00235     nbOfTypes = support.getNumberOfTypes()
00236     types = support.getTypes()
00237     print "  -Number Of Types:",nbOfTypes
00238     for k in range(nbOfTypes):
00239         type = types[k]
00240         nbOfElmtsOfType = support.getNumberOfElements(type)
00241         number = support.getNumber(type)
00242         print "    * Type",type
00243         print "    * Number",number[0:nbOfElmtsOfType]
00244     print ""
00245 
00246 support = mesh.intersectSupports(listOfSupports)
00247 
00248 supportName = support.getName()
00249 supportDescription = support.getDescription()
00250 supportMeshname = support.getMesh().getName()
00251 supportEntity = support.getEntity()
00252 supportBool = support.isOnAllElements()
00253 print "  -Name:",supportName
00254 print "  -Description:",supportDescription
00255 print "  -Entity:",supportEntity
00256 if (supportBool):
00257     print "  -Is on all entities"
00258 else:
00259     nbOfTypes = support.getNumberOfTypes()
00260     types = support.getTypes()
00261     print "  -Number Of Types:",nbOfTypes
00262     for k in range(nbOfTypes):
00263         type = types[k]
00264         nbOfElmtsOfType = support.getNumberOfElements(type)
00265         number = support.getNumber(type)
00266         print "    * Type",type
00267         print "    * Number",number[0:nbOfElmtsOfType]
00268     print ""
00269 
00270 listOfSupports.append(familyCell3)
00271 
00272 support = mesh.mergeSupports(listOfSupports)
00273 
00274 supportName = support.getName()
00275 supportDescription = support.getDescription()
00276 supportMeshname = support.getMesh().getName()
00277 supportEntity = support.getEntity()
00278 supportBool = support.isOnAllElements()
00279 print "  -Name:",supportName
00280 print "  -Description:",supportDescription
00281 print "  -Entity:",supportEntity
00282 if (supportBool):
00283     print "  -Is on all entities"
00284 else:
00285     nbOfTypes = support.getNumberOfTypes()
00286     types = support.getTypes()
00287     print "  -Number Of Types:",nbOfTypes
00288     for k in range(nbOfTypes):
00289         type = types[k]
00290         nbOfElmtsOfType = support.getNumberOfElements(type)
00291         number = support.getNumber(type)
00292         print "    * Type",type
00293         print "    * Number",number[0:nbOfElmtsOfType]
00294     print ""
00295 
00296 print "Let's now do an example of union and intersection of two supports with a non empty intersection"
00297 print ""
00298 support1 = SUPPORT()
00299 support1.setMesh(mesh)
00300 support1.setName("Partial_Support_1")
00301 support1Description = "Partial Support 1"
00302 support1NbOfTypes = 3
00303 support1TotNbElm = 8
00304 support1GeoType = [MED_TETRA4,MED_HEXA8,MED_PYRA5]
00305 support1NbOfElm = [4,2,2]
00306 support1NbValue = [1,2,3,4,15,16,13,14]
00307 
00308 support1.setpartial(support1Description,support1NbOfTypes,support1TotNbElm,
00309                     support1GeoType,support1NbOfElm,support1NbValue)
00310 
00311 supportName = support1.getName()
00312 supportDescription = support1.getDescription()
00313 supportMeshname = support1.getMesh().getName()
00314 supportEntity = support1.getEntity()
00315 supportBool = support1.isOnAllElements()
00316 print "  -Name:",supportName
00317 print "  -Description:",supportDescription
00318 print "  -Entity:",supportEntity
00319 if (supportBool):
00320     print "  -Is on all entities"
00321 else:
00322     nbOfTypes = support1.getNumberOfTypes()
00323     types = support1.getTypes()
00324     print "  -Number Of Types:",nbOfTypes
00325     for k in range(nbOfTypes):
00326         type = types[k]
00327         nbOfElmtsOfType = support1.getNumberOfElements(type)
00328         number = support1.getNumber(type)
00329         print "    * Type",type
00330         print "    * Number",number[0:nbOfElmtsOfType]
00331     print ""
00332 
00333 support2 = SUPPORT()
00334 support2.setMesh(mesh)
00335 support2.setName("Partial_Support_2")
00336 support2Description = "Partial Support 2"
00337 support2NbOfTypes = 3
00338 support2TotNbElm = 8
00339 support2GeoType = [MED_TETRA4,MED_HEXA8,MED_PYRA5]
00340 support2NbOfElm = [6,1,1]
00341 support2NbValue = [3,4,9,10,11,12,16,14]
00342 
00343 support2.setpartial(support2Description,support2NbOfTypes,support2TotNbElm,
00344                     support2GeoType,support2NbOfElm,support2NbValue)
00345 
00346 supportName = support2.getName()
00347 supportDescription = support2.getDescription()
00348 supportMeshname = support2.getMesh().getName()
00349 supportEntity = support2.getEntity()
00350 supportBool = support2.isOnAllElements()
00351 print "  -Name:",supportName
00352 print "  -Description:",supportDescription
00353 print "  -Entity:",supportEntity
00354 if (supportBool):
00355     print "  -Is on all entities"
00356 else:
00357     nbOfTypes = support2.getNumberOfTypes()
00358     types = support2.getTypes()
00359     print "  -Number Of Types:",nbOfTypes
00360     for k in range(nbOfTypes):
00361         type = types[k]
00362         nbOfElmtsOfType = support2.getNumberOfElements(type)
00363         number = support2.getNumber(type)
00364         print "    * Type",type
00365         print "    * Number",number[0:nbOfElmtsOfType]
00366     print ""
00367 
00368 listOfSupports = []
00369 listOfSupports.append(support1)
00370 listOfSupports.append(support2)
00371 
00372 print "The union"
00373 print ""
00374 
00375 support = mesh.mergeSupports(listOfSupports)
00376 
00377 supportName = support.getName()
00378 supportDescription = support.getDescription()
00379 supportMeshname = support.getMesh().getName()
00380 supportEntity = support.getEntity()
00381 supportBool = support.isOnAllElements()
00382 print "  -Name:",supportName
00383 print "  -Description:",supportDescription
00384 print "  -Entity:",supportEntity
00385 if (supportBool):
00386     print "  -Is on all entities"
00387 else:
00388     nbOfTypes = support.getNumberOfTypes()
00389     types = support.getTypes()
00390     print "  -Number Of Types:",nbOfTypes
00391     for k in range(nbOfTypes):
00392         type = types[k]
00393         nbOfElmtsOfType = support.getNumberOfElements(type)
00394         number = support.getNumber(type)
00395         print "    * Type",type
00396         print "    * Number",number[0:nbOfElmtsOfType]
00397     print ""
00398 
00399 print "The intersection"
00400 print ""
00401 
00402 support = mesh.intersectSupports(listOfSupports)
00403 
00404 supportName = support.getName()
00405 supportDescription = support.getDescription()
00406 supportMeshname = support.getMesh().getName()
00407 supportEntity = support.getEntity()
00408 supportBool = support.isOnAllElements()
00409 print "  -Name:",supportName
00410 print "  -Description:",supportDescription
00411 print "  -Entity:",supportEntity
00412 if (supportBool):
00413     print "  -Is on all entities"
00414 else:
00415     nbOfTypes = support.getNumberOfTypes()
00416     types = support.getTypes()
00417     print "  -Number Of Types:",nbOfTypes
00418     for k in range(nbOfTypes):
00419         type = types[k]
00420         nbOfElmtsOfType = support.getNumberOfElements(type)
00421         number = support.getNumber(type)
00422         print "    * Type",type
00423         print "    * Number",number[0:nbOfElmtsOfType]
00424     print ""
00425 
00426 print "END of the Pyhton script ..... Ctrl D to exit"