1 # -*- coding: utf-8 -*-
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")
8 tmpdir = tempfile.mkdtemp()
9 print("tmpdir=",tmpdir)
11 # --- generated resources
13 origFileMeshAval = os.path.join(HYDRO_TEST_RESOURCES, 'garonne_2.med')
14 origFileMeshAmont = os.path.join(HYDRO_TEST_RESOURCES, 'garonneAmont.med')
16 # ----------------------------------------------------------------------------------
17 # --- domain extension
24 from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups, fitShapePointsToMesh
29 ficMeshOutAval = os.path.join(tmpdir, "garonneAval_brd.med")
30 fileMeshAvalBrd = freeBordersGroup(origFileMeshAval, ficMeshOutAval)
31 exploreEdgeGroups(fileMeshAvalBrd, "", offsetX, offsetY)
33 ficMeshOutAmont = os.path.join(tmpdir, "garonneAmont_brd.med")
34 fileMeshAmontBrd = freeBordersGroup(origFileMeshAmont, ficMeshOutAmont)
35 exploreEdgeGroups(fileMeshAmontBrd, "", offsetX, offsetY)
37 #----------------------
39 #----------------------
42 from PyQt5.QtCore import *
43 from PyQt5.QtGui import *
45 from salome.hydrotools.hydroGeoMeshUtils import importPolylines, importBathymetry, createImmersibleZone, mergePolylines, getChildrenInStudy
47 hydro_doc = HYDROData_Document.Document()
48 hydro_doc.SetLocalCS( offsetX, offsetY )
50 fitShapePointsToMesh(os.path.join(tmpdir, "garonneAval_brd_FreeBorders.shp"),
51 os.path.join(HYDRO_SAMPLES, 'raccord_4_1.shp'),
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)
59 fitShapePointsToMesh(os.path.join(tmpdir, "garonneAmont_brd_FreeBorders.shp"),
60 os.path.join(tmpdir, 'raccord_4_1_adj.shp'),
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)
69 Cloud_02 = importBathymetry(hydro_doc, "Cloud_02", HYDRO_SAMPLES)
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)
76 Junction = hydro_doc.CreateObject( KIND_CALCULATION )
77 Junction.SetName( "Junction" )
79 Junction.SetAssignmentMode( HYDROData_CalculationCase.MANUAL )
80 Junction.AddGeometryObject( garonneAmont )
81 Junction.AddGeometryObject( garonneAval )
82 Junction.AddGeometryObject( junction )
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 )
91 Junction.SetBoundaryPolyline( limites_domaine[0] )
93 # Start the algorithm of the partition and assignment
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" )
113 # Export of the calculation case
114 Junction_entry = Junction.Export()
116 ##----------------------
118 ##----------------------
121 from salome.geom import geomBuilder
125 from salome.hydrotools.hydroGeoMeshUtils import getChildrenInStudy
127 geompy = geomBuilder.New()
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())
134 [reg_Junction] = geompy.SubShapeAll(HYDRO_Junction, geompy.ShapeType["FACE"])
136 children = getChildrenInStudy(HYDRO_Junction)
137 Junction_garonneAmont_Outer = children['Junction_garonneAmont_Outer']
138 Junction_garonneAval_Outer = children['Junction_garonneAval_Outer']
140 if salome.sg.hasDesktop():
141 salome.sg.updateObjBrowser()
143 #----------------------
145 #----------------------
147 import SMESH, SALOMEDS
148 from salome.smesh import smeshBuilder
149 from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats
151 smesh = smeshBuilder.New()
153 #--- algorithms and hypothesis
154 meshJunction = smesh.Mesh(HYDRO_Junction)
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 )
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)
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)
177 isDone = meshJunction.Compute()
179 controlMeshStats(meshJunction, 7420, 918, 14525)
181 if salome.sg.hasDesktop():
182 salome.sg.updateObjBrowser()