Version: 8.3.0
 All Classes Namespaces Files Functions Variables Groups Pages
Defining Hypotheses and Algorithms

This page provides example codes of defining algorithms and hypotheses.


Defining 1D Hypotheses


Arithmetic Progression and Geometric Progression

1 # Arithmetic Progression and Geometric Progression
2 
3 import salome
4 salome.salome_init()
5 
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 from salome.smesh import smeshBuilder
10 smesh = smeshBuilder.New(salome.myStudy)
11 
12 # create a box
13 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
14 geompy.addToStudy(box, "Box")
15 
16 # create a hexahedral mesh on the box
17 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
18 
19 # create a Regular 1D algorithm for edges
20 algo1D = hexa.Segment()
21 
22 # optionally reverse node distribution on certain edges
23 allEdges = geompy.SubShapeAllSorted( box, geompy.ShapeType["EDGE"])
24 reversedEdges = [ allEdges[0], allEdges[4] ]
25 
26 # define "Arithmetic1D" hypothesis to cut all edges in several segments with increasing arithmetic length
27 algo1D.Arithmetic1D(1, 4, reversedEdges)
28 
29 # define "Geometric Progression" hypothesis on one edge to cut this edge in segments with length increasing by 20% starting from 1
30 gpAlgo = hexa.Segment( allEdges[1] )
31 gpAlgo.GeometricProgression( 1, 1.2 )
32 
33 # propagate distribution of nodes computed using "Geometric Progression" to parallel edges
34 gpAlgo.PropagationOfDistribution()
35 
36 
37 # create a quadrangle 2D algorithm for faces
38 hexa.Quadrangle()
39 
40 # create a hexahedron 3D algorithm for solids
41 hexa.Hexahedron()
42 
43 # compute the mesh
44 hexa.Compute()

Download this script


Adaptive

1 import salome, math
2 salome.salome_init()
3 from salome.geom import geomBuilder
4 geompy = geomBuilder.New(salome.myStudy)
5 from salome.smesh import smeshBuilder
6 smesh = smeshBuilder.New(salome.myStudy)
7 
8 
9 box = geompy.MakeBoxDXDYDZ( 100, 100, 100 )
10 tool = geompy.MakeTranslation( box, 50, 0, 10 )
11 axis = geompy.MakeVector( geompy.MakeVertex( 100, 0, 100 ),geompy.MakeVertex( 100, 10, 100 ),)
12 tool = geompy.Rotate( tool, axis, math.pi * 25 / 180. )
13 shape = geompy.MakeCut( box, tool )
14 cyl = geompy.MakeCylinder( geompy.MakeVertex( -10,5, 95 ), geompy.MakeVectorDXDYDZ(1,0,0), 2, 90)
15 shape = geompy.MakeCut( shape, cyl )
16 tool = geompy.MakeBoxTwoPnt( geompy.MakeVertex( -10, 2, 15 ), geompy.MakeVertex( 90, 5, 16 ))
17 shape = geompy.MakeCut( shape, tool, theName="shape" )
18 
19 # Parameters of Adaptive hypothesis. minSize and maxSize are such that they do not limit
20 # size of segments because size of geometrical features lies within [2.-100.] range, hence
21 # size of segments is defined by deflection parameter and size of geometrical features only.
22 minSize = 0.1
23 maxSize = 200
24 deflection = 0.05
25 
26 mesh = smesh.Mesh( shape )
27 mesh.Segment().Adaptive( minSize, maxSize, deflection )
28 mesh.Triangle().MaxElementArea( 300 )
29 mesh.Compute()
30 

Download this script


Deflection and Number of Segments

