1 import batchmode_salome
5 from libMedCorba_Swig import *
9 #==============================================================================
11 def AnalyzeField(field):
12 name = field.getName()
13 desc = field.getDescription()
14 nbComp = field.getNumberOfComponents()
15 itNum = field.getIterationNumber()
16 ordNum = field.getOrderNumber()
18 print "Analysis of the field ",name," with the description ",desc
19 print "iteration number ",itNum," order Number ",ordNum
20 print "It has ",nbComp," component(s)"
22 fieldValue = field.getValue(SALOME_MED.MED_FULL_INTERLACE)
23 fieldSupport = field.getSupport()
24 fieldMesh = fieldSupport.getMesh()
25 fieldEntity = fieldSupport.getEntity()
26 bool = fieldSupport.isOnAllElements()
29 print "The support of this field is on all entities ",fieldEntity," of the mesh ",fieldMesh.getName()
30 if fieldEntity == SALOME_MED.MED_NODE:
31 nbValByComp = fieldMesh.getNumberOfNodes()
33 nbValByComp = fieldMesh.getNumberOfElements(fieldEntity,SALOME_MED.MED_ALL_ELEMENTS)
34 print "and its dimension (number of values by component of the field) is ",nbValByComp
36 print "The support of this field is partially on entities ",fieldEntity," of the mesh ",fieldMesh.getName()
37 nbValByComp = fieldSupport.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
38 print "and its dimension (number of values by component of the field) is ",nbValByComp
40 for i in range(nbComp):
41 compName = field.getComponentName(i+1)
42 compUnit = field.getComponentUnit(i+1)
43 print "The ",(i+1),"-th component ",compName," with the unit ",compUnit
45 for i in range(nbValByComp):
46 print " * ",fieldValue[i*nbComp:(i+1)*nbComp]
48 #==============================================================================
50 def getMeshObjectFromStudy(number):
51 mySO = batchmode_salome.myStudy.FindObject("MEDMESH")
52 mysub = mySO.FindSubObject(number)[1]
54 Builder = batchmode_salome.myStudy.NewBuilder()
55 anAttr = Builder.FindOrCreateAttribute(mysub, "AttributeIOR")
56 obj = batchmode_salome.orb.string_to_object(anAttr.Value())
57 myObj = obj._narrow(SALOME_MED.MESH)
60 print "ERROR: No Mesh Object stored in this Study"
63 #==============================================================================
65 def getMedObjectFromStudy():
66 mySO = batchmode_salome.myStudy.FindObject("Objet MED")
67 Builder = batchmode_salome.myStudy.NewBuilder()
68 anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR")
69 obj = batchmode_salome.orb.string_to_object(anAttr.Value())
70 myObj = obj._narrow(SALOME_MED.MED)
73 #==============================================================================
75 # Since Corba pointeurs will be generated in this Python script
76 # a POA has to be registred to activate those Corba pointeurs
77 # and make them available by any clients (in general). In our
78 # case, it is to make those pointeurs avail able to itself
79 #==============================================================================
81 print "Activation of a POA to make available any Corba pointeurs"
82 poa = batchmode_salome.orb.resolve_initial_references("RootPOA")
83 poaManager = poa._get_the_POAManager()
86 #==============================================================================
88 studyCurrent = batchmode_salome.myStudyName
89 studyCurrentId = batchmode_salome.myStudyId
91 print "We are working in the study ",studyCurrent," with the ID ",studyCurrentId
94 #medFile = "carre_en_quad4_seg2.med"
95 medFile = "cube_hexa8_quad4.med"
97 print "Loading of the Med Component"
100 med_comp = batchmode_salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
102 med_comp.readStructFile(medFile,studyCurrent)
104 med_obj = getMedObjectFromStudy()
106 nbMeshes = med_obj.getNumberOfMeshes()
108 nbFields = med_obj.getNumberOfFields()
111 print "The med file ",medFile," has ",nbMeshes," Meshe(s) and ",nbFields," Field(s)"
114 meshcorba = getMeshObjectFromStudy(1)
116 name = meshcorba.getName()
118 nbNodes = meshcorba.getNumberOfNodes()
120 spaceDim = meshcorba.getSpaceDimension()
122 print "The mesh from the Study is ",name,".It is a ",spaceDim,"-D mesh and it has ",nbNodes," Nodes"
125 for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,SALOME_MED.MED_FACE,SALOME_MED.MED_EDGE]:
126 nbFam = meshcorba.getNumberOfFamilies(entity)
127 if (entity == SALOME_MED.MED_NODE) & (nbFam > 0):
128 print "This mesh has",nbFam,"Node Family(ies)"
129 elif (entity == SALOME_MED.MED_CELL) & (nbFam > 0):
130 print "This mesh has",nbFam,"Cell Family(ies)"
131 elif (entity == SALOME_MED.MED_FACE) & (nbFam > 0):
132 print "This mesh has",nbFam,"Face Family(ies)"
133 elif (entity == SALOME_MED.MED_EDGE) & (nbFam > 0):
134 print "This mesh has",nbFam,"Edge Family(ies)"
137 for j in range(nbFam):
139 familycorba = meshcorba.getFamily(entity,j+1)
140 familyName = familycorba.getName()
141 familyDescription = familycorba.getDescription()
142 familyEntity = familycorba.getEntity()
143 familyBool = familycorba.isOnAllElements()
144 print " -Name:",familyName
145 print " -Description:",familyDescription
146 print " -Entity:",familyEntity
147 familyIdentifier = familycorba.getIdentifier()
148 nbOfAtt = familycorba.getNumberOfAttributes()
149 print " -Identifier:",familyIdentifier
150 print " -Number Of Attributes:",nbOfAtt
151 attributesids = familycorba.getAttributesIdentifiers()
152 attributesvals = familycorba.getAttributesValues()
153 for k in range(nbOfAtt):
154 print " * Attributes:",attributesids[k],":",attributesvals[k],",",familycorba.getAttributeDescription(k+1)
155 print " -Entities list:"
157 print " -Is on all entities"
159 types = familycorba.getTypes()
160 nbOfTypes = len(types)
161 print " -Number Of Types:",nbOfTypes
162 for k in range(nbOfTypes):
164 nbOfElmtsOfType = familycorba.getNumberOfElements(type)
165 number = familycorba.getNumber(type)
167 print " * Number",number[0:nbOfElmtsOfType]
169 lengthValue = familycorba.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
171 print "Generate a Local scalar double field"
172 fieldScalDblLoc = createLocalFieldDouble(nbOfComp,lengthValue)
173 for k in range(lengthValue):
175 for kcomp in range(nbOfComp):
176 valueI.append(random())
177 fieldScalDblLoc.setValueI(MED_FULL_INTERLACE,k+1,valueI)
178 valueIverif = fieldScalDblLoc.getValueI(MED_FULL_INTERLACE,k+1)
179 print " Set/Get Entry *",(k+1)," ",valueI[:nbOfComp]," / ",valueIverif[:nbOfComp]
180 print "Generate a Corba scalar double field"
181 fieldScalDblCorba = createCorbaFieldDouble(familycorba,fieldScalDblLoc)
182 AnalyzeField(fieldScalDblCorba)
184 print "Generate a Local scalar integer field"
185 fieldScalIntLoc = createLocalFieldInt(nbOfComp,lengthValue)
186 for k in range(lengthValue):
188 for kcomp in range(nbOfComp):
189 valueI.append(randint(0,100))
190 fieldScalIntLoc.setValueI(MED_FULL_INTERLACE,k+1,valueI)
191 valueIverif = fieldScalIntLoc.getValueI(MED_FULL_INTERLACE,k+1)
192 print " Set/Get Entry *",(k+1)," ",valueI[:nbOfComp]," / ",valueIverif[:nbOfComp]
193 print "Generate a Corba scalar integer field"
194 fieldScalIntCorba = createCorbaFieldInt(familycorba,fieldScalIntLoc)
195 AnalyzeField(fieldScalIntCorba)
198 print "Generate a Local vector double field"
199 fieldVectDblLoc = createLocalFieldDouble(nbOfComp,lengthValue)
200 for k in range(lengthValue):
202 for kcomp in range(nbOfComp):
203 valueI.append(random())
204 fieldVectDblLoc.setValueI(MED_FULL_INTERLACE,k+1,valueI)
205 valueIverif = fieldVectDblLoc.getValueI(MED_FULL_INTERLACE,k+1)
206 print " Set/Get Entry *",(k+1)," ",valueI[:nbOfComp]," / ",valueIverif[:nbOfComp]
207 print "Generate a Corba vector double field"
208 fieldVectDblCorba = createCorbaFieldDouble(familycorba,fieldVectDblLoc)
209 AnalyzeField(fieldVectDblCorba)
211 print "Generate a Local vector integer field"
212 fieldVectIntLoc = createLocalFieldInt(nbOfComp,lengthValue)
213 for k in range(lengthValue):
215 for kcomp in range(nbOfComp):
216 valueI.append(randint(0,100))
217 fieldVectIntLoc.setValueI(MED_FULL_INTERLACE,k+1,valueI)
218 valueIverif = fieldVectIntLoc.getValueI(MED_FULL_INTERLACE,k+1)
219 print " Set/Get Entry *",(k+1)," ",valueI[:nbOfComp]," / ",valueIverif[:nbOfComp]
220 print "Generate a Corba vector integer field"
221 fieldVectIntCorba = createCorbaFieldInt(familycorba,fieldVectIntLoc)
222 AnalyzeField(fieldVectIntCorba)
224 print "Fin du script Python ...."