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.02"
26 #========================================================================
33 #========================================================================
40 # ==================================
41 PATH_HOMARD = os.getenv('HOMARD_ROOT_DIR')
42 # Repertoire des scripts utilitaires
43 REP_PYTHON = os.path.join(PATH_HOMARD, "bin", "salome", "test", "HOMARD")
44 REP_PYTHON = os.path.normpath(REP_PYTHON)
45 sys.path.append(REP_PYTHON)
46 from test_util import remove_dir
47 from test_util import test_results
48 from test_util import saveGeometry
49 # Repertoire des donnees du test
50 REP_DATA = os.path.join(PATH_HOMARD, "share", "salome", "homardsamples")
51 REP_DATA = os.path.normpath(REP_DATA)
52 # Repertoire des resultats
54 DIRCASE = os.path.join("/tmp", TEST_NAME)
55 if ( os.path.isdir(DIRCASE) ) :
59 DIRCASE = tempfile.mkdtemp(prefix=TEST_NAME)
63 IPAR = iparameters.IParameters(salome.myStudy.GetCommonParameters("Interface Applicative", 1))
64 IPAR.append("AP_MODULES_LIST", "Homard")
66 #========================= Debut de la fonction ==================================
68 def create_geom(nom_obj, taille, verbose=False) :
70 Création de la géométrie
76 texte = "Geometrie '%s'\n" % nom_obj
77 texte += "Taille de base = %f" % taille
81 from salome.geom import geomBuilder
82 geompy = geomBuilder.New(salome.myStudy)
84 # 1. Les sommets et la première ligne
86 vertex_1 = geompy.MakeVertex( 0.*taille, 0.*taille, 0.*taille, theName = "V1")
87 vertex_2 = geompy.MakeVertex( 5.*taille, 2.*taille, 0.*taille, theName = "V2")
88 vertex_3 = geompy.MakeVertex(10.*taille, 1.*taille, 0.*taille, theName = "V3")
89 vertex_4 = geompy.MakeVertex(16.*taille, 4.*taille, 0.*taille, theName = "V4")
90 vertex_5 = geompy.MakeVertex(16.*taille, 10.*taille, 0.*taille, theName = "V5")
92 courbe_0 = geompy.MakeInterpol([vertex_1, vertex_2, vertex_3, vertex_4, vertex_5], False, False, theName="courbe_0")
94 # 2. Les sommets et la seconde ligne
96 sommet_1 = geompy.MakeVertex( 0.*taille, 0.*taille, 20.*taille, theName = "S1")
97 sommet_2 = geompy.MakeVertex( 6.*taille, -5.*taille, 20.*taille, theName = "S2")
98 sommet_3 = geompy.MakeVertex(11.*taille, -2.*taille, 20.*taille, theName = "S3")
99 sommet_4 = geompy.MakeVertex(12.*taille, 3.*taille, 20.*taille, theName = "S4")
100 sommet_5 = geompy.MakeVertex(16.*taille, 10.*taille, 20.*taille, theName = "S5")
102 courbe_1 = geompy.MakeInterpol([sommet_1, sommet_2, sommet_3, sommet_4, sommet_5], False, False, theName="courbe_1")
106 structure_g = geompy.MakeFilling([courbe_0, courbe_1], theName=nom_obj)
108 # 4. Groupes : on cherche les entites par des proximités avec des shapes bien choisies
112 shape = geompy.GetFaceNearPoint (structure_g, vertex_2)
114 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["FACE"], nom)
115 geompy.UnionList ( groupe_g, [shape] )
116 l_groupes_g.append( (nom, groupe_g, 2) )
118 shape = geompy.GetEdgeNearPoint (structure_g, vertex_2)
120 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["EDGE"], nom)
121 geompy.UnionList ( groupe_g, [shape] )
122 l_groupes_g.append( (nom, groupe_g, 1) )
124 shape = geompy.GetEdgeNearPoint (structure_g, sommet_2)
126 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["EDGE"], nom)
127 geompy.UnionList ( groupe_g, [shape] )
128 l_groupes_g.append( (nom, groupe_g, 1) )
130 shape = geompy.GetEdge (structure_g, vertex_1, sommet_1)
132 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["EDGE"], nom)
133 geompy.UnionList ( groupe_g, [shape] )
134 l_groupes_g.append( (nom, groupe_g, 1) )
136 shape = geompy.GetEdge (structure_g, vertex_5, sommet_5)
138 groupe_g = geompy.CreateGroup(structure_g, geompy.ShapeType["EDGE"], nom)
139 geompy.UnionList ( groupe_g, [shape] )
140 l_groupes_g.append( (nom, groupe_g, 1) )
142 return erreur, structure_g, l_groupes_g
144 #========================== Fin de la fonction ==================================
146 #========================= Debut de la fonction ==================================
148 def create_mail(lg_arete, structure_g, l_groupes_g, rep_mail, verbose=False) :
159 nom = structure_g.GetName()
161 texte = "Maillage de '%s'\n" % nom
162 texte += "lg_arete = %f\n" % lg_arete
163 texte += "rep_mail = '%s'" % rep_mail
167 from salome.smesh import smeshBuilder
168 smesh = smeshBuilder.New(salome.myStudy)
170 # 2. Maillage de calcul
172 maill_00 = smesh.Mesh(structure_g)
173 smesh.SetName(maill_00.GetMesh(), nom)
175 MG_CADSurf = maill_00.Triangle(algo=smeshBuilder.MG_CADSurf)
176 smesh.SetName(MG_CADSurf.GetAlgorithm(), 'MG_CADSurf')
178 MG_CADSurf_Parameters = MG_CADSurf.Parameters()
179 smesh.SetName(MG_CADSurf_Parameters, 'MG_CADSurf Triangles')
180 MG_CADSurf_Parameters.SetPhySize( lg_arete )
181 MG_CADSurf_Parameters.SetMinSize( lg_arete/20. )
182 MG_CADSurf_Parameters.SetMaxSize( lg_arete*5. )
183 MG_CADSurf_Parameters.SetChordalError( lg_arete )
184 MG_CADSurf_Parameters.SetAngleMesh( 12. )
186 # 3. Les groupes issus de la géométrie
188 for taux in l_groupes_g :
189 groupe_m = maill_00.Group(taux[1])
190 smesh.SetName(groupe_m, taux[0])
194 isDone = maill_00.Compute()
196 message += "Probleme dans le maillage de la surface."
202 ficmed = os.path.join(rep_mail,'maill.00.med')
203 texte = "Ecriture du fichier '%s'" % ficmed
206 maill_00.ExportMED( ficmed, 0, SMESH.MED_V2_2, 1 )
210 return erreur, message, ficmed
212 #========================== Fin de la fonction ==================================
214 #========================= Debut de la fonction ==================================
216 def homard_exec(nom, ficmed, xao_file, verbose=False):
218 Python script for HOMARD
225 HOMARD.SetCurrentStudy(salome.myStudy)
231 cao_name = "CAO_" + nom
232 la_frontiere = HOMARD.CreateBoundaryCAO(cao_name, xao_file)
237 print(". Hypothèses")
238 hyponame = "hypo_" + nom
239 l_hypothese = HOMARD.CreateHypothesis(hyponame)
240 l_hypothese.SetUnifRefinUnRef(1)
246 le_cas = HOMARD.CreateCase('case_'+nom, nom, ficmed)
247 le_cas.SetDirName(DIRCASE)
248 le_cas.AddBoundary(cao_name)
250 # Creation of the iterations
251 # ==========================
257 for niter in range(1, N_ITER_TEST_FILE+1):
259 print(". Itération numéro %d" % niter)
260 iter_name = "I_" + nom + "_%02d" % niter
262 l_iteration = le_cas.NextIteration(iter_name)
264 l_iteration = l_iteration.NextIteration(iter_name)
265 l_iteration.SetMeshName(nom)
266 mesh_file = os.path.join(DIRCASE, "maill.%02d.med" % niter)
267 l_iteration.SetMeshFile(mesh_file)
268 l_iteration.AssociateHypo(hyponame)
269 erreur = l_iteration.Compute(1, option)
277 message += "Erreur au calcul de l'itération %d" % erreur
279 return erreur, message
281 #========================== Fin de la fonction ==================================
292 ERREUR, STRUCTURE_G, L_GROUPES_G = create_geom(TEST_NAME, TAILLE, VERBOSE)
294 MESSAGE = "The construction of the geometry failed."
297 # B. Save the geometry
299 XAO_FILE = os.path.join(DIRCASE, TEST_NAME+".xao")
301 ERREUR = saveGeometry(XAO_FILE, TEST_NAME, "test_salome_"+TEST_NAME)
302 except Exception, eee:
304 MESSAGE = eee.message
307 MESSAGE += "Pb in saveGeometry"
312 ERREUR, MESSAGE, FICMED = create_mail(LG_ARETE, STRUCTURE_G, L_GROUPES_G, DIRCASE, VERBOSE)
316 # D. Exec of HOMARD-SALOME
318 HOMARD = salome.lcc.FindOrLoadComponent('FactoryServer', 'HOMARD')
319 assert HOMARD is not None, "Impossible to load homard engine"
320 HOMARD.SetLanguageShort("fr")
323 ERREUR, MESSAGE = homard_exec(TEST_NAME, FICMED, XAO_FILE, VERBOSE)
324 except Exception, eee:
326 MESSAGE = eee.message
329 MESSAGE += "Pb in homard_exec"
332 # E. Test of the results
334 N_REP_TEST_FILE = N_ITER_TEST_FILE
335 DESTROY_DIR = not DEBUG
336 test_results(REP_DATA, TEST_NAME, DIRCASE, N_ITER_TEST_FILE, N_REP_TEST_FILE, DESTROY_DIR)
341 MESSAGE = "\nErreur numéro %d\n" % ERREUR + MESSAGE
342 raise Exception(MESSAGE)
344 if salome.sg.hasDesktop():
345 salome.sg.updateObjBrowser(True)
346 iparameters.getSession().restoreVisualState(1)