Salome HOME
corrections to pass tests
[modules/hydro.git] / doc / salome / examples / h029_regroupMeshesNonEnglobant.py
1 # -*- coding: utf-8 -*-
2
3 import os
4 HYDRO_SAMPLES = os.path.join( os.environ["HYDRO_ROOT_DIR"], "bin/salome/test/HYDRO")
5 HYDRO_TEST_RESOURCES = os.path.join(os.environ["HYDRO_DIR"], "bin", "salome", "test", "tmp_test")
6
7 import tempfile
8 tmpdir = tempfile.mkdtemp()
9 print("tmpdir=",tmpdir)
10
11 # --- generated resources
12
13 origFileMeshAval = os.path.join(HYDRO_TEST_RESOURCES, 'garonne_2.med')
14 origFileMeshAmont = os.path.join(HYDRO_TEST_RESOURCES, 'garonneAmont.med')
15
16 # ----------------------------------------------------------------------------------
17 # --- domain extension
18
19 import sys
20 import salome
21
22 salome.salome_init()
23
24 from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups, fitShapePointsToMesh
25
26 offsetX = 430000.
27 offsetY = 6350000.
28
29 ficMeshOutAval = os.path.join(tmpdir, "garonneAval_brd.med")
30 fileMeshAvalBrd = freeBordersGroup(origFileMeshAval, ficMeshOutAval)
31 exploreEdgeGroups(fileMeshAvalBrd, "", offsetX, offsetY)
32
33 ficMeshOutAmont = os.path.join(tmpdir, "garonneAmont_brd.med")
34 fileMeshAmontBrd = freeBordersGroup(origFileMeshAmont, ficMeshOutAmont)
35 exploreEdgeGroups(fileMeshAmontBrd, "", offsetX, offsetY)
36
37 #----------------------
38 # --- HYDRO
39 #----------------------
40
41 from HYDROPy import *
42 from PyQt5.QtCore import *
43 from PyQt5.QtGui import *
44
45 from salome.hydrotools.hydroGeoMeshUtils import importPolylines, importBathymetry, createImmersibleZone, mergePolylines, getChildrenInStudy
46
47 hydro_doc = HYDROData_Document.Document()
48 hydro_doc.SetLocalCS( offsetX, offsetY )
49
50 fitShapePointsToMesh(os.path.join(tmpdir, "garonneAval_brd_FreeBorders.shp"),
51                      os.path.join(HYDRO_SAMPLES, 'raccord_4_1.shp'),
52                      tmpdir, False, False)
53
54 # TODO: if limites_aval imported as spline, problem on mesh with 2D triangle algorithm
55 #limites_aval = importPolylines(hydro_doc, os.path.join(tmpdir, "garonneAval_brd_FreeBorders.shp"), 'garonneAval_brd_FreeBorders', True, 4)
56 limites_aval = importPolylines(hydro_doc, os.path.join(tmpdir, "garonneAval_brd_FreeBorders.shp"), 'garonneAval_brd_FreeBorders', False, 4)
57 limites_domaine1  = importPolylines(hydro_doc, os.path.join(tmpdir, "raccord_4_1_adj.shp"), 'raccord_4_1', False, 2)
58
59 fitShapePointsToMesh(os.path.join(tmpdir, "garonneAmont_brd_FreeBorders.shp"),
60                      os.path.join(tmpdir, 'raccord_4_1_adj.shp'),
61                      tmpdir, False, False)
62
63
64 # TODO: if limites_amont imported as spline, problem on mesh with 2D triangle algorithm
65 #limites_amont = importPolylines(hydro_doc, os.path.join(tmpdir, "garonneAmont_brd_FreeBorders.shp"), 'garonneAmont_brd_FreeBorders', True, 5)
66 limites_amont = importPolylines(hydro_doc, os.path.join(tmpdir, "garonneAmont_brd_FreeBorders.shp"), 'garonneAmont_brd_FreeBorders', False, 5)
67 limites_domaine  = importPolylines(hydro_doc, os.path.join(tmpdir, "raccord_4_1_adj_adj.shp"), 'raccord_4_1_adj', False, 2)
68
69 Cloud_02 = importBathymetry(hydro_doc, "Cloud_02", HYDRO_SAMPLES)
70
71 junction = createImmersibleZone(hydro_doc, "junction", limites_domaine[0], Cloud_02, True, 0)
72 garonneAval = createImmersibleZone(hydro_doc, "garonneAval", limites_aval[0], Cloud_02, False, 0)
73 garonneAmont = createImmersibleZone(hydro_doc, "garonneAmont", limites_amont[0], Cloud_02, False, 0)
74
75 # Calculation case
76 Junction = hydro_doc.CreateObject( KIND_CALCULATION )
77 Junction.SetName( "Junction" )
78
79 Junction.SetAssignmentMode( HYDROData_CalculationCase.MANUAL )
80 Junction.AddGeometryObject( garonneAmont )
81 Junction.AddGeometryObject( garonneAval )
82 Junction.AddGeometryObject( junction )
83
84 case_geom_group = garonneAmont.GetGroup( 0 )
85 Junction.AddGeometryGroup( case_geom_group )
86 case_geom_group = junction.GetGroup( 0 )
87 Junction.AddGeometryGroup( case_geom_group )
88 case_geom_group = garonneAval.GetGroup( 0 )
89 Junction.AddGeometryGroup( case_geom_group )
90
91 Junction.SetBoundaryPolyline( limites_domaine[0] )
92
93 # Start the algorithm of the partition and assignment
94 Junction.Update()
95 Junction_Reg_1 = hydro_doc.FindObjectByName( "Junction_Reg_1" )
96 Junction_Zone_1 = hydro_doc.FindObjectByName( "Junction_Zone_1" )
97 Junction_Zone_1.SetMergeType( HYDROData_Zone.Merge_ZMAX )
98 Junction_Zone_1.SetColor( QColor( 228, 111, 28 ))
99 Junction_Reg_1.AddZone( Junction_Zone_1 )
100 Junction_Reg_2 = hydro_doc.FindObjectByName( "Junction_Reg_2" )
101 Junction_Zone_2 = hydro_doc.FindObjectByName( "Junction_Zone_2" )
102 Junction_Zone_2.SetMergeType( HYDROData_Zone.Merge_ZMAX )
103 Junction_Zone_2.SetColor( QColor( 185, 228, 28 ))
104 Junction_Reg_2.AddZone( Junction_Zone_2 )
105 Junction_Reg_3 = hydro_doc.FindObjectByName( "Junction_Reg_3" )
106 Junction_Zone_3 = hydro_doc.FindObjectByName( "Junction_Zone_3" )
107 Junction_Zone_3.SetColor( QColor( 28, 228, 111 ))
108 Junction_Reg_3.AddZone( Junction_Zone_3 )
109 Junction_Reg_1.SetName( "Junction_Reg_1" )
110 Junction_Reg_2.SetName( "Junction_Reg_2" )
111 Junction_Reg_3.SetName( "Junction_Reg_3" )
112
113 # Export of the calculation case
114 Junction_entry = Junction.Export()
115
116 ##----------------------
117 ## --- Geometry
118 ##----------------------
119
120 import GEOM
121 from salome.geom import geomBuilder
122 import math
123 import SALOMEDS
124
125 from salome.hydrotools.hydroGeoMeshUtils import getChildrenInStudy
126
127 geompy = geomBuilder.New()
128
129 print ("Entry:", Junction_entry)
130 HYDRO_Junction = salome.IDToObject( str( Junction_entry ) )
131 print ("Geom shape:", HYDRO_Junction)
132 print ("Geom shape name:", HYDRO_Junction.GetName())
133
134 [reg_Junction] = geompy.SubShapeAll(HYDRO_Junction, geompy.ShapeType["FACE"])
135
136 children = getChildrenInStudy(HYDRO_Junction)
137 Junction_garonneAmont_Outer = children['Junction_garonneAmont_Outer']
138 Junction_garonneAval_Outer = children['Junction_garonneAval_Outer']
139
140 if salome.sg.hasDesktop():
141   salome.sg.updateObjBrowser()
142
143 #----------------------
144 #--- Meshing
145 #----------------------
146
147 import  SMESH, SALOMEDS
148 from salome.smesh import smeshBuilder
149 from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats
150
151 smesh = smeshBuilder.New()
152
153 #--- algorithms and hypothesis
154 meshJunction = smesh.Mesh(HYDRO_Junction)
155
156 NETGEN_2D = meshJunction.Triangle(algo=smeshBuilder.NETGEN_1D2D)
157 NETGEN_2D_Parameters = NETGEN_2D.Parameters()
158 NETGEN_2D_Parameters.SetMaxSize( 200 )
159 NETGEN_2D_Parameters.SetSecondOrder( 0 )
160 NETGEN_2D_Parameters.SetOptimize( 1 )
161 NETGEN_2D_Parameters.SetFineness( 4 )
162 NETGEN_2D_Parameters.SetMinSize( 5 )
163 NETGEN_2D_Parameters.SetUseSurfaceCurvature( 1 )
164 NETGEN_2D_Parameters.SetFuseEdges( 1 )
165 NETGEN_2D_Parameters.SetQuadAllowed( 0 )
166
167 ([origMeshAvalBrd], status) = smesh.CreateMeshesFromMED(fileMeshAvalBrd)
168 FreeBordersAval = origMeshAvalBrd.GetGroupByName("FreeBorders")
169 Import_1Daval = meshJunction.UseExisting1DElements(geom=Junction_garonneAval_Outer)
170 Source_Edges_1 = Import_1Daval.SourceEdges( FreeBordersAval ,1,1)
171
172 ([origMeshAmontBrd], status) = smesh.CreateMeshesFromMED(fileMeshAmontBrd)
173 FreeBordersAmont = origMeshAmontBrd.GetGroupByName("FreeBorders")
174 Import_1Damont = meshJunction.UseExisting1DElements(geom=Junction_garonneAmont_Outer)
175 Source_Edges_2 = Import_1Damont.SourceEdges( FreeBordersAmont ,1,1)
176
177 isDone = meshJunction.Compute()
178
179 controlMeshStats(meshJunction, 7420, 918, 14525)
180
181 if salome.sg.hasDesktop():
182   salome.sg.updateObjBrowser()