Version: 8.3.0
 All Classes Namespaces Files Functions Variables Pages
Python Interface
Note
The former name of MG-Tetra mesher is GHS3D and names of the corresponding classes and modules still include "GHS3D".

Python package GHS3DPluginBuilder defines GHS3DPluginBuilder.GHS3D_Algorithm class providing access to the MG-Tetra meshing algorithm and its parameters.

You can get an instance of this class by calling smeshBuilder.Mesh.Tetrahedron(algo=smeshBuilder.MG_Tetra) or smeshBuilder.Mesh.Tetrahedron(algo=smeshBuilder.GHS3D). This call creates an algorithm (if not yet exist), assigns it to the mesh and returns an instance of GHS3DPluginBuilder.GHS3D_Algorithm to the caller.

The class of algorithm has methods to set up meshing parameters.

Below you can see examples of usage of this class for tetrahedral mesh generation.

  1. Construction of Mesh using MG-Tetra algorithm
  2. Adding enforced vertices
  3. Adding enforced mesh
  4. Mesh optimization

Construction of Mesh using MG-Tetra algorithm

Example of mesh generation with MG-Tetra algorithm:

1 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 
20 import salome
21 salome.salome_init()
22 
23 from salome.geom import geomBuilder
24 geompy = geomBuilder.New(salome.myStudy)
25 
26 from salome.smesh import smeshBuilder
27 smesh = smeshBuilder.New(salome.myStudy)
28 
29 # create a box
30 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
31 geompy.addToStudy(box, "box")
32 
33 # create a mesh on the box
34 mgtetraMesh = smesh.Mesh(box,"box: MG-Tetra and MG-CADSurf mesh")
35 
36 # create a MG_CADSurf algorithm for faces
37 MG_CADSurf = mgtetraMesh.Triangle(algo=smeshBuilder.MG_CADSurf)
38 MG_Tetra = mgtetraMesh.Tetrahedron(algo=smeshBuilder.MG_Tetra)
39 
40 # compute the mesh
41 mgtetraMesh.Compute()
42 
43 # End of script
44 

Download this script

ghs3d_screenshot.png
MG-Tetra mesh without hypothesis

Back to top

Adding enforced vertices

Example of enforced vertices with MG-Tetra algorithm:

1 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 
20 # An enforced vertex can be added via:
21 # - the coordinates x,y,z
22 # - a GEOM vertex or compound (No geometry, TUI only)
23 #
24 # The created enforced nodes can also be stored in
25 # a group.
26 #
27 # This feature is available only on meshes without geometry.
28 
29 # Ex1: Add one enforced vertex with coordinates (50,50,100)
30 # and physical size 2.
31 
32 import salome
33 salome.salome_init()
34 
35 from salome.geom import geomBuilder
36 geompy = geomBuilder.New(salome.myStudy)
37 
38 import SMESH
39 from salome.smesh import smeshBuilder
40 smesh = smeshBuilder.New(salome.myStudy)
41 
42 # create a box
43 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
44 geompy.addToStudy(box, "box")
45 # create a mesh on the box
46 mgtetraMesh = smesh.Mesh(box,"box: MG-Tetra and MG-CADSurf mesh")
47 # create a MG-CADSurf algorithm for faces
48 mgtetraMesh.Triangle(algo=smeshBuilder.MG_CADSurf)
49 # compute the mesh
50 mgtetraMesh.Compute()
51 
52 # Make a copy of the 2D mesh
53 mgtetraMesh_wo_geometry = smesh.CopyMesh( mgtetraMesh, 'MG-Tetra w/o geometry', 0, 0)
54 
55 # create a MG_Tetra algorithm and hypothesis and assign them to the mesh
56 MG_Tetra = mgtetraMesh.Tetrahedron( smeshBuilder.MG_Tetra )
57 MG_Tetra_Parameters = MG_Tetra.Parameters()
58 # Create the enforced vertex
59 MG_Tetra_Parameters.SetEnforcedVertex( 50, 50, 100, 2) # no group
60 # Compute the mesh
61 mgtetraMesh.Compute()
62 
63 
64 # Ex2: Add one vertex enforced by a GEOM vertex at (50,50,100)
65 # with physical size 5 and add it to a group called "My special nodes"
66 
67 # Create another MG_Tetra hypothesis and assign it to the mesh without geometry
68 MG_Tetra_Parameters_wo_geometry = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
69 mgtetraMesh_wo_geometry.AddHypothesis( MG_Tetra )
70 mgtetraMesh_wo_geometry.AddHypothesis( MG_Tetra_Parameters_wo_geometry )
71 
72 # Create the enforced vertex
73 p1 = geompy.MakeVertex(150, 150, 100)
74 geompy.addToStudy(p1, "p1")
75 MG_Tetra_Parameters_wo_geometry.SetEnforcedVertexGeomWithGroup( p1, 5 , "My special nodes")
76 #MG_Tetra_Parameters.SetEnforcedVertexGeom( p1, 5 ) # no group
77 
78 # compute the mesh
79 mgtetraMesh_wo_geometry.Compute()
80 
81 # Erase all enforced vertices
82 MG_Tetra_Parameters.ClearEnforcedVertices()
83 
84 # End of script

