1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2014 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Python script for HOMARD
22 Copyright EDF-R&D 2011, 2013
27 #========================================================================
31 #========================================================================
38 pathHomard = os.getenv('HOMARD_ROOT_DIR')
39 Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
40 Rep_Test = os.path.normpath(Rep_Test)
41 Rep_Test_Resu = tempfile.mktemp()
42 os.mkdir(Rep_Test_Resu)
44 sys.path.append(Rep_Test)
45 from test_util import remove_dir
49 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
50 ipar.append("AP_MODULES_LIST", "Homard")
52 #========================================================================
53 #========================================================================
54 def homard_exec(theStudy):
56 Python script for HOMARD
57 Copyright EDF-R&D 2010, 2013
63 homard.SetCurrentStudy(theStudy)
65 # Creation of the boundaries
66 # ==========================
67 # Creation of the discrete boundary
68 Boundary_3_1 = homard.CreateBoundaryDi('courbes', 'COURBES', os.path.join(Rep_Test, Test_Name + '.fr.med'))
70 # Creation of the external cylinder
71 Boundary_3_2 = homard.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
73 # Creation of the internal cylinder
74 Boundary_3_3 = homard.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
76 # Creation of the first sphere
77 Boundary_3_4 = homard.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
79 # Creation of the second sphere
80 Boundary_3_5 = homard.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
82 # Creation of the hypotheses
83 # ==========================
85 HypoName = "Hypo_" + Test_Name
86 print "-------- Creation of the hypothesis", HypoName
87 Hypo_test_3 = homard.CreateHypothesis(HypoName)
88 Hypo_test_3.SetAdapRefinUnRef(-1, 1, 0)
89 print HypoName, " : zones utilisées :", Hypo_test_3.GetZones()
90 print HypoName, " : champ utilisé :", Hypo_test_3.GetFieldName()
91 print HypoName, " : composantes utilisées :", Hypo_test_3.GetComps()
93 for num in range (n_boucle+1) :
95 print "-------- num =", num, "--------"
97 # Creation of the case Case_test_3
98 # ===========================
100 CaseName = "Case_" + Test_Name
101 print "-------- Creation of the case", CaseName
102 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
103 Case_test_3 = homard.CreateCase(CaseName, 'MOYEU', MeshFile)
104 Case_test_3.SetDirName(Rep_Test_Resu)
105 Case_test_3.SetConfType(1)
106 Case_test_3.AddBoundaryGroup('courbes', '')
107 Case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
108 Case_test_3.AddBoundaryGroup('cyl_int', 'INT')
109 Case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
110 Case_test_3.AddBoundaryGroup('sphere_2', 'END_2')
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_3_1 = Case_test_3.NextIteration(IterName)
118 Iter_test_3_1.SetMeshName('MOYEU_1')
119 Iter_test_3_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
120 Iter_test_3_1.AssociateHypo('Hypo_test_3')
121 error = Iter_test_3_1.Compute(1, 1)
126 # Creation of the iteration 2
127 IterName = "I_" + Test_Name + "_2"
128 print "-------- Creation of the iteration", IterName
129 Iter_test_3_2 = Iter_test_3_1.NextIteration(IterName)
130 Iter_test_3_2.SetMeshName('MOYEU_2')
131 Iter_test_3_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
132 Iter_test_3_2.AssociateHypo('Hypo_test_3')
133 error = Iter_test_3_2.Compute(1, 1)
138 # Creation of the schema YACS
139 # ===========================
140 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
141 ScriptFile = os.path.normpath(ScriptFile)
142 DirName = Rep_Test_Resu
143 YACSName = "YACS_" + Test_Name
144 print "-------- Creation of the schema", YACSName
145 YACS_test_3 = Case_test_3.CreateYACSSchema(YACSName, ScriptFile, DirName, MeshFile)
146 YACS_test_3.SetType(2)
147 error = YACS_test_3.Write()
154 # Destruction of the schema, sauf a la fin
155 if ( num < n_boucle ) :
156 print "-------- Destruction of the schema", YACS_test_3.GetName()
157 error = YACS_test_3.Delete(1)
161 # After the first loop, the case is deleted, except the final mesh files
162 # All the iterations are deleted
164 print "-------- Destruction of the case", Case_test_3.GetName()
165 error = Case_test_3.Delete(0)
168 # After the second loop, the iterations are deleted, with the final mesh files
170 # Recursive destruction of the iterations
171 print "-------- Recursive destruction of the iteration", Iter_test_3_1.GetName()
172 error = Iter_test_3_1.Delete(1)
176 # Destruction and creation of the hypothese
178 print "-------- Destruction of the hypothese", Hypo_test_3.GetName()
179 error = Hypo_test_3.Delete()
183 HypoName = "Hypo_test_3"
184 print "-------- Creation of the hypothesis", HypoName
185 Hypo_test_3 = homard.CreateHypothesis(HypoName)
186 Hypo_test_3.SetAdapRefinUnRef(-1, 1, 0)
192 #========================================================================
194 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
195 assert homard is not None, "Impossible to load homard engine"
196 homard.SetLanguageShort("fr")
198 # Exec of HOMARD-SALOME
201 error_main = homard_exec(salome.myStudy)
203 raise Exception('Pb in homard_exec at iteration %d' %error_main )
205 raise Exception('Pb in homard_exec: '+e.message)
209 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
210 rep_test_file = "I%02d" % (n_iter_test_file*n_boucle)
212 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
213 mess_error_ref = "\nReference file: " + test_file
215 file = open (test_file, "r")
216 mess_ref = file.readlines()
219 mess_error = mess_error_ref + "\nThis file does not exist.\n"
220 raise Exception(mess_error)
222 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
223 if os.path.isfile (test_file) :
224 file = open (test_file, "r")
225 mess = file.readlines()
228 mess_error = "\nResult file: " + test_file
229 mess_error += "\nThis file does not exist.\n"
230 raise Exception(mess_error)
232 nblign = len(mess_ref)
233 if ( len(mess) != nblign ):
234 mess_error = mess_error_ref + "\nResult file: " + test_file
235 mess_error += "\nThe number of lines of the files are not the same.\n"
236 raise Exception(mess_error)
238 for num in range(nblign) :
239 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
240 message_erreur = "\nRefe : " + mess_ref[num]
241 message_erreur += "Test : " + mess[num][:-1]
242 message_erreur += "\nThe test is different from the reference."
243 raise Exception(message_erreur)
245 remove_dir(Rep_Test_Resu)
247 if salome.sg.hasDesktop():
248 salome.sg.updateObjBrowser(1)
249 iparameters.getSession().restoreVisualState(1)