smesh/doc/examples/modifying_meshes_ex25.py

138 lines
4.1 KiB
Python
Raw Permalink Normal View History

2013-02-12 20:37:44 +06:00
# Pattern Mapping
import salome
salome.salome_init_without_session()
2022-04-11 18:28:01 +05:00
import SMESH
from salome.geom import geomBuilder
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
# define the geometry
2022-04-11 18:28:01 +05:00
Box_1 = geom_builder.MakeBoxDXDYDZ(200., 200., 200.)
geom_builder.addToStudy(Box_1, "Box_1")
2013-02-12 20:37:44 +06:00
2022-04-11 18:28:01 +05:00
faces = geom_builder.SubShapeAll(Box_1, geom_builder.ShapeType["FACE"])
2013-02-12 20:37:44 +06:00
Face_1 = faces[0]
Face_2 = faces[1]
2022-04-11 18:28:01 +05:00
geom_builder.addToStudyInFather(Box_1, Face_1, "Face_1")
geom_builder.addToStudyInFather(Box_1, Face_2, "Face_2")
2013-02-12 20:37:44 +06:00
# build a quadrangle mesh 3x3 on Face_1
2022-04-11 18:28:01 +05:00
Mesh_1 = smesh_builder.Mesh(Face_1)
2013-02-12 20:37:44 +06:00
algo1D = Mesh_1.Segment()
algo1D.NumberOfSegments(3)
Mesh_1.Quadrangle()
isDone = Mesh_1.Compute()
if not isDone: raise Exception('Mesh Mesh_1 : computation failed')
2013-02-12 20:37:44 +06:00
# build a triangle mesh on Face_2
2022-04-11 18:28:01 +05:00
Mesh_2 = smesh_builder.Mesh(Face_2)
2013-02-12 20:37:44 +06:00
algo1D = Mesh_2.Segment()
algo1D.NumberOfSegments(1)
algo2D = Mesh_2.Triangle()
algo2D.MaxElementArea(240)
isDone = Mesh_2.Compute()
if not isDone: raise Exception('Mesh Mesh_2 : computation failed')
2013-02-12 20:37:44 +06:00
# create a 2d pattern
2022-04-11 18:28:01 +05:00
pattern = smesh_builder.GetPattern()
2013-02-12 20:37:44 +06:00
isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
2017-03-20 17:27:30 +05:00
if (isDone != 1): print('LoadFromFace :', pattern.GetErrorCode())
2013-02-12 20:37:44 +06:00
# apply the pattern to a face of the first mesh
facesToSplit = Mesh_1.GetElementsByType(SMESH.FACE)
2017-03-20 17:27:30 +05:00
print("Splitting %d rectangular face(s) to %d triangles..."%(len(facesToSplit), 2*len(facesToSplit)))
2013-02-12 20:37:44 +06:00
pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), facesToSplit, 0, 0)
isDone = pattern.MakeMesh(Mesh_1.GetMesh(), 0, 0)
2017-03-20 17:27:30 +05:00
if (isDone != 1): print('MakeMesh :', pattern.GetErrorCode())
2013-02-12 20:37:44 +06:00
# create quadrangle mesh
2022-04-11 18:28:01 +05:00
Mesh_3 = smesh_builder.Mesh(Box_1)
2013-02-12 20:37:44 +06:00
Mesh_3.Segment().NumberOfSegments(1)
Mesh_3.Quadrangle()
Mesh_3.Hexahedron()
isDone = Mesh_3.Compute()
if not isDone: raise Exception('Mesh Mesh_3 : computation failed')
2013-02-12 20:37:44 +06:00
# create a 3d pattern (hexahedrons)
2022-04-11 18:28:01 +05:00
pattern_hexa = smesh_builder.GetPattern()
2013-02-12 20:37:44 +06:00
smp_hexa = """!!! Nb of points:
15
0 0 0 !- 0
1 0 0 !- 1
0 1 0 !- 2
1 1 0 !- 3
0 0 1 !- 4
1 0 1 !- 5
0 1 1 !- 6
1 1 1 !- 7
0.5 0 0.5 !- 8
0.5 0 1 !- 9
0.5 0.5 0.5 !- 10
0.5 0.5 1 !- 11
1 0 0.5 !- 12
1 0.5 0.5 !- 13
1 0.5 1 !- 14
!!! Indices of points of 4 elements:
8 12 5 9 10 13 14 11
0 8 9 4 2 10 11 6
2 10 11 6 3 13 14 7
0 1 12 8 2 3 13 10"""
pattern_hexa.LoadFromFile(smp_hexa)
# apply the pattern to a mesh
volsToSplit = Mesh_3.GetElementsByType(SMESH.VOLUME)
2017-03-20 17:27:30 +05:00
print("Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 4*len(volsToSplit)))
2013-02-12 20:37:44 +06:00
pattern_hexa.ApplyToHexahedrons(Mesh_3.GetMesh(), volsToSplit,0,3)
isDone = pattern_hexa.MakeMesh(Mesh_3.GetMesh(), True, True)
2017-03-20 17:27:30 +05:00
if (isDone != 1): print('MakeMesh :', pattern_hexa.GetErrorCode())
2013-02-12 20:37:44 +06:00
# create one more quadrangle mesh
2022-04-11 18:28:01 +05:00
Mesh_4 = smesh_builder.Mesh(Box_1)
2013-02-12 20:37:44 +06:00
Mesh_4.Segment().NumberOfSegments(1)
Mesh_4.Quadrangle()
Mesh_4.Hexahedron()
isDone = Mesh_4.Compute()
if not isDone: raise Exception('Mesh Mesh_4 : computation failed')
2013-02-12 20:37:44 +06:00
# create another 3d pattern (pyramids)
2022-04-11 18:28:01 +05:00
pattern_pyra = smesh_builder.GetPattern()
2013-02-12 20:37:44 +06:00
smp_pyra = """!!! Nb of points:
9
0 0 0 !- 0
1 0 0 !- 1
0 1 0 !- 2
1 1 0 !- 3
0 0 1 !- 4
1 0 1 !- 5
0 1 1 !- 6
1 1 1 !- 7
0.5 0.5 0.5 !- 8
!!! Indices of points of 6 elements:
0 1 5 4 8
7 5 1 3 8
3 2 6 7 8
2 0 4 6 8
0 2 3 1 8
4 5 7 6 8"""
pattern_pyra.LoadFromFile(smp_pyra)
# apply the pattern to a face mesh
volsToSplit = Mesh_4.GetElementsByType(SMESH.VOLUME)
2017-03-20 17:27:30 +05:00
print("Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 6*len(volsToSplit)))
2013-02-12 20:37:44 +06:00
pattern_pyra.ApplyToHexahedrons(Mesh_4.GetMesh(), volsToSplit,1,0)
isDone = pattern_pyra.MakeMesh(Mesh_4.GetMesh(), True, True)
2017-03-20 17:27:30 +05:00
if (isDone != 1): print('MakeMesh :', pattern_pyra.GetErrorCode())