Salome HOME
Merge from V6_main 01/04/2013
[tools/yacsgen.git] / Examples / hxx1 / test_compohxx.py
1 #==============================================================================
2 #  File      : CALCUL_test.py
3 #  Created   :
4 #  Author    :
5 #  Project   : SALOME
6 #  Copyright : CEA 2005
7 #==============================================================================
8 #
9 # Test du composant CALCUL
10 #
11 import SALOME
12 import salome
13 salome.salome_init()
14 print "Test du composant CALCUL genere par hxx2salome"
15 import hxxcompos_ORB
16 myCalc = salome.lcc.FindOrLoadComponent("FactoryServer", "CALCUL")
17 print "10+15 = ",myCalc.add(10,15)
18 print "10x15 = ",myCalc.mul(10,15)
19 #print "6!    = ",myCalc.fact(6)
20 res1,res2 = myCalc.sqr2(12.0)
21 print "12*12 = ",res1," ",res2
22 j=1
23 i1,i2,i3 = myCalc.return_3_int(j)
24 assert (i1 == j+1),'Erreur dans la fonction return_3_int'
25 assert (i2 == j+2),'Erreur dans la fonction return_3_int'
26 assert (i3 == j+3),'Erreur dans la fonction return_3_int'
27 print 'return_3_int : ',j,' ',i1,' ',i2,' ',i3
28 print "True && True  = ",myCalc.And(True,True)
29 print "True && False = ",myCalc.And(True,False)
30 print "True || False = ",myCalc.Or(True,False)
31 from math import fabs
32 assert (fabs(res1-144.0)<1.0e-6 ), 'Erreur dans la fonction myCalc.sqr2 : 12*12 = '+str(res1)
33 assert ( myCalc.And(True,True)==True ) , 'Erreur dans la fonction And(True,True)'
34 assert ( myCalc.And(True,False)==False ) , 'Erreur dans la fonction And(True,False)'
35 assert ( myCalc.Or(True,False)==True ) , 'Erreur dans la fonction Or(True,False)'
36 print "Fin test hxx2salome/001/A1"
37 #
38 #
39 myTestMed = salome.lcc.FindOrLoadComponent("FactoryServerTM", "TESTMED")
40 myMedCalc = salome.lcc.FindOrLoadComponent("FactoryServerMC", "MEDCALC")
41 #
42 banner = myTestMed.getBanner()
43 print "Banner = ",banner
44 assert  banner == "Hello" , 'erreur dans la fonction getBanner() : mauvaise valeur'
45 #
46 print "Creation et tests des supports :"
47 supportName=myTestMed.getSupportName(myTestMed.getSupport())
48 print "Support name : ",supportName
49 assert supportName == "SupportOnAll_MED_MAILLE"
50 #
51 from libMEDClient import FIELDDOUBLEClient
52 f_loc=FIELDDOUBLEClient(myTestMed.getVolume(myTestMed.getSupport()))
53 assert f_loc.getNumberOfValues() == 16 , 'created field has incorrect size'
54 from math import fabs
55 assert fabs(f_loc.norm2()-6.39444)<1.0e-5  , 'created field has incorrect norm 2'
56 ##
57 # CNC bug Medclient  myTestMed.affiche_fieldT(myTestMed.getVolume(myTestMed.getSupport()))
58 myTestMed.printSupportEntity(myTestMed.getSupport())
59 myMedCalc.printSupport(myTestMed.getSupport())
60 myMedCalc.printSupport(myTestMed.getPartialSupport())
61 f_part=FIELDDOUBLEClient(myTestMed.getVolume(myTestMed.getPartialSupport()))
62 assert f_part.getNumberOfValues() == 3, 'created field on partial support has incorrect size'
63 assert fabs(f_part.norm2()-1.15470)<1.0e-5  , 'created field on partial support has incorrect norm 2'
64 print "Fin test hxx2salome/003/A1"
65 #
66 banner = myTestMed.getBanner()
67 print "Banner = ",banner
68 assert  banner == "Hello" , 'erreur dans la fonction getBanner() : mauvaise valeur'
69 #
70 theMesh= myTestMed.getMesh()
71 theField = myTestMed.getField()
72 (theField1,theField2) = myTestMed.create2DoubleField()
73 #CNC  bug Medclient  myTestMed.affiche_fieldT(theField1)
74 mynorm=myTestMed.getNormMax(theField)
75 from math import fabs
76 assert fabs(mynorm-3.0)<1.0e-10  , 'created field has incorrect norm 1'
77 print "Norm of the Field : " , mynorm
78
79 field1 = myTestMed.getConstFieldDouble( 3.0 , "field1" )
80 # CNC bug Medclient myTestMed.affiche_fieldT(field1)
81 print "Creation tableau :"
82 size=12
83 myTab = myTestMed.createDoubleTab(size)
84 myTabInt = myTestMed.createIntVector(size)
85 myTestMed.printDoubleTab(myTab)
86 print "Create a matrix"
87 myTestMed.printMatrix(myTestMed.createMatrix(size,size))
88 print "Fin test hxx2salome/002/A1"
89
90 #
91 # test of exception mechanism
92 from SALOME_MED import SUPPORT, MED_NODE, FIELDDOUBLE
93 test_exception=False
94 f_cell = myTestMed.getField()
95 f_node = myTestMed.getFieldOnNode()
96 try:
97         f_wrong=myMedCalc.add(f_cell,f_node)
98 except SALOME.SALOME_Exception, ex:
99         test_exception=True
100         print "wrong addition was correctly catched"
101         print "Exception is : ",ex
102
103 assert test_exception, 'Error in the exception management  : the wrong MED addition was not correctly catched'
104 print "Fin test hxx2salome/003/A2"
105
106 myCoco = salome.lcc.FindOrLoadComponent("FactoryServerI", "ICOCO")
107 #
108 liste_champs = myCoco.getInputFieldsNames()
109 nb_champs=len(liste_champs)
110 print "Nombre de champs = ",nb_champs
111 assert  nb_champs == 2 , 'erreur dans le nombre de champs, different de 2!'
112 #
113 print "Champ 1 (SourceField) : ",liste_champs[0]
114 print "Champ 2 (TargetField) : ",liste_champs[1]
115 assert liste_champs[0] == "SourceField", 'erreur dans le nom du champ 1'
116 assert liste_champs[1] == "TargetField", 'erreur dans le nom du champ 2'
117 #
118 print "Fin test hxx2salome/ICOCO/A1"
119 myCoco1 = salome.lcc.FindOrLoadComponent("FactoryServerI1", "ICOCO")
120 myCoco2 = salome.lcc.FindOrLoadComponent("FactoryServerI2", "ICOCO")
121 #
122 myCoco1.initialize()
123 m=myCoco1.getInputFieldTemplate("TargetField")
124 myCoco1.solve()  #to test with 5.1.5
125 f=myCoco1.getOutputField("SourceField")
126 myCoco2.printField(f)
127 #
128 print "##################################"
129 print "Fin test hxx2salome/ICOCO/A2"