Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/FlowVelocityModelKmValueFinder.java @ 9149:5be112fba832
Updated/added reference data files for S-Info tests
author | mschaefer |
---|---|
date | Thu, 14 Jun 2018 15:12:25 +0200 |
parents | 9bd4505a20dc |
children | 1899595a8070 |
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 | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
11 package org.dive4elements.river.artifacts.sinfo.tkhcalculation; |
8898 | 12 |
13 import java.util.ArrayList; | |
14 import java.util.List; | |
15 | |
16 import org.apache.commons.lang.math.DoubleRange; | |
17 import org.apache.log4j.Logger; | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
18 import org.dive4elements.river.artifacts.math.Linear; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
19 import org.dive4elements.river.artifacts.math.Utils; |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
20 import org.dive4elements.river.artifacts.model.Calculation; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
21 import org.dive4elements.river.artifacts.sinfo.flowdepth.FlowVelocityKmModelValues; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
22 import org.dive4elements.river.backend.SessionHolder; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
23 import org.dive4elements.river.model.River; |
8898 | 24 import org.hibernate.SQLQuery; |
25 import org.hibernate.Session; | |
26 import org.hibernate.type.StandardBasicTypes; | |
27 | |
28 import gnu.trove.TDoubleArrayList; | |
29 | |
30 /** | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
31 * Searchable sorted km array with parallel FlowVelocityKmModelValues array and linear interpolation for km and the |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
32 * model values between the array elements.<br /> |
8898 | 33 * {@link loadValues} loads all the model values for a given km range of a river.<br /> |
34 * {@link findKmQValues} then searches a km in the values table or the nearest including km interval, resp. | |
35 * The v and tau values for a given discharge are either found directly or also interpolated linearly.<br /> | |
36 * | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
37 * (Created based on a copy of FlowVelocityMeasurementFactory.) |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
38 * |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
39 * @author Matthias Schäfer |
8898 | 40 */ |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
41 final class FlowVelocityModelKmValueFinder { |
9092 | 42 |
8898 | 43 /***** FIELDS *****/ |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
44 |
8898 | 45 /** |
46 * Private log to use here. | |
47 */ | |
48 private static Logger log = Logger.getLogger(FlowVelocityModelKmValueFinder.class); | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
49 |
8898 | 50 /** |
51 * Query for a range of stations of a river with all their q, main-v and tau values.<br /> | |
52 * (Might be several 10000 rows if many stations and large q range) | |
53 */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
54 private static final String SQL_SELECT_ALL = // |
9096 | 55 "SELECT fvmv.station AS station, fvmv.q AS q, fvmv.main_channel AS vmain, fvmv.shear_stress AS tau" |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
56 + " FROM (discharge_zone dz INNER JOIN flow_velocity_model fvm ON dz.id = fvm.discharge_zone_id)" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
57 + " INNER JOIN flow_velocity_model_values fvmv ON fvm.id = fvmv.flow_velocity_model_id" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
58 + " WHERE (dz.river_id = :river_id) AND (fvmv.station BETWEEN :kmfrom - 0.0001 AND :kmto + 0.0001)" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
59 /* + " WHERE (dz.river_id = :river_id) AND (fvmv.q BETWEEN :qmin AND :qmax)" */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
60 + " ORDER BY fvmv.station ASC, fvmv.q ASC"; |
8898 | 61 |
62 /** | |
63 * Query for a river's max km below a limit with all its q, main-v and tau values. | |
64 */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
65 private static final String SQL_SELECT_KMLOWER = // |
9096 | 66 "SELECT fvmv.station AS station, fvmv.q AS q, fvmv.main_channel AS vmain, fvmv.shear_stress AS tau" |
9095
1b24fdbf7fe2
Fixed flow velocity query by distinct clause to avoid duplicates
mschaefer
parents:
9092
diff
changeset
|
67 + " FROM flow_velocity_model_values fvmv" |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
68 + " INNER JOIN (SELECT MAX(fvmvi.station) AS kmmax" |
9096 | 69 + " FROM discharge_zone dz INNER JOIN flow_velocity_model fvm ON dz.id = fvm.discharge_zone_id" |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
70 + " INNER JOIN flow_velocity_model_values fvmvi ON fvm.id = fvmvi.flow_velocity_model_id" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
71 + " WHERE (dz.river_id = :river_id) AND (fvmvi.station < :kmfrom - 0.0001)) finf ON fvmv.station = finf.kmmax" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
72 + " ORDER BY fvmv.q ASC"; |
8898 | 73 |
74 /** | |
75 * Query for a river's min km above a limit with all its q, main-v and tau values. | |
76 */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
77 private static final String SQL_SELECT_KMUPPER = // |
9096 | 78 "SELECT fvmv.station AS station, fvmv.q AS q, fvmv.main_channel AS vmain, fvmv.shear_stress AS tau" |
9095
1b24fdbf7fe2
Fixed flow velocity query by distinct clause to avoid duplicates
mschaefer
parents:
9092
diff
changeset
|
79 + " FROM flow_velocity_model_values fvmv" |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
80 + " INNER JOIN (SELECT MIN(fvmvi.station) AS kmmin" |
9096 | 81 + " FROM discharge_zone dz INNER JOIN flow_velocity_model fvm ON dz.id = fvm.discharge_zone_id" |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
82 + " INNER JOIN flow_velocity_model_values fvmvi ON fvm.id = fvmvi.flow_velocity_model_id" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
83 + " WHERE (dz.river_id = :river_id) AND (fvmvi.station > :kmto + 0.0001)) fsup ON fvmv.station = fsup.kmmin" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
84 + " ORDER BY fvmv.q ASC"; |
8898 | 85 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
86 // /** |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
87 // * Query to select all km-q-v-tau of a river that are the q maxima below a q limit |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
88 // */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
89 // private static final String SQL_SELECT_QLOWER = |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
90 // "SELECT fvmv.station AS station, fvmv.q AS q, fvmv.main_channel AS vmain, fvmv.shear_stress AS tau" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
91 // + " FROM flow_velocity_model_values fvmv" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
92 // + " INNER JOIN (SELECT fv2.station, MAX(fv2.q) AS q" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
93 // + " FROM (discharge_zone dz INNER JOIN flow_velocity_model fvm ON dz.id = fvm.discharge_zone_id)" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
94 // + " INNER JOIN flow_velocity_model_values fv2 ON fvm.id = fv2.flow_velocity_model_id" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
95 // + " WHERE (dz.river_id = :river_id) AND (fv2.q < :qlim) GROUP BY fv2.station) qx" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
96 // + " ON (fvmv.station=qx.station) AND (fvmv.q=qx.q)" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
97 // + " ORDER BY fvmv.station ASC"; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
98 // |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
99 // /** |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
100 // * Query to select all km-q-v-tau of a river that are the q minima above a q limit |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
101 // */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
102 // private static final String SQL_SELECT_QUPPER = |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
103 // "SELECT fvmv.station AS station, fvmv.q AS q, fvmv.main_channel AS vmain, fvmv.shear_stress AS tau" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
104 // + " FROM flow_velocity_model_values fvmv" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
105 // + " INNER JOIN (SELECT fv2.station, MIN(fv2.q) AS q" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
106 // + " FROM (discharge_zone dz INNER JOIN flow_velocity_model fvm ON dz.id = fvm.discharge_zone_id)" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
107 // + " INNER JOIN flow_velocity_model_values fv2 ON fvm.id = fv2.flow_velocity_model_id" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
108 // + " WHERE (dz.river_id = :river_id) AND (fv2.q > :qlim) GROUP BY fv2.station) qx" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
109 // + " ON (fvmv.station=qx.station) AND (fvmv.q=qx.q)" |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
110 // + " ORDER BY fvmv.station ASC"; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
111 |
8898 | 112 /** |
113 * Kms of the loaded river range | |
114 */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
115 private final TDoubleArrayList kms = new TDoubleArrayList(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
116 |
8898 | 117 /** |
118 * For each km in kms a list of q-v-tau-tupels | |
119 */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
120 private final List<FlowVelocityKmModelValues> values = new ArrayList<>(); |
8898 | 121 |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
122 private Calculation problems; |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
123 |
8898 | 124 /** |
125 * Searched km of the last findKmValue | |
126 */ | |
127 private double findKm; | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
128 |
8898 | 129 /** |
130 * kms and values index of the interval start found by the last findKmValue | |
131 */ | |
132 private int leftIndexFound = -1; | |
133 | |
134 /** | |
135 * kms and values index of the interval end found by the last findKmValue | |
136 */ | |
137 private int rightIndexFound = -1; | |
138 | |
139 /** | |
140 * Q of the last findKmQValues | |
141 */ | |
142 private double findQ; | |
143 | |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
144 public FlowVelocityModelKmValueFinder(final Calculation problems) { |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
145 this.problems = problems; |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
146 } |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
147 |
8898 | 148 /***** METHODS *****/ |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
149 |
8898 | 150 /** |
151 * Discharge of the last {@link findKmQValue} | |
152 */ | |
153 public double getFindQ() { | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
154 return this.findQ; |
8898 | 155 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
156 |
8898 | 157 /** |
158 * Velocity of the last {@link findKmQValues} | |
159 */ | |
160 public double getFindVmainFound() { | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
161 if (this.leftIndexFound < 0) |
8898 | 162 return Double.NaN; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
163 else if (this.leftIndexFound == this.rightIndexFound) |
8898 | 164 return getLeftValues().getVmainFound(); |
165 else | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
166 return Linear.linear(this.findKm, getLeftValues().getKm(), getRightValues().getKm(), getLeftValues().getVmainFound(), |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
167 getRightValues().getVmainFound()); |
8898 | 168 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
169 |
8898 | 170 /** |
171 * Shear stress tau of the last {@link findKmQValues} | |
172 */ | |
173 public double getFindTauFound() { | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
174 if (this.leftIndexFound < 0) |
8898 | 175 return Double.NaN; |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
176 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
177 if (this.leftIndexFound == this.rightIndexFound) |
8898 | 178 return getLeftValues().getTauFound(); |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
179 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
180 return Linear.linear(this.findKm, getLeftValues().getKm(), getRightValues().getKm(), getLeftValues().getTauFound(), getRightValues().getTauFound()); |
8898 | 181 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
182 |
8898 | 183 /** |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
184 * Whether the discharge has been interpolated in the last {@link findKmQValues} |
8898 | 185 */ |
186 public boolean getFindIsQInterpolated() { | |
187 return (getLeftValues() != null) && (getLeftValues().getIsInterpolated() || getRightValues().getIsInterpolated()); | |
188 } | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
189 |
8898 | 190 /** |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
191 * Static constructor: queries a range of a river's kms with all their q-v-tau values. |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
192 * |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
193 * @param problems |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
194 * |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
195 * @return Whether the load has been successful the new instance, <code>null</code> otherwise. |
8898 | 196 */ |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
197 public static FlowVelocityModelKmValueFinder loadValues(final Calculation problems, final River river, final DoubleRange kmRange, |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
198 final DoubleRange qRange) { |
8898 | 199 // DB session |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
200 log.debug(String.format("loadValues km %.3f - %.3f / q %.1f - %.1f", kmRange.getMinimumDouble(), kmRange.getMaximumDouble(), qRange.getMinimumDouble(), |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
201 qRange.getMaximumDouble())); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
202 |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
203 final FlowVelocityModelKmValueFinder instance = new FlowVelocityModelKmValueFinder(problems); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
204 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
205 final TDoubleArrayList kms = instance.kms; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
206 final List<FlowVelocityKmModelValues> values = instance.values; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
207 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
208 final boolean isDemoValuesCorrection = river.getName().equalsIgnoreCase("beispielfluss"); |
8898 | 209 final Session session = SessionHolder.HOLDER.get(); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
210 |
8898 | 211 // Select km infimum |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
212 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_KMLOWER).addScalar("station", StandardBasicTypes.DOUBLE).addScalar("q", StandardBasicTypes.DOUBLE) |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
213 .addScalar("vmain", StandardBasicTypes.DOUBLE).addScalar("tau", StandardBasicTypes.DOUBLE); |
8898 | 214 sqlQuery.setParameter("river_id", river.getId()); |
215 sqlQuery.setParameter("kmfrom", kmRange.getMinimumDouble()); | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
216 instance.addKms(sqlQuery.list(), isDemoValuesCorrection); |
8898 | 217 |
218 // Select km range | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
219 sqlQuery = session.createSQLQuery(SQL_SELECT_ALL).addScalar("station", StandardBasicTypes.DOUBLE).addScalar("q", StandardBasicTypes.DOUBLE) |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
220 .addScalar("vmain", StandardBasicTypes.DOUBLE).addScalar("tau", StandardBasicTypes.DOUBLE); |
8898 | 221 sqlQuery.setParameter("river_id", river.getId()); |
222 sqlQuery.setParameter("kmfrom", kmRange.getMinimumDouble()); | |
223 sqlQuery.setParameter("kmto", kmRange.getMaximumDouble()); | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
224 // sqlQuery.setParameter("qmin", qRange.getMinimumDouble()); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
225 // sqlQuery.setParameter("qmax", qRange.getMaximumDouble()); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
226 |
8898 | 227 int kmcount = kms.size(); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
228 final int rowcount = instance.addKms(sqlQuery.list(), isDemoValuesCorrection); |
8898 | 229 kmcount = kms.size() - kmcount; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
230 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
231 // Select km supremum |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
232 sqlQuery = session.createSQLQuery(SQL_SELECT_KMUPPER).addScalar("station", StandardBasicTypes.DOUBLE).addScalar("q", StandardBasicTypes.DOUBLE) |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
233 .addScalar("vmain", StandardBasicTypes.DOUBLE).addScalar("tau", StandardBasicTypes.DOUBLE); |
8898 | 234 sqlQuery.setParameter("river_id", river.getId()); |
235 sqlQuery.setParameter("kmto", kmRange.getMaximumDouble()); | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
236 final int supcnt = instance.addKms(sqlQuery.list(), isDemoValuesCorrection); |
8898 | 237 |
238 // Add copy of last km for search of max km value | |
239 if ((supcnt == 0) && (values.size() >= 1)) { | |
240 kms.add(kms.getQuick(kms.size()) + 0.0001); | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
241 values.add(new FlowVelocityKmModelValues(kms.getQuick(kms.size() - 1), values.get(values.size() - 1))); |
8898 | 242 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
243 |
8898 | 244 // log.debug |
245 if (values.size() - 1 >= 0) { | |
246 log.debug(String.format("loadValues %d: km %.3f - %d values", 0, values.get(0).getKm(), values.get(0).size())); | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
247 |
8898 | 248 if (values.size() - 1 >= 1) { |
249 log.debug(String.format("loadValues %d: km %.3f - %d values", 1, values.get(1).getKm(), values.get(1).size())); | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
250 |
8898 | 251 if (values.size() - 1 >= 2) |
252 log.debug("loadValues ..."); | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
253 |
8898 | 254 if (values.size() - 2 >= 3) |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
255 log.debug(String.format("loadValues %d: km %.3f - %d values", values.size() - 2, values.get(values.size() - 2).getKm(), |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
256 values.get(values.size() - 2).size())); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
257 |
8898 | 258 if (values.size() - 1 >= 3) |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
259 log.debug(String.format("loadValues %d: km %.3f - %d values", values.size() - 1, values.get(values.size() - 1).getKm(), |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
260 values.get(values.size() - 1).size())); |
8898 | 261 } |
262 } | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
263 |
8898 | 264 log.debug(String.format("loadValues %d kms, %d values loaded", kmcount, rowcount)); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
265 |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
266 if (kms.size() == 0) { |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
267 problems.addProblem("flowvelocitymodelkmvaluefinder.empty"); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
268 return null; |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
269 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
270 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
271 return instance; |
8898 | 272 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
273 |
8898 | 274 /** |
275 * Adds the km-q-v-tau values of a query result row to the last km of the list, or a new one resp. | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
276 * |
8898 | 277 * @return Number of rows |
278 */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
279 private int addKms(final List<Object[]> rows, final boolean isDemoValuesCorrection) { |
9096 | 280 log.trace("addKms i km j q v tau"); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
281 for (final Object[] row : rows) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
282 if ((this.kms.size() == 0) || !Utils.epsilonEquals(this.kms.get(this.kms.size() - 1), (double) row[0], 0.0001)) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
283 this.kms.add((double) row[0]); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
284 this.values.add(new FlowVelocityKmModelValues(this.kms.get(this.kms.size() - 1))); |
8898 | 285 } |
286 if (isDemoValuesCorrection) | |
287 // "Verfremdung" der v-Werte etwas korrigieren (Originalwerte wurden mit Zufallswert zwischen 10 und 20 multipliziert) | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
288 this.values.get(this.values.size() - 1).addValues((double) row[1], ((double) row[2]) / 10, (double) row[3]); |
8898 | 289 else |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
290 this.values.get(this.values.size() - 1).addValues((double) row[1], (double) row[2], (double) row[3]); |
9092 | 291 final int j = this.values.size() - 1; |
9096 | 292 log.trace(String.format("addKms %d %.3f %d %.0f %.2f %.2f", this.values.size() - 1, this.values.get(j).getKm(), |
293 this.values.get(j).size() - 1, (double) row[1], (double) row[2], (double) row[3])); | |
8898 | 294 } |
295 return rows.size(); | |
296 } | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
297 |
8898 | 298 /** |
299 * Searches a km and finds or interpolates the velocity and shear stress values for a discharge<br /> | |
300 * The values may be got via {@link getVmainFound} etc. | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
301 * |
8898 | 302 * @return Whether values have been found |
303 */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
304 public boolean findKmQValues(final double km, final double q) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
305 this.findQ = q; |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
306 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
307 final boolean found = doFindKmQValues(km, q); |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
308 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
309 if (this.problems != null) { |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
310 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
311 this.problems.addProblem(km, "flowvelocitymodelkmvaluefinder.missing"); |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
312 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
313 // report only once |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
314 this.problems = null; |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
315 } |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
316 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
317 return found; |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
318 } |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
319 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
320 private boolean doFindKmQValues(final double km, final double q) { |
8898 | 321 if (!searchKm(km)) |
322 return false; | |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
323 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
324 if (this.leftIndexFound == this.rightIndexFound) { |
8898 | 325 // Exact km match |
326 final double qfound = getLeftValues().findQ(q); | |
9149
5be112fba832
Updated/added reference data files for S-Info tests
mschaefer
parents:
9096
diff
changeset
|
327 log.trace(String.format("findKmQValues km %.3f q %.0f = %.0f (%d, %.3f) - %.0f (%d, %.3f) v = %.3f, tau = %.3f", km, q, qfound, this.leftIndexFound, |
5be112fba832
Updated/added reference data files for S-Info tests
mschaefer
parents:
9096
diff
changeset
|
328 km, qfound, this.rightIndexFound, km, this.getFindVmainFound(), this.getFindTauFound())); |
8898 | 329 return !Double.isNaN(qfound); |
330 } | |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
331 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
332 final double[] qfound = { getLeftValues().findQ(q), getRightValues().findQ(q) }; |
9149
5be112fba832
Updated/added reference data files for S-Info tests
mschaefer
parents:
9096
diff
changeset
|
333 log.trace(String.format("findKmQValues km %.3f q %.0f = %.0f (%d, %.3f) - %.0f (%d, %.3f) v = %.3f, tau = %.3f", km, q, qfound[0], this.leftIndexFound, |
9017 | 334 getLeftValues().getKm(), qfound[1], this.rightIndexFound, getRightValues().getKm(), this.getFindVmainFound(), this.getFindTauFound())); |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
335 return !Double.isNaN(qfound[0]) && !Double.isNaN(qfound[1]); |
8898 | 336 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
337 |
8898 | 338 /** |
339 * Searches a km | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
340 * |
8898 | 341 * @return Whether the km was within the supported range |
342 */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
343 private boolean searchKm(final double km) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
344 this.findKm = km; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
345 this.leftIndexFound = -1; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
346 this.rightIndexFound = -1; |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
347 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
348 int i = this.kms.binarySearch(km); |
8898 | 349 if (i >= 0) { |
350 // Exact km match | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
351 this.leftIndexFound = i; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
352 this.rightIndexFound = i; |
8898 | 353 return true; |
354 } | |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
355 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
356 // Out of range or within km interval |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
357 if (i < 0) |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
358 i = -i - 1; |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
359 if ((i <= 0) || (i >= this.kms.size())) |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
360 return false; |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
361 this.leftIndexFound = i - 1; |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
362 this.rightIndexFound = i; |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8915
diff
changeset
|
363 return true; |
8898 | 364 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
365 |
8898 | 366 private FlowVelocityKmModelValues getLeftValues() { |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
367 return this.values.get(this.leftIndexFound); |
8898 | 368 } |
369 | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
370 private FlowVelocityKmModelValues getRightValues() { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
371 return this.values.get(this.rightIndexFound); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
372 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8898
diff
changeset
|
373 } |