Back to index

salome-med  6.5.0
testMeshAlliances.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 import salome
00025 import SALOME
00026 import os
00027 
00028 from libMEDClient import *
00029 
00030 filePath=os.environ["MED_ROOT_DIR"]
00031 filePath=os.path.join( filePath, "share", "salome", "resources", "med" )
00032 
00033 medFiles = []
00034 medFiles.append("extendedtransport53_triangles.med")
00035 medFiles.append("maillage_5_5_5.med")
00036 medFiles.append("maillage_chemvalIV_cas1_40elts.med")
00037 medFiles.append("Old_maillage_chemvalIV_cas1_40elts.med")
00038 
00039 meshNames = []
00040 meshNames.append("TestA3_2094_0.1_rsurf_tri")
00041 meshNames.append("maillage_5_5_5")
00042 meshNames.append("maillage_chemvalIV_cas1_40elts")
00043 meshNames.append("maillage_chemvalIV_cas1_40elts")
00044 
00045 nbOfFiles = len(medFiles)
00046 
00047 med=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
00048 
00049 for i in range(nbOfFiles):
00050   medFile = os.path.join( filePath, medFiles[i] )
00051   meshName = meshNames[i]
00052 
00053 
00054   try:
00055     meshCorba = med.readMeshInFile(medFile, salome.myStudyName,meshName)
00056   except SALOME.SALOME_Exception, ex:
00057     print ex.details
00058     print ex.details.type
00059     print ex.details.text
00060     print ex.details.sourceFile
00061     print ex.details.lineNumber
00062 
00063     raise
00064 
00065   print "meshName = ",meshCorba.getName()
00066   print "mesh number of nodes", meshCorba.getNumberOfNodes()
00067 
00068 
00069 
00070 
00071 
00072 
00073   meshLocalCopy = MESHClient(meshCorba)
00074   print "      getting information from the local copy of the distant mesh"
00075   name = meshLocalCopy.getName()
00076   spaceDimension = meshLocalCopy.getSpaceDimension()
00077   meshDimension = meshLocalCopy.getMeshDimension()
00078   numberOfNodes = meshLocalCopy.getNumberOfNodes()
00079   print "          Name = ", name, " space Dim = ", spaceDimension, " mesh Dim = ", meshDimension, " Nb of Nodes = ", numberOfNodes
00080   coordSyst = meshLocalCopy.getCoordinatesSystem()
00081   print "          The coordinates system is",coordSyst
00082   print "          The Coordinates :"
00083   coordNames = []
00084   coordUnits = []
00085   for isd in range(spaceDimension):
00086       coordNames.append(meshLocalCopy.getCoordinateName(isd))
00087       coordUnits.append(meshLocalCopy.getCoordinateUnit(isd))
00088 
00089   print "          names:", coordNames
00090   print "          units", coordUnits
00091   print "          values:"
00092   coordinates = meshLocalCopy.getCoordinates(MED_FULL_INTERLACE)
00093   for k in range(numberOfNodes):
00094       kp1 = k+1
00095       print "         ---- ", coordinates[k*spaceDimension:(kp1*spaceDimension)]
00096   print ""
00097   print "          The Cell Nodal Connectivity of the Cells:"
00098   nbTypesCell = meshLocalCopy.getNumberOfTypes(MED_CELL)
00099   print ""
00100   if (nbTypesCell>0):
00101       print "      The Mesh has",nbTypesCell,"Type(s) of Cell"
00102       types = meshLocalCopy.getTypes(MED_CELL)
00103       for k in range(nbTypesCell):
00104           type = types[k]
00105           nbElemType = meshLocalCopy.getNumberOfElements(MED_CELL,type)
00106           print "     For the type:",type,"there is(are)",nbElemType,"elemnt(s)"
00107           connectivity = meshLocalCopy.getConnectivity(MED_NODAL,MED_CELL,type)
00108           nbNodesPerCell = type%100
00109           for j in range(nbElemType):
00110               print "       Element",(j+1)," ",connectivity[j*nbNodesPerCell:(j+1)*nbNodesPerCell]
00111               pass
00112           pass
00113       pass
00114 
00115   ##
00116   ## TEST METHODS ABOUT POLY ELEMENTS ##
00117   ##
00118   nbTypesCellWithPoly = meshLocalCopy.getNumberOfTypesWithPoly(MED_CELL)
00119   if (nbTypesCell == nbTypesCellWithPoly):
00120       print ""
00121       print "          No Poly Cells in the mesh"
00122       print ""
00123       pass
00124   else:
00125       print ""
00126       print "          The Cell Nodal Connectivity of the Poly Cells:"
00127       print ""
00128       print "      The Mesh has",nbTypesCellWithPoly-nbTypesCell,"Type(s) of Poly Cell"
00129       types = meshLocalCopy.getTypesWithPoly(MED_CELL)
00130       for k in range(nbTypesCellWithPoly):
00131           type = types[k]
00132           if type == MED_POLYGON:
00133               nbElemType = meshLocalCopy.getNumberOfPolygons()
00134           elif type == MED_POLYHEDRA:
00135               nbElemType = meshLocalCopy.getNumberOfPolyhedron()
00136           else:
00137               continue
00138           print ""
00139           print "     For the type:",type,"there is(are)",nbElemType,"elemnt(s)"
00140           if type == MED_POLYGON:
00141               connectivity = meshLocalCopy.getPolygonsConnectivity(MED_NODAL,MED_CELL)
00142               index = meshLocalCopy.getPolygonsConnectivityIndex(MED_NODAL,MED_CELL)
00143               for j in range(nbElemType):
00144                   print "       Polygon",(j+1)," ",connectivity[ index[j]-1 : index[j+1]-1 ]
00145                   pass
00146               pass
00147           else:
00148               connectivity = meshLocalCopy.getPolyhedronConnectivity(MED_NODAL)
00149               fIndex = meshLocalCopy.getPolyhedronFacesIndex()
00150               index = meshLocalCopy.getPolyhedronIndex(MED_NODAL)
00151               for j in range(nbElemType):
00152                   print     "       Polyhedra",(j+1)
00153                   iF1, iF2 = index[ j ]-1, index[ j+1 ]-1
00154                   for f in range( iF2 - iF1 ):
00155                       iN1, iN2 = fIndex[ iF1+f ]-1, fIndex[ iF1+f+1 ]-1
00156                       print "         Face",f+1," ",connectivity[ iN1 : iN2 ]
00157                       pass
00158                   pass
00159               pass
00160           pass
00161       pass
00162   pass
00163 
00164 print "END of the Pyhton script ..... Ctrl D to exit"