From: Paul RASCLE Date: Thu, 20 Aug 2020 16:29:44 +0000 (+0200) Subject: test case h021_meshChangeBathy X-Git-Tag: SH_V2_2_0~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c20dd75009c63c209081f46ba08af2d94bfc7767;p=modules%2Fhydro.git test case h021_meshChangeBathy --- diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index 34960d46..6f165bde 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -40,6 +40,7 @@ SET(EXAMPLES_TESTS h018_streamInterpolation.py h019_normalCaseManualInterpolZStrickler.py h020_normalCaseChangeBathy.py + h021_meshChangeBathy.py ) SET(HYDRO_SAMPLES @@ -47,7 +48,12 @@ SET(HYDRO_SAMPLES garonne_ign_02.png Cloud_02.xyz garonne_point_L93.xyz - garonne_point_L93_50m.xyz + garonne.shp + garonne.shx + domaine.shp + domaine.shx + lit_majeur.shp + lit_majeur.shx condlim.bcd init.cas init.lqd diff --git a/doc/salome/examples/CTestTestfileInstall.cmake b/doc/salome/examples/CTestTestfileInstall.cmake index ff403603..c87ca89b 100644 --- a/doc/salome/examples/CTestTestfileInstall.cmake +++ b/doc/salome/examples/CTestTestfileInstall.cmake @@ -42,6 +42,7 @@ SET(EXAMPLES_TESTS h018_streamInterpolation h019_normalCaseManualInterpolZStrickler h020_normalCaseChangeBathy + h021_meshChangeBathy ) FOREACH(tfile ${EXAMPLES_TESTS}) diff --git a/doc/salome/examples/domaine.shp b/doc/salome/examples/domaine.shp new file mode 100644 index 00000000..68d68355 Binary files /dev/null and b/doc/salome/examples/domaine.shp differ diff --git a/doc/salome/examples/domaine.shx b/doc/salome/examples/domaine.shx new file mode 100644 index 00000000..22089200 Binary files /dev/null and b/doc/salome/examples/domaine.shx differ diff --git a/doc/salome/examples/garonne.shp b/doc/salome/examples/garonne.shp new file mode 100644 index 00000000..b1a307ab Binary files /dev/null and b/doc/salome/examples/garonne.shp differ diff --git a/doc/salome/examples/garonne.shx b/doc/salome/examples/garonne.shx new file mode 100644 index 00000000..c20bd5a1 Binary files /dev/null and b/doc/salome/examples/garonne.shx differ diff --git a/doc/salome/examples/h021_meshChangeBathy.py b/doc/salome/examples/h021_meshChangeBathy.py new file mode 100644 index 00000000..e9213d21 --- /dev/null +++ b/doc/salome/examples/h021_meshChangeBathy.py @@ -0,0 +1,365 @@ +# -*- coding: utf-8 -*- + +import os +HYDRO_SAMPLES = os.path.join( os.environ["HYDRO_ROOT_DIR"], "bin/salome/test/HYDRO") + +import sys +import salome + +salome.salome_init() + +#---------------------- +# --- HYDRO +#---------------------- + +from HYDROPy import * +from PyQt5.QtCore import * +from PyQt5.QtGui import * + +hydro_doc = HYDROData_Document.Document() + +hydro_doc.SetLocalCS( 430000, 6.35e+06 ) + +name = "garonne" +shape = os.path.join(HYDRO_SAMPLES, name+".shp" ) +HYDROData_PolylineXY.ImportShapesFromFile(shape) +garonne = hydro_doc.FindObjectByName(name + '_PolyXY_0') +for i in range(garonne.NbSections()): + garonne.SetSectionType(i, 1) # spline + garonne.Update() +garonne.SetZLevel( 2 ) + +name = "lit_majeur" +shape = os.path.join(HYDRO_SAMPLES, name+".shp" ) +HYDROData_PolylineXY.ImportShapesFromFile(shape) +lit_majeur = hydro_doc.FindObjectByName(name + '_PolyXY_0') +for i in range(lit_majeur.NbSections()): + lit_majeur.SetSectionType(i, 1) # spline + lit_majeur.Update() +lit_majeur.SetZLevel( 3 ) + +name = "domaine" +shape = os.path.join(HYDRO_SAMPLES, name+".shp" ) +HYDROData_PolylineXY.ImportShapesFromFile(shape) +domaine = hydro_doc.FindObjectByName(name + '_PolyXY_0') +for i in range(domaine.NbSections()): + domaine.SetSectionType(i, 0) # polyline + domaine.Update() +domaine.SetZLevel( 4 ) + +Cloud_02 = hydro_doc.CreateObject( KIND_BATHYMETRY ) +Cloud_02.SetName( "Cloud_02" ) + +Cloud_02.SetAltitudesInverted( 0 ) +if not(Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" ))): + raise ValueError('problem while loading bathymetry') + +Cloud_02.Update() + + +garonne_point_L93 = hydro_doc.CreateObject( KIND_BATHYMETRY ) +garonne_point_L93.SetName( "garonne_point_L93" ) + +garonne_point_L93.SetAltitudesInverted( 0 ) +if not(garonne_point_L93.ImportFromFile( os.path.join(HYDRO_SAMPLES, "garonne_point_L93.xyz" ))): + raise ValueError('problem while loading bathymetry') + +garonne_point_L93.Update() + + +litMineur = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE ) +litMineur.SetName( "litMineur" ) + +litMineur.SetZLevel( 6 ) + +litMineur.SetAltitudeObject( garonne_point_L93 ) +litMineur.SetPolyline( garonne ) + +litMineur.Update() + + +litMajeur = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE ) +litMajeur.SetName( "litMajeur" ) + +litMajeur.SetZLevel( 5 ) + +litMajeur.SetFillingColor( QColor( 0, 170, 127, 255 ) ) + +litMajeur.SetAltitudeObject( garonne_point_L93 ) +litMajeur.SetPolyline( lit_majeur ) + +litMajeur.Update() + + +domaineEtendu = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE ) +domaineEtendu.SetName( "domaineEtendu" ) + +domaineEtendu.SetZLevel( 4 ) + +domaineEtendu.SetFillingColor( QColor( 201, 203, 55, 255 ) ) + +domaineEtendu.SetAltitudeObject( Cloud_02 ) +domaineEtendu.SetPolyline( domaine ) + +domaineEtendu.Update() + + +# Calculation case +garonne_1 = hydro_doc.CreateObject( KIND_CALCULATION ) +garonne_1.SetName( "garonne_1" ) + +garonne_1.SetAssignmentMode( HYDROData_CalculationCase.MANUAL ) +garonne_1.AddGeometryObject( litMineur ) +garonne_1.AddGeometryObject( domaineEtendu ) +garonne_1.AddGeometryObject( litMajeur ) + +case_geom_group = domaineEtendu.GetGroup( 0 ) +garonne_1.AddGeometryGroup( case_geom_group ) +case_geom_group = litMineur.GetGroup( 0 ) +garonne_1.AddGeometryGroup( case_geom_group ) +case_geom_group = litMajeur.GetGroup( 0 ) +garonne_1.AddGeometryGroup( case_geom_group ) +garonne_1.SetBoundaryPolyline( domaine ) + +# Start the algorithm of the partition and assignment +garonne_1.Update() +garonne_1_litMineur = hydro_doc.FindObjectByName( "garonne_1_Reg_1" ) +garonne_1_Zone_1 = hydro_doc.FindObjectByName( "garonne_1_Zone_1" ) +garonne_1_Zone_1.SetMergeType( HYDROData_Zone.Merge_ZMIN ) +garonne_1_Zone_1.SetColor( QColor( 192, 113, 64 )) +garonne_1_litMineur.AddZone( garonne_1_Zone_1 ) + +garonne_1_riveDroite = hydro_doc.FindObjectByName( "garonne_1_Reg_2" ) +garonne_1_Zone_2 = hydro_doc.FindObjectByName( "garonne_1_Zone_2" ) +garonne_1_Zone_2.SetColor( QColor( 141, 192, 64 )) +garonne_1_riveDroite.AddZone( garonne_1_Zone_2 ) + +garonne_1_Zone_3 = hydro_doc.FindObjectByName( "garonne_1_Zone_3" ) +garonne_1_Zone_3.SetMergeType( HYDROData_Zone.Merge_Object ) +Cloud_02 = hydro_doc.FindObjectByName( "Cloud_02" ) +garonne_1_Zone_3.SetMergeObject( Cloud_02 ) +garonne_1_Zone_3.SetColor( QColor( 64, 192, 77 )) +garonne_1_riveDroite.AddZone( garonne_1_Zone_3 ) + +garonne_1_riveGauche = hydro_doc.FindObjectByName( "garonne_1_Reg_3" ) +garonne_1_Zone_4 = hydro_doc.FindObjectByName( "garonne_1_Zone_4" ) +garonne_1_Zone_4.SetMergeType( HYDROData_Zone.Merge_Object ) +Cloud_02 = hydro_doc.FindObjectByName( "Cloud_02" ) +garonne_1_Zone_4.SetMergeObject( Cloud_02 ) +garonne_1_Zone_4.SetColor( QColor( 64, 75, 192 )) +garonne_1_riveGauche.AddZone( garonne_1_Zone_4 ) + +garonne_1_Zone_5 = hydro_doc.FindObjectByName( "garonne_1_Zone_5" ) +garonne_1_Zone_5.SetColor( QColor( 64, 192, 77 )) +garonne_1_riveGauche.AddZone( garonne_1_Zone_5 ) + +garonne_1_litMineur.SetName("garonne_1_litMineur") +garonne_1_riveDroite.SetName("garonne_1_riveDroite") +garonne_1_riveGauche.SetName("garonne_1_riveGauche") + +# Export of the calculation case +garonne_1_entry = garonne_1.Export() + +#---------------------- +# --- Geometry +#---------------------- + +# Get geometry shape and print debug information +import GEOM +from salome.geom import geomBuilder +import math +import SALOMEDS +from salome.hydrotools.controls import controlGeomProps + +geompy = geomBuilder.New() + +print("Entry:", garonne_1_entry) +HYDRO_garonne_1 = salome.IDToObject( str( garonne_1_entry ) ) +print("Geom shape:", HYDRO_garonne_1) +print("Geom shape name:", HYDRO_garonne_1.GetName()) + +# --- manual definition: geometrical faces + +[garonne_litMineur,garonne_riveDroite,garonne_riveGauche] = geompy.SubShapeAll(HYDRO_garonne_1, geompy.ShapeType["FACE"]) + +controlGeomProps(geompy, garonne_riveGauche, 29149.36918, 35948828.352061) +controlGeomProps(geompy, garonne_litMineur, 30337.548492, 3488480.304388) +controlGeomProps(geompy, garonne_riveDroite, 32012.343241, 25998769.23615) + +# --- manual identification of all useful edge groups (boundary conditions) + +allEdgesIds = geompy.SubShapeAllIDs(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +print("allEdgesIds", allEdgesIds) + +(isDone, ClosedFreeBoundary, OpenFreeBoundary) = geompy.GetFreeBoundary(HYDRO_garonne_1) +geompy.addToStudyInFather(HYDRO_garonne_1, ClosedFreeBoundary[0], "ClosedFreeBoundary") + +freeBoundary = geompy.ExtractShapes(ClosedFreeBoundary[0], geompy.ShapeType["EDGE"], True) +freeBoundaryIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, freeBoundary[i]) for i in range(len(freeBoundary)) ] +print("freeBoundaryIds", freeBoundaryIds) + +[litMineur_droite] = geompy.GetSharedShapesMulti([garonne_riveDroite, garonne_litMineur], geompy.ShapeType["EDGE"], True) +[litMineur_gauche] = geompy.GetSharedShapesMulti([garonne_riveGauche, garonne_litMineur], geompy.ShapeType["EDGE"], True) +geompy.addToStudyInFather(HYDRO_garonne_1, litMineur_droite, "litMineur_droite") +geompy.addToStudyInFather(HYDRO_garonne_1, litMineur_gauche, "litMineur_gauche") +rives = [litMineur_droite, litMineur_gauche] +rivesIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, rives[i]) for i in range(len(rives)) ] +print("rivesIds", rivesIds) + +edges_litMineur = geompy.GetSharedShapesMulti([HYDRO_garonne_1, garonne_litMineur], geompy.ShapeType["EDGE"], True) +edges_riveGauche = geompy.GetSharedShapesMulti([HYDRO_garonne_1, garonne_riveGauche], geompy.ShapeType["EDGE"], True) +edges_riveDroite = geompy.GetSharedShapesMulti([HYDRO_garonne_1, garonne_riveDroite], geompy.ShapeType["EDGE"], True) +edges_litMineurIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, edges_litMineur[i]) for i in range(len(edges_litMineur)) ] +edges_riveGaucheIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, edges_riveGauche[i]) for i in range(len(edges_riveGauche)) ] +edges_riveDroiteIds = [ geompy.GetSubShapeID(HYDRO_garonne_1, edges_riveDroite[i]) for i in range(len(edges_riveDroite)) ] + +print("edges_litMineurIds", edges_litMineurIds) +print("edges_riveGaucheIds", edges_riveGaucheIds) +print("edges_riveDroiteIds", edges_riveDroiteIds) + +sectionsIds = [Id for Id in edges_litMineurIds if Id not in rivesIds] +print("sectionsIds", sectionsIds) +SectionsGaronne = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(SectionsGaronne, sectionsIds) +geompy.addToStudyInFather(HYDRO_garonne_1, SectionsGaronne, "SectionsGaronne") + +bordGaucheDomaineIds = [Id for Id in freeBoundaryIds if Id in edges_riveGaucheIds] +bordDroiteDomaineIds = [Id for Id in freeBoundaryIds if Id in edges_riveDroiteIds] +print("bordGaucheDomaineIds", bordGaucheDomaineIds) +print("bordDroiteDomaineIds", bordDroiteDomaineIds) +bordGaucheDomaine = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(bordGaucheDomaine, bordGaucheDomaineIds) +geompy.addToStudyInFather(HYDRO_garonne_1, bordGaucheDomaine, "bordGaucheDomaine") +bordDroiteDomaine = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(bordDroiteDomaine, bordDroiteDomaineIds) +geompy.addToStudyInFather(HYDRO_garonne_1, bordDroiteDomaine, "bordDroiteDomaine") + +amont = geompy.GetEdgeNearPoint(HYDRO_garonne_1, geompy.MakeVertex(46757.861314, 25833.234752, 0)) +aval = geompy.GetEdgeNearPoint(HYDRO_garonne_1, geompy.MakeVertex(39078.979127, 32588.627279, 0)) +geompy.addToStudyInFather(HYDRO_garonne_1, amont, "amont") +geompy.addToStudyInFather(HYDRO_garonne_1, aval, "aval") + +#---------------------- +# --- Meshing +#---------------------- + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder +from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats +import tempfile + +smesh = smeshBuilder.New() + +# --- algorithms and hypothesis +garonne_1 = smesh.Mesh(HYDRO_garonne_1) + +NETGEN_2D = garonne_1.Triangle(algo=smeshBuilder.NETGEN_1D2D) +NETGEN_2D_Parameters = NETGEN_2D.Parameters() +NETGEN_2D_Parameters.SetMaxSize( 200 ) +NETGEN_2D_Parameters.SetSecondOrder( 0 ) +NETGEN_2D_Parameters.SetOptimize( 1 ) +NETGEN_2D_Parameters.SetFineness( 4 ) +NETGEN_2D_Parameters.SetMinSize( 50 ) +NETGEN_2D_Parameters.SetUseSurfaceCurvature( 1 ) +NETGEN_2D_Parameters.SetFuseEdges( 1 ) +NETGEN_2D_Parameters.SetQuadAllowed( 0 ) + +algo2D_litMineur = garonne_1.Quadrangle(algo=smeshBuilder.QUAD_MA_PROJ,geom=garonne_litMineur) +algo1D_litMineur = garonne_1.Segment(geom=garonne_litMineur) +hypo1D_litMineur = algo1D_litMineur.LocalLength(100,None,1e-07) +subMesh_litMineur = algo1D_litMineur.GetSubMesh() +smesh.SetName(subMesh_litMineur, "litMineur") + +algo1D_SectionsGaronne = garonne_1.Segment(geom=SectionsGaronne) +hypo1D_SectionsGaronne = algo1D_SectionsGaronne.NumberOfSegments(8) +hypo1D_SectionsGaronne.SetDistrType( 0 ) +subMesh_SectionsGaronne = algo1D_SectionsGaronne.GetSubMesh() +smesh.SetName(subMesh_SectionsGaronne, "SectionsGaronne") + +isDone = garonne_1.SetMeshOrder( [ [ subMesh_SectionsGaronne, subMesh_litMineur ] ]) + +# --- compute mesh +isDone = garonne_1.Compute() +isDone = garonne_1.SplitQuadObject( garonne_1, 1 ) +isDone = garonne_1.ReorientObject( garonne_1 ) + +# --- geometrical groups of faces +riveGauche_1 = garonne_1.GroupOnGeom(garonne_riveGauche,'riveGauche',SMESH.FACE) +litMineur_1 = garonne_1.GroupOnGeom(garonne_litMineur,'litMineur',SMESH.FACE) +riveDroite_1 = garonne_1.GroupOnGeom(garonne_riveDroite,'riveDroite',SMESH.FACE) + +# --- geometrical groups of edges + +ClosedFreeBoundary_1 = garonne_1.GroupOnGeom(ClosedFreeBoundary[0],'ClosedFreeBoundary',SMESH.EDGE) +litMineur_droite_1 = garonne_1.GroupOnGeom(litMineur_droite,'litMineur_droite',SMESH.EDGE) +litMineur_gauche_1 = garonne_1.GroupOnGeom(litMineur_gauche,'litMineur_gauche',SMESH.EDGE) +SectionsGaronne_1 = garonne_1.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.EDGE) +bordGaucheDomaine_1 = garonne_1.GroupOnGeom(bordGaucheDomaine,'bordGaucheDomaine',SMESH.EDGE) +bordDroiteDomaine_1 = garonne_1.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.EDGE) +amont_1 = garonne_1.GroupOnGeom(amont,'amont',SMESH.EDGE) +aval_1 = garonne_1.GroupOnGeom(aval,'aval',SMESH.EDGE) + +# --- geometrical groups of nodes + +garonne_1_litMineur_2 = garonne_1.GroupOnGeom(garonne_litMineur,'garonne_1_litMineur',SMESH.NODE) +garonne_1_riveDroite_2 = garonne_1.GroupOnGeom(garonne_riveDroite,'garonne_1_riveDroite',SMESH.NODE) +garonne_1_riveGauche_2 = garonne_1.GroupOnGeom(garonne_riveGauche,'garonne_1_riveGauche',SMESH.NODE) +ClosedFreeBoundary_2 = garonne_1.GroupOnGeom(ClosedFreeBoundary[0],'ClosedFreeBoundary',SMESH.NODE) +litMineur_droite_2 = garonne_1.GroupOnGeom(litMineur_droite,'litMineur_droite',SMESH.NODE) +litMineur_gauche_2 = garonne_1.GroupOnGeom(litMineur_gauche,'litMineur_gauche',SMESH.NODE) +SectionsGaronne_2 = garonne_1.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.NODE) +bordGaucheDomaine_2 = garonne_1.GroupOnGeom(bordGaucheDomaine,'bordGaucheDomaine',SMESH.NODE) +bordDroiteDomaine_2 = garonne_1.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.NODE) +amont_2 = garonne_1.GroupOnGeom(amont,'amont',SMESH.NODE) +aval_2 = garonne_1.GroupOnGeom(aval,'aval',SMESH.NODE) + +garonne_1.SetAutoColor( 1 ) +tmpdir = tempfile.mkdtemp() +print("tmpdir=",tmpdir) +fichierMaillage = os.path.join(tmpdir, 'garonne_1.med') +garonne_1.ExportMED(fichierMaillage, 0, SMESH.MED_V2_2, 1, None ,1) + +controlMeshStats(garonne_1, 3888, 475, 7597) +controlSubMeshStats(litMineur_1, 2384) +controlSubMeshStats(riveDroite_1, 2342) +controlSubMeshStats(riveGauche_1, 2871) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() + +#---------------------- +# --- Z interpolation with HYDRO +#---------------------- + +from salome.hydrotools.interpolZ import interpolZ +from salome.hydrotools.controls import controlStatZ + +# --- case name in HYDRO +nomCas = 'garonne_1' + +# --- med file 2D(x,y) of the case produced by SMESH + +# --- dictionary [med group name] = region name +dicoGroupeRegion= dict(litMineur = 'garonne_1_litMineur', + riveDroite = 'garonne_1_riveDroite', + riveGauche = 'garonne_1_riveGauche', + ) +# --- value to use for Z when the node is not in a region (used to detect problems) +zUndef = 90 +# --- interpolation Method: 0 = nearest point on bathymetry (default), 1 = linear interpolation +interpolMethod = 0 +# --- produce a 3D mesh (Z set to its value instead of 0 +m3d = True + +# --- Z interpolation on the bathymety/altimetry on the mesh nodes +statz = interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef, interpolMethod, m3d) +#print statz +refstatz = {'riveDroite': (10.88, 32.61, 24.17, 5.12, 17.57, 31.33, 0.25), + 'riveGauche': (7.72, 71.86, 24.51, 12.18, 12.90, 60.36, 0.25), + 'litMineur': (2.06, 25.41, 13.93, 4.33, 8.47, 21.78)} +controlStatZ(statz, refstatz) + +# --- add a field on nodes of type double with z values, named "BOTTOM" +#createZfield2(fichierMaillage) + + diff --git a/doc/salome/examples/lit_majeur.shp b/doc/salome/examples/lit_majeur.shp new file mode 100644 index 00000000..29e75f2b Binary files /dev/null and b/doc/salome/examples/lit_majeur.shp differ diff --git a/doc/salome/examples/lit_majeur.shx b/doc/salome/examples/lit_majeur.shx new file mode 100644 index 00000000..54a91b79 Binary files /dev/null and b/doc/salome/examples/lit_majeur.shx differ