]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_3.py
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/homard.git] / tests / test_3.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 2011
23 Test test_3
24 """
25 __revision__ = "V1.3"
26
27 ######################################################################################
28 Test_Name = "test_3"
29 n_iter_test_file = 2
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
62     Boundary_1 = homard.CreateBoundaryDi('courbes', 'COURBES', os.path.join(Rep_Test, Test_Name + '.fr.med'))
63 #
64 # Creation of the external cylinder
65     Boundary_2 = homard.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
66 #
67 # Creation of the internal cylinder
68     Boundary_3 = homard.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
69 #
70 # Creation of the first sphere
71     Boundary_4 = homard.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
72 #
73 # Creation of the second sphere
74     Boundary_5 = homard.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
75 #
76 # Creation of the hypotheses
77 # ==========================
78 # Uniform refinement
79     Hypo = homard.CreateHypothesis('Hypo')
80     Hypo.SetAdapRefinUnRef(-1, 1, 0)
81 #
82 # Creation of the cases
83 # =====================
84 # Creation of the case Case_1
85     Case_1 = homard.CreateCase('Case_1', 'MOYEU', os.path.join(Rep_Test, Test_Name + '.00.med'))
86     Case_1.SetDirName(Rep_Test_Resu)
87     Case_1.SetConfType(1)
88     Case_1.AddBoundaryGroup('courbes', '')
89     Case_1.AddBoundaryGroup('cyl_ext', 'EXT')
90     Case_1.AddBoundaryGroup('cyl_int', 'INT')
91     Case_1.AddBoundaryGroup('sphere_1', 'END_1')
92     Case_1.AddBoundaryGroup('sphere_2', 'END_2')
93 #
94 # Creation of the iterations
95 # ==========================
96 # Creation of the iteration Iter_1
97     Iter_1 = homard.CreateIteration('Iter_1', Case_1.GetIter0Name() )
98     Iter_1.SetMeshName('MOYEU_1')
99     Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
100     homard.AssociateIterHypo('Iter_1', 'Hypo')
101     error = Iter_1.Compute(1)
102     if error :
103       error = 1
104       break
105
106 # Creation of the iteration Iter_2
107     Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
108     Iter_2.SetMeshName('MOYEU_2')
109     Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
110     homard.AssociateIterHypo('Iter_2', 'Hypo')
111     error = Iter_2.Compute(1)
112     if error :
113       error = 2
114       break
115 #
116     break
117 #
118   return error
119
120 ######################################################################################
121
122 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
123 #
124 # Exec of HOMARD-SALOME
125 #
126 try :
127   error_main = homard_exec(salome.myStudy)
128   if error_main :
129     raise Exception('Pb in homard_exec at iteration %d' %error_main )
130 except :
131   if error_main :
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