1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2017-2024 CEA, EDF
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # This test is a known failure for MeshGems <= 2.4-5 (but must not crash Salome)
33 from salome.geom import geomBuilder
38 geompy = geomBuilder.New()
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' )
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)
64 piquage = geompy.MakeFuseList([Cylinder_1, Translation_1], True, True)
65 geompy.addToStudy( piquage, 'piquage' )
67 Inlet_z = geompy.GetFaceNearPoint(piquage, O)
68 geompy.addToStudyInFather( piquage, Inlet_z, 'Inlet_z' )
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' )
74 p_outlet = geompy.MakeVertex(0, 0, h1)
75 Outlet = geompy.GetFaceNearPoint(piquage, p_outlet)
76 geompy.addToStudyInFather( piquage, Outlet, 'Outlet' )
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' )
84 p_corner = geompy.MakeVertex(-r2, 0, length_piquage+r2)
85 corner = geompy.GetVertexNearPoint(piquage, p_corner)
86 geompy.addToStudyInFather( piquage, corner, 'corner' )
88 geom_groups = [Inlet_x, Inlet_z, Outlet, Wall]
95 import SMESH, SALOMEDS
96 from salome.smesh import smeshBuilder
98 from salome.StdMeshers import StdMeshersBuilder
99 from salome.HYBRIDPlugin import HYBRIDPluginBuilder
101 smesh = smeshBuilder.New()
103 # Viscous layers with imprinting (hexa core)
104 # ==========================================
106 Mesh_4 = smesh.Mesh(piquage, "Mesh_with_imprinting_hexa_core")
108 NETGEN_2D_1_1 = Mesh_4.Triangle(algo=smeshBuilder.NETGEN_1D2D)
109 NETGEN_2D_Parameters = NETGEN_2D_1_1.Parameters()
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 )
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])
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 ] )
132 isDone = Mesh_4.Compute()
135 raise Exception("Error when computing Mesh_with_imprinting_hexa_core")
137 assert Mesh_4.NbQuadrangles() > 0
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
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
153 assert volume_error_4 < 0.02
155 # Check viscous layers with imprinting
156 faces_imprinted = ["Inlet_x", "Inlet_z", "Outlet"]
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
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