Salome HOME
updated copyright message
[plugins/blsurfplugin.git] / tests / quadrangles_gradation.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2015-2023  CEA, EDF
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 # TA 24-04-2018 : quadrangle_gradation replaces 
22 # new_1331_test_quadrangles_gradation.py as the starting geometrical part should
23 # be 3D and not 2D. A 2D part does not constitute a representative case.
24 import sys
25 import salome
26
27 salome.salome_init()
28 theStudy = salome.myStudy
29
30 ###
31 ### GEOM component
32 ###
33
34 import GEOM
35 from salome.geom import geomBuilder
36 import math
37 import SALOMEDS
38
39
40 geompy = geomBuilder.New()
41
42 h = 5
43
44 O = geompy.MakeVertex(0, 0, 0)
45 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
46 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
47 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
48 Cylinder_1 = geompy.MakeCylinderRH(1, h)
49 Sphere_1 = geompy.MakeSphereR(1.5)
50 Translation_1 = geompy.MakeTranslation(Sphere_1, 0, 0, h)
51 Fuse_1 = geompy.MakeFuseList([Cylinder_1, Sphere_1, Translation_1], False, True)
52 geompy.addToStudy( O, 'O' )
53 geompy.addToStudy( OX, 'OX' )
54 geompy.addToStudy( OY, 'OY' )
55 geompy.addToStudy( OZ, 'OZ' )
56 geompy.addToStudy( Cylinder_1, 'Cylinder_1' )
57 geompy.addToStudy( Sphere_1, 'Sphere_1' )
58 geompy.addToStudy( Translation_1, 'Translation_1' )
59 geompy.addToStudy( Fuse_1, 'Fuse_1' )
60
61 ###
62 ### SMESH component
63 ###
64
65 import  SMESH, SALOMEDS
66 from salome.smesh import smeshBuilder
67
68 from salome.BLSURFPlugin import BLSURFPluginBuilder
69
70 smesh = smeshBuilder.New()
71
72 # First mesh with quadrangle-dominant gradation
73 Mesh_1 = smesh.Mesh(Fuse_1, "Mesh_1")
74 MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
75 MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
76 MG_CADSurf_Parameters_1.SetElementType( BLSURFPluginBuilder.QuadrangleDominant )
77 MG_CADSurf_Parameters_1.SetPhySize( 1 )
78 MG_CADSurf_Parameters_1.SetMaxSize( 1 )
79 MG_CADSurf_Parameters_1.SetGradation( 1.05 )
80 MG_CADSurf_Parameters_1.SetAngleMesh( 4 )
81 isDone = Mesh_1.Compute()
82
83 min_1, max_1 = Mesh_1.GetMinMax(SMESH.FT_Area)
84
85 # Check that min and max areas are not too far
86 assert max_1/min_1 < 7
87
88 # Second mesh with anisotropy (which disable gradation)
89 Mesh_2 = smesh.Mesh(Fuse_1, "Mesh_2")
90 MG_CADSurf = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf)
91 MG_CADSurf_Parameters_2 = MG_CADSurf.Parameters()
92 MG_CADSurf_Parameters_2.SetElementType( BLSURFPluginBuilder.QuadrangleDominant )
93 MG_CADSurf_Parameters_2.SetPhySize( 1 )
94 MG_CADSurf_Parameters_2.SetMaxSize( 1 )
95 MG_CADSurf_Parameters_2.SetGradation( 1.05 )
96 MG_CADSurf_Parameters_2.SetAngleMesh( 4 )
97 MG_CADSurf_Parameters_2.SetAnisotropic( True )
98 isDone = Mesh_2.Compute()
99
100
101 errorMsg = ''
102
103 # retrieve the 2D lengths
104 length_1 = Mesh_1.GetMinMax(SMESH.FT_Length)[1]
105 length_2 = Mesh_2.GetMinMax(SMESH.FT_Length)[1]
106
107 # TEST: expecting the max length to be larger for Mesh_2
108 if length_1 > length_2:
109   errorMsg += '\n' + ' -> Inconsistent max lengths comparison: Mesh_1 = {} Mesh_2 = {}'.format(length_1,length_2)
110
111 # retrieve the max aspect ratio for the meshes
112 aspectRatio_1 = Mesh_1.GetMinMax(SMESH.FT_AspectRatio)[1]
113 aspectRatio_2 = Mesh_2.GetMinMax(SMESH.FT_AspectRatio)[1]
114
115 # TEST: expecting the max value for the aspect ratio to be larger for Mesh_2 
116 if aspectRatio_1 > aspectRatio_2:
117   errorMsg += '\n' + ' -> Inconsistent Aspect ratios comparison: Mesh_1 = {} Mesh_2 = {}'.format(aspectRatio_1,aspectRatio_2)
118
119 if errorMsg != '':
120   raise RuntimeError("Aspect ratio check the isotropic option with MG-CADSURF algo. The test is KO." + errorMsg )
121
122 if salome.sg.hasDesktop():
123   salome.sg.updateObjBrowser()