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()
26 from salome.geom import geomBuilder
27 from salome.smesh import smeshBuilder
28 from salome.shaper import model
30 def assertAlmostEqual(a,b,tol):
31 if ( abs(a-b) < tol ):
34 print( "not close vals", a, b )
38 geompy = geomBuilder.New()
40 O = geompy.MakeVertex(0, 0, 0)
41 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
42 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
43 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
46 geompy.addToStudy( O, 'O' )
47 geompy.addToStudy( OX, 'OX' )
48 geompy.addToStudy( OY, 'OY' )
49 geompy.addToStudy( OZ, 'OZ' )
50 Box = geompy.MakeBox(0,0,0,10,10,10)
52 smesh_builder = smeshBuilder.New()
54 MesherBox = smesh_builder.Mesh(Box, "Box")
55 viscousBuilder = MesherBox.ViscousLayerBuilder()
57 #############BOX AND TETRA ELEMENTS
58 #Set prismatic layer parameters
61 viscousBuilder.setBuilderParameters( offset, numLayers, 1.2, [13], False )
62 ShrinkBox = viscousBuilder.GetShrinkGeometry()
65 MesherShinkBox = smesh_builder.Mesh(ShrinkBox, "ShrinkMesh")
66 ShrinkBoxMesh = MesherShinkBox.Tetrahedron(smeshBuilder.NETGEN_1D2D3D)
69 success = MesherShinkBox.Compute()
71 assert( MesherShinkBox.NbVolumes() == 5 ) # if Fails! change the default value of volumes when meshing with Netgen!
73 FinalMesh = viscousBuilder.AddLayers( MesherShinkBox )
74 assert( FinalMesh.NbVolumes() == 5 + numLayers * 2 ) # here 2 stands for the number of face elements per face in the box
75 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)
77 #Testing the configuration where face 13 is ignored and so the offset is applied to all other faces
78 viscousBuilder.setBuilderParameters( offset, numLayers, 1.2, [13], True )
79 ShrinkBox2 = viscousBuilder.GetShrinkGeometry()
81 MesherShinkBox2 = smesh_builder.Mesh(ShrinkBox2, "ShrinkMesh2")
82 ShrinkBoxMesh2 = MesherShinkBox2.Tetrahedron(smeshBuilder.NETGEN_1D2D3D)
85 success = MesherShinkBox2.Compute()
88 #Test the number of elements on the shrink mesh
89 assert( MesherShinkBox2.NbVolumes() == 5 ) # if Fails! change the default (default hypo) number of volumes when meshing with Netgen!
91 FinalMesh2 = viscousBuilder.AddLayers( MesherShinkBox2 )
93 assert( FinalMesh2.NbVolumes() == 5 + numLayers * 2 * 5 ) # here 2 stands for the number of face elements per face in the box
94 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)
95 #############END BOX AND TETRA ELEMENTS
97 #############MESH SQUARE FACE
98 Face = geompy.MakeFaceHW(5, 5, 1)
99 Disk = geompy.MakeDiskR(5, 1)
101 MesherSqr = smesh_builder.Mesh(Face, "Face")
102 viscousBuilder = MesherSqr.ViscousLayerBuilder()
103 #Set prismatic layer parameters
106 viscousBuilder.setBuilderParameters( offset, numberOfLayers, 1.2 )
107 ShrinkFace = viscousBuilder.GetShrinkGeometry()
108 #Mesh the shrink face
109 MesherShinkFace = smesh_builder.Mesh(ShrinkFace, "ShrinkFaceMesh")
110 algo = MesherShinkFace.Segment()
112 algo.NumberOfSegments(numOfSegments)
113 ShrinkFaceMesh = MesherShinkFace.Triangle()
115 success = MesherShinkFace.Compute()
117 numFaceElementShrinkGeom = MesherShinkFace.NbFaces()
118 FinalFaceMesh = viscousBuilder.AddLayers( MesherShinkFace )
119 # Check the number of additional elements
120 # numOfSegments * 4 * numberOfLayers
121 finalNumOfElements = FinalFaceMesh.NbFaces()
122 assert( numFaceElementShrinkGeom + 4 * numOfSegments * numberOfLayers == finalNumOfElements )
124 #############END MESH SQUARE FACE
126 #############MESH CIRCULAR FACE
127 MesherCircle = smesh_builder.Mesh(Disk, "Disk")
128 viscousBuilder = MesherCircle.ViscousLayerBuilder()
129 viscousBuilder.setBuilderParameters( offset, numberOfLayers, 1.2 )
130 ShrinkCircle = viscousBuilder.GetShrinkGeometry()
131 MesherShinkCircle = smesh_builder.Mesh(ShrinkCircle, "ShrinkCircleMesh")
132 algo = MesherShinkCircle.Segment()
134 algo.NumberOfSegments(numOfSegments)
135 ShrinkCircleMesh = MesherShinkCircle.Triangle()
138 success = MesherShinkCircle.Compute()
139 numFaceElementShrinkGeom = MesherShinkCircle.NbFaces()
141 FinalCircleMesh = viscousBuilder.AddLayers( MesherShinkCircle )
142 finalNumOfElements = FinalCircleMesh.NbFaces()
143 assert( numFaceElementShrinkGeom + numOfSegments * numberOfLayers == finalNumOfElements )
144 #############END MESH CIRCULAR FACE