1 # Deflection and Number of Segments
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create a face from arc and straight segment
14 px = geompy.MakeVertex(100., 0. , 0. )
15 py = geompy.MakeVertex(0. , 100., 0. )
16 pz = geompy.MakeVertex(0. , 0. , 100.)
17 
18 exy = geompy.MakeEdge(px, py)
19 arc = geompy.MakeArc(py, pz, px)
20 
21 wire = geompy.MakeWire([exy, arc])
22 
23 isPlanarFace = 1
24 face1 = geompy.MakeFace(wire, isPlanarFace)
25 geompy.addToStudy(face1,"Face1")
26 
27 # get edges from the face
28 e_straight,e_arc = geompy.SubShapeAll(face1, geompy.ShapeType["EDGE"])
29 geompy.addToStudyInFather(face1, e_arc, "Arc Edge")
30 
31 # create hexahedral mesh
32 hexa = smesh.Mesh(face1, "Face : triangle mesh")
33 
34 # define "NumberOfSegments" hypothesis to cut a straight edge in a fixed number of segments
35 algo1D = hexa.Segment()
36 algo1D.NumberOfSegments(6)
37 
38 # define "MaxElementArea" hypothesis
39 algo2D = hexa.Triangle()
40 algo2D.MaxElementArea(70.0)
41 
42 # define a local "Deflection1D" hypothesis on the arc
43 algo_local = hexa.Segment(e_arc)
44 algo_local.Deflection1D(1.0)
45 
46 # compute the mesh
47 hexa.Compute()

Download this script


Start and End Length

1 # Start and End Length
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create a box
14 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
15 geompy.addToStudy(box, "Box")
16 
17 # get one edge of the box to put local hypothesis on
18 p5 = geompy.MakeVertex(5., 0., 0.)
19 EdgeX = geompy.GetEdgeNearPoint(box, p5)
20 geompy.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
21 
22 # create a hexahedral mesh on the box
23 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
24 
25 # set algorithms
26 algo1D = hexa.Segment()
27 hexa.Quadrangle()
28 hexa.Hexahedron()
29 
30 # define "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
31 algo1D.NumberOfSegments(4)
32 
33 # create a local hypothesis
34 algo_local = hexa.Segment(EdgeX)
35 
36 # define "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
37 algo_local.StartEndLength(1, 6)
38 
39 # define "Propagation" hypothesis that propagates all other hypothesis
40 # on all edges on the opposite side in case of quadrangular faces
41 algo_local.Propagation()
42 
43 # compute the mesh
44 hexa.Compute()

Download this script


Local Length

1 # Local Length
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create a box
14 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
15 geompy.addToStudy(box, "Box")
16 
17 # get one edge of the box to put local hypothesis on
18 p5 = geompy.MakeVertex(5., 0., 0.)
19 EdgeX = geompy.GetEdgeNearPoint(box, p5)
20 geompy.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
21 
22 # create a hexahedral mesh on the box
23 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
24 
25 # set algorithms
26 algo1D = hexa.Segment()
27 hexa.Quadrangle()
28 hexa.Hexahedron()
29 
30 # define "NumberOfSegments" hypothesis to cut all edges in a fixed number of segments
31 algo1D.NumberOfSegments(4)
32 
33 # create a sub-mesh
34 algo_local = hexa.Segment(EdgeX)
35 
36 # define "LocalLength" hypothesis to cut an edge in several segments with the same length
37 algo_local.LocalLength(2.)
38 
39 # define "Propagation" hypothesis that propagates all other hypothesis
40 # on all edges on the opposite side in case of quadrangular faces
41 algo_local.Propagation()
42 
43 # compute the mesh
44 hexa.Compute()

Download this script


Defining 2D and 3D hypotheses


Maximum Element Area

1 # Maximum Element Area
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create a face
14 px = geompy.MakeVertex(100., 0. , 0. )
15 py = geompy.MakeVertex(0. , 100., 0. )
16 pz = geompy.MakeVertex(0. , 0. , 100.)
17 
18 vxy = geompy.MakeVector(px, py)
19 arc = geompy.MakeArc(py, pz, px)
20 wire = geompy.MakeWire([vxy, arc])
21 
22 isPlanarFace = 1
23 face = geompy.MakeFace(wire, isPlanarFace)
24 
25 # add the face in the study
26 id_face = geompy.addToStudy(face, "Face to be meshed")
27 
28 # create a mesh
29 tria_mesh = smesh.Mesh(face, "Face : triangulation")
30 
31 # define 1D meshing:
32 algo = tria_mesh.Segment()
33 algo.NumberOfSegments(20)
34 
35 # define 2D meshing:
36 
37 # assign triangulation algorithm
38 algo = tria_mesh.Triangle()
39 
40 # assign "Max Element Area" hypothesis
41 algo.MaxElementArea(100)
42 
43 # compute the mesh
44 tria_mesh.Compute()

