Salome HOME
2db10cf5c73557fc8721b09e10c5c8a33711147a
[samples/calculator.git] / src / CALCULATOR / CALCULATOR_TEST.py
1 # Copyright (C) 2007-2015  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, or (at your option) any later version.
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 import os
37 host = os.getenv( 'HOST' )
38 orb, lcc, naming_service, contmgr = salome.salome_kernel.salome_kernel_init()
39
40 ################   GET A MED FIELD FROM FILE pointe.med   ###################
41 #
42 # This test program is based on the field named fieldcelldoublevector in 
43 # med file $MED_ROOT_DIR/share/salome/resources/pointe.med
44 #filePath=os.environ["MED_ROOT_DIR"]
45 filePath=os.environ["DATA_DIR"]
46 #filePath=filePath+"/share/salome/resources/med/"
47 filePath=filePath+"/MedFiles/"
48 medFile=filePath+"pointe.med"
49 fieldname = "fieldcelldoublevector"
50 meshname = "maa1"
51
52 # Launch the Med Component and use it to load into memory the test field 
53 print "Launch the Med Component: "
54 med_comp = lcc.FindOrLoadComponent("FactoryServer", "MED")
55
56 # Get a Corba field proxy on the distant field (located in the med_comp server).
57 try:
58     #TODO
59     #Manager = obj._narrow(SALOMEDS.StudyManager)
60     #print "studyManager found"
61     #myStudy = myStudyManager.NewStudy('CALCULATOR_TEST')
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     
67     f = MEDLoader.ReadFieldCell(medFile,meshname,0,fieldname,-1,-1)
68     fieldcelldouble=MEDCouplingFieldDoubleServant._this(f)
69 except SALOME.SALOME_Exception, ex:
70     print ex.details
71     print ex.details.type
72     print ex.details.text
73     print ex.details.sourceFile
74     print ex.details.lineNumber
75     raise
76
77 print "Description of Field : "
78 print f
79 print f.getName()
80 print f.getDescription()
81 print f.getNumberOfComponents()
82
83 #
84 #
85 ##############  Load Calculator Component ###################
86 # Calculator Component must be in the Container of MED
87 #
88 print "Load Calculator Component "
89 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
90 import CALCULATOR_ORB
91 calculator = lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
92
93 #
94 #
95 ##############  Test Calculator Component ###################
96 #
97 #
98 print "Appel cloneField : fieldcelldoublevector -> f1,f2,f3,f4"
99 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble)  # fieldcelldouble is consumed
100 #
101 f1.Register()
102 calculator.printField(f1)
103 print "Add fields f2+f3"
104 f_add=calculator.add(f2, f3)
105 f_add.Register()
106 calculator.printField( f_add ) # f_add is consumed
107
108 #
109 print "Apply linear function"
110 f_lin=calculator.applyLin(f4,2.0,1.0)
111 f_lin.Register()
112 calculator.printField( f_lin ) # f_lin is consumed
113 #
114 print "Appel Norme Max "
115 f_lin.Register()
116 norme=calculator.normMax(f_lin) # f_lin is consumed
117 print " -> norme = ",norme
118 #
119
120 print "End of Calculator Test!"