]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_2.py
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/homard.git] / tests / test_2.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2012  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """
21 Python script for HOMARD
22 Copyright EDF-R&D 2010
23 Test test_2
24 """
25 __revision__ = "V1.5"
26
27 ######################################################################################
28 Test_Name = "test_2"
29 n_iter_test_file = 3
30 ######################################################################################
31 import os
32 import sys
33 import tempfile
34 import HOMARD
35 import salome
36 #
37 pathHomard=os.getenv('HOMARD_ROOT_DIR')
38 Rep_Test = os.path.join(pathHomard,"share/salome/resources/homard")
39 Rep_Test_Resu = tempfile.mktemp()
40 os.mkdir(Rep_Test_Resu)
41
42 salome.salome_init()
43 import iparameters
44 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
45 ipar.append("AP_MODULES_LIST", "Homard")
46 ######################################################################################
47 ######################################################################################
48 def homard_exec(theStudy):
49   """
50 Python script for HOMARD
51 Copyright EDF-R&D 2010
52   """
53   error = 0
54 #
55   while not error :
56   #
57     homard.SetCurrentStudy(theStudy)
58   #
59   # Creation of the boundaries
60   # ==========================
61   # Creation of the discrete boundary Boundary_1
62     Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
63   #
64   # Creation of the hypotheses
65   # ==========================
66   # Creation of the hypothesis Hypo_1
67     Hypo_1 = homard.CreateHypothesis('Hypo_1')
68     Hypo_1.SetAdapRefinUnRef(-1, 1, 0)
69     Hypo_1.AddGroup('EG')
70     Hypo_1.AddGroup('BANDE')
71
72   # Creation of the hypothesis Hypo_2
73     Hypo_2 = homard.CreateHypothesis('Hypo_2')
74     Hypo_2.SetAdapRefinUnRef(-1, 1, 0)
75     Hypo_2.AddGroup('M_D')
76   #
77   # Creation of the cases
78   # =====================
79     # Creation of the case Case_1
80     Case_1 = homard.CreateCase('Case_1', 'PLAQUE_0', os.path.join(Rep_Test, Test_Name + '.00.med'))
81     Case_1.SetDirName(Rep_Test_Resu)
82     Case_1.SetConfType(1)
83     Case_1.AddBoundaryGroup('internal_boundary', '')
84   #
85   # Creation of the iterations
86   # ==========================
87   # Creation of the iteration Iter_1
88     Iter_1 = homard.CreateIteration('Iter_1', Case_1.GetIter0Name() )
89     Iter_1.SetMeshName('PLAQUE_1')
90     Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
91     homard.AssociateIterHypo('Iter_1', 'Hypo_1')
92     error = Iter_1.Compute(1)
93     if error :
94       error = 1
95       break
96
97   # Creation of the iteration Iter_2
98     Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
99     Iter_2.SetMeshName('PLAQUE_2')
100     Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
101     homard.AssociateIterHypo('Iter_2', 'Hypo_1')
102     error = Iter_2.Compute(1)
103     if error :
104       error = 2
105       break
106
107   # Creation of the iteration Iter_3
108     Iter_3 = homard.CreateIteration('Iter_3', 'Iter_2')
109     Iter_3.SetMeshName('PLAQUE_3')
110     Iter_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
111     homard.AssociateIterHypo('Iter_3', 'Hypo_2')
112     error = Iter_3.Compute(1)
113     if error :
114       error = 3
115       break
116   #
117     break
118   #
119     return error
120
121 ######################################################################################
122
123 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
124 #
125 # Exec of HOMARD-SALOME
126 #
127 try :
128   error_main = homard_exec(salome.myStudy)
129   if error_main :
130     raise Exception('Pb in homard_exec at iteration %d' %error_main )
131 except :
132   raise Exception('Pb in homard_exec at iteration %d' %error_main )
133   sys.exit(1)
134 #
135 # Test of the result
136 #
137 s_iter_test_file = str(n_iter_test_file)
138 test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
139 rep_test_file = "I0" + s_iter_test_file
140 #
141 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
142 mess_error_ref = "\nReference file: " + test_file
143 try :
144   file = open (test_file, "r")
145   mess_ref = file.readlines()
146   file.close()
147 except :
148   mess_error = mess_error_ref + "\nThis file does not exist.\n"
149   raise Exception(mess_error)
150   sys.exit(2)
151 #
152 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
153 if os.path.isfile (test_file) :
154    file = open (test_file, "r")
155    mess = file.readlines()
156    file.close()
157 else :
158   mess_error  = "\nResult file: " + test_file
159   mess_error += "\nThis file does not exist.\n"
160   raise Exception(mess_error)
161   sys.exit(2)
162
163 nblign = len(mess_ref)
164 if ( len(mess) != nblign ):
165   mess_error = mess_error_ref +  "\nResult file: " + test_file
166   mess_error += "\nThe number of lines of the files are not the same.\n"
167   raise Exception(mess_error)
168   sys.exit(2)
169
170 for num in range(nblign) :
171    if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
172        message_erreur = "\nRefe : " + mess_ref[num]
173        message_erreur += "Test : " + mess[num][:-1]
174        message_erreur += "\nThe test is different from the reference."
175        raise Exception(message_erreur)
176        sys.exit(10)
177 #
178 if salome.sg.hasDesktop():
179   salome.sg.updateObjBrowser(1)
180   iparameters.getSession().restoreVisualState(1)
181