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
25 __revision__ = "V1.12"
27 #========================================================================
30 #========================================================================
36 pathHomard = os.getenv('HOMARD_ROOT_DIR')
37 Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
38 Rep_Test = os.path.normpath(Rep_Test)
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 zones
79 # =====================
80 # Creation of the box Zone_1_1
81 Zone_1_1 = homard.CreateZoneBox('Zone_1_1', -0.01, 1.01, -0.01, 0.4, -0.01, 0.6)
83 # Creation of the sphere Zone_1_2
84 Zone_1_2 = homard.CreateZoneSphere('Zone_1_2', 0.5, 0.6, 0.7, 0.75)
86 # Creation of the hypotheses
87 # ==========================
88 # Creation of the hypothesis a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM
89 HypoName_1 = "a10_1pc_de_mailles_a_raffiner_sur_ERRE_ELEM_SIGM"
90 print "-------- Creation of the hypothesis", HypoName_1
91 Hypo_1_1 = homard.CreateHypothesis(HypoName_1)
92 Hypo_1_1.SetAdapRefinUnRef(1, 1, 0)
93 Hypo_1_1.SetField('RESU____ERRE_ELEM_SIGM__________')
94 Hypo_1_1.SetUseComp(0)
95 Hypo_1_1.AddComp('ERREST')
96 Hypo_1_1.SetRefinThr(3, 10.1)
97 Hypo_1_1.AddFieldInterp('RESU____DEPL____________________')
98 Hypo_1_1.AddFieldInterp('RESU____ERRE_ELEM_SIGM__________')
99 print HypoName_1, " : zones utilisées :", Hypo_1_1.GetZones()
100 print HypoName_1, " : champ utilisé :", Hypo_1_1.GetFieldName()
101 print HypoName_1, " : composantes utilisées :", Hypo_1_1.GetComps()
102 if ( len (Hypo_1_1.GetFieldName()) > 0 ) :
103 print ".. caractéristiques de l'adaptation :", Hypo_1_1.GetField()
104 print HypoName_1, " : champs interpolés :", Hypo_1_1.GetFieldInterps()
105 # Creation of the hypothesis Zones_1_et_2
106 HypoName_2 = "Zones_1_et_2"
107 print "-------- Creation of the hypothesis", HypoName_2
108 Zones_1_et_2 = homard.CreateHypothesis(HypoName_2)
109 Zones_1_et_2.SetAdapRefinUnRef(0, 1, 0)
110 Zones_1_et_2.AddZone('Zone_1_1', 1)
111 Zones_1_et_2.AddZone('Zone_1_2', 1)
112 print HypoName_2, " : zones utilisées :", Zones_1_et_2.GetZones()
113 print HypoName_2, " : champ utilisé :", Zones_1_et_2.GetFieldName()
114 if ( len (Zones_1_et_2.GetFieldName()) > 0 ) :
115 print ".. caractéristiques de l'adaptation :", Zones_1_et_2.GetField()
116 print HypoName_2, " : champs interpolés :", Zones_1_et_2.GetFieldInterps()
118 # Creation of the cases
119 # =====================
120 # Creation of the case Case_1
122 print "-------- Creation of the hypothesis", CaseName
123 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
124 Case_1 = homard.CreateCase(CaseName, 'MAILL', MeshFile)
125 Case_1.SetDirName(Rep_Test_Resu)
126 Case_1.SetConfType(1)
128 # Creation of the iterations
129 # ==========================
130 # Creation of the iteration I1_1
132 print "-------- Creation of the iteration", IterName_1
133 I1_1 = Case_1.NextIteration(IterName_1)
134 I1_1.AssociateHypo(HypoName_1)
135 print ". Hypothese :", HypoName_1
136 I1_1.SetMeshName('M1')
137 I1_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
138 I1_1.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.00.med'))
139 I1_1.SetTimeStepRank(1, 1)
140 I1_1.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
141 I1_1.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
142 print ". Instants d'interpolation :", I1_1.GetFieldInterpsTimeStepRank()
143 error = I1_1.Compute(1, 1)
148 # Creation of the iteration I1_2
150 print "-------- Creation of the iteration", IterName_2
151 I1_2 = I1_1.NextIteration(IterName_2)
152 I1_2.AssociateHypo(HypoName_1)
153 print ". Hypothese :", HypoName_1
154 I1_2.SetMeshName('M2')
155 I1_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
156 I1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.01.med'))
157 I1_2.SetTimeStepRank(1, 1)
158 I1_2.SetFieldInterpTimeStep('RESU____DEPL____________________', 1)
159 I1_2.SetFieldInterpTimeStepRank('RESU____ERRE_ELEM_SIGM__________', 1, 1)
160 print ". Instants d'interpolation :", I1_2.GetFieldInterpsTimeStepRank()
161 error = I1_2.Compute(1, 1)
166 # Creation of the iteration I1_3
168 print "-------- Creation of the iteration", IterName_3
169 I1_3 = I1_2.NextIteration(IterName_3)
170 I1_3.AssociateHypo(HypoName_2)
171 print ". Hypothese :", HypoName_2
172 I1_3.SetMeshName('M3')
173 I1_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
174 I1_2.SetFieldFile(os.path.join(Rep_Test, Test_Name + '.02.med'))
175 print ". Instants d'interpolation :", I1_3.GetFieldInterpsTimeStepRank()
176 error = I1_3.Compute(1, 1)
181 # Creation of the schema YACS
182 # ===========================
183 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
184 ScriptFile = os.path.normpath(ScriptFile)
185 DirName = Rep_Test_Resu
186 YACS_1 = Case_1.CreateYACSSchema("YACS_1", ScriptFile, DirName, MeshFile)
187 error = YACS_1.Write()
196 #========================================================================
198 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
199 assert homard is not None, "Impossible to load homard engine"
202 # Exec of HOMARD-SALOME
205 error_main = homard_exec(salome.myStudy)
207 raise Exception('Pb in homard_exec at iteration %d' %error_main )
209 raise Exception('Pb in homard_exec: '+e.message)
213 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
214 rep_test_file = "I%02d" % n_iter_test_file
216 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
217 mess_error_ref = "\nReference file: " + test_file
219 file = open (test_file, "r")
220 mess_ref = file.readlines()
223 mess_error = mess_error_ref + "\nThis file does not exist.\n"
224 raise Exception(mess_error)
226 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
227 if os.path.isfile (test_file) :
228 file = open (test_file, "r")
229 mess = file.readlines()
232 mess_error = "\nResult file: " + test_file
233 mess_error += "\nThis file does not exist.\n"
234 raise Exception(mess_error)
236 nblign = len(mess_ref)
237 if ( len(mess) != nblign ):
238 mess_error = mess_error_ref + "\nResult file: " + test_file
239 mess_error += "\nThe number of lines of the files are not the same.\n"
240 raise Exception(mess_error)
242 for num in range(nblign) :
243 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
244 message_erreur = "\nRefe : " + mess_ref[num]
245 message_erreur += "Test : " + mess[num][:-1]
246 message_erreur += "\nThe test is different from the reference."
247 raise Exception(message_erreur)
249 remove_dir(Rep_Test_Resu)
251 if salome.sg.hasDesktop():
252 salome.sg.updateObjBrowser(1)
253 iparameters.getSession().restoreVisualState(1)