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