2 #CALCULATOR_TEST_WITHOUTIHM.py
4 from omniORB import CORBA
12 host = os.getenv( 'HOST' )
13 orb, lcc, naming_service, contmgr = salome.salome_kernel.salome_kernel_init()
15 ################ GET A MED FIELD FROM FILE pointe.med ###################
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"
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")
28 # Get a Corba field proxy on the distant field (located in the med_comp server).
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:
44 print ex.details.sourceFile
45 print ex.details.lineNumber
48 print "Description of Field : "
50 print fieldcelldouble.getName()
51 print fieldcelldouble.getDescription()
52 print fieldcelldouble.getNumberOfComponents()
56 ############## Load Calculator Component ###################
57 # Calculator Component must be in the Container of MED
59 print "Load Calculator Component "
60 # we need to import CALCULATOR_ORB to get a typed object (to perform narrowing)
62 calculator = lcc.FindOrLoadComponent("FactoryServer", "CALCULATOR")
66 ############## Test Calculator Component ###################
69 print "Appel cloneField : fieldcelldoublevector -> f1,f2,f3,f4"
70 (f1,f2,f3,f4)=calculator.cloneField(fieldcelldouble) # fieldcelldouble is consumed
73 ##calculator.printField(f1)
74 print "Add fields f2+f3"
75 f_add=calculator.add(f2, f3)
77 ##calculator.printField( f_add ) # f_add is consumed
80 print "Apply linear function"
81 f_lin=calculator.applyLin(f4,2.0,1.0)
83 ##calculator.printField( f_lin ) # f_lin is consumed
85 print "Appel Norme Max "
87 norme=calculator.normMax(f_lin) # f_lin is consumed
88 print " -> norme = ",norme
93 ############ Creation of a MED file with fields created by Caculator #################
96 from libMEDClient import *
98 meshDistant = f_add.getSupport().getMesh()
100 meshLocal = MESHClient(meshDistant)
102 f_addLocal = FIELDDOUBLEClient(f_add)
104 f_addLocal.setName(f_addLocal.getName()+"add")
106 f_linLocal = FIELDDOUBLEClient(f_lin)
108 f_linLocal.setName(f_linLocal.getName()+"lin")
110 # med file with 2.1 format
111 OutmedFile21="Calculatorpointe_V21.med"
112 os.system( 'rm -fr ' + OutmedFile21 )
114 medFileVersion = getMedFileVersionForWriting()
115 if (medFileVersion == V22):
116 print "setMedFileVersionForWriting(V21)"
117 setMedFileVersionForWriting(V21)
120 print "meshLocal.write :"
121 idMed = meshLocal.addDriver(MED_DRIVER, OutmedFile21, meshLocal.getName(), MED_REMP)
122 meshLocal.write(idMed)
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)
129 print "f_linLocal.write :"
130 idMed = f_linLocal.addDriver(MED_DRIVER, OutmedFile21, f_linLocal.getName())
131 f_linLocal.write(idMed)
133 # med file with 2.2 format
134 OutmedFile22="Calculatorpointe_V22.med"
135 os.system( 'rm -fr ' + OutmedFile22 )
137 medFileVersion = getMedFileVersionForWriting()
138 if (medFileVersion == V21):
139 print "setMedFileVersionForWriting(V22)"
140 setMedFileVersionForWriting(V22)
143 print "meshLocal.write :"
144 idMed = meshLocal.addDriver(MED_DRIVER, OutmedFile22, meshLocal.getName(), MED_REMP)
145 meshLocal.write(idMed)
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)
152 print "f_linLocal.write :"
153 idMed = f_linLocal.addDriver(MED_DRIVER, OutmedFile22, f_linLocal.getName())
154 f_linLocal.write(idMed)
156 print "End of Calculator Test!"