diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java @ 8920:29442c03c6e3

d50 aggregation by median instead of arithmetic mean, negative tkh replaced by 0
author mschaefer
date Thu, 01 Mar 2018 09:01:58 +0100
parents 5d5d0051723f
children 9c02733a1b3c
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java	Wed Feb 28 18:55:39 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java	Thu Mar 01 09:01:58 2018 +0100
@@ -58,7 +58,7 @@
                 VALID_BED_MEASUREMENT_YEARS);
 
         if (bedMeasurementsFinder == null) {
-            final String message = Resources.getMsg(context.getMeta(), "sinfo_calc_flow_depth.warning.missingSoilKind", null, label);
+            final String message = Resources.getMsg(context.getMeta(), "sinfo_calc_flow_depth.warning.missingD50", null, label);
             problems.addProblem(message);
             return null;
         }
@@ -159,29 +159,13 @@
 
         if (!this.flowVelocitiesFinder.findKmQValues(km, discharge)) {
             // TODO: ggf. station in Fehlermeldung?
-            final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, this.problemLabel);
+            final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingVelocity", null, this.problemLabel);
             this.problems.addProblem(km, message);
             // FIXME: cumulate problems to one message?
+            return new Tkh(km, wst, meanBedHeight, discharge, kind, Double.NaN, Double.NaN, Double.NaN);
         }
 
         final double tkh = calculateTkh(wst - meanBedHeight, this.flowVelocitiesFinder.getFindVmainFound(), d50, this.flowVelocitiesFinder.getFindTauFound());
-        // FIXME: noch mal prüfen, im alten code wurde hier immer auf 0 gesetzt
-        if (Double.isNaN(tkh) || (tkh < 0)) {
-            // TODO: ggf. station in Fehlermeldung?
-
-            // FIXME: Fehlermeldung nicht korrekt, passiert mit Wasserspiegel 'MHQ' und 'QP-1993
-            final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, this.problemLabel);
-            this.problems.addProblem(km, message);
-
-            return new Tkh(km, wst, meanBedHeight, discharge, kind, Double.NaN, Double.NaN, Double.NaN);
-        }
-
-        /*
-         * log.debug(String.format("calculateTkh km %.3f q %.0f w %.2f mbh %.2f vm %.1f tau %.1f d50(mm) %.1f tkh(cm) %.1f",
-         * km, discharge, wst, meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), flowVelocitiesFinder.getFindTauFound(),
-         * d50*1000, tkh));
-         */
-
         double tkhUp;
         double tkhDown;
         switch (kind) {
@@ -211,7 +195,7 @@
      *            grain diameter D50 in m (!)
      * @param tau
      *            shear stress in N/m^2
-     * @return transport body height in cm (!)
+     * @return transport body height in cm (!), never negative
      */
     private double calculateTkh(final double h, final double vm, final double d50, final double tau) {
         final double PHYS_G = 9.81;
@@ -226,6 +210,11 @@
         final double partReynolds = Math.sqrt((PHYS_SPECGRAV_S - 1) * PHYS_G * d50) / PHYS_VISCOSITY_NUE * d50;
         final double critShields = 0.22 * Math.pow(partReynolds, -0.6) + 0.06 * Math.pow(10, 7.7 * Math.pow(partReynolds, -0.6));
         final double critTau = critShields * (PHYS_GRAIN_DENSITY_RHOS - PHYS_WATER_DENSITY_RHO) * PHYS_G * d50;
-        return 100 * h * (1 - Math.pow(froude, 2)) / (2 * PHYS_VELOCCOEFF_N * PHYS_FORMCOEFF_ALPHA) * (1 - critTau / tau);
+        final double tkh = 100 * h * (1 - Math.pow(froude, 2)) / (2 * PHYS_VELOCCOEFF_N * PHYS_FORMCOEFF_ALPHA) * (1 - critTau / tau);
+        // Some regular input values may give a negative calculation result; that is unwanted
+        if (tkh < 0.0)
+            return 0.0;
+        else
+            return tkh;
     }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org