Salome HOME
Handling cas were shaperstudy is not avaialable for salome on demand
[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 from salome.geom import geomBuilder
27 from salome.smesh import smeshBuilder
28 from salome.shaper import model
29
30 def assertAlmostEqual(a,b,tol):
31    if ( abs(a-b) < tol ):
32       return True
33    else:
34       print( "not close vals", a, b )
35       return False
36
37
38 geompy = geomBuilder.New()
39
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)
44
45 # create a disk
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)
51
52 smesh_builder = smeshBuilder.New()
53
54 MesherBox = smesh_builder.Mesh(Box, "Box")
55 viscousBuilder = MesherBox.ViscousLayerBuilder()
56
57 #############BOX AND TETRA ELEMENTS
58 #Set prismatic layer parameters
59 offset = 0.7
60 numLayers = 4
61 viscousBuilder.setBuilderParameters( offset, numLayers, 1.2, [13], False )
62 ShrinkBox = viscousBuilder.GetShrinkGeometry()
63
64 #Mesh the shrink box
65 MesherShinkBox = smesh_builder.Mesh(ShrinkBox, "ShrinkMesh")
66 ShrinkBoxMesh = MesherShinkBox.Tetrahedron(smeshBuilder.NETGEN_1D2D3D)
67
68 #Compute
69 success = MesherShinkBox.Compute()
70 assert( success )
71 assert( MesherShinkBox.NbVolumes() == 5 ) # if Fails! change the default value of volumes when meshing with Netgen!
72
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)
76
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()
80 #Mesh the shrink box
81 MesherShinkBox2 = smesh_builder.Mesh(ShrinkBox2, "ShrinkMesh2")
82 ShrinkBoxMesh2 = MesherShinkBox2.Tetrahedron(smeshBuilder.NETGEN_1D2D3D)
83
84 #Compute
85 success = MesherShinkBox2.Compute()
86 assert( success )
87
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!
90
91 FinalMesh2 = viscousBuilder.AddLayers( MesherShinkBox2 )
92
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
96
97 #############MESH SQUARE FACE
98 Face = geompy.MakeFaceHW(5, 5, 1)
99 Disk = geompy.MakeDiskR(5, 1)
100
101 MesherSqr = smesh_builder.Mesh(Face, "Face")
102 viscousBuilder = MesherSqr.ViscousLayerBuilder()
103 #Set prismatic layer parameters
104 offset = 0.5
105 numberOfLayers = 6
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()
111 numOfSegments = 4
112 algo.NumberOfSegments(numOfSegments)
113 ShrinkFaceMesh = MesherShinkFace.Triangle()
114 #Compute
115 success = MesherShinkFace.Compute()
116 assert( success )
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 )
123
124 #############END MESH SQUARE FACE
125
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()
133 numOfSegments = 12
134 algo.NumberOfSegments(numOfSegments)
135 ShrinkCircleMesh = MesherShinkCircle.Triangle()
136
137 #Compute
138 success = MesherShinkCircle.Compute()
139 numFaceElementShrinkGeom = MesherShinkCircle.NbFaces()
140 assert( success )
141 FinalCircleMesh = viscousBuilder.AddLayers( MesherShinkCircle )
142 finalNumOfElements = FinalCircleMesh.NbFaces()
143 assert( numFaceElementShrinkGeom + numOfSegments * numberOfLayers == finalNumOfElements )
144 #############END MESH CIRCULAR FACE