diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java @ 8915:d9dbf0b74bc2

Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
author gernotbelger
date Wed, 28 Feb 2018 17:27:15 +0100
parents
children b10f8415798c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java	Wed Feb 28 17:27:15 2018 +0100
@@ -0,0 +1,61 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.sinfo.tkhcalculation;
+
+import org.apache.commons.lang.math.DoubleRange;
+import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.dive4elements.river.artifacts.model.QKms;
+import org.dive4elements.river.artifacts.model.WKms;
+import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.utils.DoubleUtil;
+
+/**
+ * @author Gernot Belger
+ */
+public final class DischargeValuesFinder {
+
+    private final UnivariateRealFunction qInterpolator;
+    private final QKms qKms;
+
+    /**
+     * Create an instance from a {@link WKms} object. If the given {@link WKms} is not a {@link WQKms}, a finder that always
+     * returns {@link Double#NaN} is returned.
+     */
+    public static DischargeValuesFinder fromKms(final WKms wstKms) {
+        if (!(wstKms instanceof QKms)) {
+            return new DischargeValuesFinder(null);
+        }
+
+        final QKms qKms = (QKms) wstKms;
+
+        return new DischargeValuesFinder(qKms);
+    }
+
+    public DischargeValuesFinder(final QKms qKms) {
+        this.qKms = qKms;
+        this.qInterpolator = qKms == null ? null : DoubleUtil.getLinearInterpolator(qKms.allKms(), qKms.allQs());
+    }
+
+    /**
+     * If this provider may return valid data at all.
+     */
+    public boolean isValid() {
+        return this.qInterpolator != null;
+    }
+
+    public DoubleRange getRange() {
+        return new DoubleRange(this.qKms.allQs().min(), this.qKms.allQs().max());
+    }
+
+    public double getDischarge(final double station) throws FunctionEvaluationException {
+        return this.qInterpolator.value(station);
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org