Added the initi method also to FixedStepHandler.

Jira: MATH-714

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1207066 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-11-28 10:56:30 +00:00
parent 6041336783
commit 399249653d
4 changed files with 30 additions and 4 deletions

View File

@ -39,6 +39,18 @@ package org.apache.commons.math.ode.sampling;
public interface FixedStepHandler {
/** Initialize step handler at the start of an ODE integration.
* <p>
* This method is called once at the start of the integration. It
* may be used by the step handler to initialize some internal data
* if needed.
* </p>
* @param t0 start value of the independent <i>time</i> variable
* @param y0 array containing the start value of the state vector
* @param t target time for the integration
*/
void init(double t0, double[] y0, double t);
/**
* Handle the last accepted step
* @param t time of the current step

View File

@ -174,11 +174,16 @@ public class StepNormalizer implements StepHandler {
/** {@inheritDoc} */
public void init(double t0, double[] y0, double t) {
firstTime = Double.NaN;
lastTime = Double.NaN;
lastState = null;
lastDerivatives = null;
forward = true;
// initialize the underlying handler
handler.init(t0, y0, t);
}
/**

View File

@ -12,8 +12,8 @@ import org.junit.Test;
/** Base class for step normalizer output tests. */
public abstract class StepNormalizerOutputTestBase
implements FirstOrderDifferentialEquations, FixedStepHandler
{
implements FirstOrderDifferentialEquations, FixedStepHandler {
/** The normalized output time values. */
private List<Double> output;
@ -211,8 +211,13 @@ public abstract class StepNormalizerOutputTestBase
yDot[0] = y[0];
}
/** {@inheritDoc} */
public void init(double t0, double[] y0, double t) {
}
/** {@inheritDoc} */
public void handleStep(double t, double[] y, double[] yDot, boolean isLast) {
output.add(t);
}
}

View File

@ -41,7 +41,9 @@ public class StepNormalizerTest {
setLastSeen(false);
integ.addStepHandler(new StepNormalizer(range / 10.0,
new FixedStepHandler() {
private boolean firstCall = true;
private boolean firstCall = true;
public void init(double t0, double[] y0, double t) {
}
public void handleStep(double t,
double[] y,
double[] yDot,
@ -69,7 +71,9 @@ public class StepNormalizerTest {
setLastSeen(false);
integ.addStepHandler(new StepNormalizer(range / 10.5,
new FixedStepHandler() {
public void handleStep(double t,
public void init(double t0, double[] y0, double t) {
}
public void handleStep(double t,
double[] y,
double[] yDot,
boolean isLast) {