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__ = "V1.04"
26 #========================================================================
33 #========================================================================
39 # ==================================
40 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
41 # Repertoire des scripts utilitaires
42 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
43 REP_PYTHON = os.path.normpath(REP_PYTHON)
44 sys.path.append(REP_PYTHON)
45 from test_util import saveGeometry
46 from test_util import get_dir
47 from test_util import test_results
48 # ==================================
49 # Répertoires pour ce test
50 REP_DATA, DIRCASE = get_dir(PATH_HOMARD, TEST_NAME, DEBUG)
51 # ==================================
55 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
56 IPAR.append("AP_MODULES_LIST", "Homard")
58 #========================= Debut de la fonction ==================================
60 def create_geom(nom_obj, taille, verbose=False) :
62 Création de la géométrie
68 texte = "Geometrie '%s'\n" % nom_obj
69 texte += "Taille de base = %f" % taille
73 from salome.geom import geomBuilder
74 geompy = geomBuilder.New(salome.myStudy)
76 # 1. Les sommets et la première ligne
78 vertex_1 = geompy.MakeVertex( 0.*taille, 0.*taille, 0.*taille, theName = "V1")
79 vertex_2 = geompy.MakeVertex( 5.*taille, 2.*taille, 0.*taille, theName = "V2")
80 vertex_3 = geompy.MakeVertex(10.*taille, 1.*taille, 0.*taille, theName = "V3")
81 vertex_4 = geompy.MakeVertex(16.*taille, 4.*taille, 0.*taille, theName = "V4")
82 vertex_5 = geompy.MakeVertex(16.*taille, 10.*taille, 0.*taille, theName = "V5")
84 courbe_0 = geompy.MakeInterpol([vertex_1, vertex_2, vertex_3, vertex_4, vertex_5], False, False, theName="courbe_0")
86 # 2. Les sommets et la seconde ligne
88 sommet_1 = geompy.MakeVertex( 0.*taille, 0.*taille, 20.*taille, theName = "S1")
89 sommet_2 = geompy.MakeVertex( 6.*taille, -5.*taille, 20.*taille, theName = "S2")
90 sommet_3 = geompy.MakeVertex(11.*taille, -2.*taille, 20.*taille, theName = "S3")
91 sommet_4 = geompy.MakeVertex(12.*taille, 3.*taille, 20.*taille, theName = "S4")
92 sommet_5 = geompy.MakeVertex(16.*taille, 10.*taille, 20.*taille, theName = "S5")
94 courbe_1 = geompy.MakeInterpol([sommet_1, sommet_2, sommet_3, sommet_4, sommet_5], False, False, theName="courbe_1")
98 structure_g = geompy.MakeFilling([courbe_0, courbe_1], theName=nom_obj)
100 # 4. Groupes : on cherche les entites par des proximités avec des shapes bien choisies
104 shape = geompy.GetFaceNearPoint (structure_g, vertex_2)
106 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["FACE"], nom)
107 geompy.UnionList ( groupe_g, [shape] )
108 l_groupes_g.append( (nom, groupe_g, 2) )
110 shape = geompy.GetEdgeNearPoint (structure_g, vertex_2)
112 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["EDGE"], nom)
113 geompy.UnionList ( groupe_g, [shape] )
114 l_groupes_g.append( (nom, groupe_g, 1) )
116 shape = geompy.GetEdgeNearPoint (structure_g, sommet_2)
118 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["EDGE"], nom)
119 geompy.UnionList ( groupe_g, [shape] )
120 l_groupes_g.append( (nom, groupe_g, 1) )
122 shape = geompy.GetEdge (structure_g, vertex_1, sommet_1)
124 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["EDGE"], nom)
125 geompy.UnionList ( groupe_g, [shape] )
126 l_groupes_g.append( (nom, groupe_g, 1) )
128 shape = geompy.GetEdge (structure_g, vertex_5, sommet_5)
130 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["EDGE"], nom)
131 geompy.UnionList ( groupe_g, [shape] )
132 l_groupes_g.append( (nom, groupe_g, 1) )
134 return erreur, structure_g, l_groupes_g
136 #========================== Fin de la fonction ==================================
138 #========================= Debut de la fonction ==================================
140 def create_mail(lg_arete, structure_g, l_groupes_g, rep_mail, verbose=False) :
151 nom = structure_g.GetName()
153 texte = "Maillage de '%s'\n" % nom
154 texte += "lg_arete = %f\n" % lg_arete
155 texte += "rep_mail = '%s'" % rep_mail
159 from salome.smesh import smeshBuilder
160 smesh = smeshBuilder.New(salome.myStudy)
162 # 2. Maillage de calcul
164 maill_00 = smesh.Mesh(structure_g)
165 smesh.SetName(maill_00.GetMesh(), nom)
167 MG_CADSurf = maill_00.Triangle(algo=smeshBuilder.MG_CADSurf)
168 smesh.SetName(MG_CADSurf.GetAlgorithm(), 'MG_CADSurf')
170 MG_CADSurf_Parameters = MG_CADSurf.Parameters()
171 smesh.SetName(MG_CADSurf_Parameters, 'MG_CADSurf Triangles')
172 MG_CADSurf_Parameters.SetPhySize( lg_arete )
173 MG_CADSurf_Parameters.SetMinSize( lg_arete/20. )
174 MG_CADSurf_Parameters.SetMaxSize( lg_arete*5. )
175 MG_CADSurf_Parameters.SetChordalError( lg_arete )
176 MG_CADSurf_Parameters.SetAngleMesh( 12. )
178 # 3. Les groupes issus de la géométrie
180 for taux in l_groupes_g :
181 groupe_m = maill_00.Group(taux[1])
182 smesh.SetName(groupe_m, taux[0])
186 isDone = maill_00.Compute()
188 message += "Probleme dans le maillage de la surface."
194 ficmed = os.path.join(rep_mail,'maill.00.med')
195 texte = "Ecriture du fichier '%s'" % ficmed
198 maill_00.ExportMED( ficmed, 0, SMESH.MED_V2_2, 1 )
202 return erreur, message, ficmed
204 #========================== Fin de la fonction ==================================
206 #========================= Debut de la fonction ==================================
208 def homard_exec(nom, ficmed, xao_file, verbose=False):
210 Python script for HOMARD
217 HOMARD.SetCurrentStudy(salome.myStudy)
223 cao_name = "CAO_" + nom
224 la_frontiere = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
229 print(". Hypothèses")
230 hyponame = "hypo_" + nom
231 l_hypothese = HOMARD.CreateHypothesis(hyponame)
232 l_hypothese.SetUnifRefinUnRef(1)
238 le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
239 le_cas.SetDirName(DIRCASE)
240 le_cas.AddBoundary(cao_name)
242 # Creation of the iterations
243 # ==========================
249 for niter in range(1, N_ITER_TEST_FILE+1):
251 print(". Itération numéro %d" % niter)
252 iter_name = "I_" + nom + "_%02d" % niter
254 l_iteration = le_cas.NextIteration(iter_name)
256 l_iteration = l_iteration.NextIteration(iter_name)
257 l_iteration.SetMeshName(nom)
258 mesh_file = os.path.join(DIRCASE, "maill.%02d.med" % niter)
259 l_iteration.SetMeshFile(mesh_file)
260 l_iteration.AssociateHypo(hyponame)
261 erreur = l_iteration.Compute(1, option)
269 message += "Erreur au calcul de l'itération %d" % erreur
271 return erreur, message
273 #========================== Fin de la fonction ==================================
284 ERREUR, STRUCTURE_G, L_GROUPES_G = create_geom(TEST_NAME, TAILLE, VERBOSE)
286 MESSAGE = "The construction of the geometry failed."
289 # B. Save the geometry
291 XAO_FILE = os.path.join(DIRCASE, TEST_NAME+".xao")
293 ERREUR = saveGeometry(XAO_FILE, TEST_NAME, "test_salome_"+TEST_NAME)
294 except IOError as eee:
296 MESSAGE = str(eee.message)
299 MESSAGE += "Pb in saveGeometry"
304 ERREUR, MESSAGE, FICMED = create_mail(LG_ARETE, STRUCTURE_G, L_GROUPES_G, DIRCASE, VERBOSE)
308 # D. Exec of HOMARD-SALOME
310 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
311 assert HOMARD is not None, "Impossible to load homard engine"
312 HOMARD.SetLanguageShort("fr")
315 ERREUR, MESSAGE = homard_exec(TEST_NAME, FICMED, XAO_FILE, VERBOSE)
316 except RuntimeError as eee:
318 MESSAGE = str(eee.message)
321 MESSAGE += "Pb in homard_exec"
324 # E. Test of the results
326 N_REP_TEST_FILE = N_ITER_TEST_FILE
327 DESTROY_DIR = not DEBUG
328 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
333 MESSAGE = "\nErreur numéro %d\n" % ERREUR + MESSAGE
334 raise Exception(MESSAGE)
336 if salome.sg.hasDesktop():
337 salome.sg.updateObjBrowser(True)
338 iparameters.getSession().restoreVisualState(1)