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
23 # Instruct Python to load dynamic libraries using global resolution of symbols
24 # This is necessary to ensure that different modules will have the same definition
25 # of dynamic types and C++ RTTI will work between them
28 sys.setdlopenflags(DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL)
30 import PYCALCULATOR_ORB__POA
31 import SALOME_ComponentPy
34 from libMEDMEM_Swig import *
35 from libMedCorba_Swig import *
36 from libMEDClient import *
38 class PYCALCULATOR (PYCALCULATOR_ORB__POA.PYCALCULATOR_Gen, SALOME_ComponentPy.SALOME_ComponentPy_i ):
40 def __init__(self, orb, poa, contID, containerName, instanceName,
42 print "Begin of PYCALCULATOR::__init__"
44 SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
45 contID, containerName, instanceName, interfaceName, notif)
46 self._naming_service=SALOME_ComponentPy.SALOME_NamingServicePy_i(self._orb)
47 print "End of PYCALCULATOR::__init__"
49 def Add(self, field1, field2):
50 print "Begin of PYCALCULATOR::Add"
51 print "pointeur on first argument : ",field1
52 print " second : ",field2
55 nbOfComp1 = field1.getNumberOfComponents()
56 name1 = field1.getName()
57 description1 = field1.getDescription()
59 nbOfComp2 = field2.getNumberOfComponents()
60 name2 = field2.getName()
61 description2 = field2.getDescription()
63 if (nbOfComp1 != nbOfComp2): bool = 0
67 for k in range(nbOfComp1):
69 compName.append(field1.getComponentName(kp1))
70 compUnit.append(field1.getComponentUnit(kp1))
72 if ((compName[k] != field2.getComponentName(kp1)) or (compUnit[k] != field2.getComponentUnit(kp1))):
75 support1 = field1.getSupport()
76 entity1 = support1.getEntity()
77 mesh1 = support1.getMesh()
79 support2 = field2.getSupport()
80 entity2 = support2.getEntity()
81 mesh2 = support2.getMesh()
83 if (support1.isOnAllElements()):
84 lengthValue1 = mesh1.getNumberOfElements(entity1,SALOME_MED.MED_ALL_ELEMENTS)
86 for k in range(lengthValue1):
89 lengthValue1 = support1.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
90 number1 = support1.getNumber(SALOME_MED.MED_ALL_ELEMENTS)
92 if (support2.isOnAllElements()):
93 lengthValue2 = mesh2.getNumberOfElements(entity2,SALOME_MED.MED_ALL_ELEMENTS)
95 for k in range(lengthValue2):
98 lengthValue2 = support2.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
99 number2 = support2.getNumber(SALOME_MED.MED_ALL_ELEMENTS)
101 # comparision of each support: due to the fact that they are CORBA
102 # pointers, the comparision will be done directly throught the numbers
105 if ((lengthValue1 != lengthValue2) or (entity1 != entity2)):
109 for k in range(lengthValue1):
110 if (number1[k] != number2[k]):
113 value1 = field1.getValue(SALOME_MED.MED_FULL_INTERLACE)
117 value2 = field2.getValue(SALOME_MED.MED_FULL_INTERLACE)
121 print "CALCULATORPY::Add : The fields have the same support, they then can be added"
122 for k in range(lengthValue1*nbOfComp1):
123 valueOut.append((value1[k]+value2[k]))
125 print "CALCULATORPY::Add : WARNING !! For some reason the fields have not the same support"
126 for k in range(lengthValue1*nbOfComp1):
127 valueOut.append(value1[k])
129 supportOutLocal = SUPPORTClient( support1 )
130 supportOutCorba = createCorbaSupport( supportOutLocal )
132 print "CALCULATORPY::Add : Creation of the local field, nbOfComp = ",nbOfComp1, " length = ",lengthValue1
134 fieldOutLocal = createLocalFieldDouble(nbOfComp1,lengthValue1)
135 fieldOutLocal.setValue(valueOut)
136 fieldOutLocal.setName("-new_Add_Field-")
137 fieldOutLocal.setDescription(description1)
138 fieldOutLocal.setSupport( supportOutLocal )
140 for k in range(nbOfComp1):
142 fieldOutLocal.setComponentName(kp1,compName[k])
143 fieldOutLocal.setMEDComponentUnit(kp1,compUnit[k])
145 print "CALCULATORPY::Add : Creation of the CORBA field"
147 fieldOutCorba = createCorbaFieldDouble(supportOutCorba,fieldOutLocal)
149 print "End of CALCULATORPY::Add"
152 def Mul(self, field1, x1):
153 print "Begin of CALCULATORPY::Mul"
154 print "pointeur on first argument : ",field1
155 print " second : ",x1
157 nbOfComp = field1.getNumberOfComponents()
158 name = field1.getName()
159 description = field1.getDescription()
160 support = field1.getSupport()
161 print ".... get Names and Unit"
164 for k in range(nbOfComp):
166 compName.append(field1.getComponentName(kp1))
167 compUnit.append(field1.getComponentUnit(kp1))
170 print ".... get mesh"
171 mesh = support.getMesh()
173 if (support.isOnAllElements()):
174 lengthValue = mesh.getNumberOfElements(support.getEntity(),SALOME_MED.MED_ALL_ELEMENTS)
176 lengthValue = support.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
178 value1 = field1.getValue(SALOME_MED.MED_FULL_INTERLACE)
180 for k in range(lengthValue*nbOfComp):
181 valueOut.append(x1*value1[k])
183 supportOutLocal = SUPPORTClient( support )
184 supportOutCorba = createCorbaSupport( supportOutLocal )
186 print "CALCULATORPY::Mul : Creation of the local field, nbOfComp = ",nbOfComp, " length = ",lengthValue
188 fieldOutLocal = createLocalFieldDouble(nbOfComp,lengthValue)
189 fieldOutLocal.setValue(valueOut)
190 fieldOutLocal.setName("-new_Mul_Field-")
191 fieldOutLocal.setDescription(description)
192 fieldOutLocal.setSupport( supportOutLocal )
194 for k in range(nbOfComp):
196 fieldOutLocal.setComponentName(kp1,compName[k])
197 fieldOutLocal.setMEDComponentUnit(kp1,compUnit[k])
199 print "CALCULATORPY::Mul : Creation of the CORBA field"
201 fieldOutCorba = createCorbaFieldDouble(supportOutCorba,fieldOutLocal)
203 print "End of CALCULATORPY::Mul"
206 def Constant(self, field1, x1):
207 print "Begin of CALCULATORPY::Constant"
208 print "pointeur on first argument : ",field1
209 print " second : ",x1
211 nbOfComp = field1.getNumberOfComponents()
212 name = field1.getName()
213 description = field1.getDescription()
214 support = field1.getSupport()
217 for k in range(nbOfComp):
219 compName.append(field1.getComponentName(kp1))
220 compUnit.append(field1.getComponentUnit(kp1))
222 mesh = support.getMesh()
224 if (support.isOnAllElements()):
225 lengthValue = mesh.getNumberOfElements(support.getEntity(),SALOME_MED.MED_ALL_ELEMENTS)
227 lengthValue = support.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
230 for k in range(lengthValue*nbOfComp):
233 print "CALCULATORPY::Constant : Creation of the local field, nbOfComp = ",nbOfComp, " length = ",lengthValue
235 supportOutLocal = SUPPORTClient( support )
236 supportOutCorba = createCorbaSupport( supportOutLocal )
238 fieldOutLocal = createLocalFieldDouble(nbOfComp,lengthValue)
239 fieldOutLocal.setValue(valueOut)
240 fieldOutLocal.setName("-new_Const_Field-")
241 fieldOutLocal.setDescription(description)
242 fieldOutLocal.setSupport( supportOutLocal )
244 for k in range(nbOfComp):
246 fieldOutLocal.setComponentName(kp1,compName[k])
247 fieldOutLocal.setMEDComponentUnit(kp1,compUnit[k])
249 print "CALCULATORPY::Constant : Creation of the CORBA field"
251 fieldOutCorba = createCorbaFieldDouble(supportOutCorba,fieldOutLocal)
253 print "End of CALCULATORPY::Constant"
256 def writeMEDfile(self, field1, fileName):
257 print "Begin of CALCULATORPY::writeMEDfile"
258 print "CALCULATORPY::writeMEDfile : pointeur on first argument : ",field1
259 print " second : ",fileName
260 print "CALCULATORPY::writeMEDfile : NOT YET IMPLEMENTED"
261 print "End of CALCULATORPY::writeMEDfile"