Exemples

On trouvera ici les instructions python pour quelques configurations caractéristiques. Les fichiers de données associés sont téléchargeables. Il faut penser à adapter la valeur de la variable data_dir : c’est le répertoire dans lequel les fichiers med auront été enregistrés. C’est dans le répertoire dircase que seront écrits les fichiers résultant des adaptations successives. Ce répertoire est créé par défaut dans /tmp.

Chargement du module HOMARD

Le chargement du module HOMARD se fait de manière analogue aux autres modules.

import HOMARD
homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')
homard.UpdateStudy()

Pour utiliser le module HOMARD au sein d’un schéma YACS distribué, le chargement se fait ainsi :

import HOMARD
my_container.load_component_Library('HOMARD')
homard = my_container.create_component_instance('HOMARD',0)
homard.UpdateStudy()

Raffinement uniforme

On fera ici trois raffinements uniformes successifs du maillage contenu dans le fichier tutorial_1.00.med. Quelques remarques :
  • la même hypothèse est utilisée à chaque itération

  • le maillage produit porte toujours le même nom. Cela ne pose pas de problème car il est stocké dans des fichiers différents.

#
# Hypotheses
# ==========
l_hypothese = homard.CreateHypothesis('hypo_1')
l_hypothese.SetUnifRefinUnRef(1)
#
# Cas
# ===
le_cas = homard.CreateCase('Case_1', 'MAILL', os.path.join(DATA_TUTORIAL, "tutorial_1.00.med"))
le_cas.SetDirName(DIRCASE)
#
# Iterations
# ==========
# Iteration "iter_1_1"
iter_1_1 = le_cas.NextIteration('iter_1_1')
iter_1_1.SetMeshName('MESH')
iter_1_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
iter_1_1.AssociateHypo('hypo_1')
erreur = iter_1_1.Compute(1, 2)

# Iteration "iter_1_2"
iter_1_2 = iter_1_1.NextIteration('iter_1_2')
iter_1_2.SetMeshName('MESH')
iter_1_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
iter_1_2.AssociateHypo('hypo_1')
erreur = iter_1_2.Compute(1, 2)

# Iteration "iter_1_3"
iter_1_3 = iter_1_2.NextIteration('iter_1_3')
iter_1_3.SetMeshName('MESH')
iter_1_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
iter_1_3.AssociateHypo('hypo_1')
erreur = iter_1_3.Compute(1, 2)
#

Raffinement par des zones

On procède ici au raffinement selon des zones. Pour passer du maillage initial au maillage “M_1”, on utilise une boîte encadrant le plan z=1 et une sphère centrée sur l’origine de rayon 1.05. Puis pour passer du maillage “M_1” au maillage “M_2”, on remplace la sphère par une boîte encadrant le cube de côté 0.5, pointant sur l’origine et on déraffine les mailles contenues dans la toute première zone.

#
# Creation des zones
# ==================
# Box "Zone_0"
Zone_0 = homard.CreateZoneBox ('Zone_0', -0.1, 1.1, -0.1, 1.1, 0.9, 1.1)
#
# Sphere "Zone_1"
Zone_1 = homard.CreateZoneSphere ('Zone_1', 0., 0., 0., 1.05)
#
# Box "Zone_2"
Zone_2 = homard.CreateZoneBox ('Zone_2', -0.1, 0.51, -0.1, 0.51, -0.1, 0.51)
#
# Hypothese "hypo_2"
# ==================
l_hypothese = homard.CreateHypothesis('hypo_2')
l_hypothese.AddZone('Zone_1', 1)
l_hypothese.AddZone('Zone_0', 1)
#
# Hypothese "hypo_2_bis"
# ======================
l_hypothese_bis = homard.CreateHypothesis('hypo_2_bis')
l_hypothese_bis.AddZone('Zone_0', -1)
l_hypothese_bis.AddZone('Zone_2', 1)
#
# Cas
# ===
le_cas = homard.CreateCase('Case_2', 'MZERO', os.path.join(DATA_TUTORIAL, "tutorial_2.00.med"))
le_cas.SetDirName(DIRCASE)
#
# Iteration "iter_2_1"
# ====================
iter_2_1 = le_cas.NextIteration('iter_2_1')
iter_2_1.SetMeshName('M_1')
iter_2_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
iter_2_1.AssociateHypo('hypo_2')
erreur = iter_2_1.Compute(1, 2)
#
# Iteration "iter_2_2"
# ====================
iter_2_2 = iter_2_1.NextIteration('iter_2_2')
iter_2_2.SetMeshName('M_2')
iter_2_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
iter_2_2.AssociateHypo('hypo_2_bis')
erreur = iter_2_2.Compute(1, 2)
#

