Salome HOME
394012b7c5f8d1b31d82955eaf975f0541dd413a
[modules/smesh.git] / src / Tools / blocFissure / gmu / insereFissureLongue_d.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 """Insertion de fissure longue - maillage face de peau"""
21
22 import logging
23
24 import salome
25 from salome.smesh import smeshBuilder
26 import SMESH
27
28 from .geomsmesh import geompy
29 from .geomsmesh import smesh
30
31 from .putName import putName
32
33 def insereFissureLongue_d (facePeau, edgePeauFiss, groupEdgesBordPeau, bordsLibres, \
34                            groupsDemiCerclesPeau, groups_demiCercles, verticesOutCercles, \
35                            nbSegGenLong, nbSegGenBout, profondeur, \
36                            mailleur="MeshGems", nro_cas=None):
37   """maillage face de peau"""
38   logging.info('start')
39   logging.info("Maillage avec %s pour le cas n°%s", mailleur, nro_cas)
40
41   meshFacePeau = smesh.Mesh(facePeau)
42   putName(meshFacePeau, "facePeau", i_pref=nro_cas)
43
44   if ( mailleur == "MeshGems"):
45     algo2d = meshFacePeau.Triangle(algo=smeshBuilder.MG_CADSurf)
46     hypo2d = algo2d.Parameters()
47     hypo2d.SetPhySize( 1000 )
48     hypo2d.SetMinSize( 100 )
49     hypo2d.SetMaxSize( 3000. )
50     hypo2d.SetChordalError( 250. )
51     hypo2d.SetVerbosity( 0 )
52   else:
53     algo2d = meshFacePeau.Triangle(algo=smeshBuilder.NETGEN_2D)
54     hypo2d = algo2d.Parameters()
55     hypo2d.SetMaxSize( 1000 )
56     hypo2d.SetOptimize( 1 )
57     hypo2d.SetFineness( 2 )
58     hypo2d.SetMinSize( 2 )
59     hypo2d.SetQuadAllowed( 0 )
60   putName(algo2d.GetSubMesh(), "facePeau", i_pref=nro_cas)
61   putName(algo2d, "{}_2d_facePeau".format(mailleur), i_pref=nro_cas)
62   putName(hypo2d, "hypo2d_facePeau", i_pref=nro_cas)
63   #
64   lenEdgePeauFiss = geompy.BasicProperties(edgePeauFiss)[0]
65   frac = profondeur/lenEdgePeauFiss
66   nbSeg = nbSegGenLong +2*nbSegGenBout
67   ratio = (nbSegGenBout/float(profondeur)) / (nbSegGenLong/lenEdgePeauFiss)
68   logging.info("lenEdgePeauFiss %s, profondeur %s, nbSegGenLong %s, nbSegGenBout %s, frac %s, ratio %s", lenEdgePeauFiss, profondeur, nbSegGenLong, nbSegGenBout, frac, ratio)
69
70   algo1d = meshFacePeau.Segment(geom=edgePeauFiss)
71   hypo1d = algo1d.NumberOfSegments(nbSeg,list(),[  ])
72   hypo1d.SetDistrType( 2 )
73   hypo1d.SetConversionMode( 1 )
74   hypo1d.SetTableFunction( [ 0, ratio, frac, 1, (1.-frac), 1, 1, ratio ] )
75   putName(algo1d.GetSubMesh(), "edgePeauFiss", i_pref=nro_cas)
76   putName(algo1d, "algo1d_edgePeauFiss", i_pref=nro_cas)
77   putName(hypo1d, "hypo1d_edgePeauFiss", i_pref=nro_cas)
78   #
79   algo1d = meshFacePeau.UseExisting1DElements(geom=groupEdgesBordPeau)
80   hypo1d = algo1d.SourceEdges([ bordsLibres ],0,0)
81   putName(algo1d.GetSubMesh(), "bordsLibres", i_pref=nro_cas)
82   putName(algo1d, "algo1d_bordsLibres", i_pref=nro_cas)
83   putName(hypo1d, "hypo1d_bordsLibres", i_pref=nro_cas)
84   #
85   for i_aux in range(2):
86     algo1d = meshFacePeau.UseExisting1DElements(geom=groupsDemiCerclesPeau[i_aux])
87     hypo1d = algo1d.SourceEdges([ groups_demiCercles[i_aux] ],0,0)
88     putName(algo1d.GetSubMesh(), "DemiCercles", i_aux, nro_cas)
89     putName(algo1d, "algo1d_groupDemiCercles", i_aux, nro_cas)
90     putName(hypo1d, "hypo1d_groupDemiCercles", i_aux, nro_cas)
91
92   _ = meshFacePeau.GroupOnGeom(verticesOutCercles[0], "THOR", SMESH.NODE)
93   _ = meshFacePeau.GroupOnGeom(verticesOutCercles[1], "THEX", SMESH.NODE)
94
95   groupEdgesPeauFiss = meshFacePeau.GroupOnGeom(edgePeauFiss, "PeauFis", SMESH.EDGE)
96
97   is_done = meshFacePeau.Compute()
98   text = "meshFacePeau.Compute"
99   if is_done:
100     logging.info(text+" OK")
101   else:
102     text = "Erreur au calcul du maillage.\n" + text
103     logging.info(text)
104     raise Exception(text)
105
106   peauext_face = meshFacePeau.CreateEmptyGroup( SMESH.FACE, 'PEAUEXT' )
107   _ = peauext_face.AddFrom( meshFacePeau.GetMesh() )
108
109   return meshFacePeau, groupEdgesPeauFiss