3 # test fix bos #33557 Bad pyramids generated
18 algo_gmsh = "Delaunay"
30 from salome.geom import geomBuilder
35 geompy = geomBuilder.New()
37 O = geompy.MakeVertex(0, 0, 0)
38 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
39 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
40 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
41 Vertex_1 = geompy.MakeVertex(-0.62375, 0.0575, 0.02)
42 Vertex_2 = geompy.MakeVertex(-0.62375, -0.0575, 0.02)
43 Vertex_3 = geompy.MakeVertex(-0.365, -0.0575, 0.02)
44 Vertex_4 = geompy.MakeVertex(-0.365, 0.0575, 0.02)
45 geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
46 Curve_1 = geompy.MakePolyline([Vertex_1, Vertex_4, Vertex_3, Vertex_2], True)
47 Face_1 = geompy.MakeFaceWires([Curve_1], 1)
48 [right_side] = geompy.SubShapes(Face_1, [6])
49 [right_side] = geompy.GetExistingSubObjects(Face_1, False)
50 path = geompy.MakePrismDXDYDZ(Vertex_3, 0, 0, 0.1)
51 Translation_1 = geompy.MakeTranslation(Vertex_3, 0, -0.02, 0)
52 Translation_2 = geompy.MakeTranslation(Vertex_4, 0, 0.02, 0)
53 Translation_3 = geompy.MakeTranslation(Vertex_4, 0, 0.02, 0)
54 Line_1 = geompy.MakeLineTwoPnt(Translation_3, Translation_1)
55 Extrusion_1 = geompy.MakePrismDXDYDZ(Line_1, 0.2, 0, 0)
56 Partition_1 = geompy.MakePartition([Extrusion_1], [Face_1], [], [], geompy.ShapeType["FACE"], 0, [], 0)
57 Extrusion_2 = geompy.MakePrismDXDYDZ(Partition_1, 0, 0, 0.1)
58 [Face_to_enforce] = geompy.SubShapes(Extrusion_2, [30])
59 geompy.addToStudy( O, 'O' )
60 geompy.addToStudy( OX, 'OX' )
61 geompy.addToStudy( OY, 'OY' )
62 geompy.addToStudy( OZ, 'OZ' )
63 geompy.addToStudy( Vertex_1, 'Vertex_1' )
64 geompy.addToStudy( Vertex_2, 'Vertex_2' )
65 geompy.addToStudy( Vertex_3, 'Vertex_3' )
66 geompy.addToStudy( Vertex_4, 'Vertex_4' )
67 geompy.addToStudy( Curve_1, 'Curve_1' )
68 geompy.addToStudy( Face_1, 'Face_1' )
69 geompy.addToStudyInFather( Face_1, right_side, 'right_side' )
70 geompy.addToStudy( path, 'path' )
71 geompy.addToStudy( Translation_2, 'Translation_2' )
72 geompy.addToStudy( Translation_1, 'Translation_1' )
73 geompy.addToStudy( Translation_3, 'Translation_3' )
74 geompy.addToStudy( Line_1, 'Line_1' )
75 geompy.addToStudy( Extrusion_1, 'Extrusion_1' )
76 geompy.addToStudy( Partition_1, 'Partition_1' )
77 geompy.addToStudy( Extrusion_2, 'Extrusion_2' )
78 geompy.addToStudyInFather( Extrusion_2, Face_to_enforce, 'Face_to_enforce' )
81 # Create a group with other faces than Face_to_enforce
82 all_faces = geompy.SubShapeAll(Extrusion_2, geompy.ShapeType["FACE"])
83 gr_other_faces = geompy.CreateGroup(Extrusion_2, geompy.ShapeType["FACE"])
84 geompy.UnionList(gr_other_faces, all_faces)
85 geompy.DifferenceList(gr_other_faces, [Face_to_enforce])
86 geompy.addToStudyInFather( Extrusion_2, gr_other_faces, 'other_faces' )
88 geom_volume = geompy.BasicProperties(Extrusion_2)[2]
94 import SMESH, SALOMEDS
95 from salome.smesh import smeshBuilder
97 smesh = smeshBuilder.New()
99 Mesh_1 = smesh.Mesh(Face_1,'Mesh_1')
101 Regular_1D = Mesh_1.Segment()
102 Number_of_Segments_1 = Regular_1D.NumberOfSegments(10)
104 Quadrangle_2D = Mesh_1.Quadrangle(algo=smeshBuilder.QUADRANGLE)
106 right_side_1 = Mesh_1.GroupOnGeom(right_side,'right_side',SMESH.EDGE)
107 Regular_1D_1 = Mesh_1.Segment(geom=right_side)
110 Number_of_Segments_2 = Regular_1D_1.NumberOfSegments(nb_segs_right)
111 Propagation_of_1D_Hyp = Regular_1D_1.Propagation()
113 isDone = Mesh_1.Compute()
115 Mesh_path = smesh.Mesh(path,'Mesh_path')
117 Regular_1D_2 = Mesh_path.Segment()
118 Local_Length_1 = Regular_1D_2.LocalLength(0.01,None,1e-07)
120 isDone = Mesh_path.Compute()
122 ([ right_side_extruded, right_side_top ], error) = Mesh_1.ExtrusionAlongPathObjects( [], [ Mesh_1 ], [ Mesh_1 ], Mesh_path, None, 1, 0, [ ], 0, 0, [ 0, 0, 0 ], 1, [ ], 0 )
124 Mesh_2 = smesh.Mesh(Extrusion_2,'Mesh_2')
126 # Enforce elements from Mesh_1
127 Import_1D2D = Mesh_2.UseExisting2DElements(geom=Face_to_enforce)
128 Source_Faces_1 = Import_1D2D.SourceFaces([ right_side_extruded ],0,0)
131 # CADSurf is global mesh
132 MG_CADSurf = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf)
134 # CADSurf is a submesh on other faces
135 MG_CADSurf = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf, geom=gr_other_faces)
136 MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
137 MG_CADSurf_Parameters_1.SetGeometricMesh( 0 )
138 MG_CADSurf_Parameters_1.SetPhySize( 0.005 )
139 MG_CADSurf_Parameters_1.SetMinSize( 0.005 )
140 MG_CADSurf_Parameters_1.SetMaxSize( 0.005 )
141 MG_CADSurf_Parameters_1.SetCorrectSurfaceIntersection( False )
142 MG_CADSurf_Parameters_1.SetElementType( 1 ) # Quadrangle preference
143 if algo == "MG-Tetra":
144 Mesh_2.Tetrahedron(algo=smeshBuilder.MG_Tetra)
145 elif algo == "Netgen":
148 GMSH = Mesh_2.Tetrahedron(algo=smeshBuilder.GMSH)
149 Gmsh_Parameters = GMSH.Parameters()
150 Gmsh_Parameters.Set2DAlgo( 0 )
151 Gmsh_Parameters.SetMinSize( 0 )
152 Gmsh_Parameters.SetMaxSize( 0.005 )
153 if algo_gmsh == "HXT":
154 Gmsh_Parameters.Set3DAlgo( 4 )
156 Gmsh_Parameters.Set3DAlgo( 0 )
157 Gmsh_Parameters.SetIs2d( 0 )
159 Face_to_enforce_1 = Mesh_2.GroupOnGeom(Face_to_enforce,'Face_to_enforce',SMESH.FACE)
162 isDone = Mesh_2.Compute()
164 gr_pyramids = Mesh_2.MakeGroup("pyramids", SMESH.VOLUME, CritType=SMESH.FT_ElemGeomType, Threshold=SMESH.Geom_PYRAMID)
166 if salome.sg.hasDesktop():
167 salome.sg.updateObjBrowser()
170 raise Exception("Error on mesh compute")
172 mesh_volume = Mesh_2.GetVolume()
173 assert abs(mesh_volume-geom_volume)/geom_volume < 1e-7, "Wrong mesh volume"
175 min_aspect_ratio, max_aspect_ratio = Mesh_2.GetMinMax(SMESH.FT_AspectRatio3D)
176 assert max_aspect_ratio < 200, "Bad aspect ratio 3D: %.1f"%max_aspect_ratio
178 # Check min and max volume of pyramids
179 min_volume, max_volume = Mesh_2.GetMinMax(SMESH.FT_Volume3D, gr_pyramids)
180 assert min_volume > 1e-10, "Bad min volume: %s"%min_volume
181 expected_max_volume = 6.829e-8
182 assert max_volume < 1.5*expected_max_volume, "Bad max volume: %s"%max_volume