1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2023 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
20 """Python script for HOMARD - Test test_6"""
21 __revision__ = "V2.01"
31 from salome.shaper import model
32 from salome.smesh import smeshBuilder
34 # ==================================
35 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
36 # Repertoire des scripts utilitaires
37 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
38 REP_PYTHON = os.path.normpath(REP_PYTHON)
39 sys.path.append(REP_PYTHON)
40 from test_util import get_dir
41 from test_util import test_results
42 # ==================================
44 #========================================================================
51 # Répertoires pour ce test
52 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
53 #========================================================================
55 salome.salome_init_without_session()
57 #========================================================================
58 def create_cao_smesh ():
61 structure_sh, xao_file = create_cao ()
63 error, mesh_file = create_mesh (structure_sh)
65 return error, xao_file, mesh_file
66 #========================================================================
68 #========================================================================
73 texte = "Géométrie '{}'\n".format(TEST_NAME)
74 texte += "Taille de base ={}".format(TAILLE)
78 partset = model.moduleDocument()
80 part_1 = model.addPart(partset)
81 part_1_doc = part_1.document()
84 _ = model.addPoint(part_1_doc, 0.*TAILLE, 0.*TAILLE, 0.*TAILLE)
87 _ = model.addPoint(part_1_doc, 5.*TAILLE, 2.*TAILLE, 0.*TAILLE)
90 _ = model.addPoint(part_1_doc, 10.*TAILLE, 1.*TAILLE, 0.*TAILLE)
93 _ = model.addPoint(part_1_doc, 16.*TAILLE, 4.*TAILLE, 0.*TAILLE)
96 _ = model.addPoint(part_1_doc, 16.*TAILLE, 10.*TAILLE, 0.*TAILLE)
98 ### Create interpolation
99 interpolation_1_objects = [model.selection("VERTEX", "all-in-Point_1"), \
100 model.selection("VERTEX", "all-in-Point_2"), \
101 model.selection("VERTEX", "all-in-Point_3"), \
102 model.selection("VERTEX", "all-in-Point_4"), \
103 model.selection("VERTEX", "all-in-Point_5")]
104 _ = model.addInterpolation(part_1_doc, interpolation_1_objects, False, False)
108 _ = model.addPoint(part_1_doc, 0.*TAILLE, 0.*TAILLE, 20.*TAILLE)
111 _ = model.addPoint(part_1_doc, 6.*TAILLE, -5.*TAILLE, 20.*TAILLE)
114 _ = model.addPoint(part_1_doc, 11.*TAILLE, -2.*TAILLE, 20.*TAILLE)
117 _ = model.addPoint(part_1_doc, 12.*TAILLE, 3.*TAILLE, 20.*TAILLE)
120 _ = model.addPoint(part_1_doc, 16.*TAILLE, 10.*TAILLE, 20.*TAILLE)
122 ### Create interpolation
123 interpolation_2_objects = [model.selection("VERTEX", "all-in-Point_6"), \
124 model.selection("VERTEX", "all-in-Point_7"), \
125 model.selection("VERTEX", "all-in-Point_8"), \
126 model.selection("VERTEX", "all-in-Point_9"), \
127 model.selection("VERTEX", "all-in-Point_10")]
128 _ = model.addInterpolation(part_1_doc, interpolation_2_objects, False, False)
131 structure_sh = model.addFilling(part_1_doc, [model.selection("EDGE", "Interpolation_1_1"), model.selection("EDGE", "Interpolation_2_1")])
132 structure_sh.setName(TEST_NAME)
133 structure_sh.result().setName(TEST_NAME)
136 group_1 = model.addGroup(part_1_doc, "Faces", [model.selection("FACE", TEST_NAME)])
137 group_1.setName("Voile")
138 group_1.result().setName("Voile")
141 group_2 = model.addGroup(part_1_doc, "Edges", [model.selection("EDGE", "Interpolation_1_1")])
142 group_2.setName("C_0")
143 group_2.result().setName("C_0")
146 group_3 = model.addGroup(part_1_doc, "Edges", [model.selection("EDGE", "Interpolation_2_1")])
147 group_3.setName("C_1")
148 group_3.result().setName("C_1")
151 group_4 = model.addGroup(part_1_doc, "Edges", [model.selection("EDGE", TEST_NAME+"/Edge_0_1")])
152 group_4.setName("D_0")
153 group_4.result().setName("D_0")
156 group_5 = model.addGroup(part_1_doc, "Edges", [model.selection("EDGE", TEST_NAME+"/Edge_0_3")])
157 group_5.setName("D_1")
158 group_5.result().setName("D_1")
160 xao_file = os.path.join(DIRCASE, TEST_NAME+".xao")
161 model.exportToXAO(part_1_doc, xao_file, model.selection("FACE", TEST_NAME), "GN", TEST_NAME)
165 return structure_sh, xao_file
166 #========================================================================
168 #========================================================================
169 def create_mesh (structure_sh):
172 mesh_file = os.path.join(DIRCASE, 'maill.00.med')
175 texte = "Maillage de '{}'\n".format(TEST_NAME)
176 texte += "lg_arete = {}\n".format(LG_ARETE)
181 # 1. Importation to the study
182 # ===========================
183 model.publishToShaperStudy()
184 l_aux = SHAPERSTUDY.shape(model.featureStringId(structure_sh))
186 # 2. Creation of the mesh
187 # =======================
188 smesh = smeshBuilder.New()
189 structure_m = smesh.Mesh(l_aux[0])
191 MG_CADSurf = structure_m.Triangle(algo=smeshBuilder.MG_CADSurf)
192 smesh.SetName(MG_CADSurf.GetAlgorithm(), 'MG_CADSurf')
194 MG_CADSurf_Parameters = MG_CADSurf.Parameters()
195 smesh.SetName(MG_CADSurf_Parameters, 'MG_CADSurf Triangles')
196 MG_CADSurf_Parameters.SetPhySize( LG_ARETE )
197 MG_CADSurf_Parameters.SetMinSize( LG_ARETE/20. )
198 MG_CADSurf_Parameters.SetMaxSize( LG_ARETE*5. )
199 MG_CADSurf_Parameters.SetChordalError( LG_ARETE )
200 MG_CADSurf_Parameters.SetAngleMesh( 12. )
202 # Les groupes issus de la géométrie
203 for groupe in l_aux[1:]:
204 groupe_nom = groupe.GetName()
205 if ( groupe_nom == "Voile" ):
209 _ = structure_m.GroupOnGeom(groupe,groupe_nom,shape)
212 isDone = structure_m.Compute()
219 structure_m.ExportMED(mesh_file)
220 except IOError as eee:
222 raise Exception('ExportMED() failed. ' + str(eee))
226 return error, mesh_file
227 #========================================================================
229 #========================= Debut de la fonction ==================================
231 def homard_exec(xao_file, mesh_file):
232 """Python script for HOMARD"""
237 #HOMARD.UpdateStudy()
243 cao_name = "CAO_" + TEST_NAME
244 _ = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
249 print(". Hypothèses")
250 hyponame = "hypo_" + TEST_NAME
251 l_hypothese = HOMARD.CreateHypothesis(hyponame)
252 l_hypothese.SetUnifRefinUnRef(1)
258 le_cas = HOMARD.CreateCase('case_'+TEST_NAME, TEST_NAME, mesh_file)
259 le_cas.SetDirName(DIRCASE)
260 le_cas.AddBoundary(cao_name)
262 # Creation of the iterations
263 # ==========================
269 for niter in range(1, N_ITER_TEST_FILE+1):
271 print(". Itération numéro %d" % niter)
272 iter_name = "I_" + TEST_NAME + "_%02d" % niter
274 l_iteration = le_cas.NextIteration(iter_name)
276 l_iteration = l_iteration.NextIteration(iter_name)
277 l_iteration.SetMeshName(TEST_NAME)
278 mesh_file = os.path.join(DIRCASE, "maill.%02d.med" % niter)
279 l_iteration.SetMeshFile(mesh_file)
280 l_iteration.AssociateHypo(hyponame)
281 error = l_iteration.Compute(1, option)
290 #========================== Fin de la fonction ==================================
295 ERROR, XAO_FILE, MESH_FILE = create_cao_smesh()
297 raise Exception('Pb in create_cao_smesh')
298 except RuntimeError as eee:
299 raise Exception('Pb in create_cao_smesh: '+str(eee.message))
301 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
302 assert HOMARD is not None, "Impossible to load homard engine"
303 HOMARD.SetLanguageShort("fr")
305 # Exec of HOMARD-SALOME
308 ERROR = homard_exec(XAO_FILE, MESH_FILE)
310 raise Exception('Pb in homard_exec at iteration %d' %ERROR )
311 except RuntimeError as eee:
312 raise Exception('Pb in homard_exec: '+str(eee.message))
314 # Test of the results
316 N_REP_TEST_FILE = N_ITER_TEST_FILE
317 DESTROY_DIR = not DEBUG
318 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
320 if salome.sg.hasDesktop():
321 salome.sg.updateObjBrowser()