Salome HOME
Create LICENSE
[plugins/hexoticplugin.git] / doc / salome / examples / hexoticsubdom2.py
1 import salome
2 salome.salome_init()
3
4 from salome.geom import geomBuilder
5 geompy = geomBuilder.New()
6
7 import SMESH, SALOMEDS
8 from salome.smesh import smeshBuilder
9 smesh =  smeshBuilder.New()
10
11 # Create geometry: a box cut by a holed sphere
12 Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200)
13 Sphere_1 = geompy.MakeSphereR(75)
14 Sphere_2 = geompy.MakeSphereR(25)
15 geompy.TranslateDXDYDZ(Box_1, -100, -100, -100)
16 Cut_1 = geompy.MakeCut(Sphere_1, Sphere_2)
17 Cut_2 = geompy.MakeCut(Box_1, Cut_1)
18 geompy.addToStudy( Box_1, 'Box_1' )
19 geompy.addToStudy( Sphere_1, 'Sphere_1' )
20 geompy.addToStudy( Sphere_2, 'Sphere_2' )
21 geompy.addToStudy( Cut_1, 'Cut_1' )
22 geompy.addToStudy( Cut_2, 'Cut_2' )
23
24 # Create filters
25 # aFilter1: elements inside small sphere
26 aFilter1 = smesh.GetFilter(SMESH.VOLUME,SMESH.FT_BelongToGeom,'=',Sphere_2)
27 # aFilter2: elements inside big sphere and not inside small sphere
28 aFilter2 = smesh.GetFilterFromCriteria([smesh.GetCriterion(SMESH.VOLUME,SMESH.FT_BelongToGeom,'=',Sphere_1, SMESH.FT_LogicalAND),
29                                         smesh.GetCriterion(SMESH.VOLUME,SMESH.FT_BelongToGeom,'=',Sphere_2, SMESH.FT_LogicalNOT)])
30 # aFilter3: elements not inside big sphere
31 aFilter3 = smesh.GetFilter(SMESH.VOLUME,SMESH.FT_BelongToGeom,'=',Sphere_1, SMESH.FT_LogicalNOT)
32
33 # Create mesh of Cut_2 with sd mode 2
34 print("Create mesh of Cut_2 with sd mode 2")
35 Mesh_mghexa_sd2 = smesh.Mesh(Cut_2, "Mesh_mghexa_sd2")
36
37 # Create the 2D algo: MG-CADSurf with geometrical mesh
38 Mesh_mghexa_sd2.Triangle(algo=smeshBuilder.MG_CADSurf).SetGeometricMesh( 1 )
39
40 # Create the 3D algo: MG-Hexa with:
41 # - minl = 4
42 # - maxl = 8
43 # - sd = 2
44 Mesh_mghexa_sd2.Hexahedron(smeshBuilder.MG_Hexa).SetMinMaxHexes(4, 8).SetHexoticSdMode( 2 )
45
46 # Create the groups on filters
47 g1 = Mesh_mghexa_sd2.GroupOnFilter(SMESH.VOLUME, 'small sphere', aFilter1 )
48 g1.SetColor( SALOMEDS.Color( 1, 0, 0 ))
49 g2 = Mesh_mghexa_sd2.GroupOnFilter(SMESH.VOLUME, 'big sphere - small sphere', aFilter2 )
50 g2.SetColor( SALOMEDS.Color( 0, 1, 0 ))
51 g3 = Mesh_mghexa_sd2.GroupOnFilter(SMESH.VOLUME, 'box - big sphere', aFilter3 )
52 g3.SetColor( SALOMEDS.Color( 0, 0, 1 ))
53
54 # Compute
55 assert Mesh_mghexa_sd2.Compute(), "Meshing fails"
56
57 # End of script
58