Salome HOME
Add table of contents
[modules/smesh.git] / doc / salome / gui / SMESH / input / tui_defining_hypotheses.doc
index 04725fdc6c56d05882d01f37cf83c644abbbc2f7..bd399115b18c9c4badf5cbb08f50e92918a8ce5b 100644 (file)
@@ -2,11 +2,48 @@
 
 \page tui_defining_hypotheses_page Defining Hypotheses and Algorithms
 
+This page provides example codes of \ref tui_defining_meshing_algos
+"defining algorithms" and hypotheses. 
+<ul>
+<li>Wire discretisation ( smesh.REGULAR ) 1D algorithm
+  <ul>
+    <li>\ref tui_1d_arithmetic "Arithmetic 1D" hypothesis</li>
+    <li>\ref tui_deflection_1d "Deflection 1D and Number of Segments" hypotheses</li>
+    <li>\ref tui_start_and_end_length "Start and End Length" hypotheses</li>
+    <li>\ref tui_average_length "Local Length"</li>
+    <li>\ref tui_propagation "Propagation" additional hypothesis </li>
+    <li>\ref tui_fixed_points "Fixed Points 1D" hypothesis</li>
+  </ul>
+</li>
+<li>Triangle (Mefisto) 2D algorithm
+  <ul>
+    <li>\ref tui_max_element_area "Max Element Area" hypothesis </li>
+    <li>\ref tui_length_from_edges "Length from Edges"
+    hypothesis </li>
+  </ul>
+</li>
+<li>Tetrahedron (Netgen) 3D algorithm
+  <ul>
+    <li> \ref tui_max_element_volume "Max. Element Volume"hypothesis </li>
+    <li> \ref tui_viscous_layers "Viscous layers"</li>
+  </ul>
+</li>
+<li>\ref tui_projection "Projection Algorithms"</li>
+<li>\ref tui_radial_quadrangle "Radial Quadrangle 1D2D"</li>
+<li>Quadrangle (Mapping) 2D algorithm
+  <ul>
+    <li> \ref tui_quadrangle_parameters "Quadrangle Parameters" hypothesis </li>
+  </ul>
+</li>
+<li>\ref tui_import "Use Existing Elements"</li>
+</ul>
+<br>
+
 <h2>Defining 1D Hypotheses</h2>
 
 <br>
 \anchor tui_1d_arithmetic
-<h3>1D Arithmetic</h3>
+<h3>Arithmetic 1D</h3>
 
 \code
 import geompy
@@ -128,7 +165,7 @@ hexa.Compute()
 
 <br>
 \anchor tui_average_length
-<h3>Average Length</h3>
+<h3>Local Length</h3>
 
 \code
 from geompy import *
@@ -231,7 +268,7 @@ tetra = smesh.Mesh(cyl, "Cylinder : tetrahedrical mesh")
 # assign algorithms
 algo1D = tetra.Segment()
 algo2D = tetra.Triangle()
-algo3D = tetra.Tetrahedron(smesh.NETGEN)
+algo3D = tetra.Tetrahedron()
 
 # assign 1D and 2D hypotheses
 algo1D.NumberOfSegments(7)
@@ -363,8 +400,8 @@ algo1D = tetra.Segment()
 # create a Mefisto 2D algorithm for faces
 algo2D = tetra.Triangle()
 
-# create a Netgen 3D algorithm for solids
-algo3D = tetra.Tetrahedron(smesh.NETGEN)
+# create a 3D algorithm for solids
+algo3D = tetra.Tetrahedron()
 
 # define hypotheses
 algo1D.Arithmetic1D(1, 4)
@@ -373,17 +410,6 @@ algo2D.LengthFromEdges()
 # compute the mesh
 tetra.Compute()
 
-# 3. Create a tetrahedral mesh on the box with NETGEN_2D3D algorithm
-tetraN = smesh.Mesh(box, "Box : tetrahedrical mesh by NETGEN_2D3D")
-
-# create a Netgen_2D3D algorithm for solids
-algo3D = tetraN.Tetrahedron(smesh.FULL_NETGEN) 
-
-# define hypotheses
-n23_params = algo3D.Parameters()
-
-# compute the mesh
-tetraN.Compute()
 \endcode
 
 <br>