Download this script


Maximum Element Volume

1 # Maximum Element Volume
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create a cylinder
14 cyl = geompy.MakeCylinderRH(30., 50.)
15 geompy.addToStudy(cyl, "cyl")
16 
17 # create a mesh on the cylinder
18 tetra = smesh.Mesh(cyl, "Cylinder : tetrahedrical mesh")
19 
20 # assign algorithms
21 algo1D = tetra.Segment()
22 algo2D = tetra.Triangle()
23 algo3D = tetra.Tetrahedron()
24 
25 # assign 1D and 2D hypotheses
26 algo1D.NumberOfSegments(7)
27 algo2D.MaxElementArea(150.)
28 
29 # assign Max Element Volume hypothesis
30 algo3D.MaxElementVolume(200.)
31 
32 # compute the mesh
33 ret = tetra.Compute()
34 if ret == 0:
35  print "problem when computing the mesh"
36 else:
37  print "Computation succeeded"

Download this script


Length from Edges

1 # Length from Edges
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create sketchers
14 sketcher1 = geompy.MakeSketcher("Sketcher:F 0 0:TT 70 0:TT 70 70:TT 0 70:WW")
15 sketcher2 = geompy.MakeSketcher("Sketcher:F 20 20:TT 50 20:TT 50 50:TT 20 50:WW")
16 
17 # create a face from two wires
18 isPlanarFace = 1
19 face1 = geompy.MakeFaces([sketcher1, sketcher2], isPlanarFace)
20 geompy.addToStudy(face1, "Face1")
21 
22 # create a mesh
23 tria = smesh.Mesh(face1, "Face : triangle 2D mesh")
24 
25 # Define 1D meshing
26 algo1D = tria.Segment()
27 algo1D.LocalLength(3.)
28 
29 # create and assign the algorithm for 2D meshing with triangles
30 algo2D = tria.Triangle()
31 
32 # create and assign "LengthFromEdges" hypothesis to build triangles with
33 # linear size close to the length of the segments generated on the face wires (3.)
34 algo2D.LengthFromEdges()
35 
36 # compute the mesh
37 tria.Compute()

Download this script


Defining Additional Hypotheses


Propagation

1 # Propagation
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create a box
14 base = geompy.MakeSketcher("Sketcher:F 0 0:TT 10 0:TT 20 10:TT 0 10:WF", theName="F")
15 box = geompy.MakePrismDXDYDZ( base, 0,0,10 )
16 geompy.addToStudy(box, "Box")
17 
18 # get one edge of the box to put local hypothesis on
19 p5 = geompy.MakeVertex(5., 0., 0.)
20 EdgeX = geompy.GetEdgeNearPoint(box, p5)
21 geompy.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
22 
23 # create a hexahedral mesh on the box
24 hexa = smesh.Mesh(box, "Propagation of hypothesis")
25 
26 # set global algorithms and hypotheses
27 algo1D = hexa.Segment()
28 hexa.Quadrangle()
29 hexa.Hexahedron()
30 algo1D.NumberOfSegments(4)
31 
32 # create a sub-mesh with local 1D hypothesis and "Propagation of 1D Hypothesis"
33 algo_local = hexa.Segment(EdgeX)
34 
35 # define "Arithmetic1D" hypothesis to cut an edge in several segments with increasing length
36 algo_local.Arithmetic1D(1, 4)
37 
38 # define "Propagation" hypothesis that propagates "Arithmetic1D" hypothesis
39 # from 'EdgeX' on opposite sides of all quadilateral faces
40 algo_local.Propagation()
41 
42 # compute the mesh which contains prisms
43 hexa.Compute()
44 
45 
46 # create another mesh on the box
47 mesh = smesh.Mesh(box, "Propagation of distribution of nodes")
48 
49 # set global algorithms and hypotheses
50 algo1D = mesh.Segment()
51 mesh.Quadrangle()
52 mesh.Hexahedron()
53 algo1D.NumberOfSegments(4)
54 
55 # create a sub-mesh with local 1D hypothesis and "Propagation of Node Distribution"
56 algo_local = mesh.Segment(EdgeX)
57 algo_local.Arithmetic1D(1, 4)
58 
59 # define "Propagation Of Distribution" hypothesis that propagates
60 # distribution of nodes generated by "Arithmetic1D" hypothesis
61 # from 'EdgeX' on opposite sides of all quadilateral faces
62 algo_local.PropagationOfDistribution()
63 
64 # compute the mesh which contains hexahedra only
65 mesh.Compute()

