]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_1.py
Salome HOME
Documentation sur les schémas YACS
[modules/homard.git] / tests / test_1.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2013  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, 2013
23 Test test_1
24 """
25 __revision__ = "V1.11"
26
27 #========================================================================
28 Test_Name = "test_1"
29 n_iter_test_file = 3
30 #========================================================================
31 import os
32 import tempfile
33 import HOMARD
34 import salome
35 #
36 pathHomard = os.getenv('HOMARD_ROOT_DIR')
37 Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
38 Rep_Test = os.path.normpath(Rep_Test)
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 zones
79   # =====================
80   # Creation of the box Zone_1_1
81     Zone_1_1 = homard.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
82
83   # Creation of the sphere Zone_1_2
84     Zone_1_2 = homard.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
85   #
86   # Creation of the hypotheses
87   # ==========================
88   # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
89     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM = homard.CreateHypothesis('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
90     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetAdapRefinUnRef(1, 1, 0)
91     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetField('RESU____ERRE_ELEM_SIGM__________')
92     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetUseComp(0)
93     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddComp('ERREST')
94     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetRefinThr(3, 10.1)
95     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetTypeFieldInterp(2)
96     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddFieldInterp('RESU____DEPL____________________')
97     a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
98   # Creation of the hypothesis Zones_1_et_2
99     Zones_1_et_2 = homard.CreateHypothesis('Zones_1_et_2')
100     Zones_1_et_2.SetAdapRefinUnRef(0, 1, 0)
101     Zones_1_et_2.AddZone('Zone_1_1', 1)
102     Zones_1_et_2.AddZone('Zone_1_2', 1)
103   #
104   # Creation of the cases
105   # =====================
106     # Creation of the case Case_1
107     MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
108     Case_1 = homard.CreateCase('Case_1', 'MAILL', MeshFile)
109     Case_1.SetDirName(Rep_Test_Resu)
110     Case_1.SetConfType(1)
111   #
112   # Creation of the iterations
113   # ==========================
114   # Creation of the iteration I1_1
115     I1_1 = Case_1.NextIteration('I1_1')
116     I1_1.SetMeshName('M1')
117     I1_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
118     I1_1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
119     I1_1.SetTimeStepRank(1, 1)
120     I1_1.AssociateHypo('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
121     error = I1_1.Compute(1, 1)
122     if error :
123       error = 1
124       break
125
126   # Creation of the iteration I1_2
127     I1_2 = I1_1.NextIteration('I1_2')
128     I1_2.SetMeshName('M2')
129     I1_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
130     I1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
131     I1_2.SetTimeStepRank(1, 1)
132     I1_2.AssociateHypo('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
133     error = I1_2.Compute(1, 1)
134     if error :
135       error = 2
136       break
137
138   # Creation of the iteration I1_3
139     I1_3 = I1_2.NextIteration('I1_3')
140     I1_3.SetMeshName('M3')
141     I1_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
142     I1_3.AssociateHypo('Zones_1_et_2')
143     error = I1_3.Compute(1, 1)
144     if error :
145       error = 3
146       break
147   #
148   # Creation of the schema YACS
149   # ===========================
150     ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
151     ScriptFile = os.path.normpath(ScriptFile)
152     DirName = Rep_Test_Resu
153     YACS_1 = Case_1.CreateYACSSchema("YACS_1", ScriptFile, DirName, MeshFile)
154     error = YACS_1.Write()
155     if error :
156       error = 4
157       break
158   #
159     break
160   #
161   return error
162
163 #========================================================================
164
165 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
166 assert homard is not None, "Impossible to load homard engine"
167
168 #
169 # Exec of HOMARD-SALOME
170 #
171 try :
172   error_main = homard_exec(salome.myStudy)
173   if error_main :
174     raise Exception('Pb in homard_exec at iteration %d' %error_main )
175 except Exception, e:
176   raise Exception('Pb in homard_exec: '+e.message)
177 #
178 # Test of the result
179 #
180 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
181 rep_test_file = "I%02d" % n_iter_test_file
182 #
183 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
184 mess_error_ref = "\nReference file: " + test_file
185 try :
186   file = open (test_file, "r")
187   mess_ref = file.readlines()
188   file.close()
189 except :
190   mess_error = mess_error_ref + "\nThis file does not exist.\n"
191   raise Exception(mess_error)
192 #
193 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
194 if os.path.isfile (test_file) :
195   file = open (test_file, "r")
196   mess = file.readlines()
197   file.close()
198 else :
199   mess_error  = "\nResult file: " + test_file
200   mess_error += "\nThis file does not exist.\n"
201   raise Exception(mess_error)
202
203 nblign = len(mess_ref)
204 if ( len(mess) != nblign ):
205   mess_error = mess_error_ref +  "\nResult file: " + test_file
206   mess_error += "\nThe number of lines of the files are not the same.\n"
207   raise Exception(mess_error)
208
209 for num in range(nblign) :
210   if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
211     message_erreur = "\nRefe : " + mess_ref[num]
212     message_erreur += "Test : " + mess[num][:-1]
213     message_erreur += "\nThe test is different from the reference."
214     raise Exception(message_erreur)
215 #
216 remove_dir(Rep_Test_Resu)
217 #
218 if salome.sg.hasDesktop():
219   salome.sg.updateObjBrowser(1)
220   iparameters.getSession().restoreVisualState(1)
221