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