Download this script


Defining Meshing Algorithms

1 # Defining Meshing Algorithms
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # create a box
14 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
15 geompy.addToStudy(box, "Box")
16 
17 # Create a hexahedral mesh on the box
18 hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
19 
20 # create a Regular 1D algorithm for edges
21 algo1D = hexa.Segment()
22 
23 # create a quadrangle 2D algorithm for faces
24 algo2D = hexa.Quadrangle()
25 
26 # create a hexahedron 3D algorithm for solids
27 algo3D = hexa.Hexahedron()
28 
29 # define hypotheses
30 algo1D.Arithmetic1D(1, 4)
31 
32 # compute the mesh
33 hexa.Compute()
34 
35 # 2. Create a tetrahedral mesh on the box
36 tetra = smesh.Mesh(box, "Box : tetrahedrical mesh")
37 
38 # create a Regular 1D algorithm for edges
39 algo1D = tetra.Segment()
40 
41 # create a Mefisto 2D algorithm for faces
42 algo2D = tetra.Triangle()
43 
44 # create a 3D algorithm for solids
45 algo3D = tetra.Tetrahedron()
46 
47 # define hypotheses
48 algo1D.Arithmetic1D(1, 4)
49 algo2D.LengthFromEdges()
50 
51 # compute the mesh
52 tetra.Compute()

Download this script


Projection Algorithms

