Salome HOME
Provide missing TUI examples of some algorithms
[modules/smesh.git] / doc / salome / examples / cartesian_algo.py
1 # Usage of Body Fitting algorithm
2
3
4 import salome
5 salome.salome_init()
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 geompy.addToStudy( sphere, "sphere" )
18
19 # create a mesh and assign a "Body Fitting" algo
20 mesh = smesh.Mesh( sphere )
21 cartAlgo = mesh.BodyFitted()
22
23 # define a cartesian grid using Coordinates
24 coords = list(range(-100,100,10))
25 cartHyp = cartAlgo.SetGrid( coords,coords,coords, 1000000)
26
27 # compute the mesh
28 mesh.Compute()
29 print("nb hexahedra",mesh.NbHexas())
30 print("nb tetrahedra",mesh.NbTetras())
31 print("nb polyhedra",mesh.NbPolyhedrons())
32 print()
33
34 # define the grid by setting constant spacing
35 cartHyp = cartAlgo.SetGrid( "10","10","10", 1000000)
36
37 mesh.Compute()
38 print("nb hexahedra",mesh.NbHexas())
39 print("nb tetrahedra",mesh.NbTetras())
40 print("nb polyhedra",mesh.NbPolyhedrons())
41
42
43 # define the grid by setting different spacing in 2 sub-ranges of geometry
44 spaceFuns = ["5","10+10*t"]
45 cartAlgo.SetGrid( [spaceFuns, [0.5]], [spaceFuns, [0.5]], [spaceFuns, [0.25]], 10 )
46
47 mesh.Compute()
48 print("nb hexahedra",mesh.NbHexas())
49 print("nb tetrahedra",mesh.NbTetras())
50 print("nb polyhedra",mesh.NbPolyhedrons())
51 print()
52
53 # Example of customization of dirtections of the grid axes
54
55 # make a box with non-orthogonal edges
56 xDir = geompy.MakeVectorDXDYDZ( 1.0, 0.1, 0.0, "xDir" )
57 yDir = geompy.MakeVectorDXDYDZ(-0.1, 1.0, 0.0, "yDir"  )
58 zDir = geompy.MakeVectorDXDYDZ( 0.2, 0.3, 1.0, "zDir"  )
59 face = geompy.MakePrismVecH( xDir, yDir, 1.0 )
60 box  = geompy.MakePrismVecH( face, zDir, 1.0, theName="box" )
61
62 spc = "0.1" # spacing
63
64 # default axes
65 mesh = smesh.Mesh( box, "custom axes")
66 algo = mesh.BodyFitted()
67 algo.SetGrid( spc, spc, spc, 10000 )
68 mesh.Compute()
69 print("Default axes")
70 print("   nb hex:",mesh.NbHexas())
71
72 # set axes using edges of the box
73 algo.SetAxesDirs( xDir, [-0.1,1,0], zDir )
74 mesh.Compute()
75 print("Manual axes")
76 print("   nb hex:",mesh.NbHexas())
77
78 # set optimal orthogonal axes
79 algo.SetOptimalAxesDirs( isOrthogonal=True )
80 mesh.Compute()
81 print("Optimal orthogonal axes")
82 print("   nb hex:",mesh.NbHexas())
83
84 # set optimal non-orthogonal axes
85 algo.SetOptimalAxesDirs( isOrthogonal=False )
86 mesh.Compute()
87 print("Optimal non-orthogonal axes")
88 print("   nb hex:",mesh.NbHexas())