]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_2.py
Salome HOME
Merge from V6_main 13/12/2012
[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 assert homard is not None, "Impossible to load homard engine"
125 #
126 # Exec of HOMARD-SALOME
127 #
128 try :
129   error_main = homard_exec(salome.myStudy)
130   if error_main :
131     raise Exception('Pb in homard_exec at iteration %d' %error_main )
132 except Exception, e:
133   raise Exception('Pb in homard_exec: '+e.message)
134
135 #
136 # Test of the result
137 #
138 s_iter_test_file = str(n_iter_test_file)
139 test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
140 rep_test_file = "I0" + s_iter_test_file
141 #
142 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
143 mess_error_ref = "\nReference file: " + test_file
144 try :
145   file = open (test_file, "r")
146   mess_ref = file.readlines()
147   file.close()
148 except :
149   mess_error = mess_error_ref + "\nThis file does not exist.\n"
150   raise Exception(mess_error)
151   sys.exit(2)
152 #
153 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
154 if os.path.isfile (test_file) :
155    file = open (test_file, "r")
156    mess = file.readlines()
157    file.close()
158 else :
159   mess_error  = "\nResult file: " + test_file
160   mess_error += "\nThis file does not exist.\n"
161   raise Exception(mess_error)
162   sys.exit(2)
163
164 nblign = len(mess_ref)
165 if ( len(mess) != nblign ):
166   mess_error = mess_error_ref +  "\nResult file: " + test_file
167   mess_error += "\nThe number of lines of the files are not the same.\n"
168   raise Exception(mess_error)
169   sys.exit(2)
170
171 for num in range(nblign) :
172    if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
173        message_erreur = "\nRefe : " + mess_ref[num]
174        message_erreur += "Test : " + mess[num][:-1]
175        message_erreur += "\nThe test is different from the reference."
176        raise Exception(message_erreur)
177        sys.exit(10)
178 #
179 if salome.sg.hasDesktop():
180   salome.sg.updateObjBrowser(1)
181   iparameters.getSession().restoreVisualState(1)
182