]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_3.py
Salome HOME
36a9e8e32f56ed409f067c4e50b40f923ca4c6d9
[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, 2013
23 Test test_3
24 """
25 __revision__ = "V1.4"
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 remove_dir(directory) :
49   """
50 Empties, then removes a directory.
51 Copyright EDF-R&D 2013
52   """
53 #
54   l_aux = os.listdir(directory)
55   for fic in l_aux :
56     fic_a = os.path.join(directory, fic)
57     if os.path.isdir(fic_a) :
58       remove_dir(fic_a)
59     else :
60       os.remove(fic_a)
61   os.rmdir(directory)
62 #
63   return
64 #
65 #========================================================================
66 #========================================================================
67 def homard_exec(theStudy):
68   """
69 Python script for HOMARD
70 Copyright EDF-R&D 2010, 2013
71   """
72   error = 0
73 #
74   while not error :
75 #
76     homard.SetCurrentStudy(theStudy)
77 #
78 # Creation of the boundaries
79 # ==========================
80 # Creation of the discrete boundary
81     Boundary_1 = homard.CreateBoundaryDi('courbes', 'COURBES', os.path.join(Rep_Test, Test_Name + '.fr.med'))
82 #
83 # Creation of the external cylinder
84     Boundary_2 = homard.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
85 #
86 # Creation of the internal cylinder
87     Boundary_3 = homard.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
88 #
89 # Creation of the first sphere
90     Boundary_4 = homard.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
91 #
92 # Creation of the second sphere
93     Boundary_5 = homard.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
94 #
95 # Creation of the hypotheses
96 # ==========================
97 # Uniform refinement
98     Hypo = homard.CreateHypothesis('Hypo')
99     Hypo.SetAdapRefinUnRef(-1, 1, 0)
100 #
101 # Creation of the cases
102 # =====================
103 # Creation of the case Case_1
104     Case_1 = homard.CreateCase('Case_1', 'MOYEU', os.path.join(Rep_Test, Test_Name + '.00.med'))
105     Case_1.SetDirName(Rep_Test_Resu)
106     Case_1.SetConfType(1)
107     Case_1.AddBoundaryGroup('courbes', '')
108     Case_1.AddBoundaryGroup('cyl_ext', 'EXT')
109     Case_1.AddBoundaryGroup('cyl_int', 'INT')
110     Case_1.AddBoundaryGroup('sphere_1', 'END_1')
111     Case_1.AddBoundaryGroup('sphere_2', 'END_2')
112 #
113 # Creation of the iterations
114 # ==========================
115 # Creation of the iteration Iter_1
116     Iter_1 = Case_1.NextIteration('Iter_1')
117     Iter_1.SetMeshName('MOYEU_1')
118     Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
119     Iter_1.AssociateHypo('Hypo')
120     error = Iter_1.Compute(1)
121     if error :
122       error = 1
123       break
124
125 # Creation of the iteration Iter_2
126     Iter_2 = Iter_1.NextIteration('Iter_2')
127     Iter_2.SetMeshName('MOYEU_2')
128     Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
129     Iter_2.AssociateHypo('Hypo')
130     error = Iter_2.Compute(1)
131     if error :
132       error = 2
133       break
134 #
135     break
136 #
137   return error
138
139 #========================================================================
140
141 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
142 assert homard is not None, "Impossible to load homard engine"
143
144 #
145 # Exec of HOMARD-SALOME
146 #
147 try :
148   error_main = homard_exec(salome.myStudy)
149   if error_main :
150     raise Exception('Pb in homard_exec at iteration %d' %error_main )
151 except Exception, e:
152   raise Exception('Pb in homard_exec: '+e.message)
153
154 #
155 # Test of the result
156 #
157 s_iter_test_file = str(n_iter_test_file)
158 test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
159 rep_test_file = "I0" + s_iter_test_file
160 #
161 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
162 mess_error_ref = "\nReference file: " + test_file
163 try :
164   file = open (test_file, "r")
165   mess_ref = file.readlines()
166   file.close()
167 except :
168   mess_error = mess_error_ref + "\nThis file does not exist.\n"
169   raise Exception(mess_error)
170   sys.exit(2)
171 #
172 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
173 if os.path.isfile (test_file) :
174    file = open (test_file, "r")
175    mess = file.readlines()
176    file.close()
177 else :
178   mess_error  = "\nResult file: " + test_file
179   mess_error += "\nThis file does not exist.\n"
180   raise Exception(mess_error)
181   sys.exit(2)
182
183 nblign = len(mess_ref)
184 if ( len(mess) != nblign ):
185   mess_error = mess_error_ref +  "\nResult file: " + test_file
186   mess_error += "\nThe number of lines of the files are not the same.\n"
187   raise Exception(mess_error)
188   sys.exit(2)
189
190 for num in range(nblign) :
191    if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
192        message_erreur = "\nRefe : " + mess_ref[num]
193        message_erreur += "Test : " + mess[num][:-1]
194        message_erreur += "\nThe test is different from the reference."
195        raise Exception(message_erreur)
196        sys.exit(10)
197 #
198 remove_dir(Rep_Test_Resu)
199 #
200 if salome.sg.hasDesktop():
201   salome.sg.updateObjBrowser(1)
202   iparameters.getSession().restoreVisualState(1)
203