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:
parent
6041336783
commit
399249653d
|
@ -39,6 +39,18 @@ package org.apache.commons.math.ode.sampling;
|
||||||
|
|
||||||
public interface FixedStepHandler {
|
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
|
* Handle the last accepted step
|
||||||
* @param t time of the current step
|
* @param t time of the current step
|
||||||
|
|
|
@ -174,11 +174,16 @@ public class StepNormalizer implements StepHandler {
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public void init(double t0, double[] y0, double t) {
|
public void init(double t0, double[] y0, double t) {
|
||||||
|
|
||||||
firstTime = Double.NaN;
|
firstTime = Double.NaN;
|
||||||
lastTime = Double.NaN;
|
lastTime = Double.NaN;
|
||||||
lastState = null;
|
lastState = null;
|
||||||
lastDerivatives = null;
|
lastDerivatives = null;
|
||||||
forward = true;
|
forward = true;
|
||||||
|
|
||||||
|
// initialize the underlying handler
|
||||||
|
handler.init(t0, y0, t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,8 +12,8 @@ import org.junit.Test;
|
||||||
|
|
||||||
/** Base class for step normalizer output tests. */
|
/** Base class for step normalizer output tests. */
|
||||||
public abstract class StepNormalizerOutputTestBase
|
public abstract class StepNormalizerOutputTestBase
|
||||||
implements FirstOrderDifferentialEquations, FixedStepHandler
|
implements FirstOrderDifferentialEquations, FixedStepHandler {
|
||||||
{
|
|
||||||
/** The normalized output time values. */
|
/** The normalized output time values. */
|
||||||
private List<Double> output;
|
private List<Double> output;
|
||||||
|
|
||||||
|
@ -211,8 +211,13 @@ public abstract class StepNormalizerOutputTestBase
|
||||||
yDot[0] = y[0];
|
yDot[0] = y[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public void init(double t0, double[] y0, double t) {
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public void handleStep(double t, double[] y, double[] yDot, boolean isLast) {
|
public void handleStep(double t, double[] y, double[] yDot, boolean isLast) {
|
||||||
output.add(t);
|
output.add(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,8 @@ public class StepNormalizerTest {
|
||||||
integ.addStepHandler(new StepNormalizer(range / 10.0,
|
integ.addStepHandler(new StepNormalizer(range / 10.0,
|
||||||
new FixedStepHandler() {
|
new FixedStepHandler() {
|
||||||
private boolean firstCall = true;
|
private boolean firstCall = true;
|
||||||
|
public void init(double t0, double[] y0, double t) {
|
||||||
|
}
|
||||||
public void handleStep(double t,
|
public void handleStep(double t,
|
||||||
double[] y,
|
double[] y,
|
||||||
double[] yDot,
|
double[] yDot,
|
||||||
|
@ -69,6 +71,8 @@ public class StepNormalizerTest {
|
||||||
setLastSeen(false);
|
setLastSeen(false);
|
||||||
integ.addStepHandler(new StepNormalizer(range / 10.5,
|
integ.addStepHandler(new StepNormalizer(range / 10.5,
|
||||||
new FixedStepHandler() {
|
new FixedStepHandler() {
|
||||||
|
public void init(double t0, double[] y0, double t) {
|
||||||
|
}
|
||||||
public void handleStep(double t,
|
public void handleStep(double t,
|
||||||
double[] y,
|
double[] y,
|
||||||
double[] yDot,
|
double[] yDot,
|
||||||
|
|
Loading…
Reference in New Issue