Salome HOME
Copyright update 2022
[plugins/hybridplugin.git] / tests / mg_hybrid_pyramids.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2017-2022  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21
22 import sys
23 import salome
24
25 salome.salome_init()
26
27 ###
28 ### GEOM component
29 ###
30
31 import GEOM
32 from salome.geom import geomBuilder
33 import math
34 import SALOMEDS
35
36
37 geompy = geomBuilder.New()
38
39 box_side = 200
40
41 O = geompy.MakeVertex(0, 0, 0)
42 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
43 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
44 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
45 Box_1 = geompy.MakeBoxDXDYDZ(box_side, box_side, box_side)
46 geompy.addToStudy( O, 'O' )
47 geompy.addToStudy( OX, 'OX' )
48 geompy.addToStudy( OY, 'OY' )
49 geompy.addToStudy( OZ, 'OZ' )
50 geompy.addToStudy( Box_1, 'Box_1' )
51
52 ###
53 ### SMESH component
54 ###
55
56 import  SMESH, SALOMEDS
57 from salome.smesh import smeshBuilder
58
59 smesh = smeshBuilder.New()
60 Mesh_1 = smesh.Mesh(Box_1)
61 MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
62 MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
63 MG_CADSurf_Parameters_1.SetPhySize( 10 )
64 MG_CADSurf_Parameters_1.SetMinSize( 0.34641 )
65 MG_CADSurf_Parameters_1.SetMaxSize( 69.282 )
66
67 isDone = Mesh_1.Compute()
68
69 # Copy the skin mesh
70 Mesh_2 = smesh.CopyMesh( Mesh_1, 'Mesh_2', 0, 0)
71
72 # Add hybrid
73 HYBRID_3D = Mesh_1.Tetrahedron(algo=smeshBuilder.HYBRID)
74 MG_Hybrid_Parameters_1 = HYBRID_3D.Parameters()
75 MG_Hybrid_Parameters_1.SetElementGeneration( 1 )
76 MG_Hybrid_Parameters_1.SetHeightFirstLayer( 1 )
77 MG_Hybrid_Parameters_1.SetNbOfBoundaryLayers( 3 )
78
79 # Compute mesh on CAD
80 # ===================
81 isDone = Mesh_1.Compute()
82
83 # Check volume
84 vol_mesh_1 = smesh.GetVolume(Mesh_1)
85 vol_box = box_side**3
86 assert abs(vol_mesh_1-vol_box)/vol_box < 1e-4
87
88 # Check number of pyramids
89 assert Mesh_1.NbPyramids() > 1000
90
91 # Add hybrid to skin mesh
92 HYBRID_3D_1 = Mesh_2.Tetrahedron(algo=smeshBuilder.HYBRID,geom=None)
93 status = Mesh_2.AddHypothesis(MG_Hybrid_Parameters_1,None)
94
95 # Compute mesh without CAD
96 # ========================
97 isDone = Mesh_2.Compute()
98
99 # Check volume
100 vol_mesh_2 = smesh.GetVolume(Mesh_2)
101 vol_box = box_side**3
102 assert abs(vol_mesh_2-vol_box)/vol_box < 1e-4
103
104 # Check number of pyramids
105 assert Mesh_2.NbPyramids() > 1000
106