Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowVelocityKmModelValues.java @ 8978:b5600453bb8f
SINFO Calculations: do not produce result rows if some input data has missing values.
Also check for years of waterlevels in flow depth development calculation.
author | gernotbelger |
---|---|
date | Thu, 05 Apr 2018 11:57:54 +0200 |
parents | 45f1ad66560e |
children | 9bd4505a20dc |
line wrap: on
line source
/* 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 final double km; /** * The station's discharge model values, sorted in ascending order */ private final TDoubleArrayList qs; /** * The station's main section velocity for the q values */ private final TDoubleArrayList vmains; /** * The station's shear stress (tau) values for the q values */ private final 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(final double km) { this.km = km; this.qs = new TDoubleArrayList(); this.vmains = new TDoubleArrayList(); this.taus = new TDoubleArrayList(); this.vInterpolator = null; this.tauInterpolator = null; } /** * Copy constructor with new km */ public FlowVelocityKmModelValues(final double km, final FlowVelocityKmModelValues src) { this(km); src.copyTo(this.qs, this.vmains, this.taus); } /***** METHODS *****/ /** * Number of the q-v-tau tuples */ public int size() { return this.qs.size(); } /** * Km */ public double getKm() { return this.km; } /** * Adds all q-v-tau to another set of arrays */ void copyTo(final TDoubleArrayList dstqs, final TDoubleArrayList dstvmains, final TDoubleArrayList dsttaus) { for (int i = 0; i <= this.qs.size(); i++) { dstqs.add(this.qs.getQuick(i)); dstvmains.add(this.vmains.getQuick(i)); dsttaus.add(this.taus.getQuick(i)); } } /** * Discharge found by the last {@link findQ} * * @return */ public double getFindQ() { return this.findQ; } /** * Velocity found by the last {@link findQ} */ public double getVmainFound() { return this.vmainFound; } /** * Shear stress found by the last {@link findQ} */ public double getTauFound() { return this.tauFound; } /** * Whether qFound has been interpolated */ public boolean getIsInterpolated() { return this.isInterpolated; } /** * Adds a q-v-tau value triple. */ public void addValues(final double q, final double vmain, final double tau) { this.qs.add(q); this.vmains.add(vmain); this.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(final double q) { if (this.vInterpolator == null) { this.vInterpolator = new LinearInterpolator().interpolate(this.qs.toNativeArray(), this.vmains.toNativeArray()); this.tauInterpolator = new LinearInterpolator().interpolate(this.qs.toNativeArray(), this.taus.toNativeArray()); } this.findQ = q; try { this.vmainFound = this.vInterpolator.value(q); this.tauFound = this.tauInterpolator.value(q); return q; } catch (final Exception e) { e.printStackTrace(); return Double.NaN; } } }