Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowVelocityKmModelValues.java @ 8898:89f3c5462a16
Implemented S-INFO Flowdepth TKH calculation
author | mschaefer |
---|---|
date | Thu, 22 Feb 2018 12:03:31 +0100 |
parents | |
children | 45f1ad66560e |
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/flowdepth/FlowVelocityKmModelValues.java Thu Feb 22 12:03:31 2018 +0100 @@ -0,0 +1,186 @@ +/* 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.flowdepth; + +import org.apache.commons.math.analysis.interpolation.LinearInterpolator; +import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; + +import gnu.trove.TDoubleArrayList; + +/** + * Sorted arrays of a station's q, v, and tau model values, running in parallel + * @author Matthias Schäfer + * + */ +public class FlowVelocityKmModelValues { + + /***** FIELDS *****/ + + /** + * Km + */ + private double km; + + /** + * The station's discharge model values, sorted in ascending order + */ + private TDoubleArrayList qs; + + /** + * The station's main section velocity for the q values + */ + private TDoubleArrayList vmains; + + /** + * The station's shear stress (tau) values for the q values + */ + private TDoubleArrayList taus; + + /** + * Discharge found by the last findQ + */ + private double findQ; + + /** + * Velocity found by the last {@link findQ} + */ + private double vmainFound; + + /** + * Shear stress found by the last {@link findQ} + */ + private double tauFound; + + /** + * Whether qFound has been interpolated + */ + private boolean isInterpolated; + + /** + * Real linear interpolator for q and v values + */ + private PolynomialSplineFunction vInterpolator; + + /** + * Real linear interpolator for q and tau values + */ + private PolynomialSplineFunction tauInterpolator; + + + /***** CONSTRUCTORS *****/ + + /** + * Constructor with km parameter + */ + public FlowVelocityKmModelValues(double km) { + this.km = km; + qs = new TDoubleArrayList(); + vmains = new TDoubleArrayList(); + taus = new TDoubleArrayList(); + vInterpolator = null; + tauInterpolator = null; + } + + /** + * Copy constructor with new km + */ + public FlowVelocityKmModelValues(double km, FlowVelocityKmModelValues src) { + this(km); + src.copyTo(qs, vmains, taus); + } + + /***** METHODS *****/ + + /** + * Number of the q-v-tau tuples + */ + public int size() { + if (qs != null) + return qs.size(); + else + return 0; + } + + /** + * Km + */ + public double getKm() { + return km; + } + + /** + * Adds all q-v-tau to another set of arrays + */ + void copyTo(TDoubleArrayList dstqs, TDoubleArrayList dstvmains, TDoubleArrayList dsttaus) { + for (int i = 0; i <= qs.size(); i++) { + dstqs.add(qs.getQuick(i)); + dstvmains.add(vmains.getQuick(i)); + dsttaus.add(taus.getQuick(i)); + } + } + + /** + * Discharge found by the last {@link findQ} + * @return + */ + public double getFindQ() { + return findQ; + } + + /** + * Velocity found by the last {@link findQ} + */ + public double getVmainFound() { + return vmainFound; + } + + /** + * Shear stress found by the last {@link findQ} + */ + public double getTauFound() { + return tauFound; + } + + /** + * Whether qFound has been interpolated + */ + public boolean getIsInterpolated() { + return isInterpolated; + } + + /** + * Adds a q-v-tau value triple. + */ + public void addValues(double q, double vmain, double tau) { + qs.add(q); + vmains.add(vmain); + taus.add(tau); + } + + /** + * Searches a discharge value and returns it or the interpolated value + * @return Found or interpolated discharge, or NaN otherwise + */ + public double findQ(double q) { + if (vInterpolator == null) { + vInterpolator = new LinearInterpolator().interpolate(qs.toNativeArray(), vmains.toNativeArray()); + tauInterpolator = new LinearInterpolator().interpolate(qs.toNativeArray(), taus.toNativeArray()); + } + findQ = q; + try { + vmainFound = vInterpolator.value(q); + tauFound = tauInterpolator.value(q); + } catch (Exception e) { + q = Double.NaN; + } + return q; + } +}