2013-02-12 20:37:44 +06:00
|
|
|
# Export of a Mesh
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
import salome
|
|
|
|
salome.salome_init()
|
|
|
|
import GEOM
|
|
|
|
from salome.geom import geomBuilder
|
2017-06-13 15:01:10 +05:00
|
|
|
geompy = geomBuilder.New()
|
2013-04-04 13:08:19 +06:00
|
|
|
|
|
|
|
import SMESH, SALOMEDS
|
|
|
|
from salome.smesh import smeshBuilder
|
2017-06-13 15:01:10 +05:00
|
|
|
smesh = smeshBuilder.New()
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# create a box
|
|
|
|
box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
|
|
|
|
idbox = geompy.addToStudy(box, "box")
|
|
|
|
|
|
|
|
# create a mesh
|
|
|
|
tetra = smesh.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
|
|
|
|
tetra.Compute()
|
|
|
|
|
|
|
|
# export the mesh in a MED file
|
2013-06-05 21:13:53 +06:00
|
|
|
import tempfile
|
|
|
|
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
|
|
|
|
face = geompy.SubShapeAll( box, geompy.ShapeType["FACE"])[0] # a box side
|
|
|
|
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
|
|
|
|
# ========================
|
|
|
|
|
|
|
|
face = geompy.MakeFaceHW( 10, 10, 1, "rectangle" )
|
|
|
|
mesh2D = smesh.Mesh( face, "mesh2D" )
|
|
|
|
mesh2D.AutomaticHexahedralization(0)
|
|
|
|
|
|
|
|
import MEDLoader, os
|
|
|
|
|
|
|
|
# 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 )
|