1 # Projection Algorithms
2 
3 # Project prisms from one meshed box to another mesh on the same box
4 
5 import salome
6 salome.salome_init()
7 import GEOM
8 from salome.geom import geomBuilder
9 geompy = geomBuilder.New(salome.myStudy)
10 
11 import SMESH, SALOMEDS
12 from salome.smesh import smeshBuilder
13 smesh = smeshBuilder.New(salome.myStudy)
14 
15 # Prepare geometry
16 
17 # Create a parallelepiped
18 box = geompy.MakeBoxDXDYDZ(200, 100, 70)
19 geompy.addToStudy( box, "box" )
20 
21 # Get geom faces to mesh with triangles in the 1ts and 2nd meshes
22 faces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
23 # 2 adjacent faces of the box
24 f1 = faces[2]
25 f2 = faces[0]
26 # face opposite to f2
27 f2opp = geompy.GetOppositeFace( box, f2 )
28 
29 # Get vertices used to specify how to associate sides of faces at projection
30 [v1F1, v2F1] = geompy.SubShapeAll(f1, geompy.ShapeType["VERTEX"])[:2]
31 [v1F2, v2F2] = geompy.SubShapeAll(f2, geompy.ShapeType["VERTEX"])[:2]
32 geompy.addToStudyInFather( box, v1F1, "v1F1" )
33 geompy.addToStudyInFather( box, v2F1, "v2F1" )
34 geompy.addToStudyInFather( box, v1F2, "v1F2" )
35 geompy.addToStudyInFather( box, v2F2, "v2F2" )
36 
37 # Make group of 3 edges of f1 and f2
38 edgesF1 = geompy.CreateGroup(f1, geompy.ShapeType["EDGE"])
39 geompy.UnionList( edgesF1, geompy.SubShapeAll(f1, geompy.ShapeType["EDGE"])[:3])
40 edgesF2 = geompy.CreateGroup(f2, geompy.ShapeType["EDGE"])
41 geompy.UnionList( edgesF2, geompy.SubShapeAll(f2, geompy.ShapeType["EDGE"])[:3])
42 geompy.addToStudyInFather( box, edgesF1, "edgesF1" )
43 geompy.addToStudyInFather( box, edgesF2, "edgesF2" )
44 
45 
46 # Make the source mesh with prisms
47 src_mesh = smesh.Mesh(box, "Source mesh")
48 src_mesh.Segment().NumberOfSegments(9,10)
49 src_mesh.Quadrangle()
50 src_mesh.Hexahedron()
51 src_mesh.Triangle(f1) # triangular sub-mesh
52 src_mesh.Compute()
53 
54 
55 # Mesh the box using projection algorithms
56 
57 # Define the same global 1D and 2D hypotheses
58 tgt_mesh = smesh.Mesh(box, "Target mesh")
59 tgt_mesh.Segment().NumberOfSegments(9,10,UseExisting=True)
60 tgt_mesh.Quadrangle()
61 
62 # Define Projection 1D algorithm to project 1d mesh elements from group edgesF2 to edgesF1
63 # It is actually not needed, just a demonstration
64 proj1D = tgt_mesh.Projection1D( edgesF1 )
65 # each vertex must be at the end of a connected group of edges (or a sole edge)
66 proj1D.SourceEdge( edgesF2, src_mesh, v2F1, v2F2 )
67 
68 # Define 2D hypotheses to project triangles from f1 face of the source mesh to
69 # f2 face in the target mesh. Vertices specify how to associate sides of faces
70 proj2D = tgt_mesh.Projection2D( f2 )
71 proj2D.SourceFace( f1, src_mesh, v1F1, v1F2, v2F1, v2F2 )
72 
73 # 2D hypotheses to project triangles from f2 of target mesh to the face opposite to f2.
74 # Association of face sides is default
75 proj2D = tgt_mesh.Projection2D( f2opp )
76 proj2D.SourceFace( f2 )
77 
78 # 3D hypotheses to project prisms from the source to the target mesh
79 proj3D = tgt_mesh.Projection3D()
80 proj3D.SourceShape3D( box, src_mesh, v1F1, v1F2, v2F1, v2F2 )
81 tgt_mesh.Compute()
82 
83 # Move the source mesh to visualy compare the two meshes
84 src_mesh.TranslateObject( src_mesh, smesh.MakeDirStruct( 210, 0, 0 ), Copy=False)

Download this script

Projection 1D2D

1 # Projection 1D2D
2 
3 # Project triangles from one meshed face to another mesh on the same box
4 
5 import salome
6 salome.salome_init()
7 import GEOM
8 from salome.geom import geomBuilder
9 geompy = geomBuilder.New(salome.myStudy)
10 
11 import SMESH, SALOMEDS
12 from salome.smesh import smeshBuilder
13 smesh = smeshBuilder.New(salome.myStudy)
14 
15 # Prepare geometry
16 
17 # Create a box
18 box = geompy.MakeBoxDXDYDZ(100, 100, 100)
19 
20 # Get geom faces to mesh with triangles in the 1ts and 2nd meshes
21 faces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
22 # 2 adjacent faces of the box
23 Face_1 = faces[2]
24 Face_2 = faces[0]
25 
26 geompy.addToStudy( box, 'box' )
27 geompy.addToStudyInFather( box, Face_1, 'Face_1' )
28 geompy.addToStudyInFather( box, Face_2, 'Face_2' )
29 
30 
31 # Make the source mesh triangulated by MEFISTO
32 src_mesh = smesh.Mesh(Face_1, "Source mesh")
33 src_mesh.Segment().NumberOfSegments(15)
34 src_mesh.Triangle()
35 src_mesh.Compute()
36 
37 # Mesh the target mesh using the algorithm Projection1D2D
38 tgt_mesh = smesh.Mesh(Face_2, "Target mesh")
39 tgt_mesh.Projection1D2D().SourceFace(Face_1,src_mesh)
40 tgt_mesh.Compute()

Download this script


1D Mesh with Fixed Points example

