X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=tests%2Fquadrangles_gradation.py;h=5e2f4fc50a7b3faedb23dfecf6f1ac4a46c327ab;hb=a5c88747eadb675c60b9c2f5f47a0e4fc05ece5c;hp=264fd8f266207c5ac96787d785badbd81b773792;hpb=217595b043e342bae8db187eb63ac9bd8c483b20;p=plugins%2Fblsurfplugin.git diff --git a/tests/quadrangles_gradation.py b/tests/quadrangles_gradation.py index 264fd8f..5e2f4fc 100644 --- a/tests/quadrangles_gradation.py +++ b/tests/quadrangles_gradation.py @@ -1,155 +1,123 @@ # -*- coding: utf-8 -*- - +# Copyright (C) 2015-2019 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# TA 24-04-2018 : quadrangle_gradation replaces +# new_1331_test_quadrangles_gradation.py as the starting geometrical part should +# be 3D and not 2D. A 2D part does not constitute a representative case. +import sys import salome +salome.salome_init() +theStudy = salome.myStudy + +### +### GEOM component +### + import GEOM from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - import math +import SALOMEDS -area_tolerance = 0.1 -nb_faces_tolerance = 20 -## Return the min and max areas of a mesh -def getMinMaxArea(mesh): - mini, maxi = mesh.GetMinMax(SMESH.FT_Area) - return mini, maxi +geompy = geomBuilder.New() + +h = 5 O = geompy.MakeVertex(0, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OY = geompy.MakeVectorDXDYDZ(0, 1, 0) OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) - -Face_1 = geompy.MakeFaceHW(10, 10, 1) -geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) -Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) -vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) -Curve_1 = geompy.MakeInterpol(vertices, True, True) - -p_small = geompy.MakeVertexOnCurve(Curve_1, 0.001) -geompy.addToStudy(p_small, "p_small") - -p_small2 = geompy.MakeVertexOnCurve(Curve_1, 0.5) -geompy.addToStudy(p_small2, "p_small2") - -p_small3 = geompy.MakeVertexOnCurve(Curve_1, 0.501) -geompy.addToStudy(p_small3, "p_small3") - -part = geompy.MakePartition([Face_1], [Curve_1, p_small, p_small2, p_small3], Limit=geompy.ShapeType["FACE"]) -geompy.addToStudy(part, "part") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -p1 = geompy.MakeVertex(-5, -5, 0) -p2 = geompy.MakeVertex(5, 5, 0) -left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(left, left_edges) -geompy.addToStudyInFather(part, left, "left") - -right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(right, right_edges) -geompy.addToStudyInFather(part, right, "right") - -bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(bottom, bottom_edges) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(top, top_edges) -geompy.addToStudyInFather(part, top, "top") - -faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"]) -sub_shapes = [] -for i, face in enumerate(faces): - geompy.addToStudyInFather(part, face, "face_%i"%(i+1)) - sub_shapes.append(face) - -# Mesh -# ==== - -import SMESH +Cylinder_1 = geompy.MakeCylinderRH(1, h) +Sphere_1 = geompy.MakeSphereR(1.5) +Translation_1 = geompy.MakeTranslation(Sphere_1, 0, 0, h) +Fuse_1 = geompy.MakeFuseList([Cylinder_1, Sphere_1, Translation_1], False, True) +geompy.addToStudy( O, 'O' ) +geompy.addToStudy( OX, 'OX' ) +geompy.addToStudy( OY, 'OY' ) +geompy.addToStudy( OZ, 'OZ' ) +geompy.addToStudy( Cylinder_1, 'Cylinder_1' ) +geompy.addToStudy( Sphere_1, 'Sphere_1' ) +geompy.addToStudy( Translation_1, 'Translation_1' ) +geompy.addToStudy( Fuse_1, 'Fuse_1' ) + +### +### SMESH component +### + +import SMESH, SALOMEDS from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -# Test gradation with quadrangles -Mesh_1 = smesh.Mesh(part, "Mesh") -algo2d = Mesh_1.Triangle(algo=smeshBuilder.BLSURF) -params = algo2d.Parameters() -params.SetGeometricMesh( 1 ) -params.SetAngleMesh( 4 ) -params.SetPhySize( 8 ) -algo2d.SetGradation(1.05) -params.SetElementType( True ) +from salome.BLSURFPlugin import BLSURFPluginBuilder -ok = Mesh_1.Compute() +smesh = smeshBuilder.New() -if not ok: - raise Exception("Error when computing Mesh_1") +# First mesh with quadrangle-dominant gradation +Mesh_1 = smesh.Mesh(Fuse_1, "Mesh_1") +MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) +MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters() +MG_CADSurf_Parameters_1.SetElementType( BLSURFPluginBuilder.QuadrangleDominant ) +MG_CADSurf_Parameters_1.SetPhySize( 1 ) +MG_CADSurf_Parameters_1.SetMaxSize( 1 ) +MG_CADSurf_Parameters_1.SetGradation( 1.05 ) +MG_CADSurf_Parameters_1.SetAngleMesh( 4 ) +isDone = Mesh_1.Compute() -# Check the areas of Mesh_1 -mini_1, maxi_1 = getMinMaxArea(Mesh_1) -mini_1_ref = 0.00197 -maxi_1_ref = 0.530 +min_1, max_1 = Mesh_1.GetMinMax(SMESH.FT_Area) -if abs(mini_1-mini_1_ref) > area_tolerance: - raise Exception("Min area of Mesh_1 incorrect") +# Check that min and max areas are not too far +assert max_1/min_1 < 6 -if maxi_1 > maxi_1_ref: - raise Exception("Max area of Mesh_1 incorrect") +# Second mesh with anisotropy (which disable gradation) +Mesh_2 = smesh.Mesh(Fuse_1, "Mesh_2") +MG_CADSurf = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf) +MG_CADSurf_Parameters_2 = MG_CADSurf.Parameters() +MG_CADSurf_Parameters_2.SetElementType( BLSURFPluginBuilder.QuadrangleDominant ) +MG_CADSurf_Parameters_2.SetPhySize( 1 ) +MG_CADSurf_Parameters_2.SetMaxSize( 1 ) +MG_CADSurf_Parameters_2.SetGradation( 1.05 ) +MG_CADSurf_Parameters_2.SetAngleMesh( 4 ) +MG_CADSurf_Parameters_2.SetAnisotropic( True ) +isDone = Mesh_2.Compute() -# Check the number of faces of Mesh_1 -nb_faces_1 = Mesh_1.NbFaces() -nb_faces_1_ref = 1208 -if nb_faces_1 < nb_faces_1_ref: - raise Exception("Number of faces of Mesh_1 incorrect") +errorMsg = '' +# retrieve the 2D lengths +length_1 = Mesh_1.GetMinMax(SMESH.FT_Length)[1] +length_2 = Mesh_2.GetMinMax(SMESH.FT_Length)[1] -# Test no gradation with quadrangles and anisotropy -# RQ: this kind of mesh is not suitable for simulation -# but gives a coarse mesh like a stl geometry -Mesh_2 = smesh.Mesh(part, "Mesh") +# TEST: expecting the max length to be larger for Mesh_2 +if length_1 > length_2: + errorMsg += '\n' + ' -> Inconsistent max lengths comparison: Mesh_1 = {} Mesh_2 = {}'.format(length_1,length_2) -algo2d = Mesh_2.Triangle(algo=smeshBuilder.BLSURF) -params = algo2d.Parameters() -params.SetGeometricMesh( 1 ) -params.SetAngleMesh( 4 ) -params.SetPhySize( 8 ) -algo2d.SetGradation(1.05) -params.SetElementType( 1 ) -params.SetAnisotropic(True) +# retrieve the max aspect ratio for the meshes +aspectRatio_1 = Mesh_1.GetMinMax(SMESH.FT_AspectRatio)[1] +aspectRatio_2 = Mesh_2.GetMinMax(SMESH.FT_AspectRatio)[1] -ok = Mesh_2.Compute() +# TEST: expecting the max value for the aspect ratio to be larger for Mesh_2 +if aspectRatio_1 > aspectRatio_2: + errorMsg += '\n' + ' -> Inconsistent Aspect ratios comparison: Mesh_1 = {} Mesh_2 = {}'.format(aspectRatio_1,aspectRatio_2) -if not ok: - raise Exception("Error when computing Mesh_2") - -# Check the areas of Mesh_2 -mini_2, maxi_2 = getMinMaxArea(Mesh_2) -mini_2_ref = 0.000408 -maxi_2_ref = 10.1982 - -if abs(mini_2-mini_2_ref) > area_tolerance: - raise Exception("Min area of Mesh_2 incorrect") - -if abs(maxi_2-maxi_2_ref) > area_tolerance: - raise Exception("Max area of Mesh_2 incorrect") - -# Check the number of faces of Mesh_2 -nb_faces_2 = Mesh_2.NbFaces() -nb_faces_2_ref = 121 -if abs(nb_faces_2-nb_faces_2_ref) > nb_faces_tolerance: - raise Exception("Number of faces of Mesh_2 incorrect") +if errorMsg != '': + raise RuntimeError("Aspect ratio check the isotropic option with MG-CADSURF algo. The test is KO." + errorMsg ) if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) - - + salome.sg.updateObjBrowser()