From: Christophe Bourcier Date: Wed, 14 Feb 2018 11:30:09 +0000 (+0100) Subject: Change the shape to better illustrate anisotropy with quadrangles (check that gradati... X-Git-Tag: V8_5_0a1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eca8d6662b4b079ed8ca03e48d5ed2ab27da3b9e;p=plugins%2Fblsurfplugin.git Change the shape to better illustrate anisotropy with quadrangles (check that gradation is deactivated) --- diff --git a/tests/quadrangles_gradation.py b/tests/quadrangles_gradation.py index 264fd8f..5fd4813 100644 --- a/tests/quadrangles_gradation.py +++ b/tests/quadrangles_gradation.py @@ -1,155 +1,86 @@ # -*- coding: utf-8 -*- + +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(theStudy) + +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 ) - -ok = Mesh_1.Compute() - -if not ok: - raise Exception("Error when computing Mesh_1") - -# Check the areas of Mesh_1 -mini_1, maxi_1 = getMinMaxArea(Mesh_1) -mini_1_ref = 0.00197 -maxi_1_ref = 0.530 -if abs(mini_1-mini_1_ref) > area_tolerance: - raise Exception("Min area of Mesh_1 incorrect") +from salome.BLSURFPlugin import BLSURFPluginBuilder -if maxi_1 > maxi_1_ref: - raise Exception("Max area of Mesh_1 incorrect") +smesh = smeshBuilder.New(theStudy) -# Check the number of faces of Mesh_1 -nb_faces_1 = Mesh_1.NbFaces() -nb_faces_1_ref = 1208 +# 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() -if nb_faces_1 < nb_faces_1_ref: - raise Exception("Number of faces of Mesh_1 incorrect") +min_1, max_1 = Mesh_1.GetMinMax(SMESH.FT_Area) +# Check that min and max areas are not too far +assert max_1/min_1 < 6 -# 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") +# 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() -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) +min_2, max_2 = Mesh_2.GetMinMax(SMESH.FT_Area) -ok = Mesh_2.Compute() - -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") +# Check that min and max ration increase with anisotropy +assert max_2/min_2 > 20 if salome.sg.hasDesktop(): salome.sg.updateObjBrowser(True) - -