Repository: parflow/parflow (language: python)

Issue:
pfmask-to-pfsol argument bug

We may have uncovered a bug (or swap / typo really) in the pftools pfmask-to-pfsol code.  We are setting up a mask from a PFB solid file using the more simple workflow and are passing the flags for the top and bottom.  From the readme:

https://github.com/parflow/parflow/tree/master/pftools#readme

using this setup:

pfmask-to-pfsol    --mask <top mask input filename>  --vtk <VTK output filename>     --pfsol <PFSOL output filename>   --bottom-patch-label <bottom patch id>   --side-patch-label <side_patch id>

my commands look like

>$PARFLOW_DIR/bin/pfmask-to-pfsol --mask Taylor_1983.mask-2.pfb --vtk MaskTaylor.vtk --pfsol Taylor.pfsol --bottom-patch-label 2 --side-patch-label 3 

The mask file looks good, etc, but is too small for the domain (we need it to be 0 to 1000m).  When we add the top and bottom flags as follows

$PARFLOW_DIR/bin/pfmask-to-pfsol --mask Taylor_1983.mask-2.pfb --vtk MaskTaylor.vtk --pfsol Taylor.pfsol --bottom-patch-label 2 --side-patch-label 3 --z-top 1000.0 --z-bottom 0.0

it runs but gives us a weird mask in the ParFlow output and takes *for ever* to set up the domain.  I noticed the values for bottom are larger than the top in the example and flipped them as an experiment:

$PARFLOW_DIR/bin/pfmask-to-pfsol --mask Taylor_1983.mask-2.pfb --vtk MaskTaylor.vtk --pfsol Taylor.pfsol --bottom-patch-label 2 --side-patch-label 3 --z-top 0.0 --z-bottom 1000.0

This produces a solid file that runs smoothly.  Are the flags for the top and bottom arguments flipped?  This might be worth swapping, but I want to make sure before I put in an issue.


Discussion / hints:

Fix patch:
diff --git a/pftools/README.md b/pftools/README.md
index 442d4796c..e81ab62b2 100644
--- a/pftools/README.md
+++ b/pftools/README.md
@@ -63,11 +63,11 @@ number of points in Z = 1.
 #### Setting Top/Bottom of domain
 
 The mask file is typically coming from a 2D file so does not have any
-depth information.  By default the top is 0 and bottom is 1000.0.  The
+depth information.  By default the top is 1000.0 and bottom is 0.0.  The
 top and bottom can be set using the "--z-top" and "--z-bottom" flags:
 
 ```shell
-pfmask-to-pfsol --z-top 10.0 --z-bottom 200.0
+pfmask-to-pfsol --z-top 200.0 --z-bottom 10.0
 ```
 
 ### Mask ASC file format
diff --git a/pftools/pfmask-to-pfsol.cpp b/pftools/pfmask-to-pfsol.cpp
index b9079dff5..a65496f70 100644
--- a/pftools/pfmask-to-pfsol.cpp
+++ b/pftools/pfmask-to-pfsol.cpp
@@ -436,22 +436,27 @@ int main(int argc, char **argv)
   dy = DataboxDy(databox[0]);
 
   // If user specifies Top/Bottom on command line override defaults
-  if(isnan(zTop))
+  if(isnan(zBot))
   {
     sz = 0.0;
   }
   else
   {
-    sz = zTop;
+    sz = zBot;
   }
 
-  if(isnan(zBot))
+  if(isnan(zTop))
   {
     dz = DataboxDz(databox[0]);
   }
   else
   {
-    dz = zBot - sz;
+    if ( zTop < sz )
+    {
+      cerr << "Top must be > bottom (top is " << zTop << " bottom " << sz<< "\n";
+      exit(-2);
+    }
+    dz = zTop - sz;
   }
 
   cout << "Domain Size = (" << nx << "," << ny << "," << nz << ")" << std::endl;


Test patch:
diff --git a/pftools/test/CMakeLists.txt b/pftools/test/CMakeLists.txt
index 8ebe94333..ac50f3315 100644
--- a/pftools/test/CMakeLists.txt
+++ b/pftools/test/CMakeLists.txt
@@ -6,8 +6,8 @@ foreach(testname mask-test-1 mask-test-2 mask-test-3 mask-test-4 mask-test-5 mas
   pf_add_mask_test(${testname} "${testname}.asc" TEST_ARGS "--bottom-patch-label" "2" "--side-patch-label" "3")
 endforeach()
 
-pf_add_mask_test("depth-test-1" "depth-test-1.asc" TEST_ARGS "--bottom-patch-label" "2" "--side-patch-label" "3" "--z-bottom" "1000.0")
-pf_add_mask_test("depth-test-2" "depth-test-2.asc" TEST_ARGS "--bottom-patch-label" "2" "--side-patch-label" "3" "--z-top" "100.0" "--z-bottom" "1000.0")
+pf_add_mask_test("depth-test-1" "depth-test-1.asc" TEST_ARGS "--bottom-patch-label" "2" "--side-patch-label" "3" "--z-top" "1000.0" "--z-bottom" "0.0")
+pf_add_mask_test("depth-test-2" "depth-test-2.asc" TEST_ARGS "--bottom-patch-label" "2" "--side-patch-label" "3" "--z-top" "1000.0" "--z-bottom" "100.0")
 
 foreach(testname multiple-mask-test-1)
   pf_add_multi_mask_test(${testname} "${testname}.asc")