# -*- coding: utf-8 -*-
+# Copyright (C) 2017-2022 CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
import sys
import salome
salome.salome_init()
-theStudy = salome.myStudy
###
### GEOM component
import SALOMEDS
-geompy = geomBuilder.New(theStudy)
+geompy = geomBuilder.New()
+
+# first cylinder
+r1 = 0.5
+h1 = 5
+
+# second cylinder
+r2 = 0.3
+h2 = 3
+
+length_piquage = 1.5
O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
-Cylinder_1 = geompy.MakeCylinderRH(0.5, 5)
-Cylinder_2 = geompy.MakeCylinderRH(0.3, 3)
-Rotation_1 = geompy.MakeRotation(Cylinder_2, OY, -90*math.pi/180.0)
-Translation_1 = geompy.MakeTranslation(Rotation_1, 0, 0, 1.5)
-piquage = geompy.MakeFuseList([Cylinder_1, Translation_1], True, True)
-[Outlet] = geompy.SubShapes(piquage, [15])
-[Inlet_z,Inlet_x] = geompy.SubShapes(piquage, [13, 22])
-[corner] = geompy.SubShapes(piquage, [14])
-geomObj_1 = geompy.MakeVertex(0, 0, 0)
-geomObj_2 = geompy.MakeVectorDXDYDZ(1, 0, 0)
-geomObj_3 = geompy.MakeVectorDXDYDZ(0, 1, 0)
-geomObj_4 = geompy.MakeVectorDXDYDZ(0, 0, 1)
-Wall = geompy.CreateGroup(piquage, geompy.ShapeType["FACE"])
-geompy.UnionIDs(Wall, [3, 17])
geompy.addToStudy( O, 'O' )
geompy.addToStudy( OX, 'OX' )
geompy.addToStudy( OY, 'OY' )
geompy.addToStudy( OZ, 'OZ' )
-geompy.addToStudy( Cylinder_1, 'Cylinder_1' )
-geompy.addToStudy( Cylinder_2, 'Cylinder_2' )
-geompy.addToStudy( Rotation_1, 'Rotation_1' )
-geompy.addToStudy( Translation_1, 'Translation_1' )
+
+Cylinder_1 = geompy.MakeCylinderRH(r1, h1)
+Cylinder_2 = geompy.MakeCylinderRH(r2, h2)
+Rotation_1 = geompy.MakeRotation(Cylinder_2, OY, -90*math.pi/180.0)
+Translation_1 = geompy.MakeTranslation(Rotation_1, 0, 0, length_piquage)
+
+piquage = geompy.MakeFuseList([Cylinder_1, Translation_1], True, True)
geompy.addToStudy( piquage, 'piquage' )
+
+Inlet_z = geompy.GetFaceNearPoint(piquage, O)
+geompy.addToStudyInFather( piquage, Inlet_z, 'Inlet_z' )
+
+p_inlet_x = geompy.MakeVertex(-h2, 0, length_piquage)
+Inlet_x = geompy.GetFaceNearPoint(piquage, p_inlet_x)
geompy.addToStudyInFather( piquage, Inlet_x, 'Inlet_x' )
+
+p_outlet = geompy.MakeVertex(0, 0, h1)
+Outlet = geompy.GetFaceNearPoint(piquage, p_outlet)
geompy.addToStudyInFather( piquage, Outlet, 'Outlet' )
+
+Wall = geompy.CreateGroup(piquage, geompy.ShapeType["FACE"])
+faces = geompy.SubShapeAll(piquage, geompy.ShapeType["FACE"])
+geompy.UnionList(Wall, faces)
+geompy.DifferenceList(Wall, [Inlet_x, Inlet_z, Outlet])
geompy.addToStudyInFather( piquage, Wall, 'Wall' )
-geompy.addToStudyInFather( piquage, Inlet_z, 'Inlet_z' )
+
+p_corner = geompy.MakeVertex(-r2, 0, length_piquage+r2)
+corner = geompy.GetVertexNearPoint(piquage, p_corner)
geompy.addToStudyInFather( piquage, corner, 'corner' )
geom_groups = [Inlet_x, Inlet_z, Outlet, Wall]
from salome.StdMeshers import StdMeshersBuilder
from salome.HYBRIDPlugin import HYBRIDPluginBuilder
-smesh = smeshBuilder.New(theStudy)
+smesh = smeshBuilder.New()
# Viscous layers without imprinting
NETGEN_2D_Parameters.SetNbSegPerEdge( 2 )
NETGEN_2D_Parameters.SetNbSegPerRadius( 3 )
+wall_faces = geompy.SubShapeAll(Wall, geompy.ShapeType["FACE"])
+wall_ids = geompy.GetSubShapesIDs(piquage, wall_faces)
+
MG_Hybrid = Mesh_1.Tetrahedron(algo=smeshBuilder.HYBRID)
MG_Hybrid_Parameters_1 = MG_Hybrid.Parameters()
MG_Hybrid_Parameters_1.SetLayersOnAllWrap( 0 )
MG_Hybrid_Parameters_1.SetHeightFirstLayer( 0.01 )
MG_Hybrid_Parameters_1.SetBoundaryLayersProgression( 1.1 )
MG_Hybrid_Parameters_1.SetNbOfBoundaryLayers( 3 )
-MG_Hybrid_Parameters_1.SetFacesWithLayers( [ 3, 17 ] )
+MG_Hybrid_Parameters_1.SetFacesWithLayers( wall_ids )
isDone = Mesh_1.Compute()
NETGEN_2D_1_1 = Mesh_2.Triangle(algo=smeshBuilder.NETGEN_1D2D)
status = Mesh_2.AddHypothesis(NETGEN_2D_Parameters)
+Inlet_x_id, Inlet_z_id, Outlet_id = geompy.GetSubShapesIDs(piquage, [Inlet_x, Inlet_z, Outlet])
+
MG_Hybrid_2 = Mesh_2.Tetrahedron(algo=smeshBuilder.HYBRID)
MG_Hybrid_Parameters_2 = MG_Hybrid_2.Parameters()
MG_Hybrid_Parameters_2.SetLayersOnAllWrap( 0 )
MG_Hybrid_Parameters_2.SetHeightFirstLayer( 0.01 )
MG_Hybrid_Parameters_2.SetBoundaryLayersProgression( 1.1 )
MG_Hybrid_Parameters_2.SetNbOfBoundaryLayers( 3 )
-MG_Hybrid_Parameters_2.SetFacesWithLayers( [ 3, 17 ] )
-MG_Hybrid_Parameters_2.SetFacesWithImprinting( [ 22, 15, 13 ] )
+MG_Hybrid_Parameters_2.SetFacesWithLayers( wall_ids )
+MG_Hybrid_Parameters_2.SetFacesWithImprinting( [ Inlet_x_id, Inlet_z_id, Outlet_id ] )
isDone = Mesh_2.Compute()
assert area_error_1 < 0.025
# Compare mesh group with imprinting and mesh group without imprinting
area_error_2 = abs(smesh.GetArea(gr_1)-smesh.GetArea(gr_2))/smesh.GetArea(gr_1)
- assert area_error_2 < 1e-10
+ assert area_error_2 < 1e-08
# Compare whole mesh volume
mesh_2_volume = Mesh_2.GetVolume()
mesh_3_volume = Mesh_3.GetVolume()
volume_error_3 = abs(mesh_2_volume-mesh_3_volume)/mesh_2_volume
-assert abs(mesh_3_volume-mesh_2_volume)/mesh_2_volume < 1e-10
+assert math.isclose(mesh_3_volume,mesh_2_volume,rel_tol=1e-7)
# Check viscous layers with imprinting
for name in faces_imprinted:
assert gr_2.GetMeshInfo()[7] == gr_3.GetMeshInfo()[7]
# Compare mesh group with imprinting set by ids and mesh group with imprinting set by geom group
- area_error_3 = abs(smesh.GetArea(gr_2)-smesh.GetArea(gr_3))/smesh.GetArea(gr_2)
- assert area_error_3 < 1e-10
+ assert math.isclose( smesh.GetArea(gr_2), smesh.GetArea(gr_3))
-if salome.sg.hasDesktop():
- salome.sg.updateObjBrowser(1)