Raffinement selon un champ

On procède ici au raffinement selon un champ. Les hypothèses servent à définir le nom du champ et les seuils de raffinement/déraffinement. La donnée du fichier et des instants est faite dans l’itération. Des champs sur les noeuds ou sur les mailles sont interpolés. Pour adapter le maillage H_1 issu de l’itération Iter_1, deux variantes sont appliquées. Dans la première, Iter_2, le champ est un champ scalaire d’indicateurs d’erreur et on découpe les 1.5% de mailles où l’erreur est la plus grande. Dans la seconde variante, Iter_2_bis, on se base sur un champ vectoriel et on examine le saut de ce vecteur entre une maille et ses voisines : on découpera là où la norme infinie de ce saut est supérieure au seuil absolu de 0.0001.

#
# Hypothese "hypo_0vers1"
# =======================
hypo_0vers1 = homard.CreateHypothesis('hypo_0vers1')
# Characterization of the field
hypo_0vers1.SetField('SOLU_0__QIRE_ELEM_SIGM__________')
hypo_0vers1.SetUseComp(0)
hypo_0vers1.AddComp('ERREST          ')
hypo_0vers1.SetRefinThr(3, 1.0)
hypo_0vers1.SetTypeFieldInterp(2)
hypo_0vers1.AddFieldInterp('SOLU_0__DEPL____________________')
hypo_0vers1.AddFieldInterp('SOLU_0__ERRE_ELEM_SIGM__________')
#
# Hypothese "hypo_1vers2"
# =======================
hypo_1vers2 = homard.CreateHypothesis('hypo_1vers2')
# Characterization of the field
hypo_1vers2.SetField('SOLU_1__QIRE_ELEM_SIGM__________')
hypo_1vers2.SetUseComp(0)
hypo_1vers2.AddComp('ERREST          ')
hypo_1vers2.SetRefinThr(3, 1.5)
hypo_1vers2.SetUnRefThr(3, 6.)
hypo_1vers2.SetTypeFieldInterp(2)
hypo_1vers2.AddFieldInterp('SOLU_1__DEPL____________________')
hypo_1vers2.AddFieldInterp('SOLU_1__QIRE_ELEM_SIGM__________')
#
# Hypothese "hypo_1vers2_bis"
# ===========================
hypo_1vers2_bis = homard.CreateHypothesis('hypo_1vers2_bis')
# Characterization of the field
hypo_1vers2_bis.SetField('SOLU_1__DEPL____________________')
hypo_1vers2_bis.SetUseComp(1)
hypo_1vers2_bis.AddComp('DX')
hypo_1vers2_bis.AddComp('DY')
hypo_1vers2_bis.AddComp('DZ')
hypo_1vers2_bis.SetRefinThr(1, 0.0001)
hypo_1vers2_bis.SetUnRefThr(1, 0.000001)
hypo_1vers2_bis.SetTypeFieldInterp(0)
#
# Cas
# ===
le_cas = homard.CreateCase('Case_3', 'G_0', os.path.join(DATA_TUTORIAL, "tutorial_3.00.med"))
le_cas.SetDirName(DIRCASE)
#
# Iteration "iter_3_1"
# ====================
iter_3_1 = le_cas.NextIteration('iter_3_1')
iter_3_1.SetMeshName('H_1')
iter_3_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
iter_3_1.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.00.med"))
iter_3_1.SetTimeStepRank( 1, 1)
iter_3_1.AssociateHypo('hypo_0vers1')
erreur = iter_3_1.Compute(1, 2)
#
# Iteration "iter_3_2"
# ====================
iter_3_2 = iter_3_1.NextIteration('iter_3_2')
iter_3_2.SetMeshName('H_2')
iter_3_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
iter_3_2.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.01.med"))
iter_3_2.SetTimeStepRank(1, 1)
iter_3_2.AssociateHypo('hypo_1vers2')
erreur = iter_3_2.Compute(1, 2)
#
# Iteration "iter_3_2_bis"
# ========================
iter_3_2_bis = iter_3_1.NextIteration('iter_3_2_bis')
iter_3_2_bis.SetMeshName('H_2_bis')
iter_3_2_bis.SetMeshFile(os.path.join(DIRCASE, "maill.02.bis.med"))
iter_3_2_bis.SetFieldFile(os.path.join(DATA_TUTORIAL, "tutorial_3.01.med"))
iter_3_2_bis.SetTimeStepRank(1, 1)
iter_3_2_bis.AssociateHypo('hypo_1vers2_bis')
erreur = iter_3_2_bis.Compute(1, 2)
#

