Salome HOME
Copyright update 2022
[plugins/hybridplugin.git] / tests / advanced_text_option.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2018-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 import sys
22 import salome
23
24 salome.salome_init()
25
26 ###
27 ### GEOM component
28 ###
29
30 import GEOM
31 from salome.geom import geomBuilder
32 import math
33 import SALOMEDS
34
35
36 geompy = geomBuilder.New()
37
38 # first cylinder
39 r1 = 0.5
40 h1 = 5
41
42 # second cylinder
43 r2 = 0.3
44 h2 = 3
45
46 length_piquage = 1.5
47
48 O = geompy.MakeVertex(0, 0, 0)
49 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
50 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
51 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
52 geompy.addToStudy( O, 'O' )
53 geompy.addToStudy( OX, 'OX' )
54 geompy.addToStudy( OY, 'OY' )
55 geompy.addToStudy( OZ, 'OZ' )
56
57 Cylinder_1 = geompy.MakeCylinderRH(r1, h1)
58 Cylinder_2 = geompy.MakeCylinderRH(r2, h2)
59 Rotation_1 = geompy.MakeRotation(Cylinder_2, OY, -90*math.pi/180.0)
60 Translation_1 = geompy.MakeTranslation(Rotation_1, 0, 0, length_piquage)
61
62 piquage = geompy.MakeFuseList([Cylinder_1, Translation_1], True, True)
63 geompy.addToStudy( piquage, 'piquage' )
64
65 Inlet_z = geompy.GetFaceNearPoint(piquage, O)
66 geompy.addToStudyInFather( piquage, Inlet_z, 'Inlet_z' )
67
68 p_inlet_x = geompy.MakeVertex(-h2, 0, length_piquage)
69 Inlet_x = geompy.GetFaceNearPoint(piquage, p_inlet_x)
70 geompy.addToStudyInFather( piquage, Inlet_x, 'Inlet_x' )
71
72 p_outlet = geompy.MakeVertex(0, 0, h1)
73 Outlet = geompy.GetFaceNearPoint(piquage, p_outlet)
74 geompy.addToStudyInFather( piquage, Outlet, 'Outlet' )
75
76 Wall = geompy.CreateGroup(piquage, geompy.ShapeType["FACE"])
77 faces = geompy.SubShapeAll(piquage, geompy.ShapeType["FACE"])
78 geompy.UnionList(Wall, faces)
79 geompy.DifferenceList(Wall, [Inlet_x, Inlet_z, Outlet])
80 geompy.addToStudyInFather( piquage, Wall, 'Wall' )
81
82 p_corner = geompy.MakeVertex(-r2, 0, length_piquage+r2)
83 corner = geompy.GetVertexNearPoint(piquage, p_corner)
84 geompy.addToStudyInFather( piquage, corner, 'corner' )
85
86 ###
87 ### SMESH component
88 ###
89
90 import  SMESH, SALOMEDS
91 from salome.smesh import smeshBuilder
92
93 smesh = smeshBuilder.New()
94
95 Mesh_with_imprinting_set_by_groups = smesh.Mesh(piquage)
96 NETGEN_2D_1 = Mesh_with_imprinting_set_by_groups.Triangle(algo=smeshBuilder.NETGEN_1D2D)
97 NETGEN_Parameters_2D = NETGEN_2D_1.Parameters()
98 NETGEN_Parameters_2D.SetMinSize( 0.01 )
99 NETGEN_Parameters_2D.SetLocalSizeOnShape(corner, 0.01)
100 NETGEN_Parameters_2D.SetFineness( 5 )
101 NETGEN_Parameters_2D.SetGrowthRate( 0.1 )
102 NETGEN_Parameters_2D.SetNbSegPerEdge( 2 )
103 NETGEN_Parameters_2D.SetNbSegPerRadius( 3 )
104
105 wall_faces = geompy.SubShapeAll(Wall, geompy.ShapeType["FACE"])
106 wall_ids = geompy.GetSubShapesIDs(piquage, wall_faces)
107 Inlet_x_id, Inlet_z_id, Outlet_id = geompy.GetSubShapesIDs(piquage, [Inlet_x, Inlet_z, Outlet])
108
109 HYBRID_3D_2_2 = Mesh_with_imprinting_set_by_groups.Tetrahedron(algo=smeshBuilder.HYBRID)
110 HYBRID_Parameters_2 = HYBRID_3D_2_2.Parameters()
111 HYBRID_Parameters_2.SetElementGeneration( 0 )
112 HYBRID_Parameters_2.SetHeightFirstLayer( 0.01 )
113 HYBRID_Parameters_2.SetBoundaryLayersProgression( 1.1 )
114 HYBRID_Parameters_2.SetNbOfBoundaryLayers( 3 )
115 HYBRID_Parameters_2.SetFacesWithLayers( wall_ids )
116 HYBRID_Parameters_2.SetFacesWithImprinting( [ Inlet_x_id, Inlet_z_id, Outlet_id ] )
117 HYBRID_Parameters_2.SetLayersOnAllWrap( 0 )
118 isDone = Mesh_with_imprinting_set_by_groups.Compute()
119
120 if not isDone:
121   raise Exception("Problem in mesh generation")
122
123 Nb_elems_0 = Mesh_with_imprinting_set_by_groups.NbVolumes()
124
125 print("Nb_elems_0: ", Nb_elems_0)
126
127 Inlet_x_3 = Mesh_with_imprinting_set_by_groups.GroupOnGeom(Inlet_x,'Inlet_x',SMESH.FACE)
128 Inlet_z_3 = Mesh_with_imprinting_set_by_groups.GroupOnGeom(Inlet_z,'Inlet_z',SMESH.FACE)
129 Outlet_3 = Mesh_with_imprinting_set_by_groups.GroupOnGeom(Outlet,'Outlet',SMESH.FACE)
130 Wall_3 = Mesh_with_imprinting_set_by_groups.GroupOnGeom(Wall,'Wall',SMESH.FACE)
131
132 # Add an advanced option as text
133 HYBRID_Parameters_2.SetAdvancedOption( '--boundary_layer_height_relative_to_local_surface_size yes' )
134 isDone = Mesh_with_imprinting_set_by_groups.Compute()
135
136 if not isDone:
137   raise Exception("Problem in mesh generation")
138
139 Nb_elems_1 = Mesh_with_imprinting_set_by_groups.NbVolumes()
140
141 print("Nb_elems_1: ", Nb_elems_1)
142
143 # Check that the number of elements is changed by the option
144 assert Nb_elems_1> 1.5*Nb_elems_0, "Advanced option as text does not work"
145