From 98ac9de5d38f785a9a66eccb7c70976278a1832e Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Thu, 27 Aug 2020 17:03:18 +0200 Subject: [PATCH] add Python test on extension with shape adjustements --- doc/salome/examples/CMakeLists.txt | 1 + .../examples/CTestTestfileInstall.cmake | 1 + .../examples/h023_extensionSimpleAmont.py | 150 ++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 doc/salome/examples/h023_extensionSimpleAmont.py diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index abf31765..fb9d81d1 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -43,6 +43,7 @@ SET(EXAMPLES_TESTS h021_meshChangeBathy.py g022_extensionSimpleComplete.py h022_extensionSimpleComplete.py + h023_extensionSimpleAmont.py ) SET(HYDRO_SAMPLES diff --git a/doc/salome/examples/CTestTestfileInstall.cmake b/doc/salome/examples/CTestTestfileInstall.cmake index 0173e760..2cf13a46 100644 --- a/doc/salome/examples/CTestTestfileInstall.cmake +++ b/doc/salome/examples/CTestTestfileInstall.cmake @@ -45,6 +45,7 @@ SET(EXAMPLES_TESTS h021_meshChangeBathy g022_extensionSimpleComplete h022_extensionSimpleComplete + h023_extensionSimpleAmont ) FOREACH(tfile ${EXAMPLES_TESTS}) diff --git a/doc/salome/examples/h023_extensionSimpleAmont.py b/doc/salome/examples/h023_extensionSimpleAmont.py new file mode 100644 index 00000000..4587dc31 --- /dev/null +++ b/doc/salome/examples/h023_extensionSimpleAmont.py @@ -0,0 +1,150 @@ +# -*- 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_2.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_2_brd.med") +fileMeshBrd = freeBordersGroup(origFileMesh, ficMeshOut) +exploreEdgeGroups(fileMeshBrd, "", offsetX, offsetY) + +fitShapePointsToMesh(os.path.join(tmpdir, "garonne_2_brd_FreeBorders.shp"), + os.path.join(HYDRO_SAMPLES, 'extension_1_2.shp'), + tmpdir, True, True) + +#---------------------- +# --- HYDRO +#---------------------- + +from HYDROPy import * +from PyQt5.QtCore import * +from PyQt5.QtGui import * + +from salome.hydrotools.hydroGeoMeshUtils import importPolylines, importBathymetry, createImmersibleZone, mergePolylines + +hydro_doc = HYDROData_Document.Document() +hydro_doc.SetLocalCS( offsetX, offsetY ) + +limites_original = importPolylines(hydro_doc, os.path.join(tmpdir, "garonne_2_brd_FreeBorders_split.shp"), 'garonne_2_brd_FreeBorders', True, 4) +limites_domaine = importPolylines(hydro_doc, os.path.join(tmpdir, "extension_1_2_adj.shp"), 'extension_1_2', False, 2) + +limite_extension = mergePolylines(hydro_doc, 'limite_extension', [limites_original[0], limites_domaine[0]]) + +Cloud_02 = importBathymetry(hydro_doc, "Cloud_02", HYDRO_SAMPLES) + +domaine_extension = createImmersibleZone(hydro_doc, "domaine_extension", limite_extension, Cloud_02, True, 0) + +# Calculation case +extension = hydro_doc.CreateObject( KIND_CALCULATION ) +extension.SetName( "extension" ) +extension.SetAssignmentMode( HYDROData_CalculationCase.AUTOMATIC ) +extension.AddGeometryObject( domaine_extension ) +extension.SetBoundaryPolyline( limite_extension ) +extension.Update() + +# # Calculation case +# extension = hydro_doc.CreateObject( KIND_CALCULATION ) +# extension.SetName( "extension" ) +# extension.SetAssignmentMode( HYDROData_CalculationCase.MANUAL ) +# extension.AddGeometryObject( domaine_extension ) +# case_geom_group = domaine_extension.GetGroup( 0 ) +# extension.AddGeometryGroup( case_geom_group ) +# extension.SetBoundaryPolyline( limite_extension ) +# extension.SetStricklerTable( Strickler_table_1 ) +# # Start the algorithm of the partition and assignment +# extension.Update() +# extension_Reg_1 = hydro_doc.FindObjectByName( "extension_Reg_1" ) +# extension_Zone_1 = hydro_doc.FindObjectByName( "extension_Zone_1" ) +# extension_Zone_1.SetColor( QColor( 105, 228, 28 )) +# extension_Reg_1.AddZone( extension_Zone_1 ) +# extension_Reg_1.SetName( "Case_1_Reg_1" ) + +# 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"] +#TODO: better identification +extension_domaine_original_Outer = geompy.CreateGroup(HYDRO_extension, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(extension_domaine_original_Outer, [3]) +geompy.addToStudyInFather( HYDRO_extension, extension_domaine_original_Outer, '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() + +controlMeshStats(extensionEnglobante, 4716, 596, 9193) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() -- 2.39.2