Mercurial > dive4elements > river
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 | 1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 | |
11 package org.dive4elements.river.artifacts.sinfo.flowdepth; | |
12 | |
13 import org.apache.commons.math.analysis.interpolation.LinearInterpolator; | |
14 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; | |
15 | |
16 import gnu.trove.TDoubleArrayList; | |
9096 | 17 import gnu.trove.TIntArrayList; |
8898 | 18 |
19 /** | |
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 | 22 * @author Matthias Schäfer |
23 * | |
24 */ | |
25 public class FlowVelocityKmModelValues { | |
26 | |
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 | 29 /** |
30 * Km | |
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 | 34 /** |
35 * The station's discharge model values, sorted in ascending order | |
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 | 39 /** |
9096 | 40 * Same q values count used to calculate mean |
41 */ | |
42 private final TIntArrayList counts; | |
43 | |
44 /** | |
8898 | 45 * The station's main section velocity for the q values |
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 | 49 /** |
50 * The station's shear stress (tau) values for the q values | |
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 | 53 |
54 /** | |
55 * Discharge found by the last findQ | |
56 */ | |
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 | 59 /** |
60 * Velocity found by the last {@link findQ} | |
61 */ | |
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 | 64 /** |
65 * Shear stress found by the last {@link findQ} | |
66 */ | |
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 | 69 /** |
70 * Whether qFound has been interpolated | |
71 */ | |
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 | 74 /** |
75 * Real linear interpolator for q and v values | |
76 */ | |
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 | 79 /** |
80 * Real linear interpolator for q and tau values | |
81 */ | |
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 | 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 | 86 /** |
87 * Constructor with km parameter | |
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 | 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 | 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 | 97 } |
98 | |
99 /** | |
100 * Copy constructor with new km | |
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 | 103 this(km); |
9096 | 104 src.copyTo(this.qs, this.counts, this.vmains, this.taus); |
8898 | 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 | 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 | 109 /** |
110 * Number of the q-v-tau tuples | |
111 */ | |
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 | 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 | 116 /** |
117 * Km | |
118 */ | |
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 | 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 | 123 /** |
124 * Adds all q-v-tau to another set of arrays | |
125 */ | |
9096 | 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 | 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 | 132 } |
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 | 135 /** |
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 | 138 * @return |
139 */ | |
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 | 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 | 144 /** |
145 * Velocity found by the last {@link findQ} | |
146 */ | |
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 | 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 | 151 /** |
152 * Shear stress found by the last {@link findQ} | |
153 */ | |
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 | 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 | 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 | 160 */ |
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 | 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 | 165 /** |
9096 | 166 * Adds a q-v-tau value triple, averaging the last values if q duplicates. |
8898 | 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 | 169 final int j = this.qs.size() - 1; |
170 if ((j >= 0) && (q < this.qs.getQuick(j) + 0.001)) { | |
171 this.qs.setQuick(j, (this.qs.getQuick(j) * this.counts.getQuick(j) + q) / (this.counts.getQuick(j) + 1)); | |
172 this.vmains.setQuick(j, (this.vmains.getQuick(j) * this.counts.getQuick(j) + vmain) / (this.counts.getQuick(j) + 1)); | |
173 this.taus.setQuick(j, (this.taus.getQuick(j) * this.counts.getQuick(j) + tau) / (this.counts.getQuick(j) + 1)); | |
174 this.counts.setQuick(j, this.counts.getQuick(j) + 1); | |
175 } | |
176 else { | |
177 this.qs.add(q); | |
178 this.counts.add(1); | |
179 this.vmains.add(vmain); | |
180 this.taus.add(tau); | |
181 } | |
8898 | 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 | 184 /** |
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 | 187 * @return Found or interpolated discharge, or NaN otherwise |
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 | 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 | 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 | 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 | 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 } |