1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2016 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
24 __revision__ = "V4.04"
26 #========================================================================
31 #========================================================================
37 # ==================================
38 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
39 # Repertoire des scripts utilitaires
40 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
41 REP_PYTHON = os.path.normpath(REP_PYTHON)
42 sys.path.append(REP_PYTHON)
43 from test_util import get_dir
44 from test_util import test_results
45 # ==================================
46 # Répertoires pour ce test
47 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
48 # ==================================
52 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
53 IPAR.append("AP_MODULES_LIST", "Homard")
55 #========================================================================
56 #========================================================================
59 Python script for HOMARD
67 # Creation of the boundaries
68 # ==========================
69 # Creation of the discrete boundary
70 boundary_3_1 = HOMARD.CreateBoundaryDi('courbes', 'COURBES', os.path.join(REP_DATA, TEST_NAME + '.fr.med'))
72 # Creation of the external cylinder
73 boundary_3_2 = HOMARD.CreateBoundaryCylinder('cyl_ext', 50.0, 25., -25., 1., 0., 0., 100.)
75 # Creation of the internal cylinder
76 boundary_3_3 = HOMARD.CreateBoundaryCylinder('cyl_int', 50.0, 25., -25., 1., 0., 0., 50.)
78 # Creation of the first sphere
79 boundary_3_4 = HOMARD.CreateBoundarySphere('sphere_1', 50.0, 25., -25., 100.)
81 # Creation of the second sphere
82 boundary_3_5 = HOMARD.CreateBoundarySphere('sphere_2', 450.0, 25., -25., 100.)
84 # Creation of the hypotheses
85 # ==========================
87 hyponame = "hypo_" + TEST_NAME
88 print("-------- Creation of the hypothesis", hyponame)
89 hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
90 hypo_test_3.SetUnifRefinUnRef(1)
91 print(hyponame, " : zones utilisées :", hypo_test_3.GetZones())
92 print(hyponame, " : champ utilisé :", hypo_test_3.GetFieldName())
93 print(hyponame, " : composantes utilisées :", hypo_test_3.GetComps())
95 for num in range (N_BOUCLE+1) :
97 print("-------- num =", num, "--------")
99 # Creation of the case case_test_3
100 # ===========================
102 print("-------- Creation of the case", TEST_NAME)
103 mesh_file = os.path.join(REP_DATA, TEST_NAME + '.00.med')
104 case_test_3 = HOMARD.CreateCase(TEST_NAME, 'MOYEU', mesh_file)
105 case_test_3.SetDirName(DIRCASE)
106 case_test_3.AddBoundary('courbes')
107 case_test_3.AddBoundaryGroup('cyl_ext', 'EXT')
108 case_test_3.AddBoundaryGroup('cyl_int', 'INT')
109 case_test_3.AddBoundaryGroup('sphere_1', 'END_1')
110 case_test_3.AddBoundaryGroup('sphere_2', 'END_2')
112 # Creation of the iterations
113 # ==========================
114 # Creation of the iteration 1
115 iter_name = "I_" + TEST_NAME + "_1"
116 print("-------- Creation of the iteration", iter_name)
117 iter_test_3_1 = case_test_3.NextIteration(iter_name)
118 iter_test_3_1.SetMeshName('MOYEU_1')
119 iter_test_3_1.SetMeshFile(os.path.join(DIRCASE, 'maill.01.med'))
120 iter_test_3_1.AssociateHypo('hypo_test_3')
121 error = iter_test_3_1.Compute(1, 1)
126 # Creation of the iteration 2
127 iter_name = "I_" + TEST_NAME + "_2"
128 print("-------- Creation of the iteration", iter_name)
129 iter_test_3_2 = iter_test_3_1.NextIteration(iter_name)
130 iter_test_3_2.SetMeshName('MOYEU_2')
131 iter_test_3_2.SetMeshFile(os.path.join(DIRCASE, 'maill.02.med'))
132 iter_test_3_2.AssociateHypo('hypo_test_3')
133 error = iter_test_3_2.Compute(1, 1)
138 # Creation of the schema YACS
139 # ===========================
140 scriptfile = os.path.join(PATH_HOMARD, "share", "doc", "salome", "gui", "HOMARD", "en", "_downloads", "yacs_script_test.py")
141 scriptfile = os.path.normpath(scriptfile)
143 yacsname = "YACS_" + TEST_NAME
144 print("-------- Creation of the schema", yacsname)
145 yacs_test_3 = case_test_3.CreateYACSSchema(yacsname, scriptfile, dirname, mesh_file)
146 yacs_test_3.SetType(2)
147 yacs_test_3.SetMaxIter(2)
148 error = yacs_test_3.Write()
155 # Destruction of the schema, sauf a la fin
156 if ( num < N_BOUCLE ) :
157 print("-------- Destruction of the schema", yacs_test_3.GetName())
158 error = yacs_test_3.Delete(1)
162 # After the first loop, the case is deleted, except the final mesh files
163 # All the iterations are deleted
165 print("-------- Destruction of the case", case_test_3.GetName())
166 error = case_test_3.Delete(0)
169 # After the second loop, the iterations are deleted, with the final mesh files
171 # Recursive destruction of the iterations
172 print("-------- Recursive destruction of the iteration", iter_test_3_1.GetName())
173 error = iter_test_3_1.Delete(1)
177 # Destruction and creation of the hypothese
179 print("-------- Destruction of the hypothese", hypo_test_3.GetName())
180 error = hypo_test_3.Delete()
184 hyponame = "hypo_test_3"
185 print("-------- Creation of the hypothesis", hyponame)
186 hypo_test_3 = HOMARD.CreateHypothesis(hyponame)
187 hypo_test_3.SetUnifRefinUnRef(1)
193 #========================================================================
195 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
196 assert HOMARD is not None, "Impossible to load homard engine"
197 HOMARD.SetLanguageShort("fr")
199 # Exec of HOMARD-SALOME
202 ERROR = homard_exec()
204 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
205 except RuntimeError as eee:
206 raise Exception('Pb in homard_exec: '+str(eee.message))
208 # Test of the results
210 N_REP_TEST_FILE = N_ITER_TEST_FILE*N_BOUCLE
211 DESTROY_DIR = not DEBUG
212 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
214 if salome.sg.hasDesktop():
215 salome.sg.updateObjBrowser()
216 iparameters.getSession().restoreVisualState(1)