Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/StaticSQRelationFacet.java @ 7298:5b2126d21c2e
Polish SQ Datacage and Facets
The starting point is now taken from the blackboard
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 11 Oct 2013 15:35:25 +0200 |
parents | af13ceeba52a |
children | e4606eae8ea5 |
comparison
equal
deleted
inserted
replaced
7297:257d72524249 | 7298:5b2126d21c2e |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.states.sq; | 9 package org.dive4elements.river.artifacts.states.sq; |
10 | 10 |
11 import java.util.List; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 | |
11 import org.dive4elements.artifactdatabase.state.DefaultFacet; | 15 import org.dive4elements.artifactdatabase.state.DefaultFacet; |
12 import org.dive4elements.artifactdatabase.state.Facet; | 16 import org.dive4elements.artifactdatabase.state.Facet; |
13 import org.dive4elements.artifacts.Artifact; | 17 import org.dive4elements.artifacts.Artifact; |
14 import org.dive4elements.artifacts.CallContext; | 18 import org.dive4elements.artifacts.CallContext; |
19 import org.dive4elements.artifacts.DataProvider; | |
15 import org.dive4elements.river.artifacts.math.fitting.Function; | 20 import org.dive4elements.river.artifacts.math.fitting.Function; |
16 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory; | 21 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory; |
17 import org.dive4elements.river.artifacts.model.sq.SQFunction; | 22 import org.dive4elements.river.artifacts.model.sq.SQFunction; |
18 import org.dive4elements.river.artifacts.model.sq.StaticSQRelation; | 23 import org.dive4elements.river.artifacts.model.sq.StaticSQRelation; |
19 | 24 |
24 { | 29 { |
25 public static final String FUNCTION = "sq-pow"; | 30 public static final String FUNCTION = "sq-pow"; |
26 | 31 |
27 private StaticSQRelation relation; | 32 private StaticSQRelation relation; |
28 | 33 |
34 private static final Logger logger = | |
35 Logger.getLogger(StaticSQRelationFacet.class); | |
29 | 36 |
30 public StaticSQRelationFacet( | 37 public StaticSQRelationFacet( |
31 int ndx, | 38 int ndx, |
32 String name, | 39 String name, |
33 String description, | 40 String description, |
41 double qmax = relation.getQmax(); | 48 double qmax = relation.getQmax(); |
42 double[] coeffs = new double[] {relation.getA(), relation.getB()}; | 49 double[] coeffs = new double[] {relation.getA(), relation.getB()}; |
43 Function func = FunctionFactory.getInstance().getFunction(FUNCTION); | 50 Function func = FunctionFactory.getInstance().getFunction(FUNCTION); |
44 org.dive4elements.river.artifacts.math.Function function = | 51 org.dive4elements.river.artifacts.math.Function function = |
45 func.instantiate(coeffs); | 52 func.instantiate(coeffs); |
46 SQFunction sqf = new SQFunction(function, 0, qmax); | 53 |
54 /* Figure out a good starting point by checking for calculated | |
55 * SQ Curves and using their starting point */ | |
56 | |
57 // this is ok because we are a DefaultFacet and not a DataFacet | |
58 // and so we are not registred with Mr. Blackboard | |
59 List<DataProvider> providers = context.getDataProvider(name); | |
60 | |
61 double startingPoint = Double.MAX_VALUE; | |
62 | |
63 for (DataProvider dp: providers) { | |
64 SQFunction other = (SQFunction) dp.provideData( | |
65 name, | |
66 null, | |
67 context); | |
68 if (other == null) { | |
69 // name is not really unique here but it's our only key | |
70 // should not happen anyhow. | |
71 logger.error("Did not get data from: " + name); | |
72 continue; | |
73 } | |
74 startingPoint = Math.min(other.getMinQ(), startingPoint); | |
75 } | |
76 if (startingPoint == Double.MAX_VALUE) { | |
77 startingPoint = 0; | |
78 } | |
79 | |
80 SQFunction sqf = new SQFunction(function, startingPoint, qmax); | |
47 return sqf; | 81 return sqf; |
48 } | 82 } |
49 | 83 |
50 @Override | 84 @Override |
51 public Facet deepCopy() { | 85 public Facet deepCopy() { |