Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedParametersResult.java @ 8581:073ea4bcea58
(issue1755) Interpolate BedQuality Results
This adds an interpolation function to each various bedQuality result class.
Imho this is ok as the interpolation function can be seen as part of the result.
The interpolation function is initalized on first use and can be accessed through
get.*Interpol functions.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 16 Mar 2015 15:36:38 +0100 |
parents | af13ceeba52a |
children |
comparison
equal
deleted
inserted
replaced
8580:d9f038b8e2ce | 8581:073ea4bcea58 |
---|---|
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.model.minfo; | 9 package org.dive4elements.river.artifacts.model.minfo; |
10 | 10 |
11 import gnu.trove.TDoubleArrayList; | 11 import gnu.trove.TDoubleArrayList; |
12 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; | |
13 import org.dive4elements.river.utils.DoubleUtil; | |
14 import org.apache.commons.math.ArgumentOutsideDomainException; | |
12 | 15 |
13 import java.io.Serializable; | 16 import java.io.Serializable; |
14 | 17 |
15 | 18 |
16 public class BedParametersResult | 19 public class BedParametersResult |
19 protected TDoubleArrayList porosityCap; | 22 protected TDoubleArrayList porosityCap; |
20 protected TDoubleArrayList porositySub; | 23 protected TDoubleArrayList porositySub; |
21 protected TDoubleArrayList loadDensityCap; | 24 protected TDoubleArrayList loadDensityCap; |
22 protected TDoubleArrayList loadDensitySub; | 25 protected TDoubleArrayList loadDensitySub; |
23 protected TDoubleArrayList kms; | 26 protected TDoubleArrayList kms; |
27 | |
28 protected PolynomialSplineFunction interpolPoroSub; | |
29 protected PolynomialSplineFunction interpolPoroCap; | |
30 protected PolynomialSplineFunction interpolDensSub; | |
31 protected PolynomialSplineFunction interpolDensCap; | |
32 | |
33 protected boolean nonInterpolPoroSub; | |
34 protected boolean nonInterpolPoroCap; | |
35 protected boolean nonInterpolDensSub; | |
36 protected boolean nonInterpolDensCap; | |
24 | 37 |
25 public BedParametersResult() { | 38 public BedParametersResult() { |
26 | 39 |
27 } | 40 } |
28 | 41 |
36 this.kms = kms; | 49 this.kms = kms; |
37 this.porosityCap = porosityCap; | 50 this.porosityCap = porosityCap; |
38 this.porositySub = porositySub; | 51 this.porositySub = porositySub; |
39 this.loadDensityCap = densityCap; | 52 this.loadDensityCap = densityCap; |
40 this.loadDensitySub = densitySub; | 53 this.loadDensitySub = densitySub; |
54 | |
55 PolynomialSplineFunction interpolPoroSub = null; | |
56 PolynomialSplineFunction interpolPoroCap = null; | |
57 PolynomialSplineFunction interpolDensSub = null; | |
58 PolynomialSplineFunction interpolDensCap = null; | |
59 | |
60 nonInterpolPoroSub = false; | |
61 nonInterpolPoroCap = false; | |
62 nonInterpolDensSub = false; | |
63 nonInterpolDensCap = false; | |
41 } | 64 } |
42 | 65 |
43 public double getPorosityCap(int ndx) { | 66 public double getPorosityCap(int ndx) { |
44 return porosityCap.get(ndx); | 67 return porosityCap.get(ndx); |
45 } | 68 } |
109 return new double[][] { | 132 return new double[][] { |
110 kms.toNativeArray(), | 133 kms.toNativeArray(), |
111 loadDensitySub.toNativeArray() | 134 loadDensitySub.toNativeArray() |
112 }; | 135 }; |
113 } | 136 } |
137 | |
138 public double getPorositySubInterpol(double km) { | |
139 if (nonInterpolPoroSub) { | |
140 return Double.NaN; | |
141 } | |
142 if (interpolPoroSub == null) { | |
143 interpolPoroSub = DoubleUtil.getLinearInterpolator(kms, porositySub); | |
144 if (interpolPoroSub == null) { | |
145 nonInterpolPoroSub = true; | |
146 return Double.NaN; | |
147 } | |
148 } | |
149 try { | |
150 return interpolPoroSub.value(km); | |
151 } catch (ArgumentOutsideDomainException e) { | |
152 /* This is expected for many results. */ | |
153 return Double.NaN; | |
154 } | |
155 } | |
156 | |
157 public double getPorosityCapInterpol(double km) { | |
158 if (nonInterpolPoroCap) { | |
159 return Double.NaN; | |
160 } | |
161 if (interpolPoroCap == null) { | |
162 interpolPoroCap = DoubleUtil.getLinearInterpolator(kms, porosityCap); | |
163 if (interpolPoroCap == null) { | |
164 nonInterpolPoroCap = true; | |
165 return Double.NaN; | |
166 } | |
167 } | |
168 try { | |
169 return interpolPoroCap.value(km); | |
170 } catch (ArgumentOutsideDomainException e) { | |
171 /* This is expected for many results. */ | |
172 return Double.NaN; | |
173 } | |
174 } | |
175 | |
176 public double getDensitySubInterpol(double km) { | |
177 if (nonInterpolDensSub) { | |
178 return Double.NaN; | |
179 } | |
180 if (interpolDensSub == null) { | |
181 interpolDensSub = DoubleUtil.getLinearInterpolator(kms, loadDensitySub); | |
182 if (interpolDensSub == null) { | |
183 nonInterpolDensSub = true; | |
184 return Double.NaN; | |
185 } | |
186 } | |
187 try { | |
188 return interpolDensSub.value(km); | |
189 } catch (ArgumentOutsideDomainException e) { | |
190 /* This is expected for many results. */ | |
191 return Double.NaN; | |
192 } | |
193 } | |
194 | |
195 public double getDensityCapInterpol(double km) { | |
196 if (nonInterpolDensCap) { | |
197 return Double.NaN; | |
198 } | |
199 if (interpolDensCap == null) { | |
200 interpolDensCap = DoubleUtil.getLinearInterpolator(kms, loadDensityCap); | |
201 if (interpolDensCap == null) { | |
202 nonInterpolDensCap = true; | |
203 return Double.NaN; | |
204 } | |
205 } | |
206 try { | |
207 return interpolDensCap.value(km); | |
208 } catch (ArgumentOutsideDomainException e) { | |
209 /* This is expected for many results. */ | |
210 return Double.NaN; | |
211 } | |
212 } | |
213 | |
114 } | 214 } |