1 # 1D Mesh with Fixed Points example
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 from salome.StdMeshers import StdMeshersBuilder
13 
14 # Create face and explode it on edges
15 face = geompy.MakeFaceHW(100, 100, 1)
16 edges = geompy.SubShapeAllSorted(face, geompy.ShapeType["EDGE"])
17 geompy.addToStudy( face, "Face" )
18 
19 # get the first edge from exploded result
20 edge1 = geompy.GetSubShapeID(face, edges[0])
21 
22 # Define Mesh on previously created face
23 Mesh_1 = smesh.Mesh(face)
24 
25 # Create Fixed Point 1D hypothesis and define parameters.
26 # Note: values greater than 1.0 and less than 0.0 are not taken into account;
27 # duplicated values are removed. Also, if not specified explicitly, values 0.0 and 1.0
28 # add added automatically.
29 # The number of segments should correspond to the number of points (NbSeg = NbPnt-1);
30 # extra values of segments splitting parameter are not taken into account,
31 # while missing values are considered to be equal to 1.
32 Fixed_points_1D_1 = smesh.CreateHypothesis('FixedPoints1D')
33 Fixed_points_1D_1.SetPoints( [ 1.1, 0.9, 0.5, 0.0, 0.5, -0.3 ] )
34 Fixed_points_1D_1.SetNbSegments( [ 3, 1, 2 ] )
35 Fixed_points_1D_1.SetReversedEdges( [edge1] )
36 
37 # Add hypothesis to mesh and define 2D parameters
38 Mesh_1.AddHypothesis(Fixed_points_1D_1)
39 Regular_1D = Mesh_1.Segment()
40 Quadrangle_2D = Mesh_1.Quadrangle()
41 # Compute mesh
42 Mesh_1.Compute()

Download this script

Radial Quadrangle 1D-2D example

1 # Radial Quadrangle 1D-2D example
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # Create face from the wire and add to study
14 Face = geompy.MakeSketcher("Sketcher:F 0 0:TT 20 0:R 90:C 20 90:WF", [0, 0, 0, 1, 0, 0, 0, 0, 1])
15 geompy.addToStudy(Face,"Face")
16 circle, radius1, radius2 = geompy.SubShapeAllSorted(Face, geompy.ShapeType["EDGE"])
17 geompy.addToStudyInFather(Face, radius1,"radius1")
18 geompy.addToStudyInFather(Face, radius2,"radius2")
19 geompy.addToStudyInFather(Face, circle,"circle")
20 
21 
22 # Define geometry for mesh, and Radial Quadrange algorithm
23 mesh = smesh.Mesh(Face)
24 radial_Quad_algo = mesh.Quadrangle(algo=smeshBuilder.RADIAL_QUAD)
25 
26 # The Radial Quadrange algorithm can work without any hypothesis
27 # In this case it uses "Default Nb of Segments" preferences parameter to discretize edges
28 mesh.Compute()
29 
30 # The Radial Quadrange uses global or local 1d hypotheses if it does
31 # not have its own hypotheses.
32 # Define global hypotheses to discretize radial edges and a local one for circular edge
33 global_Nb_Segments = mesh.Segment().NumberOfSegments(5)
34 local_Nb_Segments = mesh.Segment(circle).NumberOfSegments(10)
35 mesh.Compute()
36 
37 # Define own parameters of Radial Quadrange algorithm
38 radial_Quad_algo.NumberOfLayers( 4 )
39 mesh.Compute()

Download this script

Quadrangle Parameters example 1 (meshing a face with 3 edges)

1 # Quadrangle Parameters example 1 (meshing a face with 3 edges)
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # Get 1/4 part from the disk face.
14 Box_1 = geompy.MakeBoxDXDYDZ(100, 100, 100)
15 Disk_1 = geompy.MakeDiskR(100, 1)
16 Common_1 = geompy.MakeCommon(Disk_1, Box_1)
17 geompy.addToStudy( Disk_1, "Disk_1" )
18 geompy.addToStudy( Box_1, "Box_1" )
19 geompy.addToStudy( Common_1, "Common_1" )
20 
21 # Set the Geometry for meshing
22 Mesh_1 = smesh.Mesh(Common_1)
23 
24 
25 # Define 1D hypothesis and compute the mesh
26 Regular_1D = Mesh_1.Segment()
27 Nb_Segments_1 = Regular_1D.NumberOfSegments(10)
28 Nb_Segments_1.SetDistrType( 0 )
29 
30 # Create Quadrangle parameters and define the Base Vertex.
31 Quadrangle_2D = Mesh_1.Quadrangle().TriangleVertex( 8 )
32 
33 Mesh_1.Compute()

