diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java @ 8914:e3519c3e7a0a

Workflow for SINFO-Transport bodies heights inclduing winfo calculation
author gernotbelger
date Tue, 27 Feb 2018 18:06:52 +0100
parents 37ff7f435912
children d9dbf0b74bc2
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java	Mon Feb 26 18:10:03 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java	Tue Feb 27 18:06:52 2018 +0100
@@ -19,7 +19,6 @@
 import org.apache.commons.lang.math.DoubleRange;
 import org.apache.commons.math.FunctionEvaluationException;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
-import org.apache.log4j.Logger;
 import org.dive4elements.artifacts.ArtifactDatabase;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.BedHeightsArtifact;
@@ -47,7 +46,7 @@
 
 class FlowDepthCalculation {
 
-    private static Logger log = Logger.getLogger(FlowDepthCalculation.class);
+    // private static Logger log = Logger.getLogger(FlowDepthCalculation.class);
 
     private static final int VALID_BED_MEASUREMENT_YEARS = 20;
 
@@ -172,14 +171,14 @@
         if (doCalcTkh) {
             qInterpolator = DoubleUtil.getLinearInterpolator(((QKms) wstKms).allKms(), ((QKms) wstKms).allQs());
             if (qInterpolator != null)
-                qRange = new DoubleRange( ((QKms) wstKms).allQs().min(), ((QKms) wstKms).allQs().max());
+                qRange = new DoubleRange(((QKms) wstKms).allQs().min(), ((QKms) wstKms).allQs().max());
             else {
                 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label);
                 problems.addProblem(message);
                 doCalcTkh = false;
             }
         }
-        
+
         // FIXME: sort by station first, but in what direction?
         // FIXME: using river.getKmUp()?
         final List<BedHeightValue> values = bedHeight.getValues();
@@ -198,7 +197,7 @@
                 problems.addProblem(message);
             }
         }
-        
+
         FlowVelocityModelKmValueFinder flowVelocitiesFinder = null;
         if (doCalcTkh) {
             flowVelocitiesFinder = new FlowVelocityModelKmValueFinder();
@@ -245,60 +244,43 @@
                     double d50 = Double.NaN;
                     try {
                         d50 = bedMeasurementsFinder.findD50(km);
-                    } catch (Exception e) {
+                    }
+                    catch (final Exception e) {
                         final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingD50", null, label);
                         problems.addProblem(km, message);
-                        //FIXME: cumulate problems to one message?
+                        // FIXME: cumulate problems to one message?
                     }
                     if (!Double.isNaN(d50)) {
                         if (flowVelocitiesFinder.findKmQValues(km, discharge)) {
                             tkh = calculateTkh(wst - meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), d50, flowVelocitiesFinder.getFindTauFound());
                             if (!Double.isNaN(tkh) && (tkh < 0))
                                 tkh = 0;
-                            /* 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)); */
-                        }
-                        else {
+                            /*
+                             * 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));
+                             */
+                        } else {
                             final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label);
                             problems.addProblem(km, message);
-                            //FIXME: cumulate problems to one message?
+                            // FIXME: cumulate problems to one message?
                         }
-                    }
-                    else
+                    } else
                         tkh = Double.NaN;
                 }
-                
+
                 // Soil kind
                 SoilKind kind = SoilKind.mobil;
                 if (doCalcTkh) {
                     try {
-                        kind = soilKindFinder.findSoilKind(km);                        
-                    } catch (Exception e) {
+                        kind = soilKindFinder.findSoilKind(km);
+                    }
+                    catch (final Exception e) {
                         final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingSoilKind", null, label);
                         problems.addProblem(km, message);
-                        //FIXME: cumulate problems to one message?
+                        // FIXME: cumulate problems to one message?
                     }
                 }
-                
-                /* // REMARK: bissl spielerei zum testen damit die sohlart nicht zu schnell wechselt
-                SoilKind kind;
-                final boolean changeKind = Math.random() > 0.95;
-                if (changeKind) {
-                    switch (lastKind) {
-                    case starr:
-                        kind = SoilKind.mobil;
-                        break;
-                    case mobil:
-                    default:
-                        kind = SoilKind.starr;
-                        break;
-                    }
-                } else
-                    kind = lastKind;
-                lastKind = kind;
-                */
-                
-                //tkh = 100 + 10 * (Math.random() - 0.5);
 
                 final double flowDepthTkh;
                 final double tkhUp;
@@ -326,15 +308,14 @@
 
                 final String gaugeLabel = gauge == null ? notinrange : gauge.getName();
 
-                resultData.addRow(km, flowDepth, flowDepthTkh, kind, tkh, tkhUp, tkhDown, wst, discharge, wstLabel,
-                        gaugeLabel, meanBedHeight, bedHeightLabel, location);
+                resultData.addRow(km, flowDepth, flowDepthTkh, kind, tkh, tkhUp, tkhDown, wst, discharge, wstLabel, gaugeLabel, meanBedHeight, bedHeightLabel,
+                        location);
             }
             catch (final FunctionEvaluationException e) {
                 /* should only happen if out of range */
                 e.printStackTrace();
                 /* simply ignore */
             }
-
         }
 
         return resultData;
@@ -470,16 +451,21 @@
 
         return BedHeight.getBedHeightById(bedheightId);
     }
-    
+
     /**
      * Calculates a transport body height
-     * @param h flow depth in m
-     * @param vm flow velocity in m
-     * @param d50 grain diameter D50 in m (!)
-     * @param tau shear stress in N/m^2
+     *
+     * @param h
+     *            flow depth in m
+     * @param vm
+     *            flow velocity in m
+     * @param d50
+     *            grain diameter D50 in m (!)
+     * @param tau
+     *            shear stress in N/m^2
      * @return transport body height in cm (!)
      */
-    private double calculateTkh(double h, double vm, double d50, double tau) {
+    private double calculateTkh(final double h, final double vm, final double d50, final double tau) {
         final double PHYS_G = 9.81;
         final double PHYS_SPECGRAV_S = 2.6;
         final double PHYS_VELOCCOEFF_N = 6;
@@ -487,10 +473,10 @@
         final double PHYS_VISCOSITY_NUE = 1.3e-6;
         final double PHYS_GRAIN_DENSITY_RHOS = 2603;
         final double PHYS_WATER_DENSITY_RHO = 999.97;
-        
+
         final double froude = vm / Math.sqrt(PHYS_G * h);
         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 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);
     }

http://dive4elements.wald.intevation.org