Salome HOME
bos #29171 Refactor testing procedure
[modules/smesh.git] / doc / examples / cartesian_algo.py
1 # Usage of Body Fitting algorithm
2
3 import salome
4 salome.salome_init_without_session()
5
6 from salome.geom import geomBuilder
7 from salome.smesh import smeshBuilder
8
9 geom_builder = geomBuilder.New()
10 smesh_builder = smeshBuilder.New()
11
12 # create a sphere
13 sphere = geom_builder.MakeSphereR( 50 )
14
15 # cut the sphere by a box
16 box = geom_builder.MakeBoxDXDYDZ( 100, 100, 100 )
17 partition = geom_builder.MakePartition([ sphere ], [ box ], theName="partition")
18
19 # create a mesh and assign a "Body Fitting" algo
20 mesh = smesh_builder.Mesh( partition )
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 print("nb faces",mesh.NbFaces())
42 print()
43
44 # activate creation of faces
45 cartHyp.SetToCreateFaces( True )
46
47 mesh.Compute()
48 print("nb hexahedra",mesh.NbHexas())
49 print("nb tetrahedra",mesh.NbTetras())
50 print("nb polyhedra",mesh.NbPolyhedrons())
51 print("nb faces",mesh.NbFaces())
52 print()
53
54 # enable consideration of shared faces
55 cartHyp.SetToConsiderInternalFaces( True )
56 mesh.Compute()
57 print("nb hexahedra",mesh.NbHexas())
58 print("nb tetrahedra",mesh.NbTetras())
59 print("nb polyhedra",mesh.NbPolyhedrons())
60 print("nb faces",mesh.NbFaces())
61 print()
62
63 # define the grid by setting different spacing in 2 sub-ranges of geometry
64 spaceFuns = ["5","10+10*t"]
65 cartAlgo.SetGrid( [spaceFuns, [0.5]], [spaceFuns, [0.5]], [spaceFuns, [0.25]], 10 )
66
67 mesh.Compute()
68 print("nb hexahedra",mesh.NbHexas())
69 print("nb tetrahedra",mesh.NbTetras())
70 print("nb polyhedra",mesh.NbPolyhedrons())
71 print()
72
73 # Example of customization of dirtections of the grid axes
74
75 # make a box with non-orthogonal edges
76 xDir = geom_builder.MakeVectorDXDYDZ( 1.0, 0.1, 0.0, "xDir" )
77 yDir = geom_builder.MakeVectorDXDYDZ(-0.1, 1.0, 0.0, "yDir"  )
78 zDir = geom_builder.MakeVectorDXDYDZ( 0.2, 0.3, 1.0, "zDir"  )
79 face = geom_builder.MakePrismVecH( xDir, yDir, 1.0 )
80 box  = geom_builder.MakePrismVecH( face, zDir, 1.0, theName="box" )
81
82 spc = "0.1" # spacing
83
84 # default axes
85 mesh = smesh_builder.Mesh( box, "custom axes")
86 algo = mesh.BodyFitted()
87 algo.SetGrid( spc, spc, spc, 10000 )
88 mesh.Compute()
89 print("Default axes")
90 print("   nb hex:",mesh.NbHexas())
91
92 # set axes using edges of the box
93 algo.SetAxesDirs( xDir, [-0.1,1,0], zDir )
94 mesh.Compute()
95 print("Manual axes")
96 print("   nb hex:",mesh.NbHexas())
97
98 # set optimal orthogonal axes
99 algo.SetOptimalAxesDirs( isOrthogonal=True )
100 mesh.Compute()
101 print("Optimal orthogonal axes")
102 print("   nb hex:",mesh.NbHexas())
103
104 # set optimal non-orthogonal axes
105 algo.SetOptimalAxesDirs( isOrthogonal=False )
106 mesh.Compute()
107 print("Optimal non-orthogonal axes")
108 print("   nb hex:",mesh.NbHexas())