Download this script

Quadrangle Parameters example 2 (using different types)

1 # Quadrangle Parameters example 2 (using different types)
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 from salome.StdMeshers import StdMeshersBuilder
13 
14 # Make quadrangle face and explode it on edges.
15 Vertex_1 = geompy.MakeVertex(0, 0, 0)
16 Vertex_2 = geompy.MakeVertex(40, 0, 0)
17 Vertex_3 = geompy.MakeVertex(40, 30, 0)
18 Vertex_4 = geompy.MakeVertex(0, 30, 0)
19 Quadrangle_Face_1 = geompy.MakeQuad4Vertices(Vertex_1, Vertex_4, Vertex_3, Vertex_2)
20 [Edge_1,Edge_2,Edge_3,Edge_4] = geompy.SubShapeAllSorted(Quadrangle_Face_1, geompy.ShapeType["EDGE"])
21 geompy.addToStudy( Vertex_1, "Vertex_1" )
22 geompy.addToStudy( Vertex_2, "Vertex_2" )
23 geompy.addToStudy( Vertex_3, "Vertex_3" )
24 geompy.addToStudy( Vertex_4, "Vertex_4" )
25 geompy.addToStudy( Quadrangle_Face_1, "Quadrangle Face_1" )
26 geompy.addToStudyInFather( Quadrangle_Face_1, Edge_2, "Edge_2" )
27 
28 # Set the Geometry for meshing
29 Mesh_1 = smesh.Mesh(Quadrangle_Face_1)
30 
31 # Create Quadrangle parameters and
32 # define the Type as Quadrangle Preference
33 Quadrangle_Parameters_1 = smesh.CreateHypothesis('QuadrangleParams')
34 Quadrangle_Parameters_1.SetQuadType( StdMeshersBuilder.QUAD_QUADRANGLE_PREF )
35 
36 # Define other hypotheses and algorithms
37 Regular_1D = Mesh_1.Segment()
38 Nb_Segments_1 = Regular_1D.NumberOfSegments(4)
39 Nb_Segments_1.SetDistrType( 0 )
40 status = Mesh_1.AddHypothesis(Quadrangle_Parameters_1)
41 Quadrangle_2D = Mesh_1.Quadrangle()
42 
43 # Define submesh on one edge to provide different number of segments
44 Regular_1D_1 = Mesh_1.Segment(geom=Edge_2)
45 Nb_Segments_2 = Regular_1D_1.NumberOfSegments(10)
46 Nb_Segments_2.SetDistrType( 0 )
47 SubMesh_1 = Regular_1D_1.GetSubMesh()
48 
49 # Compute mesh (with Quadrangle Preference type)
50 isDone = Mesh_1.Compute()
51 
52 # Change type to Reduced and compute again
53 Quadrangle_Parameters_1.SetQuadType( StdMeshersBuilder.QUAD_REDUCED )
54 isDone = Mesh_1.Compute()

Download this script

"Import 1D-2D Elements from Another Mesh" example

