1 # -*- coding: utf-8 -*-
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")
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"), False, 4)
56 limites_domaine1 = importPolylines(hydro_doc, os.path.join(tmpdir, "raccord_4_1_adj.shp"), False, 2)
58 fitShapePointsToMesh(os.path.join(tmpdir, "garonneAmont_brd_FreeBorders.shp"),
59 os.path.join(tmpdir, 'raccord_4_1_adj.shp'),
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)
67 Cloud_02 = importBathymetry(hydro_doc, os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz"))
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)
74 Junction = hydro_doc.CreateObject( KIND_CALCULATION )
75 Junction.SetName( "Junction" )
77 Junction.SetAssignmentMode( HYDROData_CalculationCase.MANUAL )
78 Junction.AddGeometryObject( garonneAmont )
79 Junction.AddGeometryObject( garonneAval )
80 Junction.AddGeometryObject( junction )
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 )
89 Junction.SetBoundaryPolyline( limites_domaine[0] )
91 # Start the algorithm of the partition and assignment
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" )
111 # Export of the calculation case
112 Junction_entry = Junction.Export()
114 ##----------------------
116 ##----------------------
119 from salome.geom import geomBuilder
123 from salome.hydrotools.hydroGeoMeshUtils import getChildrenInStudy
125 geompy = geomBuilder.New()
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())
132 [reg_Junction] = geompy.SubShapeAll(HYDRO_Junction, geompy.ShapeType["FACE"])
134 children = getChildrenInStudy(HYDRO_Junction)
135 Junction_garonneAmont_Outer = children['Junction_garonneAmont_Outer']
136 Junction_garonneAval_Outer = children['Junction_garonneAval_Outer']
138 if salome.sg.hasDesktop():
139 salome.sg.updateObjBrowser()
141 #----------------------
143 #----------------------
145 import SMESH, SALOMEDS
146 from salome.smesh import smeshBuilder
147 from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats
149 smesh = smeshBuilder.New()
151 #--- algorithms and hypothesis
152 meshJunction = smesh.Mesh(HYDRO_Junction)
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 )
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)
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)
175 isDone = meshJunction.Compute()
177 controlMeshStats(meshJunction, 7420, 918, 14525)
179 if salome.sg.hasDesktop():
180 salome.sg.updateObjBrowser()