]> SALOME platform Git repositories - modules/hydro.git/blob - doc/salome/examples/h020_normalCaseChangeBathy.py
Salome HOME
add test case h020_normalCaseChangeBathy.py
[modules/hydro.git] / doc / salome / examples / h020_normalCaseChangeBathy.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
6 import sys
7 import salome
8
9 salome.salome_init()
10
11 #----------------------
12 # --- HYDRO
13 #----------------------
14
15 from HYDROPy import *
16 from PyQt5.QtCore import *
17 from PyQt5.QtGui import *
18
19 hydro_doc = HYDROData_Document.Document()
20
21 hydro_doc.SetLocalCS( 430000, 6.35e+06 )
22
23 garonne_ign_01 = hydro_doc.CreateObject( KIND_IMAGE )
24 garonne_ign_01.SetName( "garonne_ign_01" )
25
26 garonne_ign_01.SetZLevel( 0 )
27
28
29 if not(garonne_ign_01.LoadImage(os.path.join(HYDRO_SAMPLES, "garonne_ign_01.png" ))):
30   raise ValueError('problem while loading image')
31
32 garonne_ign_01.SetLocalPoints( QPoint( 40, 817 ),
33                                QPoint( 1325, 85 ) )
34
35 garonne_ign_01.SetGlobalPoints( 1,
36                                 QPointF( 471562, 6.36775e+06 ),
37                                 QPointF( 489400, 6.37702e+06 ) )
38
39 garonne_ign_01.Update()
40
41 garonne_ign_02 = hydro_doc.CreateObject( KIND_IMAGE )
42 garonne_ign_02.SetName( "garonne_ign_02" )
43
44 garonne_ign_02.SetZLevel( 1 )
45
46
47 if not(garonne_ign_02.LoadImage( os.path.join(HYDRO_SAMPLES, "garonne_ign_02.png" ))):
48   raise ValueError('problem while loading image')
49
50 garonne_ign_02.SetLocalPoints( QPoint( 1389, 447 ),
51                                QPoint( 784, 481 ) )
52
53 garonne_ign_02.SetGlobalPoints( 3,
54                                 QPointF( 631, 95 ),
55                                 QPointF( 26, 129 ) )
56 garonne_ign_02.SetTrsfReferenceImage( garonne_ign_01 )
57
58 garonne_ign_02.Update()
59
60 garonne = hydro_doc.CreateObject( KIND_POLYLINEXY )
61 garonne.SetName( "garonne" )
62
63 garonne.SetZLevel( 2 )
64
65 garonne.AddSection( "Section_1", 1, 1 )
66 garonne.AddPoint( 0, gp_XY( 38191.48, 33184.55 ) )
67 garonne.AddPoint( 0, gp_XY( 38553.78, 33013.53 ) )
68 garonne.AddPoint( 0, gp_XY( 38993.90, 32767.64 ) )
69 garonne.AddPoint( 0, gp_XY( 39678.58, 32533.58 ) )
70 garonne.AddPoint( 0, gp_XY( 40240.26, 32305.27 ) )
71 garonne.AddPoint( 0, gp_XY( 40717.94, 32193.70 ) )
72 garonne.AddPoint( 0, gp_XY( 41361.00, 32464.18 ) )
73 garonne.AddPoint( 0, gp_XY( 41831.41, 32626.69 ) )
74 garonne.AddPoint( 0, gp_XY( 41950.14, 32618.24 ) )
75 garonne.AddPoint( 0, gp_XY( 42524.97, 32419.61 ) )
76 garonne.AddPoint( 0, gp_XY( 42909.80, 32291.33 ) )
77 garonne.AddPoint( 0, gp_XY( 43177.03, 32269.95 ) )
78 garonne.AddPoint( 0, gp_XY( 43465.65, 32344.78 ) )
79 garonne.AddPoint( 0, gp_XY( 43754.27, 32152.37 ) )
80 garonne.AddPoint( 0, gp_XY( 44128.40, 31842.37 ) )
81 garonne.AddPoint( 0, gp_XY( 44003.90, 31269.93 ) )
82 garonne.AddPoint( 0, gp_XY( 44010.82, 30869.63 ) )
83 garonne.AddPoint( 0, gp_XY( 44064.26, 30655.84 ) )
84 garonne.AddPoint( 0, gp_XY( 44434.73, 30366.18 ) )
85 garonne.AddPoint( 0, gp_XY( 45208.04, 30484.81 ) )
86 garonne.AddPoint( 0, gp_XY( 45705.01, 30287.34 ) )
87 garonne.AddPoint( 0, gp_XY( 45933.89, 30046.87 ) )
88 garonne.AddPoint( 0, gp_XY( 46127.34, 29490.68 ) )
89 garonne.AddPoint( 0, gp_XY( 46111.60, 29226.08 ) )
90 garonne.AddPoint( 0, gp_XY( 46228.62, 28784.05 ) )
91 garonne.AddPoint( 0, gp_XY( 46247.64, 28449.75 ) )
92 garonne.AddPoint( 0, gp_XY( 46108.48, 28086.94 ) )
93 garonne.AddPoint( 0, gp_XY( 45618.52, 27553.74 ) )
94 garonne.AddPoint( 0, gp_XY( 45276.77, 27042.78 ) )
95 garonne.AddPoint( 0, gp_XY( 45001.89, 26273.15 ) )
96 garonne.AddPoint( 0, gp_XY( 45167.76, 25975.34 ) )
97 garonne.AddPoint( 0, gp_XY( 46018.15, 25848.84 ) )
98 garonne.AddPoint( 0, gp_XY( 46378.94, 25872.21 ) )
99 garonne.AddPoint( 0, gp_XY( 46885.57, 25937.64 ) )
100 garonne.AddPoint( 0, gp_XY( 47278.36, 25782.88 ) )
101 garonne.AddPoint( 0, gp_XY( 47153.86, 25728.04 ) )
102 garonne.AddPoint( 0, gp_XY( 46987.51, 25749.97 ) )
103 garonne.AddPoint( 0, gp_XY( 46658.26, 25715.71 ) )
104 garonne.AddPoint( 0, gp_XY( 45650.76, 25634.46 ) )
105 garonne.AddPoint( 0, gp_XY( 45122.63, 25748.21 ) )
106 garonne.AddPoint( 0, gp_XY( 44797.63, 26325.09 ) )
107 garonne.AddPoint( 0, gp_XY( 45114.51, 27168.75 ) )
108 garonne.AddPoint( 0, gp_XY( 45508.28, 27713.21 ) )
109 garonne.AddPoint( 0, gp_XY( 45994.19, 28382.53 ) )
110 garonne.AddPoint( 0, gp_XY( 45927.01, 29201.34 ) )
111 garonne.AddPoint( 0, gp_XY( 45756.39, 29859.47 ) )
112 garonne.AddPoint( 0, gp_XY( 45390.76, 30151.97 ) )
113 garonne.AddPoint( 0, gp_XY( 45039.85, 30120.84 ) )
114 garonne.AddPoint( 0, gp_XY( 44513.26, 30084.28 ) )
115 garonne.AddPoint( 0, gp_XY( 43923.42, 30426.28 ) )
116 garonne.AddPoint( 0, gp_XY( 43768.81, 30934.29 ) )
117 garonne.AddPoint( 0, gp_XY( 43820.10, 31425.20 ) )
118 garonne.AddPoint( 0, gp_XY( 43854.78, 31801.12 ) )
119 garonne.AddPoint( 0, gp_XY( 43479.64, 32053.54 ) )
120 garonne.AddPoint( 0, gp_XY( 42923.47, 32051.85 ) )
121 garonne.AddPoint( 0, gp_XY( 42493.64, 32187.97 ) )
122 garonne.AddPoint( 0, gp_XY( 42074.27, 32302.91 ) )
123 garonne.AddPoint( 0, gp_XY( 41624.75, 32330.93 ) )
124 garonne.AddPoint( 0, gp_XY( 41325.93, 32187.97 ) )
125 garonne.AddPoint( 0, gp_XY( 40879.52, 31987.29 ) )
126 garonne.AddPoint( 0, gp_XY( 40308.78, 32018.46 ) )
127 garonne.AddPoint( 0, gp_XY( 39782.86, 32207.17 ) )
128 garonne.AddPoint( 0, gp_XY( 38814.10, 32560.43 ) )
129 garonne.AddPoint( 0, gp_XY( 38302.17, 32903.70 ) )
130
131 garonne.Update()
132
133
134 domaine = hydro_doc.CreateObject( KIND_POLYLINEXY )
135 domaine.SetName( "domaine" )
136
137 domaine.SetZLevel( 3 )
138
139 domaine.AddSection( "Section_1", 0, 1 )
140 domaine.AddPoint( 0, gp_XY( 39901.15, 34762.30 ) );
141 domaine.AddPoint( 0, gp_XY( 38086.50, 29964.69 ) );
142 domaine.AddPoint( 0, gp_XY( 44835.83, 24264.97 ) );
143 domaine.AddPoint( 0, gp_XY( 46758.56, 25021.86 ) );
144 domaine.AddPoint( 0, gp_XY( 46757.20, 26601.21 ) );
145 domaine.AddPoint( 0, gp_XY( 48566.45, 30152.81 ) );
146 domaine.AddPoint( 0, gp_XY( 45532.36, 33239.83 ) );
147 domaine.AddPoint( 0, gp_XY( 43548.77, 34048.39 ) );
148
149 domaine.Update()
150
151
152 lit_majeur = hydro_doc.CreateObject( KIND_POLYLINEXY )
153 lit_majeur.SetName( "lit_majeur" )
154
155 lit_majeur.SetZLevel( 7 )
156
157 lit_majeur.AddSection( "Section_1", 1, 1 )
158 lit_majeur.AddPoint( 0, gp_XY( 41225.22, 34118.46 ) )
159 lit_majeur.AddPoint( 0, gp_XY( 41716.41, 33705.87 ) )
160 lit_majeur.AddPoint( 0, gp_XY( 42384.43, 33293.27 ) )
161 lit_majeur.AddPoint( 0, gp_XY( 42561.26, 32684.19 ) )
162 lit_majeur.AddPoint( 0, gp_XY( 42875.62, 32369.83 ) )
163 lit_majeur.AddPoint( 0, gp_XY( 43700.82, 32350.18 ) )
164 lit_majeur.AddPoint( 0, gp_XY( 44526.02, 31662.51 ) )
165 lit_majeur.AddPoint( 0, gp_XY( 45370.87, 31819.69 ) )
166 lit_majeur.AddPoint( 0, gp_XY( 46274.66, 31682.16 ) )
167 lit_majeur.AddPoint( 0, gp_XY( 46981.97, 31328.50 ) )
168 lit_majeur.AddPoint( 0, gp_XY( 47021.27, 30719.43 ) )
169 lit_majeur.AddPoint( 0, gp_XY( 47217.74, 30051.41 ) )
170 lit_majeur.AddPoint( 0, gp_XY( 47846.46, 29560.22 ) )
171 lit_majeur.AddPoint( 0, gp_XY( 48730.61, 28735.02 ) )
172 lit_majeur.AddPoint( 0, gp_XY( 48809.20, 27732.99 ) )
173 lit_majeur.AddPoint( 0, gp_XY( 49143.21, 27163.21 ) )
174 lit_majeur.AddPoint( 0, gp_XY( 49654.05, 26829.20 ) )
175 lit_majeur.AddPoint( 0, gp_XY( 49693.34, 25355.63 ) )
176 lit_majeur.AddPoint( 0, gp_XY( 48612.72, 23214.04 ) )
177 lit_majeur.AddPoint( 0, gp_XY( 47453.51, 23115.80 ) )
178 lit_majeur.AddPoint( 0, gp_XY( 46471.13, 24176.77 ) )
179 lit_majeur.AddPoint( 0, gp_XY( 45960.29, 25257.39 ) )
180 lit_majeur.AddPoint( 0, gp_XY( 44899.32, 25591.40 ) )
181 lit_majeur.AddPoint( 0, gp_XY( 44270.60, 26573.78 ) )
182 lit_majeur.AddPoint( 0, gp_XY( 43248.92, 27909.82 ) )
183 lit_majeur.AddPoint( 0, gp_XY( 42757.73, 28243.83 ) )
184 lit_majeur.AddPoint( 0, gp_XY( 42266.54, 28342.07 ) )
185 lit_majeur.AddPoint( 0, gp_XY( 41736.06, 28106.30 ) )
186 lit_majeur.AddPoint( 0, gp_XY( 41402.05, 28833.26 ) )
187 lit_majeur.AddPoint( 0, gp_XY( 40910.86, 28911.85 ) )
188 lit_majeur.AddPoint( 0, gp_XY( 40576.85, 29324.45 ) )
189 lit_majeur.AddPoint( 0, gp_XY( 40144.60, 29599.51 ) )
190 lit_majeur.AddPoint( 0, gp_XY( 39024.69, 30130.00 ) )
191 lit_majeur.AddPoint( 0, gp_XY( 38612.09, 30365.77 ) )
192 lit_majeur.AddPoint( 0, gp_XY( 38828.21, 33391.50 ) )
193
194 lit_majeur.Update()
195
196
197 Cloud_02 = hydro_doc.CreateObject( KIND_BATHYMETRY )
198 Cloud_02.SetName( "Cloud_02" )
199
200 Cloud_02.SetAltitudesInverted( 0 )
201 if not(Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" ))):
202   raise ValueError('problem while loading bathymetry')
203
204 Cloud_02.Update()
205
206
207 garonne_point_L93 = hydro_doc.CreateObject( KIND_BATHYMETRY )
208 garonne_point_L93.SetName( "garonne_point_L93" )
209
210 garonne_point_L93.SetAltitudesInverted( 0 )
211 if not(garonne_point_L93.ImportFromFile( os.path.join(HYDRO_SAMPLES, "garonne_point_L93.xyz" ))):
212   raise ValueError('problem while loading bathymetry')
213
214 garonne_point_L93.Update()
215
216
217 litMineur = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE )
218 litMineur.SetName( "litMineur" )
219
220 litMineur.SetZLevel( 6 )
221
222 litMineur.SetAltitudeObject( garonne_point_L93 )
223 litMineur.SetPolyline( garonne )
224
225 litMineur.Update()
226
227
228 litMajeur = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE )
229 litMajeur.SetName( "litMajeur" )
230
231 litMajeur.SetZLevel( 5 )
232
233 litMajeur.SetFillingColor( QColor( 0, 170, 127, 255 ) )
234
235 litMajeur.SetAltitudeObject( garonne_point_L93 )
236 litMajeur.SetPolyline( lit_majeur )
237
238 litMajeur.Update()
239
240
241 domaineEtendu = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE )
242 domaineEtendu.SetName( "domaineEtendu" )
243
244 domaineEtendu.SetZLevel( 4 )
245
246 domaineEtendu.SetFillingColor( QColor( 201, 203, 55, 255 ) )
247
248 domaineEtendu.SetAltitudeObject( Cloud_02 )
249 domaineEtendu.SetPolyline( domaine )
250
251 domaineEtendu.Update()
252
253
254 # Calculation case
255 garonne_1 = hydro_doc.CreateObject( KIND_CALCULATION )
256 garonne_1.SetName( "garonne_1" )
257
258 garonne_1.SetAssignmentMode( HYDROData_CalculationCase.MANUAL )
259 garonne_1.AddGeometryObject( litMineur )
260 garonne_1.AddGeometryObject( domaineEtendu )
261 garonne_1.AddGeometryObject( litMajeur )
262
263 case_geom_group = domaineEtendu.GetGroup( 0 )
264 garonne_1.AddGeometryGroup( case_geom_group )
265 case_geom_group = litMineur.GetGroup( 0 )
266 garonne_1.AddGeometryGroup( case_geom_group )
267 case_geom_group = litMajeur.GetGroup( 0 )
268 garonne_1.AddGeometryGroup( case_geom_group )
269 garonne_1.SetBoundaryPolyline( domaine )
270
271 # Start the algorithm of the partition and assignment
272 garonne_1.Update()
273 garonne_1_litMineur = hydro_doc.FindObjectByName( "garonne_1_Reg_1" )
274 garonne_1_Zone_1 = hydro_doc.FindObjectByName( "garonne_1_Zone_1" )
275 garonne_1_Zone_1.SetMergeType( HYDROData_Zone.Merge_ZMIN )
276 garonne_1_Zone_1.SetColor( QColor( 192, 113, 64 ))
277 garonne_1_litMineur.AddZone( garonne_1_Zone_1 )
278
279 garonne_1_riveDroite = hydro_doc.FindObjectByName( "garonne_1_Reg_2" )
280 garonne_1_Zone_2 = hydro_doc.FindObjectByName( "garonne_1_Zone_2" )
281 garonne_1_Zone_2.SetColor( QColor( 141, 192, 64 ))
282 garonne_1_riveDroite.AddZone( garonne_1_Zone_2 )
283
284 garonne_1_Zone_3 = hydro_doc.FindObjectByName( "garonne_1_Zone_3" )
285 garonne_1_Zone_3.SetMergeType( HYDROData_Zone.Merge_Object )
286 Cloud_02 = hydro_doc.FindObjectByName( "Cloud_02" )
287 garonne_1_Zone_3.SetMergeObject( Cloud_02 )
288 garonne_1_Zone_3.SetColor( QColor( 64, 192, 77 ))
289 garonne_1_riveDroite.AddZone( garonne_1_Zone_3 )
290
291 garonne_1_riveGauche = hydro_doc.FindObjectByName( "garonne_1_Reg_3" )
292 garonne_1_Zone_4 = hydro_doc.FindObjectByName( "garonne_1_Zone_4" )
293 garonne_1_Zone_4.SetMergeType( HYDROData_Zone.Merge_Object )
294 Cloud_02 = hydro_doc.FindObjectByName( "Cloud_02" )
295 garonne_1_Zone_4.SetMergeObject( Cloud_02 )
296 garonne_1_Zone_4.SetColor( QColor( 64, 75, 192 ))
297 garonne_1_riveGauche.AddZone( garonne_1_Zone_4 )
298
299 garonne_1_Zone_5 = hydro_doc.FindObjectByName( "garonne_1_Zone_5" )
300 garonne_1_Zone_5.SetColor( QColor( 64, 192, 77 ))
301 garonne_1_riveGauche.AddZone( garonne_1_Zone_5 )
302
303 garonne_1_litMineur.SetName("garonne_1_litMineur")
304 garonne_1_riveDroite.SetName("garonne_1_riveDroite")
305 garonne_1_riveGauche.SetName("garonne_1_riveGauche")
306
307 # Export of the calculation case
308 garonne_1_entry = garonne_1.Export()
309
310 # --- add a new bathymetry for 'litMineur'
311
312 import tempfile
313 tmpdir = tempfile.mkdtemp()
314 print("tmpdir=",tmpdir)
315
316 newBathy = os.path.join(tmpdir, 'newBathy.xyz')
317 fi=open(os.path.join(HYDRO_SAMPLES, "garonne_point_L93.xyz" ), 'r')
318 fo=open(newBathy, 'w')
319 for ligne in fi:
320     vals = ligne.split()
321     if len(vals) < 3:
322         continue
323     x = float(vals[0])
324     y = float(vals[1])
325     z = float(vals[2]) + 50
326     l = "%12.3f  %12.3f %12.3f\n" % (x, y, z)
327     fo.write(l)
328 fi.close()
329 fo.close()
330
331 nomBathy = "garonne_point_L93_50m"
332 garonne_point_L93_50m = hydro_doc.CreateObject( KIND_BATHYMETRY )
333 garonne_point_L93_50m.SetName( nomBathy )
334
335 garonne_point_L93_50m.SetAltitudesInverted( 0 )
336 if not(garonne_point_L93_50m.ImportFromFile( newBathy )):
337   raise ValueError('problem while loading bathymetry')
338
339 garonne_point_L93_50m.Update()
340
341 #----------------------
342 # --- Geometry
343 #----------------------
344
345 # Get geometry shape and print debug information
346 import GEOM
347 from salome.geom import geomBuilder
348 import math
349 import SALOMEDS
350 from salome.hydrotools.controls import controlGeomProps
351
352 geompy = geomBuilder.New()
353
354 print("Entry:", garonne_1_entry)
355 HYDRO_garonne_1 = salome.IDToObject( str( garonne_1_entry ) )
356 print("Geom shape:", HYDRO_garonne_1)
357 print("Geom shape name:", HYDRO_garonne_1.GetName())
358
359 # --- manual definition: geometrical faces
360
361 [garonne_litMineur,garonne_riveDroite,garonne_riveGauche] = geompy.SubShapeAll(HYDRO_garonne_1, geompy.ShapeType["FACE"])
362
363 controlGeomProps(geompy, garonne_riveGauche,  29149.36918,  35948828.352061)
364 controlGeomProps(geompy, garonne_litMineur,   30337.548492,  3488480.304388)
365 controlGeomProps(geompy, garonne_riveDroite,  32012.343241, 25998769.23615)
366
367 # --- manual identification of all useful edge groups (boundary conditions)
368
369 allEdgesIds = geompy.SubShapeAllIDs(HYDRO_garonne_1, geompy.ShapeType["EDGE"])
370 print("allEdgesIds", allEdgesIds)
371
372 (isDone, ClosedFreeBoundary, OpenFreeBoundary) = geompy.GetFreeBoundary(HYDRO_garonne_1)
373 geompy.addToStudyInFather(HYDRO_garonne_1, ClosedFreeBoundary[0], "ClosedFreeBoundary")
374
375 freeBoundary = geompy.ExtractShapes(ClosedFreeBoundary[0], geompy.ShapeType["EDGE"], True)
376 freeBoundaryIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, freeBoundary[i]) for i in range(len(freeBoundary)) ]
377 print("freeBoundaryIds", freeBoundaryIds)
378
379 [litMineur_droite] = geompy.GetSharedShapesMulti([garonne_riveDroite, garonne_litMineur], geompy.ShapeType["EDGE"], True)
380 [litMineur_gauche] = geompy.GetSharedShapesMulti([garonne_riveGauche, garonne_litMineur], geompy.ShapeType["EDGE"], True)
381 geompy.addToStudyInFather(HYDRO_garonne_1, litMineur_droite, "litMineur_droite")
382 geompy.addToStudyInFather(HYDRO_garonne_1, litMineur_gauche, "litMineur_gauche")
383 rives = [litMineur_droite, litMineur_gauche]
384 rivesIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, rives[i]) for i in range(len(rives)) ]
385 print("rivesIds", rivesIds)
386
387 edges_litMineur = geompy.GetSharedShapesMulti([HYDRO_garonne_1, garonne_litMineur], geompy.ShapeType["EDGE"], True)
388 edges_riveGauche = geompy.GetSharedShapesMulti([HYDRO_garonne_1, garonne_riveGauche], geompy.ShapeType["EDGE"], True)
389 edges_riveDroite = geompy.GetSharedShapesMulti([HYDRO_garonne_1, garonne_riveDroite], geompy.ShapeType["EDGE"], True)
390 edges_litMineurIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, edges_litMineur[i]) for i in range(len(edges_litMineur)) ]
391 edges_riveGaucheIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, edges_riveGauche[i]) for i in range(len(edges_riveGauche)) ]
392 edges_riveDroiteIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, edges_riveDroite[i]) for i in range(len(edges_riveDroite)) ]
393
394 print("edges_litMineurIds", edges_litMineurIds) 
395 print("edges_riveGaucheIds", edges_riveGaucheIds)
396 print("edges_riveDroiteIds", edges_riveDroiteIds)
397
398 sectionsIds = [Id for Id in edges_litMineurIds if Id not in rivesIds]
399 print("sectionsIds", sectionsIds)
400 SectionsGaronne = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"])
401 geompy.UnionIDs(SectionsGaronne, sectionsIds)
402 geompy.addToStudyInFather(HYDRO_garonne_1, SectionsGaronne, "SectionsGaronne")
403
404 bordGaucheDomaineIds = [Id for Id in freeBoundaryIds if Id in edges_riveGaucheIds]
405 bordDroiteDomaineIds = [Id for Id in freeBoundaryIds if Id in edges_riveDroiteIds]
406 print("bordGaucheDomaineIds", bordGaucheDomaineIds)
407 print("bordDroiteDomaineIds", bordDroiteDomaineIds)
408 bordGaucheDomaine = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"])
409 geompy.UnionIDs(bordGaucheDomaine, bordGaucheDomaineIds)
410 geompy.addToStudyInFather(HYDRO_garonne_1, bordGaucheDomaine, "bordGaucheDomaine")
411 bordDroiteDomaine = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"])
412 geompy.UnionIDs(bordDroiteDomaine, bordDroiteDomaineIds)
413 geompy.addToStudyInFather(HYDRO_garonne_1, bordDroiteDomaine, "bordDroiteDomaine")
414
415 amont = geompy.GetEdgeNearPoint(HYDRO_garonne_1, geompy.MakeVertex(46757.861314, 25833.234752, 0))
416 aval = geompy.GetEdgeNearPoint(HYDRO_garonne_1, geompy.MakeVertex(39078.979127, 32588.627279, 0))
417 geompy.addToStudyInFather(HYDRO_garonne_1, amont, "amont")
418 geompy.addToStudyInFather(HYDRO_garonne_1, aval, "aval")
419
420 #----------------------
421 # --- Meshing
422 #----------------------
423
424 import  SMESH, SALOMEDS
425 from salome.smesh import smeshBuilder
426 from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats
427
428 smesh = smeshBuilder.New()
429
430 # --- algorithms and hypothesis
431 garonne_1 = smesh.Mesh(HYDRO_garonne_1)
432
433 NETGEN_2D = garonne_1.Triangle(algo=smeshBuilder.NETGEN_1D2D)
434 NETGEN_2D_Parameters = NETGEN_2D.Parameters()
435 NETGEN_2D_Parameters.SetMaxSize( 200 )
436 NETGEN_2D_Parameters.SetSecondOrder( 0 )
437 NETGEN_2D_Parameters.SetOptimize( 1 )
438 NETGEN_2D_Parameters.SetFineness( 4 )
439 NETGEN_2D_Parameters.SetMinSize( 50 )
440 NETGEN_2D_Parameters.SetUseSurfaceCurvature( 1 )
441 NETGEN_2D_Parameters.SetFuseEdges( 1 )
442 NETGEN_2D_Parameters.SetQuadAllowed( 0 )
443
444 algo2D_litMineur = garonne_1.Quadrangle(algo=smeshBuilder.QUAD_MA_PROJ,geom=garonne_litMineur)
445 algo1D_litMineur = garonne_1.Segment(geom=garonne_litMineur)
446 hypo1D_litMineur = algo1D_litMineur.LocalLength(100,None,1e-07)
447 subMesh_litMineur = algo1D_litMineur.GetSubMesh()
448 smesh.SetName(subMesh_litMineur, "litMineur")
449
450 algo1D_SectionsGaronne = garonne_1.Segment(geom=SectionsGaronne)
451 hypo1D_SectionsGaronne = algo1D_SectionsGaronne.NumberOfSegments(8)
452 hypo1D_SectionsGaronne.SetDistrType( 0 )
453 subMesh_SectionsGaronne = algo1D_SectionsGaronne.GetSubMesh()
454 smesh.SetName(subMesh_SectionsGaronne, "SectionsGaronne")
455
456 isDone = garonne_1.SetMeshOrder( [ [ subMesh_SectionsGaronne, subMesh_litMineur ] ])
457
458 # --- compute mesh
459 isDone = garonne_1.Compute()
460 isDone = garonne_1.SplitQuadObject( garonne_1, 1 )
461 isDone = garonne_1.ReorientObject( garonne_1 )
462
463 # --- geometrical groups of faces
464 riveGauche_1 = garonne_1.GroupOnGeom(garonne_riveGauche,'riveGauche',SMESH.FACE)
465 litMineur_1 = garonne_1.GroupOnGeom(garonne_litMineur,'litMineur',SMESH.FACE)
466 riveDroite_1 = garonne_1.GroupOnGeom(garonne_riveDroite,'riveDroite',SMESH.FACE)
467
468 # --- geometrical groups of edges
469
470 ClosedFreeBoundary_1 = garonne_1.GroupOnGeom(ClosedFreeBoundary[0],'ClosedFreeBoundary',SMESH.EDGE)
471 litMineur_droite_1 = garonne_1.GroupOnGeom(litMineur_droite,'litMineur_droite',SMESH.EDGE)
472 litMineur_gauche_1 = garonne_1.GroupOnGeom(litMineur_gauche,'litMineur_gauche',SMESH.EDGE)
473 SectionsGaronne_1 = garonne_1.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.EDGE)
474 bordGaucheDomaine_1 = garonne_1.GroupOnGeom(bordGaucheDomaine,'bordGaucheDomaine',SMESH.EDGE)
475 bordDroiteDomaine_1 = garonne_1.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.EDGE)
476 amont_1 = garonne_1.GroupOnGeom(amont,'amont',SMESH.EDGE)
477 aval_1 = garonne_1.GroupOnGeom(aval,'aval',SMESH.EDGE)
478
479 # --- geometrical groups of nodes
480
481 garonne_1_litMineur_2 = garonne_1.GroupOnGeom(garonne_litMineur,'garonne_1_litMineur',SMESH.NODE)
482 garonne_1_riveDroite_2 = garonne_1.GroupOnGeom(garonne_riveDroite,'garonne_1_riveDroite',SMESH.NODE)
483 garonne_1_riveGauche_2 = garonne_1.GroupOnGeom(garonne_riveGauche,'garonne_1_riveGauche',SMESH.NODE)
484 ClosedFreeBoundary_2 = garonne_1.GroupOnGeom(ClosedFreeBoundary[0],'ClosedFreeBoundary',SMESH.NODE)
485 litMineur_droite_2 = garonne_1.GroupOnGeom(litMineur_droite,'litMineur_droite',SMESH.NODE)
486 litMineur_gauche_2 = garonne_1.GroupOnGeom(litMineur_gauche,'litMineur_gauche',SMESH.NODE)
487 SectionsGaronne_2 = garonne_1.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.NODE)
488 bordGaucheDomaine_2 = garonne_1.GroupOnGeom(bordGaucheDomaine,'bordGaucheDomaine',SMESH.NODE)
489 bordDroiteDomaine_2 = garonne_1.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.NODE)
490 amont_2 = garonne_1.GroupOnGeom(amont,'amont',SMESH.NODE)
491 aval_2 = garonne_1.GroupOnGeom(aval,'aval',SMESH.NODE)
492
493 garonne_1.SetAutoColor( 1 )
494 fichierMaillage = os.path.join(tmpdir, 'garonne_1.med')
495 garonne_1.ExportMED(fichierMaillage, 0, SMESH.MED_V2_2, 1, None ,1)
496
497 controlMeshStats(garonne_1, 3888, 475, 7597)
498 controlSubMeshStats(litMineur_1, 2384)
499 controlSubMeshStats(riveDroite_1, 2342)
500 controlSubMeshStats(riveGauche_1, 2871)
501
502 if salome.sg.hasDesktop():
503   salome.sg.updateObjBrowser()
504
505 #----------------------
506 # --- Z interpolation with HYDRO
507 #----------------------
508
509 from salome.hydrotools.interpolZ import interpolZ
510 from salome.hydrotools.controls import controlStatZ
511
512 # --- case name in HYDRO
513 nomCas = 'garonne_1'
514
515 # --- med file 2D(x,y) of the case produced by SMESH
516
517 # --- dictionary [med group name] = region name
518 dicoGroupeRegion= dict(litMineur  = 'garonne_1_litMineur',
519                        riveDroite = 'garonne_1_riveDroite',
520                        riveGauche = 'garonne_1_riveGauche',
521                        )
522 # --- value to use for Z when the node is not in a region (used to detect problems)
523 zUndef = 90
524 # --- interpolation Method: 0 = nearest point on bathymetry (default), 1 = linear interpolation
525 interpolMethod = 0
526 # --- produce a 3D mesh (Z set to its value instead of 0
527 m3d = True
528
529 # --- Z interpolation on the bathymety/altimetry on the mesh nodes
530 statz = interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef, interpolMethod, m3d)
531 #print(statz)
532 refstatz = {'riveDroite': (10.88, 32.61, 24.17, 5.12, 17.57, 31.33, 0.25),
533             'riveGauche': (7.72, 71.86, 24.51, 12.18, 12.90, 60.36, 0.25),
534             'litMineur': (2.06, 25.41, 13.93, 4.33, 8.47, 21.78)}
535 controlStatZ(statz, refstatz)
536
537 # --- interpolation on a new bathymetry for 'litMineur'
538
539 newMesh = os.path.splitext(fichierMaillage)[0] + 'F.med'
540 from salome.hydrotools.interpolZ import interpolZ_B
541
542 # --- Z interpolation on the bathymety/altimetry on the mesh nodes
543 statz = interpolZ_B(nomBathy, newMesh, 'litMineur', zUndef, interpolMethod, m3d)
544 print(statz)
545 refstatz = {'litMineur': (52.06, 75.68, 64.44, 4.84, 58.47, 72.73)}
546 controlStatZ(statz, refstatz)
547