Salome HOME
29093ebe82c1f46ff9a2a602b6f073ab4748d97d
[samples/calculator.git] / src / CALCULATOR / CALCULATOR_TEST_WITHOUTIHM.py
1 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 #CALCULATOR_TEST_WITHOUTIHM.py
24 #
25 from omniORB import CORBA
26
27 import salome
28 import SALOME
29 import SALOME_MED
30 import SALOMEDS
31
32 from MEDCouplingCorba import *
33 from MEDCoupling import *
34 from MEDLoader import *
35
36
37 import os
38 host = os.getenv( 'HOST' )
39 orb, lcc, naming_service, contmgr = salome.salome_kernel.salome_kernel_init()
40
41 ################   GET A MED FIELD FROM FILE pointe.med   ###################
42 #
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=filePath+"/share/salome/resources/med/"
47 medFile=filePath+"pointe.med"
48 fieldname = "fieldcelldoublevector"
49 meshname = "maa1"
50
51 # Launch the Med Component and use it to load into memory the test field 
52 print "Launch the Med Component: "
53 med_comp = lcc.FindOrLoadComponent("FactoryServer", "MED")
54
55 # Get a Corba field proxy on the distant field (located in the med_comp server).
56 try:
57     #TODO
58     #obj = naming_service.Resolve('myStudyManager')
59     #myStudyManager = obj._narrow(SALOMEDS.StudyManager)
60     #print "studyManager found"
61     #myStudy = myStudyManager.NewStudy('CALCULATOR_TEST_WITHOUTIHM')
62     #studynameId = myStudy._get_StudyId()
63     #studyname = myStudy._get_Name()
64     #print "We are working in the study ",studyname," with the ID ",studynameId
65     print "Read field ",fieldname
66     f = MEDLoader.ReadFieldCell(medFile,meshname,0,fieldname,-1,-1)
67     fieldcelldouble=MEDCouplingFieldDoubleServant._this(f)
68 except SALOME.SALOME_Exception, ex:
69     print ex.details
70     print ex.details.type
71     print ex.details.text
72     print ex.details.sourceFile
73     print ex.details.lineNumber
74     raise
75
76 print "Description of Field : "
77 print f
78 print f.getName()
79 print f.getDescription()
80 print f.getNumberOfComponents()
81
82 #
83 #
84 ##############  Load Calculator Component ###################
85 # Calculator Component must be in the Container of MED
86 #
87 print "Load Calculator Component "
88 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
89 import CALCULATOR_ORB
90 calculator = lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
91
92 #
93 #
94 ##############  Test Calculator Component ###################
95 #
96 #
97 print "Appel cloneField : fieldcelldoublevector -> f1,f2,f3,f4"
98 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble)  # fieldcelldouble is consumed
99 #
100 ##f1.Register()
101 ##calculator.printField(f1)
102 print "Add fields f2+f3"
103 f_add=calculator.add(f2, f3)
104 ##f_add.Register()
105 ##calculator.printField( f_add ) # f_add is consumed
106
107 #
108 print "Apply linear function"
109 f_lin=calculator.applyLin(f4,2.0,1.0)
110 ##f_lin.Register()
111 ##calculator.printField( f_lin ) # f_lin is consumed
112 #
113 print "Appel Norme Max "
114 f_lin.Register()
115 norme=calculator.normMax(f_lin) # f_lin is consumed
116 print " -> norme = ",norme
117 #
118
119 #
120 #
121 ############  Creation of a MED file with fields created by Caculator  #################
122 #                   via Client classes
123 #
124 #from libMEDClient import *
125 from MEDCouplingClient import *
126 import MEDCouplingCorbaServant_idl
127
128 f_addLocal=MEDCouplingFieldDoubleClient.New(f_add)
129 f_addLocal.setName(f_addLocal.getName()+"add")
130 f_add.UnRegister()
131
132 f_linLocal=MEDCouplingFieldDoubleClient.New(f_lin)
133 f_linLocal.setName(f_linLocal.getName()+"lin")
134 f_lin.UnRegister()
135
136
137
138 OutmedFile22="Calculatorpointe_V22.med"
139 #os.system( 'rm -fr ' + OutmedFile22 )
140 MEDLoader.WriteField(OutmedFile22,f_addLocal,True)
141 MEDLoader.WriteFieldUsingAlreadyWrittenMesh(OutmedFile22,f_linLocal)
142
143
144 print "End of Calculator Test!"