1 # "Import 2D Elements from Another Mesh" example
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 # Make a patritioned box
14 
15 box = geompy.MakeBoxDXDYDZ(100,100,100)
16 
17 N = geompy.MakeVectorDXDYDZ( 1,0,0 )
18 O = geompy.MakeVertex( 50,0,0 )
19 plane = geompy.MakePlane( O, N, 200 ) # plane YOZ
20 
21 shape2boxes = geompy.MakeHalfPartition( box, plane )
22 boxes = geompy.SubShapeAllSorted(shape2boxes, geompy.ShapeType["SOLID"])
23 
24 geompy.addToStudy( boxes[0], "boxes[0]")
25 geompy.addToStudy( boxes[1], "boxes[1]")
26 midFace0 = geompy.SubShapeAllSorted(boxes[0], geompy.ShapeType["FACE"])[5]
27 geompy.addToStudyInFather( boxes[0], midFace0, "middle Face")
28 midFace1 = geompy.SubShapeAllSorted(boxes[1], geompy.ShapeType["FACE"])[0]
29 geompy.addToStudyInFather( boxes[1], midFace1, "middle Face")
30 
31 # Mesh one of boxes with quadrangles. It is a source mesh
32 
33 srcMesh = smesh.Mesh(boxes[0], "source mesh") # box coloser to CS origin
34 nSeg1 = srcMesh.Segment().NumberOfSegments(4)
35 srcMesh.Quadrangle()
36 srcMesh.Compute()
37 srcFaceGroup = srcMesh.GroupOnGeom( midFace0, "src faces", SMESH.FACE )
38 
39 # Import faces from midFace0 to the target mesh
40 
41 tgtMesh = smesh.Mesh(boxes[1], "target mesh")
42 importAlgo = tgtMesh.UseExisting2DElements(midFace1)
43 import2hyp = importAlgo.SourceFaces( [srcFaceGroup] )
44 tgtMesh.Segment().NumberOfSegments(3)
45 tgtMesh.Quadrangle()
46 tgtMesh.Compute()
47 
48 # Import the whole source mesh with groups
49 import2hyp.SetCopySourceMesh(True,True)
50 tgtMesh.Compute()

Download this script

Viscous layers construction

1 # Viscous layers construction
2 
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
12 
13 X = geompy.MakeVectorDXDYDZ( 1,0,0 )
14 O = geompy.MakeVertex( 100,50,50 )
15 plane = geompy.MakePlane( O, X, 200 ) # plane YZ
16 
17 box = geompy.MakeBoxDXDYDZ(200,100,100)
18 
19 shape = geompy.MakeHalfPartition( box, plane )
20 
21 faces = geompy.SubShapeAllSorted(shape, geompy.ShapeType["FACE"])
22 face1 = faces[1]
23 ignoreFaces = [ faces[0], faces[-1]]
24 
25 geompy.addToStudy( shape, "shape" )
26 geompy.addToStudyInFather( shape, face1, "face1")
27 
28 # 3D Viscous layers
29 
30 mesh = smesh.Mesh(shape, "CFD")
31 
32 mesh.Segment().NumberOfSegments( 4 )
33 
34 mesh.Triangle()
35 mesh.Quadrangle(face1)
36 mesh.Compute()
37 algo3D = mesh.Tetrahedron()
38 
39 thickness = 20
40 numberOfLayers = 10
41 stretchFactor = 1.5
42 layersHyp = algo3D.ViscousLayers(thickness,numberOfLayers,stretchFactor,ignoreFaces)
43 
44 mesh.Compute()
45 
46 mesh.MakeGroup("Tetras",SMESH.VOLUME,SMESH.FT_ElemGeomType,"=",SMESH.Geom_TETRA)
47 mesh.MakeGroup("Pyras",SMESH.VOLUME,SMESH.FT_ElemGeomType,"=",SMESH.Geom_PYRAMID)
48 mesh.MakeGroup("Prims",SMESH.VOLUME,SMESH.FT_ElemGeomType,"=",SMESH.Geom_PENTA)
49 
50 # 2D Viscous layers
51 
52 # 3 edges of the 4 edges of face1
53 edgeIds = geompy.SubShapeAllIDs( face1, geompy.ShapeType["EDGE"])[:-1]
54 
55 mesh = smesh.Mesh(face1,"VicsousLayers2D")
56 mesh.Segment().NumberOfSegments( 5 )
57 
58 # viscous layers should be created on 1 edge, as we set 3 edges to ignore
59 vlHyp = mesh.Triangle().ViscousLayers2D( 2, 3, 1.5, edgeIds, isEdgesToIgnore=True )
60 
61 mesh.Compute()
62 
63 # viscous layers should be created on 3 edges, as we pass isEdgesToIgnore=False
64 vlHyp.SetEdges( edgeIds, False )
65 
66 mesh.Compute()

Download this script