1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
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
23 salome.salome_init_without_session()
27 from salome.geom import geomBuilder
28 from salome.smesh import smeshBuilder
29 from salome.shaper import model
31 def assertAlmostEqual(a,b,tol):
32 if ( abs(a-b) < tol ):
35 print( "not close vals", a, b )
39 geompy = geomBuilder.New()
41 O = geompy.MakeVertex(0, 0, 0)
42 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
43 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
44 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
47 geompy.addToStudy( O, 'O' )
48 geompy.addToStudy( OX, 'OX' )
49 geompy.addToStudy( OY, 'OY' )
50 geompy.addToStudy( OZ, 'OZ' )
51 Box = geompy.MakeBox(0,0,0,10,10,10)
53 smesh_builder = smeshBuilder.New()
55 MesherBox = smesh_builder.Mesh(Box, "Box")
56 viscousBuilder = MesherBox.ViscousLayerBuilder()
58 #############BOX AND TETRA ELEMENTS
59 #Set prismatic layer parameters
62 viscousBuilder.setBuilderParameters( offset, numLayers, 1.2, [13], False )
63 ShrinkBox = viscousBuilder.GetShrinkGeometry()
66 MesherShinkBox = smesh_builder.Mesh(ShrinkBox, "ShrinkMesh")
67 ShrinkBoxMesh = MesherShinkBox.Tetrahedron(smeshBuilder.NETGEN_1D2D3D)
70 success = MesherShinkBox.Compute()
72 assert( MesherShinkBox.NbVolumes() == 5 ) # if Fails! change the default value of volumes when meshing with Netgen!
74 FinalMesh = viscousBuilder.AddLayers( MesherShinkBox )
75 assert( FinalMesh.NbVolumes() == 5 + numLayers * 2 ) # here 2 stands for the number of face elements per face in the box
76 assert( FinalMesh.NbFaces() == 6 * 2 + 4 * numLayers ) # here is the number of face elements for the box + the new faces in the VL. (6 is the number of sides in the box)
78 #Testing the configuration where face 13 is ignored and so the offset is applied to all other faces
79 viscousBuilder.setBuilderParameters( offset, numLayers, 1.2, [13], True )
80 ShrinkBox2 = viscousBuilder.GetShrinkGeometry()
82 MesherShinkBox2 = smesh_builder.Mesh(ShrinkBox2, "ShrinkMesh2")
83 ShrinkBoxMesh2 = MesherShinkBox2.Tetrahedron(smeshBuilder.NETGEN_1D2D3D)
86 success = MesherShinkBox2.Compute()
89 #Test the number of elements on the shrink mesh
90 assert( MesherShinkBox2.NbVolumes() == 5 ) # if Fails! change the default (default hypo) number of volumes when meshing with Netgen!
92 FinalMesh2 = viscousBuilder.AddLayers( MesherShinkBox2 )
94 assert( FinalMesh2.NbVolumes() == 5 + numLayers * 2 * 5 ) # here 2 stands for the number of face elements per face in the box
95 assert( FinalMesh2.NbFaces() == 6 * 2 + 4 * numLayers ) # here is the number of face elements for the box + the new faces in the VL. (6 is the number of sides in the box)
96 #############END BOX AND TETRA ELEMENTS
98 #############MESH SQUARE FACE
99 Face = geompy.MakeFaceHW(5, 5, 1)
100 Disk = geompy.MakeDiskR(5, 1)
102 MesherSqr = smesh_builder.Mesh(Face, "Face")
103 viscousBuilder = MesherSqr.ViscousLayerBuilder()
104 #Set prismatic layer parameters
107 viscousBuilder.setBuilderParameters( offset, numberOfLayers, 1.2 )
108 ShrinkFace = viscousBuilder.GetShrinkGeometry()
109 #Mesh the shrink face
110 MesherShinkFace = smesh_builder.Mesh(ShrinkFace, "ShrinkFaceMesh")
111 algo = MesherShinkFace.Segment()
113 algo.NumberOfSegments(numOfSegments)
114 ShrinkFaceMesh = MesherShinkFace.Triangle()
116 success = MesherShinkFace.Compute()
118 numFaceElementShrinkGeom = MesherShinkFace.NbFaces()
119 FinalFaceMesh = viscousBuilder.AddLayers( MesherShinkFace )
120 # Check the number of additional elements
121 # numOfSegments * 4 * numberOfLayers
122 finalNumOfElements = FinalFaceMesh.NbFaces()
123 assert( numFaceElementShrinkGeom + 4 * numOfSegments * numberOfLayers == finalNumOfElements )
125 #############END MESH SQUARE FACE
127 #############MESH CIRCULAR FACE
128 MesherCircle = smesh_builder.Mesh(Disk, "Disk")
129 viscousBuilder = MesherCircle.ViscousLayerBuilder()
130 viscousBuilder.setBuilderParameters( offset, numberOfLayers, 1.2 )
131 ShrinkCircle = viscousBuilder.GetShrinkGeometry()
132 MesherShinkCircle = smesh_builder.Mesh(ShrinkCircle, "ShrinkCircleMesh")
133 algo = MesherShinkCircle.Segment()
135 algo.NumberOfSegments(numOfSegments)
136 ShrinkCircleMesh = MesherShinkCircle.Triangle()
139 success = MesherShinkCircle.Compute()
140 numFaceElementShrinkGeom = MesherShinkCircle.NbFaces()
142 FinalCircleMesh = viscousBuilder.AddLayers( MesherShinkCircle )
143 finalNumOfElements = FinalCircleMesh.NbFaces()
144 assert( numFaceElementShrinkGeom + numOfSegments * numberOfLayers == finalNumOfElements )
145 #############END MESH CIRCULAR FACE