1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2015 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
26 #========================================================================
31 #========================================================================
38 # ==================================
39 pathHomard = os.getenv('HOMARD_ROOT_DIR')
40 # Repertoire des donnees du test
41 Rep_Test = os.path.join(pathHomard, "share", "salome", "resources", "homard")
42 Rep_Test = os.path.normpath(Rep_Test)
43 sys.path.append(Rep_Test)
44 from test_util import remove_dir
45 from test_util import test_results
46 # Repertoire des resultats
48 dircase = os.path.join("/tmp", Test_Name)
49 if ( os.path.isdir(dircase) ) :
53 dircase = tempfile.mkdtemp()
54 # ==================================
58 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
59 ipar.append("AP_MODULES_LIST", "Homard")
61 #========================================================================
62 #========================================================================
63 def homard_exec(theStudy):
65 Python script for HOMARD
71 homard.SetCurrentStudy(theStudy)
73 # Creation of the boundaries
74 # ==========================
75 # Creation of the discrete boundary
76 Boundary_3_1 = homard.CreateBoundaryDi('courbes', 'COURBES', os.path.join(Rep_Test, Test_Name + '.fr.med'))
78 # Creation of the external cylinder
79 Boundary_3_2 = homard.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
81 # Creation of the internal cylinder
82 Boundary_3_3 = homard.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
84 # Creation of the first sphere
85 Boundary_3_4 = homard.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
87 # Creation of the second sphere
88 Boundary_3_5 = homard.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
90 # Creation of the hypotheses
91 # ==========================
93 HypoName = "Hypo_" + Test_Name
94 print "-------- Creation of the hypothesis", HypoName
95 Hypo_test_3 = homard.CreateHypothesis(HypoName)
96 Hypo_test_3.SetUnifRefinUnRef(1)
97 print HypoName, " : zones utilisées :", Hypo_test_3.GetZones()
98 print HypoName, " : champ utilisé :", Hypo_test_3.GetFieldName()
99 print HypoName, " : composantes utilisées :", Hypo_test_3.GetComps()
101 for num in range (n_boucle+1) :
103 print "-------- num =", num, "--------"
105 # Creation of the case Case_test_3
106 # ===========================
108 CaseName = "Case_" + Test_Name
109 print "-------- Creation of the case", CaseName
110 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
111 Case_test_3 = homard.CreateCase(CaseName, 'MOYEU', MeshFile)
112 Case_test_3.SetDirName(dircase)
113 Case_test_3.AddBoundaryGroup('courbes', '')
114 Case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
115 Case_test_3.AddBoundaryGroup('cyl_int', 'INT')
116 Case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
117 Case_test_3.AddBoundaryGroup('sphere_2', 'END_2')
119 # Creation of the iterations
120 # ==========================
121 # Creation of the iteration 1
122 IterName = "I_" + Test_Name + "_1"
123 print "-------- Creation of the iteration", IterName
124 Iter_test_3_1 = Case_test_3.NextIteration(IterName)
125 Iter_test_3_1.SetMeshName('MOYEU_1')
126 Iter_test_3_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
127 Iter_test_3_1.AssociateHypo('Hypo_test_3')
128 error = Iter_test_3_1.Compute(1, 1)
133 # Creation of the iteration 2
134 IterName = "I_" + Test_Name + "_2"
135 print "-------- Creation of the iteration", IterName
136 Iter_test_3_2 = Iter_test_3_1.NextIteration(IterName)
137 Iter_test_3_2.SetMeshName('MOYEU_2')
138 Iter_test_3_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
139 Iter_test_3_2.AssociateHypo('Hypo_test_3')
140 error = Iter_test_3_2.Compute(1, 1)
145 # Creation of the schema YACS
146 # ===========================
147 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
148 ScriptFile = os.path.normpath(ScriptFile)
150 YACSName = "YACS_" + Test_Name
151 print "-------- Creation of the schema", YACSName
152 YACS_test_3 = Case_test_3.CreateYACSSchema(YACSName, ScriptFile, DirName, MeshFile)
153 YACS_test_3.SetType(2)
154 YACS_test_3.SetMaxIter(2)
155 error = YACS_test_3.Write()
162 # Destruction of the schema, sauf a la fin
163 if ( num < n_boucle ) :
164 print "-------- Destruction of the schema", YACS_test_3.GetName()
165 error = YACS_test_3.Delete(1)
169 # After the first loop, the case is deleted, except the final mesh files
170 # All the iterations are deleted
172 print "-------- Destruction of the case", Case_test_3.GetName()
173 error = Case_test_3.Delete(0)
176 # After the second loop, the iterations are deleted, with the final mesh files
178 # Recursive destruction of the iterations
179 print "-------- Recursive destruction of the iteration", Iter_test_3_1.GetName()
180 error = Iter_test_3_1.Delete(1)
184 # Destruction and creation of the hypothese
186 print "-------- Destruction of the hypothese", Hypo_test_3.GetName()
187 error = Hypo_test_3.Delete()
191 HypoName = "Hypo_test_3"
192 print "-------- Creation of the hypothesis", HypoName
193 Hypo_test_3 = homard.CreateHypothesis(HypoName)
194 Hypo_test_3.SetUnifRefinUnRef(1)
200 #========================================================================
202 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
203 assert homard is not None, "Impossible to load homard engine"
204 homard.SetLanguageShort("fr")
206 # Exec of HOMARD-SALOME
209 error_main = homard_exec(salome.myStudy)
211 raise Exception('Pb in homard_exec at iteration %d' %error_main )
213 raise Exception('Pb in homard_exec: '+e.message)
215 # Test of the results
217 n_rep_test_file = n_iter_test_file*n_boucle
218 destroy_dir = not debug
219 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir)
221 if salome.sg.hasDesktop():
222 salome.sg.updateObjBrowser(1)
223 iparameters.getSession().restoreVisualState(1)