Salome HOME
Copyright update 2022
[plugins/hybridplugin.git] / tests / layers_imprinting_hexa_core.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2017-2022  CEA/DEN, 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 # This test is a known failure for MeshGems <= 2.4-5 (but must not crash Salome)
22
23 import sys
24 import salome
25
26 salome.salome_init()
27
28 ###
29 ### GEOM component
30 ###
31
32 import GEOM
33 from salome.geom import geomBuilder
34 import math
35 import SALOMEDS
36
37
38 geompy = geomBuilder.New()
39
40 # first cylinder
41 r1 = 0.5
42 h1 = 5
43
44 # second cylinder
45 r2 = 0.3
46 h2 = 3
47
48 length_piquage = 1.5
49
50 O = geompy.MakeVertex(0, 0, 0)
51 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
52 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
53 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
54 geompy.addToStudy( O, 'O' )
55 geompy.addToStudy( OX, 'OX' )
56 geompy.addToStudy( OY, 'OY' )
57 geompy.addToStudy( OZ, 'OZ' )
58
59 Cylinder_1 = geompy.MakeCylinderRH(r1, h1)
60 Cylinder_2 = geompy.MakeCylinderRH(r2, h2)
61 Rotation_1 = geompy.MakeRotation(Cylinder_2, OY, -90*math.pi/180.0)
62 Translation_1 = geompy.MakeTranslation(Rotation_1, 0, 0, length_piquage)
63
64 piquage = geompy.MakeFuseList([Cylinder_1, Translation_1], True, True)
65 geompy.addToStudy( piquage, 'piquage' )
66
67 Inlet_z = geompy.GetFaceNearPoint(piquage, O)
68 geompy.addToStudyInFather( piquage, Inlet_z, 'Inlet_z' )
69
70 p_inlet_x = geompy.MakeVertex(-h2, 0, length_piquage)
71 Inlet_x = geompy.GetFaceNearPoint(piquage, p_inlet_x)
72 geompy.addToStudyInFather( piquage, Inlet_x, 'Inlet_x' )
73
74 p_outlet = geompy.MakeVertex(0, 0, h1)
75 Outlet = geompy.GetFaceNearPoint(piquage, p_outlet)
76 geompy.addToStudyInFather( piquage, Outlet, 'Outlet' )
77
78 Wall = geompy.CreateGroup(piquage, geompy.ShapeType["FACE"])
79 faces = geompy.SubShapeAll(piquage, geompy.ShapeType["FACE"])
80 geompy.UnionList(Wall, faces)
81 geompy.DifferenceList(Wall, [Inlet_x, Inlet_z, Outlet])
82 geompy.addToStudyInFather( piquage, Wall, 'Wall' )
83
84 p_corner = geompy.MakeVertex(-r2, 0, length_piquage+r2)
85 corner = geompy.GetVertexNearPoint(piquage, p_corner)
86 geompy.addToStudyInFather( piquage, corner, 'corner' )
87
88 geom_groups = [Inlet_x, Inlet_z, Outlet, Wall]
89 d_geom_groups = {}
90
91 ###
92 ### SMESH component
93 ###
94
95 import  SMESH, SALOMEDS
96 from salome.smesh import smeshBuilder
97
98 from salome.StdMeshers import StdMeshersBuilder
99 from salome.HYBRIDPlugin import HYBRIDPluginBuilder
100
101 smesh = smeshBuilder.New()
102
103 # Viscous layers with imprinting (hexa core)
104 # ==========================================
105
106 Mesh_4 = smesh.Mesh(piquage, "Mesh_with_imprinting_hexa_core")
107
108 NETGEN_2D_1_1 = Mesh_4.Triangle(algo=smeshBuilder.NETGEN_1D2D)
109 NETGEN_2D_Parameters = NETGEN_2D_1_1.Parameters()
110
111 NETGEN_2D_Parameters.SetMinSize( 0.01 )
112 NETGEN_2D_Parameters.SetLocalSizeOnShape(corner, 0.01)
113 NETGEN_2D_Parameters.SetFineness( 5 )
114 NETGEN_2D_Parameters.SetGrowthRate( 0.1 )
115 NETGEN_2D_Parameters.SetNbSegPerEdge( 2 )
116 NETGEN_2D_Parameters.SetNbSegPerRadius( 3 )
117
118 wall_faces = geompy.SubShapeAll(Wall, geompy.ShapeType["FACE"])
119 wall_ids = geompy.GetSubShapesIDs(piquage, wall_faces)
120 Inlet_x_id, Inlet_z_id, Outlet_id = geompy.GetSubShapesIDs(piquage, [Inlet_x, Inlet_z, Outlet])
121
122 MG_Hybrid_4 = Mesh_4.Tetrahedron(algo=smeshBuilder.HYBRID)
123 MG_Hybrid_Parameters_4 = MG_Hybrid_4.Parameters()
124 MG_Hybrid_Parameters_4.SetLayersOnAllWrap( 0 )
125 MG_Hybrid_Parameters_4.SetElementGeneration( HYBRIDPluginBuilder.Generation_Hexa_Dominant )
126 MG_Hybrid_Parameters_4.SetHeightFirstLayer( 0.01 )
127 MG_Hybrid_Parameters_4.SetBoundaryLayersProgression( 1.1 )
128 MG_Hybrid_Parameters_4.SetNbOfBoundaryLayers( 3 )
129 MG_Hybrid_Parameters_4.SetFacesWithLayers( wall_ids )
130 MG_Hybrid_Parameters_4.SetFacesWithImprinting( [ Inlet_x_id, Inlet_z_id, Outlet_id ] )
131
132 isDone = Mesh_4.Compute()
133
134 if not isDone:
135   raise Exception("Error when computing Mesh_with_imprinting_hexa_core")
136
137 assert Mesh_4.NbQuadrangles() > 0
138
139 d_groups_4 = {}
140 d_geom_groups = {}
141
142 for geom_group in geom_groups:
143   name = geom_group.GetName()
144   gr = Mesh_4.Group(geom_group)
145   d_groups_4[name] = gr
146   d_geom_groups[name] = geom_group
147
148 # Compare whole mesh volume
149 mesh_4_volume = Mesh_4.GetVolume()
150 shape_volume = geompy.BasicProperties(piquage)[2]
151 volume_error_4 = abs(shape_volume-mesh_4_volume)/shape_volume
152
153 assert volume_error_4 < 0.02
154
155 # Check viscous layers with imprinting
156 faces_imprinted = ["Inlet_x", "Inlet_z", "Outlet"]
157
158 for name in faces_imprinted:
159   gr_4 = d_groups_4[name]
160   #assert gr_1.Size() > 0
161   assert gr_4.Size() > 0
162   # Nb of quadrangles is in 7th index of mesh info
163   assert gr_4.GetMeshInfo()[7] > 0
164
165   # Compare mesh group and geom group
166   geom_area = geompy.BasicProperties(d_geom_groups[name])[1]
167   area_error_1 = abs(geom_area-smesh.GetArea(gr_4))/geom_area
168   assert area_error_1 < 0.025
169