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 zones
60 # =====================
61 # Creation of the box Zone_1
62 Zone_1 = homard.CreateZoneBox('Zone_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
64 # Creation of the sphere Zone_2
65 Zone_2 = homard.CreateZoneSphere('Zone_2', 0.5, 0.6, 0.7, 0.75)
67 # Creation of the hypotheses
68 # ==========================
69 # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
70 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM = homard.CreateHypothesis('a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
71 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetAdapRefinUnRef(1, 1, 0)
72 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetField('RESU____ERRE_ELEM_SIGM__________')
73 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetUseComp(0)
74 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddComp('ERREST')
75 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetRefinThr(3, 10.1)
76 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.SetTypeFieldInterp(2)
77 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddFieldInterp('RESU____DEPL____________________')
78 a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
79 # Creation of the hypothesis Zones_1_et_2
80 Zones_1_et_2 = homard.CreateHypothesis('Zones_1_et_2')
81 Zones_1_et_2.SetAdapRefinUnRef(0, 1, 0)
82 homard.AssociateHypoZone('Zones_1_et_2', 'Zone_1', 1)
83 homard.AssociateHypoZone('Zones_1_et_2', 'Zone_2', 1)
85 # Creation of the cases
86 # =====================
87 # Creation of the case zzzz121b
88 Case_1 = homard.CreateCase('zzzz121b', 'MAILL', os.path.join(Rep_Test, Test_Name + '.00.med'))
89 Case_1.SetDirName(Rep_Test_Resu)
92 # Creation of the iterations
93 # ==========================
94 # Creation of the iteration I1
95 I1 = homard.CreateIteration('I1', Case_1.GetIter0Name() )
97 I1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
98 I1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
99 I1.SetTimeStepRank(1, 1)
100 homard.AssociateIterHypo('I1', 'a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
101 error = I1.Compute(1)
106 # Creation of the iteration I2
107 I2 = homard.CreateIteration('I2', 'I1')
109 I2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
110 I2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
111 I2.SetTimeStepRank(1, 1)
112 homard.AssociateIterHypo('I2', 'a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM')
113 error = I2.Compute(1)
118 # Creation of the iteration I3
119 I3 = homard.CreateIteration('I3', 'I2')
121 I3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
122 homard.AssociateIterHypo('I3', 'Zones_1_et_2')
123 error = I3.Compute(1)
132 ######################################################################################
134 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
136 # Exec of HOMARD-SALOME
139 error_main = homard_exec(salome.myStudy)
141 raise Exception('Pb in homard_exec at iteration %d' %error_main )
143 raise Exception('Pb in homard_exec at iteration %d' %error_main )
148 s_iter_test_file = str(n_iter_test_file)
149 test_file_suff = "apad.0" + s_iter_test_file + ".bilan"
150 rep_test_file = "I0" + s_iter_test_file
152 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
153 mess_error_ref = "\nReference file: " + test_file
155 file = open (test_file, "r")
156 mess_ref = file.readlines()
159 mess_error = mess_error_ref + "\nThis file does not exist.\n"
160 raise Exception(mess_error)
163 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
164 if os.path.isfile (test_file) :
165 file = open (test_file, "r")
166 mess = file.readlines()
169 mess_error = "\nResult file: " + test_file
170 mess_error += "\nThis file does not exist.\n"
171 raise Exception(mess_error)
174 nblign = len(mess_ref)
175 if ( len(mess) != nblign ):
176 mess_error = mess_error_ref + "\nResult file: " + test_file
177 mess_error += "\nThe number of lines of the files are not the same.\n"
178 raise Exception(mess_error)
181 for num in range(nblign) :
182 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
183 message_erreur = "\nRefe : " + mess_ref[num]
184 message_erreur += "Test : " + mess[num][:-1]
185 message_erreur += "\nThe test is different from the reference."
186 raise Exception(message_erreur)
189 if salome.sg.hasDesktop():
190 salome.sg.updateObjBrowser(1)
191 iparameters.getSession().restoreVisualState(1)