Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowVelocityKmModelValues.java @ 8898:89f3c5462a16
Implemented S-INFO Flowdepth TKH calculation
author | mschaefer |
---|---|
date | Thu, 22 Feb 2018 12:03:31 +0100 |
parents | |
children | 45f1ad66560e |
comparison
equal
deleted
inserted
replaced
8891:f431aec10d2c | 8898:89f3c5462a16 |
---|---|
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 | |
20 * @author Matthias Schäfer | |
21 * | |
22 */ | |
23 public class FlowVelocityKmModelValues { | |
24 | |
25 /***** FIELDS *****/ | |
26 | |
27 /** | |
28 * Km | |
29 */ | |
30 private double km; | |
31 | |
32 /** | |
33 * The station's discharge model values, sorted in ascending order | |
34 */ | |
35 private TDoubleArrayList qs; | |
36 | |
37 /** | |
38 * The station's main section velocity for the q values | |
39 */ | |
40 private TDoubleArrayList vmains; | |
41 | |
42 /** | |
43 * The station's shear stress (tau) values for the q values | |
44 */ | |
45 private TDoubleArrayList taus; | |
46 | |
47 /** | |
48 * Discharge found by the last findQ | |
49 */ | |
50 private double findQ; | |
51 | |
52 /** | |
53 * Velocity found by the last {@link findQ} | |
54 */ | |
55 private double vmainFound; | |
56 | |
57 /** | |
58 * Shear stress found by the last {@link findQ} | |
59 */ | |
60 private double tauFound; | |
61 | |
62 /** | |
63 * Whether qFound has been interpolated | |
64 */ | |
65 private boolean isInterpolated; | |
66 | |
67 /** | |
68 * Real linear interpolator for q and v values | |
69 */ | |
70 private PolynomialSplineFunction vInterpolator; | |
71 | |
72 /** | |
73 * Real linear interpolator for q and tau values | |
74 */ | |
75 private PolynomialSplineFunction tauInterpolator; | |
76 | |
77 | |
78 /***** CONSTRUCTORS *****/ | |
79 | |
80 /** | |
81 * Constructor with km parameter | |
82 */ | |
83 public FlowVelocityKmModelValues(double km) { | |
84 this.km = km; | |
85 qs = new TDoubleArrayList(); | |
86 vmains = new TDoubleArrayList(); | |
87 taus = new TDoubleArrayList(); | |
88 vInterpolator = null; | |
89 tauInterpolator = null; | |
90 } | |
91 | |
92 /** | |
93 * Copy constructor with new km | |
94 */ | |
95 public FlowVelocityKmModelValues(double km, FlowVelocityKmModelValues src) { | |
96 this(km); | |
97 src.copyTo(qs, vmains, taus); | |
98 } | |
99 | |
100 /***** METHODS *****/ | |
101 | |
102 /** | |
103 * Number of the q-v-tau tuples | |
104 */ | |
105 public int size() { | |
106 if (qs != null) | |
107 return qs.size(); | |
108 else | |
109 return 0; | |
110 } | |
111 | |
112 /** | |
113 * Km | |
114 */ | |
115 public double getKm() { | |
116 return km; | |
117 } | |
118 | |
119 /** | |
120 * Adds all q-v-tau to another set of arrays | |
121 */ | |
122 void copyTo(TDoubleArrayList dstqs, TDoubleArrayList dstvmains, TDoubleArrayList dsttaus) { | |
123 for (int i = 0; i <= qs.size(); i++) { | |
124 dstqs.add(qs.getQuick(i)); | |
125 dstvmains.add(vmains.getQuick(i)); | |
126 dsttaus.add(taus.getQuick(i)); | |
127 } | |
128 } | |
129 | |
130 /** | |
131 * Discharge found by the last {@link findQ} | |
132 * @return | |
133 */ | |
134 public double getFindQ() { | |
135 return findQ; | |
136 } | |
137 | |
138 /** | |
139 * Velocity found by the last {@link findQ} | |
140 */ | |
141 public double getVmainFound() { | |
142 return vmainFound; | |
143 } | |
144 | |
145 /** | |
146 * Shear stress found by the last {@link findQ} | |
147 */ | |
148 public double getTauFound() { | |
149 return tauFound; | |
150 } | |
151 | |
152 /** | |
153 * Whether qFound has been interpolated | |
154 */ | |
155 public boolean getIsInterpolated() { | |
156 return isInterpolated; | |
157 } | |
158 | |
159 /** | |
160 * Adds a q-v-tau value triple. | |
161 */ | |
162 public void addValues(double q, double vmain, double tau) { | |
163 qs.add(q); | |
164 vmains.add(vmain); | |
165 taus.add(tau); | |
166 } | |
167 | |
168 /** | |
169 * Searches a discharge value and returns it or the interpolated value | |
170 * @return Found or interpolated discharge, or NaN otherwise | |
171 */ | |
172 public double findQ(double q) { | |
173 if (vInterpolator == null) { | |
174 vInterpolator = new LinearInterpolator().interpolate(qs.toNativeArray(), vmains.toNativeArray()); | |
175 tauInterpolator = new LinearInterpolator().interpolate(qs.toNativeArray(), taus.toNativeArray()); | |
176 } | |
177 findQ = q; | |
178 try { | |
179 vmainFound = vInterpolator.value(q); | |
180 tauFound = tauInterpolator.value(q); | |
181 } catch (Exception e) { | |
182 q = Double.NaN; | |
183 } | |
184 return q; | |
185 } | |
186 } |