From ddc8b027120ad163e63fd1a6b9828aeec3aff79b Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Wed, 26 Aug 2020 11:40:29 +0200 Subject: [PATCH] introducing test on mesh extension, with resources generated first --- doc/salome/examples/CMakeLists.txt | 2 + .../examples/CTestTestfileInstall.cmake | 2 + .../examples/g022_extensionSimpleComplete.py | 379 ++++++++++++++++++ .../examples/h022_extensionSimpleComplete.py | 176 ++++++++ src/HYDROTools/CMakeLists.txt | 3 +- src/HYDROTools/hydroGeoMeshUtils.py | 22 + 6 files changed, 583 insertions(+), 1 deletion(-) create mode 100644 doc/salome/examples/g022_extensionSimpleComplete.py create mode 100644 doc/salome/examples/h022_extensionSimpleComplete.py create mode 100644 src/HYDROTools/hydroGeoMeshUtils.py diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index 7c4d3ad7..abf31765 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -41,6 +41,8 @@ SET(EXAMPLES_TESTS h019_normalCaseManualInterpolZStrickler.py h020_normalCaseChangeBathy.py h021_meshChangeBathy.py + g022_extensionSimpleComplete.py + h022_extensionSimpleComplete.py ) SET(HYDRO_SAMPLES diff --git a/doc/salome/examples/CTestTestfileInstall.cmake b/doc/salome/examples/CTestTestfileInstall.cmake index c87ca89b..0173e760 100644 --- a/doc/salome/examples/CTestTestfileInstall.cmake +++ b/doc/salome/examples/CTestTestfileInstall.cmake @@ -43,6 +43,8 @@ SET(EXAMPLES_TESTS h019_normalCaseManualInterpolZStrickler h020_normalCaseChangeBathy h021_meshChangeBathy + g022_extensionSimpleComplete + h022_extensionSimpleComplete ) FOREACH(tfile ${EXAMPLES_TESTS}) diff --git a/doc/salome/examples/g022_extensionSimpleComplete.py b/doc/salome/examples/g022_extensionSimpleComplete.py new file mode 100644 index 00000000..6598ee50 --- /dev/null +++ b/doc/salome/examples/g022_extensionSimpleComplete.py @@ -0,0 +1,379 @@ +# -*- coding: utf-8 -*- + +import os +HYDRO_SAMPLES = os.path.join( os.environ["HYDRO_ROOT_DIR"], "bin/salome/test/HYDRO") +HYDRO_TEST_RESOURCES = "/home/paul/testsHydro" #os.environ("HYDRO_TEST_RESOURCES") +if not os.path.isdir(HYDRO_TEST_RESOURCES): + os.mkdir(HYDRO_TEST_RESOURCES) + +import tempfile +tmpdir = tempfile.mkdtemp() +print("tmpdir=",tmpdir) + +import sys +import salome + +salome.salome_init() + +#---------------------- +# --- HYDRO +#---------------------- + +from HYDROPy import * +from PyQt5.QtCore import * +from PyQt5.QtGui import * + +hydro_doc = HYDROData_Document.Document() + +offsetX = 430000. +offsetY = 6350000. +hydro_doc.SetLocalCS( offsetX, offsetY ) + +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 = "ile" +shape = os.path.join(HYDRO_SAMPLES, name+".shp" ) +HYDROData_PolylineXY.ImportShapesFromFile(shape) +ile = hydro_doc.FindObjectByName(name + '_PolyXY_0') +for i in range(ile.NbSections()): + ile.SetSectionType(i, 1) # spline + ile.Update() +ile.SetZLevel( 4 ) + +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( 5 ) + +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() + +ilot = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE ) +ilot.SetName( "ilot" ) + +ilot.SetZLevel( 9 ) + +ilot.SetPolyline( ile ) +ilot.SetIsSubmersible(False) + +ilot.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 ) +garonne_1.AddGeometryObject( ilot ) + +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_ile = hydro_doc.FindObjectByName( "garonne_1_Reg_4" ) +garonne_1_Zone_6 = hydro_doc.FindObjectByName( "garonne_1_Zone_6" ) +garonne_1_Zone_6.SetMergeType( HYDROData_Zone.Merge_ZMAX ) +garonne_1_Zone_6.SetColor( QColor( 228, 145, 28 )) +garonne_1_ile.AddZone( garonne_1_Zone_6 ) + +garonne_1_litMineur.SetName("garonne_1_litMineur") +garonne_1_riveDroite.SetName("garonne_1_riveDroite") +garonne_1_riveGauche.SetName("garonne_1_riveGauche") +garonne_1_ile.SetName( "garonne_1_ile" ) + +# Export of the calculation case +garonne_1_entry = garonne_1.Export() + +# --- add a new bathymetry for the test changeBathy + +newBathy = os.path.join(tmpdir, 'newBathy.xyz') +fi=open(os.path.join(HYDRO_SAMPLES, "garonne_point_L93.xyz" ), 'r') +fo=open(newBathy, 'w') +for ligne in fi: + vals = ligne.split() + if len(vals) < 3: + continue + x = float(vals[0]) + y = float(vals[1]) + z = float(vals[2]) + 50 + l = "%12.3f %12.3f %12.3f\n" % (x, y, z) + fo.write(l) +fi.close() +fo.close() + +#---------------------- +# --- 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, 33378.8047, 34595667.2876) +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 ) +fichierMaillage = os.path.join(HYDRO_TEST_RESOURCES, 'garonne_1.med') +garonne_1.ExportMED(fichierMaillage, 0, SMESH.MED_V2_2, 1, None ,1) + +controlMeshStats(garonne_1, 3952, 512, 7690) +controlSubMeshStats(litMineur_1, 2384) +controlSubMeshStats(riveDroite_1, 2321) +controlSubMeshStats(riveGauche_1, 2985) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() + diff --git a/doc/salome/examples/h022_extensionSimpleComplete.py b/doc/salome/examples/h022_extensionSimpleComplete.py new file mode 100644 index 00000000..ec543f49 --- /dev/null +++ b/doc/salome/examples/h022_extensionSimpleComplete.py @@ -0,0 +1,176 @@ +# -*- coding: utf-8 -*- + +import os +HYDRO_SAMPLES = os.path.join( os.environ["HYDRO_ROOT_DIR"], "bin/salome/test/HYDRO") +HYDRO_TEST_RESOURCES = "/home/paul/testsHydro" #os.environ("HYDRO_TEST_RESOURCES") + +import tempfile +tmpdir = tempfile.mkdtemp() +print("tmpdir=",tmpdir) + +# --- generated resources + +origFileMesh = os.path.join(HYDRO_TEST_RESOURCES, 'garonne_1.med') + +# ---------------------------------------------------------------------------------- +# --- domain extension + +import sys +import salome + +salome.salome_init() + +from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups, fitShapePointsToMesh + +offsetX = 430000. +offsetY = 6350000. + +ficMeshOut = os.path.join(tmpdir, "garonne_1_brd.med") +fileMeshBrd = freeBordersGroup(origFileMesh, ficMeshOut) +exploreEdgeGroups(fileMeshBrd, "", offsetX, offsetY) + +#---------------------- +# --- HYDRO +#---------------------- + +from HYDROPy import * +from PyQt5.QtCore import * +from PyQt5.QtGui import * + +hydro_doc = HYDROData_Document.Document() +hydro_doc.SetLocalCS( offsetX, offsetY ) + +name = "garonne_1_brd_FreeBorders" +shape = os.path.join(tmpdir, name+".shp" ) +HYDROData_PolylineXY.ImportShapesFromFile(shape) +limite_original = hydro_doc.FindObjectByName(name + '_0') +for i in range(limite_original.NbSections()): + limite_original.SetSectionType(i, 1) # spline + limite_original.Update() +limite_original.SetZLevel( 4 ) + +name = "extension_1_1" +shape = os.path.join(HYDRO_SAMPLES, name+".shp" ) +HYDROData_PolylineXY.ImportShapesFromFile(shape) +limite_domaine = hydro_doc.FindObjectByName(name + '_PolyXY_0') +for i in range(limite_domaine.NbSections()): + limite_domaine.SetSectionType(i, 0) # polyline + limite_domaine.Update() +limite_domaine.SetZLevel( 2 ) + +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() + + +domaine_original = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE ) +domaine_original.SetName( "domaine_original" ) +domaine_original.SetZLevel( 1 ) +domaine_original.SetAltitudeObject( Cloud_02 ) +domaine_original.SetPolyline( limite_original ) +domaine_original.SetIsSubmersible(False) +domaine_original.Update() + +domaine_englobant = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE ) +domaine_englobant.SetName( "domaine_englobant" ) +domaine_englobant.SetZLevel( 0 ) +domaine_englobant.SetAltitudeObject( Cloud_02 ) +domaine_englobant.SetPolyline( limite_domaine ) +domaine_englobant.Update() + +# Calculation case +extension = hydro_doc.CreateObject( KIND_CALCULATION ) +extension.SetName( "extension" ) + +extension.SetAssignmentMode( HYDROData_CalculationCase.MANUAL ) +extension.AddGeometryObject( domaine_englobant ) +extension.AddGeometryObject( domaine_original ) + +case_geom_group = domaine_englobant.GetGroup( 0 ) +extension.AddGeometryGroup( case_geom_group ) +case_geom_group = domaine_original.GetGroup( 0 ) +extension.AddGeometryGroup( case_geom_group ) + +extension.SetBoundaryPolyline( limite_domaine ) + +# Start the algorithm of the partition and assignment +extension.Update() +reg_extension = hydro_doc.FindObjectByName( "extension_Reg_1" ) +extension_Zone_1 = hydro_doc.FindObjectByName( "extension_Zone_1" ) +extension_Zone_1.SetColor( QColor( 28, 168, 228 )) +reg_extension.AddZone( extension_Zone_1 ) +reg_original = hydro_doc.FindObjectByName( "extension_Reg_2" ) +extension_Zone_2 = hydro_doc.FindObjectByName( "extension_Zone_2" ) +extension_Zone_2.SetMergeType( HYDROData_Zone.Merge_Object ) +Cloud_02 = hydro_doc.FindObjectByName( "Cloud_02" ) +extension_Zone_2.SetMergeObject( Cloud_02 ) +extension_Zone_2.SetColor( QColor( 28, 51, 228 )) +reg_original.AddZone( extension_Zone_2 ) +reg_extension.SetName( "reg_extension" ) +reg_original.SetName( "reg_original" ) + +# Export of the calculation case +extension_entry = extension.Export() + +##---------------------- +## --- Geometry +##---------------------- + +import GEOM +from salome.geom import geomBuilder +import math +import SALOMEDS + +from salome.hydrotools.hydroGeoMeshUtils import getChildrenInStudy + +geompy = geomBuilder.New() + +print ("Entry:", extension_entry) +HYDRO_extension = salome.IDToObject( str( extension_entry ) ) +print ("Geom shape:", HYDRO_extension) +print ("Geom shape name:", HYDRO_extension.GetName()) + +[reg_extension] = geompy.SubShapeAll(HYDRO_extension, geompy.ShapeType["FACE"]) +children = getChildrenInStudy(HYDRO_extension) +extension_domaine_original_Outer = children["extension_domaine_original_Outer"] + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() + +#---------------------- +#--- Meshing +#---------------------- + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder +from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats + +smesh = smeshBuilder.New() + +#--- algorithms and hypothesis +extensionEnglobante = smesh.Mesh(HYDRO_extension) + +NETGEN_2D = extensionEnglobante.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( 5 ) +NETGEN_2D_Parameters.SetUseSurfaceCurvature( 1 ) +NETGEN_2D_Parameters.SetFuseEdges( 1 ) +NETGEN_2D_Parameters.SetQuadAllowed( 0 ) + +([origMeshBrd], status) = smesh.CreateMeshesFromMED(fileMeshBrd) +FreeBorders = origMeshBrd.GetGroupByName("FreeBorders") + +Import_1D = extensionEnglobante.UseExisting1DElements(geom=extension_domaine_original_Outer) +Source_Edges_1 = Import_1D.SourceEdges( FreeBorders ,1,1) + +isDone = extensionEnglobante.Compute() + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() diff --git a/src/HYDROTools/CMakeLists.txt b/src/HYDROTools/CMakeLists.txt index 49232045..551b8322 100644 --- a/src/HYDROTools/CMakeLists.txt +++ b/src/HYDROTools/CMakeLists.txt @@ -28,6 +28,7 @@ SET(PYFILES cutMesh.py changeCoords.py changeBathy.py + hydroGeoMeshUtils.py ) # --- plugins dialogs @@ -38,7 +39,7 @@ ADD_SUBDIRECTORY(testPlugin) # --- plugin scripts / static SET(plugin_SCRIPTS - hydro_plugins.py + hydro_plugins.py ) # --- rules --- diff --git a/src/HYDROTools/hydroGeoMeshUtils.py b/src/HYDROTools/hydroGeoMeshUtils.py new file mode 100644 index 00000000..ec96c526 --- /dev/null +++ b/src/HYDROTools/hydroGeoMeshUtils.py @@ -0,0 +1,22 @@ +import sys +import salome + +salome.salome_init() + +def getChildrenInStudy(obj): + """ + Given an object published in SALOME study (for instance a GEOM object), retreive its children. + return a dictionary [name] --> object + """ + SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR(obj)) + childIterator = salome.myStudy.NewChildIterator(SO) + children = {} + while childIterator.More(): + childItem = childIterator.Value() + print("item", childItem) + itemName = childItem.GetName() + itemID = childItem.GetID() + itemObj = salome.IDToObject(str(itemID)) + children[itemName] = itemObj + childIterator.Next() + return children -- 2.39.2