1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2014 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, or (at your option) any later version.
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
27 #========================================================================
30 #========================================================================
37 pathHomard = os.getenv('HOMARD_ROOT_DIR')
38 Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
39 Rep_Test = os.path.normpath(Rep_Test)
40 Rep_Test_Resu = tempfile.mktemp()
41 os.mkdir(Rep_Test_Resu)
43 sys.path.append(Rep_Test)
44 from test_util import remove_dir
48 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
49 ipar.append("AP_MODULES_LIST", "Homard")
51 #========================================================================
52 #========================================================================
53 def homard_exec(theStudy):
55 Python script for HOMARD
56 Copyright EDF-R&D 2010, 2013
62 homard.SetCurrentStudy(theStudy)
64 # Creation of the boundaries
65 # ==========================
66 # Creation of the discrete boundary Boundary_1
67 Boundary_1 = homard.CreateBoundaryDi('internal_boundary', 'plaque', os.path.join(Rep_Test, Test_Name + '.fr.med'))
69 # Creation of the hypotheses
70 # ==========================
71 # Creation of the hypothesis 1
72 HypoName_1 = "Hypo_" + Test_Name + "_1"
73 print "-------- Creation of the hypothesis", HypoName_1
74 Hypo_test_2_1 = homard.CreateHypothesis(HypoName_1)
75 Hypo_test_2_1.SetAdapRefinUnRef(-1, 1, 0)
76 Hypo_test_2_1.AddGroup('EG')
77 Hypo_test_2_1.AddGroup('BANDE')
78 print HypoName_1, " : zones utilisées :", Hypo_test_2_1.GetZones()
79 print HypoName_1, " : champ utilisé :", Hypo_test_2_1.GetFieldName()
80 print HypoName_1, " : composantes utilisées :", Hypo_test_2_1.GetComps()
81 if ( len (Hypo_test_2_1.GetFieldName()) > 0 ) :
82 print ".. caractéristiques de l'adaptation :", Hypo_test_2_1.GetField()
84 # Creation of the hypothesis 2
85 HypoName_2 = "Hypo_" + Test_Name + "_2"
86 print "-------- Creation of the hypothesis", HypoName_2
87 Hypo_test_2_2 = homard.CreateHypothesis(HypoName_2)
88 Hypo_test_2_2.SetAdapRefinUnRef(-1, 1, 0)
89 Hypo_test_2_2.AddGroup('M_D')
90 print HypoName_2, " : zones utilisées :", Hypo_test_2_2.GetZones()
91 print HypoName_2, " : champ utilisé :", Hypo_test_2_2.GetFieldName()
92 print HypoName_2, " : composantes utilisées :", Hypo_test_2_2.GetComps()
93 if ( len (Hypo_test_2_2.GetFieldName()) > 0 ) :
94 print ".. caractéristiques de l'adaptation :", Hypo_test_2_2.GetField()
96 # Creation of the cases
97 # =====================
98 # Creation of the case
99 CaseName = "Case_" + Test_Name
100 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
101 Case_test_2 = homard.CreateCase(CaseName, 'PLAQUE_0', MeshFile)
102 Case_test_2.SetDirName(Rep_Test_Resu)
103 Case_test_2.SetConfType(1)
104 Case_test_2.AddBoundaryGroup('internal_boundary', '')
106 # Creation of the iterations
107 # ==========================
108 # Creation of the iteration 1
109 IterName = "I_" + Test_Name + "_1"
110 Iter_test_2_1 = Case_test_2.NextIteration(IterName)
111 Iter_test_2_1.SetMeshName('PLAQUE_1')
112 Iter_test_2_1.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.01.med'))
113 Iter_test_2_1.AssociateHypo(HypoName_1)
114 error = Iter_test_2_1.Compute(1, 1)
119 # Creation of the iteration 2
120 IterName = "I_" + Test_Name + "_2"
121 Iter_test_2_2 = Iter_test_2_1.NextIteration(IterName)
122 Iter_test_2_2.SetMeshName('PLAQUE_2')
123 Iter_test_2_2.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.02.med'))
124 Iter_test_2_2.AssociateHypo(HypoName_1)
125 error = Iter_test_2_2.Compute(1, 1)
130 # Creation of the iteration 3
131 IterName = "I_" + Test_Name + "_3"
132 Iter_test_2_3 = Iter_test_2_2.NextIteration(IterName)
133 Iter_test_2_3.SetMeshName('PLAQUE_3')
134 Iter_test_2_3.SetMeshFile(os.path.join(Rep_Test_Resu, 'maill.03.med'))
135 Iter_test_2_3.AssociateHypo(HypoName_2)
136 error = Iter_test_2_3.Compute(1, 1)
141 # Creation of the schema YACS
142 # ===========================
143 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script.py")
144 ScriptFile = os.path.normpath(ScriptFile)
145 DirName = Rep_Test_Resu
146 YACS_test_2 = Case_test_2.CreateYACSSchema("YACS_test_2", ScriptFile, DirName, MeshFile)
147 YACS_test_2.SetType(1)
148 filexml = os.path.join(Rep_Test_Resu, 'YACS_test_2.xml')
149 error = YACS_test_2.WriteOnFile(filexml)
158 #========================================================================
160 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
161 assert homard is not None, "Impossible to load homard engine"
162 homard.SetLanguageShort("fr")
164 # Exec of HOMARD-SALOME
167 error_main = homard_exec(salome.myStudy)
169 raise Exception('Pb in homard_exec at iteration %d' %error_main )
171 raise Exception('Pb in homard_exec: '+e.message)
176 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
177 rep_test_file = "I%02d" % n_iter_test_file
179 test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
180 mess_error_ref = "\nReference file: " + test_file
182 file = open (test_file, "r")
183 mess_ref = file.readlines()
186 mess_error = mess_error_ref + "\nThis file does not exist.\n"
187 raise Exception(mess_error)
189 test_file = os.path.join(Rep_Test_Resu, rep_test_file, test_file_suff)
190 if os.path.isfile (test_file) :
191 file = open (test_file, "r")
192 mess = file.readlines()
195 mess_error = "\nResult file: " + test_file
196 mess_error += "\nThis file does not exist.\n"
197 raise Exception(mess_error)
199 nblign = len(mess_ref)
200 if ( len(mess) != nblign ):
201 mess_error = mess_error_ref + "\nResult file: " + test_file
202 mess_error += "\nThe number of lines of the files are not the same.\n"
203 raise Exception(mess_error)
205 for num in range(nblign) :
206 if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
207 message_erreur = "\nRefe : " + mess_ref[num]
208 message_erreur += "Test : " + mess[num][:-1]
209 message_erreur += "\nThe test is different from the reference."
210 raise Exception(message_erreur)
212 remove_dir(Rep_Test_Resu)
214 if salome.sg.hasDesktop():
215 salome.sg.updateObjBrowser(1)
216 iparameters.getSession().restoreVisualState(1)