comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java @ 3043:22da13d1b180

Added facet for derivate curve and fixed facet names. flys-artifacts/trunk@4612 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 06 Jun 2012 14:58:25 +0000
parents
children d87aadaa4f7e
comparison
equal deleted inserted replaced
3042:2ff802d66b71 3043:22da13d1b180
1 package de.intevation.flys.artifacts.model.fixings;
2
3 import org.apache.log4j.Logger;
4
5 import de.intevation.artifacts.Artifact;
6 import de.intevation.artifacts.CallContext;
7
8 import de.intevation.flys.utils.KMIndex;
9
10 import de.intevation.flys.artifacts.FLYSArtifact;
11 import de.intevation.flys.artifacts.FixationArtifactAccess;
12
13 import de.intevation.flys.artifacts.model.FacetTypes;
14 import de.intevation.flys.artifacts.model.DataFacet;
15 import de.intevation.flys.artifacts.model.CalculationResult;
16 import de.intevation.flys.artifacts.model.Parameters;
17
18 import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
19 import de.intevation.flys.artifacts.math.fitting.Function;
20
21 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
22
23
24 /**
25 * Facet to show the W|Q values.
26 *
27 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
28 */
29 public class FixDerivateFacet
30 extends DataFacet
31 implements FacetTypes {
32
33 /** House logger. */
34 private static Logger logger = Logger.getLogger(FixDerivateFacet.class);
35
36 /** Trivial Constructor. */
37 public FixDerivateFacet() {
38 }
39
40
41 /**
42 * @param name
43 */
44 public FixDerivateFacet(String name, String description) {
45 super(0, name, description, ComputeType.ADVANCE, null, null);
46 }
47
48
49 /**
50 * Returns the data this facet requires.
51 *
52 * @param artifact the owner artifact.
53 * @param context the CallContext (ignored).
54 *
55 * @return the data.
56 */
57 @Override
58 public Object getData(Artifact artifact, CallContext context) {
59 logger.debug("FixDerivateFacet.getData");
60 if (artifact instanceof FLYSArtifact) {
61 FLYSArtifact flys = (FLYSArtifact)artifact;
62 FixationArtifactAccess access = new FixationArtifactAccess(flys);
63
64 CalculationResult res =
65 (CalculationResult) flys.compute(context,
66 ComputeType.ADVANCE,
67 false);
68
69 FixResult result = (FixResult) res.getData();
70
71 double km = access.getCurrentKm();
72
73 String function = access.getFunction();
74 Function ff = FunctionFactory.getInstance().getFunction(function);
75 Function.Derivative fd = ff.getDerivative();
76
77 Parameters params = result.getParameters();
78 int row = params.binarySearch("km", km, Math.pow(10, -4));
79 String[] paramNames = ff.getParameterNames();
80 int[] paramInd = params.columnIndices(paramNames);
81 double[] coeffs = new double[paramNames.length];
82 params.get(row, paramInd, coeffs);
83
84 de.intevation.flys.artifacts.math.Function mf =
85 fd.instantiate(coeffs);
86
87 double maxQ = getMaxQ(result, km);
88
89 FixFunction fix = new FixFunction(
90 "",
91 ff.getDescription(),
92 mf,
93 maxQ);
94
95 return fix;
96 }
97 else {
98 logger.debug("Not an instance of FixationArtifact.");
99 return null;
100 }
101 }
102
103
104 protected double getMaxQ(FixResult result, double km) {
105 double maxQ = 0;
106
107 KMIndex<QW []> kmQWRef = result.getReferenced();
108
109 QW[] qwRef = kmQWRef.binarySearch(km).getValue();
110 if (qwRef != null) {
111 for (int i = 0; i < qwRef.length; i++) {
112 if (qwRef[i].getQ() > maxQ) {
113 maxQ = qwRef[i].getQ();
114 }
115 }
116 }
117
118 KMIndex<AnalysisPeriod []> kmQWDAna = result.getAnalysisPeriods();
119 AnalysisPeriod[] periods = kmQWDAna.binarySearch(km).getValue();
120
121 if(periods != null) {
122 for (int i = 0; i < periods.length; i++) {
123 QWD[] qwdAna = periods[i].getQWDs();
124 if (qwdAna != null) {
125 for (int j = 0; j < qwdAna.length; j++) {
126 if (qwdAna[j].getQ() > maxQ) {
127 maxQ = qwdAna[j].getQ();
128 }
129 }
130 }
131 }
132 }
133 return maxQ;
134 }
135
136 /**
137 * Create a deep copy of this Facet.
138 * @return a deep copy.
139 */
140 @Override
141 public FixDerivateFacet deepCopy() {
142 FixDerivateFacet copy = new FixDerivateFacet();
143 copy.set(this);
144 return copy;
145 }
146 }
147 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org