1 # Copyright (C) 2007-2013 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 getVersion( self ):
51 return salome_version.getVersion("PYCALCULATOR", True)
53 def Add(self, field1, field2):
54 print "Begin of PYCALCULATOR::Add"
55 print "pointeur on first argument : ",field1
56 print " second : ",field2
59 nbOfComp1 = field1.getNumberOfComponents()
60 name1 = field1.getName()
61 description1 = field1.getDescription()
63 nbOfComp2 = field2.getNumberOfComponents()
64 name2 = field2.getName()
65 description2 = field2.getDescription()
67 if (nbOfComp1 != nbOfComp2): bool = 0
71 for k in range(nbOfComp1):
73 compName.append(field1.getComponentName(kp1))
74 compUnit.append(field1.getComponentUnit(kp1))
76 if ((compName[k] != field2.getComponentName(kp1)) or (compUnit[k] != field2.getComponentUnit(kp1))):
79 support1 = field1.getSupport()
80 entity1 = support1.getEntity()
81 mesh1 = support1.getMesh()
83 support2 = field2.getSupport()
84 entity2 = support2.getEntity()
85 mesh2 = support2.getMesh()
87 if (support1.isOnAllElements()):
88 lengthValue1 = mesh1.getNumberOfElements(entity1,SALOME_MED.MED_ALL_ELEMENTS)
90 for k in range(lengthValue1):
93 lengthValue1 = support1.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
94 number1 = support1.getNumber(SALOME_MED.MED_ALL_ELEMENTS)
96 if (support2.isOnAllElements()):
97 lengthValue2 = mesh2.getNumberOfElements(entity2,SALOME_MED.MED_ALL_ELEMENTS)
99 for k in range(lengthValue2):
102 lengthValue2 = support2.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
103 number2 = support2.getNumber(SALOME_MED.MED_ALL_ELEMENTS)
105 # comparision of each support: due to the fact that they are CORBA
106 # pointers, the comparision will be done directly throught the numbers
109 if ((lengthValue1 != lengthValue2) or (entity1 != entity2)):
113 for k in range(lengthValue1):
114 if (number1[k] != number2[k]):
117 value1 = field1.getValue(SALOME_MED.MED_FULL_INTERLACE)
121 value2 = field2.getValue(SALOME_MED.MED_FULL_INTERLACE)
125 print "CALCULATORPY::Add : The fields have the same support, they then can be added"
126 for k in range(lengthValue1*nbOfComp1):
127 valueOut.append((value1[k]+value2[k]))
129 print "CALCULATORPY::Add : WARNING !! For some reason the fields have not the same support"
130 for k in range(lengthValue1*nbOfComp1):
131 valueOut.append(value1[k])
133 supportOutLocal = SUPPORTClient( support1 )
134 supportOutCorba = createCorbaSupport( supportOutLocal )
136 print "CALCULATORPY::Add : Creation of the local field, nbOfComp = ",nbOfComp1, " length = ",lengthValue1
138 fieldOutLocal = createLocalFieldDouble(nbOfComp1,lengthValue1)
139 fieldOutLocal.setValue(valueOut)
140 fieldOutLocal.setName("-new_Add_Field-")
141 fieldOutLocal.setDescription(description1)
142 fieldOutLocal.setSupport( supportOutLocal )
144 for k in range(nbOfComp1):
146 fieldOutLocal.setComponentName(kp1,compName[k])
147 fieldOutLocal.setMEDComponentUnit(kp1,compUnit[k])
149 print "CALCULATORPY::Add : Creation of the CORBA field"
151 fieldOutCorba = createCorbaFieldDouble(supportOutCorba,fieldOutLocal)
153 print "End of CALCULATORPY::Add"
156 def Mul(self, field1, x1):
157 print "Begin of CALCULATORPY::Mul"
158 print "pointeur on first argument : ",field1
159 print " second : ",x1
161 nbOfComp = field1.getNumberOfComponents()
162 name = field1.getName()
163 description = field1.getDescription()
164 support = field1.getSupport()
165 print ".... get Names and Unit"
168 for k in range(nbOfComp):
170 compName.append(field1.getComponentName(kp1))
171 compUnit.append(field1.getComponentUnit(kp1))
174 print ".... get mesh"
175 mesh = support.getMesh()
177 if (support.isOnAllElements()):
178 lengthValue = mesh.getNumberOfElements(support.getEntity(),SALOME_MED.MED_ALL_ELEMENTS)
180 lengthValue = support.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
182 value1 = field1.getValue(SALOME_MED.MED_FULL_INTERLACE)
184 for k in range(lengthValue*nbOfComp):
185 valueOut.append(x1*value1[k])
187 supportOutLocal = SUPPORTClient( support )
188 supportOutCorba = createCorbaSupport( supportOutLocal )
190 print "CALCULATORPY::Mul : Creation of the local field, nbOfComp = ",nbOfComp, " length = ",lengthValue
192 fieldOutLocal = createLocalFieldDouble(nbOfComp,lengthValue)
193 fieldOutLocal.setValue(valueOut)
194 fieldOutLocal.setName("-new_Mul_Field-")
195 fieldOutLocal.setDescription(description)
196 fieldOutLocal.setSupport( supportOutLocal )
198 for k in range(nbOfComp):
200 fieldOutLocal.setComponentName(kp1,compName[k])
201 fieldOutLocal.setMEDComponentUnit(kp1,compUnit[k])
203 print "CALCULATORPY::Mul : Creation of the CORBA field"
205 fieldOutCorba = createCorbaFieldDouble(supportOutCorba,fieldOutLocal)
207 print "End of CALCULATORPY::Mul"
210 def Constant(self, field1, x1):
211 print "Begin of CALCULATORPY::Constant"
212 print "pointeur on first argument : ",field1
213 print " second : ",x1
215 nbOfComp = field1.getNumberOfComponents()
216 name = field1.getName()
217 description = field1.getDescription()
218 support = field1.getSupport()
221 for k in range(nbOfComp):
223 compName.append(field1.getComponentName(kp1))
224 compUnit.append(field1.getComponentUnit(kp1))
226 mesh = support.getMesh()
228 if (support.isOnAllElements()):
229 lengthValue = mesh.getNumberOfElements(support.getEntity(),SALOME_MED.MED_ALL_ELEMENTS)
231 lengthValue = support.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS)
234 for k in range(lengthValue*nbOfComp):
237 print "CALCULATORPY::Constant : Creation of the local field, nbOfComp = ",nbOfComp, " length = ",lengthValue
239 supportOutLocal = SUPPORTClient( support )
240 supportOutCorba = createCorbaSupport( supportOutLocal )
242 fieldOutLocal = createLocalFieldDouble(nbOfComp,lengthValue)
243 fieldOutLocal.setValue(valueOut)
244 fieldOutLocal.setName("-new_Const_Field-")
245 fieldOutLocal.setDescription(description)
246 fieldOutLocal.setSupport( supportOutLocal )
248 for k in range(nbOfComp):
250 fieldOutLocal.setComponentName(kp1,compName[k])
251 fieldOutLocal.setMEDComponentUnit(kp1,compUnit[k])
253 print "CALCULATORPY::Constant : Creation of the CORBA field"
255 fieldOutCorba = createCorbaFieldDouble(supportOutCorba,fieldOutLocal)
257 print "End of CALCULATORPY::Constant"
260 def writeMEDfile(self, field1, fileName):
261 print "Begin of CALCULATORPY::writeMEDfile"
262 print "CALCULATORPY::writeMEDfile : pointeur on first argument : ",field1
263 print " second : ",fileName
264 print "CALCULATORPY::writeMEDfile : NOT YET IMPLEMENTED"
265 print "End of CALCULATORPY::writeMEDfile"