2013-02-12 20:37:44 +06:00
|
|
|
# Projection Algorithms
|
|
|
|
|
|
|
|
# Project prisms from one meshed box to another mesh on the same box
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
import salome
|
2021-08-12 14:38:10 +05:00
|
|
|
salome.salome_init_without_session()
|
2013-04-04 13:08:19 +06:00
|
|
|
|
2022-04-11 18:28:01 +05:00
|
|
|
from salome.geom import geomBuilder
|
2013-04-04 13:08:19 +06:00
|
|
|
from salome.smesh import smeshBuilder
|
2022-04-11 18:28:01 +05:00
|
|
|
|
|
|
|
geom_builder = geomBuilder.New()
|
|
|
|
smesh_builder = smeshBuilder.New()
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Prepare geometry
|
|
|
|
|
|
|
|
# Create a parallelepiped
|
2022-04-11 18:28:01 +05:00
|
|
|
box = geom_builder.MakeBoxDXDYDZ(200, 100, 70)
|
|
|
|
geom_builder.addToStudy( box, "box" )
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Get geom faces to mesh with triangles in the 1ts and 2nd meshes
|
2022-04-11 18:28:01 +05:00
|
|
|
faces = geom_builder.SubShapeAll(box, geom_builder.ShapeType["FACE"])
|
2013-02-12 20:37:44 +06:00
|
|
|
# 2 adjacent faces of the box
|
|
|
|
f1 = faces[2]
|
|
|
|
f2 = faces[0]
|
|
|
|
# face opposite to f2
|
2022-04-11 18:28:01 +05:00
|
|
|
f2opp = geom_builder.GetOppositeFace( box, f2 )
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Get vertices used to specify how to associate sides of faces at projection
|
2022-04-11 18:28:01 +05:00
|
|
|
[v1F1, v2F1] = geom_builder.SubShapeAll(f1, geom_builder.ShapeType["VERTEX"])[:2]
|
|
|
|
[v1F2, v2F2] = geom_builder.SubShapeAll(f2, geom_builder.ShapeType["VERTEX"])[:2]
|
|
|
|
geom_builder.addToStudyInFather( box, v1F1, "v1F1" )
|
|
|
|
geom_builder.addToStudyInFather( box, v2F1, "v2F1" )
|
|
|
|
geom_builder.addToStudyInFather( box, v1F2, "v1F2" )
|
|
|
|
geom_builder.addToStudyInFather( box, v2F2, "v2F2" )
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Make group of 3 edges of f1 and f2
|
2022-04-11 18:28:01 +05:00
|
|
|
edgesF1 = geom_builder.CreateGroup(f1, geom_builder.ShapeType["EDGE"])
|
|
|
|
geom_builder.UnionList( edgesF1, geom_builder.SubShapeAll(f1, geom_builder.ShapeType["EDGE"])[:3])
|
|
|
|
edgesF2 = geom_builder.CreateGroup(f2, geom_builder.ShapeType["EDGE"])
|
|
|
|
geom_builder.UnionList( edgesF2, geom_builder.SubShapeAll(f2, geom_builder.ShapeType["EDGE"])[:3])
|
|
|
|
geom_builder.addToStudyInFather( box, edgesF1, "edgesF1" )
|
|
|
|
geom_builder.addToStudyInFather( box, edgesF2, "edgesF2" )
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Make the source mesh with prisms
|
2022-04-11 18:28:01 +05:00
|
|
|
src_mesh = smesh_builder.Mesh(box, "Source mesh")
|
2013-02-12 20:37:44 +06:00
|
|
|
src_mesh.Segment().NumberOfSegments(9,10)
|
|
|
|
src_mesh.Quadrangle()
|
|
|
|
src_mesh.Hexahedron()
|
2016-03-21 17:03:25 +05:00
|
|
|
src_mesh.Triangle(f1) # triangular sub-mesh
|
2023-02-21 18:59:44 +05:00
|
|
|
if not src_mesh.Compute(): raise Exception("Error when computing Mesh")
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2017-03-02 21:51:35 +05:00
|
|
|
# Mesh the box using projection algorithms
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Define the same global 1D and 2D hypotheses
|
2022-04-11 18:28:01 +05:00
|
|
|
tgt_mesh = smesh_builder.Mesh(box, "Target mesh")
|
2013-02-12 20:37:44 +06:00
|
|
|
tgt_mesh.Segment().NumberOfSegments(9,10,UseExisting=True)
|
|
|
|
tgt_mesh.Quadrangle()
|
|
|
|
|
|
|
|
# Define Projection 1D algorithm to project 1d mesh elements from group edgesF2 to edgesF1
|
|
|
|
# It is actually not needed, just a demonstration
|
|
|
|
proj1D = tgt_mesh.Projection1D( edgesF1 )
|
|
|
|
# each vertex must be at the end of a connected group of edges (or a sole edge)
|
|
|
|
proj1D.SourceEdge( edgesF2, src_mesh, v2F1, v2F2 )
|
|
|
|
|
|
|
|
# Define 2D hypotheses to project triangles from f1 face of the source mesh to
|
|
|
|
# f2 face in the target mesh. Vertices specify how to associate sides of faces
|
|
|
|
proj2D = tgt_mesh.Projection2D( f2 )
|
|
|
|
proj2D.SourceFace( f1, src_mesh, v1F1, v1F2, v2F1, v2F2 )
|
|
|
|
|
|
|
|
# 2D hypotheses to project triangles from f2 of target mesh to the face opposite to f2.
|
|
|
|
# Association of face sides is default
|
|
|
|
proj2D = tgt_mesh.Projection2D( f2opp )
|
|
|
|
proj2D.SourceFace( f2 )
|
|
|
|
|
|
|
|
# 3D hypotheses to project prisms from the source to the target mesh
|
|
|
|
proj3D = tgt_mesh.Projection3D()
|
|
|
|
proj3D.SourceShape3D( box, src_mesh, v1F1, v1F2, v2F1, v2F2 )
|
2023-02-21 18:59:44 +05:00
|
|
|
if not tgt_mesh.Compute(): raise Exception("Error when computing Mesh")
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2018-06-19 21:58:29 +05:00
|
|
|
# Move the source mesh to visually compare the two meshes
|
2022-04-11 18:28:01 +05:00
|
|
|
src_mesh.TranslateObject( src_mesh, smesh_builder.MakeDirStruct( 210, 0, 0 ), Copy=False)
|