@@ -468,6 +494,40 @@ src_mesh.TranslateObject( src_mesh, MakeDirStruct( 210, 0, 0 ), Copy=False)
 
 \endcode
 
+<h3>Projection 1D2D</h3>
+
+\code
+# Project triangles from one meshed face to another mesh on the same box
+
+from smesh import *
+
+# Prepare geometry
+
+# Create a box
+box = geompy.MakeBoxDXDYDZ(100, 100, 100)
+
+# Get geom faces to mesh with triangles in the 1ts and 2nd meshes
+faces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
+# 2 adjacent faces of the box
+Face_1 = faces[2]
+Face_2 = faces[0]
+
+geompy.addToStudy( box, 'box' )
+geompy.addToStudyInFather( box, Face_1, 'Face_1' )
+geompy.addToStudyInFather( box, Face_2, 'Face_2' )
+
+# Make the source mesh with Netgem2D
+src_mesh = Mesh(Face_1, "Source mesh")
+src_mesh.Segment().NumberOfSegments(15)
+src_mesh.Triangle()
+src_mesh.Compute()
+
+# Mesh the target mesh using the algoritm Projection1D2D
+tgt_mesh = smesh.Mesh(Face_2, "Target mesh")
+tgt_mesh.Projection1D2D().SourceFace(Face_1,src_mesh)
+tgt_mesh.Compute()
+\endcode
+
 <br>
 
 \anchor tui_fixed_points
@@ -514,37 +574,208 @@ Mesh_1.Compute()
 \anchor tui_radial_quadrangle
 <h2> Radial Quadrangle 1D2D example </h2>
 \code
-import salome
-import geompy
-import smesh
-import StdMeshers
+from smesh import *
+
+SetCurrentStudy(salome.myStudy)
 
 # Create face from the wire and add to study
-WirePath = geompy.MakeSketcher("Sketcher:F 0 0:TT 20 0:R 90:C 20 90:WW", [0, 0, 0, 1, 0, 0, 0, 0, 1])
-Face = geompy.MakeFace(WirePath,1)
+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])
 geompy.addToStudy(Face,"Face")
+edges = geompy.SubShapeAllSorted(Face, geompy.ShapeType["EDGE"])
+circle, radius1, radius2 = edges
+geompy.addToStudyInFather(Face, radius1,"radius1")
+geompy.addToStudyInFather(Face, radius2,"radius2")
+geompy.addToStudyInFather(Face, circle,"circle")
 
-# Define geometry for mesh, and 1D parameters
+
+# Define geometry for mesh, and Radial Quadrange algorithm
 mesh = smesh.Mesh(Face)
-Wire_discretisation = mesh.Segment()
-Nb_Segments = Wire_discretisation.NumberOfSegments(5)
-Nb_Segments.SetDistrType( 0 )
+radial_Quad_algo = mesh.Quadrangle(algo=RADIAL_QUAD)
+
+# The Radial Quadrange algorithm can work without any hypothesis
+# In this case it uses "Default Nb of Segments" preferences parameter to discretize edges
+mesh.Compute()
 
-# Define 2D parameters and Radial Quadrange hypothesis
-Number_of_Layers = smesh.CreateHypothesis('NumberOfLayers2D')
-Number_of_Layers.SetNumberOfLayers( 4 )
-mesh.AddHypothesis(Number_of_Layers)
-RadialQuadrangle_1D2D = smesh.CreateHypothesis('RadialQuadrangle_1D2D')
-mesh.AddHypothesis(RadialQuadrangle_1D2D)
+# The Radial Quadrange uses global or local 1d hypotheses if it does
+# not have its own hypotheses.
+# Define global hypotheses to discretize radial edges and a local one for circular edge
+global_Nb_Segments = mesh.Segment().NumberOfSegments(5)
+local_Nb_Segments  = mesh.Segment(circle).NumberOfSegments(10)
+mesh.Compute()
 
