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.11"
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 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_2_1
86 HypoName_1 = "Hypo_2_1"
87 print "-------- Creation of the hypothesis", HypoName_1
88 Hypo_2_1 = homard.CreateHypothesis(HypoName_1)
89 Hypo_2_1.SetAdapRefinUnRef(-1, 1, 0)
90 Hypo_2_1.AddGroup('EG')
91 Hypo_2_1.AddGroup('BANDE')
92 print HypoName_1, " : zones utilisées :", Hypo_2_1.GetZones()
93 print HypoName_1, " : champ utilisé :", Hypo_2_1.GetFieldName()
94 print HypoName_1, " : composantes utilisées :", Hypo_2_1.GetComps()
95 if ( len (Hypo_2_1.GetFieldName()) > 0 ) :
96 print ".. caractéristiques de l'adaptation :", Hypo_2_1.GetField()
98 # Creation of the hypothesis Hypo_2_2
99 HypoName_2 = "Hypo_2_2"
100 print "-------- Creation of the hypothesis", HypoName_2
101 Hypo_2_2 = homard.CreateHypothesis(HypoName_2)
102 Hypo_2_2.SetAdapRefinUnRef(-1, 1, 0)
103 Hypo_2_2.AddGroup('M_D')
104 print HypoName_2, " : zones utilisées :", Hypo_2_2.GetZones()
105 print HypoName_2, " : champ utilisé :", Hypo_2_2.GetFieldName()
106 print HypoName_2, " : composantes utilisées :", Hypo_2_2.GetComps()
107 if ( len (Hypo_2_2.GetFieldName()) > 0 ) :
108 print ".. caractéristiques de l'adaptation :", Hypo_2_2.GetField()
110 # Creation of the cases
111 # =====================
112 # Creation of the case Case_2
113 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
114 Case_2 = homard.CreateCase('Case_2', 'PLAQUE_0', MeshFile)
115 Case_2.SetDirName(Rep_Test_Resu)
116 Case_2.SetConfType(1)
117 Case_2.AddBoundaryGroup('internal_boundary', '')
119 # Creation of the iterations
120 # ==========================
121 # Creation of the iteration Iter_2_1
122 Iter_2_1 = Case_2.NextIteration('Iter_2_1')
123 Iter_2_1.SetMeshName('PLAQUE_1')
124 Iter_2_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
125 Iter_2_1.AssociateHypo(HypoName_1)
126 error = Iter_2_1.Compute(1, 1)
131 # Creation of the iteration Iter_2_2
132 Iter_2_2 = Iter_2_1.NextIteration('Iter_2_2')
133 Iter_2_2.SetMeshName('PLAQUE_2')
134 Iter_2_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
135 Iter_2_2.AssociateHypo(HypoName_1)
136 error = Iter_2_2.Compute(1, 1)
141 # Creation of the iteration Iter_2_3
142 Iter_2_3 = Iter_2_2.NextIteration('Iter_2_3')
143 Iter_2_3.SetMeshName('PLAQUE_3')
144 Iter_2_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
145 Iter_2_3.AssociateHypo(HypoName_2)
146 error = Iter_2_3.Compute(1, 1)
151 # Creation of the schema YACS
152 # ===========================
153 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
154 ScriptFile = os.path.normpath(ScriptFile)
155 DirName = Rep_Test_Resu
156 YACS_2 = Case_2.CreateYACSSchema("YACS_2", ScriptFile, DirName, MeshFile)
158 filexml = os.path.join(Rep_Test_Resu, 'YACS_2.xml')
159 error = YACS_2.WriteOnFile(filexml)
168 #========================================================================
170 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
171 assert homard is not None, "Impossible to load homard engine"
173 # Exec of HOMARD-SALOME
176 error_main = homard_exec(salome.myStudy)
178 raise Exception('Pb in homard_exec at iteration %d' %error_main )
180 raise Exception('Pb in homard_exec: '+e.message)
185 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
186 rep_test_file = "I%02d" % n_iter_test_file
188 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
189 mess_error_ref = "\nReference file: " + test_file
191 file = open (test_file, "r")
192 mess_ref = file.readlines()
195 mess_error = mess_error_ref + "\nThis file does not exist.\n"
196 raise Exception(mess_error)
198 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
199 if os.path.isfile (test_file) :
200 file = open (test_file, "r")
201 mess = file.readlines()
204 mess_error = "\nResult file: " + test_file
205 mess_error += "\nThis file does not exist.\n"
206 raise Exception(mess_error)
208 nblign = len(mess_ref)
209 if ( len(mess) != nblign ):
210 mess_error = mess_error_ref + "\nResult file: " + test_file
211 mess_error += "\nThe number of lines of the files are not the same.\n"
212 raise Exception(mess_error)
214 for num in range(nblign) :
215 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
216 message_erreur = "\nRefe : " + mess_ref[num]
217 message_erreur += "Test : " + mess[num][:-1]
218 message_erreur += "\nThe test is different from the reference."
219 raise Exception(message_erreur)
221 remove_dir(Rep_Test_Resu)
223 if salome.sg.hasDesktop():
224 salome.sg.updateObjBrowser(1)
225 iparameters.getSession().restoreVisualState(1)