1 # Copyright (C) 2007-2016 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
30 from MEDCoupling import *
31 from MEDLoader import *
32 from MEDCouplingCorba import *
33 from MEDCouplingClient import *
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")
39 fieldName = "fieldcelldoublevector"
45 print "[CALC] Get reference to MED component ..."
46 med = salome.lcc.FindOrLoadComponent("FactoryServer", "MED")
49 # Get CALCULATOR component
50 print "[CALC] Get reference to CALCULATOR component ..."
51 calculator = salome.lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
54 # Get a CORBA field proxy on the distant field (located in the med server)
55 print "[CALC] Read field %s ..." % fieldName
56 f = MEDLoader.ReadFieldCell(medFile, meshName, 0, fieldName, -1, -1)
57 fieldcelldouble = MEDCouplingFieldDoubleServant._this(f)
59 print "[CALC] -> fieldcelldouble is:"
62 print f.getDescription()
63 print f.getNumberOfComponents()
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)
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)
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)
84 print "[CALC] Apply Norm Max to f_lin ..."
85 norm = calculator.normMax(f_lin)
86 print "[CALC] -> norm is ", norm
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
98 print "[CALC] Get information from the local copy of the distant mesh"
99 meshLocal = f_addLocal.getMesh()
100 print "[CALC] -> meshLocal is", meshLocal
103 print "[CALC] Write mesh and fields to MED file ..."
105 outfile = tempfile.NamedTemporaryFile(prefix="Calculator_pointe_", suffix=".med")
107 MEDLoader.WriteUMesh(outfile.name, meshLocal, True)
108 MEDLoader.WriteFieldUsingAlreadyWrittenMesh(outfile.name, f_addLocal)
109 MEDLoader.WriteFieldUsingAlreadyWrittenMesh(outfile.name, f_linLocal)
110 os.remove(outfile.name)
113 print "[CALC] End of Calculator Test!"