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