Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java @ 8915:d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
author | gernotbelger |
---|---|
date | Wed, 28 Feb 2018 17:27:15 +0100 |
parents | |
children | b10f8415798c |
comparison
equal
deleted
inserted
replaced
8914:e3519c3e7a0a | 8915:d9dbf0b74bc2 |
---|---|
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 package org.dive4elements.river.artifacts.sinfo.tkhcalculation; | |
11 | |
12 import org.apache.commons.lang.math.DoubleRange; | |
13 import org.apache.commons.math.FunctionEvaluationException; | |
14 import org.apache.commons.math.analysis.UnivariateRealFunction; | |
15 import org.dive4elements.river.artifacts.model.QKms; | |
16 import org.dive4elements.river.artifacts.model.WKms; | |
17 import org.dive4elements.river.artifacts.model.WQKms; | |
18 import org.dive4elements.river.utils.DoubleUtil; | |
19 | |
20 /** | |
21 * @author Gernot Belger | |
22 */ | |
23 public final class DischargeValuesFinder { | |
24 | |
25 private final UnivariateRealFunction qInterpolator; | |
26 private final QKms qKms; | |
27 | |
28 /** | |
29 * Create an instance from a {@link WKms} object. If the given {@link WKms} is not a {@link WQKms}, a finder that always | |
30 * returns {@link Double#NaN} is returned. | |
31 */ | |
32 public static DischargeValuesFinder fromKms(final WKms wstKms) { | |
33 if (!(wstKms instanceof QKms)) { | |
34 return new DischargeValuesFinder(null); | |
35 } | |
36 | |
37 final QKms qKms = (QKms) wstKms; | |
38 | |
39 return new DischargeValuesFinder(qKms); | |
40 } | |
41 | |
42 public DischargeValuesFinder(final QKms qKms) { | |
43 this.qKms = qKms; | |
44 this.qInterpolator = qKms == null ? null : DoubleUtil.getLinearInterpolator(qKms.allKms(), qKms.allQs()); | |
45 } | |
46 | |
47 /** | |
48 * If this provider may return valid data at all. | |
49 */ | |
50 public boolean isValid() { | |
51 return this.qInterpolator != null; | |
52 } | |
53 | |
54 public DoubleRange getRange() { | |
55 return new DoubleRange(this.qKms.allQs().min(), this.qKms.allQs().max()); | |
56 } | |
57 | |
58 public double getDischarge(final double station) throws FunctionEvaluationException { | |
59 return this.qInterpolator.value(station); | |
60 } | |
61 } |