Salome HOME
Préparation pour MG-CADSurf
[modules/smesh.git] / src / Tools / blocFissure / gmu / genereMeshCalculZoneDefaut.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2020  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
21 import logging
22 from .geomsmesh import smesh
23 from salome.smesh import smeshBuilder
24
25 # -----------------------------------------------------------------------------
26 # --- maillage face de fissure pour identification zone de defaut
27
28 def genereMeshCalculZoneDefaut(facefiss, minSize, maxSize, \
29                                mailleur="MeshGems"):
30   """Maillage de l'objet géométrique 'facefiss'
31
32 . Avec l'algorithme MG_CADSurf :
33       -SetMaxSize     = dimension max d'un élément (maxSize)
34       -SetSecondOrder = élément quadratique (Y=1, N=0)
35       -SetOptimize    = élément régulier (Y=1, N=0)
36       -SetFineness    = finesse du maillage
37
38 . Avec l'algorithme NETGEN_1D2D :
39       -SetMaxSize     = dimension max d'un élément (maxSize)
40       -SetSecondOrder = élément quadratique (Y=1, N=0)
41       -SetOptimize    = élément régulier (Y=1, N=0)
42       -SetFineness    = finesse du maillage
43        [very_coarse, coarse, moderate, fine, very_fine, custom]
44        [0,           1,      2,        3,    4,         5     ]
45       -SetMinSize     = dimension min d'un élément (minSize)
46       -SetQuadAllowed = permission quadrangle dans maillage triangle
47
48 -On récupère les coordonnées de chaque noeud de la fissure qu'on stocke
49    dans une liste sous la forme : [X0, Y0, Z0, ..., Xn, Yn, Zn]"""
50
51   logging.info('start')
52
53   meshFissure = smesh.Mesh(facefiss)
54   text = "Maillage de '{}' avec {}".format(facefiss.GetName(),mailleur)
55   logging.info(text)
56   if ( mailleur == "MeshGems"):
57     algo2d = meshFissure.Triangle(algo=smeshBuilder.MG_CADSurf)
58     hypo2d = algo2d.Parameters()
59     hypo2d.SetPhySize( maxSize )
60     hypo2d.SetMinSize( maxSize/4. )
61     hypo2d.SetMaxSize( maxSize*2. )
62     hypo2d.SetChordalError( maxSize*0.25 )
63     hypo2d.SetVerbosity( 0 )
64   else:
65     algo2d = meshFissure.Triangle(algo=smeshBuilder.NETGEN_1D2D)
66     hypo2d = algo2d.Parameters()
67     hypo2d.SetMaxSize( maxSize )
68     hypo2d.SetSecondOrder( 0 )
69     hypo2d.SetOptimize( 1 )
70     hypo2d.SetFineness( 2 )
71     hypo2d.SetMinSize( minSize )
72     hypo2d.SetQuadAllowed( 0 )
73   smesh.SetName(algo2d, "algo2d_zoneFiss")
74   smesh.SetName(hypo2d, "hypo1d_zoneFiss")
75
76   is_done = meshFissure.Compute()
77   text = "meshFissure.Compute"
78   if is_done:
79     logging.info(text+" OK")
80   else:
81     text = "Erreur au calcul du maillage.\n" + text
82     logging.info(text)
83     raise Exception(text)
84
85   coordsNoeudsFissure = list()
86   nodeIds = meshFissure.GetNodesId()
87   for indice in nodeIds:
88     coords = meshFissure.GetNodeXYZ(indice)
89     coordsNoeudsFissure.append(coords[0])
90     coordsNoeudsFissure.append(coords[1])
91     coordsNoeudsFissure.append(coords[2])
92
93   logging.info('end')
94
95   return coordsNoeudsFissure