Suivi de frontières courbes

On teste ici le suivi des frontières courbes en fournissant la géométrie représentée par la CAO de la pièce. Cette CAO est fournie dans un fichier au format XAO. Le pilotage du raffinement est le suivant : raffinement uniforme de toutes les mailles contenues dans des groupes désignés. On commence par raffiner les faces internes aux tuyaux ; ensuite, on raffine deux fois de suite les faces externes aux tuyaux. Le schéma YACS réalisant cette adaptation est téléchargeable.

#
# Frontières
# ==========
boun_4 = homard.CreateBoundaryCAO("PIQUAGE", os.path.join(DATA_TUTORIAL, "tutorial_4.xao"))
#
# Cas
# ===
le_cas = homard.CreateCase('Case_4', "PIQUAGE", os.path.join(DATA_TUTORIAL, "tutorial_4.00.med"))
le_cas.SetDirName(DIRCASE)
le_cas.AddBoundary( "PIQUAGE" )
#
# Hypotheses
# ==========
# Creation of the hypothesis hypo_4
l_hypothese = homard.CreateHypothesis('hypo_4')
l_hypothese.SetUnifRefinUnRef(1)
l_hypothese.AddGroup('T1_INT_I')
l_hypothese.AddGroup('T1_INT_O')
l_hypothese.AddGroup('T2_INT')
# Creation of the hypothesis hypo_4_bis
l_hypothese_bis = homard.CreateHypothesis('hypo_4_bis')
l_hypothese_bis.SetUnifRefinUnRef(1)
l_hypothese_bis.AddGroup('T1_EXT_I')
l_hypothese_bis.AddGroup('T1_EXT_O')
l_hypothese_bis.AddGroup('T2_EXT')
#
# Iterations
# ==========
# Iteration iter_4_1 : raffinement selon les faces internes
iter_4_1 = le_cas.NextIteration('iter_4_1')
iter_4_1.SetMeshName('PIQUAGE_1')
iter_4_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
iter_4_1.AssociateHypo('hypo_4')
erreur = iter_4_1.Compute(1, 2)
# Iteration iter_4_2 : raffinement selon les faces externes
iter_4_2 = iter_4_1.NextIteration('iter_4_2')
iter_4_2.SetMeshName('PIQUAGE_2')
iter_4_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
iter_4_2.AssociateHypo('hypo_4_bis')
erreur = iter_4_2.Compute(1, 2)
# Iteration iter_4_3 : second raffinement selon les faces externes
iter_4_3 = iter_4_2.NextIteration('iter_4_3')
iter_4_3.SetMeshName('PIQUAGE_3')
iter_4_3.SetMeshFile(os.path.join(DIRCASE, "maill.03.med"))
iter_4_3.AssociateHypo('hypo_4_bis')
erreur = iter_4_3.Compute(1, 2)
#

Si la géométrie sous forme de CAO n’est pas disponible, on peut l’approcher ainsi : des frontières analytiques pour décrire les différentes surfaces des tuyaux et une frontière discrète pour décrire les lignes d’intersection des deux tuyaux. Il suffit de remplacer la définition des frontières.

