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