Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java @ 8951:322b0e6298ea
Work on SINFO FlowDepth-Development
author | gernotbelger |
---|---|
date | Fri, 16 Mar 2018 18:08:38 +0100 |
parents | 5d5d482da3e9 |
children | 45f1ad66560e |
rev | line source |
---|---|
8854 | 1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
8877 | 2 * Software engineering by |
3 * Björnsen Beratende Ingenieure GmbH | |
8854 | 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.flowdepth; | |
11 | |
12 import java.util.Collection; | |
13 | |
8894 | 14 import org.apache.commons.lang.math.DoubleRange; |
8854 | 15 import org.dive4elements.artifacts.CallContext; |
16 import org.dive4elements.river.artifacts.model.Calculation; | |
17 import org.dive4elements.river.artifacts.model.CalculationResult; | |
18 import org.dive4elements.river.artifacts.model.WKms; | |
19 import org.dive4elements.river.artifacts.resources.Resources; | |
20 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
21 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
22 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.DischargeValuesFinder; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
23 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.TkhCalculator; |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
24 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.WaterlevelValuesFinder; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
25 import org.dive4elements.river.artifacts.sinfo.tkhstate.BedHeightsFinder; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
26 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils; |
8894 | 27 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; |
28 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; | |
8882 | 29 import org.dive4elements.river.artifacts.states.WaterlevelData; |
30 import org.dive4elements.river.artifacts.states.WaterlevelFetcher; | |
8854 | 31 import org.dive4elements.river.model.River; |
32 | |
33 class FlowDepthCalculation { | |
34 | |
8914
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8911
diff
changeset
|
35 // private static Logger log = Logger.getLogger(FlowDepthCalculation.class); |
8898 | 36 |
8877 | 37 private final CallContext context; |
8854 | 38 |
8882 | 39 public FlowDepthCalculation(final CallContext context) { |
8877 | 40 this.context = context; |
8854 | 41 } |
42 | |
8877 | 43 public CalculationResult calculate(final SINFOArtifact sinfo) { |
8854 | 44 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
45 final String user = CalculationUtils.findArtifactUser(this.context, sinfo); |
8854 | 46 |
8877 | 47 /* access input data */ |
48 final FlowDepthAccess access = new FlowDepthAccess(sinfo); | |
49 final River river = access.getRiver(); | |
8894 | 50 final RiverInfo riverInfo = new RiverInfo(river); |
8854 | 51 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
52 final Collection<WstSoundingIdPair> diffPairs = access.getDifferencePairs(); |
8877 | 53 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
54 final DoubleRange calcRange = access.getRange(); |
8877 | 55 |
56 final boolean useTkh = access.isUseTransportBodies(); | |
57 | |
58 /* calculate results for each diff pair */ | |
59 final Calculation problems = new Calculation(); | |
60 | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
61 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange); |
8877 | 62 |
8882 | 63 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); |
8877 | 64 |
8894 | 65 final FlowDepthCalculationResults results = new FlowDepthCalculationResults(calcModeLabel, user, riverInfo, calcRange, useTkh); |
8877 | 66 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
67 for (final WstSoundingIdPair diffPair : diffPairs) { |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
68 final FlowDepthCalculationResult result = calculateResult(calcRange, diffPair, problems, infoProvider, useTkh); |
8882 | 69 if (result != null) |
8877 | 70 results.addResult(result); |
71 } | |
72 | |
8882 | 73 return new CalculationResult(results, problems); |
8877 | 74 } |
75 | |
8898 | 76 /** |
77 * Calculates one W-MSH differences pair. | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
78 * |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
79 * @param infoProvider |
8898 | 80 */ |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
81 private FlowDepthCalculationResult calculateResult(final DoubleRange calcRange, final WstSoundingIdPair diffPair, final Calculation problems, |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
82 final RiverInfoProvider infoProvider, final boolean useTkh) { |
8877 | 83 |
84 /* access real input data from database */ | |
85 final String soundingId = diffPair.getSoundingId(); | |
86 final String wstId = diffPair.getWstId(); | |
87 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
88 final BedHeightsFinder bedHeight = BedHeightsFinder.forId(this.context, soundingId, calcRange, problems); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
89 if (bedHeight == null) |
8877 | 90 return null; |
91 | |
8882 | 92 /* REMARK: fetch ALL wst kms, because we want to determine the original reference gauge */ |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
93 final WaterlevelData waterlevel = new WaterlevelFetcher().findWaterlevel(this.context, wstId, Double.NaN, Double.NaN, problems); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
94 if (waterlevel == null) |
8877 | 95 return null; |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
96 |
8882 | 97 final WKms wstKms = waterlevel.getWkms(); |
98 | |
8883 | 99 final String wspLabel = wstKms.getName(); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
100 final String soundingLabel = bedHeight.getInfo().getDescription(); |
8883 | 101 final String label = String.format("%s - %s", wspLabel, soundingLabel); |
8877 | 102 |
8951 | 103 FlowDepthUtils.checkYearDifference(label, waterlevel.getYear(), bedHeight.getInfo().getYear(), problems); |
8894 | 104 checkWaterlevelDiscretisation(wstKms, calcRange, problems); |
8901 | 105 // TODO: prüfen, ob sohlhöhen die calcRange abdecken/überschneiden |
8882 | 106 |
107 /* re-determine the reference gauge, in the same way as the WaterlevelArtifact would do it */ | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
108 final RiverInfoProvider riverInfoProvider = infoProvider.forWaterlevel(waterlevel); |
8894 | 109 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
110 final int wspYear = waterlevel.getYear(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
111 final WstInfo wstInfo = new WstInfo(wspLabel, wspYear, riverInfoProvider.getReferenceGauge()); |
8914
e3519c3e7a0a
Workflow for SINFO-Transport bodies heights inclduing winfo calculation
gernotbelger
parents:
8911
diff
changeset
|
112 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
113 final WaterlevelValuesFinder waterlevelProvider = WaterlevelValuesFinder.fromKms(wstKms); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
114 final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wstKms); |
8886 | 115 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
116 final River river = riverInfoProvider.getRiver(); |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
117 final TkhCalculator tkhCalculator = TkhCalculator.buildTkhCalculator(useTkh, this.context, problems, label, river, calcRange, waterlevelProvider, |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
118 dischargeProvider, |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
119 bedHeight); |
8883 | 120 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8915
diff
changeset
|
121 final FlowDepthCalculator calculator = new FlowDepthCalculator(riverInfoProvider, wspLabel, bedHeight, tkhCalculator); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
8914
diff
changeset
|
122 return calculator.execute(label, wstInfo, calcRange); |
8877 | 123 } |
124 | |
8882 | 125 /* Checks if the discretisation of the waterlevel exceeds 1000m */ |
8894 | 126 private void checkWaterlevelDiscretisation(final WKms wstKms, final DoubleRange calcRange, final Calculation problems) { |
127 | |
8882 | 128 final int size = wstKms.size(); |
129 for (int i = 0; i < size - 2; i++) { | |
130 final double kmPrev = wstKms.getKm(i); | |
131 final double kmNext = wstKms.getKm(i + 1); | |
132 | |
8894 | 133 /* only check if we are within the calculation range */ |
134 if (calcRange.overlapsRange(new DoubleRange(kmPrev, kmNext))) { | |
135 if (Math.abs(kmPrev - kmNext) > 1) { | |
136 final String label = wstKms.getName(); | |
8882 | 137 |
8894 | 138 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.waterlevel_discretisation", null, label); |
139 problems.addProblem(kmPrev, message); | |
140 } | |
8882 | 141 } |
142 } | |
143 } | |
8884 | 144 } |