+# Define own parameters of Radial Quadrange algorithm
+radial_Quad_algo.NumberOfLayers( 4 )
 mesh.Compute()
 \endcode
 
+\anchor tui_quadrangle_parameters
+<h2>Quadrangle Parameters example 1 (meshing a face with 3 edges) </h2>
+\code
+from smesh import *
+SetCurrentStudy(salome.myStudy)
+
+# Get 1/4 part from the disk face.
+Box_1 = geompy.MakeBoxDXDYDZ(100, 100, 100)
+Disk_1 = geompy.MakeDiskR(100, 1)
+Common_1 = geompy.MakeCommon(Disk_1, Box_1)
+geompy.addToStudy( Disk_1, "Disk_1" )
+geompy.addToStudy( Box_1, "Box_1" )
+geompy.addToStudy( Common_1, "Common_1" )
 
-\n Other meshing algorithms:
+# Set the Geometry for meshing
+Mesh_1 = smesh.Mesh(Common_1)
+
+
+# Define 1D hypothesis and compute the mesh
+Regular_1D = Mesh_1.Segment()
+Nb_Segments_1 = Regular_1D.NumberOfSegments(10)
+Nb_Segments_1.SetDistrType( 0 )
+
+# Create Quadrangle parameters and define the Base Vertex.
+Quadrangle_2D = Mesh_1.Quadrangle().TriangleVertex( 8 )
+
+Mesh_1.Compute()
+\endcode
+
+<h2>Quadrangle Parameters example 2 (using different types) </h2>
+\code
+import geompy
+import smesh
+import StdMeshers
+
+# Make quadrangle face and explode it on edges.
+Vertex_1 = geompy.MakeVertex(0, 0, 0)
+Vertex_2 = geompy.MakeVertex(40, 0, 0)
+Vertex_3 = geompy.MakeVertex(40, 30, 0)
+Vertex_4 = geompy.MakeVertex(0, 30, 0)
+Quadrangle_Face_1 = geompy.MakeQuad4Vertices(Vertex_1, Vertex_4, Vertex_3, Vertex_2)
+[Edge_1,Edge_2,Edge_3,Edge_4] = geompy.SubShapeAllSorted(Quadrangle_Face_1, geompy.ShapeType["EDGE"])
+geompy.addToStudy( Vertex_1, "Vertex_1" )
+geompy.addToStudy( Vertex_2, "Vertex_2" )
+geompy.addToStudy( Vertex_3, "Vertex_3" )
+geompy.addToStudy( Vertex_4, "Vertex_4" )
+geompy.addToStudy( Quadrangle_Face_1, "Quadrangle Face_1" )
+geompy.addToStudyInFather( Quadrangle_Face_1, Edge_2, "Edge_2" )
+
+# Set the Geometry for meshing
+Mesh_1 = smesh.Mesh(Quadrangle_Face_1)
+
+# Create Quadrangle parameters and
+# define the Type as Quadrangle Preference
+Quadrangle_Parameters_1 = smesh.CreateHypothesis('QuadrangleParams')
+Quadrangle_Parameters_1.SetQuadType( StdMeshers.QUAD_QUADRANGLE_PREF )
+
+# Define other hypotheses and algorithms
+Regular_1D = Mesh_1.Segment()
+Nb_Segments_1 = Regular_1D.NumberOfSegments(4)
+Nb_Segments_1.SetDistrType( 0 )
+status = Mesh_1.AddHypothesis(Quadrangle_Parameters_1)
+Quadrangle_2D = Mesh_1.Quadrangle()
+
+# Define submesh on one edge to provide different number of segments
+Regular_1D_1 = Mesh_1.Segment(geom=Edge_2)
+Nb_Segments_2 = Regular_1D_1.NumberOfSegments(10)
+Nb_Segments_2.SetDistrType( 0 )
+SubMesh_1 = Regular_1D_1.GetSubMesh()
+
+# Compute mesh (with Quadrangle Preference type)
+isDone = Mesh_1.Compute()
+
+# Change type to Reduced and compute again
+Quadrangle_Parameters_1.SetQuadType( StdMeshers.QUAD_REDUCED )
+isDone = Mesh_1.Compute()
+\endcode
+
+\anchor tui_import
+<h2>"Use Existing Elements" example </h2>
+\code
+
+from smesh import *
+SetCurrentStudy(salome.myStudy)
+
+# Make a patritioned box
+
+box = geompy.MakeBoxDXDYDZ(100,100,100)
+
+N = geompy.MakeVectorDXDYDZ( 1,0,0 )
+O = geompy.MakeVertex( 50,0,0 )
+plane = geompy.MakePlane( O, N, 200 ) # plane YOZ
+
+shape2boxes = geompy.MakeHalfPartition( box, plane )
+boxes = geompy.SubShapeAllSorted(shape2boxes, geompy.ShapeType["SOLID"])
+
+geompy.addToStudy( boxes[0], "boxes[0]")
+geompy.addToStudy( boxes[1], "boxes[1]")
+midFace0 = geompy.SubShapeAllSorted(boxes[0], geompy.ShapeType["FACE"])[5]
+geompy.addToStudyInFather( boxes[0], midFace0, "middle Face")
+midFace1 = geompy.SubShapeAllSorted(boxes[1], geompy.ShapeType["FACE"])[0]
+geompy.addToStudyInFather( boxes[1], midFace1, "middle Face")
+
+# Mesh one of boxes with quadrangles. It is a source mesh
+
+srcMesh = Mesh(boxes[0], "source mesh") # box coloser to CS origin
+nSeg1 = srcMesh.Segment().NumberOfSegments(4)
+srcMesh.Quadrangle()
+srcMesh.Compute()
+srcFaceGroup = srcMesh.GroupOnGeom( midFace0, "src faces", FACE )
+
+# Import faces from midFace0 to the target mesh
+
+tgtMesh = Mesh(boxes[1], "target mesh")
+importAlgo = tgtMesh.UseExisting2DElements(midFace1)
+import2hyp = importAlgo.SourceFaces( [srcFaceGroup] )
+tgtMesh.Segment().NumberOfSegments(3)
+tgtMesh.Quadrangle()
+tgtMesh.Compute()
+
+# Import the whole source mesh with groups
+import2hyp.SetCopySourceMesh(True,True)
+tgtMesh.Compute()
+\endcode
+
+\anchor tui_viscous_layers
+<h2>Viscous layers construction</h2>
+
+\code
+from smesh import *
+SetCurrentStudy(salome.myStudy)
+
+X = geompy.MakeVectorDXDYDZ( 1,0,0 )
+O = geompy.MakeVertex( 100,50,50 )
+plane = geompy.MakePlane( O, X, 200 ) # plane YZ
+
+box = geompy.MakeBoxDXDYDZ(200,100,100)
+
+shape = geompy.MakeHalfPartition( box, plane )
+
+faces = geompy.SubShapeAllSorted(shape, geompy.ShapeType["FACE"])
+face1 = faces[1]
+ignoreFaces = [ faces[0], faces[-1]]
+
+geompy.addToStudy( shape, "shape" )
+geompy.addToStudyInFather( shape, face1, "face1")
+
+
+mesh = Mesh(shape, "CFD")
+
+mesh.Segment().NumberOfSegments( 4 )
+
+mesh.Triangle()
+mesh.Quadrangle(face1)
+mesh.Compute()
+algo3D = mesh.Tetrahedron()
+
+thickness = 20
+numberOfLayers = 10
+stretchFactor = 1.5
+layersHyp = algo3D.ViscousLayers(thickness,numberOfLayers,stretchFactor,ignoreFaces)
+
+mesh.Compute()
+
+mesh.MakeGroup("Tetras",VOLUME,FT_ElemGeomType,"=",Geom_TETRA)
+mesh.MakeGroup("Pyras",VOLUME,FT_ElemGeomType,"=",Geom_PYRAMID)
+mesh.MakeGroup("Prims",VOLUME,FT_ElemGeomType,"=",Geom_PENTA)
+
+\endcode
 
-<ul>
-<li>\subpage tui_defining_blsurf_hypotheses_page</li>
-<li>\subpage tui_defining_ghs3d_hypotheses_page</li>
-</ul>
 */