Salome HOME
correction test case H015
[modules/hydro.git] / doc / salome / examples / h014_caseDigueManualInterpolZ.py
index 174c6bee343ba9394138cfa976169412fc10adb9..d5469b30eaf4a6474a04e52da3f8490f880158f2 100644 (file)
@@ -8,14 +8,14 @@ import salome
 
 salome.salome_init()
 theStudy = salome.myStudy
-  
+
 #----------------------
-# --- HYDRO 
+# --- HYDRO
 #----------------------
 
 from HYDROPy import *
-from PyQt4.QtCore import *
-from PyQt4.QtGui import *
+from PyQt5.QtCore import *
+from PyQt5.QtGui import *
 
 hydro_doc = HYDROData_Document.Document( theStudy._get_StudyId() )
 
@@ -219,7 +219,8 @@ 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" ))
+if not(Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" ))):
+  raise ValueError('problem while loading bathymetry')
 
 Cloud_02.Update()
 
@@ -228,7 +229,8 @@ 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" ))
+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()
 
@@ -342,24 +344,42 @@ garonne_2.SetBoundaryPolyline( domaine );
 
 # Start the algorithm of the partition and assignment
 garonne_2.Update();
-garonne_2_litMineur = hydro_doc.FindObjectByName( "garonne_2_Reg_1" );
-garonne_2_Zone_1 = hydro_doc.FindObjectByName( "garonne_2_Zone_1" );
+
+garonne_2_litMineur = hydro_doc.FindObjectByName( "garonne_2_Reg_1" )
+garonne_2_Zone_1 = hydro_doc.FindObjectByName( "garonne_2_Zone_1" )
 garonne_2_Zone_1.SetMergeType( HYDROData_Zone.Merge_ZMIN )
-garonne_2_litMineur.AddZone( garonne_2_Zone_1 );
-garonne_2_riveDroite = hydro_doc.FindObjectByName( "garonne_2_Reg_2" );
-garonne_2_Zone_2 = hydro_doc.FindObjectByName( "garonne_2_Zone_2" );
-garonne_2_riveDroite.AddZone( garonne_2_Zone_2 );
-garonne_2_Zone_3 = hydro_doc.FindObjectByName( "garonne_2_Zone_3" );
-garonne_2_riveDroite.AddZone( garonne_2_Zone_3 );
-garonne_2_riveGauche = hydro_doc.FindObjectByName( "garonne_2_Reg_3" );
-garonne_2_Zone_4 = hydro_doc.FindObjectByName( "garonne_2_Zone_4" );
-garonne_2_riveGauche.AddZone( garonne_2_Zone_4 );
-garonne_2_Zone_5 = hydro_doc.FindObjectByName( "garonne_2_Zone_5" );
-garonne_2_riveGauche.AddZone( garonne_2_Zone_5 );
-garonne_2_digue = hydro_doc.FindObjectByName( "garonne_2_Reg_4" );
-garonne_2_Zone_6 = hydro_doc.FindObjectByName( "garonne_2_Zone_6" );
+garonne_2_Zone_1.SetColor( QColor( 192, 137, 64 ))
+garonne_2_litMineur.AddZone( garonne_2_Zone_1 )
+
+garonne_2_riveDroite = hydro_doc.FindObjectByName( "garonne_2_Reg_2" )
+garonne_2_Zone_2 = hydro_doc.FindObjectByName( "garonne_2_Zone_2" )
+garonne_2_Zone_2.SetColor( QColor( 64, 192, 98 ))
+garonne_2_riveDroite.AddZone( garonne_2_Zone_2 )
+
+garonne_2_Zone_3 = hydro_doc.FindObjectByName( "garonne_2_Zone_3" )
+garonne_2_Zone_3.SetMergeType( HYDROData_Zone.Merge_Object )
+Cloud_02 = hydro_doc.FindObjectByName( "Cloud_02" )
+garonne_2_Zone_3.SetMergeObject( Cloud_02 )
+garonne_2_Zone_3.SetColor( QColor( 64, 66, 192 ))
+garonne_2_riveDroite.AddZone( garonne_2_Zone_3 )
+
+garonne_2_riveGauche = hydro_doc.FindObjectByName( "garonne_2_Reg_3" )
+garonne_2_Zone_4 = hydro_doc.FindObjectByName( "garonne_2_Zone_4" )
+garonne_2_Zone_4.SetMergeType( HYDROData_Zone.Merge_Object )
+Cloud_02 = hydro_doc.FindObjectByName( "Cloud_02" )
+garonne_2_Zone_4.SetMergeObject( Cloud_02 )
+garonne_2_Zone_4.SetColor( QColor( 64, 192, 164 ))
+garonne_2_riveGauche.AddZone( garonne_2_Zone_4 )
+
+garonne_2_Zone_5 = hydro_doc.FindObjectByName( "garonne_2_Zone_5" )
+garonne_2_Zone_5.SetColor( QColor( 192, 149, 64 ))
+garonne_2_riveGauche.AddZone( garonne_2_Zone_5 )
+
+garonne_2_digue = hydro_doc.FindObjectByName( "garonne_2_Reg_4" )
+garonne_2_Zone_6 = hydro_doc.FindObjectByName( "garonne_2_Zone_6" )
 garonne_2_Zone_6.SetMergeType( HYDROData_Zone.Merge_ZMAX )
-garonne_2_digue.AddZone( garonne_2_Zone_6 );
+garonne_2_Zone_6.SetColor( QColor( 64, 192, 177 ))
+garonne_2_digue.AddZone( garonne_2_Zone_6 )
 
 garonne_2_litMineur.SetName("garonne_2_litMineur")
 garonne_2_riveDroite.SetName("garonne_2_riveDroite")
@@ -370,7 +390,7 @@ garonne_2_digue.SetName("garonne_2_digue")
 garonne_2_entry = garonne_2.Export( theStudy._get_StudyId() )
 
 #----------------------
-# --- Geometry 
+# --- Geometry
 #----------------------
 
 # Get geometry shape and print debug information
@@ -394,14 +414,14 @@ geompy.addToStudyInFather( HYDRO_garonne_2, litMineur, 'litMineur' )
 geompy.addToStudyInFather( HYDRO_garonne_2, riveDroite, 'riveDroite' )
 
 SectionsGaronne = geompy.CreateGroup(HYDRO_garonne_2, geompy.ShapeType["EDGE"])
-geompy.UnionIDs(SectionsGaronne, [4, 11])
+geompy.UnionIDs(SectionsGaronne, [7, 9])
 geompy.addToStudyInFather( HYDRO_garonne_2, SectionsGaronne, 'SectionsGaronne' )
 
 SectionsDigue = geompy.CreateGroup(HYDRO_garonne_2, geompy.ShapeType["EDGE"])
-geompy.UnionIDs(SectionsDigue, [46, 50])
+geompy.UnionIDs(SectionsDigue, [40, 35])
 geompy.addToStudyInFather( HYDRO_garonne_2, SectionsDigue, 'SectionsDigue' )
 
-# --- recreate subshapes already exported from HYDRO to get access from Python 
+# --- recreate subshapes already exported from HYDRO to get access from Python
 #garonne_2_domaineEtendu_Outer = geompy.CreateGroup(HYDRO_garonne_2, geompy.ShapeType["EDGE"])
 #geompy.UnionIDs(garonne_2_domaineEtendu_Outer, [4, 11, 17, 24, 26, 28, 14, 19, 20, 22, 31, 39, 41, 33, 35, 37])
 #garonne_2_digue_Left_Bank = geompy.CreateGroup(HYDRO_garonne_2, geompy.ShapeType["EDGE"])
@@ -415,13 +435,13 @@ geompy.addToStudyInFather( HYDRO_garonne_2, SectionsDigue, 'SectionsDigue' )
 #garonne_2_digue_Right_Bank = geompy.CreateGroup(HYDRO_garonne_2, geompy.ShapeType["EDGE"])
 #geompy.UnionIDs(garonne_2_digue_Right_Bank, [48])
 
-controlGeomProps(geompy, riveGauche,  39493.270103, 35885901.558025)
-controlGeomProps(geompy, digue,       10343.900923,   103893.397004)
-controlGeomProps(geompy, litMineur,   30337.548492,  3646827.749809)
-controlGeomProps(geompy, riveDroite,  32012.343241, 26177085.460092)
+controlGeomProps(geompy, riveGauche,  39490.835288, 35845737.590926)
+controlGeomProps(geompy, digue,       10341.466108,   103090.760662)
+controlGeomProps(geompy, litMineur,   30337.548492,  3488480.304388)
+controlGeomProps(geompy, riveDroite,  32012.343241, 25998769.23615)
 
 #----------------------
-# --- Meshing 
+# --- Meshing
 #----------------------
 
 import  SMESH, SALOMEDS
@@ -504,9 +524,23 @@ digue_2 = garonne_2.GroupOnGeom(digue,'digue',SMESH.NODE)
 #bordDroiteDomaine_2 = garonne_2.GroupOnGeom(bordDroiteDomaine,'bordDroiteDomaine',SMESH.NODE)
 SectionsGaronne_3 = garonne_2.GroupOnGeom(SectionsGaronne,'SectionsGaronne',SMESH.NODE)
 
+
+med_file = r'/tmp/garonne_2.med'
+
+try:
+  os.remove(med_file)
+except OSError:
+  pass
+
+
 garonne_2.SetAutoColor( 1 )
-garonne_2.ExportMED( r'/tmp/garonne_2.med', 0, SMESH.MED_V2_2, 1, None ,1)
+garonne_2.ExportMED( med_file, 0, SMESH.MED_V2_2, 1, None ,1)
 
+#controlMeshStats(garonne_2, 5247, 717, 10075)
+#controlSubMeshStats(litMineur_2, 2384)
+#controlSubMeshStats(riveDroite_1, 2348)
+#controlSubMeshStats(riveGauche_1, 5343)
+#controlSubMeshStats(digue_1, 0)
 controlMeshStats(garonne_2, 6190, 691, 12201)
 controlSubMeshStats(litMineur_2, 2384)
 controlSubMeshStats(riveDroite_1, 2400)
@@ -517,7 +551,7 @@ if salome.sg.hasDesktop():
   salome.sg.updateObjBrowser(1)
 
 #----------------------
-# --- Z interpolation with HYDRO 
+# --- Z interpolation with HYDRO
 #----------------------
 
 from salome.hydrotools.interpolZ import interpolZ, createZfield2
@@ -527,7 +561,7 @@ from salome.hydrotools.controls import controlStatZ
 nomCas = 'garonne_2'
 
 # --- med file 2D(x,y) of the case produced by SMESH
-fichierMaillage = '/tmp/garonne_2.med'
+fichierMaillage = med_file
 
 # --- dictionary [med group name] = region name
 dicoGroupeRegion= dict(litMineur  = 'garonne_2_litMineur',
@@ -535,13 +569,13 @@ dicoGroupeRegion= dict(litMineur  = 'garonne_2_litMineur',
                        riveGauche = 'garonne_2_riveGauche',
                        digue      = 'garonne_2_digue',
                        )
-# --- value to use for Z when the node is not in a region (used to detect problems)                       
+# --- 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)
+refstatz = {'riveDroite': (10.88, 32.61), 'riveGauche': (7.72, 71.86, 0.5), 'litMineur': (2.06, 25.41), 'digue': (14.10,27.09)}
+controlStatZ(statz, refstatz)
 
 # --- add a field on nodes of type double with z values, named "BOTTOM"
 createZfield2(fichierMaillage)