1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2012 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
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 homard_exec(theStudy):
50 Python script for HOMARD
51 Copyright EDF-R&D 2010
57 homard.SetCurrentStudy(theStudy)
59 # Creation of the boundaries
60 # ==========================
61 # Creation of the discrete boundary Boundary_1
62 Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
64 # Creation of the hypotheses
65 # ==========================
66 # Creation of the hypothesis Hypo_1
67 Hypo_1 = homard.CreateHypothesis('Hypo_1')
68 Hypo_1.SetAdapRefinUnRef(-1, 1, 0)
70 Hypo_1.AddGroup('BANDE')
72 # Creation of the hypothesis Hypo_2
73 Hypo_2 = homard.CreateHypothesis('Hypo_2')
74 Hypo_2.SetAdapRefinUnRef(-1, 1, 0)
75 Hypo_2.AddGroup('M_D')
77 # Creation of the cases
78 # =====================
79 # Creation of the case Case_1
80 Case_1 = homard.CreateCase('Case_1', 'PLAQUE_0', os.path.join(Rep_Test, Test_Name + '.00.med'))
81 Case_1.SetDirName(Rep_Test_Resu)
83 Case_1.AddBoundaryGroup('internal_boundary', '')
85 # Creation of the iterations
86 # ==========================
87 # Creation of the iteration Iter_1
88 Iter_1 = homard.CreateIteration('Iter_1', Case_1.GetIter0Name() )
89 Iter_1.SetMeshName('PLAQUE_1')
90 Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
91 homard.AssociateIterHypo('Iter_1', 'Hypo_1')
92 error = Iter_1.Compute(1)
97 # Creation of the iteration Iter_2
98 Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
99 Iter_2.SetMeshName('PLAQUE_2')
100 Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
101 homard.AssociateIterHypo('Iter_2', 'Hypo_1')
102 error = Iter_2.Compute(1)
107 # Creation of the iteration Iter_3
108 Iter_3 = homard.CreateIteration('Iter_3', 'Iter_2')
109 Iter_3.SetMeshName('PLAQUE_3')
110 Iter_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
111 homard.AssociateIterHypo('Iter_3', 'Hypo_2')
112 error = Iter_3.Compute(1)
121 ######################################################################################
123 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
125 # Exec of HOMARD-SALOME
128 error_main = homard_exec(salome.myStudy)
130 raise Exception('Pb in homard_exec at iteration %d' %error_main )
132 raise Exception('Pb in homard_exec at iteration %d' %error_main )
137 s_iter_test_file = str(n_iter_test_file)
138 test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
139 rep_test_file = "I0" + s_iter_test_file
141 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
142 mess_error_ref = "\nReference file: " + test_file
144 file = open (test_file, "r")
145 mess_ref = file.readlines()
148 mess_error = mess_error_ref + "\nThis file does not exist.\n"
149 raise Exception(mess_error)
152 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
153 if os.path.isfile (test_file) :
154 file = open (test_file, "r")
155 mess = file.readlines()
158 mess_error = "\nResult file: " + test_file
159 mess_error += "\nThis file does not exist.\n"
160 raise Exception(mess_error)
163 nblign = len(mess_ref)
164 if ( len(mess) != nblign ):
165 mess_error = mess_error_ref + "\nResult file: " + test_file
166 mess_error += "\nThe number of lines of the files are not the same.\n"
167 raise Exception(mess_error)
170 for num in range(nblign) :
171 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
172 message_erreur = "\nRefe : " + mess_ref[num]
173 message_erreur += "Test : " + mess[num][:-1]
174 message_erreur += "\nThe test is different from the reference."
175 raise Exception(message_erreur)
178 if salome.sg.hasDesktop():
179 salome.sg.updateObjBrowser(1)
180 iparameters.getSession().restoreVisualState(1)