comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractTkhCalculationResult.java @ 8946:5d5d482da3e9

Implementing SINFO - FlowDepthMinMax calculation
author gernotbelger
date Tue, 13 Mar 2018 18:49:33 +0100
parents
children a4f1ac81f26d
comparison
equal deleted inserted replaced
8945:4a6b6a3c279c 8946:5d5d482da3e9
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.common;
11
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.List;
15
16 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.SoilKind;
17 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
18
19 import gnu.trove.TDoubleArrayList;
20
21 /**
22 * @author Gernot Belger
23 */
24 public abstract class AbstractTkhCalculationResult<ROW extends AbstractTkhResultRow> extends AbstractSInfoCalculationResult<ROW> {
25
26 private static final long serialVersionUID = 1L;
27
28 private final boolean hasTkh;
29
30 public AbstractTkhCalculationResult(final String label, final WstInfo wst, final boolean hasTkh, final Collection<ROW> rows) {
31 super(label, wst, rows);
32 this.hasTkh = hasTkh;
33 }
34
35 public final boolean hasTkh() {
36 return this.hasTkh;
37 }
38
39 public double[][] getFlowDepthPoints() {
40
41 final Collection<ROW> rows = getRows();
42
43 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
44 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
45
46 for (final ROW row : rows) {
47 xPoints.add(row.getStation());
48 yPoints.add(row.getFlowDepth());
49 }
50
51 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
52 }
53
54 public double[][] getFlowDepthTkhPoints() {
55
56 final Collection<ROW> rows = getRows();
57
58 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
59 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
60
61 for (final ROW row : rows) {
62 xPoints.add(row.getStation());
63 yPoints.add(row.getFlowDepthWithTkh());
64 }
65
66 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
67 }
68
69 public final double[][] getTkhUpPoints() {
70
71 final Collection<ROW> rows = getRows();
72
73 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
74 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
75 final List<SoilKind> kinds = new ArrayList<>(rows.size());
76
77 for (final ROW row : rows) {
78 xPoints.add(row.getStation());
79 yPoints.add(row.getTkhUp());
80 kinds.add(row.getTkhKind());
81 }
82
83 return adjustTkhVisualization(xPoints, yPoints, kinds);
84 }
85
86 public final double[][] getTkhDownPoints() {
87
88 final Collection<ROW> rows = getRows();
89
90 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
91 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
92 final List<SoilKind> kinds = new ArrayList<>(rows.size());
93
94 for (final ROW row : rows) {
95 xPoints.add(row.getStation());
96 yPoints.add(row.getTkhDown());
97 kinds.add(row.getTkhKind());
98 }
99
100 return adjustTkhVisualization(xPoints, yPoints, kinds);
101 }
102
103 public double[][] getVelocityPoints() {
104
105 final Collection<ROW> rows = getRows();
106
107 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
108 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
109
110 for (final ROW row : rows) {
111 xPoints.add(row.getStation());
112 yPoints.add(row.getVelocity());
113 }
114
115 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
116 }
117
118 public double[][] getD50Points() {
119
120 final Collection<ROW> rows = getRows();
121
122 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
123 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
124
125 for (final ROW row : rows) {
126 xPoints.add(row.getStation());
127 yPoints.add(row.getD50());
128 }
129
130 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
131 }
132
133 public double[][] getTauPoints() {
134
135 final Collection<ROW> rows = getRows();
136
137 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
138 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
139
140 for (final ROW row : rows) {
141 xPoints.add(row.getStation());
142 yPoints.add(row.getTau());
143 }
144
145 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
146 }
147
148 /**
149 * the up and down points must be further adjusted for visualization, see Mail Hr. Reiß
150 * basically we need to introduce extra points when the kind changes, so we get vertical lines in that case
151 */
152 private double[][] adjustTkhVisualization(final TDoubleArrayList xPoints, final TDoubleArrayList yPoints, final List<SoilKind> kinds) {
153
154 final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.size());
155 final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.size());
156
157 adjustedX.add(xPoints.get(0));
158 adjustedY.add(yPoints.get(0));
159
160 for (int i = 1; i < xPoints.size(); i++) {
161
162 final SoilKind kind1 = kinds.get(i - 1);
163 final SoilKind kind2 = kinds.get(i);
164
165 if (kind1 != kind2) {
166 /* introduce two extra points in order to create a vertical line in the middle of the two adjacent points */
167 final double x1 = xPoints.get(i - 1);
168 final double y1 = yPoints.get(i - 1);
169 final double x2 = xPoints.get(i);
170 final double y2 = yPoints.get(i);
171
172 final double middleX = (x1 + x2) / 2;
173
174 // REMARK: we can't produce a 100% vertical line, as the area-renderer will not work correctly
175 adjustedX.add(middleX - 0.0001);
176 adjustedY.add(y1);
177
178 adjustedX.add(middleX + 0.0001);
179 adjustedY.add(y2);
180 }
181
182 /* always add the real point now */
183 adjustedX.add(xPoints.get(i));
184 adjustedY.add(yPoints.get(i));
185 }
186
187 return new double[][] { adjustedX.toNativeArray(), adjustedY.toNativeArray() };
188 }
189 }

http://dive4elements.wald.intevation.org