Salome HOME
version 5_1_4 HOMARD_SRC
[modules/homard.git] / tests / test_1.py
1 # -*- coding: iso-8859-1 -*-
2 """
3 Python script for HOMARD
4 Copyright EDF-R&D 2010
5 Test test_1
6 """
7 __revision__ = "V1.2"
8
9 ######################################################################################
10 Test_Name = "test_1"
11 n_iter_test_file = 3
12 ######################################################################################
13 import os
14 import sys
15 import tempfile
16 import HOMARD
17 import salome
18 #
19 pathHomard=os.getenv('HOMARD_ROOT_DIR')
20 Rep_Test = os.path.join(pathHomard,"share/salome/resources/homard")
21 Rep_Test_Resu = tempfile.mktemp()
22 os.mkdir(Rep_Test_Resu)
23
24 salome.salome_init()
25 import iparameters
26 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
27 ipar.append("AP_MODULES_LIST", "Homard")
28 ######################################################################################
29 ######################################################################################
30 def homard_exec(theStudy):
31   """
32 Python script for HOMARD
33 Copyright EDF-R&D 2010
34   """
35   homard.SetCurrentStudy(theStudy)
36 #
37 # Creation of the zones
38 # =====================
39 # Creation of the  box Zone_1
40   Zone_1 = homard.CreateZone('Zone_1', 2)
41   Zone_1.SetBox(-0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
42
43 # Creation of the  sphere Zone_2
44   Zone_2 = homard.CreateZone('Zone_2', 4)
45   Zone_2.SetSphere(0.5, 0.6, 0.7, 0.75)
46 #
47 # Creation of the hypotheses
48 # ==========================
49 # Creation of the hypothesis Zones_1_et_2
50   Zones_1_et_2 = homard.CreateHypothesis('Zones_1_et_2')
51   Zones_1_et_2.SetAdapRefinUnRef(0, 1, 0)
52   homard.AssociateHypoZone('Zone_1', 'Zones_1_et_2')
53   homard.AssociateHypoZone('Zone_2', 'Zones_1_et_2')
54
55 # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
56   a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM = homard.CreateHypothesis('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
57   a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetAdapRefinUnRef(1, 1, 0)
58   a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetField('RESU____ERRE_ELEM_SIGM__________')
59   a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetUseComp(0)
60   a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddComp('ERREST')
61   a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetRefinThr(3, 10.1)
62 #
63 # Creation of the cases
64 # =====================
65   # Creation of the case zzzz121b
66   Case_1 = homard.CreateCase('zzzz121b', 'MAILL', os.path.join(Rep_Test, Test_Name + '.00.med'))
67   Case_1.SetDirName(Rep_Test_Resu)
68   Case_1.SetConfType(1)
69 #
70 # Creation of the iterations
71 # ==========================
72 # Creation of the iteration I1
73   I1 = homard.CreateIteration('I1', Case_1.GetIter0Name() )
74   I1.SetMeshName('M1')
75   I1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
76   I1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
77   I1.SetTimeStepRank( 1, 1)
78   homard.AssociateIterHypo('I1', 'a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
79   result1 = homard.Compute('I1', 1)
80
81 # Creation of the iteration I2
82   I2 = homard.CreateIteration('I2', 'I1')
83   I2.SetMeshName('M2')
84   I2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
85   I2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
86   I2.SetTimeStepRank( 1, 1)
87   homard.AssociateIterHypo('I2', 'a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
88   result2 = homard.Compute('I2', 1)
89
90 # Creation of the iteration I3
91   I3 = homard.CreateIteration('I3', 'I2')
92   I3.SetMeshName('M3')
93   I3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
94   homard.AssociateIterHypo('I3', 'Zones_1_et_2')
95   result3 = homard.Compute('I3', 1)
96   return result1*result2*result3
97
98 ######################################################################################
99
100 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
101 #
102 # Exec of HOMARD-SALOME
103 #
104 try :
105   result=homard_exec(salome.myStudy)
106   if (result != True):
107       raise Exception('Pb in homard_exec')
108 except :
109   raise Exception('Pb in homard_exec')
110   sys.exit(1)
111 #
112 # Test of the result
113 #
114 s_iter_test_file = str(n_iter_test_file)
115 test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
116 rep_test_file = "I0" + s_iter_test_file
117 #
118 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
119 try :
120   file = open (test_file, "r")
121   mess_ref = file.readlines()
122   file.close()
123 except :
124   raise Exception('Reference file does not exist.')
125   sys.exit(2)
126 #
127 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
128 if os.path.isfile (test_file) :
129    file = open (test_file, "r")
130    mess = file.readlines()
131    file.close()
132 else :
133   raise Exception('Result file does not exist.')
134   sys.exit(2)
135
136 nblign = len(mess_ref)
137 if ( len(mess) != nblign ):
138   raise Exception('The number of lines of the files are not the same.')
139   sys.exit(2)
140
141 for num in range(nblign) :
142    if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
143        message_erreur = "\nRefe : " + mess_ref[num]
144        message_erreur += "Test : " + mess[num][:-1]
145        message_erreur += "\nThe test is different from the reference."
146        raise Exception(message_erreur)
147        sys.exit(10)
148 #
149 if salome.sg.hasDesktop():
150   salome.sg.updateObjBrowser(1)
151   iparameters.getSession().restoreVisualState(1)
152