Salome HOME
Updated copyright comment
[modules/smesh.git] / test / test_vlapi_growthlayer.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import math
22 import salome
23 salome.salome_init_without_session()
24
25 import GEOM
26 import SHAPERSTUDY
27 from salome.geom import geomBuilder
28 from salome.smesh import smeshBuilder
29 from salome.shaper import model
30
31 def assertAlmostEqual(a,b,tol):
32    if ( abs(a-b) < tol ):
33       return True
34    else:
35       print( "not close vals", a, b ) 
36       return False
37
38
39 geompy = geomBuilder.New()
40
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)
45
46 # create a disk
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)
52
53 smesh_builder = smeshBuilder.New()
54
55 MesherBox = smesh_builder.Mesh(Box, "Box")
56 viscousBuilder = MesherBox.ViscousLayerBuilder()
57
58 #############BOX AND TETRA ELEMENTS
59 #Set prismatic layer parameters
60 offset = 0.7
61 numLayers = 4
62 viscousBuilder.setBuilderParameters( offset, numLayers, 1.2, [13], False )
63 ShrinkBox = viscousBuilder.GetShrinkGeometry()
64
65 #Mesh the shrink box
66 MesherShinkBox = smesh_builder.Mesh(ShrinkBox, "ShrinkMesh")
67 ShrinkBoxMesh = MesherShinkBox.Tetrahedron(smeshBuilder.NETGEN_1D2D3D)
68
69 #Compute 
70 success = MesherShinkBox.Compute()
71 assert( success )
72 assert( MesherShinkBox.NbVolumes() == 5 ) # if Fails! change the default value of volumes when meshing with Netgen!
73
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)
77
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()
81 #Mesh the shrink box
82 MesherShinkBox2 = smesh_builder.Mesh(ShrinkBox2, "ShrinkMesh2")
83 ShrinkBoxMesh2 = MesherShinkBox2.Tetrahedron(smeshBuilder.NETGEN_1D2D3D)
84
85 #Compute 
86 success = MesherShinkBox2.Compute()
87 assert( success )
88
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!
91
92 FinalMesh2 = viscousBuilder.AddLayers( MesherShinkBox2 )
93
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
97
98 #############MESH SQUARE FACE
99 Face = geompy.MakeFaceHW(5, 5, 1)
100 Disk = geompy.MakeDiskR(5, 1)
101
102 MesherSqr = smesh_builder.Mesh(Face, "Face")
103 viscousBuilder = MesherSqr.ViscousLayerBuilder()
104 #Set prismatic layer parameters
105 offset = 0.5
106 numberOfLayers = 6
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()
112 numOfSegments = 4
113 algo.NumberOfSegments(numOfSegments)
114 ShrinkFaceMesh = MesherShinkFace.Triangle()
115 #Compute 
116 success = MesherShinkFace.Compute()
117 assert( success )
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 )
124
125 #############END MESH SQUARE FACE
126
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()
134 numOfSegments = 12
135 algo.NumberOfSegments(numOfSegments)
136 ShrinkCircleMesh = MesherShinkCircle.Triangle()
137
138 #Compute 
139 success = MesherShinkCircle.Compute()
140 numFaceElementShrinkGeom = MesherShinkCircle.NbFaces()
141 assert( success )
142 FinalCircleMesh = viscousBuilder.AddLayers( MesherShinkCircle )
143 finalNumOfElements = FinalCircleMesh.NbFaces()
144 assert( numFaceElementShrinkGeom + numOfSegments * numberOfLayers == finalNumOfElements )
145 #############END MESH CIRCULAR FACE