annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowVelocityKmModelValues.java @ 9096:9bd4505a20dc

Fixed removing duplicates
author mschaefer
date Sat, 26 May 2018 15:41:47 +0200
parents 45f1ad66560e
children
rev   line source
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
2 * Software engineering by
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
5 *
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
9 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
10
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
11 package org.dive4elements.river.artifacts.sinfo.flowdepth;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
12
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
13 import org.apache.commons.math.analysis.interpolation.LinearInterpolator;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
14 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
15
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
16 import gnu.trove.TDoubleArrayList;
9096
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
17 import gnu.trove.TIntArrayList;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
18
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
19 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
20 * Sorted arrays of a station's q, v, and tau model values, running in parallel
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
21 *
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
22 * @author Matthias Schäfer
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
23 *
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
24 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
25 public class FlowVelocityKmModelValues {
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
26
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
27 /***** FIELDS *****/
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
28
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
29 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
30 * Km
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
31 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
32 private final double km;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
33
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
34 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
35 * The station's discharge model values, sorted in ascending order
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
36 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
37 private final TDoubleArrayList qs;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
38
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
39 /**
9096
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
40 * Same q values count used to calculate mean
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
41 */
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
42 private final TIntArrayList counts;
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
43
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
44 /**
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
45 * The station's main section velocity for the q values
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
46 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
47 private final TDoubleArrayList vmains;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
48
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
49 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
50 * The station's shear stress (tau) values for the q values
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
51 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
52 private final TDoubleArrayList taus;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
53
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
54 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
55 * Discharge found by the last findQ
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
56 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
57 private double findQ;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
58
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
59 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
60 * Velocity found by the last {@link findQ}
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
61 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
62 private double vmainFound;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
63
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
64 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
65 * Shear stress found by the last {@link findQ}
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
66 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
67 private double tauFound;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
68
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
69 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
70 * Whether qFound has been interpolated
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
71 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
72 private boolean isInterpolated;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
73
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
74 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
75 * Real linear interpolator for q and v values
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
76 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
77 private PolynomialSplineFunction vInterpolator;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
78
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
79 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
80 * Real linear interpolator for q and tau values
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
81 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
82 private PolynomialSplineFunction tauInterpolator;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
83
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
84 /***** CONSTRUCTORS *****/
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
85
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
86 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
87 * Constructor with km parameter
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
88 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
89 public FlowVelocityKmModelValues(final double km) {
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
90 this.km = km;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
91 this.qs = new TDoubleArrayList();
9096
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
92 this.counts = new TIntArrayList();
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
93 this.vmains = new TDoubleArrayList();
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
94 this.taus = new TDoubleArrayList();
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
95 this.vInterpolator = null;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
96 this.tauInterpolator = null;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
97 }
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
98
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
99 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
100 * Copy constructor with new km
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
101 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
102 public FlowVelocityKmModelValues(final double km, final FlowVelocityKmModelValues src) {
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
103 this(km);
9096
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
104 src.copyTo(this.qs, this.counts, this.vmains, this.taus);
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
105 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
106
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
107 /***** METHODS *****/
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
108
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
109 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
110 * Number of the q-v-tau tuples
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
111 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
112 public int size() {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
113 return this.qs.size();
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
114 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
115
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
116 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
117 * Km
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
118 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
119 public double getKm() {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
120 return this.km;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
121 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
122
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
123 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
124 * Adds all q-v-tau to another set of arrays
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
125 */
9096
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
126 void copyTo(final TDoubleArrayList dstqs, final TIntArrayList dstcounts, final TDoubleArrayList dstvmains, final TDoubleArrayList dsttaus) {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
127 for (int i = 0; i <= this.qs.size(); i++) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
128 dstqs.add(this.qs.getQuick(i));
9096
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
129 dstcounts.add(this.counts.getQuick(i));
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
130 dstvmains.add(this.vmains.getQuick(i));
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
131 dsttaus.add(this.taus.getQuick(i));
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
132 }
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
133 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
134
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
135 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
136 * Discharge found by the last {@link findQ}
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
137 *
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
138 * @return
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
139 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
140 public double getFindQ() {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
141 return this.findQ;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
142 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
143
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
144 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
145 * Velocity found by the last {@link findQ}
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
146 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
147 public double getVmainFound() {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
148 return this.vmainFound;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
149 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
150
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
151 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
152 * Shear stress found by the last {@link findQ}
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
153 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
154 public double getTauFound() {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
155 return this.tauFound;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
156 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
157
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
158 /**
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
159 * Whether qFound has been interpolated
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
160 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
161 public boolean getIsInterpolated() {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
162 return this.isInterpolated;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
163 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
164
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
165 /**
9096
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
166 * Adds a q-v-tau value triple, averaging the last values if q duplicates.
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
167 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
168 public void addValues(final double q, final double vmain, final double tau) {
9096
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
169 final int j = this.qs.size() - 1;
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
170 if ((j >= 0) && (q < this.qs.getQuick(j) + 0.001)) {
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
171 this.qs.setQuick(j, (this.qs.getQuick(j) * this.counts.getQuick(j) + q) / (this.counts.getQuick(j) + 1));
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
172 this.vmains.setQuick(j, (this.vmains.getQuick(j) * this.counts.getQuick(j) + vmain) / (this.counts.getQuick(j) + 1));
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
173 this.taus.setQuick(j, (this.taus.getQuick(j) * this.counts.getQuick(j) + tau) / (this.counts.getQuick(j) + 1));
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
174 this.counts.setQuick(j, this.counts.getQuick(j) + 1);
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
175 }
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
176 else {
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
177 this.qs.add(q);
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
178 this.counts.add(1);
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
179 this.vmains.add(vmain);
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
180 this.taus.add(tau);
9bd4505a20dc Fixed removing duplicates
mschaefer
parents: 8964
diff changeset
181 }
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
182 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
183
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
184 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
185 * Searches a discharge value and returns it or the interpolated value
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
186 *
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
187 * @return Found or interpolated discharge, or NaN otherwise
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
188 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
189 public double findQ(final double q) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
190 if (this.vInterpolator == null) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
191 this.vInterpolator = new LinearInterpolator().interpolate(this.qs.toNativeArray(), this.vmains.toNativeArray());
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
192 this.tauInterpolator = new LinearInterpolator().interpolate(this.qs.toNativeArray(), this.taus.toNativeArray());
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
193 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
194
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
195 this.findQ = q;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
196
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
197 try {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
198 this.vmainFound = this.vInterpolator.value(q);
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
199 this.tauFound = this.tauInterpolator.value(q);
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
200 return q;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
201 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
202 catch (final Exception e) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
203 e.printStackTrace();
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
204 return Double.NaN;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
205 }
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
206 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8898
diff changeset
207 }

http://dive4elements.wald.intevation.org