Back to index

salome-med  6.5.0
test_gibi.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 ###################################################################################
00026 #
00027 from libMEDMEM_Swig import *
00028 from random import *
00029 import string
00030 import os
00031 #
00032 #befor running this script, please be sure about the path the file fileName
00033 #
00034 filePath=os.environ["MED_ROOT_DIR"]
00035 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
00036 gibiFile = "elle_2D_QT_2x2.sauve"
00037 mesh1Name = string.split(gibiFile,".")[0]+"_fromGibiDriver"
00038 
00039 gibiFile = os.path.join(filePath, gibiFile)
00040 medFile = string.split(gibiFile,".")[0]+"_fromGibiDriver.med"
00041 vtkFile = string.split(gibiFile,".")[0]+"_fromGibiDriver.vtk"
00042 mesh2Name = mesh1Name
00043 
00044 mesh = MESH()
00045 meshDriver = GIBI_MESH_RDONLY_DRIVER(gibiFile,mesh)
00046 
00047 meshDriver.open()
00048 meshDriver.read()
00049 meshDriver.close()
00050 
00051 #print mesh
00052 
00053 meshName = mesh.getName()
00054 spaceDim = mesh.getSpaceDimension()
00055 meshDim = mesh.getMeshDimension()
00056 print "The mesh ",meshName," is a ",spaceDim,"D mesh on a ",meshDim,"D geometry"
00057 print "and is mounted via the GIBI driver"
00058 nbNodes = mesh.getNumberOfNodes()
00059 print "The mesh ",meshName," has",nbNodes,"Nodes"
00060 coordSyst = mesh.getCoordinatesSystem()
00061 print "The coordinates system is",coordSyst
00062 print "The Coordinates :"
00063 coordNames = []
00064 coordUnits = []
00065 for isd in range(spaceDim):
00066     coordNames.append(mesh.getCoordinateName(isd))
00067     coordUnits.append(mesh.getCoordinateUnit(isd))
00068 
00069 print "names:", coordNames
00070 print "units", coordUnits
00071 print "values:"
00072 coordinates = mesh.getCoordinates(MED_FULL_INTERLACE)
00073 for k in range(nbNodes):
00074     kp1 = k+1
00075     coords = []
00076     for isd in range(spaceDim):
00077         isdp1 = isd+1
00078         coords.append(mesh.getCoordinate(kp1,isdp1))
00079 
00080     print coords," ---- ", coordinates[k*spaceDim:((k+1)*spaceDim)]
00081 
00082 print ""
00083 print "Show the Nodal Connectivity:"
00084 nbTypesCell = mesh.getNumberOfTypes(MED_CELL)
00085 print ""
00086 if (nbTypesCell>0):
00087     print "The Mesh has",nbTypesCell,"Type(s) of Cell"
00088     types = mesh.getTypes(MED_CELL)
00089     for k in range(nbTypesCell):
00090         type = types[k]
00091         nbElemType = mesh.getNumberOfElements(MED_CELL,type)
00092         print "For the type:",type,"there is(are)",nbElemType,"elemnt(s)"
00093         connectivity = mesh.getConnectivity(MED_NODAL,MED_CELL,type)
00094         nbNodesPerCell = type%100
00095         for j in range(nbElemType):
00096             print "Element",(j+1)," ",connectivity[j*nbNodesPerCell:(j+1)*nbNodesPerCell]
00097 
00098 print ""
00099 print "Show the Reverse Nodal Connectivity:"
00100 ReverseConnectivity = mesh.getReverseConnectivity(MED_NODAL)
00101 ReverseConnectivityIndex = mesh.getReverseConnectivityIndex(MED_NODAL)
00102 print ""
00103 for j in range(nbNodes):
00104     begin = ReverseConnectivityIndex[j]-1
00105     end = ReverseConnectivityIndex[j+1]-1
00106     print "Node",(j+1),"-->",ReverseConnectivity[begin:end]
00107 
00108 print ""
00109 print "Show the Descending Connectivity:"
00110 mesh.calculateConnectivity(MED_DESCENDING,MED_CELL)
00111 nbElemts = mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00112 Connectivity = mesh.getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS)
00113 ConnectivityIndex = mesh.getConnectivityIndex(MED_DESCENDING,MED_CELL)
00114 print ""
00115 for j in range(nbElemts):
00116     begin = ConnectivityIndex[j]-1
00117     end = ConnectivityIndex[j+1]-1
00118     print "Element",(j+1),"-->",Connectivity[begin:end]
00119 
00120 print ""
00121 for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
00122     nbFam = mesh.getNumberOfFamilies(entity)
00123     nbGrp = mesh.getNumberOfGroups(entity)
00124     if (entity == MED_NODE) :
00125         if (nbFam > 0) : print "This mesh has",nbFam,"Node Family(ies)"
00126         if (nbGrp > 0) : print "This mesh has",nbGrp,"Node Group(s)"
00127     elif (entity == MED_CELL) :
00128         if (nbFam > 0) : print "This mesh has",nbFam,"Cell Family(ies)"
00129         if (nbGrp > 0) : print "This mesh has",nbGrp,"Cell Group(s)"
00130     elif (entity == MED_FACE) :
00131         if (nbFam > 0) : print "This mesh has",nbFam,"Face Family(ies)"
00132         if (nbGrp > 0) : print "This mesh has",nbGrp,"Face Group(s)"
00133     elif (entity == MED_EDGE) :
00134         if (nbFam > 0) : print "This mesh has",nbFam,"Edge Family(ies)"
00135         if (nbGrp > 0) : print "This mesh has",nbGrp,"Edge Group(s)"
00136 
00137 for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
00138     nbFam = mesh.getNumberOfFamilies(entity)
00139     nbGrp = mesh.getNumberOfGroups(entity)
00140     if nbFam > 0:
00141         for j in range(nbFam):
00142             print ""
00143             family = mesh.getFamily(entity,j+1)
00144             familyName = family.getName()
00145             familyDescription = family.getDescription()
00146             familyEntity = family.getEntity()
00147             familyBool = family.isOnAllElements()
00148             print "  -Name:",familyName
00149             print "  -Description:",familyDescription
00150             print "  -Entity:",familyEntity
00151             familyIdentifier = family.getIdentifier()
00152             nbOfAtt = family.getNumberOfAttributes()
00153             print "  -Identifier:",familyIdentifier
00154             print "  -Number Of Attributes:",nbOfAtt
00155             attributesids = family.getAttributesIdentifiers()
00156             attributesvals = family.getAttributesValues()
00157             for k in range(nbOfAtt):
00158                 print "    * Attributes:",attributesids[k],":",attributesvals[k],",",family.getAttributeDescription(k+1)
00159             nbOfGrp = family.getNumberOfGroups()
00160             print "  -Number Of Groups:",nbOfGrp
00161             for k in range(nbOfGrp):
00162                 print "    * Group:",family.getGroupName(k+1)
00163             print "  -Entities list:"
00164             if (familyBool):
00165                 print "  -Is on all entities"
00166             else:
00167                 nbOfTypes = family.getNumberOfTypes()
00168                 types = family.getTypes()
00169                 print "  -Number Of Types:",nbOfTypes
00170                 for k in range(nbOfTypes):
00171                     type = types[k]
00172                     nbOfElmtsOfType = family.getNumberOfElements(type)
00173                     number = family.getNumber(type)
00174                     print "    * Type",type
00175                     print "    * Number",number[0:nbOfElmtsOfType]
00176                 print ""
00177     print ""
00178 
00179     if nbGrp > 0:
00180         for j in range(nbGrp):
00181             print ""
00182             group = mesh.getGroup(entity,j+1)
00183             groupName = group.getName()
00184             groupDescription = group.getDescription()
00185             groupEntity = group.getEntity()
00186             groupBool = group.isOnAllElements()
00187             print "  -Name:",groupName
00188             print "  -Description:",groupDescription
00189             print "  -Entity:",groupEntity
00190             nbOfFam = group.getNumberOfFamilies()
00191             print "  -Number Of Families:",nbOfFam
00192             for k in range(nbOfFam):
00193                 print "    * Family:",group.getFamily(k+1).getName()
00194             print "  -Entities list:"
00195             if (groupBool):
00196                 print "  -Is on all entities"
00197             else:
00198                 nbOfTypes = group.getNumberOfTypes()
00199                 types = group.getTypes()
00200                 print "  -Number Of Types:",nbOfTypes
00201                 for k in range(nbOfTypes):
00202                     type = types[k]
00203                     nbOfElmtsOfType = group.getNumberOfElements(type)
00204                     number = group.getNumber(type)
00205                     print "    * Type",type
00206                     print "    * Number",number[0:nbOfElmtsOfType]
00207                 print ""
00208         print ""
00209 
00210 print "Printing of this mesh in med and vtk format with the name ", mesh.getName()
00211 
00212 idMed = mesh.addDriver(MED_DRIVER,medFile,mesh1Name)
00213 mesh.write(idMed)
00214 
00215 idVtk = mesh.addDriver(VTK_DRIVER,vtkFile,mesh2Name)
00216 mesh.write(idVtk)
00217 print ""
00218 print "Mounting this mesh using the MED driver"
00219 print ""
00220 
00221 mesh1 = MESH()
00222 mesh1Driver = MED_MESH_RDONLY_DRIVER(medFile,mesh1)
00223 
00224 mesh1Driver.setMeshName(mesh1Name)
00225 
00226 mesh1Driver.open()
00227 mesh1Driver.read()
00228 mesh1Driver.close()
00229 
00230 #print mesh
00231 
00232 mesh_name = mesh1Driver.getMeshName()
00233 meshName = mesh1.getName()
00234 spaceDim = mesh1.getSpaceDimension()
00235 meshDim = mesh1.getMeshDimension()
00236 print "The mesh ",meshName," is a ",spaceDim,"D mesh on a ",meshDim,"D geometry"
00237 nbNodes = mesh1.getNumberOfNodes()
00238 print "The mesh has",nbNodes,"Nodes"
00239 coordSyst = mesh1.getCoordinatesSystem()
00240 print "The coordinates system is",coordSyst
00241 print "The Coordinates :"
00242 coordNames = []
00243 coordUnits = []
00244 for isd in range(spaceDim):
00245     coordNames.append(mesh1.getCoordinateName(isd))
00246     coordUnits.append(mesh1.getCoordinateUnit(isd))
00247 
00248 print "names:", coordNames
00249 print "units", coordUnits
00250 print "values:"
00251 coordinates = mesh1.getCoordinates(MED_FULL_INTERLACE)
00252 for k in range(nbNodes):
00253     kp1 = k+1
00254     coords = []
00255     for isd in range(spaceDim):
00256         isdp1 = isd+1
00257         coords.append(mesh1.getCoordinate(kp1,isdp1))
00258 
00259     print coords," ---- ", coordinates[k*spaceDim:((k+1)*spaceDim)]
00260 
00261 print ""
00262 print "Show the Nodal Connectivity:"
00263 nbTypesCell = mesh1.getNumberOfTypes(MED_CELL)
00264 print ""
00265 if (nbTypesCell>0):
00266     print "The Mesh has",nbTypesCell,"Type(s) of Cell"
00267     types = mesh1.getTypes(MED_CELL)
00268     for k in range(nbTypesCell):
00269         type = types[k]
00270         nbElemType = mesh1.getNumberOfElements(MED_CELL,type)
00271         print "For the type:",type,"there is(are)",nbElemType,"elemnt(s)"
00272         connectivity = mesh1.getConnectivity(MED_NODAL,MED_CELL,type)
00273         nbNodesPerCell = type%100
00274         for j in range(nbElemType):
00275             print "Element",(j+1)," ",connectivity[j*nbNodesPerCell:(j+1)*nbNodesPerCell]
00276 
00277 print ""
00278 print "Show the Reverse Nodal Connectivity:"
00279 ReverseConnectivity = mesh1.getReverseConnectivity(MED_NODAL)
00280 ReverseConnectivityIndex = mesh1.getReverseConnectivityIndex(MED_NODAL)
00281 print ""
00282 for j in range(nbNodes):
00283     begin = ReverseConnectivityIndex[j]-1
00284     end = ReverseConnectivityIndex[j+1]-1
00285     print "Node",(j+1),"-->",ReverseConnectivity[begin:end]
00286 
00287 print ""
00288 print "Show the Descending Connectivity:"
00289 mesh1.calculateConnectivity(MED_DESCENDING,MED_CELL)
00290 nbElemts = mesh1.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00291 Connectivity = mesh1.getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS)
00292 ConnectivityIndex = mesh1.getConnectivityIndex(MED_DESCENDING,MED_CELL)
00293 print ""
00294 for j in range(nbElemts):
00295     begin = ConnectivityIndex[j]-1
00296     end = ConnectivityIndex[j+1]-1
00297     print "Element",(j+1),"-->",Connectivity[begin:end]
00298 
00299 print ""
00300 for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
00301     nbFam = mesh1.getNumberOfFamilies(entity)
00302     nbGrp = mesh1.getNumberOfGroups(entity)
00303     if (entity == MED_NODE) :
00304         if (nbFam > 0) : print "This mesh has",nbFam,"Node Family(ies)"
00305         if (nbGrp > 0) : print "This mesh has",nbGrp,"Node Group(s)"
00306     elif (entity == MED_CELL) :
00307         if (nbFam > 0) : print "This mesh has",nbFam,"Cell Family(ies)"
00308         if (nbGrp > 0) : print "This mesh has",nbGrp,"Cell Group(s)"
00309     elif (entity == MED_FACE) :
00310         if (nbFam > 0) : print "This mesh has",nbFam,"Face Family(ies)"
00311         if (nbGrp > 0) : print "This mesh has",nbGrp,"Face Group(s)"
00312     elif (entity == MED_EDGE) :
00313         if (nbFam > 0) : print "This mesh has",nbFam,"Edge Family(ies)"
00314         if (nbGrp > 0) : print "This mesh has",nbGrp,"Edge Group(s)"
00315 
00316 for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
00317     nbFam = mesh1.getNumberOfFamilies(entity)
00318     nbGrp = mesh1.getNumberOfGroups(entity)
00319     if nbFam > 0:
00320         for j in range(nbFam):
00321             print ""
00322             family = mesh1.getFamily(entity,j+1)
00323             familyName = family.getName()
00324             familyDescription = family.getDescription()
00325             familyEntity = family.getEntity()
00326             familyBool = family.isOnAllElements()
00327             print "  -Name:",familyName
00328             print "  -Description:",familyDescription
00329             print "  -Entity:",familyEntity
00330             familyIdentifier = family.getIdentifier()
00331             nbOfAtt = family.getNumberOfAttributes()
00332             print "  -Identifier:",familyIdentifier
00333             print "  -Number Of Attributes:",nbOfAtt
00334             attributesids = family.getAttributesIdentifiers()
00335             attributesvals = family.getAttributesValues()
00336             for k in range(nbOfAtt):
00337                 print "    * Attributes:",attributesids[k],":",attributesvals[k],",",family.getAttributeDescription(k+1)
00338             nbOfGrp = family.getNumberOfGroups()
00339             print "  -Number Of Groups:",nbOfGrp
00340             for k in range(nbOfGrp):
00341                 print "    * Group:",family.getGroupName(k+1)
00342             print "  -Entities list:"
00343             if (familyBool):
00344                 print "  -Is on all entities"
00345             else:
00346                 nbOfTypes = family.getNumberOfTypes()
00347                 types = family.getTypes()
00348                 print "  -Number Of Types:",nbOfTypes
00349                 for k in range(nbOfTypes):
00350                     type = types[k]
00351                     nbOfElmtsOfType = family.getNumberOfElements(type)
00352                     number = family.getNumber(type)
00353                     print "    * Type",type
00354                     print "    * Number",number[0:nbOfElmtsOfType]
00355                 print ""
00356     print ""
00357 
00358     if nbGrp > 0:
00359         for j in range(nbGrp):
00360             print ""
00361             group = mesh1.getGroup(entity,j+1)
00362             groupName = group.getName()
00363             groupDescription = group.getDescription()
00364             groupEntity = group.getEntity()
00365             groupBool = group.isOnAllElements()
00366             print "  -Name:",groupName
00367             print "  -Description:",groupDescription
00368             print "  -Entity:",groupEntity
00369             nbOfFam = group.getNumberOfFamilies()
00370             print "  -Number Of Families:",nbOfFam
00371             for k in range(nbOfFam):
00372                 print "    * Family:",group.getFamily(k+1).getName()
00373             print "  -Entities list:"
00374             if (groupBool):
00375                 print "  -Is on all entities"
00376             else:
00377                 nbOfTypes = group.getNumberOfTypes()
00378                 types = group.getTypes()
00379                 print "  -Number Of Types:",nbOfTypes
00380                 for k in range(nbOfTypes):
00381                     type = types[k]
00382                     nbOfElmtsOfType = group.getNumberOfElements(type)
00383                     number = group.getNumber(type)
00384                     print "    * Type",type
00385                     print "    * Number",number[0:nbOfElmtsOfType]
00386                 print ""
00387         print ""
00388 
00389 print "END of the Pyhton script ..... Ctrl D to exit"