comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixDerivateFacet.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixDerivateFacet.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.artifacts.model.fixings;
2
3 import org.dive4elements.artifacts.Artifact;
4 import org.dive4elements.artifacts.CallContext;
5
6 import org.dive4elements.river.artifacts.FLYSArtifact;
7
8 import org.dive4elements.river.artifacts.access.FixAnalysisAccess;
9
10 import org.dive4elements.river.artifacts.math.fitting.Function;
11 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory;
12
13 import org.dive4elements.river.artifacts.model.CalculationResult;
14 import org.dive4elements.river.artifacts.model.FacetTypes;
15 import org.dive4elements.river.artifacts.model.Parameters;
16
17 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
18
19 import org.apache.log4j.Logger;
20
21
22 /**
23 * Facet to show the W|Q values.
24 *
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
26 */
27 public class FixDerivateFacet
28 extends FixingsFacet
29 implements FacetTypes {
30
31 /** House logger. */
32 private static Logger logger = Logger.getLogger(FixDerivateFacet.class);
33
34
35 /** Trivial Constructor. */
36 public FixDerivateFacet() {
37 }
38
39
40 /**
41 * @param name
42 */
43 public FixDerivateFacet(String name, String description) {
44 super(0, name, description, ComputeType.ADVANCE, null, null);
45 }
46
47 public FixDerivateFacet(int index, String name, String description) {
48 super(index, name, description, ComputeType.ADVANCE, null, null);
49 }
50
51
52 /**
53 * Returns the data this facet requires.
54 *
55 * @param artifact the owner artifact.
56 * @param context the CallContext (ignored).
57 *
58 * @return the data.
59 */
60 @Override
61 public Object getData(Artifact artifact, CallContext context) {
62
63 logger.debug("FixDerivateFacet.getData");
64 if (!(artifact instanceof FLYSArtifact)) {
65 logger.debug("Not an instance of FixationArtifact.");
66 return null;
67 }
68
69 FLYSArtifact flys = (FLYSArtifact)artifact;
70 FixAnalysisAccess access = new FixAnalysisAccess(flys, context);
71
72 CalculationResult res =
73 (CalculationResult) flys.compute(context,
74 ComputeType.ADVANCE,
75 false);
76
77 FixAnalysisResult result = (FixAnalysisResult) res.getData();
78 double currentKm = getCurrentKm(context);
79
80 String function = access.getFunction();
81 Function ff = FunctionFactory.getInstance().getFunction(function);
82 Function.Derivative fd = ff.getDerivative();
83
84 Parameters params = result.getParameters();
85 double maxQ = FixFacetUtils.getMaxQ(params, currentKm);
86
87 String[] paramNames = ff.getParameterNames();
88
89 double[] coeffs = params.interpolate("km", currentKm, paramNames);
90 if (coeffs == null) {
91 logger.warn("getData: coeffs == null");
92 return null;
93 }
94
95 org.dive4elements.river.artifacts.math.Function mf =
96 fd.instantiate(coeffs);
97
98 FixFunction fix = new FixFunction(
99 "",
100 fd.getDescription(),
101 mf,
102 maxQ);
103
104 return fix;
105 }
106
107
108 /**
109 * Create a deep copy of this Facet.
110 * @return a deep copy.
111 */
112 @Override
113 public FixDerivateFacet deepCopy() {
114 FixDerivateFacet copy = new FixDerivateFacet();
115 copy.set(this);
116 return copy;
117 }
118 }
119 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org