Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MedClient / src / testMeshAlliances.py
1 import salome
2 import SALOME
3 import os
4
5 from libMEDClient import *
6
7 filePath=os.environ["MED_ROOT_DIR"]
8 filePath=filePath+"/share/salome/resources/med/"
9
10 medFiles = []
11 medFiles.append("extendedtransport53_triangles.med")
12 medFiles.append("maillage_5_5_5.med")
13 medFiles.append("maillage_chemvalIV_cas1_40elts.med")
14 medFiles.append("Old_maillage_chemvalIV_cas1_40elts.med")
15
16 meshNames = []
17 meshNames.append("TestA3_2094_0.1_rsurf_tri")
18 meshNames.append("maillage_5_5_5")
19 meshNames.append("maillage_chemvalIV_cas1_40elts")
20 meshNames.append("maillage_chemvalIV_cas1_40elts")
21
22 nbOfFiles = len(medFiles)
23
24 med=salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
25
26 for i in range(nbOfFiles):
27   medFile = filePath + medFiles[i]
28   meshName = meshNames[i]
29
30
31   try:
32     meshCorba = med.readMeshInFile(medFile, salome.myStudyName,meshName)
33   except SALOME.SALOME_Exception, ex:
34     print ex.details
35     print ex.details.type
36     print ex.details.text
37     print ex.details.sourceFile
38     print ex.details.lineNumber
39
40     raise
41
42   print "meshName = ",meshCorba.getName()
43   print "mesh number of nodes", meshCorba.getNumberOfNodes()
44
45
46
47
48
49
50   meshLocalCopy = MESHClient(meshCorba)
51   print "      getting information from the local copy of the distant mesh"
52   name = meshLocalCopy.getName()
53   spaceDimension = meshLocalCopy.getSpaceDimension()
54   meshDimension = meshLocalCopy.getMeshDimension()
55   numberOfNodes = meshLocalCopy.getNumberOfNodes()
56   print "          Name = ", name, " space Dim = ", spaceDimension, " mesh Dim = ", meshDimension, " Nb of Nodes = ", numberOfNodes
57   coordSyst = meshLocalCopy.getCoordinatesSystem()
58   print "          The coordinates system is",coordSyst
59   print "          The Coordinates :"
60   coordNames = []
61   coordUnits = []
62   for isd in range(spaceDimension):
63       coordNames.append(meshLocalCopy.getCoordinateName(isd))
64       coordUnits.append(meshLocalCopy.getCoordinateUnit(isd))
65
66   print "          names:", coordNames
67   print "          units", coordUnits
68   print "          values:"
69   coordinates = meshLocalCopy.getCoordinates(MED_FULL_INTERLACE)
70   for k in range(numberOfNodes):
71       kp1 = k+1
72       print "         ---- ", coordinates[k*spaceDimension:(kp1*spaceDimension)]
73   print ""
74   print "          The Cell Nodal Connectivity of the Cells:"
75   nbTypesCell = meshLocalCopy.getNumberOfTypes(MED_CELL)
76   print ""
77   if (nbTypesCell>0):
78       print "      The Mesh has",nbTypesCell,"Type(s) of Cell"
79       types = meshLocalCopy.getTypes(MED_CELL)
80       for k in range(nbTypesCell):
81           type = types[k]
82           nbElemType = meshLocalCopy.getNumberOfElements(MED_CELL,type)
83           print "     For the type:",type,"there is(are)",nbElemType,"elemnt(s)"
84           connectivity = meshLocalCopy.getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,type)
85           nbNodesPerCell = type%100
86           for j in range(nbElemType):
87               print "       Element",(j+1)," ",connectivity[j*nbNodesPerCell:(j+1)*nbNodesPerCell]
88               pass
89           pass
90       pass
91
92   ##
93   ## TEST METHODS ABOUT POLY ELEMENTS ##
94   ##
95   nbTypesCellWithPoly = meshLocalCopy.getNumberOfTypesWithPoly(MED_CELL)
96   if (nbTypesCell == nbTypesCellWithPoly):
97       print ""
98       print "          No Poly Cells in the mesh"
99       print ""
100       pass
101   else:
102       print ""
103       print "          The Cell Nodal Connectivity of the Poly Cells:"
104       print ""
105       print "      The Mesh has",nbTypesCellWithPoly-nbTypesCell,"Type(s) of Poly Cell"
106       types = meshLocalCopy.getTypesWithPoly(MED_CELL)
107       for k in range(nbTypesCellWithPoly):
108           type = types[k]
109           if type == MED_POLYGON:
110               nbElemType = meshLocalCopy.getNumberOfPolygons()
111           elif type == MED_POLYHEDRA:
112               nbElemType = meshLocalCopy.getNumberOfPolyhedron()
113           else:
114               continue
115           print ""
116           print "     For the type:",type,"there is(are)",nbElemType,"elemnt(s)"
117           if type == MED_POLYGON:
118               connectivity = meshLocalCopy.getPolygonsConnectivity(MED_NODAL,MED_CELL)
119               index = meshLocalCopy.getPolygonsConnectivityIndex(MED_NODAL,MED_CELL)
120               for j in range(nbElemType):
121                   print "       Polygon",(j+1)," ",connectivity[ index[j]-1 : index[j+1]-1 ]
122                   pass
123               pass
124           else:
125               connectivity = meshLocalCopy.getPolyhedronConnectivity(MED_NODAL)
126               fIndex = meshLocalCopy.getPolyhedronFacesIndex()
127               index = meshLocalCopy.getPolyhedronIndex(MED_NODAL)
128               for j in range(nbElemType):
129                   print     "       Polyhedra",(j+1)
130                   iF1, iF2 = index[ j ]-1, index[ j+1 ]-1
131                   for f in range( iF2 - iF1 ):
132                       iN1, iN2 = fIndex[ iF1+f ]-1, fIndex[ iF1+f+1 ]-1
133                       print "         Face",f+1," ",connectivity[ iN1 : iN2 ]
134                       pass
135                   pass
136               pass
137           pass
138       pass
139   pass
140
141 print "END of the Pyhton script ..... Ctrl D to exit"