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 2011
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
62 Boundary_1 = homard.CreateBoundaryDi('courbes', 'COURBES', os.path.join(Rep_Test, Test_Name + '.fr.med'))
64 # Creation of the external cylinder
65 Boundary_2 = homard.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
67 # Creation of the internal cylinder
68 Boundary_3 = homard.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
70 # Creation of the first sphere
71 Boundary_4 = homard.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
73 # Creation of the second sphere
74 Boundary_5 = homard.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
76 # Creation of the hypotheses
77 # ==========================
79 Hypo = homard.CreateHypothesis('Hypo')
80 Hypo.SetAdapRefinUnRef(-1, 1, 0)
82 # Creation of the cases
83 # =====================
84 # Creation of the case Case_1
85 Case_1 = homard.CreateCase('Case_1', 'MOYEU', os.path.join(Rep_Test, Test_Name + '.00.med'))
86 Case_1.SetDirName(Rep_Test_Resu)
88 Case_1.AddBoundaryGroup('courbes', '')
89 Case_1.AddBoundaryGroup('cyl_ext', 'EXT')
90 Case_1.AddBoundaryGroup('cyl_int', 'INT')
91 Case_1.AddBoundaryGroup('sphere_1', 'END_1')
92 Case_1.AddBoundaryGroup('sphere_2', 'END_2')
94 # Creation of the iterations
95 # ==========================
96 # Creation of the iteration Iter_1
97 Iter_1 = homard.CreateIteration('Iter_1', Case_1.GetIter0Name() )
98 Iter_1.SetMeshName('MOYEU_1')
99 Iter_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
100 homard.AssociateIterHypo('Iter_1', 'Hypo')
101 error = Iter_1.Compute(1)
106 # Creation of the iteration Iter_2
107 Iter_2 = homard.CreateIteration('Iter_2', 'Iter_1')
108 Iter_2.SetMeshName('MOYEU_2')
109 Iter_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
110 homard.AssociateIterHypo('Iter_2', 'Hypo')
111 error = Iter_2.Compute(1)
120 ######################################################################################
122 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
124 # Exec of HOMARD-SALOME
127 error_main = homard_exec(salome.myStudy)
129 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)