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 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
40 # Repertoire des scripts utilitaires
41 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
42 REP_PYTHON = os.path.normpath(REP_PYTHON)
43 sys.path.append(REP_PYTHON)
44 from test_util import remove_dir
45 from test_util import test_results
46 # Repertoire des donnees du test
47 REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
48 REP_DATA = os.path.normpath(REP_DATA)
49 # Repertoire des resultats
51 DIRCASE = os.path.join("/tmp", TEST_NAME)
52 if ( os.path.isdir(DIRCASE) ) :
56 DIRCASE = tempfile.mkdtemp()
57 # ==================================
61 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
62 IPAR.append("AP_MODULES_LIST", "Homard")
64 #========================================================================
65 #========================================================================
66 def homard_exec(theStudy):
68 Python script for HOMARD
74 HOMARD.SetCurrentStudy(theStudy)
76 # Creation of the boundaries
77 # ==========================
78 # Creation of the discrete boundary
79 boundary_3_1 = HOMARD.CreateBoundaryDi('courbes', 'COURBES', os.path.join(REP_DATA, TEST_NAME + '.fr.med'))
81 # Creation of the external cylinder
82 boundary_3_2 = HOMARD.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
84 # Creation of the internal cylinder
85 boundary_3_3 = HOMARD.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
87 # Creation of the first sphere
88 boundary_3_4 = HOMARD.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
90 # Creation of the second sphere
91 boundary_3_5 = HOMARD.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
93 # Creation of the hypotheses
94 # ==========================
96 hyponame = "hypo_" + TEST_NAME
97 print "-------- Creation of the hypothesis", hyponame
98 hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
99 hypo_test_3.SetUnifRefinUnRef(1)
100 print hyponame, " : zones utilisées :", hypo_test_3.GetZones()
101 print hyponame, " : champ utilisé :", hypo_test_3.GetFieldName()
102 print hyponame, " : composantes utilisées :", hypo_test_3.GetComps()
104 for num in range (N_BOUCLE+1) :
106 print "-------- num =", num, "--------"
108 # Creation of the case case_test_3
109 # ===========================
111 casename = "case_" + TEST_NAME
112 print "-------- Creation of the case", casename
113 mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
114 case_test_3 = HOMARD.CreateCase(casename, 'MOYEU', mesh_file)
115 case_test_3.SetDirName(DIRCASE)
116 case_test_3.AddBoundaryGroup('courbes', '')
117 case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
118 case_test_3.AddBoundaryGroup('cyl_int', 'INT')
119 case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
120 case_test_3.AddBoundaryGroup('sphere_2', 'END_2')
122 # Creation of the iterations
123 # ==========================
124 # Creation of the iteration 1
125 iter_name = "I_" + TEST_NAME + "_1"
126 print "-------- Creation of the iteration", iter_name
127 iter_test_3_1 = case_test_3.NextIteration(iter_name)
128 iter_test_3_1.SetMeshName('MOYEU_1')
129 iter_test_3_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
130 iter_test_3_1.AssociateHypo('hypo_test_3')
131 error = iter_test_3_1.Compute(1, 1)
136 # Creation of the iteration 2
137 iter_name = "I_" + TEST_NAME + "_2"
138 print "-------- Creation of the iteration", iter_name
139 iter_test_3_2 = iter_test_3_1.NextIteration(iter_name)
140 iter_test_3_2.SetMeshName('MOYEU_2')
141 iter_test_3_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
142 iter_test_3_2.AssociateHypo('hypo_test_3')
143 error = iter_test_3_2.Compute(1, 1)
148 # Creation of the schema YACS
149 # ===========================
150 scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
151 scriptfile = os.path.normpath(scriptfile)
153 yacsname = "YACS_" + TEST_NAME
154 print "-------- Creation of the schema", yacsname
155 yacs_test_3 = case_test_3.CreateYACSSchema(yacsname, scriptfile, dirname, mesh_file)
156 yacs_test_3.SetType(2)
157 yacs_test_3.SetMaxIter(2)
158 error = yacs_test_3.Write()
165 # Destruction of the schema, sauf a la fin
166 if ( num < N_BOUCLE ) :
167 print "-------- Destruction of the schema", yacs_test_3.GetName()
168 error = yacs_test_3.Delete(1)
172 # After the first loop, the case is deleted, except the final mesh files
173 # All the iterations are deleted
175 print "-------- Destruction of the case", case_test_3.GetName()
176 error = case_test_3.Delete(0)
179 # After the second loop, the iterations are deleted, with the final mesh files
181 # Recursive destruction of the iterations
182 print "-------- Recursive destruction of the iteration", iter_test_3_1.GetName()
183 error = iter_test_3_1.Delete(1)
187 # Destruction and creation of the hypothese
189 print "-------- Destruction of the hypothese", hypo_test_3.GetName()
190 error = hypo_test_3.Delete()
194 hyponame = "hypo_test_3"
195 print "-------- Creation of the hypothesis", hyponame
196 hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
197 hypo_test_3.SetUnifRefinUnRef(1)
203 #========================================================================
205 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
206 assert HOMARD is not None, "Impossible to load homard engine"
207 HOMARD.SetLanguageShort("fr")
209 # Exec of HOMARD-SALOME
212 ERROR = homard_exec(salome.myStudy)
214 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
215 except Exception, eee:
216 raise Exception('Pb in homard_exec: '+eee.message)
218 # Test of the results
220 N_REP_TEST_FILE = N_ITER_TEST_FILE*N_BOUCLE
221 DESTROY_DIR = not DEBUG
222 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
224 if salome.sg.hasDesktop():
225 salome.sg.updateObjBrowser(1)
226 iparameters.getSession().restoreVisualState(1)