Salome HOME
Update tests
[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 import os
24
25 import MED_ORB
26 import CALCULATOR_ORB
27
28 import salome
29
30 from MEDCoupling import *
31 from MEDLoader import *
32 from MEDCouplingCorba import *
33 from MEDCouplingClient import *
34
35 # This test program is based on the field named fieldcelldoublevector in 
36 # med file ${DATA_DIR}/MedFiles/pointe.med
37 medFile = os.path.join(os.environ["DATA_DIR"], "MedFiles", "pointe.med")
38 meshName = "maa1"
39 fieldName = "fieldcelldoublevector"
40
41 # init SALOME session
42 salome.salome_init()
43
44 # Get MED component
45 print "[CALC] Get reference to MED component ..."
46 med = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
47 print "[CALC] ---"
48
49 # Get CALCULATOR component
50 print "[CALC] Get reference to CALCULATOR component ..."
51 calculator = salome.lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
52 print "[CALC] ---"
53
54 # Get a CORBA field proxy on the distant field (located in the med server)
55 print "[CALC] Read field %s ..." % fieldName
56 f = ReadFieldCell(medFile, meshName, 0, fieldName, -1, -1)
57 fieldcelldouble = MEDCouplingFieldDoubleServant._this(f)
58
59 print "[CALC] -> fieldcelldouble is:"
60 print f
61 print f.getName()
62 print f.getDescription()
63 print f.getNumberOfComponents()
64 print "[CALC] ---"
65
66 print "[CALC] Clone field: fieldcelldoublevector -> f1,f2,f3,f4 ..."
67 (f1,f2,f3,f4) = calculator.cloneField(fieldcelldouble)
68 print "[CALC] -> f1 is:"
69 calculator.printField(f1)
70 print "[CALC] ---"
71
72 print "[CALC] Add fields f2+f3 ..."
73 f_add = calculator.add(f2, f3)
74 print "[CALC] -> f_add is:"
75 calculator.printField(f_add)
76 print "[CALC] ---"
77
78 print "[CALC] Apply linear function to f4 ..."
79 f_lin = calculator.applyLin(f4, 2.0, 1.0)
80 print "[CALC] -> f_add is:"
81 calculator.printField(f_lin)
82 print "[CALC] ---"
83
84 print "[CALC] Apply Norm Max to f_lin ..."
85 norm = calculator.normMax(f_lin)
86 print "[CALC] -> norm is ", norm
87 print "[CALC] ---"
88
89 print "[CALC] Clone fields created by Calculator via client classes ..."
90 f_addLocal = MEDCouplingFieldDoubleClient.New(f_add)
91 f_addLocal.setName(f_addLocal.getName() + "add")
92 f_linLocal = MEDCouplingFieldDoubleClient.New(f_lin)
93 f_linLocal.setName(f_linLocal.getName() + "lin")
94 print "[CALC] -> f_addLocal is ", f_addLocal
95 print "[CALC] -> f_linLocal is ", f_linLocal
96 print "[CALC] ---"
97
98 print "[CALC] Get information from the local copy of the distant mesh"
99 meshLocal = f_addLocal.getMesh()
100 print "[CALC] -> meshLocal is", meshLocal
101 print "[CALC] ---"
102
103 print "[CALC] Write mesh and fields to MED file ..."
104 import tempfile
105 outfile = tempfile.NamedTemporaryFile(prefix="Calculator_pointe_", suffix=".med")
106 outfile.close()
107 WriteUMesh(outfile.name, meshLocal, True)
108 WriteFieldUsingAlreadyWrittenMesh(outfile.name, f_addLocal)
109 WriteFieldUsingAlreadyWrittenMesh(outfile.name, f_linLocal)
110 os.remove(outfile.name)
111 print "[CALC] ---"
112
113 print "[CALC] End of Calculator Test!"