From c6d4eb2525f0658cb9b9e76f49d7eb578c8b4a0f Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Mon, 2 Nov 2015 17:15:25 +0100 Subject: [PATCH] ajout test interpolation z et regroupement des fonctions de controle --- CMakeLists.txt | 1 + doc/salome/examples/CMakeLists.txt | 1 + .../examples/CTestTestfileInstall.cmake | 1 + doc/salome/examples/h008_simpleCase.py | 25 +- doc/salome/examples/h009_normalCaseManual.py | 33 +- .../examples/h010_normalCaseManualMesh.py | 64 +-- .../h011_normalCaseManualInterpolZ.py | 454 ++++++++++++++++++ src/HYDROTools/CMakeLists.txt | 30 ++ src/HYDROTools/__init__.py | 0 src/HYDROTools/controls.py | 80 +++ src/HYDROTools/interpolZ.py | 239 +++++++++ 11 files changed, 833 insertions(+), 95 deletions(-) create mode 100644 doc/salome/examples/h011_normalCaseManualInterpolZ.py create mode 100644 src/HYDROTools/CMakeLists.txt create mode 100644 src/HYDROTools/__init__.py create mode 100644 src/HYDROTools/controls.py create mode 100644 src/HYDROTools/interpolZ.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 601d0ab6..2b603ead 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,7 @@ ADD_SUBDIRECTORY (src/shapelib) ADD_SUBDIRECTORY (src/HYDROData) ADD_SUBDIRECTORY (src/HYDROGUI) ADD_SUBDIRECTORY (src/HYDROPy) +ADD_SUBDIRECTORY (src/HYDROTools) IF(SALOME_BUILD_DOC) ADD_SUBDIRECTORY(doc) ENDIF() diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index 9bc1261c..94bc798a 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -30,6 +30,7 @@ SET(EXAMPLES_TESTS h008_simpleCase.py h009_normalCaseManual.py h010_normalCaseManualMesh.py + h011_normalCaseManualInterpolZ.py ) SET(HYDRO_SAMPLES diff --git a/doc/salome/examples/CTestTestfileInstall.cmake b/doc/salome/examples/CTestTestfileInstall.cmake index bd5054a2..1f99c152 100644 --- a/doc/salome/examples/CTestTestfileInstall.cmake +++ b/doc/salome/examples/CTestTestfileInstall.cmake @@ -32,6 +32,7 @@ SET(EXAMPLES_TESTS h008_simpleCase h009_normalCaseManual h010_normalCaseManualMesh + h011_normalCaseManualInterpolZ ) FOREACH(tfile ${EXAMPLES_TESTS}) diff --git a/doc/salome/examples/h008_simpleCase.py b/doc/salome/examples/h008_simpleCase.py index f6d6dd36..c0536177 100644 --- a/doc/salome/examples/h008_simpleCase.py +++ b/doc/salome/examples/h008_simpleCase.py @@ -5,25 +5,15 @@ import salome salome.salome_init() theStudy = salome.myStudy + +#---------------------- +# --- HYDRO +#---------------------- from HYDROPy import * from PyQt4.QtCore import * from PyQt4.QtGui import * -def controlGeomProps(geomShape, refLength, refArea): - props = geompy.BasicProperties(geomShape) - print " Wires length: ", props[0] - print " Surface area: ", props[1] - print " Volume : ", props[2] - deltaLength = 2.0*abs((props[0] - refLength)/(props[0] + refLength)) - deltaArea = 2.0*abs((props[1] - refArea)/(props[1] + refArea)) - if deltaLength > 1e-7 or deltaArea > 1e-7 or props[2] != 0: - print "While must be:" - print " Wires length: ", refLength - print " Surface area: ", refArea - print " Volume : ", 0. - raise ValueError("Bad length or area") - hydro_doc = HYDROData_Document.Document( theStudy._get_StudyId() ) hydro_doc.SetLocalCS( 0, 0 ) @@ -74,11 +64,16 @@ Case_1.Update() # Export of the calculation case Case_1_entry = Case_1.Export( theStudy._get_StudyId() ) +#---------------------- +# --- 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(theStudy) @@ -87,7 +82,7 @@ Case_1_geom = salome.IDToObject( str( Case_1_entry ) ) print "Geom shape:", Case_1_geom print "Geom shape name:", Case_1_geom.GetName() -controlGeomProps(Case_1_geom, 1218.7373973, 49697.2117918) +controlGeomProps(geompy, Case_1_geom, 1218.7373973, 49697.2117918) if salome.sg.hasDesktop(): salome.sg.updateObjBrowser(1) diff --git a/doc/salome/examples/h009_normalCaseManual.py b/doc/salome/examples/h009_normalCaseManual.py index be5f67de..4a79e748 100644 --- a/doc/salome/examples/h009_normalCaseManual.py +++ b/doc/salome/examples/h009_normalCaseManual.py @@ -8,29 +8,15 @@ import salome salome.salome_init() theStudy = salome.myStudy + +#---------------------- +# --- HYDRO +#---------------------- from HYDROPy import * from PyQt4.QtCore import * from PyQt4.QtGui import * -# ------------------------------------- - -def controlGeomProps(geomShape, refLength, refArea): - props = geompy.BasicProperties(geomShape) - print " Wires length: ", props[0] - print " Surface area: ", props[1] - print " Volume : ", props[2] - deltaLength = 2.0*abs((props[0] - refLength)/(props[0] + refLength)) - deltaArea = 2.0*abs((props[1] - refArea)/(props[1] + refArea)) - if deltaLength > 1e-7 or deltaArea > 1e-7 or props[2] != 0: - print "While must be:" - print " Wires length: ", refLength - print " Surface area: ", refArea - print " Volume : ", 0. - raise ValueError("Bad length or area") - -# ------------------------------------- - hydro_doc = HYDROData_Document.Document( theStudy._get_StudyId() ) hydro_doc.SetLocalCS( 430000, 6.35e+06 ) @@ -304,11 +290,16 @@ garonne_1_riveGauche.SetName("garonne_1_riveGauche") # Export of the calculation case garonne_1_entry = garonne_1.Export( theStudy._get_StudyId() ) +#---------------------- +# --- 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(theStudy) @@ -331,9 +322,9 @@ geompy.addToStudyInFather( HYDRO_garonne_1, riveGauche, 'riveGauche' ) geompy.addToStudyInFather( HYDRO_garonne_1, litMineur, 'litMineur' ) geompy.addToStudyInFather( HYDRO_garonne_1, riveDroite, 'riveDroite' ) -controlGeomProps(riveGauche, 29149.36918, 35992556.454929) -controlGeomProps(litMineur, 30337.548492, 3646827.749809) -controlGeomProps(riveDroite, 32012.343241, 26177085.460092) +controlGeomProps(geompy, riveGauche, 29149.36918, 35992556.454929) +controlGeomProps(geompy, litMineur, 30337.548492, 3646827.749809) +controlGeomProps(geompy, riveDroite, 32012.343241, 26177085.460092) if salome.sg.hasDesktop(): salome.sg.updateObjBrowser(1) diff --git a/doc/salome/examples/h010_normalCaseManualMesh.py b/doc/salome/examples/h010_normalCaseManualMesh.py index 66fa95a9..42ce8c92 100644 --- a/doc/salome/examples/h010_normalCaseManualMesh.py +++ b/doc/salome/examples/h010_normalCaseManualMesh.py @@ -8,62 +8,6 @@ import salome salome.salome_init() theStudy = salome.myStudy - -# ------------------------------------- - -def controlGeomProps(geomShape, refLength, refArea): - props = geompy.BasicProperties(geomShape) - print " Wires length: ", props[0] - print " Surface area: ", props[1] - print " Volume : ", props[2] - deltaLength = 2.0*abs((props[0] - refLength)/(props[0] + refLength)) - deltaArea = 2.0*abs((props[1] - refArea)/(props[1] + refArea)) - if deltaLength > 1e-7 or deltaArea > 1e-7 or props[2] != 0: - print "While must be:" - print " Wires length: ", refLength - print " Surface area: ", refArea - print " Volume : ", 0. - raise ValueError("Bad length or area") - -# ------------------------------------- - -def controlMeshStats(aMesh, nbNodes, nbEdges, nbTriangles): - """ - Only for a mesh, not for a subMesh - """ - tolerance = 0.05 - references = {} - references['Entity_Node'] = nbNodes - references['Entity_Edge'] = nbEdges - references['Entity_Triangle'] = nbTriangles - - mesures = aMesh.GetMeshInfo() - #print mesures - d= {} - for key, value in mesures.iteritems(): - d[str(key)] = value - #print d - for key in ('Entity_Triangle', 'Entity_Edge', 'Entity_Node'): - if (d[key] < (1.0 - tolerance)*references[key]) \ - or (d[key] > (1.0 + tolerance)*references[key]): - print aMesh.GetName() - print key, ": value: ", d[key], " reference: ", references[key] - raise ValueError("Bad number of nodes or elements") - -# ------------------------------------- - -def controlSubMeshStats(aSubMesh, nbItems): - """ - Only for a mesh, not for a subMesh - """ - tolerance = 0.05 - mesures = aSubMesh.GetMeshInfo() - nbRef = sum(mesures) - if (nbItems < (1.0 - tolerance)*nbRef) \ - or (nbItems > (1.0 + tolerance)*nbRef): - print aSubMesh.GetName() - print "value: ", nbItems, " reference: ", nbRef - raise ValueError("Bad number of nodes or elements") #---------------------- # --- HYDRO @@ -355,6 +299,7 @@ import GEOM from salome.geom import geomBuilder import math import SALOMEDS +from salome.hydrotools.controls import controlGeomProps geompy = geomBuilder.New(theStudy) @@ -394,9 +339,9 @@ geompy.addToStudyInFather( HYDRO_garonne_1, bordGaucheDomaine, 'bordGaucheDomain geompy.addToStudyInFather( HYDRO_garonne_1, bordDroiteDomaine, 'bordDroiteDomaine' ) # --- basic properties control: edges length, surfaces -controlGeomProps(riveGauche, 29149.36918, 35992556.454929) -controlGeomProps(litMineur, 30337.548492, 3646827.749809) -controlGeomProps(riveDroite, 32012.343241, 26177085.460092) +controlGeomProps(geompy, riveGauche, 29149.36918, 35992556.454929) +controlGeomProps(geompy, litMineur, 30337.548492, 3646827.749809) +controlGeomProps(geompy, riveDroite, 32012.343241, 26177085.460092) #---------------------- # --- Meshing @@ -404,6 +349,7 @@ controlGeomProps(riveDroite, 32012.343241, 26177085.460092) import SMESH, SALOMEDS from salome.smesh import smeshBuilder +from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats smesh = smeshBuilder.New(theStudy) diff --git a/doc/salome/examples/h011_normalCaseManualInterpolZ.py b/doc/salome/examples/h011_normalCaseManualInterpolZ.py new file mode 100644 index 00000000..26d613d0 --- /dev/null +++ b/doc/salome/examples/h011_normalCaseManualInterpolZ.py @@ -0,0 +1,454 @@ +# -*- 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() +theStudy = salome.myStudy + +#---------------------- +# --- HYDRO +#---------------------- + +from HYDROPy import * +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +hydro_doc = HYDROData_Document.Document( theStudy._get_StudyId() ) + +hydro_doc.SetLocalCS( 430000, 6.35e+06 ) + +garonne_ign_01 = hydro_doc.CreateObject( KIND_IMAGE ) +garonne_ign_01.SetName( "garonne_ign_01" ) + +garonne_ign_01.SetZLevel( 0 ) + + +garonne_ign_01.LoadImage(os.path.join(HYDRO_SAMPLES, "garonne_ign_01.png" )) + +garonne_ign_01.SetLocalPoints( QPoint( 40, 817 ), + QPoint( 1325, 85 ) ) + +garonne_ign_01.SetGlobalPoints( 1, + QPointF( 471562, 6.36775e+06 ), + QPointF( 489400, 6.37702e+06 ) ) + +garonne_ign_01.Update() + +garonne_ign_02 = hydro_doc.CreateObject( KIND_IMAGE ) +garonne_ign_02.SetName( "garonne_ign_02" ) + +garonne_ign_02.SetZLevel( 1 ) + + +garonne_ign_02.LoadImage( os.path.join(HYDRO_SAMPLES, "garonne_ign_02.png" )) + +garonne_ign_02.SetLocalPoints( QPoint( 1389, 447 ), + QPoint( 784, 481 ) ) + +garonne_ign_02.SetGlobalPoints( 3, + QPointF( 631, 95 ), + QPointF( 26, 129 ) ) +garonne_ign_02.SetTrsfReferenceImage( garonne_ign_01 ) + +garonne_ign_02.Update() + +garonne = hydro_doc.CreateObject( KIND_POLYLINEXY ) +garonne.SetName( "garonne" ) + +garonne.SetZLevel( 2 ) + +garonne.AddSection( "Section_1", 1, 1 ) +garonne.AddPoint( 0, gp_XY( 38191.48, 33184.55 ) ) +garonne.AddPoint( 0, gp_XY( 38553.78, 33013.53 ) ) +garonne.AddPoint( 0, gp_XY( 38993.90, 32767.64 ) ) +garonne.AddPoint( 0, gp_XY( 39678.58, 32533.58 ) ) +garonne.AddPoint( 0, gp_XY( 40240.26, 32305.27 ) ) +garonne.AddPoint( 0, gp_XY( 40717.94, 32193.70 ) ) +garonne.AddPoint( 0, gp_XY( 41361.00, 32464.18 ) ) +garonne.AddPoint( 0, gp_XY( 41831.41, 32626.69 ) ) +garonne.AddPoint( 0, gp_XY( 41950.14, 32618.24 ) ) +garonne.AddPoint( 0, gp_XY( 42524.97, 32419.61 ) ) +garonne.AddPoint( 0, gp_XY( 42909.80, 32291.33 ) ) +garonne.AddPoint( 0, gp_XY( 43177.03, 32269.95 ) ) +garonne.AddPoint( 0, gp_XY( 43465.65, 32344.78 ) ) +garonne.AddPoint( 0, gp_XY( 43754.27, 32152.37 ) ) +garonne.AddPoint( 0, gp_XY( 44128.40, 31842.37 ) ) +garonne.AddPoint( 0, gp_XY( 44003.90, 31269.93 ) ) +garonne.AddPoint( 0, gp_XY( 44010.82, 30869.63 ) ) +garonne.AddPoint( 0, gp_XY( 44064.26, 30655.84 ) ) +garonne.AddPoint( 0, gp_XY( 44434.73, 30366.18 ) ) +garonne.AddPoint( 0, gp_XY( 45208.04, 30484.81 ) ) +garonne.AddPoint( 0, gp_XY( 45705.01, 30287.34 ) ) +garonne.AddPoint( 0, gp_XY( 45933.89, 30046.87 ) ) +garonne.AddPoint( 0, gp_XY( 46127.34, 29490.68 ) ) +garonne.AddPoint( 0, gp_XY( 46111.60, 29226.08 ) ) +garonne.AddPoint( 0, gp_XY( 46228.62, 28784.05 ) ) +garonne.AddPoint( 0, gp_XY( 46247.64, 28449.75 ) ) +garonne.AddPoint( 0, gp_XY( 46108.48, 28086.94 ) ) +garonne.AddPoint( 0, gp_XY( 45618.52, 27553.74 ) ) +garonne.AddPoint( 0, gp_XY( 45276.77, 27042.78 ) ) +garonne.AddPoint( 0, gp_XY( 45001.89, 26273.15 ) ) +garonne.AddPoint( 0, gp_XY( 45167.76, 25975.34 ) ) +garonne.AddPoint( 0, gp_XY( 46018.15, 25848.84 ) ) +garonne.AddPoint( 0, gp_XY( 46378.94, 25872.21 ) ) +garonne.AddPoint( 0, gp_XY( 46885.57, 25937.64 ) ) +garonne.AddPoint( 0, gp_XY( 47278.36, 25782.88 ) ) +garonne.AddPoint( 0, gp_XY( 47153.86, 25728.04 ) ) +garonne.AddPoint( 0, gp_XY( 46987.51, 25749.97 ) ) +garonne.AddPoint( 0, gp_XY( 46658.26, 25715.71 ) ) +garonne.AddPoint( 0, gp_XY( 45650.76, 25634.46 ) ) +garonne.AddPoint( 0, gp_XY( 45122.63, 25748.21 ) ) +garonne.AddPoint( 0, gp_XY( 44797.63, 26325.09 ) ) +garonne.AddPoint( 0, gp_XY( 45114.51, 27168.75 ) ) +garonne.AddPoint( 0, gp_XY( 45508.28, 27713.21 ) ) +garonne.AddPoint( 0, gp_XY( 45994.19, 28382.53 ) ) +garonne.AddPoint( 0, gp_XY( 45927.01, 29201.34 ) ) +garonne.AddPoint( 0, gp_XY( 45756.39, 29859.47 ) ) +garonne.AddPoint( 0, gp_XY( 45390.76, 30151.97 ) ) +garonne.AddPoint( 0, gp_XY( 45039.85, 30120.84 ) ) +garonne.AddPoint( 0, gp_XY( 44513.26, 30084.28 ) ) +garonne.AddPoint( 0, gp_XY( 43923.42, 30426.28 ) ) +garonne.AddPoint( 0, gp_XY( 43768.81, 30934.29 ) ) +garonne.AddPoint( 0, gp_XY( 43820.10, 31425.20 ) ) +garonne.AddPoint( 0, gp_XY( 43854.78, 31801.12 ) ) +garonne.AddPoint( 0, gp_XY( 43479.64, 32053.54 ) ) +garonne.AddPoint( 0, gp_XY( 42923.47, 32051.85 ) ) +garonne.AddPoint( 0, gp_XY( 42493.64, 32187.97 ) ) +garonne.AddPoint( 0, gp_XY( 42074.27, 32302.91 ) ) +garonne.AddPoint( 0, gp_XY( 41624.75, 32330.93 ) ) +garonne.AddPoint( 0, gp_XY( 41325.93, 32187.97 ) ) +garonne.AddPoint( 0, gp_XY( 40879.52, 31987.29 ) ) +garonne.AddPoint( 0, gp_XY( 40308.78, 32018.46 ) ) +garonne.AddPoint( 0, gp_XY( 39782.86, 32207.17 ) ) +garonne.AddPoint( 0, gp_XY( 38814.10, 32560.43 ) ) +garonne.AddPoint( 0, gp_XY( 38302.17, 32903.70 ) ) + +garonne.Update() + + +domaine = hydro_doc.CreateObject( KIND_POLYLINEXY ) +domaine.SetName( "domaine" ) + +domaine.SetZLevel( 3 ) + +domaine.AddSection( "Section_1", 0, 1 ) +domaine.AddPoint( 0, gp_XY( 39901.15, 34762.30 ) ); +domaine.AddPoint( 0, gp_XY( 38086.50, 29964.69 ) ); +domaine.AddPoint( 0, gp_XY( 44835.83, 24264.97 ) ); +domaine.AddPoint( 0, gp_XY( 46758.56, 25021.86 ) ); +domaine.AddPoint( 0, gp_XY( 46757.20, 26601.21 ) ); +domaine.AddPoint( 0, gp_XY( 48566.45, 30152.81 ) ); +domaine.AddPoint( 0, gp_XY( 45532.36, 33239.83 ) ); +domaine.AddPoint( 0, gp_XY( 43548.77, 34048.39 ) ); + +domaine.Update() + + +lit_majeur = hydro_doc.CreateObject( KIND_POLYLINEXY ) +lit_majeur.SetName( "lit_majeur" ) + +lit_majeur.SetZLevel( 7 ) + +lit_majeur.AddSection( "Section_1", 1, 1 ) +lit_majeur.AddPoint( 0, gp_XY( 41225.22, 34118.46 ) ) +lit_majeur.AddPoint( 0, gp_XY( 41716.41, 33705.87 ) ) +lit_majeur.AddPoint( 0, gp_XY( 42384.43, 33293.27 ) ) +lit_majeur.AddPoint( 0, gp_XY( 42561.26, 32684.19 ) ) +lit_majeur.AddPoint( 0, gp_XY( 42875.62, 32369.83 ) ) +lit_majeur.AddPoint( 0, gp_XY( 43700.82, 32350.18 ) ) +lit_majeur.AddPoint( 0, gp_XY( 44526.02, 31662.51 ) ) +lit_majeur.AddPoint( 0, gp_XY( 45370.87, 31819.69 ) ) +lit_majeur.AddPoint( 0, gp_XY( 46274.66, 31682.16 ) ) +lit_majeur.AddPoint( 0, gp_XY( 46981.97, 31328.50 ) ) +lit_majeur.AddPoint( 0, gp_XY( 47021.27, 30719.43 ) ) +lit_majeur.AddPoint( 0, gp_XY( 47217.74, 30051.41 ) ) +lit_majeur.AddPoint( 0, gp_XY( 47846.46, 29560.22 ) ) +lit_majeur.AddPoint( 0, gp_XY( 48730.61, 28735.02 ) ) +lit_majeur.AddPoint( 0, gp_XY( 48809.20, 27732.99 ) ) +lit_majeur.AddPoint( 0, gp_XY( 49143.21, 27163.21 ) ) +lit_majeur.AddPoint( 0, gp_XY( 49654.05, 26829.20 ) ) +lit_majeur.AddPoint( 0, gp_XY( 49693.34, 25355.63 ) ) +lit_majeur.AddPoint( 0, gp_XY( 48612.72, 23214.04 ) ) +lit_majeur.AddPoint( 0, gp_XY( 47453.51, 23115.80 ) ) +lit_majeur.AddPoint( 0, gp_XY( 46471.13, 24176.77 ) ) +lit_majeur.AddPoint( 0, gp_XY( 45960.29, 25257.39 ) ) +lit_majeur.AddPoint( 0, gp_XY( 44899.32, 25591.40 ) ) +lit_majeur.AddPoint( 0, gp_XY( 44270.60, 26573.78 ) ) +lit_majeur.AddPoint( 0, gp_XY( 43248.92, 27909.82 ) ) +lit_majeur.AddPoint( 0, gp_XY( 42757.73, 28243.83 ) ) +lit_majeur.AddPoint( 0, gp_XY( 42266.54, 28342.07 ) ) +lit_majeur.AddPoint( 0, gp_XY( 41736.06, 28106.30 ) ) +lit_majeur.AddPoint( 0, gp_XY( 41402.05, 28833.26 ) ) +lit_majeur.AddPoint( 0, gp_XY( 40910.86, 28911.85 ) ) +lit_majeur.AddPoint( 0, gp_XY( 40576.85, 29324.45 ) ) +lit_majeur.AddPoint( 0, gp_XY( 40144.60, 29599.51 ) ) +lit_majeur.AddPoint( 0, gp_XY( 39024.69, 30130.00 ) ) +lit_majeur.AddPoint( 0, gp_XY( 38612.09, 30365.77 ) ) +lit_majeur.AddPoint( 0, gp_XY( 38828.21, 33391.50 ) ) + +lit_majeur.Update() + + +Cloud_02 = hydro_doc.CreateObject( KIND_BATHYMETRY ) +Cloud_02.SetName( "Cloud_02" ) + +Cloud_02.SetAltitudesInverted( 0 ) +Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" )) + +Cloud_02.Update() + + +garonne_point_L93 = hydro_doc.CreateObject( KIND_BATHYMETRY ) +garonne_point_L93.SetName( "garonne_point_L93" ) + +garonne_point_L93.SetAltitudesInverted( 0 ) +garonne_point_L93.ImportFromFile( os.path.join(HYDRO_SAMPLES, "garonne_point_L93.xyz" )) + +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( Cloud_02 ) +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.SetAssignmentLandCoverMode( HYDROData_CalculationCase.AUTOMATIC ) +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_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_riveDroite.AddZone( garonne_1_Zone_2 ) +garonne_1_Zone_3 = hydro_doc.FindObjectByName( "garonne_1_Zone_3" ) +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_riveGauche.AddZone( garonne_1_Zone_4 ) +garonne_1_Zone_5 = hydro_doc.FindObjectByName( "garonne_1_Zone_5" ) +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( theStudy._get_StudyId() ) + +#---------------------- +# --- 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(theStudy) + +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 +[riveGauche,litMineur,riveDroite] = geompy.ExtractShapes(HYDRO_garonne_1, geompy.ShapeType["FACE"], True) + +# --- manual definition: useful groups of edges +garonne_1_litMineur_Outer = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(garonne_1_litMineur_Outer, [7, 9]) +garonne_1_domaineEtendu_Outer = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(garonne_1_domaineEtendu_Outer, [4, 11, 17, 24, 26, 28, 14, 19, 20, 22, 31, 39, 41, 33, 35, 37]) + +aval = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(aval, [4]) +amont = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(amont, [11]) +SectionsGaronne = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(SectionsGaronne, [4, 11]) +bordGaucheDomaine = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(bordGaucheDomaine, [14, 28, 20, 24, 19, 17, 26, 22]) +bordDroiteDomaine = geompy.CreateGroup(HYDRO_garonne_1, geompy.ShapeType["EDGE"]) +geompy.UnionIDs(bordDroiteDomaine, [41, 35, 31, 33, 39, 37]) + +# --- publications dans l'étude +geompy.addToStudyInFather( HYDRO_garonne_1, riveGauche, 'riveGauche' ) +geompy.addToStudyInFather( HYDRO_garonne_1, litMineur, 'litMineur' ) +geompy.addToStudyInFather( HYDRO_garonne_1, riveDroite, 'riveDroite' ) +geompy.addToStudyInFather( HYDRO_garonne_1, aval, 'aval' ) +geompy.addToStudyInFather( HYDRO_garonne_1, amont, 'amont' ) +geompy.addToStudyInFather( HYDRO_garonne_1, SectionsGaronne, 'SectionsGaronne' ) +geompy.addToStudyInFather( HYDRO_garonne_1, bordGaucheDomaine, 'bordGaucheDomaine' ) +geompy.addToStudyInFather( HYDRO_garonne_1, bordDroiteDomaine, 'bordDroiteDomaine' ) + +# --- basic properties control: edges length, surfaces +controlGeomProps(geompy, riveGauche, 29149.36918, 35992556.454929) +controlGeomProps(geompy, litMineur, 30337.548492, 3646827.749809) +controlGeomProps(geompy, riveDroite, 32012.343241, 26177085.460092) + +#---------------------- +# --- Meshing +#---------------------- + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder +from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats + +smesh = smeshBuilder.New(theStudy) + +# --- 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=litMineur) +algo1D_litMineur = garonne_1.Segment(geom=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 ) + +# --- geometrical groups of edges +garonne_1_litMineur_Outer_1 = garonne_1.GroupOnGeom(garonne_1_litMineur_Outer,'garonne_1_litMineur_Outer',SMESH.EDGE) +garonne_1_domaineEtendu_Outer_1 = garonne_1.GroupOnGeom(garonne_1_domaineEtendu_Outer,'garonne_1_domaineEtendu_Outer',SMESH.EDGE) +aval_1 = garonne_1.GroupOnGeom(aval,'aval',SMESH.EDGE) +amont_1 = garonne_1.GroupOnGeom(amont,'amont',SMESH.EDGE) +bordGaucheDomaine_1 = garonne_1.GroupOnGeom(bordGaucheDomaine,'bordGaucheDomaine',SMESH.EDGE) +bordDroiteDomaine_1 = garonne_1.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.EDGE) +SectionsGaronne_2 = garonne_1.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.EDGE) + +# --- geometrical groups of faces +riveGauche_1 = garonne_1.GroupOnGeom(riveGauche,'riveGauche',SMESH.FACE) +litMineur_2 = garonne_1.GroupOnGeom(litMineur,'litMineur',SMESH.FACE) +riveDroite_1 = garonne_1.GroupOnGeom(riveDroite,'riveDroite',SMESH.FACE) + +# --- geometrical groups of nodes +garonne_1_litMineur_Outer_2 = garonne_1.GroupOnGeom(garonne_1_litMineur_Outer,'garonne_1_litMineur_Outer',SMESH.NODE) +garonne_1_domaineEtendu_Outer_2 = garonne_1.GroupOnGeom(garonne_1_domaineEtendu_Outer,'garonne_1_domaineEtendu_Outer',SMESH.NODE) +riveGauche_2 = garonne_1.GroupOnGeom(riveGauche,'riveGauche',SMESH.NODE) +litMineur_3 = garonne_1.GroupOnGeom(litMineur,'litMineur',SMESH.NODE) +riveDroite_2 = garonne_1.GroupOnGeom(riveDroite,'riveDroite',SMESH.NODE) +aval_2 = garonne_1.GroupOnGeom(aval,'aval',SMESH.NODE) +amont_2 = garonne_1.GroupOnGeom(amont,'amont',SMESH.NODE) +bordGaucheDomaine_2 = garonne_1.GroupOnGeom(bordGaucheDomaine,'bordGaucheDomaine',SMESH.NODE) +bordDroiteDomaine_2 = garonne_1.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.NODE) +SectionsGaronne_3 = garonne_1.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.NODE) + +garonne_1.SetAutoColor( 1 ) +garonne_1.ExportMED( r'/tmp/garonne_1.med', 0, SMESH.MED_V2_2, 1, None ,1) + +controlMeshStats(garonne_1, 3888, 475, 7597) +controlSubMeshStats(litMineur_2, 2384) +controlSubMeshStats(riveDroite_1, 2342) +controlSubMeshStats(riveGauche_1, 2871) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(1) + +#---------------------- +# --- Z interpolation with HYDRO +#---------------------- + +from salome.hydrotools.interpolZ import interpolZ, createZfield2 +from salome.hydrotools.controls import controlStatZ + +# --- case name in HYDRO +nomCas = 'garonne_1' + +# --- med file 2D(x,y) of the case produced by SMESH +fichierMaillage = '/tmp/garonne_1.med' + +# --- 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 + +# --- Z interpolation on the bathymety/altimetry on the mesh nodes +statz = interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef) +refstatz = {'riveDroite': (10.88, 32.47999954), 'riveGauche': (7.72, 71.38999939), 'litMineur': (2.06, 25.41)} +controlStatZ(statz, refstatz) + +# --- add a field on nodes of type double with z values, named "BOTTOM" +createZfield2(fichierMaillage) + + diff --git a/src/HYDROTools/CMakeLists.txt b/src/HYDROTools/CMakeLists.txt new file mode 100644 index 00000000..0e5548f0 --- /dev/null +++ b/src/HYDROTools/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (C) 2012-2013 EDF +# +# This file is part of SALOME HYDRO module. +# +# SALOME HYDRO module is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# SALOME HYDRO module is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with SALOME HYDRO module. If not, see . + +#ADD_SUBDIRECTORY(xxx) + +# --- Python files --- + +SET(PYFILES + __init__.py + controls.py + interpolZ.py +) + +# --- rules --- + +INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES}" ${SALOME_INSTALL_PYTHON}/salome/hydrotools) diff --git a/src/HYDROTools/__init__.py b/src/HYDROTools/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/HYDROTools/controls.py b/src/HYDROTools/controls.py new file mode 100644 index 00000000..bf8927db --- /dev/null +++ b/src/HYDROTools/controls.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- + +# ------------------------------------- + +def controlGeomProps(geompy, geomShape, refLength, refArea): + """ + compare area and length of a geometric face with a reference, + with relative precision of 1.E-7 + """ + props = geompy.BasicProperties(geomShape) + print " Wires length: ", props[0] + print " Surface area: ", props[1] + print " Volume : ", props[2] + deltaLength = 2.0*abs((props[0] - refLength)/(props[0] + refLength)) + deltaArea = 2.0*abs((props[1] - refArea)/(props[1] + refArea)) + if deltaLength > 1e-7 or deltaArea > 1e-7 or props[2] != 0: + print "While must be:" + print " Wires length: ", refLength + print " Surface area: ", refArea + print " Volume : ", 0. + raise ValueError("Bad length or area") + +# ------------------------------------- + +def controlMeshStats(aMesh, nbNodes, nbEdges, nbTriangles): + """ + Compare number of nodes and elements with a reference, + with a precision of 5%. + Only for a mesh, not for a subMesh. + """ + tolerance = 0.05 + references = {} + references['Entity_Node'] = nbNodes + references['Entity_Edge'] = nbEdges + references['Entity_Triangle'] = nbTriangles + + mesures = aMesh.GetMeshInfo() + #print mesures + d= {} + for key, value in mesures.iteritems(): + d[str(key)] = value + for key in ('Entity_Triangle', 'Entity_Edge', 'Entity_Node'): + if (d[key] < (1.0 - tolerance)*references[key]) \ + or (d[key] > (1.0 + tolerance)*references[key]): + print aMesh.GetName() + print key, ": value: ", d[key], " reference: ", references[key] + raise ValueError("Bad number of nodes or elements") + +# ------------------------------------- + +def controlSubMeshStats(aSubMesh, nbItems): + """ + Compare number of nodes and elements with a reference, + with a precision of 5%. + Only for a subMesh, not for a mesh. + """ + tolerance = 0.05 + mesures = aSubMesh.GetMeshInfo() + nbRef = sum(mesures) + if (nbItems < (1.0 - tolerance)*nbRef) \ + or (nbItems > (1.0 + tolerance)*nbRef): + print aSubMesh.GetName() + print "value: ", nbItems, " reference: ", nbRef + raise ValueError("Bad number of nodes or elements") + +# ------------------------------------- + +def controlStatZ(statz,refstatz): + """ + Compare min and max of z of regions with a reference, + with a precision of 0.05m. + """ + tolerance = 0.05 # metres + for nomreg, valsref in refstatz.iteritems(): + vals = statz[nomreg] + if abs(vals[0] - valsref[0]) > tolerance \ + or abs(vals[1] - valsref[1]) > tolerance: + print nomreg + print "value: ", vals, " reference: ", valsref + raise ValueError("z interpolation error") diff --git a/src/HYDROTools/interpolZ.py b/src/HYDROTools/interpolZ.py new file mode 100644 index 00000000..efe490a2 --- /dev/null +++ b/src/HYDROTools/interpolZ.py @@ -0,0 +1,239 @@ +# -*- coding: utf-8 -*- + +""" +example of use case of interpolZ and createZfield methods: + +# --- case name in HYDRO +nomCas = 'inondation1' + +# --- med file 2D(x,y) of the case produced by SMESH +fichierMaillage = '/home/B27118/projets/LNHE/garonne/inondation1.med' + +# --- dictionary [med group name] = region name +dicoGroupeRegion= dict(litMineur = 'inondation1_litMineur', + litMajeurDroite = 'inondation1_riveDroite', + litMajeurGauche = 'inondation1_riveGauche', + ) +# --- value to use for Z when the node is not in a region (used to detect problems) +zUndef = 90 + +# --- Z interpolation on the bathymety/altimetry on the mesh nodes +interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef) + +# --- add a field on nodes of type double with z values, named "BOTTOM" +createZfield2(fichierMaillage) +""" +# ----------------------------------------------------------------------------- + +import string + +# ----------------------------------------------------------------------------- + +import sys +import salome + +salome.salome_init() +theStudy = salome.myStudy +theStudyId = salome.myStudyId + +# ----------------------------------------------------------------------------- + +from med import medfile +from med import medmesh +#from med import medfilter +from med import medfield +from med import medenum +#from med import medprofile +#from med import medlocalization +#from med import medlink + +def createZfield1(fichierMaillage): + """ + Complete the mesh for Telemac. + Add a field on nodes, named "BOTTOM", of type double, containing z coordinates of nodes. + createZfield1 is used after interpolZ. createZfield1 is base on med file interface. + There is an alternate method based on MEDLoader, equivalent (createZfield2). + The file F.med produced by interpolz must exist, and is modified. + fichierMaillage : 2D (x,y) med file produced by SMESH and used by interpolZ. + return F.med : med file containing the field "BOTTOM" + """ + + noms = string.split(fichierMaillage,'.') + basename = string.join(noms[:-1], '.') + fichierFMaillage = basename + 'F.med' + print fichierFMaillage + + # --- ouverture du fichier + fid=medfile.MEDfileOpen(fichierFMaillage, medenum.MED_ACC_RDEXT) + + maa, sdim, mdim, meshtype, desc, dtunit, sort, nstep, repere, axisname, axisunit = medmesh.MEDmeshInfo(fid, 1) + print "Maillage de nom : %s , de dimension : %d , et de type %s"%(maa,mdim,meshtype) + print " Dimension de l'espace : %d"%(sdim) + + # --- Combien de noeuds a lire ? + nnoe, chgt, trsf = medmesh.MEDmeshnEntity(fid, maa, medenum.MED_NO_DT, medenum.MED_NO_IT, + medenum.MED_NODE, medenum.MED_NONE, + medenum.MED_COORDINATE, medenum.MED_NO_CMODE) + + if nnoe > 0: + # --- Allocations memoire + # --- table des coordonnees flt : (dimension * nombre de noeuds ) + coords = medfile.MEDFLOAT(nnoe*sdim) + # --- table des numeros des noeuds + numnoe = medfile.MEDINT(nnoe) + + # --- Lecture des composantes des coordonnees des noeuds + medmesh.MEDmeshNodeCoordinateRd(fid, maa, medenum.MED_NO_DT, medenum.MED_NO_IT, + medenum.MED_FULL_INTERLACE, coords) + #print "Valeur de coords : ",coords + valz=medfile.MEDFLOAT([z for (i,z) in enumerate(coords) if i%3==2]) + #print "Valeur de z : ",valz + + # --- creation du champ + nomcha1 = "BOTTOM" + ncomp1 = 1 + # --1234567890123456-- + comp1 = "z " + unit1 = "m " + dtunit = "" + medfield.MEDfieldCr(fid, nomcha1, medfile.MED_FLOAT64, + ncomp1, comp1, unit1, dtunit, maa) + + # --- ecriture du champ + + medfield.MEDfieldValueWr(fid, nomcha1, medenum.MED_NO_DT, medenum.MED_NO_IT, 0.0, + medenum.MED_NODE, medenum.MED_NONE, + medenum.MED_FULL_INTERLACE, medenum.MED_ALL_CONSTITUENT, nnoe, valz) + # --- fermeture du fichier + medfile.MEDfileClose(fid) + +# ----------------------------------------------------------------------------- + +from MEDLoader import MEDLoader, MEDCouplingFieldDouble, ON_NODES, DataArrayDouble + +def createZfield2(fichierMaillage): + """ + Complete the mesh for Telemac. + Add a field on nodes, named "BOTTOM", of type double, containing z coordinates of nodes. + createZfield2 is used after interpolZ. createZfield1 is base on MEDLoader interface. + There is an alternate method based on Med file, equivalent (createZfield1). + The file F.med produced by interpolz must exist, and is modified. + fichierMaillage : 2D (x,y) med file produced by SMESH and used by interpolZ. + return L.med : med file containing the field "BOTTOM" + """ + + noms = string.split(fichierMaillage,'.') + basename = string.join(noms[:-1], '.') + fichierZMaillage = basename + 'Z.med' + fichierLMaillage = basename + 'L.med' + print fichierLMaillage + + mymesh = MEDLoader.ReadUMeshFromFile(fichierZMaillage,0) + fieldOnNodes=MEDCouplingFieldDouble.New(ON_NODES) + fieldOnNodes.setName("BOTTOM") + fieldOnNodes.setMesh(mymesh) + fieldOnNodes.setArray(mymesh.getCoords()[:,2]) + + MEDLoader.WriteField(fichierLMaillage,fieldOnNodes,True) + +# ----------------------------------------------------------------------------- + +import HYDROPy + +class MyInterpolator( HYDROPy.HYDROData_IInterpolator ): + def GetAltitudeForPoint( self, theCoordX, theCoordY ): + alt_obj = HYDROPy.HYDROData_IInterpolator.GetAltitudeObject( self ); + z = alt_obj.GetAltitudeForPoint( theCoordX, theCoordY ) # Custom calculation takes the base value and changes it to test + #z2 = (z - 74.0)*10 + z2 = z + return z2 + +# ----------------------------------------------------------------------------- + +import SMESH +import SALOMEDS +from salome.smesh import smeshBuilder + +smesh = smeshBuilder.New(theStudy) + +def interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef): + """ + interpolZ takes a 2D (x,y) mesh and calls the active instance of module HYDRO + to interpolate the bathymetry/altimetry on the mesh nodes, to produce the Z value of each node. + interpolZ must be followed by createZfield1 or createZfield2. + nomCas: Calculation Case Name in module HYDRO + fichierMaillage: med file name produced by SMESH, corresponding to the HYDRO case + dicoGroupeRegion: python dictionary giving the coorespondance of mesh groups to HYDRO regions. + Key: face group name, value: region name in the HYDRO Case + zUndef: Z value to use for nodes outside the regions (there must be none if the case is correct). + return Z.med : med file with Z value on nodes + return F.med : an exact copy of Z.med + """ + + doc = HYDROPy.HYDROData_Document.Document( theStudyId ) + cas = doc.FindObjectByName(nomCas) + print cas + custom_inter = MyInterpolator() + + noms = string.split(fichierMaillage,'.') + basename = string.join(noms[:-1], '.') + fichierZMaillage = basename + 'Z.med' + fichierFMaillage = basename + 'F.med' + fichierFonds = basename + '.xyz' + + print fichierMaillage + print fichierZMaillage + print fichierFMaillage + print fichierFonds + + regions = {} + ([maillagePlat], status) = smesh.CreateMeshesFromMED(fichierMaillage) + groups = maillagePlat.GetGroups() + + for grp in groups: + if grp.GetType() == SMESH.NODE: + grpName = grp.GetName() + print grpName + if grpName in dicoGroupeRegion.keys(): + regions[dicoGroupeRegion[grpName]] = grp + + fo = open(fichierFonds, 'w') + statz = {} + for nomreg, grp in regions.iteritems(): + print "------- region : ", nomreg + region = doc.FindObjectByName(nomreg) + #print region + #region.SetInterpolator(custom_inter) + nodesIds = grp.GetListOfID() + #print nodesIds + vx = [] + vy = [] + for nodeId in nodesIds: + xyz = maillagePlat.GetNodeXYZ(nodeId) + #print xyz + vx.append(xyz[0]) + vy.append(xyz[1]) + vz = cas.GetAltitudesForPoints( vx, vy, region ) + minz = min(vz) + maxz = max(vz) + statz[grp.GetName()] = (minz, maxz) + + + for i,nodeId in enumerate(nodesIds): + x = vx[i] + y = vy[i] + z = vz[i] + if z < -9000: + z = zUndef + #print i, nodeId, x, y, z + maillagePlat.MoveNode(nodeId, x, y, z) + l = "%10.2f %10.2f %10.2f\n"%(x, y, z) + fo.write(l) + + fo.close() + maillagePlat.ExportMED(fichierZMaillage , 0, SMESH.MED_V2_2, 1 ) + maillagePlat.ExportMED(fichierFMaillage , 0, SMESH.MED_V2_2, 1 ) + return statz + +# ----------------------------------------------------------------------------- + -- 2.39.2