1 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 import PYCALCULATOR_ORB
29 #==============================================================================
31 def AnalyzeField(field):
32 name = field.getName()
33 desc = field.getDescription()
34 nbComp = field.getNumberOfComponents()
35 itNum = field.getIterationNumber()
36 ordNum = field.getOrderNumber()
38 print "Analysis of the field ",name," with the description ",desc
39 print "iteration number ",itNum," order Number ",ordNum
40 print "It has ",nbComp," component(s)"
42 fieldValue = field.getValue(SALOME_MED.MED_FULL_INTERLACE)
43 fieldSupport = field.getSupport()
44 fieldMesh = fieldSupport.getMesh()
45 fieldEntity = fieldSupport.getEntity()
46 bool = fieldSupport.isOnAllElements()
49 print "The support of this field is on all entities ",fieldEntity," of the mesh ",fieldMesh.getName()
50 if fieldEntity == SALOME_MED.MED_NODE:
51 nbValByComp = fieldMesh.getNumberOfNodes()
53 nbValByComp = fieldMesh.getNumberOfElements(fieldEntity,SALOME_MED.MED_ALL_ELEMENTS)
54 print "and its dimension (number of values by component of the field) is ",nbValByComp
56 print "The support of this field is partially on entities ",fieldEntity," of the mesh ",fieldMesh.getName()
57 nbValByComp = fieldSupport.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
58 print "and its dimension (number of values by component of the field) is ",nbValByComp
60 for i in range(nbComp):
61 compName = field.getComponentName(i+1)
62 compUnit = field.getComponentUnit(i+1)
63 print "The ",(i+1),"-th component ",compName," with the unit ",compUnit
65 for i in range(nbValByComp):
66 print " * ",fieldValue[i*nbComp:(i+1)*nbComp]
68 #==============================================================================
70 def getFieldIntObjectFromStudy(number,subnumber):
71 mySO = salome.myStudy.FindObject("MEDFIELD")
72 mysub = mySO.FindSubObject(number)[1]
74 mysubsub = mysub.FindSubObject(subnumber)[1]
76 Builder = salome.myStudy.NewBuilder()
77 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
78 obj = salome.orb.string_to_object(anAttr.Value())
79 myObj = obj._narrow(SALOME_MED.FIELDINT)
82 print "ERROR: No FieldInt Object stored in this Study"
85 print "ERROR: No FieldInt Object stored in this Study"
88 #==============================================================================
90 def getFieldDoubleObjectFromStudy(number,subnumber):
91 mySO = salome.myStudy.FindObject("MEDFIELD")
92 mysub = mySO.FindSubObject(number)[1]
94 mysubsub = mysub.FindSubObject(subnumber)[1]
96 Builder = salome.myStudy.NewBuilder()
97 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
98 obj = salome.orb.string_to_object(anAttr.Value())
99 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
102 print "ERROR: No FieldDouble Object stored in this Study"
105 print "ERROR: No FieldDouble Object stored in this Study"
108 #==============================================================================
110 studyname = salome.myStudyName
111 studynameId = salome.myStudyId
113 print "We are working in the study ",studyname," with the ID ",studynameId
116 filePath=os.environ["MED_ROOT_DIR"]
117 filePath=filePath+"/share/salome/resources/med/"
118 medFile=filePath+"pointe.med"
119 fieldname = "fieldcelldoublevector"
121 print "Load the Med Component "
122 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
125 fieldcell = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
126 except SALOME.SALOME_Exception, ex:
128 print ex.details.type
129 print ex.details.text
130 print ex.details.sourceFile
131 print ex.details.lineNumber
135 print fieldcell.getName()
136 print fieldcell.getDescription()
137 print fieldcell.getNumberOfComponents()
140 AnalyzeField(fieldcell)
144 print "Loading of the CalculatorPy Component "
145 calculator = salome.lcc.FindOrLoadComponent("FactoryServerPy", "PYCALCULATOR")
146 print "calculator = ", calculator
149 print "Multiplication of fieldcelldouble by alpha"
150 fieldcellalpha = calculator.Mul(fieldcell,alpha)
152 AnalyzeField(fieldcellalpha)
154 print "Adding of alpha*fieldcelldouble and fieldcelldouble"
155 fieldcelladd = calculator.Add(fieldcell,fieldcellalpha)
157 AnalyzeField(fieldcelladd)
159 print "Put fieldcelladd in study"
160 fieldcelladd.addInStudy(salome.myStudy,fieldcelladd)
162 print "update Salome GUI"
163 salome.sg.updateObjBrowser(1)
165 print "Get back Field from study"
166 # we grab the second field in MEDFIELD - first iteration
167 fieldcelldouble = getFieldDoubleObjectFromStudy(1,1)
168 print fieldcelldouble
169 AnalyzeField(fieldcelldouble)
172 print "Fin du test PYCALCULATOR"