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