From: Paul RASCLE Date: Sat, 29 Aug 2020 09:03:01 +0000 (+0200) Subject: resource for tests on fusion of several domains X-Git-Tag: SH_V2_2_0~64 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=330c29a11c4e9f9854d257547b207b7a4272d0f2;p=modules%2Fhydro.git resource for tests on fusion of several domains --- diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index 1161336c..aa67e424 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -47,6 +47,7 @@ SET(EXAMPLES_TESTS h024_extensionSimpleAval.py h025_extensionSimpleRiveDroite.py h026_extensionSimpleRiveGauche.py + g027_domaineAmont.py ) SET(HYDRO_SAMPLES diff --git a/doc/salome/examples/CTestTestfileInstall.cmake b/doc/salome/examples/CTestTestfileInstall.cmake index 3ee6b4d8..31e80f3e 100644 --- a/doc/salome/examples/CTestTestfileInstall.cmake +++ b/doc/salome/examples/CTestTestfileInstall.cmake @@ -49,6 +49,7 @@ SET(EXAMPLES_TESTS h024_extensionSimpleAval h025_extensionSimpleRiveDroite h026_extensionSimpleRiveGauche + g027_domaineAmont ) FOREACH(tfile ${EXAMPLES_TESTS}) diff --git a/doc/salome/examples/g027_domaineAmont.py b/doc/salome/examples/g027_domaineAmont.py new file mode 100644 index 00000000..357dbbda --- /dev/null +++ b/doc/salome/examples/g027_domaineAmont.py @@ -0,0 +1,248 @@ +# -*- 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 * + +from salome.hydrotools.hydroGeoMeshUtils import importPolylines, importBathymetry, createImmersibleZone, mergePolylines, getChildrenInStudy + +hydro_doc = HYDROData_Document.Document() + +offsetX = 430000. +offsetY = 6350000. +hydro_doc.SetLocalCS( offsetX, offsetY ) + +limites_amont = importPolylines(hydro_doc, os.path.join(HYDRO_SAMPLES, "domaineAmont.shp"), "domaineAmont_PolyXY", False, 4) +garonnes_amont = importPolylines(hydro_doc, os.path.join(HYDRO_SAMPLES, "garonneAmont.shp"), "garonneAmont_PolyXY", True, 3) + +Cloud_02 = importBathymetry(hydro_doc, "Cloud_02", HYDRO_SAMPLES) +garonne_point_L93 = importBathymetry(hydro_doc, "garonne_point_L93", HYDRO_SAMPLES) + +domaine_amont = createImmersibleZone(hydro_doc, "domaine_amont", limites_amont[0], Cloud_02, True, 0) +garonne_amont = createImmersibleZone(hydro_doc, "garonne_amont", garonnes_amont[0], garonne_point_L93, True, 0) + +# Calculation case +domaineAmont = hydro_doc.CreateObject( KIND_CALCULATION ) +domaineAmont.SetName( "domaineAmont" ) + +domaineAmont.SetAssignmentMode( HYDROData_CalculationCase.MANUAL ) +domaineAmont.AddGeometryObject( domaine_amont ) +domaineAmont.AddGeometryObject( garonne_amont ) + +case_geom_group = domaine_amont.GetGroup( 0 ) +domaineAmont.AddGeometryGroup( case_geom_group ) +case_geom_group = garonne_amont.GetGroup( 0 ) +domaineAmont.AddGeometryGroup( case_geom_group ) + +domaineAmont.SetBoundaryPolyline( limites_amont[0] ) + +# Start the algorithm of the partition and assignment +domaineAmont.Update() +domaineAmont_RiveGauche = hydro_doc.FindObjectByName( "domaineAmont_Reg_1" ) +domaineAmont_Zone_1 = hydro_doc.FindObjectByName( "domaineAmont_Zone_1" ) +domaineAmont_Zone_1.SetColor( QColor( 28, 205, 228 )) +domaineAmont_RiveGauche.AddZone( domaineAmont_Zone_1 ) +domaineAmont_LitMineur = hydro_doc.FindObjectByName( "domaineAmont_Reg_2" ) +domaineAmont_Zone_2 = hydro_doc.FindObjectByName( "domaineAmont_Zone_2" ) +domaineAmont_Zone_2.SetMergeType( HYDROData_Zone.Merge_ZMIN ) +domaineAmont_Zone_2.SetColor( QColor( 228, 205, 28 )) +domaineAmont_LitMineur.AddZone( domaineAmont_Zone_2 ) +domaineAmont_RiveDroite = hydro_doc.FindObjectByName( "domaineAmont_Reg_3" ) +domaineAmont_Zone_3 = hydro_doc.FindObjectByName( "domaineAmont_Zone_3" ) +domaineAmont_Zone_3.SetColor( QColor( 118, 228, 28 )) +domaineAmont_RiveDroite.AddZone( domaineAmont_Zone_3 ) +domaineAmont_RiveGauche.SetName( "domaineAmont_RiveGauche" ) +domaineAmont_LitMineur.SetName( "domaineAmont_LitMineur" ) +domaineAmont_RiveDroite.SetName( "domaineAmont_RiveDroite" ) + +# Export of the calculation case +domaineAmont_entry = domaineAmont.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:", domaineAmont_entry) +HYDRO_domaineAmont = salome.IDToObject( str( domaineAmont_entry ) ) +print ("Geom shape:", HYDRO_domaineAmont) +print ("Geom shape name:", HYDRO_domaineAmont.GetName()) + +# --- manual definition: geometrical faces + +children = getChildrenInStudy(HYDRO_domaineAmont) +garonne_riveGauche = children["domaineAmont_RiveGauche"] +garonne_litMineur = children["domaineAmont_LitMineur"] +garonne_riveDroite = children["domaineAmont_RiveDroite"] +#[garonne_riveGauche, garonne_litMineur, garonne_riveDroite] = geompy.SubShapeAll(HYDRO_domaineAmont, geompy.ShapeType["FACE"]) + +controlGeomProps(geompy, garonne_riveGauche, 23924.943383, 19616095.293123) +controlGeomProps(geompy, garonne_litMineur, 21161.868589, 2453082.699997) +controlGeomProps(geompy, garonne_riveDroite, 21871.837974, 25319246.863937) + +# --- manual identification of all useful edge groups (boundary conditions) + +allEdgesIds = geompy.SubShapeAllIDs(HYDRO_domaineAmont, geompy.ShapeType["EDGE"]) +print("allEdgesIds", allEdgesIds) + +(isDone, ClosedFreeBoundary, OpenFreeBoundary) = geompy.GetFreeBoundary(HYDRO_domaineAmont) +geompy.addToStudyInFather(HYDRO_domaineAmont, ClosedFreeBoundary[0], "ClosedFreeBoundary") + +freeBoundary = geompy.ExtractShapes(ClosedFreeBoundary[0], geompy.ShapeType["EDGE"], True) +freeBoundaryIds = [ geompy.GetSubShapeID(HYDRO_domaineAmont, 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_domaineAmont, litMineur_droite, "litMineur_droite") +geompy.addToStudyInFather(HYDRO_domaineAmont, litMineur_gauche, "litMineur_gauche") +rives = [litMineur_droite, litMineur_gauche] +rivesIds = [ geompy.GetSubShapeID(HYDRO_domaineAmont, rives[i]) for i in range(len(rives)) ] +print("rivesIds", rivesIds) + +edges_litMineur = geompy.GetSharedShapesMulti([HYDRO_domaineAmont, garonne_litMineur], geompy.ShapeType["EDGE"], True) +edges_riveGauche = geompy.GetSharedShapesMulti([HYDRO_domaineAmont, garonne_riveGauche], geompy.ShapeType["EDGE"], True) +edges_riveDroite = geompy.GetSharedShapesMulti([HYDRO_domaineAmont, garonne_riveDroite], geompy.ShapeType["EDGE"], True) +edges_litMineurIds = [ geompy.GetSubShapeID(HYDRO_domaineAmont, edges_litMineur[i]) for i in range(len(edges_litMineur)) ] +edges_riveGaucheIds = [ geompy.GetSubShapeID(HYDRO_domaineAmont, edges_riveGauche[i]) for i in range(len(edges_riveGauche)) ] +edges_riveDroiteIds = [ geompy.GetSubShapeID(HYDRO_domaineAmont, 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_domaineAmont, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(SectionsGaronne, sectionsIds) +geompy.addToStudyInFather(HYDRO_domaineAmont, 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_domaineAmont, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(bordGaucheDomaine, bordGaucheDomaineIds) +geompy.addToStudyInFather(HYDRO_domaineAmont, bordGaucheDomaine, "bordGaucheDomaine") +bordDroiteDomaine = geompy.CreateGroup(HYDRO_domaineAmont, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(bordDroiteDomaine, bordDroiteDomaineIds) +geompy.addToStudyInFather(HYDRO_domaineAmont, bordDroiteDomaine, "bordDroiteDomaine") + +amont = geompy.GetEdgeNearPoint(HYDRO_domaineAmont, geompy.MakeVertex(54062.101935, 20486.776236, 0)) +aval = geompy.GetEdgeNearPoint(HYDRO_domaineAmont, geompy.MakeVertex(47800.17745, 25211,491804, 0)) +geompy.addToStudyInFather(HYDRO_domaineAmont, amont, "amont") +geompy.addToStudyInFather(HYDRO_domaineAmont, 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 +garonneAmont = smesh.Mesh(HYDRO_domaineAmont) + +NETGEN_2D = garonneAmont.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 = garonneAmont.Quadrangle(algo=smeshBuilder.QUAD_MA_PROJ,geom=garonne_litMineur) +algo1D_litMineur = garonneAmont.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 = garonneAmont.Segment(geom=SectionsGaronne) +hypo1D_SectionsGaronne = algo1D_SectionsGaronne.NumberOfSegments(8) +hypo1D_SectionsGaronne.SetDistrType( 0 ) +subMesh_SectionsGaronne = algo1D_SectionsGaronne.GetSubMesh() +smesh.SetName(subMesh_SectionsGaronne, "SectionsGaronne") + +isDone = garonneAmont.SetMeshOrder( [ [ subMesh_SectionsGaronne, subMesh_litMineur ] ]) + +# --- compute mesh +isDone = garonneAmont.Compute() +isDone = garonneAmont.SplitQuadObject( garonneAmont, 1 ) +isDone = garonneAmont.ReorientObject( garonneAmont ) + +# --- geometrical groups of faces +riveGauche_1 = garonneAmont.GroupOnGeom(garonne_riveGauche,'riveGauche',SMESH.FACE) +litMineur_1 = garonneAmont.GroupOnGeom(garonne_litMineur,'litMineur',SMESH.FACE) +riveDroite_1 = garonneAmont.GroupOnGeom(garonne_riveDroite,'riveDroite',SMESH.FACE) + +# --- geometrical groups of edges + +ClosedFreeBoundary_1 = garonneAmont.GroupOnGeom(ClosedFreeBoundary[0],'ClosedFreeBoundary',SMESH.EDGE) +litMineur_droite_1 = garonneAmont.GroupOnGeom(litMineur_droite,'litMineur_droite',SMESH.EDGE) +litMineur_gauche_1 = garonneAmont.GroupOnGeom(litMineur_gauche,'litMineur_gauche',SMESH.EDGE) +SectionsgaronneAmont = garonneAmont.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.EDGE) +bordGaucheDomaine_1 = garonneAmont.GroupOnGeom(bordGaucheDomaine,'bordGaucheDomaine',SMESH.EDGE) +bordDroiteDomaine_1 = garonneAmont.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.EDGE) +amont_1 = garonneAmont.GroupOnGeom(amont,'amont',SMESH.EDGE) +aval_1 = garonneAmont.GroupOnGeom(aval,'aval',SMESH.EDGE) + +# --- geometrical groups of nodes + +garonneAmont_litMineur_2 = garonneAmont.GroupOnGeom(garonne_litMineur,'garonneAmont_litMineur',SMESH.NODE) +garonneAmont_riveDroite_2 = garonneAmont.GroupOnGeom(garonne_riveDroite,'garonneAmont_riveDroite',SMESH.NODE) +garonneAmont_riveGauche_2 = garonneAmont.GroupOnGeom(garonne_riveGauche,'garonneAmont_riveGauche',SMESH.NODE) +ClosedFreeBoundary_2 = garonneAmont.GroupOnGeom(ClosedFreeBoundary[0],'ClosedFreeBoundary',SMESH.NODE) +litMineur_droite_2 = garonneAmont.GroupOnGeom(litMineur_droite,'litMineur_droite',SMESH.NODE) +litMineur_gauche_2 = garonneAmont.GroupOnGeom(litMineur_gauche,'litMineur_gauche',SMESH.NODE) +SectionsgaronneAmont = garonneAmont.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.NODE) +bordGaucheDomaine_2 = garonneAmont.GroupOnGeom(bordGaucheDomaine,'bordGaucheDomaine',SMESH.NODE) +bordDroiteDomaine_2 = garonneAmont.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.NODE) +amont_2 = garonneAmont.GroupOnGeom(amont,'amont',SMESH.NODE) +aval_2 = garonneAmont.GroupOnGeom(aval,'aval',SMESH.NODE) + +garonneAmont.SetAutoColor( 1 ) +fichierMaillage = os.path.join(HYDRO_TEST_RESOURCES, 'garonneAmont.med') +garonneAmont.ExportMED(fichierMaillage, 0, SMESH.MED_V2_2, 1, None ,1) + +controlMeshStats(garonneAmont, 2759, 354, 5368) +controlSubMeshStats(litMineur_1, 1648) +controlSubMeshStats(riveDroite_1, 2018) +controlSubMeshStats(riveGauche_1, 1702) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() +