Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[samples/calculator.git] / src / CALCULATOR / CALCULATOR_TEST_WITHOUTIHM.py
1
2 #CALCULATOR_TEST_WITHOUTIHM.py
3
4 from omniORB import CORBA
5
6 import salome
7 import SALOME
8 import SALOME_MED
9 import SALOMEDS
10
11 import os
12 host = os.getenv( 'HOST' )
13 orb, lcc, naming_service, contmgr = salome.salome_kernel.salome_kernel_init()
14
15 ################   GET A MED FIELD FROM FILE pointe.med   ###################
16 #
17 # This test program is based on the field named fieldcelldoublevector in 
18 # med file $MED_ROOT_DIR/share/salome/resources/med/pointe.med
19 filePath=os.environ["MED_ROOT_DIR"]
20 filePath=filePath+"/share/salome/resources/med/"
21 medFile=filePath+"pointe.med"
22 fieldname = "fieldcelldoublevector"
23
24 # Launch the Med Component and use it to load into memory the test field 
25 print "Launch the Med Component: "
26 med_comp = lcc.FindOrLoadComponent("FactoryServer", "MED")
27
28 # Get a Corba field proxy on the distant field (located in the med_comp server).
29 try:
30     obj = naming_service.Resolve('myStudyManager')
31     myStudyManager = obj._narrow(SALOMEDS.StudyManager)
32     print "studyManager found"
33     myStudy = myStudyManager.NewStudy('CALCULATOR_TEST_WITHOUTIHM')
34     studynameId = myStudy._get_StudyId()
35     studyname = myStudy._get_Name()
36     print "We are working in the study ",studyname," with the ID ",studynameId
37     print "Read field ",fieldname
38     fieldcell  = med_comp.readFieldInFile(medFile,studyname,fieldname,-1,-1)
39     fieldcelldouble = fieldcell._narrow(SALOME_MED.FIELDDOUBLE)
40 except SALOME.SALOME_Exception, ex:
41     print ex.details
42     print ex.details.type
43     print ex.details.text
44     print ex.details.sourceFile
45     print ex.details.lineNumber
46     raise
47
48 print "Description of Field : "
49 print fieldcelldouble
50 print fieldcelldouble.getName()
51 print fieldcelldouble.getDescription()
52 print fieldcelldouble.getNumberOfComponents()
53
54 #
55 #
56 ##############  Load Calculator Component ###################
57 # Calculator Component must be in the Container of MED
58 #
59 print "Load Calculator Component "
60 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
61 import CALCULATOR_ORB
62 calculator = lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
63
64 #
65 #
66 ##############  Test Calculator Component ###################
67 #
68 #
69 print "Appel cloneField : fieldcelldoublevector -> f1,f2,f3,f4"
70 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble)  # fieldcelldouble is consumed
71 #
72 ##f1.Register()
73 ##calculator.printField(f1)
74 print "Add fields f2+f3"
75 f_add=calculator.add(f2, f3)
76 ##f_add.Register()
77 ##calculator.printField( f_add ) # f_add is consumed
78
79 #
80 print "Apply linear function"
81 f_lin=calculator.applyLin(f4,2.0,1.0)
82 ##f_lin.Register()
83 ##calculator.printField( f_lin ) # f_lin is consumed
84 #
85 print "Appel Norme Max "
86 f_lin.Register()
87 norme=calculator.normMax(f_lin) # f_lin is consumed
88 print " -> norme = ",norme
89 #
90
91 #
92 #
93 ############  Creation of a MED file with fields created by Caculator  #################
94 #                   via Client classes
95 #
96 from libMEDClient import *
97
98 meshDistant = f_add.getSupport().getMesh()
99
100 meshLocal = MESHClient(meshDistant)
101
102 f_addLocal = FIELDDOUBLEClient(f_add)
103
104 f_addLocal.setName(f_addLocal.getName()+"add")
105
106 f_linLocal = FIELDDOUBLEClient(f_lin)
107
108 f_linLocal.setName(f_linLocal.getName()+"lin")
109
110 # med file with 2.1 format
111 OutmedFile21="Calculatorpointe_V21.med"
112 os.system( 'rm -fr ' + OutmedFile21 )
113
114 medFileVersion = getMedFileVersionForWriting()
115 if (medFileVersion == V22):
116     print "setMedFileVersionForWriting(V21)"
117     setMedFileVersionForWriting(V21)
118
119 # writting the mesh
120 print "meshLocal.write :"
121 idMed = meshLocal.addDriver(MED_DRIVER, OutmedFile21, meshLocal.getName(), MED_REMP)
122 meshLocal.write(idMed)
123
124 # writting the 2 fields
125 print "f_addLocal.write :"
126 idMed = f_addLocal.addDriver(MED_DRIVER, OutmedFile21, f_addLocal.getName())
127 f_addLocal.write(idMed)
128
129 print "f_linLocal.write :"
130 idMed = f_linLocal.addDriver(MED_DRIVER, OutmedFile21, f_linLocal.getName())
131 f_linLocal.write(idMed)
132
133 # med file with 2.2 format
134 OutmedFile22="Calculatorpointe_V22.med"
135 os.system( 'rm -fr ' + OutmedFile22 )
136
137 medFileVersion = getMedFileVersionForWriting()
138 if (medFileVersion == V21):
139     print "setMedFileVersionForWriting(V22)"
140     setMedFileVersionForWriting(V22)
141
142 # writting the mesh
143 print "meshLocal.write :"
144 idMed = meshLocal.addDriver(MED_DRIVER, OutmedFile22, meshLocal.getName(), MED_REMP)
145 meshLocal.write(idMed)
146
147 # writting the 2 fields
148 print "f_addLocal.write :"
149 idMed = f_addLocal.addDriver(MED_DRIVER, OutmedFile22, f_addLocal.getName())
150 f_addLocal.write(idMed)
151
152 print "f_linLocal.write :"
153 idMed = f_linLocal.addDriver(MED_DRIVER, OutmedFile22, f_linLocal.getName())
154 f_linLocal.write(idMed)
155
156 print "End of Calculator Test!"