Mercurial > dive4elements > river
annotate 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 |
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; | |
17 | |
18 /** | |
19 * 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
|
20 * |
8898 | 21 * @author Matthias Schäfer |
22 * | |
23 */ | |
24 public class FlowVelocityKmModelValues { | |
25 | |
26 /***** 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
|
27 |
8898 | 28 /** |
29 * Km | |
30 */ | |
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
|
31 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
|
32 |
8898 | 33 /** |
34 * The station's discharge model values, sorted in ascending order | |
35 */ | |
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
|
36 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
|
37 |
8898 | 38 /** |
39 * The station's main section velocity for the q values | |
40 */ | |
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
|
41 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
|
42 |
8898 | 43 /** |
44 * The station's shear stress (tau) values for the q values | |
45 */ | |
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
|
46 private final TDoubleArrayList taus; |
8898 | 47 |
48 /** | |
49 * Discharge found by the last findQ | |
50 */ | |
51 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
|
52 |
8898 | 53 /** |
54 * Velocity found by the last {@link findQ} | |
55 */ | |
56 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
|
57 |
8898 | 58 /** |
59 * Shear stress found by the last {@link findQ} | |
60 */ | |
61 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
|
62 |
8898 | 63 /** |
64 * Whether qFound has been interpolated | |
65 */ | |
66 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
|
67 |
8898 | 68 /** |
69 * Real linear interpolator for q and v values | |
70 */ | |
71 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
|
72 |
8898 | 73 /** |
74 * Real linear interpolator for q and tau values | |
75 */ | |
76 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
|
77 |
8898 | 78 /***** 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
|
79 |
8898 | 80 /** |
81 * Constructor with km parameter | |
82 */ | |
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 public FlowVelocityKmModelValues(final double km) { |
8898 | 84 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
|
85 this.qs = 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
|
86 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
|
87 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
|
88 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
|
89 this.tauInterpolator = null; |
8898 | 90 } |
91 | |
92 /** | |
93 * Copy constructor with new km | |
94 */ | |
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
|
95 public FlowVelocityKmModelValues(final double km, final FlowVelocityKmModelValues src) { |
8898 | 96 this(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
|
97 src.copyTo(this.qs, this.vmains, this.taus); |
8898 | 98 } |
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
|
99 |
8898 | 100 /***** 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
|
101 |
8898 | 102 /** |
103 * Number of the q-v-tau tuples | |
104 */ | |
105 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
|
106 return this.qs.size(); |
8898 | 107 } |
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 * Km | |
111 */ | |
112 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
|
113 return this.km; |
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 * Adds all q-v-tau to another set of arrays | |
118 */ | |
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
|
119 void copyTo(final TDoubleArrayList dstqs, final TDoubleArrayList dstvmains, final TDoubleArrayList dsttaus) { |
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 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
|
121 dstqs.add(this.qs.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
|
122 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
|
123 dsttaus.add(this.taus.getQuick(i)); |
8898 | 124 } |
125 } | |
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
|
126 |
8898 | 127 /** |
128 * 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
|
129 * |
8898 | 130 * @return |
131 */ | |
132 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
|
133 return this.findQ; |
8898 | 134 } |
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
|
135 |
8898 | 136 /** |
137 * Velocity found by the last {@link findQ} | |
138 */ | |
139 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
|
140 return this.vmainFound; |
8898 | 141 } |
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
|
142 |
8898 | 143 /** |
144 * Shear stress found by the last {@link findQ} | |
145 */ | |
146 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
|
147 return this.tauFound; |
8898 | 148 } |
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
|
149 |
8898 | 150 /** |
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
|
151 * Whether qFound has been interpolated |
8898 | 152 */ |
153 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
|
154 return this.isInterpolated; |
8898 | 155 } |
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
|
156 |
8898 | 157 /** |
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
|
158 * Adds a q-v-tau value triple. |
8898 | 159 */ |
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
|
160 public void addValues(final double q, final double vmain, final double tau) { |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8898
diff
changeset
|
161 this.qs.add(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
|
162 this.vmains.add(vmain); |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8898
diff
changeset
|
163 this.taus.add(tau); |
8898 | 164 } |
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
|
165 |
8898 | 166 /** |
167 * 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
|
168 * |
8898 | 169 * @return Found or interpolated discharge, or NaN otherwise |
170 */ | |
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
|
171 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
|
172 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
|
173 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
|
174 this.tauInterpolator = new LinearInterpolator().interpolate(this.qs.toNativeArray(), this.taus.toNativeArray()); |
8898 | 175 } |
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
|
176 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8898
diff
changeset
|
177 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
|
178 |
8898 | 179 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
|
180 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
|
181 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
|
182 return q; |
8898 | 183 } |
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
|
184 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
|
185 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
|
186 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
|
187 } |
8898 | 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 } |