Salome HOME
Corrections of examples path after install with scbi
[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")
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"), False, 4)
56 limites_domaine1  = importPolylines(hydro_doc, os.path.join(tmpdir, "raccord_4_1_adj.shp"), False, 2)
57
58 fitShapePointsToMesh(os.path.join(tmpdir, "garonneAmont_brd_FreeBorders.shp"),
59                      os.path.join(tmpdir, 'raccord_4_1_adj.shp'),
60                      tmpdir, False, False)
61
62
63 # TODO: if limites_amont imported as spline, problem on mesh with 2D triangle algorithm
64 limites_amont = importPolylines(hydro_doc, os.path.join(tmpdir, "garonneAmont_brd_FreeBorders.shp"), False, 5)
65 limites_domaine  = importPolylines(hydro_doc, os.path.join(tmpdir, "raccord_4_1_adj_adj.shp"), False, 2)
66
67 Cloud_02 = importBathymetry(hydro_doc, os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz"))
68
69 junction = createImmersibleZone(hydro_doc, "junction", limites_domaine[0], Cloud_02, True, 0)
70 garonneAval = createImmersibleZone(hydro_doc, "garonneAval", limites_aval[0], Cloud_02, False, 0)
71 garonneAmont = createImmersibleZone(hydro_doc, "garonneAmont", limites_amont[0], Cloud_02, False, 0)
72
73 # Calculation case
74 Junction = hydro_doc.CreateObject( KIND_CALCULATION )
75 Junction.SetName( "Junction" )
76
77 Junction.SetAssignmentMode( HYDROData_CalculationCase.MANUAL )
78 Junction.AddGeometryObject( garonneAmont )
79 Junction.AddGeometryObject( garonneAval )
80 Junction.AddGeometryObject( junction )
81
82 case_geom_group = garonneAmont.GetGroup( 0 )
83 Junction.AddGeometryGroup( case_geom_group )
84 case_geom_group = junction.GetGroup( 0 )
85 Junction.AddGeometryGroup( case_geom_group )
86 case_geom_group = garonneAval.GetGroup( 0 )
87 Junction.AddGeometryGroup( case_geom_group )
88
89 Junction.SetBoundaryPolyline( limites_domaine[0] )
90
91 # Start the algorithm of the partition and assignment
92 Junction.Update()
93 Junction_Reg_1 = hydro_doc.FindObjectByName( "Junction_Reg_1" )
94 Junction_Zone_1 = hydro_doc.FindObjectByName( "Junction_Zone_1" )
95 Junction_Zone_1.SetMergeType( HYDROData_Zone.Merge_ZMAX )
96 Junction_Zone_1.SetColor( QColor( 228, 111, 28 ))
97 Junction_Reg_1.AddZone( Junction_Zone_1 )
98 Junction_Reg_2 = hydro_doc.FindObjectByName( "Junction_Reg_2" )
99 Junction_Zone_2 = hydro_doc.FindObjectByName( "Junction_Zone_2" )
100 Junction_Zone_2.SetMergeType( HYDROData_Zone.Merge_ZMAX )
101 Junction_Zone_2.SetColor( QColor( 185, 228, 28 ))
102 Junction_Reg_2.AddZone( Junction_Zone_2 )
103 Junction_Reg_3 = hydro_doc.FindObjectByName( "Junction_Reg_3" )
104 Junction_Zone_3 = hydro_doc.FindObjectByName( "Junction_Zone_3" )
105 Junction_Zone_3.SetColor( QColor( 28, 228, 111 ))
106 Junction_Reg_3.AddZone( Junction_Zone_3 )
107 Junction_Reg_1.SetName( "Junction_Reg_1" )
108 Junction_Reg_2.SetName( "Junction_Reg_2" )
109 Junction_Reg_3.SetName( "Junction_Reg_3" )
110
111 # Export of the calculation case
112 Junction_entry = Junction.Export()
113
114 ##----------------------
115 ## --- Geometry
116 ##----------------------
117
118 import GEOM
119 from salome.geom import geomBuilder
120 import math
121 import SALOMEDS
122
123 from salome.hydrotools.hydroGeoMeshUtils import getChildrenInStudy
124
125 geompy = geomBuilder.New()
126
127 print ("Entry:", Junction_entry)
128 HYDRO_Junction = salome.IDToObject( str( Junction_entry ) )
129 print ("Geom shape:", HYDRO_Junction)
130 print ("Geom shape name:", HYDRO_Junction.GetName())
131
132 [reg_Junction] = geompy.SubShapeAll(HYDRO_Junction, geompy.ShapeType["FACE"])
133
134 children = getChildrenInStudy(HYDRO_Junction)
135 Junction_garonneAmont_Outer = children['Junction_garonneAmont_Outer']
136 Junction_garonneAval_Outer = children['Junction_garonneAval_Outer']
137
138 if salome.sg.hasDesktop():
139   salome.sg.updateObjBrowser()
140
141 #----------------------
142 #--- Meshing
143 #----------------------
144
145 import  SMESH, SALOMEDS
146 from salome.smesh import smeshBuilder
147 from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats
148
149 smesh = smeshBuilder.New()
150
151 #--- algorithms and hypothesis
152 meshJunction = smesh.Mesh(HYDRO_Junction)
153
154 NETGEN_2D = meshJunction.Triangle(algo=smeshBuilder.NETGEN_1D2D)
155 NETGEN_2D_Parameters = NETGEN_2D.Parameters()
156 NETGEN_2D_Parameters.SetMaxSize( 200 )
157 NETGEN_2D_Parameters.SetSecondOrder( 0 )
158 NETGEN_2D_Parameters.SetOptimize( 1 )
159 NETGEN_2D_Parameters.SetFineness( 4 )
160 NETGEN_2D_Parameters.SetMinSize( 5 )
161 NETGEN_2D_Parameters.SetUseSurfaceCurvature( 1 )
162 NETGEN_2D_Parameters.SetFuseEdges( 1 )
163 NETGEN_2D_Parameters.SetQuadAllowed( 0 )
164
165 ([origMeshAvalBrd], status) = smesh.CreateMeshesFromMED(fileMeshAvalBrd)
166 FreeBordersAval = origMeshAvalBrd.GetGroupByName("FreeBorders")
167 Import_1Daval = meshJunction.UseExisting1DElements(geom=Junction_garonneAval_Outer)
168 Source_Edges_1 = Import_1Daval.SourceEdges( FreeBordersAval ,1,1)
169
170 ([origMeshAmontBrd], status) = smesh.CreateMeshesFromMED(fileMeshAmontBrd)
171 FreeBordersAmont = origMeshAmontBrd.GetGroupByName("FreeBorders")
172 Import_1Damont = meshJunction.UseExisting1DElements(geom=Junction_garonneAmont_Outer)
173 Source_Edges_2 = Import_1Damont.SourceEdges( FreeBordersAmont ,1,1)
174
175 isDone = meshJunction.Compute()
176
177 controlMeshStats(meshJunction, 7420, 918, 14525)
178
179 if salome.sg.hasDesktop():
180   salome.sg.updateObjBrowser()