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
|
|
|
|
|
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
|
|
|
|
|
|
|
# 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")
|
2013-06-05 21:13:53 +06:00
|
|
|
tetra.Segment().NumberOfSegments(7)
|
|
|
|
tetra.Triangle()
|
|
|
|
tetra.Tetrahedron()
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# compute the mesh
|
2023-02-21 18:59:44 +05:00
|
|
|
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
|
2013-06-05 21:13:53 +06:00
|
|
|
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>
|
2013-06-05 21:13:53 +06:00
|
|
|
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" )
|
2013-06-05 21:13:53 +06:00
|
|
|
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 )
|
2018-09-14 14:08:44 +05:00
|
|
|
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())
|
2013-06-05 21:13:53 +06:00
|
|
|
|
|
|
|
# exported mesh is in 3D space, same as in Mesh module,
|
|
|
|
# thanks to autoDimension=False
|
|
|
|
mesh2D.ExportMED( medFile, autoDimension=False )
|
2018-09-14 14:08:44 +05:00
|
|
|
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())
|
2013-06-05 21:13:53 +06:00
|
|
|
|
|
|
|
os.remove( medFile )
|