1 # Copyright (C) 2007-2015 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, or (at your option) any later version.
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 #CALCULATOR_TEST_WITHOUTIHM.py
25 from omniORB import CORBA
32 from MEDCouplingCorba import *
33 from MEDCoupling import *
34 from MEDLoader import *
38 host = os.getenv( 'HOST' )
39 orb, lcc, naming_service, contmgr = salome.salome_kernel.salome_kernel_init()
41 ################ GET A MED FIELD FROM FILE pointe.med ###################
43 # This test program is based on the field named fieldcelldoublevector in
44 # med file $MED_ROOT_DIR/share/salome/resources/med/pointe.med
45 #filePath=os.environ["MED_ROOT_DIR"]
46 filePath=os.environ["DATA_DIR"]
47 filePath=filePath+"/MedFiles/"
48 #filePath=filePath+"/share/salome/resources/med/"
49 medFile=filePath+"pointe.med"
50 fieldname = "fieldcelldoublevector"
53 # Launch the Med Component and use it to load into memory the test field
54 print "Launch the Med Component: "
55 med_comp = lcc.FindOrLoadComponent("FactoryServer", "MED")
57 # Get a Corba field proxy on the distant field (located in the med_comp server).
60 #obj = naming_service.Resolve('myStudyManager')
61 #myStudyManager = obj._narrow(SALOMEDS.StudyManager)
62 #print "studyManager found"
63 #myStudy = myStudyManager.NewStudy('CALCULATOR_TEST_WITHOUTIHM')
64 #studynameId = myStudy._get_StudyId()
65 #studyname = myStudy._get_Name()
66 #print "We are working in the study ",studyname," with the ID ",studynameId
67 print "Read field ",fieldname
68 f = MEDLoader.ReadFieldCell(medFile,meshname,0,fieldname,-1,-1)
69 fieldcelldouble=MEDCouplingFieldDoubleServant._this(f)
70 except SALOME.SALOME_Exception, ex:
74 print ex.details.sourceFile
75 print ex.details.lineNumber
78 print "Description of Field : "
81 print f.getDescription()
82 print f.getNumberOfComponents()
86 ############## Load Calculator Component ###################
87 # Calculator Component must be in the Container of MED
89 print "Load Calculator Component "
90 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
92 calculator = lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
96 ############## Test Calculator Component ###################
99 print "Appel cloneField : fieldcelldoublevector -> f1,f2,f3,f4"
100 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble) # fieldcelldouble is consumed
103 ##calculator.printField(f1)
104 print "Add fields f2+f3"
105 f_add=calculator.add(f2, f3)
107 ##calculator.printField( f_add ) # f_add is consumed
110 print "Apply linear function"
111 f_lin=calculator.applyLin(f4,2.0,1.0)
113 ##calculator.printField( f_lin ) # f_lin is consumed
115 print "Appel Norme Max "
117 norme=calculator.normMax(f_lin) # f_lin is consumed
118 print " -> norme = ",norme
123 ############ Creation of a MED file with fields created by Caculator #################
126 #from libMEDClient import *
127 from MEDCouplingClient import *
128 import MEDCouplingCorbaServant_idl
130 f_addLocal=MEDCouplingFieldDoubleClient.New(f_add)
131 f_addLocal.setName(f_addLocal.getName()+"add")
134 f_linLocal=MEDCouplingFieldDoubleClient.New(f_lin)
135 f_linLocal.setName(f_linLocal.getName()+"lin")
140 OutmedFile22="Calculatorpointe_V22.med"
141 #os.system( 'rm -fr ' + OutmedFile22 )
142 MEDLoader.WriteField(OutmedFile22,f_addLocal,True)
143 MEDLoader.WriteFieldUsingAlreadyWrittenMesh(OutmedFile22,f_linLocal)
146 print "End of Calculator Test!"