#
# Frontières
# ==========
boun_6_1 = homard.CreateBoundaryDi('intersection', 'COURBES', os.path.join(DATA_TUTORIAL, "tutorial_6.fr.med"))
#
boun_6_2 = homard.CreateBoundaryCylinder('cyl_1_ext', 0.0, 25., -25., 25., 50., 75., 100.)
#
boun_6_3 = homard.CreateBoundaryCylinder('cyl_2_ext', 17.5, -2.5, -12.5, -100., -75., -25., 50.)
#
boun_6_4 = homard.CreateBoundaryCylinder('cyl_1_int', 0.0, 25., -25., 25., 50., 75., 75.)
#
boun_6_5 = homard.CreateBoundaryCylinder('cyl_2_int', 17.5, -2.5, -12.5, -100., -75., -25., 25.)
#
# Cas
# ===
le_cas = homard.CreateCase('Case_6', 'PIQUAGE', os.path.join(DATA_TUTORIAL, "tutorial_4.00.med"))
le_cas.SetDirName(DIRCASE)
le_cas.AddBoundary( 'intersection' )
le_cas.AddBoundaryGroup( 'cyl_1_int', 'T1_INT_I' )
le_cas.AddBoundaryGroup( 'cyl_1_ext', 'T1_EXT_I' )
le_cas.AddBoundaryGroup( 'cyl_1_int', 'T1_INT_O' )
le_cas.AddBoundaryGroup( 'cyl_1_ext', 'T1_EXT_O' )
le_cas.AddBoundaryGroup( 'cyl_2_int', 'T2_INT' )
le_cas.AddBoundaryGroup( 'cyl_2_ext', 'T2_EXT' )
#

Instructions spécifiques au 2D

Les instructions pour adapter un maillage 2D sont exactement identiques à celles nécessaires à l’adaptation d’un maillage 3D. La seule exception concerne le raffinement selon des zones géométriques : des fonctions différentes sont utilisées pour pouvoir définir des zones 2D. On donne alors les coordonnées 2D des zones, en précisant l’orientation du plan du maillage. Dans le cas présenté ici, on raffine une première fois toutes les mailles contenues dans un disque percé, puis dans une seconde itération, toutes les mailles contenues dans un rectangle. On notera l’utilisation du suivi des frontières circulaires du domaine.

#
# Frontière
# =========
# Creation of the discrete boundary boun_5_1
boun_5_1 = homard.CreateBoundaryDi('boun_5_1', 'MAIL_EXT', os.path.join(DATA_TUTORIAL, "tutorial_5.fr.med"))
#
# Creation des zones
# ==================
# Creation of the disk with hole enveloppe
enveloppe = homard.CreateZoneDiskWithHole( 'enveloppe', 0., 0., 250., 193., 1 )
# Creation of the rectangle quart_sup
quart_sup = homard.CreateZoneBox2D( 'quart_sup', 0., 250., 0., 250., 1 )
#
# Hypotheses
# ==========
# Creation of the hypothesis hypo_5
l_hypothese = homard.CreateHypothesis('hypo_5')
l_hypothese.AddZone('enveloppe', 1)
# Creation of the hypothesis l_hypothese_bis
l_hypothese_bis = homard.CreateHypothesis('hypo_5_bis')
l_hypothese_bis.AddZone('quart_sup', 1)
#
# Cas
# ===
le_cas = homard.CreateCase('Case_5', 'COEUR_2D', os.path.join(DATA_TUTORIAL, "tutorial_5.00.med"))
le_cas.SetDirName(DIRCASE)
le_cas.SetConfType(1)
le_cas.AddBoundary('boun_5_1')
#
# Iteration "iter_5_1"
# ====================
iter_5_1 = le_cas.NextIteration('iter_5_1')
iter_5_1.SetMeshName('COEUR_2D_01')
iter_5_1.SetMeshFile(os.path.join(DIRCASE, "maill.01.med"))
iter_5_1.AssociateHypo('hypo_5')
erreur = iter_5_1.Compute(1, 2)
#
# Iteration "iter_5_2"
# ====================
iter_5_2 = iter_5_1.NextIteration('iter_5_2')
iter_5_2.SetMeshName('COEUR_2D_02')
iter_5_2.SetMeshFile(os.path.join(DIRCASE, "maill.02.med"))
iter_5_2.AssociateHypo('hypo_5_bis')
erreur = iter_5_2.Compute(1, 2)
#