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