Salome HOME
Copyright update 2022
[plugins/hybridplugin.git] / tests / cartesian_core_size.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 O = geompy.MakeVertex(0, 0, 0)
40 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
41 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
42 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
43 Cylinder_1 = geompy.MakeCylinderRH(100, 300)
44 geompy.addToStudy( O, 'O' )
45 geompy.addToStudy( OX, 'OX' )
46 geompy.addToStudy( OY, 'OY' )
47 geompy.addToStudy( OZ, 'OZ' )
48 geompy.addToStudy( Cylinder_1, 'Cylinder_1' )
49
50 ###
51 ### SMESH component
52 ###
53
54 import  SMESH, SALOMEDS
55 from salome.smesh import smeshBuilder
56
57 from salome.HYBRIDPlugin import HYBRIDPluginBuilder
58
59 smesh = smeshBuilder.New()
60
61 # Hybrid mesh with hexa dominant core
62 # ===================================
63
64 Mesh_1 = smesh.Mesh(Cylinder_1)
65
66 MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
67
68 MG_Hybrid = Mesh_1.Tetrahedron(algo=smeshBuilder.HYBRID)
69 MG_Hybrid_Parameters_1 = MG_Hybrid.Parameters()
70 MG_Hybrid_Parameters_1.SetElementGeneration( HYBRIDPluginBuilder.Generation_Hexa_Dominant )
71 MG_Hybrid_Parameters_1.SetHeightFirstLayer( 1 )
72 MG_Hybrid_Parameters_1.SetNbOfBoundaryLayers( 3 )
73
74 isDone = Mesh_1.Compute()
75
76 nb_hexas_1 = Mesh_1.NbHexas()
77
78 # check that hexaedra have been genereted
79 assert nb_hexas_1 > 0
80
81 # Hybrid mesh with cartesian core
82 # ===============================
83
84 Mesh_2 = smesh.Mesh(Cylinder_1)
85
86 MG_CADSurf_1 = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf)
87
88 MG_Hybrid_1 = Mesh_2.Tetrahedron(algo=smeshBuilder.HYBRID)
89 MG_Hybrid_Parameters_2 = MG_Hybrid_1.Parameters()
90 MG_Hybrid_Parameters_2.SetElementGeneration( HYBRIDPluginBuilder.Generation_Cartesian_Core )
91 MG_Hybrid_Parameters_2.SetHeightFirstLayer( 1 )
92 MG_Hybrid_Parameters_2.SetNbOfBoundaryLayers( 3 )
93
94 isDone = Mesh_2.Compute()
95
96 nb_hexas_2 = Mesh_2.NbHexas()
97
98 # check that hexaedra have been genereted
99 assert nb_hexas_2 > 0
100
101
102 # Hybrid mesh with cartesian core with fine core elements size
103 # ============================================================
104
105 Mesh_3 = smesh.Mesh(Cylinder_1)
106
107 MG_CADSurf_1 = Mesh_3.Triangle(algo=smeshBuilder.MG_CADSurf)
108
109 MG_Hybrid_1 = Mesh_3.Tetrahedron(algo=smeshBuilder.HYBRID)
110 MG_Hybrid_Parameters_3 = MG_Hybrid_1.Parameters()
111 MG_Hybrid_Parameters_3.SetElementGeneration( HYBRIDPluginBuilder.Generation_Cartesian_Core )
112 MG_Hybrid_Parameters_3.SetHeightFirstLayer( 1 )
113 MG_Hybrid_Parameters_3.SetNbOfBoundaryLayers( 3 )
114 MG_Hybrid_Parameters_3.SetCoreSize( 10 )
115
116 isDone = Mesh_3.Compute()
117
118 nb_hexas_3 = Mesh_3.NbHexas()
119
120 # check that more hexaedra have been genereted
121 assert nb_hexas_3 > nb_hexas_2
122