From 6041336783ba94b46fe5953e8415884bf0cef32c Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Mon, 28 Nov 2011 10:20:51 +0000 Subject: [PATCH] Added init methods to StepHandler and EventHandler interfaces. The reset method in StepHandler interface has been renamed init and is provided more information on the integration by the calling integrator. A similar init method has been added to the EventHandler interface. Jira: MATH-714 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1207054 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/ode/AbstractIntegrator.java | 21 +++++++-- .../math/ode/ContinuousOutputModel.java | 14 +++--- .../commons/math/ode/MultistepIntegrator.java | 2 +- .../commons/math/ode/events/EventHandler.java | 12 +++++ .../nonstiff/AdamsBashforthIntegrator.java | 7 +-- .../ode/nonstiff/AdamsMoultonIntegrator.java | 7 +-- .../EmbeddedRungeKuttaIntegrator.java | 7 +-- .../GraggBulirschStoerIntegrator.java | 6 +-- .../ode/nonstiff/RungeKuttaIntegrator.java | 7 +-- .../math/ode/sampling/DummyStepHandler.java | 7 +-- .../math/ode/sampling/StepHandler.java | 46 +++++++++++-------- .../math/ode/sampling/StepNormalizer.java | 21 +++++---- src/site/xdoc/changes.xml | 5 ++ src/site/xdoc/userguide/ode.xml | 16 +++---- .../apache/commons/math/ode/TestProblem4.java | 6 +++ .../commons/math/ode/TestProblemHandler.java | 7 ++- .../math/ode/events/EventStateTest.java | 5 ++ .../ode/events/OverlappingEventsTest.java | 4 ++ .../math/ode/events/ReappearingEventTest.java | 4 ++ .../ClassicalRungeKuttaIntegratorTest.java | 9 ++-- .../DormandPrince54IntegratorTest.java | 7 ++- .../DormandPrince54StepInterpolatorTest.java | 4 +- .../DormandPrince853IntegratorTest.java | 12 +++-- .../DormandPrince853StepInterpolatorTest.java | 2 +- .../ode/nonstiff/EulerIntegratorTest.java | 2 +- .../math/ode/nonstiff/GillIntegratorTest.java | 5 +- .../GraggBulirschStoerIntegratorTest.java | 12 +++-- ...raggBulirschStoerStepInterpolatorTest.java | 2 +- .../nonstiff/HighamHall54IntegratorTest.java | 4 ++ .../HighamHall54StepInterpolatorTest.java | 2 +- .../ode/nonstiff/MidpointIntegratorTest.java | 2 +- .../math/ode/nonstiff/StepProblem.java | 3 ++ .../nonstiff/ThreeEighthesIntegratorTest.java | 4 +- .../sampling/StepInterpolatorTestUtils.java | 2 +- 34 files changed, 160 insertions(+), 116 deletions(-) diff --git a/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java b/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java index e09a92206..fe121c97d 100644 --- a/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/AbstractIntegrator.java @@ -91,7 +91,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { statesInitialized = false; evaluations = new Incrementor(); setMaxEvaluations(-1); - resetEvaluations(); + evaluations.resetCount(); } /** Build an instance with a null name. @@ -179,10 +179,25 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { return evaluations.getCount(); } - /** Reset the number of evaluations to zero. + /** Prepare the start of an integration. + * @param t0 start value of the independent time variable + * @param y0 array containing the start value of the state vector + * @param t target time for the integration */ - protected void resetEvaluations() { + protected void initIntegration(final double t0, final double[] y0, final double t) { + evaluations.resetCount(); + + for (final EventState state : eventsStates) { + state.getEventHandler().init(t0, y0, t); + } + + for (StepHandler handler : stepHandlers) { + handler.init(t0, y0, t); + } + + setStateInitialized(false); + } /** Set the equations. diff --git a/src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java b/src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java index e8c6416b6..b240206d8 100644 --- a/src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java +++ b/src/main/java/org/apache/commons/math/ode/ContinuousOutputModel.java @@ -112,7 +112,10 @@ public class ContinuousOutputModel */ public ContinuousOutputModel() { steps = new ArrayList(); - reset(); + initialTime = Double.NaN; + finalTime = Double.NaN; + forward = true; + index = 0; } /** Append another model at the end of the instance. @@ -163,17 +166,14 @@ public class ContinuousOutputModel } - /** Reset the step handler. - * Initialize the internal data as required before the first step is - * handled. - */ - public void reset() { + /** {@inheritDoc} */ + public void init(double t0, double[] y0, double t) { initialTime = Double.NaN; finalTime = Double.NaN; forward = true; index = 0; steps.clear(); - } + } /** Handle the last accepted step. * A copy of the information provided by the last step is stored in diff --git a/src/main/java/org/apache/commons/math/ode/MultistepIntegrator.java b/src/main/java/org/apache/commons/math/ode/MultistepIntegrator.java index cfeb906e5..094cc0be0 100644 --- a/src/main/java/org/apache/commons/math/ode/MultistepIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/MultistepIntegrator.java @@ -382,7 +382,7 @@ public abstract class MultistepIntegrator extends AdaptiveStepsizeIntegrator { } /** {@inheritDoc} */ - public void reset() { + public void init(double t0, double[] y0, double t) { // nothing to do } diff --git a/src/main/java/org/apache/commons/math/ode/events/EventHandler.java b/src/main/java/org/apache/commons/math/ode/events/EventHandler.java index 63e94b866..83e7f6054 100644 --- a/src/main/java/org/apache/commons/math/ode/events/EventHandler.java +++ b/src/main/java/org/apache/commons/math/ode/events/EventHandler.java @@ -87,6 +87,18 @@ public interface EventHandler { } + /** Initialize event handler at the start of an ODE integration. + *

+ * This method is called once at the start of the integration. It + * may be used by the event handler to initialize some internal data + * if needed. + *

+ * @param t0 start value of the independent time 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); + /** Compute the value of the switching function. *

The discrete events are generated when the sign of this diff --git a/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java b/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java index f4208cea5..3d1433fa8 100644 --- a/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java @@ -22,7 +22,6 @@ import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.linear.Array2DRowRealMatrix; import org.apache.commons.math.ode.ExpandableStatefulODE; import org.apache.commons.math.ode.sampling.NordsieckStepInterpolator; -import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.util.FastMath; @@ -194,7 +193,6 @@ public class AdamsBashforthIntegrator extends AdamsIntegrator { sanityChecks(equations, t); setEquations(equations); - resetEvaluations(); final boolean forward = t > equations.getTime(); // initialize working arrays @@ -208,10 +206,7 @@ public class AdamsBashforthIntegrator extends AdamsIntegrator { equations.getPrimaryMapper(), equations.getSecondaryMappers()); // set up integration control objects - for (StepHandler handler : stepHandlers) { - handler.reset(); - } - setStateInitialized(false); + initIntegration(equations.getTime(), y0, t); // compute the initial Nordsieck vector using the configured starter integrator start(equations.getTime(), y, t); diff --git a/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java b/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java index 362deb2f2..ffe30c795 100644 --- a/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java @@ -25,7 +25,6 @@ import org.apache.commons.math.linear.Array2DRowRealMatrix; import org.apache.commons.math.linear.RealMatrixPreservingVisitor; import org.apache.commons.math.ode.ExpandableStatefulODE; import org.apache.commons.math.ode.sampling.NordsieckStepInterpolator; -import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.util.FastMath; @@ -211,7 +210,6 @@ public class AdamsMoultonIntegrator extends AdamsIntegrator { sanityChecks(equations, t); setEquations(equations); - resetEvaluations(); final boolean forward = t > equations.getTime(); // initialize working arrays @@ -228,10 +226,7 @@ public class AdamsMoultonIntegrator extends AdamsIntegrator { equations.getPrimaryMapper(), equations.getSecondaryMappers()); // set up integration control objects - for (StepHandler handler : stepHandlers) { - handler.reset(); - } - setStateInitialized(false); + initIntegration(equations.getTime(), y0, t); // compute the initial Nordsieck vector using the configured starter integrator start(equations.getTime(), y, t); diff --git a/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java b/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java index 34d2c0073..13ced27d7 100644 --- a/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java @@ -20,7 +20,6 @@ package org.apache.commons.math.ode.nonstiff; import org.apache.commons.math.exception.MathIllegalArgumentException; import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.ode.ExpandableStatefulODE; -import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.util.FastMath; /** @@ -194,7 +193,6 @@ public abstract class EmbeddedRungeKuttaIntegrator sanityChecks(equations, t); setEquations(equations); - resetEvaluations(); final boolean forward = t > equations.getTime(); // create some internal working arrays @@ -215,10 +213,7 @@ public abstract class EmbeddedRungeKuttaIntegrator stepStart = equations.getTime(); double hNew = 0; boolean firstTime = true; - for (StepHandler handler : stepHandlers) { - handler.reset(); - } - setStateInitialized(false); + initIntegration(equations.getTime(), y0, t); // main integration loop isLastStep = false; diff --git a/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java b/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java index 2e92c2e00..873f50ca0 100644 --- a/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java @@ -546,7 +546,6 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { sanityChecks(equations, t); setEquations(equations); - resetEvaluations(); final boolean forward = t > equations.getTime(); // create some internal working arrays @@ -613,10 +612,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator { boolean firstTime = true; boolean newStep = true; boolean firstStepAlreadyComputed = false; - for (StepHandler handler : stepHandlers) { - handler.reset(); - } - setStateInitialized(false); + initIntegration(equations.getTime(), y0, t); costPerTimeUnit[0] = 0; isLastStep = false; do { diff --git a/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java b/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java index c51620c17..39a810f16 100644 --- a/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java +++ b/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java @@ -22,7 +22,6 @@ import org.apache.commons.math.exception.MathIllegalArgumentException; import org.apache.commons.math.exception.MathIllegalStateException; import org.apache.commons.math.ode.AbstractIntegrator; import org.apache.commons.math.ode.ExpandableStatefulODE; -import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.util.FastMath; /** @@ -96,7 +95,6 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator { sanityChecks(equations, t); setEquations(equations); - resetEvaluations(); final boolean forward = t > equations.getTime(); // create some internal working arrays @@ -119,10 +117,7 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator { // set up integration control objects stepStart = equations.getTime(); stepSize = forward ? step : -step; - for (StepHandler handler : stepHandlers) { - handler.reset(); - } - setStateInitialized(false); + initIntegration(equations.getTime(), y0, t); // main integration loop isLastStep = false; diff --git a/src/main/java/org/apache/commons/math/ode/sampling/DummyStepHandler.java b/src/main/java/org/apache/commons/math/ode/sampling/DummyStepHandler.java index b2f0e3273..0369053b7 100644 --- a/src/main/java/org/apache/commons/math/ode/sampling/DummyStepHandler.java +++ b/src/main/java/org/apache/commons/math/ode/sampling/DummyStepHandler.java @@ -50,11 +50,8 @@ public class DummyStepHandler implements StepHandler { return LazyHolder.INSTANCE; } - /** Reset the step handler. - * Initialize the internal data as required before the first step is - * handled. - */ - public void reset() { + /** {@inheritDoc} */ + public void init(double t0, double[] y0, double t) { } /** diff --git a/src/main/java/org/apache/commons/math/ode/sampling/StepHandler.java b/src/main/java/org/apache/commons/math/ode/sampling/StepHandler.java index f15ba4cd6..b3ac9f590 100644 --- a/src/main/java/org/apache/commons/math/ode/sampling/StepHandler.java +++ b/src/main/java/org/apache/commons/math/ode/sampling/StepHandler.java @@ -40,26 +40,32 @@ package org.apache.commons.math.ode.sampling; public interface StepHandler { - /** Reset the step handler. - * Initialize the internal data as required before the first step is - * handled. - */ - void reset(); + /** Initialize step handler at the start of an ODE integration. + *

+ * 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. + *

+ * @param t0 start value of the independent time 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 interpolator interpolator for the last accepted step. For - * efficiency purposes, the various integrators reuse the same - * object on each call, so if the instance wants to keep it across - * all calls (for example to provide at the end of the integration a - * continuous model valid throughout the integration range, as the - * {@link org.apache.commons.math.ode.ContinuousOutputModel - * ContinuousOutputModel} class does), it should build a local copy - * using the clone method of the interpolator and store this copy. - * Keeping only a reference to the interpolator and reusing it will - * result in unpredictable behavior (potentially crashing the application). - * @param isLast true if the step is the last one - */ - void handleStep(StepInterpolator interpolator, boolean isLast); + /** + * Handle the last accepted step + * @param interpolator interpolator for the last accepted step. For + * efficiency purposes, the various integrators reuse the same + * object on each call, so if the instance wants to keep it across + * all calls (for example to provide at the end of the integration a + * continuous model valid throughout the integration range, as the + * {@link org.apache.commons.math.ode.ContinuousOutputModel + * ContinuousOutputModel} class does), it should build a local copy + * using the clone method of the interpolator and store this copy. + * Keeping only a reference to the interpolator and reusing it will + * result in unpredictable behavior (potentially crashing the application). + * @param isLast true if the step is the last one + */ + void handleStep(StepInterpolator interpolator, boolean isLast); } diff --git a/src/main/java/org/apache/commons/math/ode/sampling/StepNormalizer.java b/src/main/java/org/apache/commons/math/ode/sampling/StepNormalizer.java index e3d43dc4b..9aa0a5954 100644 --- a/src/main/java/org/apache/commons/math/ode/sampling/StepNormalizer.java +++ b/src/main/java/org/apache/commons/math/ode/sampling/StepNormalizer.java @@ -161,18 +161,19 @@ public class StepNormalizer implements StepHandler { public StepNormalizer(final double h, final FixedStepHandler handler, final StepNormalizerMode mode, final StepNormalizerBounds bounds) { - this.h = FastMath.abs(h); - this.handler = handler; - this.mode = mode; - this.bounds = bounds; - reset(); + this.h = FastMath.abs(h); + this.handler = handler; + this.mode = mode; + this.bounds = bounds; + firstTime = Double.NaN; + lastTime = Double.NaN; + lastState = null; + lastDerivatives = null; + forward = true; } - /** Reset the step handler. - * Initialize the internal data as required before the first step is - * handled. - */ - public void reset() { + /** {@inheritDoc} */ + public void init(double t0, double[] y0, double t) { firstTime = Double.NaN; lastTime = Double.NaN; lastState = null; diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index bf71dcd30..7969b0b6d 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -52,6 +52,11 @@ The type attribute can be add,update,fix,remove. If the output is not quite correct, check for invisible trailing spaces! --> + + The reset method in StepHandler interface has been renamed init and is provided + more information on the integration by the calling integrator. A similar init method + has been added to the EventHandler interface. + Improved accuracy of Runge-Kutta based step interpolators near step start. diff --git a/src/site/xdoc/userguide/ode.xml b/src/site/xdoc/userguide/ode.xml index 86f5b37aa..84561b4f4 100644 --- a/src/site/xdoc/userguide/ode.xml +++ b/src/site/xdoc/userguide/ode.xml @@ -128,7 +128,8 @@ dp853.integrate(ode, 0.0, y, 16.0, y); // now y contains final state at time t=1

StepHandler stepHandler = new StepHandler() { - public void reset() {} + public void init(double t0, double[] y0, double t) { + } public void handleStep(StepInterpolator interpolator, boolean isLast) { double t = interpolator.getCurrentTime(); @@ -182,15 +183,10 @@ integrator.addStepHandler(stepHandler); a simple g(t, y) function depending on the current time and state. The integrator will monitor the value of the function throughout integration range and will trigger the - event when its sign changes. The magnitude of the value is almost irrelevant, - it should however be continuous (but not necessarily smooth) for the sake of - root finding. The steps are shortened as needed to ensure the events occur - at step boundaries (even if the integrator is a fixed-step integrator). Note that - g function signs changes at the very beginning of the integration (from t0 - to t0 + ε where ε is the events detection convergence threshold) - are explicitely ignored. This prevents having the integration stuck at its - initial point when a new integration is restarted just at the same point a - previous one had been stopped by an event. + event when its sign changes. The magnitude of the value is almost irrelevant. + For the sake of root finding, it should however be continuous (but not necessarily smooth) + at least in the roots vicinity. The steps are shortened as needed to ensure the events occur + at step boundaries (even if the integrator is a fixed-step integrator).

When an event is triggered, the event time, current state and an indicator diff --git a/src/test/java/org/apache/commons/math/ode/TestProblem4.java b/src/test/java/org/apache/commons/math/ode/TestProblem4.java index 44fee21ee..5a8f91540 100644 --- a/src/test/java/org/apache/commons/math/ode/TestProblem4.java +++ b/src/test/java/org/apache/commons/math/ode/TestProblem4.java @@ -115,6 +115,9 @@ public TestProblem4 copy() { sign = +1; } + public void init(double t0, double[] y0, double t) { + } + public double g(double t, double[] y) { return sign * y[0]; } @@ -137,6 +140,9 @@ public TestProblem4 copy() { public Stop() { } + public void init(double t0, double[] y0, double t) { + } + public double g(double t, double[] y) { return t - 12.0; } diff --git a/src/test/java/org/apache/commons/math/ode/TestProblemHandler.java b/src/test/java/org/apache/commons/math/ode/TestProblemHandler.java index 4cbf4ddf8..8118d7173 100644 --- a/src/test/java/org/apache/commons/math/ode/TestProblemHandler.java +++ b/src/test/java/org/apache/commons/math/ode/TestProblemHandler.java @@ -55,10 +55,13 @@ public class TestProblemHandler public TestProblemHandler(TestProblemAbstract problem, ODEIntegrator integrator) { this.problem = problem; this.integrator = integrator; - reset(); + maxValueError = 0; + maxTimeError = 0; + lastError = 0; + expectedStepStart = Double.NaN; } - public void reset() { + public void init(double t0, double[] y0, double t) { maxValueError = 0; maxTimeError = 0; lastError = 0; diff --git a/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java b/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java index 7813c1c51..80d07f189 100644 --- a/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java +++ b/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java @@ -36,6 +36,8 @@ public class EventStateTest { final double r2 = 135.0; final double gap = r2 - r1; EventHandler closeEventsGenerator = new EventHandler() { + public void init(double t0, double[] y0, double t) { + } public void resetState(double t, double[] y) { } public double g(double t, double[] y) { @@ -112,6 +114,9 @@ public class EventStateTest { this.tEvent = tEvent; } + public void init(double t0, double[] y0, double t) { + } + public double g(double t, double[] y) { // the bug corresponding to issue 695 causes the g function // to be called at obsolete times t despite an event diff --git a/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java b/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java index 30b166f95..0d615b184 100644 --- a/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java +++ b/src/test/java/org/apache/commons/math/ode/events/OverlappingEventsTest.java @@ -135,6 +135,10 @@ public class OverlappingEventsTest implements FirstOrderDifferentialEquations { this.eventType = eventType; } + /** {@inheritDoc} */ + public void init(double t0, double[] y0, double t) { + } + /** {@inheritDoc} */ public double g(double t, double[] y) { return (eventType == 0) ? y[idx] >= 1.0 ? 1.0 : -1.0 diff --git a/src/test/java/org/apache/commons/math/ode/events/ReappearingEventTest.java b/src/test/java/org/apache/commons/math/ode/events/ReappearingEventTest.java index 239854a92..87a01ee4f 100644 --- a/src/test/java/org/apache/commons/math/ode/events/ReappearingEventTest.java +++ b/src/test/java/org/apache/commons/math/ode/events/ReappearingEventTest.java @@ -67,6 +67,10 @@ public class ReappearingEventTest { /** State events for this unit test. */ protected static class Event implements EventHandler { + + public void init(double t0, double[] y0, double t) { + } + public double g(double t, double[] y) { return y[6] - 15.0; } diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java index 00c5ad2d5..9414c6a85 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java @@ -71,6 +71,9 @@ public class ClassicalRungeKuttaIntegratorTest { integrator.addEventHandler(new EventHandler() { + public void init(double t0, double[] y0, double t) { + } + public void resetState(double t, double[] y) { } @@ -242,9 +245,9 @@ public class ClassicalRungeKuttaIntegratorTest { private static class KeplerHandler implements StepHandler { public KeplerHandler(TestProblem3 pb) { this.pb = pb; - reset(); + maxError = 0; } - public void reset() { + public void init(double t0, double[] y0, double t) { maxError = 0; } public void handleStep(StepInterpolator interpolator, boolean isLast) { @@ -281,7 +284,7 @@ public class ClassicalRungeKuttaIntegratorTest { 1.0e-12); } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(new FirstOrderDifferentialEquations() { diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java index dbebdf19a..0a8ae4ab7 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java @@ -124,7 +124,7 @@ public class DormandPrince54IntegratorTest { this.minStep = minStep; } - public void reset() { + public void init(double t0, double[] y0, double t) { } public void handleStep(StepInterpolator interpolator, boolean isLast) { @@ -265,9 +265,8 @@ public class DormandPrince54IntegratorTest { private static class KeplerHandler implements StepHandler { public KeplerHandler(TestProblem3 pb) { this.pb = pb; - reset(); } - public void reset() { + public void init(double t0, double[] y0, double t) { nbSteps = 0; maxError = 0; } @@ -306,7 +305,7 @@ public class DormandPrince54IntegratorTest { minStep = 0; maxStep = 0; } - public void reset() { + public void init(double t0, double[] y0, double t) { firstTime = true; minStep = 0; maxStep = 0; diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince54StepInterpolatorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince54StepInterpolatorTest.java index 22ec5f301..6ba85576f 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince54StepInterpolatorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince54StepInterpolatorTest.java @@ -112,7 +112,7 @@ public class DormandPrince54StepInterpolatorTest { scalAbsoluteTolerance, scalRelativeTolerance); integ.addStepHandler(new StepHandler() { - public void handleStep(StepInterpolator interpolator, boolean isLast) { + public void handleStep(StepInterpolator interpolator, boolean isLast) { StepInterpolator cloned = interpolator.copy(); double tA = cloned.getPreviousTime(); double tB = cloned.getCurrentTime(); @@ -132,7 +132,7 @@ public class DormandPrince54StepInterpolatorTest { } } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(pb, diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java index 723d16b5b..7d5e9b736 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java @@ -73,6 +73,9 @@ public class DormandPrince853IntegratorTest { integrator.setInitialStepSize(60.0); integrator.addEventHandler(new EventHandler() { + public void init(double t0, double[] y0, double t) { + } + public void resetState(double t, double[] y) { } @@ -289,9 +292,8 @@ public class DormandPrince853IntegratorTest { private static class KeplerHandler implements StepHandler { public KeplerHandler(TestProblem3 pb) { this.pb = pb; - reset(); } - public void reset() { + public void init(double t0, double[] y0, double t) { nbSteps = 0; maxError = 0; } @@ -326,9 +328,11 @@ public class DormandPrince853IntegratorTest { private static class VariableHandler implements StepHandler { public VariableHandler() { - reset(); + firstTime = true; + minStep = 0; + maxStep = 0; } - public void reset() { + public void init(double t0, double[] y0, double t) { firstTime = true; minStep = 0; maxStep = 0; diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolatorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolatorTest.java index e2c0f45ba..f88e07516 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolatorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolatorTest.java @@ -132,7 +132,7 @@ public class DormandPrince853StepInterpolatorTest { } } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(pb, diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java index 77932e95f..affe289ee 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java @@ -163,7 +163,7 @@ public class EulerIntegratorTest { 1.0e-12); } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(new FirstOrderDifferentialEquations() { diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java index c25282e8f..e3e06ce6c 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java @@ -177,9 +177,8 @@ public class GillIntegratorTest { private static class KeplerStepHandler implements StepHandler { public KeplerStepHandler(TestProblem3 pb) { this.pb = pb; - reset(); } - public void reset() { + public void init(double t0, double[] y0, double t) { maxError = 0; } public void handleStep(StepInterpolator interpolator, boolean isLast) { @@ -216,7 +215,7 @@ public class GillIntegratorTest { 1.0e-12); } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(new FirstOrderDifferentialEquations() { diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java index 69ae26a03..0be4a0c5c 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java @@ -271,7 +271,8 @@ public class GraggBulirschStoerIntegratorTest { FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(1e-10, 100.0, 1e-7, 1e-7); integ.addStepHandler(new StepHandler() { - public void reset() {} + public void init(double t0, double[] y0, double t) { + } public void handleStep(StepInterpolator interpolator, boolean isLast) { double t = interpolator.getCurrentTime(); @@ -300,9 +301,8 @@ public class GraggBulirschStoerIntegratorTest { private static class KeplerStepHandler implements StepHandler { public KeplerStepHandler(TestProblem3 pb) { this.pb = pb; - reset(); } - public void reset() { + public void init(double t0, double[] y0, double t) { nbSteps = 0; maxError = 0; } @@ -337,9 +337,11 @@ public class GraggBulirschStoerIntegratorTest { public static class VariableStepHandler implements StepHandler { public VariableStepHandler() { - reset(); + firstTime = true; + minStep = 0; + maxStep = 0; } - public void reset() { + public void init(double t0, double[] y0, double t) { firstTime = true; minStep = 0; maxStep = 0; diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolatorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolatorTest.java index 89e5ad089..2729ebcb2 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolatorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolatorTest.java @@ -134,7 +134,7 @@ public class GraggBulirschStoerStepInterpolatorTest { } } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(pb, diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java index 74dc08640..60853085b 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java @@ -202,6 +202,8 @@ public class HighamHall54IntegratorTest { integ.addStepHandler(handler); integ.addEventHandler(new EventHandler() { + public void init(double t0, double[] y0, double t) { + } public Action eventOccurred(double t, double[] y, boolean increasing) { return Action.CONTINUE; } @@ -246,6 +248,8 @@ public class HighamHall54IntegratorTest { integ.addStepHandler(handler); integ.addEventHandler(new EventHandler() { + public void init(double t0, double[] y0, double t) { + } public Action eventOccurred(double t, double[] y, boolean increasing) { return Action.CONTINUE; } diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java index 42787d2e3..a2b6607a0 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java @@ -132,7 +132,7 @@ public class HighamHall54StepInterpolatorTest { } } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(pb, diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java index 624c07b4a..a55fcc840 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java @@ -163,7 +163,7 @@ public class MidpointIntegratorTest { 1.0e-12); } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(new FirstOrderDifferentialEquations() { diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java b/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java index 00f7cdd6c..49c5cb84f 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/StepProblem.java @@ -43,6 +43,9 @@ public class StepProblem this.rate = rate; } + public void init(double t0, double[] y0, double t) { + } + public Action eventOccurred(double t, double[] y, boolean increasing) { setRate(rateAfter); return Action.RESET_DERIVATIVES; diff --git a/src/test/java/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java b/src/test/java/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java index d88609cb1..a46a6da2f 100644 --- a/src/test/java/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java +++ b/src/test/java/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java @@ -170,7 +170,7 @@ public class ThreeEighthesIntegratorTest { maxError = 0; } - public void reset() { + public void init(double t0, double[] y0, double t) { maxError = 0; } @@ -210,7 +210,7 @@ public class ThreeEighthesIntegratorTest { 1.0e-12); } } - public void reset() { + public void init(double t0, double[] y0, double t) { } }); integ.integrate(new FirstOrderDifferentialEquations() { diff --git a/src/test/java/org/apache/commons/math/ode/sampling/StepInterpolatorTestUtils.java b/src/test/java/org/apache/commons/math/ode/sampling/StepInterpolatorTestUtils.java index 10cfa6e02..206f790a7 100644 --- a/src/test/java/org/apache/commons/math/ode/sampling/StepInterpolatorTestUtils.java +++ b/src/test/java/org/apache/commons/math/ode/sampling/StepInterpolatorTestUtils.java @@ -68,7 +68,7 @@ public class StepInterpolatorTestUtils { } - public void reset() { + public void init(double t0, double[] y0, double t) { } });