1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2013 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.
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_Resu = tempfile.mktemp()
41 os.mkdir(Rep_Test_Resu)
45 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
46 ipar.append("AP_MODULES_LIST", "Homard")
47 #========================================================================
48 #========================================================================
49 def remove_dir(directory) :
51 Empties, then removes a directory.
52 Copyright EDF-R&D 2013
55 l_aux = os.listdir(directory)
57 fic_a = os.path.join(directory, fic)
58 if os.path.isdir(fic_a) :
66 #========================================================================
67 #========================================================================
68 def homard_exec(theStudy):
70 Python script for HOMARD
71 Copyright EDF-R&D 2010, 2013
77 homard.SetCurrentStudy(theStudy)
79 # Creation of the boundaries
80 # ==========================
81 # Creation of the discrete boundary
82 Boundary_3_1 = homard.CreateBoundaryDi('courbes', 'COURBES', os.path.join(Rep_Test, Test_Name + '.fr.med'))
84 # Creation of the external cylinder
85 Boundary_3_2 = homard.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
87 # Creation of the internal cylinder
88 Boundary_3_3 = homard.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
90 # Creation of the first sphere
91 Boundary_3_4 = homard.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
93 # Creation of the second sphere
94 Boundary_3_5 = homard.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
96 # Creation of the hypotheses
97 # ==========================
99 Hypo_3_ = homard.CreateHypothesis('Hypo_3_')
100 Hypo_3_.SetAdapRefinUnRef(-1, 1, 0)
102 for iaux in range (n_boucle+1) :
104 # Creation of the case Case_3
105 # ===========================
107 Case_3 = homard.CreateCase('Case_3', 'MOYEU', os.path.join(Rep_Test, Test_Name + '.00.med'))
108 Case_3.SetDirName(Rep_Test_Resu)
109 Case_3.SetConfType(1)
110 Case_3.AddBoundaryGroup('courbes', '')
111 Case_3.AddBoundaryGroup('cyl_ext', 'EXT')
112 Case_3.AddBoundaryGroup('cyl_int', 'INT')
113 Case_3.AddBoundaryGroup('sphere_1', 'END_1')
114 Case_3.AddBoundaryGroup('sphere_2', 'END_2')
116 # Creation and destruction of the iterations
117 # ==========================================
119 # Creation of the iteration Iter_3_1
120 Iter_3_1 = Case_3.NextIteration('Iter_3_1')
121 Iter_3_1.SetMeshName('MOYEU_1')
122 Iter_3_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
123 Iter_3_1.AssociateHypo('Hypo_3_')
124 error = Iter_3_1.Compute(1, 1)
129 # Creation of the iteration Iter_3_2
130 Iter_3_2 = Iter_3_1.NextIteration('Iter_3_2')
131 Iter_3_2.SetMeshName('MOYEU_2')
132 Iter_3_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
133 Iter_3_2.AssociateHypo('Hypo_3_')
134 error = Iter_3_2.Compute(1, 1)
140 # After the first loop, the case is deleted, except the final mesh files
142 error = Case_3.Delete(0)
145 # After the second loop, the iterations are deleted, with the final mesh files
147 # Recursive destruction of the iterations
148 error = Iter_3_1.Delete(1)
152 # Destruction and creation of the hypothese
154 error = Hypo_3_.Delete()
158 Hypo_3_ = homard.CreateHypothesis('Hypo_3_')
159 Hypo_3_.SetAdapRefinUnRef(-1, 1, 0)
165 #========================================================================
167 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
168 assert homard is not None, "Impossible to load homard engine"
171 # Exec of HOMARD-SALOME
174 error_main = homard_exec(salome.myStudy)
176 raise Exception('Pb in homard_exec at iteration %d' %error_main )
178 raise Exception('Pb in homard_exec: '+e.message)
183 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
184 rep_test_file = "I%02d" % (n_iter_test_file*n_boucle)
186 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
187 mess_error_ref = "\nReference file: " + test_file
189 file = open (test_file, "r")
190 mess_ref = file.readlines()
193 mess_error = mess_error_ref + "\nThis file does not exist.\n"
194 raise Exception(mess_error)
197 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
198 if os.path.isfile (test_file) :
199 file = open (test_file, "r")
200 mess = file.readlines()
203 mess_error = "\nResult file: " + test_file
204 mess_error += "\nThis file does not exist.\n"
205 raise Exception(mess_error)
208 nblign = len(mess_ref)
209 if ( len(mess) != nblign ):
210 mess_error = mess_error_ref + "\nResult file: " + test_file
211 mess_error += "\nThe number of lines of the files are not the same.\n"
212 raise Exception(mess_error)
215 for num in range(nblign) :
216 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
217 message_erreur = "\nRefe : " + mess_ref[num]
218 message_erreur += "Test : " + mess[num][:-1]
219 message_erreur += "\nThe test is different from the reference."
220 raise Exception(message_erreur)
223 remove_dir(Rep_Test_Resu)
225 if salome.sg.hasDesktop():
226 salome.sg.updateObjBrowser(1)
227 iparameters.getSession().restoreVisualState(1)