Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowVelocityKmModelValues.java @ 8964:45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
author | gernotbelger |
---|---|
date | Thu, 29 Mar 2018 15:48:17 +0200 |
parents | 89f3c5462a16 |
children | 9bd4505a20dc |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowVelocityKmModelValues.java Wed Mar 28 17:04:20 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowVelocityKmModelValues.java Thu Mar 29 15:48:17 2018 +0200 @@ -17,170 +17,173 @@ /** * 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; - + private final double km; + /** * The station's discharge model values, sorted in ascending order */ - private TDoubleArrayList qs; - + private final TDoubleArrayList qs; + /** * The station's main section velocity for the q values */ - private TDoubleArrayList vmains; - + private final TDoubleArrayList vmains; + /** * The station's shear stress (tau) values for the q values */ - private TDoubleArrayList taus; + 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(double km) { + public FlowVelocityKmModelValues(final double km) { this.km = km; - qs = new TDoubleArrayList(); - vmains = new TDoubleArrayList(); - taus = new TDoubleArrayList(); - vInterpolator = null; - tauInterpolator = null; + 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(double km, FlowVelocityKmModelValues src) { + public FlowVelocityKmModelValues(final double km, final FlowVelocityKmModelValues src) { this(km); - src.copyTo(qs, vmains, taus); + src.copyTo(this.qs, this.vmains, this.taus); } - + /***** METHODS *****/ - + /** * Number of the q-v-tau tuples */ public int size() { - if (qs != null) - return qs.size(); - else - return 0; + return this.qs.size(); } - + /** * Km */ public double getKm() { - return km; + return this.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)); + 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 findQ; + return this.findQ; } - + /** * Velocity found by the last {@link findQ} */ public double getVmainFound() { - return vmainFound; + return this.vmainFound; } - + /** * Shear stress found by the last {@link findQ} */ public double getTauFound() { - return tauFound; + return this.tauFound; } - + /** - * Whether qFound has been interpolated + * Whether qFound has been interpolated */ public boolean getIsInterpolated() { - return isInterpolated; + return this.isInterpolated; } - + /** - * Adds a q-v-tau value triple. + * 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); + 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(double q) { - if (vInterpolator == null) { - vInterpolator = new LinearInterpolator().interpolate(qs.toNativeArray(), vmains.toNativeArray()); - tauInterpolator = new LinearInterpolator().interpolate(qs.toNativeArray(), taus.toNativeArray()); + 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()); } - findQ = q; + + this.findQ = q; + try { - vmainFound = vInterpolator.value(q); - tauFound = tauInterpolator.value(q); - } catch (Exception e) { - q = Double.NaN; + this.vmainFound = this.vInterpolator.value(q); + this.tauFound = this.tauInterpolator.value(q); + return q; } - return q; + catch (final Exception e) { + e.printStackTrace(); + return Double.NaN; + } } -} +} \ No newline at end of file