4 import PYCALCULATOR_ORB
7 #==============================================================================
9 def AnalyzeField(field):
10 name = field.getName()
11 desc = field.getDescription()
12 nbComp = field.getNumberOfComponents()
13 itNum = field.getIterationNumber()
14 ordNum = field.getOrderNumber()
16 print "Analysis of the field ",name," with the description ",desc
17 print "iteration number ",itNum," order Number ",ordNum
18 print "It has ",nbComp," component(s)"
20 fieldValue = field.getValue(SALOME_MED.MED_FULL_INTERLACE)
21 fieldSupport = field.getSupport()
22 fieldMesh = fieldSupport.getMesh()
23 fieldEntity = fieldSupport.getEntity()
24 bool = fieldSupport.isOnAllElements()
27 print "The support of this field is on all entities ",fieldEntity," of the mesh ",fieldMesh.getName()
28 if fieldEntity == SALOME_MED.MED_NODE:
29 nbValByComp = fieldMesh.getNumberOfNodes()
31 nbValByComp = fieldMesh.getNumberOfElements(fieldEntity,SALOME_MED.MED_ALL_ELEMENTS)
32 print "and its dimension (number of values by component of the field) is ",nbValByComp
34 print "The support of this field is partially on entities ",fieldEntity," of the mesh ",fieldMesh.getName()
35 nbValByComp = fieldSupport.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
36 print "and its dimension (number of values by component of the field) is ",nbValByComp
38 for i in range(nbComp):
39 compName = field.getComponentName(i+1)
40 compUnit = field.getComponentUnit(i+1)
41 print "The ",(i+1),"-th component ",compName," with the unit ",compUnit
43 for i in range(nbValByComp):
44 print " * ",fieldValue[i*nbComp:(i+1)*nbComp]
46 #==============================================================================
48 def getFieldIntObjectFromStudy(number,subnumber):
49 mySO = salome.myStudy.FindObject("MEDFIELD")
50 mysub = mySO.FindSubObject(number)[1]
52 mysubsub = mysub.FindSubObject(subnumber)[1]
54 Builder = salome.myStudy.NewBuilder()
55 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
56 obj = salome.orb.string_to_object(anAttr.Value())
57 myObj = obj._narrow(SALOME_MED.FIELDINT)
60 print "ERROR: No FieldInt Object stored in this Study"
63 print "ERROR: No FieldInt Object stored in this Study"
66 #==============================================================================
68 def getFieldDoubleObjectFromStudy(number,subnumber):
69 mySO = salome.myStudy.FindObject("MEDFIELD")
70 mysub = mySO.FindSubObject(number)[1]
72 mysubsub = mysub.FindSubObject(subnumber)[1]
74 Builder = salome.myStudy.NewBuilder()
75 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
76 obj = salome.orb.string_to_object(anAttr.Value())
77 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
80 print "ERROR: No FieldDouble Object stored in this Study"
83 print "ERROR: No FieldDouble Object stored in this Study"
86 #==============================================================================
88 studyname = salome.myStudyName
89 studynameId = salome.myStudyId
91 print "We are working in the study ",studyname," with the ID ",studynameId
94 filePath=os.environ["MED_ROOT_DIR"]
95 filePath=filePath+"/share/salome/resources/"
96 medFile=filePath+"pointe.med"
97 fieldname = "fieldcelldouble"
99 print "Load the Med Component "
100 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
103 fieldcell = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
104 except SALOME.SALOME_Exception, ex:
106 print ex.details.type
107 print ex.details.text
108 print ex.details.sourceFile
109 print ex.details.lineNumber
113 print fieldcell.getName()
114 print fieldcell.getDescription()
115 print fieldcell.getNumberOfComponents()
118 AnalyzeField(fieldcell)
122 print "Loading of the CalculatorPy Component "
123 calculator = salome.lcc.FindOrLoadComponent("FactoryServerPy", "PYCALCULATOR")
124 print "calculator = "
128 print "Multiplication of fieldcelldouble by alpha"
129 fieldcellalpha = calculator.Mul(fieldcell,alpha)
131 AnalyzeField(fieldcellalpha)
133 print "Adding of alpha*fieldcelldouble and fieldcelldouble"
134 fieldcelladd = calculator.Add(fieldcell,fieldcellalpha)
136 AnalyzeField(fieldcelladd)
138 print "Put fieldcelladd in study"
139 fieldcelladd.addInStudy(salome.myStudy,fieldcelladd)
141 print "update Salome GUI"
142 salome.sg.updateObjBrowser(1)
144 print "Get back Field from study"
145 # we grab the second field in MEDFIELD - first iteration
146 fieldcelldouble = getFieldDoubleObjectFromStudy(2,1)
147 print fieldcelldouble
148 AnalyzeField(fieldcelldouble)
151 print "Fin du test PYCALCULATOR"