1 # Usage of Body Fitting algorithm
5 salome.salome_init_without_session()
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New()
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New()
16 sphere = geompy.MakeSphereR( 50 )
18 # cut the sphere by a box
19 box = geompy.MakeBoxDXDYDZ( 100, 100, 100 )
20 partition = geompy.MakePartition([ sphere ], [ box ], theName="partition")
22 # create a mesh and assign a "Body Fitting" algo
23 mesh = smesh.Mesh( partition )
24 cartAlgo = mesh.BodyFitted()
26 # define a cartesian grid using Coordinates
27 coords = list(range(-100,100,10))
28 cartHyp = cartAlgo.SetGrid( coords,coords,coords, 1000000)
32 print("nb hexahedra",mesh.NbHexas())
33 print("nb tetrahedra",mesh.NbTetras())
34 print("nb polyhedra",mesh.NbPolyhedrons())
37 # define the grid by setting constant spacing
38 cartHyp = cartAlgo.SetGrid( "10","10","10", 1000000)
41 print("nb hexahedra",mesh.NbHexas())
42 print("nb tetrahedra",mesh.NbTetras())
43 print("nb polyhedra",mesh.NbPolyhedrons())
44 print("nb faces",mesh.NbFaces())
47 # activate creation of faces
48 cartHyp.SetToCreateFaces( True )
51 print("nb hexahedra",mesh.NbHexas())
52 print("nb tetrahedra",mesh.NbTetras())
53 print("nb polyhedra",mesh.NbPolyhedrons())
54 print("nb faces",mesh.NbFaces())
57 # enable consideration of shared faces
58 cartHyp.SetToConsiderInternalFaces( True )
60 print("nb hexahedra",mesh.NbHexas())
61 print("nb tetrahedra",mesh.NbTetras())
62 print("nb polyhedra",mesh.NbPolyhedrons())
63 print("nb faces",mesh.NbFaces())
66 # define the grid by setting different spacing in 2 sub-ranges of geometry
67 spaceFuns = ["5","10+10*t"]
68 cartAlgo.SetGrid( [spaceFuns, [0.5]], [spaceFuns, [0.5]], [spaceFuns, [0.25]], 10 )
71 print("nb hexahedra",mesh.NbHexas())
72 print("nb tetrahedra",mesh.NbTetras())
73 print("nb polyhedra",mesh.NbPolyhedrons())
76 # Example of customization of dirtections of the grid axes
78 # make a box with non-orthogonal edges
79 xDir = geompy.MakeVectorDXDYDZ( 1.0, 0.1, 0.0, "xDir" )
80 yDir = geompy.MakeVectorDXDYDZ(-0.1, 1.0, 0.0, "yDir" )
81 zDir = geompy.MakeVectorDXDYDZ( 0.2, 0.3, 1.0, "zDir" )
82 face = geompy.MakePrismVecH( xDir, yDir, 1.0 )
83 box = geompy.MakePrismVecH( face, zDir, 1.0, theName="box" )
88 mesh = smesh.Mesh( box, "custom axes")
89 algo = mesh.BodyFitted()
90 algo.SetGrid( spc, spc, spc, 10000 )
93 print(" nb hex:",mesh.NbHexas())
95 # set axes using edges of the box
96 algo.SetAxesDirs( xDir, [-0.1,1,0], zDir )
99 print(" nb hex:",mesh.NbHexas())
101 # set optimal orthogonal axes
102 algo.SetOptimalAxesDirs( isOrthogonal=True )
104 print("Optimal orthogonal axes")
105 print(" nb hex:",mesh.NbHexas())
107 # set optimal non-orthogonal axes
108 algo.SetOptimalAxesDirs( isOrthogonal=False )
110 print("Optimal non-orthogonal axes")
111 print(" nb hex:",mesh.NbHexas())