Salome HOME
Merge branch 'master' into gni/evolution
[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   """
30   -Permet de générer un maillage sur l'objet géométrique 'facefiss' via
31    l'algorithme NETGEN_1D2D :
32       -SetMaxSize     = dimension max d'un élément (maxSize)
33       -SetSecondOrder = élément quadratique (Y=1, N=0)
34       -SetOptimize    = élément régulier (Y=1, N=0)
35       -SetFineness    = finesse du maillage
36        [very_coarse, coarse, moderate, fine, very_fine, custom]
37        [0,           1,      2,        3,    4,         5     ]
38       -SetMinSize     = dimension min d'un élément (minSize)
39       -SetQuadAllowed = permission quadrangle dans maillage triangle
40   -On récupère les coordonnées de chaque noeud de la fissure qu'on stocke
41    dans une liste sous la forme : [X0, Y0, Z0, ..., Xn, Yn, Zn]"""
42
43   logging.info('start')
44   text = "Maillage de '{}'".format(facefiss.GetName())
45   logging.info(text)
46
47   meshFissure = smesh.Mesh(facefiss)
48   algo2d = meshFissure.Triangle(algo=smeshBuilder.NETGEN_1D2D)
49   hypo2d = algo2d.Parameters()
50   hypo2d.SetMaxSize( maxSize )
51   hypo2d.SetSecondOrder( 0 )
52   hypo2d.SetOptimize( 1 )
53   hypo2d.SetFineness( 2 )
54   hypo2d.SetMinSize( minSize )
55   hypo2d.SetQuadAllowed( 0 )
56   smesh.SetName(algo2d, "algo2d_zoneFiss")
57   smesh.SetName(hypo2d, "hypo1d_zoneFiss")
58
59   is_done = meshFissure.Compute()
60   text = "meshFissure.Compute"
61   if is_done:
62     logging.info(text+" OK")
63   else:
64     text = "Erreur au calcul du maillage.\n" + text
65     logging.info(text)
66     raise Exception(text)
67
68   coordsNoeudsFissure = list()
69   nodeIds = meshFissure.GetNodesId()
70   for id in nodeIds:
71     coords = meshFissure.GetNodeXYZ(id)
72     coordsNoeudsFissure.append(coords[0])
73     coordsNoeudsFissure.append(coords[1])
74     coordsNoeudsFissure.append(coords[2])
75
76   logging.info('end')
77
78   return coordsNoeudsFissure