1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2015-2019 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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.
28 theStudy = salome.myStudy
35 from salome.geom import geomBuilder
40 geompy = geomBuilder.New()
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' )
65 import SMESH, SALOMEDS
66 from salome.smesh import smeshBuilder
68 from salome.BLSURFPlugin import BLSURFPluginBuilder
70 smesh = smeshBuilder.New()
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()
83 min_1, max_1 = Mesh_1.GetMinMax(SMESH.FT_Area)
85 # Check that min and max areas are not too far
86 assert max_1/min_1 < 6
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()
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]
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)
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]
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)
120 raise RuntimeError("Aspect ratio check the isotropic option with MG-CADSURF algo. The test is KO." + errorMsg )
122 if salome.sg.hasDesktop():
123 salome.sg.updateObjBrowser()