smesh/doc/examples/creating_meshes_ex05.py

59 lines
1.7 KiB
Python
Raw Permalink Normal View History

2013-02-12 20:37:44 +06:00
# Export of a Mesh
2022-04-11 18:28:01 +05:00
import os
import tempfile
import MEDLoader
import salome
salome.salome_init_without_session()
2022-04-11 18:28:01 +05:00
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
# create a box
2022-04-11 18:28:01 +05:00
box = geom_builder.MakeBox(0., 0., 0., 100., 200., 300.)
idbox = geom_builder.addToStudy(box, "box")
2013-02-12 20:37:44 +06:00
# create a mesh
2022-04-11 18:28:01 +05:00
tetra = smesh_builder.Mesh(box, "MeshBox")
tetra.Segment().NumberOfSegments(7)
tetra.Triangle()
tetra.Tetrahedron()
2013-02-12 20:37:44 +06:00
# compute the mesh
if not tetra.Compute(): raise Exception("Error when computing Mesh")
2013-02-12 20:37:44 +06:00
# export the mesh in a MED file
medFile = tempfile.NamedTemporaryFile(suffix=".med").name
tetra.ExportMED( medFile, 0 )
2013-02-12 20:37:44 +06:00
# export a group in a MED file
2022-04-11 18:28:01 +05:00
face = geom_builder.SubShapeAll( box, geom_builder.ShapeType["FACE"])[0] # a box side
2013-02-12 20:37:44 +06:00
group = tetra.GroupOnGeom( face, "face group" ) # group of 2D elements on the <face>
tetra.ExportMED( medFile, meshPart=group )
# ========================
# autoDimension parameter
# ========================
2022-04-11 18:28:01 +05:00
face = geom_builder.MakeFaceHW( 10, 10, 1, "rectangle" )
mesh2D = smesh_builder.Mesh( face, "mesh2D" )
mesh2D.AutomaticHexahedralization(0)
# exported mesh is in 2D space because it is a planar mesh lying
# on XOY plane, and autoDimension=True by default
mesh2D.ExportMED( medFile )
medMesh = MEDLoader.ReadUMeshFromFile(medFile,mesh2D.GetName(),0)
2017-03-20 17:27:30 +05:00
print("autoDimension==True, exported mesh is in %sD"%medMesh.getSpaceDimension())
# exported mesh is in 3D space, same as in Mesh module,
# thanks to autoDimension=False
mesh2D.ExportMED( medFile, autoDimension=False )
medMesh = MEDLoader.ReadUMeshFromFile(medFile,mesh2D.GetName(),0)
2017-03-20 17:27:30 +05:00
print("autoDimension==False, exported mesh is in %sD"%medMesh.getSpaceDimension())
os.remove( medFile )