Download this script

ghs3d_screenshot_enf1.png
MG-Tetra mesh with enforced vertex
ghs3d_screenshot_enf2.png
MG-Tetra mesh with enforced vertex from GEOM vertex

Back to top

Adding enforced mesh

Example of enforced meshes with MG-Tetra algorithm:

1 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 
20 # It is possible to constrain MG-Tetra with another mesh or group.
21 # The constraint can refer to the nodes, edges or faces.
22 # This feature is available only on 2D meshes without geometry.
23 # The constraining elements are called enforced elements for the mesh.
24 # They can be recovered using groups if necessary.
25 
26 # In the following examples, a box and a cylinder are meshed in 2D.
27 # The mesh of the cylinder will be used as a constraint for the
28 # 3D mesh of the box.
29 
30 import salome
31 salome.salome_init()
32 import GEOM
33 from salome.geom import geomBuilder
34 geompy = geomBuilder.New(salome.myStudy)
35 
36 import SMESH, SALOMEDS
37 from salome.smesh import smeshBuilder
38 smesh = smeshBuilder.New(salome.myStudy)
39 
40 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
41 geompy.addToStudy( box, "box" )
42 cylindre = geompy.MakeCylinderRH(50, 50)
43 geompy.TranslateDXDYDZ(cylindre, 100, 100, 30)
44 face_cyl = geompy.ExtractShapes(cylindre, geompy.ShapeType["FACE"], True)[1]
45 geompy.addToStudy( cylindre, 'cylindre' )
46 geompy.addToStudyInFather( cylindre, face_cyl, 'face_cyl' )
47 p1 = geompy.MakeVertex(20, 20, 20)
48 p2 = geompy.MakeVertex(180, 180, 20)
49 c = geompy.MakeCompound([p1,p2])
50 geompy.addToStudy( p1, "p1" )
51 geompy.addToStudy( p2, "p2" )
52 geompy.addToStudy( c, "c" )
53 
54 # Create the 2D algorithm and hypothesis
55 MG_CADSurf = smesh.CreateHypothesis('MG-CADSurf', 'BLSURFEngine')
56 # For the box
57 MG_CADSurf_Parameters = smesh.CreateHypothesis('MG-CADSurf Parameters', 'BLSURFEngine')
58 MG_CADSurf_Parameters.SetPhysicalMesh( 1 )
59 MG_CADSurf_Parameters.SetPhySize( 200 )
60 # For the cylinder
61 MG_CADSurf_Parameters2 = smesh.CreateHypothesis('MG-CADSurf Parameters', 'BLSURFEngine')
62 MG_CADSurf_Parameters2.SetGeometricMesh( 1 )
63 
64 # Create the 3D algorithm and hypothesis
65 MG_Tetra = smesh.CreateHypothesis('MG-Tetra', 'GHS3DEngine')
66 MG_Tetra_Parameters_node = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
67 #MG_Tetra_Parameters_node.SetToMeshHoles( 1 )
68 MG_Tetra_Parameters_edge = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
69 #MG_Tetra_Parameters_edge.SetToMeshHoles( 1 )
70 MG_Tetra_Parameters_face = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
71 MG_Tetra_Parameters_face.SetToMeshHoles( 1 ) # to mesh inside the cylinder
72 MG_Tetra_Parameters_mesh = smesh.CreateHypothesis('MG-Tetra Parameters', 'GHS3DEngine')
73 MG_Tetra_Parameters_mesh.SetToMeshHoles( 1 ) # to mesh inside the cylinder
74 
75 # Create the mesh on the cylinder
76 Mesh_cylindre = smesh.Mesh(cylindre)
77 smesh.SetName(Mesh_cylindre,"Mesh_cylindre")
78 Mesh_cylindre.AddHypothesis( MG_CADSurf )
79 Mesh_cylindre.AddHypothesis( MG_CADSurf_Parameters2 )
80 # Create some groups
81 face_cyl_faces = Mesh_cylindre.GroupOnGeom(face_cyl,'group_face_cyl', SMESH.FACE)
82 face_cyl_edges = Mesh_cylindre.GroupOnGeom(face_cyl,'group_edge_cyl', SMESH.EDGE)
83 face_cyl_nodes = Mesh_cylindre.GroupOnGeom(face_cyl,'group_node_cyl', SMESH.NODE)
84 Mesh_cylindre.Compute()
85 
86 # Create the mesh on the cylinder
87 Mesh_box_tri = smesh.Mesh(box,"Mesh_box_tri")
88 Mesh_box_tri.AddHypothesis( MG_CADSurf )
89 Mesh_box_tri.AddHypothesis( MG_CADSurf_Parameters )
90 Mesh_box_tri.Compute()
91 
92 # Create 4 copies of the 2D mesh to test the 3 types of contraints (NODE, EDGE, FACE)
93 # from the whole mesh and from groups of elements.
94 # Then the 3D algo and hypothesis are assigned to them.
95 
96 mesh_mesh = smesh.CopyMesh( Mesh_box_tri, 'Enforced by faces of mesh', 0, 0)
97 mesh_mesh.AddHypothesis( MG_Tetra )
98 mesh_mesh.AddHypothesis( MG_Tetra_Parameters_mesh)
99 
100 mesh_node = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of nodes', 0, 0)
101 mesh_node.AddHypothesis( MG_Tetra )
102 mesh_node.AddHypothesis( MG_Tetra_Parameters_node)
103 
104 mesh_edge = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of edges', 0, 0)
105 mesh_edge.AddHypothesis( MG_Tetra )
106 mesh_edge.AddHypothesis( MG_Tetra_Parameters_edge)
107 
108 mesh_face = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of faces', 0, 0)
109 mesh_face.AddHypothesis( MG_Tetra )
110 mesh_face.AddHypothesis( MG_Tetra_Parameters_face)
111 
112 # Add the enforced elements
113 MG_Tetra_Parameters_mesh.SetEnforcedMeshWithGroup(Mesh_cylindre.GetMesh(),SMESH.FACE,"faces from cylinder")
114 MG_Tetra_Parameters_node.SetEnforcedMeshWithGroup(face_cyl_nodes,SMESH.NODE,"nodes from face_cyl_nodes")
115 MG_Tetra_Parameters_edge.SetEnforcedMeshWithGroup(face_cyl_edges,SMESH.EDGE,"edges from face_cyl_edges")
116 MG_Tetra_Parameters_face.SetEnforcedMeshWithGroup(face_cyl_faces,SMESH.FACE,"faces from face_cyl_faces")
117 
118 #Compute the meshes
119 mesh_node.Compute()
120 mesh_edge.Compute()
121 mesh_face.Compute()
122 mesh_mesh.Compute()
123 
124 # End of script

