Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / doc / salome / examples / cartesian_algo.py
1 # Usage of Body Fitting algorithm
2
3
4 import salome
5 salome.salome_init_without_session()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New()
9
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh =  smeshBuilder.New()
13
14
15 # create a sphere
16 sphere = geompy.MakeSphereR( 50 )
17
18 # cut the sphere by a box
19 box = geompy.MakeBoxDXDYDZ( 100, 100, 100 )
20 partition = geompy.MakePartition([ sphere ], [ box ], theName="partition")
21
22 # create a mesh and assign a "Body Fitting" algo
23 mesh = smesh.Mesh( partition )
24 cartAlgo = mesh.BodyFitted()
25
26 # define a cartesian grid using Coordinates
27 coords = list(range(-100,100,10))
28 cartHyp = cartAlgo.SetGrid( coords,coords,coords, 1000000)
29
30 # compute the mesh
31 mesh.Compute()
32 print("nb hexahedra",mesh.NbHexas())
33 print("nb tetrahedra",mesh.NbTetras())
34 print("nb polyhedra",mesh.NbPolyhedrons())
35 print()
36
37 # define the grid by setting constant spacing
38 cartHyp = cartAlgo.SetGrid( "10","10","10", 1000000)
39
40 mesh.Compute()
41 print("nb hexahedra",mesh.NbHexas())
42 print("nb tetrahedra",mesh.NbTetras())
43 print("nb polyhedra",mesh.NbPolyhedrons())
44 print("nb faces",mesh.NbFaces())
45 print()
46
47 # activate creation of faces
48 cartHyp.SetToCreateFaces( True )
49
50 mesh.Compute()
51 print("nb hexahedra",mesh.NbHexas())
52 print("nb tetrahedra",mesh.NbTetras())
53 print("nb polyhedra",mesh.NbPolyhedrons())
54 print("nb faces",mesh.NbFaces())
55 print()
56
57 # enable consideration of shared faces
58 cartHyp.SetToConsiderInternalFaces( True )
59 mesh.Compute()
60 print("nb hexahedra",mesh.NbHexas())
61 print("nb tetrahedra",mesh.NbTetras())
62 print("nb polyhedra",mesh.NbPolyhedrons())
63 print("nb faces",mesh.NbFaces())
64 print()
65
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 )
69
70 mesh.Compute()
71 print("nb hexahedra",mesh.NbHexas())
72 print("nb tetrahedra",mesh.NbTetras())
73 print("nb polyhedra",mesh.NbPolyhedrons())
74 print()
75
76 # Example of customization of dirtections of the grid axes
77
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" )
84
85 spc = "0.1" # spacing
86
87 # default axes
88 mesh = smesh.Mesh( box, "custom axes")
89 algo = mesh.BodyFitted()
90 algo.SetGrid( spc, spc, spc, 10000 )
91 mesh.Compute()
92 print("Default axes")
93 print("   nb hex:",mesh.NbHexas())
94
95 # set axes using edges of the box
96 algo.SetAxesDirs( xDir, [-0.1,1,0], zDir )
97 mesh.Compute()
98 print("Manual axes")
99 print("   nb hex:",mesh.NbHexas())
100
101 # set optimal orthogonal axes
102 algo.SetOptimalAxesDirs( isOrthogonal=True )
103 mesh.Compute()
104 print("Optimal orthogonal axes")
105 print("   nb hex:",mesh.NbHexas())
106
107 # set optimal non-orthogonal axes
108 algo.SetOptimalAxesDirs( isOrthogonal=False )
109 mesh.Compute()
110 print("Optimal non-orthogonal axes")
111 print("   nb hex:",mesh.NbHexas())