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