]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_1.py
Salome HOME
Suppression de la fonction SetAdapRefinUnRef et création de la fonction SetUnifRefinU...
[modules/homard.git] / tests / test_1.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2014  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, or (at your option) any later version.
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__ = "V2.1"
26
27 #========================================================================
28 Test_Name = "test_1"
29 n_iter_test_file = 3
30 #========================================================================
31 import os
32 import tempfile
33 import sys
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 = os.path.normpath(Rep_Test)
40 Rep_Test_Resu = tempfile.mktemp()
41 os.mkdir(Rep_Test_Resu)
42
43 sys.path.append(Rep_Test)
44 from test_util import remove_dir
45
46 salome.salome_init()
47 import iparameters
48 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
49 ipar.append("AP_MODULES_LIST", "Homard")
50 #
51 #========================================================================
52 #========================================================================
53 def homard_exec(theStudy):
54   """
55 Python script for HOMARD
56 Copyright EDF-R&D 2010, 2013
57   """
58   error = 0
59 #
60   while not error :
61   #
62     homard.SetCurrentStudy(theStudy)
63   #
64   # Creation of the zones
65   # =====================
66   # Creation of the box Zone_1_1
67     Zone_1_1 = homard.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
68
69   # Creation of the sphere Zone_1_2
70     Zone_1_2 = homard.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
71   #
72   # Creation of the hypotheses
73   # ==========================
74   # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
75     HypoName_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
76     print "-------- Creation of the hypothesis", HypoName_1
77     Hypo_1_1 = homard.CreateHypothesis(HypoName_1)
78     Hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
79     Hypo_1_1.SetUseComp(0)
80     Hypo_1_1.AddComp('ERREST')
81     Hypo_1_1.SetRefinThr(3, 10.1)
82     Hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
83     Hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
84     print HypoName_1, " : zones utilisées :", Hypo_1_1.GetZones()
85     print HypoName_1, " : champ utilisé :", Hypo_1_1.GetFieldName()
86     print HypoName_1, " : composantes utilisées :", Hypo_1_1.GetComps()
87     if ( len (Hypo_1_1.GetFieldName()) > 0 ) :
88       print ".. caractéristiques de l'adaptation :", Hypo_1_1.GetField()
89     print HypoName_1, " : champs interpolés :", Hypo_1_1.GetFieldInterps()
90   # Creation of the hypothesis Zones_1_et_2
91     HypoName_2 = "Zones_1_et_2"
92     print "-------- Creation of the hypothesis", HypoName_2
93     Zones_1_et_2 = homard.CreateHypothesis(HypoName_2)
94     Zones_1_et_2.AddZone('Zone_1_1', 1)
95     Zones_1_et_2.AddZone('Zone_1_2', 1)
96     print HypoName_2, " : zones utilisées :", Zones_1_et_2.GetZones()
97     print HypoName_2, " : champ utilisé :", Zones_1_et_2.GetFieldName()
98     if ( len (Zones_1_et_2.GetFieldName()) > 0 ) :
99       print ".. caractéristiques de l'adaptation :", Zones_1_et_2.GetField()
100     print HypoName_2, " : champs interpolés :", Zones_1_et_2.GetFieldInterps()
101   #
102   # Creation of the cases
103   # =====================
104     # Creation of the case
105     CaseName = "Case_" + Test_Name
106     print "-------- Creation of the case", CaseName
107     MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
108     Case_test_1 = homard.CreateCase(CaseName, 'MAILL', MeshFile)
109     Case_test_1.SetDirName(Rep_Test_Resu)
110     Case_test_1.SetConfType(1)
111   #
112   # Creation of the iterations
113   # ==========================
114   # Creation of the iteration 1
115     IterName = "I_" + Test_Name + "_1"
116     print "-------- Creation of the iteration", IterName
117     Iter_test_1_1 = Case_test_1.NextIteration(IterName)
118     Iter_test_1_1.AssociateHypo(HypoName_1)
119     print ". Hypothese :", HypoName_1
120     Iter_test_1_1.SetMeshName('M1')
121     Iter_test_1_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
122     Iter_test_1_1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
123     Iter_test_1_1.SetTimeStepRank(1, 1)
124     Iter_test_1_1.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
125     Iter_test_1_1.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
126     print ". Instants d'interpolation :", Iter_test_1_1.GetFieldInterpsTimeStepRank()
127     error = Iter_test_1_1.Compute(1, 1)
128     if error :
129       error = 1
130       break
131
132   # Creation of the iteration 2
133     IterName = "I_" + Test_Name + "_2"
134     print "-------- Creation of the iteration", IterName
135     Iter_test_1_2 = Iter_test_1_1.NextIteration(IterName)
136     Iter_test_1_2.AssociateHypo(HypoName_1)
137     print ". Hypothese :", HypoName_1
138     Iter_test_1_2.SetMeshName('M2')
139     Iter_test_1_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
140     Iter_test_1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
141     Iter_test_1_2.SetTimeStepRank(1, 1)
142     Iter_test_1_2.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
143     Iter_test_1_2.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
144     print ". Instants d'interpolation :", Iter_test_1_2.GetFieldInterpsTimeStepRank()
145     error = Iter_test_1_2.Compute(1, 1)
146     if error :
147       error = 2
148       break
149
150   # Creation of the iteration 3
151     IterName = "I_" + Test_Name + "_3"
152     print "-------- Creation of the iteration", IterName
153     Iter_test_1_3 = Iter_test_1_2.NextIteration(IterName)
154     Iter_test_1_3.AssociateHypo(HypoName_2)
155     print ". Hypothese :", HypoName_2
156     Iter_test_1_3.SetMeshName('M3')
157     Iter_test_1_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
158     Iter_test_1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.02.med'))
159     print ". Instants d'interpolation :", Iter_test_1_3.GetFieldInterpsTimeStepRank()
160     error = Iter_test_1_3.Compute(1, 1)
161     if error :
162       error = 3
163       break
164   #
165   # Creation of the schema YACS
166   # ===========================
167     ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
168     ScriptFile = os.path.normpath(ScriptFile)
169     DirName = Rep_Test_Resu
170     YACS_test_1 = Case_test_1.CreateYACSSchema("YACS_test_1", ScriptFile, DirName, MeshFile)
171     error = YACS_test_1.Write()
172     if error :
173       error = 4
174       break
175   #
176     break
177   #
178   return error
179
180 #========================================================================
181
182 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
183 assert homard is not None, "Impossible to load homard engine"
184 homard.SetLanguageShort("fr")
185
186 #
187 # Exec of HOMARD-SALOME
188 #
189 try :
190   error_main = homard_exec(salome.myStudy)
191   if error_main :
192     raise Exception('Pb in homard_exec at iteration %d' %error_main )
193 except Exception, e:
194   raise Exception('Pb in homard_exec: '+e.message)
195 #
196 # Test of the result
197 #
198 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
199 rep_test_file = "I%02d" % n_iter_test_file
200 #
201 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
202 mess_error_ref = "\nReference file: " + test_file
203 try :
204   file = open (test_file, "r")
205   mess_ref = file.readlines()
206   file.close()
207 except :
208   mess_error = mess_error_ref + "\nThis file does not exist.\n"
209   raise Exception(mess_error)
210 #
211 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
212 if os.path.isfile (test_file) :
213   file = open (test_file, "r")
214   mess = file.readlines()
215   file.close()
216 else :
217   mess_error  = "\nResult file: " + test_file
218   mess_error += "\nThis file does not exist.\n"
219   raise Exception(mess_error)
220
221 nblign = len(mess_ref)
222 if ( len(mess) != nblign ):
223   mess_error = mess_error_ref +  "\nResult file: " + test_file
224   mess_error += "\nThe number of lines of the files are not the same.\n"
225   raise Exception(mess_error)
226
227 for num in range(nblign) :
228   if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
229     message_erreur = "\nRefe : " + mess_ref[num]
230     message_erreur += "Test : " + mess[num][:-1]
231     message_erreur += "\nThe test is different from the reference."
232     raise Exception(message_erreur)
233 #
234 remove_dir(Rep_Test_Resu)
235 #
236 if salome.sg.hasDesktop():
237   salome.sg.updateObjBrowser(1)
238   iparameters.getSession().restoreVisualState(1)
239