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 2011, 2013
27 #========================================================================
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 test_results
45 # Repertoire des resultats
46 dircase = tempfile.mkdtemp()
47 # ==================================
51 ipar = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
52 ipar.append("AP_MODULES_LIST", "Homard")
54 #========================================================================
55 #========================================================================
56 def homard_exec(theStudy):
58 Python script for HOMARD
64 homard.SetCurrentStudy(theStudy)
66 # Creation of the boundaries
67 # ==========================
68 # Creation of the discrete boundary
69 Boundary_3_1 = homard.CreateBoundaryDi('courbes', 'COURBES', os.path.join(Rep_Test, Test_Name + '.fr.med'))
71 # Creation of the external cylinder
72 Boundary_3_2 = homard.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
74 # Creation of the internal cylinder
75 Boundary_3_3 = homard.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
77 # Creation of the first sphere
78 Boundary_3_4 = homard.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
80 # Creation of the second sphere
81 Boundary_3_5 = homard.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
83 # Creation of the hypotheses
84 # ==========================
86 HypoName = "Hypo_" + Test_Name
87 print "-------- Creation of the hypothesis", HypoName
88 Hypo_test_3 = homard.CreateHypothesis(HypoName)
89 Hypo_test_3.SetUnifRefinUnRef(1)
90 print HypoName, " : zones utilisées :", Hypo_test_3.GetZones()
91 print HypoName, " : champ utilisé :", Hypo_test_3.GetFieldName()
92 print HypoName, " : composantes utilisées :", Hypo_test_3.GetComps()
94 for num in range (n_boucle+1) :
96 print "-------- num =", num, "--------"
98 # Creation of the case Case_test_3
99 # ===========================
101 CaseName = "Case_" + Test_Name
102 print "-------- Creation of the case", CaseName
103 MeshFile = os.path.join(Rep_Test, Test_Name + '.00.med')
104 Case_test_3 = homard.CreateCase(CaseName, 'MOYEU', MeshFile)
105 Case_test_3.SetDirName(dircase)
106 Case_test_3.SetConfType(1)
107 Case_test_3.AddBoundaryGroup('courbes', '')
108 Case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
109 Case_test_3.AddBoundaryGroup('cyl_int', 'INT')
110 Case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
111 Case_test_3.AddBoundaryGroup('sphere_2', 'END_2')
113 # Creation of the iterations
114 # ==========================
115 # Creation of the iteration 1
116 IterName = "I_" + Test_Name + "_1"
117 print "-------- Creation of the iteration", IterName
118 Iter_test_3_1 = Case_test_3.NextIteration(IterName)
119 Iter_test_3_1.SetMeshName('MOYEU_1')
120 Iter_test_3_1.SetMeshFile(os.path.join(dircase, 'maill.01.med'))
121 Iter_test_3_1.AssociateHypo('Hypo_test_3')
122 error = Iter_test_3_1.Compute(1, 1)
127 # Creation of the iteration 2
128 IterName = "I_" + Test_Name + "_2"
129 print "-------- Creation of the iteration", IterName
130 Iter_test_3_2 = Iter_test_3_1.NextIteration(IterName)
131 Iter_test_3_2.SetMeshName('MOYEU_2')
132 Iter_test_3_2.SetMeshFile(os.path.join(dircase, 'maill.02.med'))
133 Iter_test_3_2.AssociateHypo('Hypo_test_3')
134 error = Iter_test_3_2.Compute(1, 1)
139 # Creation of the schema YACS
140 # ===========================
141 ScriptFile = os.path.join(pathHomard, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
142 ScriptFile = os.path.normpath(ScriptFile)
144 YACSName = "YACS_" + Test_Name
145 print "-------- Creation of the schema", YACSName
146 YACS_test_3 = Case_test_3.CreateYACSSchema(YACSName, ScriptFile, DirName, MeshFile)
147 YACS_test_3.SetType(2)
148 YACS_test_3.SetMaxIter(2)
149 error = YACS_test_3.Write()
156 # Destruction of the schema, sauf a la fin
157 if ( num < n_boucle ) :
158 print "-------- Destruction of the schema", YACS_test_3.GetName()
159 error = YACS_test_3.Delete(1)
163 # After the first loop, the case is deleted, except the final mesh files
164 # All the iterations are deleted
166 print "-------- Destruction of the case", Case_test_3.GetName()
167 error = Case_test_3.Delete(0)
170 # After the second loop, the iterations are deleted, with the final mesh files
172 # Recursive destruction of the iterations
173 print "-------- Recursive destruction of the iteration", Iter_test_3_1.GetName()
174 error = Iter_test_3_1.Delete(1)
178 # Destruction and creation of the hypothese
180 print "-------- Destruction of the hypothese", Hypo_test_3.GetName()
181 error = Hypo_test_3.Delete()
185 HypoName = "Hypo_test_3"
186 print "-------- Creation of the hypothesis", HypoName
187 Hypo_test_3 = homard.CreateHypothesis(HypoName)
188 Hypo_test_3.SetUnifRefinUnRef(1)
194 #========================================================================
196 homard = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
197 assert homard is not None, "Impossible to load homard engine"
198 homard.SetLanguageShort("fr")
200 # Exec of HOMARD-SALOME
203 error_main = homard_exec(salome.myStudy)
205 raise Exception('Pb in homard_exec at iteration %d' %error_main )
207 raise Exception('Pb in homard_exec: '+e.message)
209 # Test of the results
211 n_rep_test_file = n_iter_test_file*n_boucle
212 test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, True)
214 if salome.sg.hasDesktop():
215 salome.sg.updateObjBrowser(1)
216 iparameters.getSession().restoreVisualState(1)