2013-02-12 20:37:44 +06:00
|
|
|
# Usage of Body Fitting algorithm
|
|
|
|
|
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-04-04 13:08:19 +06:00
|
|
|
import salome_notebook
|
|
|
|
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# create a sphere
|
|
|
|
sphere = geompy.MakeSphereR( 50 )
|
|
|
|
geompy.addToStudy( sphere, "sphere" )
|
|
|
|
|
|
|
|
# create a mesh and assign a "Body Fitting" algo
|
2013-04-04 13:08:19 +06:00
|
|
|
mesh = smesh.Mesh( sphere )
|
2013-02-12 20:37:44 +06:00
|
|
|
cartAlgo = mesh.BodyFitted()
|
|
|
|
|
|
|
|
# define a cartesian grid using Coordinates
|
2017-03-20 17:27:30 +05:00
|
|
|
coords = list(range(-100,100,10))
|
2013-02-12 20:37:44 +06:00
|
|
|
cartHyp = cartAlgo.SetGrid( coords,coords,coords, 1000000)
|
|
|
|
|
|
|
|
# compute the mesh
|
|
|
|
mesh.Compute()
|
2017-03-20 17:27:30 +05:00
|
|
|
print("nb hexahedra",mesh.NbHexas())
|
|
|
|
print("nb tetrahedra",mesh.NbTetras())
|
|
|
|
print("nb polyhedra",mesh.NbPolyhedrons())
|
|
|
|
print()
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# define the grid by setting constant spacing
|
|
|
|
cartHyp = cartAlgo.SetGrid( "10","10","10", 1000000)
|
|
|
|
|
|
|
|
mesh.Compute()
|
2017-03-20 17:27:30 +05:00
|
|
|
print("nb hexahedra",mesh.NbHexas())
|
|
|
|
print("nb tetrahedra",mesh.NbTetras())
|
|
|
|
print("nb polyhedra",mesh.NbPolyhedrons())
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
|
|
|
|
# define the grid by setting different spacing in 2 sub-ranges of geometry
|
|
|
|
spaceFuns = ["5","10+10*t"]
|
|
|
|
cartAlgo.SetGrid( [spaceFuns, [0.5]], [spaceFuns, [0.5]], [spaceFuns, [0.25]], 10 )
|
|
|
|
|
|
|
|
mesh.Compute()
|
2017-03-20 17:27:30 +05:00
|
|
|
print("nb hexahedra",mesh.NbHexas())
|
|
|
|
print("nb tetrahedra",mesh.NbTetras())
|
|
|
|
print("nb polyhedra",mesh.NbPolyhedrons())
|
|
|
|
print()
|
2014-02-04 19:02:26 +06:00
|
|
|
|
|
|
|
# Example of customization of dirtections of the grid axes
|
|
|
|
|
|
|
|
# make a box with non-orthogonal edges
|
|
|
|
xDir = geompy.MakeVectorDXDYDZ( 1.0, 0.1, 0.0, "xDir" )
|
|
|
|
yDir = geompy.MakeVectorDXDYDZ(-0.1, 1.0, 0.0, "yDir" )
|
|
|
|
zDir = geompy.MakeVectorDXDYDZ( 0.2, 0.3, 1.0, "zDir" )
|
|
|
|
face = geompy.MakePrismVecH( xDir, yDir, 1.0 )
|
|
|
|
box = geompy.MakePrismVecH( face, zDir, 1.0, theName="box" )
|
|
|
|
|
|
|
|
spc = "0.1" # spacing
|
|
|
|
|
|
|
|
# default axes
|
|
|
|
mesh = smesh.Mesh( box, "custom axes")
|
|
|
|
algo = mesh.BodyFitted()
|
|
|
|
algo.SetGrid( spc, spc, spc, 10000 )
|
|
|
|
mesh.Compute()
|
2017-03-20 17:27:30 +05:00
|
|
|
print("Default axes")
|
|
|
|
print(" nb hex:",mesh.NbHexas())
|
2014-02-04 19:02:26 +06:00
|
|
|
|
|
|
|
# set axes using edges of the box
|
|
|
|
algo.SetAxesDirs( xDir, [-0.1,1,0], zDir )
|
|
|
|
mesh.Compute()
|
2017-03-20 17:27:30 +05:00
|
|
|
print("Manual axes")
|
|
|
|
print(" nb hex:",mesh.NbHexas())
|
2014-02-04 19:02:26 +06:00
|
|
|
|
|
|
|
# set optimal orthogonal axes
|
|
|
|
algo.SetOptimalAxesDirs( isOrthogonal=True )
|
|
|
|
mesh.Compute()
|
2017-03-20 17:27:30 +05:00
|
|
|
print("Optimal orthogonal axes")
|
|
|
|
print(" nb hex:",mesh.NbHexas())
|
2014-02-04 19:02:26 +06:00
|
|
|
|
|
|
|
# set optimal non-orthogonal axes
|
|
|
|
algo.SetOptimalAxesDirs( isOrthogonal=False )
|
|
|
|
mesh.Compute()
|
2017-03-20 17:27:30 +05:00
|
|
|
print("Optimal non-orthogonal axes")
|
|
|
|
print(" nb hex:",mesh.NbHexas())
|