annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java @ 3086:ba7df29264cd

Removed superfluous import. flys-artifacts/trunk@4683 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 18 Jun 2012 08:55:51 +0000
parents 26119b7b3154
children 960307cf2adc
rev   line source
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model.fixings;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import de.intevation.artifacts.Artifact;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 import de.intevation.artifacts.CallContext;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 import de.intevation.flys.artifacts.FLYSArtifact;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import de.intevation.flys.artifacts.FixationArtifactAccess;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8
3086
ba7df29264cd Removed superfluous import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3081
diff changeset
9 import de.intevation.flys.artifacts.math.fitting.Function;
ba7df29264cd Removed superfluous import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3081
diff changeset
10 import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
ba7df29264cd Removed superfluous import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3081
diff changeset
11
ba7df29264cd Removed superfluous import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3081
diff changeset
12 import de.intevation.flys.artifacts.model.CalculationResult;
ba7df29264cd Removed superfluous import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3081
diff changeset
13 import de.intevation.flys.artifacts.model.DataFacet;
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import de.intevation.flys.artifacts.model.FacetTypes;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import de.intevation.flys.artifacts.model.Parameters;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
3086
ba7df29264cd Removed superfluous import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3081
diff changeset
17 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18
3086
ba7df29264cd Removed superfluous import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3081
diff changeset
19 import org.apache.log4j.Logger;
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 /**
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 * Facet to show the W|Q values.
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 *
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 */
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 public class FixDerivateFacet
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 extends DataFacet
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 implements FacetTypes {
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 /** House logger. */
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 private static Logger logger = Logger.getLogger(FixDerivateFacet.class);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33
3080
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
34 private double currentKm;
3081
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
35 private double maxQ;
3080
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
36
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 /** Trivial Constructor. */
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 public FixDerivateFacet() {
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 }
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 /**
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 * @param name
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 */
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 public FixDerivateFacet(String name, String description) {
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 super(0, name, description, ComputeType.ADVANCE, null, null);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 }
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49
3080
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
50 public Object getData(Artifact artifact, CallContext context, double km) {
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
51 this.currentKm = km;
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
52 return getData(artifact, context);
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
53 }
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
54
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
55
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 /**
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 * Returns the data this facet requires.
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 *
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 * @param artifact the owner artifact.
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 * @param context the CallContext (ignored).
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 *
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 * @return the data.
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 */
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 @Override
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 public Object getData(Artifact artifact, CallContext context) {
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 logger.debug("FixDerivateFacet.getData");
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 if (artifact instanceof FLYSArtifact) {
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 FLYSArtifact flys = (FLYSArtifact)artifact;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 FixationArtifactAccess access = new FixationArtifactAccess(flys);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 CalculationResult res =
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 (CalculationResult) flys.compute(context,
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 ComputeType.ADVANCE,
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 false);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 FixResult result = (FixResult) res.getData();
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 String function = access.getFunction();
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 Function ff = FunctionFactory.getInstance().getFunction(function);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 Function.Derivative fd = ff.getDerivative();
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 Parameters params = result.getParameters();
3081
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
83
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
84 // Determine maxQ
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
85 double[] maxQs = params
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
86 .interpolate("km", this.currentKm, new String [] { "max_q" });
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
87 if(maxQs != null) {
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
88 maxQ = maxQs[0];
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
89 }
26119b7b3154 Fixing output generator hacking
Christian Lins <christian.lins@intevation.de>
parents: 3080
diff changeset
90
3080
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
91 int row = params.binarySearch("km", currentKm, Math.pow(10, -4));
3067
d87aadaa4f7e Add FixDerivedCurveGenerator class
Christian Lins <christian.lins@intevation.de>
parents: 3043
diff changeset
92 if(row < 0) {
d87aadaa4f7e Add FixDerivedCurveGenerator class
Christian Lins <christian.lins@intevation.de>
parents: 3043
diff changeset
93 row = -row - 1;
d87aadaa4f7e Add FixDerivedCurveGenerator class
Christian Lins <christian.lins@intevation.de>
parents: 3043
diff changeset
94 logger.debug("getData: no direct hit in params.binarySearch");
d87aadaa4f7e Add FixDerivedCurveGenerator class
Christian Lins <christian.lins@intevation.de>
parents: 3043
diff changeset
95 }
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
96 String[] paramNames = ff.getParameterNames();
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 int[] paramInd = params.columnIndices(paramNames);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 double[] coeffs = new double[paramNames.length];
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99 params.get(row, paramInd, coeffs);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 de.intevation.flys.artifacts.math.Function mf =
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 fd.instantiate(coeffs);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103
3080
dc2765e31e1f Added getData method with an additional km parameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3067
diff changeset
104 double maxQ = getMaxQ(result, currentKm);
3043
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 FixFunction fix = new FixFunction(
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 "",
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 ff.getDescription(),
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 mf,
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 maxQ);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 return fix;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 }
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 else {
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115 logger.debug("Not an instance of FixationArtifact.");
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116 return null;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
117 }
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 }
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
121 protected double getMaxQ(FixResult result, double km) {
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
122 return maxQ;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123 }
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125 /**
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 * Create a deep copy of this Facet.
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 * @return a deep copy.
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 */
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 @Override
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130 public FixDerivateFacet deepCopy() {
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131 FixDerivateFacet copy = new FixDerivateFacet();
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
132 copy.set(this);
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
133 return copy;
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 }
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
135 }
22da13d1b180 Added facet for derivate curve and fixed facet names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
136 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org