From: Paul RASCLE Date: Mon, 21 Sep 2020 09:42:29 +0000 (+0200) Subject: test linear interpolation of a stream X-Git-Tag: SH_V2_2_0~53 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bfb2939637cf5dab8c88fcc5bc9a86cefb493575;p=modules%2Fhydro.git test linear interpolation of a stream --- diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index 12ea1741..6c814f70 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -53,6 +53,7 @@ SET(EXAMPLES_TESTS h028_regroupOverlappingMeshes.py h029_regroupMeshesNonEnglobant.py h030_editNonHydroMesh.py + h031_interpolationLineaireStream.py ) SET(HYDRO_SAMPLES diff --git a/doc/salome/examples/CTestTestfileInstall.cmake b/doc/salome/examples/CTestTestfileInstall.cmake index db8b9460..25d524be 100644 --- a/doc/salome/examples/CTestTestfileInstall.cmake +++ b/doc/salome/examples/CTestTestfileInstall.cmake @@ -55,6 +55,7 @@ SET(EXAMPLES_TESTS h028_regroupOverlappingMeshes h029_regroupMeshesNonEnglobant h030_editNonHydroMesh + h031_interpolationLineaireStream ) FOREACH(tfile ${EXAMPLES_TESTS}) diff --git a/doc/salome/examples/h031_interpolationLineaireStream.py b/doc/salome/examples/h031_interpolationLineaireStream.py new file mode 100644 index 00000000..259c3b94 --- /dev/null +++ b/doc/salome/examples/h031_interpolationLineaireStream.py @@ -0,0 +1,123 @@ +# -*- 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() + +from HYDROPy import * +from PyQt5.QtCore import * +from PyQt5.QtGui import * + +from salome.hydrotools.controls import controlValues + +hydro_doc = HYDROData_Document.Document() + +hydro_doc.SetLocalCS( 0.000, 0.000 ) + +axe = hydro_doc.CreateObject( KIND_POLYLINEXY ) +axe.SetName( "axe" ) +axe.SetZLevel( 2 ) +axe.SetSectionColor( 0, QColor( 228, 105, 28, 255 ) ) +axe.AddSection( "Section_1", 1, 0 ) +axe.AddPoint( 0, gp_XY( 9.00, 20.00 ) ) +axe.AddPoint( 0, gp_XY( 31.00, 20.00 ) ) +axe.AddPoint( 0, gp_XY( 48.84, 26.13 ) ) +axe.AddPoint( 0, gp_XY( 64.61, 34.64 ) ) +axe.AddPoint( 0, gp_XY( 84.63, 58.56 ) ) +axe.AddPoint( 0, gp_XY( 97.38, 72.55 ) ) +axe.Update() + +riveGauche = hydro_doc.CreateObject( KIND_POLYLINEXY ) +riveGauche.SetName( "riveGauche" ) +riveGauche.SetZLevel( 0 ) +riveGauche.SetSectionColor( 0, QColor( 28, 228, 68, 255 ) ) +riveGauche.AddSection( "Section_1", 1, 0 ) +riveGauche.AddPoint( 0, gp_XY( 8.01, 26.89 ) ) +riveGauche.AddPoint( 0, gp_XY( 31.62, 28.04 ) ) +riveGauche.AddPoint( 0, gp_XY( 55.02, 36.84 ) ) +riveGauche.AddPoint( 0, gp_XY( 85.29, 74.85 ) ) +riveGauche.AddPoint( 0, gp_XY( 86.64, 76.59 ) ) +riveGauche.Update() + +riveDroite = hydro_doc.CreateObject( KIND_POLYLINEXY ) +riveDroite.SetName( "riveDroite" ) +riveDroite.SetZLevel( 1 ) +riveDroite.SetSectionColor( 0, QColor( 228, 218, 28, 255 ) ) +riveDroite.AddSection( "Section_1", 1, 0 ) +riveDroite.AddPoint( 0, gp_XY( 8.75, 12.88 ) ) +riveDroite.AddPoint( 0, gp_XY( 10.04, 13.03 ) ) +riveDroite.AddPoint( 0, gp_XY( 36.87, 13.54 ) ) +riveDroite.AddPoint( 0, gp_XY( 60.01, 25.02 ) ) +riveDroite.AddPoint( 0, gp_XY( 99.97, 60.03 ) ) +riveDroite.AddPoint( 0, gp_XY( 100.35, 60.37 ) ) +riveDroite.Update() + +Profile_1 = hydro_doc.CreateObject( KIND_PROFILE ) +Profile_1.SetName( "Profile_1" ) +profile_points = [ gp_XYZ( 10, 13, 10 ), + gp_XYZ( 10, 14, 6 ), + gp_XYZ( 10, 16, 6 ), + gp_XYZ( 10, 17, 5 ), + gp_XYZ( 10, 19, 5 ), + gp_XYZ( 10, 20, 8 ), + gp_XYZ( 10, 22, 8 ), + gp_XYZ( 10, 23, 7 ), + gp_XYZ( 10, 25, 7 ), + gp_XYZ( 10, 27, 11 ) ]; +Profile_1.SetProfilePoints( profile_points ) +Profile_1.Update() + +Profile_2 = hydro_doc.CreateObject( KIND_PROFILE ) +Profile_2.SetName( "Profile_2" ) +profile_points = [ gp_XYZ( 60, 25, 11 ), + gp_XYZ( 59.2857, 26.7143, 9 ), + gp_XYZ( 58.5714, 28.4286, 9 ), + gp_XYZ( 58.2143, 29.2857, 10 ), + gp_XYZ( 57.8571, 30.1429, 10 ), + gp_XYZ( 57.5, 31, 6 ), + gp_XYZ( 57.1429, 31.8571, 6 ), + gp_XYZ( 56.4286, 33.5714, 8 ), + gp_XYZ( 55.3571, 36.1429, 8 ), + gp_XYZ( 55, 37, 9 ) ]; +Profile_2.SetProfilePoints( profile_points ) +Profile_2.Update() + +Profile_3 = hydro_doc.CreateObject( KIND_PROFILE ) +Profile_3.SetName( "Profile_3" ) +profile_points = [ gp_XYZ( 100, 60, 11 ), + gp_XYZ( 97.75, 62.25, 7 ), + gp_XYZ( 96.25, 63.75, 6 ), + gp_XYZ( 94, 66, 7 ), + gp_XYZ( 91, 69, 6 ), + gp_XYZ( 90.25, 69.75, 6 ), + gp_XYZ( 88.75, 71.25, 5 ), + gp_XYZ( 85, 75, 10 ) ]; +Profile_3.SetProfilePoints( profile_points ) +Profile_3.Update() + +Stream_1 = hydro_doc.CreateObject( KIND_STREAM ) +Stream_1.SetName( "Stream_1" ) +Stream_1.SetZLevel( 3 ) +Stream_1.SetInterpolationMethod( 1 ) +Stream_1.SetHydraulicAxis( axe ) +Stream_1.AddProfile( Profile_1 ) +Stream_1.AddProfile( Profile_2 ) +Stream_1.AddProfile( Profile_3 ) +Stream_1.SetLeftBank( riveGauche ) +Stream_1.SetRightBank( riveDroite ) +Stream_1.SetHaxStep( 1.000 ) +Stream_1.SetNbProfilePoints( 100 ) +Stream_1.Update() + +bathy = hydro_doc.FindObjectByName("Stream_1_Altitude_1") +vecX=[40., 44., 48.] +vecY=[35., 43., 51.] +alti = bathy.GetAltitudesForPoints(vecX, vecY) +refs = [9.59, 9.31, 9.11] +controlValues(alti, refs, 0.05) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() diff --git a/src/HYDROTools/controls.py b/src/HYDROTools/controls.py index 921048a4..28d3cece 100644 --- a/src/HYDROTools/controls.py +++ b/src/HYDROTools/controls.py @@ -90,6 +90,19 @@ def controlStatZ(statz,refstatz): print("value: ", vals) print("reference: ", valsref, "tolerance for mean, std dev: ", tolerance, "and ", 10*tolerance, "for other values: OK") +def controlValues(vals, refs, tol = 0.1): + """ + control a list of values against a list of references, with an absolute tolerance + """ + print("values: ", vals) + print("references: ", refs) + print("tolerance: ", tol) + for v,r in zip(vals, refs): + if abs(v-r) >tol: + print("value: ", v) + print("reference: ", r) + print("tolerance: ", tol) + raise ValueError("value error") import MEDLoader from MEDLoader import MEDCouplingFieldDouble, ON_NODES, DataArrayDouble, MEDFileMesh