1 # Copyright (C) 2005 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 import PYCALCULATOR_ORB
25 #==============================================================================
27 def AnalyzeField(field):
28 name = field.getName()
29 desc = field.getDescription()
30 nbComp = field.getNumberOfComponents()
31 itNum = field.getIterationNumber()
32 ordNum = field.getOrderNumber()
34 print "Analysis of the field ",name," with the description ",desc
35 print "iteration number ",itNum," order Number ",ordNum
36 print "It has ",nbComp," component(s)"
38 fieldValue = field.getValue(SALOME_MED.MED_FULL_INTERLACE)
39 fieldSupport = field.getSupport()
40 fieldMesh = fieldSupport.getMesh()
41 fieldEntity = fieldSupport.getEntity()
42 bool = fieldSupport.isOnAllElements()
45 print "The support of this field is on all entities ",fieldEntity," of the mesh ",fieldMesh.getName()
46 if fieldEntity == SALOME_MED.MED_NODE:
47 nbValByComp = fieldMesh.getNumberOfNodes()
49 nbValByComp = fieldMesh.getNumberOfElements(fieldEntity,SALOME_MED.MED_ALL_ELEMENTS)
50 print "and its dimension (number of values by component of the field) is ",nbValByComp
52 print "The support of this field is partially on entities ",fieldEntity," of the mesh ",fieldMesh.getName()
53 nbValByComp = fieldSupport.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
54 print "and its dimension (number of values by component of the field) is ",nbValByComp
56 for i in range(nbComp):
57 compName = field.getComponentName(i+1)
58 compUnit = field.getComponentUnit(i+1)
59 print "The ",(i+1),"-th component ",compName," with the unit ",compUnit
61 for i in range(nbValByComp):
62 print " * ",fieldValue[i*nbComp:(i+1)*nbComp]
64 #==============================================================================
66 def getFieldIntObjectFromStudy(number,subnumber):
67 mySO = salome.myStudy.FindObject("MEDFIELD")
68 mysub = mySO.FindSubObject(number)[1]
70 mysubsub = mysub.FindSubObject(subnumber)[1]
72 Builder = salome.myStudy.NewBuilder()
73 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
74 obj = salome.orb.string_to_object(anAttr.Value())
75 myObj = obj._narrow(SALOME_MED.FIELDINT)
78 print "ERROR: No FieldInt Object stored in this Study"
81 print "ERROR: No FieldInt Object stored in this Study"
84 #==============================================================================
86 def getFieldDoubleObjectFromStudy(number,subnumber):
87 mySO = salome.myStudy.FindObject("MEDFIELD")
88 mysub = mySO.FindSubObject(number)[1]
90 mysubsub = mysub.FindSubObject(subnumber)[1]
92 Builder = salome.myStudy.NewBuilder()
93 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
94 obj = salome.orb.string_to_object(anAttr.Value())
95 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
98 print "ERROR: No FieldDouble Object stored in this Study"
101 print "ERROR: No FieldDouble Object stored in this Study"
104 #==============================================================================
106 studyname = salome.myStudyName
107 studynameId = salome.myStudyId
109 print "We are working in the study ",studyname," with the ID ",studynameId
112 filePath=os.environ["MED_ROOT_DIR"]
113 filePath=filePath+"/share/salome/resources/"
114 medFile=filePath+"pointe.med"
115 fieldname = "fieldcelldouble"
117 print "Load the Med Component "
118 med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
121 fieldcell = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
122 except SALOME.SALOME_Exception, ex:
124 print ex.details.type
125 print ex.details.text
126 print ex.details.sourceFile
127 print ex.details.lineNumber
131 print fieldcell.getName()
132 print fieldcell.getDescription()
133 print fieldcell.getNumberOfComponents()
136 AnalyzeField(fieldcell)
140 print "Loading of the CalculatorPy Component "
141 calculator = salome.lcc.FindOrLoadComponent("FactoryServerPy", "PYCALCULATOR")
142 print "calculator = "
146 print "Multiplication of fieldcelldouble by alpha"
147 fieldcellalpha = calculator.Mul(fieldcell,alpha)
149 AnalyzeField(fieldcellalpha)
151 print "Adding of alpha*fieldcelldouble and fieldcelldouble"
152 fieldcelladd = calculator.Add(fieldcell,fieldcellalpha)
154 AnalyzeField(fieldcelladd)
156 print "Put fieldcelladd in study"
157 fieldcelladd.addInStudy(salome.myStudy,fieldcelladd)
159 print "update Salome GUI"
160 salome.sg.updateObjBrowser(1)
162 print "Get back Field from study"
163 # we grab the second field in MEDFIELD - first iteration
164 fieldcelldouble = getFieldDoubleObjectFromStudy(2,1)
165 print fieldcelldouble
166 AnalyzeField(fieldcelldouble)
169 print "Fin du test PYCALCULATOR"