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 2010, 2013
27 #========================================================================
30 #========================================================================
37 pathHomard=os.getenv('HOMARD_ROOT_DIR')
38 Rep_Test = os.path.join(pathHomard,"share/salome/resources/homard")
39 Rep_Test_Resu = tempfile.mktemp()
40 os.mkdir(Rep_Test_Resu)
44 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
45 ipar.append("AP_MODULES_LIST", "Homard")
46 #========================================================================
47 #========================================================================
48 def remove_dir(directory) :
50 Empties, then removes a directory.
51 Copyright EDF-R&D 2013
54 l_aux = os.listdir(directory)
56 fic_a = os.path.join(directory, fic)
57 if os.path.isdir(fic_a) :
65 #========================================================================
66 #========================================================================
67 def homard_exec(theStudy):
69 Python script for HOMARD
70 Copyright EDF-R&D 2010, 2013
76 homard.SetCurrentStudy(theStudy)
78 # Creation of the boundaries
79 # ==========================
80 # Creation of the discrete boundary Boundary_1
81 Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
83 # Creation of the hypotheses
84 # ==========================
85 # Creation of the hypothesis Hypo_1
86 Hypo_1 = homard.CreateHypothesis('Hypo_1')
87 Hypo_1.SetAdapRefinUnRef(-1, 1, 0)
89 Hypo_1.AddGroup('BANDE')
91 # Creation of the hypothesis Hypo_2
92 Hypo_2 = homard.CreateHypothesis('Hypo_2')
93 Hypo_2.SetAdapRefinUnRef(-1, 1, 0)
94 Hypo_2.AddGroup('M_D')
96 # Creation of the cases
97 # =====================
98 # Creation of the case Case_1
99 Case_1 = homard.CreateCase('Case_1', 'PLAQUE_0', os.path.join(Rep_Test, Test_Name + '.00.med'))
100 Case_1.SetDirName(Rep_Test_Resu)
101 Case_1.SetConfType(1)
102 Case_1.AddBoundaryGroup('internal_boundary', '')
104 # Creation of the iterations
105 # ==========================
106 # Creation of the iteration Iter_1
107 Iter_1 = Case_1.NextIteration('Iter_1')
108 Iter_1.SetMeshName('PLAQUE_1')
109 Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
110 Iter_1.AssociateHypo('Hypo_1')
111 error = Iter_1.Compute(1, 1)
116 # Creation of the iteration Iter_2
117 Iter_2 = Iter_1.NextIteration('Iter_2')
118 Iter_2.SetMeshName('PLAQUE_2')
119 Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
120 Iter_2.AssociateHypo('Hypo_1')
121 error = Iter_2.Compute(1, 1)
126 # Creation of the iteration Iter_3
127 Iter_3 = Iter_2.NextIteration('Iter_3')
128 Iter_3.SetMeshName('PLAQUE_3')
129 Iter_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
130 Iter_3.AssociateHypo('Hypo_2')
131 error = Iter_3.Compute(1, 1)
140 #========================================================================
142 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
143 assert homard is not None, "Impossible to load homard engine"
145 # Exec of HOMARD-SALOME
148 error_main = homard_exec(salome.myStudy)
150 raise Exception('Pb in homard_exec at iteration %d' %error_main )
152 raise Exception('Pb in homard_exec: '+e.message)
157 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
158 rep_test_file = "I%02d" % n_iter_test_file
160 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
161 mess_error_ref = "\nReference file: " + test_file
163 file = open (test_file, "r")
164 mess_ref = file.readlines()
167 mess_error = mess_error_ref + "\nThis file does not exist.\n"
168 raise Exception(mess_error)
171 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
172 if os.path.isfile (test_file) :
173 file = open (test_file, "r")
174 mess = file.readlines()
177 mess_error = "\nResult file: " + test_file
178 mess_error += "\nThis file does not exist.\n"
179 raise Exception(mess_error)
182 nblign = len(mess_ref)
183 if ( len(mess) != nblign ):
184 mess_error = mess_error_ref + "\nResult file: " + test_file
185 mess_error += "\nThe number of lines of the files are not the same.\n"
186 raise Exception(mess_error)
189 for num in range(nblign) :
190 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
191 message_erreur = "\nRefe : " + mess_ref[num]
192 message_erreur += "Test : " + mess[num][:-1]
193 message_erreur += "\nThe test is different from the reference."
194 raise Exception(message_erreur)
197 remove_dir(Rep_Test_Resu)
199 if salome.sg.hasDesktop():
200 salome.sg.updateObjBrowser(1)
201 iparameters.getSession().restoreVisualState(1)