1 # Copyright (C) 2007-2008 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
25 import PYCALCULATOR_ORB
28 #==============================================================================
30 def AnalyzeField(field):
31 name = field.getName()
32 desc = field.getDescription()
33 nbComp = field.getNumberOfComponents()
34 itNum = field.getIterationNumber()
35 ordNum = field.getOrderNumber()
37 print "Analysis of the field ",name," with the description ",desc
38 print "iteration number ",itNum," order Number ",ordNum
39 print "It has ",nbComp," component(s)"
41 fieldValue = field.getValue(SALOME_MED.MED_FULL_INTERLACE)
42 fieldSupport = field.getSupport()
43 fieldMesh = fieldSupport.getMesh()
44 fieldEntity = fieldSupport.getEntity()
45 bool = fieldSupport.isOnAllElements()
48 print "The support of this field is on all entities ",fieldEntity," of the mesh ",fieldMesh.getName()
49 if fieldEntity == SALOME_MED.MED_NODE:
50 nbValByComp = fieldMesh.getNumberOfNodes()
52 nbValByComp = fieldMesh.getNumberOfElements(fieldEntity,SALOME_MED.MED_ALL_ELEMENTS)
53 print "and its dimension (number of values by component of the field) is ",nbValByComp
55 print "The support of this field is partially on entities ",fieldEntity," of the mesh ",fieldMesh.getName()
56 nbValByComp = fieldSupport.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
57 print "and its dimension (number of values by component of the field) is ",nbValByComp
59 for i in range(nbComp):
60 compName = field.getComponentName(i+1)
61 compUnit = field.getComponentUnit(i+1)
62 print "The ",(i+1),"-th component ",compName," with the unit ",compUnit
64 for i in range(nbValByComp):
65 print " * ",fieldValue[i*nbComp:(i+1)*nbComp]
67 #==============================================================================
69 def getFieldIntObjectFromStudy(number,subnumber):
70 mySO = salome.myStudy.FindObject("MEDFIELD")
71 mysub = mySO.FindSubObject(number)[1]
73 mysubsub = mysub.FindSubObject(subnumber)[1]
75 Builder = salome.myStudy.NewBuilder()
76 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
77 obj = salome.orb.string_to_object(anAttr.Value())
78 myObj = obj._narrow(SALOME_MED.FIELDINT)
81 print "ERROR: No FieldInt Object stored in this Study"
84 print "ERROR: No FieldInt Object stored in this Study"
87 #==============================================================================
89 def getFieldDoubleObjectFromStudy(number,subnumber):
90 mySO = salome.myStudy.FindObject("MEDFIELD")
91 mysub = mySO.FindSubObject(number)[1]
93 mysubsub = mysub.FindSubObject(subnumber)[1]
95 Builder = salome.myStudy.NewBuilder()
96 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
97 obj = salome.orb.string_to_object(anAttr.Value())
98 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
101 print "ERROR: No FieldDouble Object stored in this Study"
104 print "ERROR: No FieldDouble Object stored in this Study"
107 #==============================================================================
109 studyname = salome.myStudyName
110 studynameId = salome.myStudyId
112 print "We are working in the study ",studyname," with the ID ",studynameId
115 filePath=os.environ["MED_ROOT_DIR"]
116 filePath=filePath+"/share/salome/resources/med/"
117 medFile=filePath+"pointe.med"
118 fieldname = "fieldcelldouble"
120 print "Load the Med Component "
121 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
124 fieldcell = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
125 except SALOME.SALOME_Exception, ex:
127 print ex.details.type
128 print ex.details.text
129 print ex.details.sourceFile
130 print ex.details.lineNumber
134 print fieldcell.getName()
135 print fieldcell.getDescription()
136 print fieldcell.getNumberOfComponents()
139 AnalyzeField(fieldcell)
143 print "Loading of the CalculatorPy Component "
144 calculator = salome.lcc.FindOrLoadComponent("FactoryServerPy", "PYCALCULATOR")
145 print "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(2,1)
168 print fieldcelldouble
169 AnalyzeField(fieldcelldouble)
172 print "Fin du test PYCALCULATOR"