Salome HOME
[bos #40505][CEA] Allow assign of 3D Tetra paramam on imported 2D mesh.
[modules/smesh.git] / test / test_vlapi_shrinkgeometry.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 #Set prismatic layer parameters
59 offset = 0.1
60
61 ####SHRINK THE BOX IN ALL DIRECTIONS
62 #No list of faces is passed and the isToIgnore flag true by default so the offset if applied to the entire geometry
63 viscousBuilder.setBuilderParameters( offset, 4, 1.2 )
64 ShrinkBox = viscousBuilder.GetShrinkGeometry()
65
66 BoxProperties = geompy.BasicProperties(Box)
67 ShrinkBoxProperties = geompy.BasicProperties(ShrinkBox)
68 assert( BoxProperties[2] > ShrinkBoxProperties[2] )
69
70 assert( assertAlmostEqual( BoxProperties[2], (10.0)**(3.0), 1e-12 ) )
71 #The geometry is shrank in all directions
72 assert( assertAlmostEqual( ShrinkBoxProperties[2], (10.0-offset*2)**(3), 1e-12 ) ) 
73 ####END SHRINK THE BOX IN ALL DIRECTIONS
74
75 ####SHRINK THE BOX EXCEPT FOR ONE FACE
76 viscousBuilder = MesherBox.ViscousLayerBuilder()
77 selectableFaces = geompy.SubShapeAllSortedCentresIDs(Box, geompy.ShapeType["FACE"])
78 # Set face 1 TO BE ignored
79 viscousBuilder.setBuilderParameters( offset, 4, 1.2, [ selectableFaces[ 0 ] ], True  ) # Shrink in all faces except face id
80 ShrinkBox = viscousBuilder.GetShrinkGeometry()
81 ShrinkBoxProperties = geompy.BasicProperties(ShrinkBox)
82 selectableShrinkFaces = geompy.SubShapeAllSortedCentresIDs(ShrinkBox, geompy.ShapeType["FACE"])
83 assert( assertAlmostEqual( ShrinkBoxProperties[2], (10.0-offset*2)**(2)*(10.0-offset), 1e-12 ) ) 
84 ####END SHRINK THE BOX EXCEPT FOR ONE FACE
85
86 ####SHRINK THE BOX IN DIRECTION OF ONLY ONE FACE
87 # Set face 1 TO NOT be ignored
88 viscousBuilder.setBuilderParameters( offset, 4, 1.2, [ selectableFaces[ 0 ] ], False ) # Shrink only the faceid
89 ShrinkBox = viscousBuilder.GetShrinkGeometry()
90 ShrinkBoxProperties = geompy.BasicProperties(ShrinkBox)
91 assert( assertAlmostEqual( ShrinkBoxProperties[2], (10.0)**(2)*(10.0-offset), 1e-12 ) ) 
92 selectableShrinkFaces = geompy.SubShapeAllSortedCentresIDs(ShrinkBox, geompy.ShapeType["FACE"])
93 ####END SHRINK THE BOX IN DIRECTION OF ONLY ONE FACE
94
95 ####DO NOT SHRINK THE BOX
96 viscousBuilder.setBuilderParameters( offset, 4, 1.2, isElementToIgnore = False )
97 ShrinkBox = viscousBuilder.GetShrinkGeometry()
98 BoxProperties = geompy.BasicProperties(Box)
99 ShrinkBoxProperties = geompy.BasicProperties(ShrinkBox)
100 assert( assertAlmostEqual( BoxProperties[2], ShrinkBoxProperties[2], 1e-12) )
101 ####END DO NOT SHRINK THE BOX
102
103 ####SHRINK THE ENTIRE SPHERE
104 #Test shrinking sphere
105 Radius = 10.0
106 Sphere = geompy.MakeSphere(0,0,0,Radius)
107 MesherSphere = smesh_builder.Mesh(Sphere, "Sphere")
108 viscousBuilder = MesherSphere.ViscousLayerBuilder()
109 viscousBuilder.setBuilderParameters( offset, 4, 1.2 )
110 ShrinkSphere = viscousBuilder.GetShrinkGeometry()
111 ShrinkSphereProperties = geompy.BasicProperties(ShrinkSphere)
112 assert( ShrinkSphereProperties[2] < 4.0/3.0*math.pi * Radius**3 )
113 assert( assertAlmostEqual( ShrinkSphereProperties[2], 4.0/3.0*math.pi*(10.0-offset)**(3), 1e-12 ) ) 
114 ####END SHRINK THE ENTIRE SPHERE
115
116 ####SHRINK THE ENTIRE CYLINDER
117 #Test shrinking cylinder 
118 Cylinder = geompy.MakeCylinderRH(10,30)
119 MesherCylinder = smesh_builder.Mesh(Cylinder, "Cylinder")
120 viscousBuilder = MesherCylinder.ViscousLayerBuilder()
121 viscousBuilder.setBuilderParameters( offset, 4, 1.2 )
122 ShrinkCylinder = viscousBuilder.GetShrinkGeometry()
123 CylinderProp = geompy.BasicProperties(Cylinder)
124 ShirnkCylinderProp = geompy.BasicProperties(ShrinkCylinder)
125
126 assert( CylinderProp[2] > ShirnkCylinderProp[2] )
127 ####END SHRINK THE ENTIRE CYLINDER
128
129 ####SHRINK THE ENTIRE TUBE
130 #Test shrinking tube
131 Circle_1 = geompy.MakeCircle(None, None, 20)
132 Circle_2 = geompy.MakeCircle(None, None, 10)
133 Face_1 = geompy.MakeFaceWires([Circle_1, Circle_2], 1)
134 Tube = geompy.MakePrismDXDYDZ(Face_1, 0, 0, 100)
135
136 MesherTube = smesh_builder.Mesh(Tube, "Tube")
137 viscousBuilder = MesherTube.ViscousLayerBuilder()
138 viscousBuilder.setBuilderParameters( offset, 4, 1.2 )
139 ShrinkTube = viscousBuilder.GetShrinkGeometry()
140 TubeProp = geompy.BasicProperties(Tube)
141 ShirnkTubeProp = geompy.BasicProperties(ShrinkTube)
142 assert( TubeProp[2] > ShirnkTubeProp[2] )
143 ####END SHRINK THE ENTIRE TUBE
144
145 ####SHRINK COMPOUND OBJECT TO GENERATE COMPOUND WITH COMMON FACE
146 X     = geompy.MakeVectorDXDYDZ( 1,0,0 )
147 O     = geompy.MakeVertex( 100,50,50 )
148 plane = geompy.MakePlane( O, X, 200 ) # plane YZ
149 lX    = 200
150 lYlZ  = 100
151 box   = geompy.MakeBoxDXDYDZ(lX,lYlZ,lYlZ)
152 sBox  = geompy.MakeHalfPartition( box, plane )
153
154 # Generate a uniquebody whit coincident faces
155 # 4 left, 34 middle, 50 right
156 ignoreFaces = [4,34,50]
157 geompy.addToStudy( sBox, "SisterBox" )
158 MesherSBox = smesh_builder.Mesh( sBox, "SisterBoxMesh") 
159 ViscousBuilder = MesherSBox.ViscousLayerBuilder()
160 thickness = 20  
161 numberOfLayers = 10
162 stretchFactor = 1.5
163 ViscousBuilder.setBuilderParameters( thickness, numberOfLayers, stretchFactor, ignoreFaces )
164 ShrinkSBox = ViscousBuilder.GetShrinkGeometry()
165 SBoxProp = geompy.BasicProperties(sBox)
166 ShirnksBoxProp = geompy.BasicProperties(ShrinkSBox)
167 assert( assertAlmostEqual(ShirnksBoxProp[2], lX * (lYlZ - 2.0*thickness)**(2.0), 1e-12 ) )
168 ####END SHRINK COMPOUND OBJECT TO GENERATE COMPUND WITH COMMON FACE
169
170
171 ####SHRINK COMPOUND OBJECT TO GENERATE TWO DISJOINT SOLIDS
172 ignoreFaces = [4,50]
173 ViscousBuilder.setBuilderParameters( thickness, numberOfLayers, stretchFactor, ignoreFaces )
174 ShrinkSBox2 = ViscousBuilder.GetShrinkGeometry()
175 SBoxProp = geompy.BasicProperties(sBox)
176 ShirnksBoxProp2 = geompy.BasicProperties(ShrinkSBox2)
177 assert( assertAlmostEqual(ShirnksBoxProp2[2], (lX -2.0*thickness) * (lYlZ - 2.0*thickness)**(2.0), 1e-12 ) )
178 ####END SHRINK COMPOUND OBJECT TO GENERATE TWO DISJOINT SOLIDS
179
180
181 ######SHRINK SQUARE
182 offset = 0.5
183 numberOfLayers = 6
184 Face = geompy.MakeFaceHW(5, 5, 1)
185 MesherSqr = smesh_builder.Mesh(Face, "Face")
186 viscousBuilder = MesherSqr.ViscousLayerBuilder()
187 viscousBuilder.setBuilderParameters( offset, numberOfLayers, 1.2 )
188 ShrinkFace = viscousBuilder.GetShrinkGeometry()
189
190 FaceProperties = geompy.BasicProperties(Face)
191 ShrinkFaceProperties = geompy.BasicProperties(ShrinkFace)
192 #Test smaller face
193 assert( ShrinkFaceProperties[1] < FaceProperties[1] )
194 assertAlmostEqual( ShrinkFaceProperties[1], (5.0-offset*2.0)**(2.0), 1e-12 )
195 ######END SHRINK SQUARE
196
197 ######SHRINK CIRCLE
198 Disk = geompy.MakeDiskR(5, 1)
199
200 #Test with circle 
201 MesherCircle = smesh_builder.Mesh(Disk, "Disk")
202 viscousBuilder = MesherCircle.ViscousLayerBuilder()
203 viscousBuilder.setBuilderParameters( offset, numberOfLayers, 1.2 )
204 ShrinkCircle = viscousBuilder.GetShrinkGeometry()
205 FaceProperties = geompy.BasicProperties(Disk)
206 ShrinkFaceProperties = geompy.BasicProperties(ShrinkCircle)
207
208 assert( ShrinkFaceProperties[1] < FaceProperties[1] )
209 ######END SHRINK CIRCLE