raimund@3043: package de.intevation.flys.artifacts.model.fixings; raimund@3043: raimund@3043: import de.intevation.artifacts.Artifact; raimund@3043: import de.intevation.artifacts.CallContext; raimund@3043: raimund@3043: import de.intevation.flys.artifacts.FLYSArtifact; raimund@3043: import de.intevation.flys.artifacts.FixationArtifactAccess; raimund@3043: sascha@3086: import de.intevation.flys.artifacts.math.fitting.Function; sascha@3086: import de.intevation.flys.artifacts.math.fitting.FunctionFactory; sascha@3086: sascha@3086: import de.intevation.flys.artifacts.model.CalculationResult; sascha@3086: import de.intevation.flys.artifacts.model.DataFacet; raimund@3043: import de.intevation.flys.artifacts.model.FacetTypes; raimund@3043: import de.intevation.flys.artifacts.model.Parameters; raimund@3043: sascha@3086: import de.intevation.flys.artifacts.states.DefaultState.ComputeType; raimund@3043: sascha@3086: import org.apache.log4j.Logger; raimund@3043: raimund@3043: raimund@3043: /** raimund@3043: * Facet to show the W|Q values. raimund@3043: * raimund@3043: * @author Raimund Renkert raimund@3043: */ raimund@3043: public class FixDerivateFacet raimund@3043: extends DataFacet raimund@3043: implements FacetTypes { raimund@3043: raimund@3043: /** House logger. */ raimund@3043: private static Logger logger = Logger.getLogger(FixDerivateFacet.class); raimund@3043: raimund@3080: private double currentKm; christian@3081: private double maxQ; raimund@3080: raimund@3043: /** Trivial Constructor. */ raimund@3043: public FixDerivateFacet() { raimund@3043: } raimund@3043: raimund@3043: raimund@3043: /** raimund@3043: * @param name raimund@3043: */ raimund@3043: public FixDerivateFacet(String name, String description) { raimund@3043: super(0, name, description, ComputeType.ADVANCE, null, null); raimund@3043: } raimund@3043: raimund@3043: raimund@3080: public Object getData(Artifact artifact, CallContext context, double km) { raimund@3080: this.currentKm = km; raimund@3080: return getData(artifact, context); raimund@3080: } raimund@3080: raimund@3080: raimund@3043: /** raimund@3043: * Returns the data this facet requires. raimund@3043: * raimund@3043: * @param artifact the owner artifact. raimund@3043: * @param context the CallContext (ignored). raimund@3043: * raimund@3043: * @return the data. raimund@3043: */ raimund@3043: @Override raimund@3043: public Object getData(Artifact artifact, CallContext context) { raimund@3043: logger.debug("FixDerivateFacet.getData"); raimund@3043: if (artifact instanceof FLYSArtifact) { raimund@3043: FLYSArtifact flys = (FLYSArtifact)artifact; raimund@3043: FixationArtifactAccess access = new FixationArtifactAccess(flys); raimund@3043: raimund@3043: CalculationResult res = raimund@3043: (CalculationResult) flys.compute(context, raimund@3043: ComputeType.ADVANCE, raimund@3043: false); raimund@3043: raimund@3043: FixResult result = (FixResult) res.getData(); raimund@3043: raimund@3043: String function = access.getFunction(); raimund@3043: Function ff = FunctionFactory.getInstance().getFunction(function); raimund@3043: Function.Derivative fd = ff.getDerivative(); raimund@3043: raimund@3043: Parameters params = result.getParameters(); christian@3081: christian@3081: // Determine maxQ christian@3081: double[] maxQs = params christian@3081: .interpolate("km", this.currentKm, new String [] { "max_q" }); christian@3081: if(maxQs != null) { christian@3081: maxQ = maxQs[0]; christian@3081: } christian@3081: raimund@3080: int row = params.binarySearch("km", currentKm, Math.pow(10, -4)); christian@3067: if(row < 0) { christian@3067: row = -row - 1; christian@3067: logger.debug("getData: no direct hit in params.binarySearch"); christian@3067: } raimund@3043: String[] paramNames = ff.getParameterNames(); raimund@3043: int[] paramInd = params.columnIndices(paramNames); raimund@3043: double[] coeffs = new double[paramNames.length]; raimund@3043: params.get(row, paramInd, coeffs); raimund@3043: raimund@3043: de.intevation.flys.artifacts.math.Function mf = raimund@3043: fd.instantiate(coeffs); raimund@3043: raimund@3080: double maxQ = getMaxQ(result, currentKm); raimund@3043: raimund@3043: FixFunction fix = new FixFunction( raimund@3043: "", raimund@3043: ff.getDescription(), raimund@3043: mf, raimund@3043: maxQ); raimund@3043: raimund@3043: return fix; raimund@3043: } raimund@3043: else { raimund@3043: logger.debug("Not an instance of FixationArtifact."); raimund@3043: return null; raimund@3043: } raimund@3043: } raimund@3043: raimund@3043: raimund@3043: protected double getMaxQ(FixResult result, double km) { raimund@3043: return maxQ; raimund@3043: } raimund@3043: raimund@3043: /** raimund@3043: * Create a deep copy of this Facet. raimund@3043: * @return a deep copy. raimund@3043: */ raimund@3043: @Override raimund@3043: public FixDerivateFacet deepCopy() { raimund@3043: FixDerivateFacet copy = new FixDerivateFacet(); raimund@3043: copy.set(this); raimund@3043: return copy; raimund@3043: } raimund@3043: } raimund@3043: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :