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 print "-------- Creation of the case", TEST_NAME
112 mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
113 case_test_3 = HOMARD.CreateCase(TEST_NAME, 'MOYEU', mesh_file)
114 case_test_3.SetDirName(DIRCASE)
115 case_test_3.AddBoundaryGroup('courbes', '')
116 case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
117 case_test_3.AddBoundaryGroup('cyl_int', 'INT')
118 case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
119 case_test_3.AddBoundaryGroup('sphere_2', 'END_2')
121 # Creation of the iterations
122 # ==========================
123 # Creation of the iteration 1
124 iter_name = "I_" + TEST_NAME + "_1"
125 print "-------- Creation of the iteration", iter_name
126 iter_test_3_1 = case_test_3.NextIteration(iter_name)
127 iter_test_3_1.SetMeshName('MOYEU_1')
128 iter_test_3_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
129 iter_test_3_1.AssociateHypo('hypo_test_3')
130 error = iter_test_3_1.Compute(1, 1)
135 # Creation of the iteration 2
136 iter_name = "I_" + TEST_NAME + "_2"
137 print "-------- Creation of the iteration", iter_name
138 iter_test_3_2 = iter_test_3_1.NextIteration(iter_name)
139 iter_test_3_2.SetMeshName('MOYEU_2')
140 iter_test_3_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
141 iter_test_3_2.AssociateHypo('hypo_test_3')
142 error = iter_test_3_2.Compute(1, 1)
147 # Creation of the schema YACS
148 # ===========================
149 scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
150 scriptfile = os.path.normpath(scriptfile)
152 yacsname = "YACS_" + TEST_NAME
153 print "-------- Creation of the schema", yacsname
154 yacs_test_3 = case_test_3.CreateYACSSchema(yacsname, scriptfile, dirname, mesh_file)
155 yacs_test_3.SetType(2)
156 yacs_test_3.SetMaxIter(2)
157 error = yacs_test_3.Write()
164 # Destruction of the schema, sauf a la fin
165 if ( num < N_BOUCLE ) :
166 print "-------- Destruction of the schema", yacs_test_3.GetName()
167 error = yacs_test_3.Delete(1)
171 # After the first loop, the case is deleted, except the final mesh files
172 # All the iterations are deleted
174 print "-------- Destruction of the case", case_test_3.GetName()
175 error = case_test_3.Delete(0)
178 # After the second loop, the iterations are deleted, with the final mesh files
180 # Recursive destruction of the iterations
181 print "-------- Recursive destruction of the iteration", iter_test_3_1.GetName()
182 error = iter_test_3_1.Delete(1)
186 # Destruction and creation of the hypothese
188 print "-------- Destruction of the hypothese", hypo_test_3.GetName()
189 error = hypo_test_3.Delete()
193 hyponame = "hypo_test_3"
194 print "-------- Creation of the hypothesis", hyponame
195 hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
196 hypo_test_3.SetUnifRefinUnRef(1)
202 #========================================================================
204 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
205 assert HOMARD is not None, "Impossible to load homard engine"
206 HOMARD.SetLanguageShort("fr")
208 # Exec of HOMARD-SALOME
211 ERROR = homard_exec(salome.myStudy)
213 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
214 except Exception, eee:
215 raise Exception('Pb in homard_exec: '+eee.message)
217 # Test of the results
219 N_REP_TEST_FILE = N_ITER_TEST_FILE*N_BOUCLE
220 DESTROY_DIR = not DEBUG
221 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
223 if salome.sg.hasDesktop():
224 salome.sg.updateObjBrowser(1)
225 iparameters.getSession().restoreVisualState(1)