Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / src / Tools / blocFissure / gmu / construitFissureGenerale_c.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2022  EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """construction de la fissure générale - maillage"""
21
22 import os
23
24 import logging
25
26 from salome.smesh import smeshBuilder
27 import SMESH
28
29 from .geomsmesh import geompy
30
31 from .putName import putName
32 from .enleveDefaut import enleveDefaut
33 from .shapeSurFissure import shapeSurFissure
34 from .regroupeSainEtDefaut import RegroupeSainEtDefaut
35 from .triedreBase import triedreBase
36
37 # -----------------------------------------------------------------------------
38
39 def construitFissureGenerale_c(maillageSain, meshBoiteDefaut, \
40                               zoneDefaut, zoneDefaut_skin, zoneDefaut_internalFaces, zoneDefaut_internalEdges, \
41                               facesPortFissure, \
42                               maillageFissureParams, \
43                               mailleur="MeshGems", nro_cas=None):
44   """construction de la fissure générale - maillage"""
45   logging.info('start')
46   logging.info("Usage du mailleur %s pour le cas n°%s", mailleur, nro_cas)
47
48   nomRep            = maillageFissureParams['nomRep']
49   nomFicSain        = maillageFissureParams['nomFicSain']
50   nomFicFissure     = maillageFissureParams['nomFicFissure']
51
52   O, _, _, _ = triedreBase()
53
54   # pour aider l'algo hexa-tetra à ne pas mettre de pyramides à l'exterieur des volumes repliés sur eux-mêmes
55   # on désigne les faces de peau en quadrangles par le groupe "skinFaces"
56   group_faceFissOutPipe = None
57   group_faceFissInPipe = None
58   groups = meshBoiteDefaut.GetGroups()
59   for grp in groups:
60     if grp.GetType() == SMESH.FACE:
61       if grp.GetName() == "fisOutPi":
62         group_faceFissOutPipe = grp
63       elif grp.GetName() == "fisInPi":
64         group_faceFissInPipe = grp
65
66   # le maillage NETGEN ne passe pas toujours ==> on force l'usage de MG_Tetra
67   mailleur = "MeshGems"
68   logging.info("Maillage avec %s", mailleur)
69   if ( mailleur == "MeshGems"):
70     algo3d = meshBoiteDefaut.Tetrahedron(algo=smeshBuilder.MG_Tetra)
71   else:
72     algo3d = meshBoiteDefaut.Tetrahedron(algo=smeshBuilder.NETGEN)
73     hypo3d = algo3d.MaxElementVolume(1000.0)
74     hypo3d.SetVerboseLevel( 0 )
75     hypo3d.SetStandardOutputLog( 0 )
76     hypo3d.SetRemoveLogOnSuccess( 1 )
77   putName(algo3d.GetSubMesh(), "boiteDefaut", i_pref=nro_cas)
78
79   is_done = meshBoiteDefaut.Compute()
80   text = "meshBoiteDefaut.Compute"
81   if is_done:
82     logging.info(text+" OK")
83   else:
84     text = "Erreur au calcul du maillage.\n" + text
85     logging.info(text)
86     raise Exception(text)
87
88   _ = meshBoiteDefaut.GetMesh().UnionListOfGroups( [ group_faceFissOutPipe, group_faceFissInPipe ], \
89                                                              'FACE1' )
90   maillageSain = enleveDefaut(maillageSain, zoneDefaut, zoneDefaut_skin,
91                               zoneDefaut_internalFaces, zoneDefaut_internalEdges)
92   putName(maillageSain, nomFicSain+"_coupe", i_pref=nro_cas)
93   _, normfiss = shapeSurFissure(facesPortFissure)
94   maillageComplet = RegroupeSainEtDefaut(maillageSain, meshBoiteDefaut, \
95                                          None, None, 'COMPLET', normfiss)
96   putName(maillageComplet, nomFicFissure)
97
98   logging.info("conversion quadratique")
99   maillageComplet.ConvertToQuadratic( 1 )
100
101   logging.info("groupes")
102   groups = maillageComplet.GetGroups()
103   grps = [ grp for grp in groups if grp.GetName() == 'FONDFISS']
104   _ = maillageComplet.GetMesh().CreateDimGroup( grps, SMESH.NODE, 'FONDFISS' )
105
106   logging.info("réorientation face de fissure FACE1")
107   grps = [ grp for grp in groups if grp.GetName() == 'FACE1']
108   _ = maillageComplet.Reorient2D( grps[0], normfiss, grps[0].GetID(1))
109
110   logging.info("réorientation face de fissure FACE2")
111   plansim = geompy.MakePlane(O, normfiss, 10000)
112   fissnorm = geompy.MakeMirrorByPlane(normfiss, plansim)
113   grps = [ grp for grp in groups if grp.GetName() == 'FACE2']
114   _ = maillageComplet.Reorient2D( grps[0], fissnorm, grps[0].GetID(1))
115   _ = maillageComplet.GetMesh().CreateDimGroup( grps, SMESH.NODE, 'FACE2' )
116
117   logging.info("export maillage fini")
118   fichierMaillageFissure = os.path.join (nomRep , '{}.med'.format(nomFicFissure))
119   maillageComplet.ExportMED(fichierMaillageFissure)
120   logging.info("fichier maillage fissure %s", fichierMaillageFissure)
121
122   return maillageComplet