Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/WaterlevelValuesFinder.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 | 5d5d482da3e9 |
children |
comparison
equal
deleted
inserted
replaced
8963:b98fbd91f64a | 8964:45f1ad66560e |
---|---|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
8 * documentation coming with Dive4Elements River for details. | 8 * documentation coming with Dive4Elements River for details. |
9 */ | 9 */ |
10 package org.dive4elements.river.artifacts.sinfo.tkhcalculation; | 10 package org.dive4elements.river.artifacts.sinfo.tkhcalculation; |
11 | 11 |
12 import org.apache.commons.math.ArgumentOutsideDomainException; | 12 import org.dive4elements.river.artifacts.model.Calculation; |
13 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; | |
14 import org.dive4elements.river.artifacts.model.WKms; | 13 import org.dive4elements.river.artifacts.model.WKms; |
15 import org.dive4elements.river.utils.DoubleUtil; | 14 import org.dive4elements.river.artifacts.sinfo.util.LinearInterpolator; |
16 | 15 |
17 /** | 16 /** |
18 * Abstraction for access to waterlevels by station. | 17 * Abstraction for access to waterlevels by station. |
19 * | 18 * |
20 * @author Gernot Belger | 19 * @author Gernot Belger |
21 */ | 20 */ |
22 public class WaterlevelValuesFinder { | 21 public class WaterlevelValuesFinder { |
23 | 22 |
24 public static WaterlevelValuesFinder fromKms(final WKms wkms) { | 23 private static final double MAX_DSTANCE_KM = 1.0; |
25 return new WaterlevelValuesFinder(wkms); | 24 |
25 public static WaterlevelValuesFinder fromKms(final Calculation problems, final WKms wkms) { | |
26 return new WaterlevelValuesFinder(problems, wkms); | |
26 } | 27 } |
27 | 28 |
28 private final PolynomialSplineFunction wstInterpolator; | 29 private final LinearInterpolator wstInterpolator; |
29 | 30 |
30 private WaterlevelValuesFinder(final WKms wkms) { | 31 private WaterlevelValuesFinder(final Calculation problems, final WKms wkms) { |
31 this.wstInterpolator = DoubleUtil.getLinearInterpolator(wkms.allKms(), wkms.allWs()); | 32 this.wstInterpolator = LinearInterpolator.create(problems, wkms.allKms(), wkms.allWs(), MAX_DSTANCE_KM); |
32 } | 33 } |
33 | 34 |
34 public double getWaterlevel(final double km) { | 35 public double getWaterlevel(final double km) { |
35 try { | 36 return this.wstInterpolator.value(km); |
36 return this.wstInterpolator.value(km); | |
37 } | |
38 catch (final ArgumentOutsideDomainException e) { | |
39 e.printStackTrace(); | |
40 return Double.NaN; | |
41 } | |
42 } | 37 } |
43 } | 38 } |