Download this script

ghs3d_screenshot_enf3.png
ghs3d_screenshot_enf4.png
ghs3d_screenshot_enf5.png
ghs3d_screenshot_enf6.png

Mesh optimization

Example of mesh optimization with MG-Tetra Optimization:

1 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 
20 import salome
21 salome.salome_init()
22 
23 from salome.geom import geomBuilder
24 geompy = geomBuilder.New(salome.myStudy)
25 
26 from salome.smesh import smeshBuilder
27 smesh = smeshBuilder.New(salome.myStudy)
28 
29 # create a disk
30 disk = geompy.MakeDiskR(100., 1, theName="disk")
31 
32 # triangulate the disk
33 mesh = smesh.Mesh( disk )
34 cadsurf = mesh.Triangle( smeshBuilder.MG_CADSurf )
35 cadsurf.SetQuadAllowed( True )
36 mesh.Compute()
37 
38 # extrude the 2D mesh into a prismatic mesh
39 mesh.ExtrusionSweepObject( mesh, [0,0,10], 7 )
40 
41 # split prisms into tetrahedra
42 mesh.SplitVolumesIntoTetra( mesh )
43 
44 # copy the mesh into a new mesh, since only a mesh not based of geometry
45 # can be optimized using MG-Tetra Optimization
46 optMesh = smesh.CopyMesh( mesh, "optimization" )
47 
48 # add MG-Tetra Optimization
49 mg_opt = optMesh.Tetrahedron( smeshBuilder.MG_Tetra_Optimization )
50 mg_opt.SetSmoothOffSlivers( True )
51 mg_opt.SetOptimizationLevel( smeshBuilder.Strong_Optimization )
52 
53 # run optimization
54 optMesh.Compute()
55 
56 print "Nb tetra before optimization", mesh.NbTetras()
57 print "Nb tetra after optimization", optMesh.NbTetras()
58 
59 # End of script
60 

Download this script

Back to top