]> SALOME platform Git repositories - modules/homard.git/blob - tests/test_2.py
Salome HOME
Transfert des options avec ou sans pyramides pour un cas
[modules/homard.git] / tests / test_2.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_2
24 """
25 __revision__ = "V2.1"
26
27 #========================================================================
28 Test_Name = "test_2"
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 boundaries
65   # ==========================
66   # Creation of the discrete boundary Boundary_1
67     Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
68   #
69   # Creation of the hypotheses
70   # ==========================
71   # Creation of the hypothesis 1
72     HypoName_1 = "Hypo_" + Test_Name + "_1"
73     print "-------- Creation of the hypothesis", HypoName_1
74     Hypo_test_2_1 = homard.CreateHypothesis(HypoName_1)
75     Hypo_test_2_1.SetAdapRefinUnRef(-1, 1, 0)
76     Hypo_test_2_1.AddGroup('EG')
77     Hypo_test_2_1.AddGroup('BANDE')
78     print HypoName_1, " : zones utilisées :", Hypo_test_2_1.GetZones()
79     print HypoName_1, " : champ utilisé :", Hypo_test_2_1.GetFieldName()
80     print HypoName_1, " : composantes utilisées :", Hypo_test_2_1.GetComps()
81     if ( len (Hypo_test_2_1.GetFieldName()) > 0 ) :
82       print ".. caractéristiques de l'adaptation :", Hypo_test_2_1.GetField()
83
84   # Creation of the hypothesis 2
85     HypoName_2 = "Hypo_" + Test_Name + "_2"
86     print "-------- Creation of the hypothesis", HypoName_2
87     Hypo_test_2_2 = homard.CreateHypothesis(HypoName_2)
88     Hypo_test_2_2.SetAdapRefinUnRef(-1, 1, 0)
89     Hypo_test_2_2.AddGroup('M_D')
90     print HypoName_2, " : zones utilisées :", Hypo_test_2_2.GetZones()
91     print HypoName_2, " : champ utilisé :", Hypo_test_2_2.GetFieldName()
92     print HypoName_2, " : composantes utilisées :", Hypo_test_2_2.GetComps()
93     if ( len (Hypo_test_2_2.GetFieldName()) > 0 ) :
94       print ".. caractéristiques de l'adaptation :", Hypo_test_2_2.GetField()
95   #
96   # Creation of the cases
97   # =====================
98     # Creation of the case
99     CaseName = "Case_" + Test_Name
100     MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
101     Case_test_2 = homard.CreateCase(CaseName, 'PLAQUE_0', MeshFile)
102     Case_test_2.SetDirName(Rep_Test_Resu)
103     Case_test_2.SetConfType(1)
104     Case_test_2.AddBoundaryGroup('internal_boundary', '')
105   #
106   # Creation of the iterations
107   # ==========================
108   # Creation of the iteration 1
109     IterName = "I_" + Test_Name + "_1"
110     Iter_test_2_1 = Case_test_2.NextIteration(IterName)
111     Iter_test_2_1.SetMeshName('PLAQUE_1')
112     Iter_test_2_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
113     Iter_test_2_1.AssociateHypo(HypoName_1)
114     error = Iter_test_2_1.Compute(1, 1)
115     if error :
116       error = 1
117       break
118
119   # Creation of the iteration 2
120     IterName = "I_" + Test_Name + "_2"
121     Iter_test_2_2 = Iter_test_2_1.NextIteration(IterName)
122     Iter_test_2_2.SetMeshName('PLAQUE_2')
123     Iter_test_2_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
124     Iter_test_2_2.AssociateHypo(HypoName_1)
125     error = Iter_test_2_2.Compute(1, 1)
126     if error :
127       error = 2
128       break
129
130   # Creation of the iteration 3
131     IterName = "I_" + Test_Name + "_3"
132     Iter_test_2_3 = Iter_test_2_2.NextIteration(IterName)
133     Iter_test_2_3.SetMeshName('PLAQUE_3')
134     Iter_test_2_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
135     Iter_test_2_3.AssociateHypo(HypoName_2)
136     error = Iter_test_2_3.Compute(1, 1)
137     if error :
138       error = 3
139       break
140   #
141   # Creation of the schema YACS
142   # ===========================
143     ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
144     ScriptFile = os.path.normpath(ScriptFile)
145     DirName = Rep_Test_Resu
146     YACS_test_2 = Case_test_2.CreateYACSSchema("YACS_test_2", ScriptFile, DirName, MeshFile)
147     YACS_test_2.SetType(1)
148     filexml = os.path.join(Rep_Test_Resu, 'YACS_test_2.xml')
149     error = YACS_test_2.WriteOnFile(filexml)
150     if error :
151       error = 4
152       break
153   #
154     break
155   #
156   return error
157
158 #========================================================================
159
160 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
161 assert homard is not None, "Impossible to load homard engine"
162 homard.SetLanguageShort("fr")
163 #
164 # Exec of HOMARD-SALOME
165 #
166 try :
167   error_main = homard_exec(salome.myStudy)
168   if error_main :
169     raise Exception('Pb in homard_exec at iteration %d' %error_main )
170 except Exception, e:
171   raise Exception('Pb in homard_exec: '+e.message)
172
173 #
174 # Test of the result
175 #
176 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
177 rep_test_file = "I%02d" % n_iter_test_file
178 #
179 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
180 mess_error_ref = "\nReference file: " + test_file
181 try :
182   file = open (test_file, "r")
183   mess_ref = file.readlines()
184   file.close()
185 except :
186   mess_error = mess_error_ref + "\nThis file does not exist.\n"
187   raise Exception(mess_error)
188 #
189 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
190 if os.path.isfile (test_file) :
191   file = open (test_file, "r")
192   mess = file.readlines()
193   file.close()
194 else :
195   mess_error  = "\nResult file: " + test_file
196   mess_error += "\nThis file does not exist.\n"
197   raise Exception(mess_error)
198
199 nblign = len(mess_ref)
200 if ( len(mess) != nblign ):
201   mess_error = mess_error_ref +  "\nResult file: " + test_file
202   mess_error += "\nThe number of lines of the files are not the same.\n"
203   raise Exception(mess_error)
204
205 for num in range(nblign) :
206   if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
207     message_erreur = "\nRefe : " + mess_ref[num]
208     message_erreur += "Test : " + mess[num][:-1]
209     message_erreur += "\nThe test is different from the reference."
210     raise Exception(message_erreur)
211 #
212 remove_dir(Rep_Test_Resu)
213 #
214 if salome.sg.hasDesktop():
215   salome.sg.updateObjBrowser(1)
216   iparameters.getSession().restoreVisualState(1)
217