diff --git a/src/java/org/apache/commons/math/ode/AbstractIntegrator.java b/src/java/org/apache/commons/math/ode/AbstractIntegrator.java index ea7dbe323..a04e12242 100644 --- a/src/java/org/apache/commons/math/ode/AbstractIntegrator.java +++ b/src/java/org/apache/commons/math/ode/AbstractIntegrator.java @@ -17,11 +17,12 @@ package org.apache.commons.math.ode; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import org.apache.commons.math.ode.events.CombinedEventsManager; import org.apache.commons.math.ode.events.EventHandler; -import org.apache.commons.math.ode.sampling.DummyStepHandler; import org.apache.commons.math.ode.sampling.StepHandler; /** @@ -35,7 +36,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { private final String name; /** Step handler. */ - protected StepHandler handler; + protected Collection stepHandlers; /** Current step start time. */ protected double stepStart; @@ -51,7 +52,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { */ public AbstractIntegrator(final String name) { this.name = name; - handler = DummyStepHandler.getInstance(); + stepHandlers = new ArrayList(); stepStart = Double.NaN; stepSize = Double.NaN; eventsHandlersManager = new CombinedEventsManager(); @@ -63,13 +64,18 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { } /** {@inheritDoc} */ - public void setStepHandler(final StepHandler handler) { - this.handler = handler; + public void addStepHandler(final StepHandler handler) { + stepHandlers.add(handler); } /** {@inheritDoc} */ - public StepHandler getStepHandler() { - return handler; + public Collection getStepHandlers() { + return Collections.unmodifiableCollection(stepHandlers); + } + + /** {@inheritDoc} */ + public void clearStepHandlers() { + stepHandlers.clear(); } /** {@inheritDoc} */ @@ -82,15 +88,27 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { } /** {@inheritDoc} */ - public Collection getEventsHandlers() { + public Collection getEventHandlers() { return eventsHandlersManager.getEventsHandlers(); } /** {@inheritDoc} */ - public void clearEventsHandlers() { + public void clearEventHandlers() { eventsHandlersManager.clearEventsHandlers(); } + /** Check if one of the step handlers requires dense output. + * @return true if one of the step handlers requires dense output + */ + protected boolean requiresDenseOutput() { + for (StepHandler handler : stepHandlers) { + if (handler.requiresDenseOutput()) { + return true; + } + } + return false; + } + /** {@inheritDoc} */ public double getCurrentStepStart() { return stepStart; diff --git a/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java b/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java index 64e265064..80640779d 100644 --- a/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java +++ b/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java @@ -45,17 +45,30 @@ public interface FirstOrderIntegrator extends Serializable { */ public String getName(); - /** Set the step handler for this integrator. - * The handler will be called by the integrator for each accepted - * step. + /** Add a step handler to this integrator. + *

The handler will be called by the integrator for each accepted + * step.

* @param handler handler for the accepted steps + * @see #getStepHandlers() + * @see #clearStepHandlers() + * @since 2.0 */ - public void setStepHandler (StepHandler handler); + public void addStepHandler (StepHandler handler); - /** Get the step handler for this integrator. - * @return the step handler for this integrator + /** Get all the step handlers that have been added to the integrator. + * @return an unmodifiable collection of the added events handlers + * @see #addStepHandler(StepHandler) + * @see #clearStepHandlers() + * @since 2.0 */ - public StepHandler getStepHandler(); + public Collection getStepHandlers(); + + /** Remove all the step handlers that have been added to the integrator. + * @see #addStepHandler(StepHandler) + * @see #getStepHandlers() + * @since 2.0 + */ + public void clearStepHandlers(); /** Add an event handler to the integrator. * @param handler event handler @@ -65,24 +78,24 @@ public interface FirstOrderIntegrator extends Serializable { * @param convergence convergence threshold in the event time search * @param maxIterationCount upper limit of the iteration count in * the event time search - * @see #getEventsHandlers() - * @see #clearEventsHandlers() + * @see #getEventHandlers() + * @see #clearEventHandlers() */ public void addEventHandler(EventHandler handler, double maxCheckInterval, double convergence, int maxIterationCount); - /** Get all the events handlers that have been added to the integrator. + /** Get all the event handlers that have been added to the integrator. * @return an unmodifiable collection of the added events handlers * @see #addEventHandler(EventHandler, double, double, int) - * @see #clearEventsHandlers() + * @see #clearEventHandlers() */ - public Collection getEventsHandlers(); + public Collection getEventHandlers(); - /** Remove all the events handlers that have been added to the integrator. + /** Remove all the event handlers that have been added to the integrator. * @see #addEventHandler(EventHandler, double, double, int) - * @see #getEventsHandlers() + * @see #getEventHandlers() */ - public void clearEventsHandlers(); + public void clearEventHandlers(); /** Integrate the differential equations up to the given time. *

This method solves an Initial Value Problem (IVP).

diff --git a/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java b/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java index 320f2c31a..e0b7564c5 100644 --- a/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java +++ b/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java @@ -22,6 +22,7 @@ import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.IntegratorException; import org.apache.commons.math.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math.ode.sampling.DummyStepInterpolator; +import org.apache.commons.math.ode.sampling.StepHandler; /** * This class implements the common part of all embedded Runge-Kutta @@ -180,7 +181,7 @@ public abstract class EmbeddedRungeKuttaIntegrator // set up an interpolator sharing the integrator arrays AbstractStepInterpolator interpolator; - if (handler.requiresDenseOutput() || (! eventsHandlersManager.isEmpty())) { + if (requiresDenseOutput() || (! eventsHandlersManager.isEmpty())) { final RungeKuttaStepInterpolator rki = (RungeKuttaStepInterpolator) prototype.copy(); rki.reinitialize(equations, yTmp, yDotK, forward); interpolator = rki; @@ -193,7 +194,9 @@ public abstract class EmbeddedRungeKuttaIntegrator double hNew = 0; boolean firstTime = true; boolean lastStep; - handler.reset(); + for (StepHandler handler : stepHandlers) { + handler.reset(); + } do { interpolator.shift(); @@ -289,7 +292,9 @@ public abstract class EmbeddedRungeKuttaIntegrator // provide the step data to the step handler interpolator.storeTime(nextStep); - handler.handleStep(interpolator, lastStep); + for (StepHandler handler : stepHandlers) { + handler.handleStep(interpolator, lastStep); + } stepStart = nextStep; if (fsal) { diff --git a/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java b/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java index 717e7a599..73e89b3ac 100644 --- a/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java +++ b/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java @@ -117,7 +117,7 @@ public class GraggBulirschStoerIntegrator final double scalRelativeTolerance) { super(METHOD_NAME, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - denseOutput = (handler.requiresDenseOutput() || (! eventsHandlersManager.isEmpty())); + denseOutput = requiresDenseOutput() || (! eventsHandlersManager.isEmpty()); setStabilityCheck(true, -1, -1, -1); setStepsizeControl(-1, -1, -1, -1); setOrderControl(-1, -1, -1); @@ -140,7 +140,7 @@ public class GraggBulirschStoerIntegrator final double[] vecRelativeTolerance) { super(METHOD_NAME, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); - denseOutput = (handler.requiresDenseOutput() || (! eventsHandlersManager.isEmpty())); + denseOutput = requiresDenseOutput() || (! eventsHandlersManager.isEmpty()); setStabilityCheck(true, -1, -1, -1); setStepsizeControl(-1, -1, -1, -1); setOrderControl(-1, -1, -1); @@ -281,15 +281,11 @@ public class GraggBulirschStoerIntegrator } - /** Set the step handler for this integrator. - * The handler will be called by the integrator for each accepted - * step. - * @param handler handler for the accepted steps - */ - public void setStepHandler (final StepHandler handler) { + /** {@inheritDoc} */ + public void addStepHandler (final StepHandler handler) { - super.setStepHandler(handler); - denseOutput = (handler.requiresDenseOutput() || (! eventsHandlersManager.isEmpty())); + super.addStepHandler(handler); + denseOutput = requiresDenseOutput() || (! eventsHandlersManager.isEmpty()); // reinitialize the arrays initializeArrays(); @@ -302,7 +298,7 @@ public class GraggBulirschStoerIntegrator final double convergence, final int maxIterationCount) { super.addEventHandler(function, maxCheckInterval, convergence, maxIterationCount); - denseOutput = (handler.requiresDenseOutput() || (! eventsHandlersManager.isEmpty())); + denseOutput = requiresDenseOutput() || (! eventsHandlersManager.isEmpty()); // reinitialize the arrays initializeArrays(); @@ -585,7 +581,9 @@ public class GraggBulirschStoerIntegrator boolean newStep = true; boolean lastStep = false; boolean firstStepAlreadyComputed = false; - handler.reset(); + for (StepHandler handler : stepHandlers) { + handler.reset(); + } costPerTimeUnit[0] = 0; while (! lastStep) { @@ -858,7 +856,9 @@ public class GraggBulirschStoerIntegrator // provide the step data to the step handler interpolator.storeTime(nextStep); - handler.handleStep(interpolator, lastStep); + for (StepHandler handler : stepHandlers) { + handler.handleStep(interpolator, lastStep); + } stepStart = nextStep; if (eventsHandlersManager.reset(stepStart, y) && ! lastStep) { diff --git a/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java b/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java index 4e89bea62..d58fa3f45 100644 --- a/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java +++ b/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java @@ -24,6 +24,7 @@ import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.IntegratorException; import org.apache.commons.math.ode.sampling.AbstractStepInterpolator; import org.apache.commons.math.ode.sampling.DummyStepInterpolator; +import org.apache.commons.math.ode.sampling.StepHandler; /** * This class implements the common part of all fixed step Runge-Kutta @@ -96,7 +97,7 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator { // set up an interpolator sharing the integrator arrays AbstractStepInterpolator interpolator; - if (handler.requiresDenseOutput() || (! eventsHandlersManager.isEmpty())) { + if (requiresDenseOutput() || (! eventsHandlersManager.isEmpty())) { final RungeKuttaStepInterpolator rki = (RungeKuttaStepInterpolator) prototype.copy(); rki.reinitialize(equations, yTmp, yDotK, forward); interpolator = rki; @@ -110,7 +111,9 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator { boolean lastStep = false; stepStart = t0; stepSize = (t - t0) / nbStep; - handler.reset(); + for (StepHandler handler : stepHandlers) { + handler.reset(); + } for (long i = 0; ! lastStep; ++i) { interpolator.shift(); @@ -168,7 +171,9 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator { // provide the step data to the step handler interpolator.storeTime(nextStep); - handler.handleStep(interpolator, lastStep); + for (StepHandler handler : stepHandlers) { + handler.handleStep(interpolator, lastStep); + } stepStart = nextStep; if (eventsHandlersManager.reset(stepStart, y) && ! lastStep) { diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 9006a2ba7..4a7af0f2a 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -39,6 +39,13 @@ The type attribute can be add,update,fix,remove. + + The ODE integrators now support several step handlers at once, instead of just one. + This is more consistent with event handlers management. + The setStepHandler method has therefore been replaced by addStephandler, the + getStepHandler method has been replaced by getStepHandlers which returns a Collection + and a clearStepHandlers method has been added. + All step interpolators for ODE integrators now provide interpolation for both the state and its time derivatives. The interpolated derivatives are diff --git a/src/test/org/apache/commons/math/ode/ContinuousOutputModelTest.java b/src/test/org/apache/commons/math/ode/ContinuousOutputModelTest.java index a389da3b0..5f58d8285 100644 --- a/src/test/org/apache/commons/math/ode/ContinuousOutputModelTest.java +++ b/src/test/org/apache/commons/math/ode/ContinuousOutputModelTest.java @@ -41,11 +41,11 @@ public class ContinuousOutputModelTest public void testBoundaries() throws DerivativeException, IntegratorException { - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); - ContinuousOutputModel cm = (ContinuousOutputModel) integ.getStepHandler(); + ContinuousOutputModel cm = (ContinuousOutputModel) integ.getStepHandlers().iterator().next(); cm.setInterpolatedTime(2.0 * pb.getInitialTime() - pb.getFinalTime()); cm.setInterpolatedTime(2.0 * pb.getFinalTime() - pb.getInitialTime()); cm.setInterpolatedTime(0.5 * (pb.getFinalTime() + pb.getInitialTime())); @@ -55,7 +55,7 @@ public class ContinuousOutputModelTest throws DerivativeException, IntegratorException { ContinuousOutputModel cm = new ContinuousOutputModel(); - integ.setStepHandler(cm); + integ.addStepHandler(cm); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -101,7 +101,7 @@ public class ContinuousOutputModelTest ContinuousOutputModel cm1 = new ContinuousOutputModel(); FirstOrderIntegrator integ1 = new DormandPrince853Integrator(0, 1.0, 1.0e-8, 1.0e-8); - integ1.setStepHandler(cm1); + integ1.addStepHandler(cm1); integ1.integrate(problem, Math.PI, new double[] { -1.0, 0.0 }, 0, new double[2]); @@ -109,7 +109,7 @@ public class ContinuousOutputModelTest ContinuousOutputModel cm2 = new ContinuousOutputModel(); FirstOrderIntegrator integ2 = new DormandPrince853Integrator(0, 0.1, 1.0e-12, 1.0e-12); - integ2.setStepHandler(cm2); + integ2.addStepHandler(cm2); integ2.integrate(problem, 2.0 * Math.PI, new double[] { 1.0, 0.0 }, Math.PI, new double[2]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java index 4cbdd884e..1bf1ecd0a 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java @@ -81,13 +81,13 @@ public class ClassicalRungeKuttaIntegratorTest FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, 1.0e-6 * step, 1000); } - assertEquals(functions.length, integ.getEventsHandlers().size()); + assertEquals(functions.length, integ.getEventHandlers().size()); double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); if (functions.length == 0) { @@ -100,8 +100,8 @@ public class ClassicalRungeKuttaIntegratorTest } previousError = error; assertEquals(0, handler.getMaximalTimeError(), 1.0e-12); - integ.clearEventsHandlers(); - assertEquals(0, integ.getEventsHandlers().size()); + integ.clearEventHandlers(); + assertEquals(0, integ.getEventHandlers().size()); } } @@ -116,7 +116,7 @@ public class ClassicalRungeKuttaIntegratorTest FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -134,7 +134,7 @@ public class ClassicalRungeKuttaIntegratorTest FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -151,7 +151,7 @@ public class ClassicalRungeKuttaIntegratorTest double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); - integ.setStepHandler(new KeplerHandler(pb)); + integ.addStepHandler(new KeplerHandler(pb)); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaStepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaStepInterpolatorTest.java index a9c7f3fe1..be612e904 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaStepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaStepInterpolatorTest.java @@ -30,6 +30,7 @@ import junit.framework.TestSuite; import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.IntegratorException; +import org.apache.commons.math.ode.sampling.StepHandler; public class ClassicalRungeKuttaStepInterpolatorTest extends StepInterpolatorAbstractTest { @@ -53,14 +54,16 @@ public class ClassicalRungeKuttaStepInterpolatorTest TestProblem3 pb = new TestProblem3(0.9); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; ClassicalRungeKuttaIntegrator integ = new ClassicalRungeKuttaIntegrator(step); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 700000); assertTrue(bos.size () < 701000); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java index 4a98880bc..f43441e54 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java @@ -64,7 +64,7 @@ public class DormandPrince54IntegratorTest vecAbsoluteTolerance, vecRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -91,7 +91,7 @@ public class DormandPrince54IntegratorTest scalRelativeTolerance); DP54SmallLastHandler handler = new DP54SmallLastHandler(minStep); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.setInitialStepSize(1.7); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), @@ -152,7 +152,7 @@ public class DormandPrince54IntegratorTest integ.setSafety(0.8); integ.setMaxGrowth(5.0); integ.setMinReduction(0.3); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -187,13 +187,13 @@ public class DormandPrince54IntegratorTest scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); } - assertEquals(functions.length, integ.getEventsHandlers().size()); + assertEquals(functions.length, integ.getEventHandlers().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -201,8 +201,8 @@ public class DormandPrince54IntegratorTest assertTrue(handler.getMaximalValueError() < 5.0e-6); assertEquals(0, handler.getMaximalTimeError(), 1.0e-12); assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep); - integ.clearEventsHandlers(); - assertEquals(0, integ.getEventsHandlers().size()); + integ.clearEventHandlers(); + assertEquals(0, integ.getEventHandlers().size()); } @@ -218,7 +218,7 @@ public class DormandPrince54IntegratorTest FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new KeplerHandler(pb)); + integ.addStepHandler(new KeplerHandler(pb)); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -239,7 +239,7 @@ public class DormandPrince54IntegratorTest FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new VariableHandler()); + integ.addStepHandler(new VariableHandler()); double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); assertEquals(pb.getFinalTime(), stopTime, 1.0e-10); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54StepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54StepInterpolatorTest.java index 9981ac8ab..31241e630 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54StepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54StepInterpolatorTest.java @@ -64,14 +64,16 @@ public class DormandPrince54StepInterpolatorTest DormandPrince54Integrator integ = new DormandPrince54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 119500); assertTrue(bos.size () < 120500); @@ -110,7 +112,7 @@ public class DormandPrince54StepInterpolatorTest DormandPrince54Integrator integ = new DormandPrince54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new StepHandler() { + integ.addStepHandler(new StepHandler() { private static final long serialVersionUID = -6768136169276197L; public void handleStep(StepInterpolator interpolator, boolean isLast) throws DerivativeException { diff --git a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java index 8ea28e2fa..674580443 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java @@ -79,7 +79,7 @@ public class DormandPrince853IntegratorTest vecAbsoluteTolerance, vecRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -106,7 +106,7 @@ public class DormandPrince853IntegratorTest scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -138,13 +138,13 @@ public class DormandPrince853IntegratorTest scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); } - assertEquals(functions.length, integ.getEventsHandlers().size()); + assertEquals(functions.length, integ.getEventHandlers().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -152,8 +152,8 @@ public class DormandPrince853IntegratorTest assertTrue(handler.getMaximalValueError() < 5.0e-8); assertEquals(0, handler.getMaximalTimeError(), 1.0e-12); assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep); - integ.clearEventsHandlers(); - assertEquals(0, integ.getEventsHandlers().size()); + integ.clearEventHandlers(); + assertEquals(0, integ.getEventHandlers().size()); } @@ -169,7 +169,7 @@ public class DormandPrince853IntegratorTest FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new KeplerHandler(pb)); + integ.addStepHandler(new KeplerHandler(pb)); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -190,7 +190,7 @@ public class DormandPrince853IntegratorTest FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new VariableHandler()); + integ.addStepHandler(new VariableHandler()); double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -210,13 +210,13 @@ public class DormandPrince853IntegratorTest FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(DummyStepHandler.getInstance()); + integ.addStepHandler(DummyStepHandler.getInstance()); integ.integrate(pb1, pb1.getInitialTime(), pb1.getInitialState(), pb1.getFinalTime(), new double[pb1.getDimension()]); int callsWithoutDenseOutput = pb1.getCalls(); - integ.setStepHandler(new InterpolatingStepHandler()); + integ.addStepHandler(new InterpolatingStepHandler()); integ.integrate(pb2, pb2.getInitialTime(), pb2.getInitialState(), pb2.getFinalTime(), new double[pb2.getDimension()]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolatorTest.java index 6209cbb86..3e005b9c3 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolatorTest.java @@ -64,14 +64,16 @@ public class DormandPrince853StepInterpolatorTest DormandPrince853Integrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 86000); assertTrue(bos.size () < 87000); @@ -110,7 +112,7 @@ public class DormandPrince853StepInterpolatorTest DormandPrince853Integrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new StepHandler() { + integ.addStepHandler(new StepHandler() { private static final long serialVersionUID = 2209212559670665268L; public void handleStep(StepInterpolator interpolator, boolean isLast) throws DerivativeException { diff --git a/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java index ce9da9ee3..a8809415d 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java @@ -60,7 +60,7 @@ public class EulerIntegratorTest FirstOrderIntegrator integ = new EulerIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], @@ -93,7 +93,7 @@ public class EulerIntegratorTest FirstOrderIntegrator integ = new EulerIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -113,7 +113,7 @@ public class EulerIntegratorTest FirstOrderIntegrator integ = new EulerIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/EulerStepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/EulerStepInterpolatorTest.java index c6576ffa6..48d38f881 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/EulerStepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/EulerStepInterpolatorTest.java @@ -31,6 +31,7 @@ import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.FirstOrderDifferentialEquations; import org.apache.commons.math.ode.IntegratorException; +import org.apache.commons.math.ode.sampling.StepHandler; public class EulerStepInterpolatorTest extends StepInterpolatorAbstractTest { @@ -132,14 +133,16 @@ public class EulerStepInterpolatorTest TestProblem1 pb = new TestProblem1(); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; EulerIntegrator integ = new EulerIntegrator(step); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 82000); assertTrue(bos.size () < 83000); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java index 1ef0d9db0..251344533 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java @@ -62,7 +62,7 @@ public class GillIntegratorTest FirstOrderIntegrator integ = new GillIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], @@ -95,7 +95,7 @@ public class GillIntegratorTest FirstOrderIntegrator integ = new GillIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -114,7 +114,7 @@ public class GillIntegratorTest FirstOrderIntegrator integ = new GillIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -131,7 +131,7 @@ public class GillIntegratorTest double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; FirstOrderIntegrator integ = new GillIntegrator(step); - integ.setStepHandler(new KeplerStepHandler(pb)); + integ.addStepHandler(new KeplerStepHandler(pb)); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/GillStepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/GillStepInterpolatorTest.java index dfffaddac..c3c2290a3 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/GillStepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/GillStepInterpolatorTest.java @@ -29,6 +29,7 @@ import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.IntegratorException; import org.apache.commons.math.ode.nonstiff.GillIntegrator; +import org.apache.commons.math.ode.sampling.StepHandler; public class GillStepInterpolatorTest extends StepInterpolatorAbstractTest { @@ -52,14 +53,16 @@ public class GillStepInterpolatorTest TestProblem3 pb = new TestProblem3(0.9); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; GillIntegrator integ = new GillIntegrator(step); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 700000); assertTrue(bos.size () < 701000); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java index 82a7709c4..b7ecde4ea 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java @@ -78,7 +78,7 @@ public class GraggBulirschStoerIntegratorTest new GraggBulirschStoerIntegrator(minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -105,7 +105,7 @@ public class GraggBulirschStoerIntegratorTest new GraggBulirschStoerIntegrator(minStep, maxStep, absTolerance, relTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -158,7 +158,7 @@ public class GraggBulirschStoerIntegratorTest private double getMaxError(FirstOrderIntegrator integrator, TestProblemAbstract pb) throws DerivativeException, IntegratorException { TestProblemHandler handler = new TestProblemHandler(pb, integrator); - integrator.setStepHandler(handler); + integrator.addStepHandler(handler); integrator.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -178,13 +178,13 @@ public class GraggBulirschStoerIntegratorTest scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); } - assertEquals(functions.length, integ.getEventsHandlers().size()); + assertEquals(functions.length, integ.getEventHandlers().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -192,8 +192,8 @@ public class GraggBulirschStoerIntegratorTest assertTrue(handler.getMaximalValueError() < 5.0e-8); assertEquals(0, handler.getMaximalTimeError(), 1.0e-12); assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep); - integ.clearEventsHandlers(); - assertEquals(0, integ.getEventsHandlers().size()); + integ.clearEventHandlers(); + assertEquals(0, integ.getEventHandlers().size()); } @@ -209,7 +209,7 @@ public class GraggBulirschStoerIntegratorTest FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep, absTolerance, relTolerance); - integ.setStepHandler(new KeplerStepHandler(pb)); + integ.addStepHandler(new KeplerStepHandler(pb)); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -229,7 +229,7 @@ public class GraggBulirschStoerIntegratorTest FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep, absTolerance, relTolerance); - integ.setStepHandler(new VariableStepHandler()); + integ.addStepHandler(new VariableStepHandler()); double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolatorTest.java index d1115cc76..cb2ec0445 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolatorTest.java @@ -66,14 +66,16 @@ public class GraggBulirschStoerStepInterpolatorTest GraggBulirschStoerIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep, absTolerance, relTolerance); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 34000); assertTrue(bos.size () < 35000); @@ -112,7 +114,7 @@ public class GraggBulirschStoerStepInterpolatorTest GraggBulirschStoerIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new StepHandler() { + integ.addStepHandler(new StepHandler() { private static final long serialVersionUID = -5947183291381232297L; public void handleStep(StepInterpolator interpolator, boolean isLast) throws DerivativeException { diff --git a/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java index b8381cb51..cbc721d5f 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java @@ -92,7 +92,7 @@ public class HighamHall54IntegratorTest vecAbsoluteTolerance, vecRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -119,7 +119,7 @@ public class HighamHall54IntegratorTest scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -151,13 +151,13 @@ public class HighamHall54IntegratorTest scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); } - assertEquals(functions.length, integ.getEventsHandlers().size()); + assertEquals(functions.length, integ.getEventHandlers().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -165,8 +165,8 @@ public class HighamHall54IntegratorTest assertTrue(handler.getMaximalValueError() < 1.0e-7); assertEquals(0, handler.getMaximalTimeError(), 1.0e-12); assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep); - integ.clearEventsHandlers(); - assertEquals(0, integ.getEventsHandlers().size()); + integ.clearEventHandlers(); + assertEquals(0, integ.getEventHandlers().size()); } @@ -183,7 +183,7 @@ public class HighamHall54IntegratorTest new HighamHall54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.addEventHandler(new EventHandler() { public int eventOccurred(double t, double[] y) { @@ -229,7 +229,7 @@ public class HighamHall54IntegratorTest new HighamHall54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.addEventHandler(new EventHandler() { public int eventOccurred(double t, double[] y) { @@ -332,7 +332,7 @@ public class HighamHall54IntegratorTest FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); - integ.setStepHandler(new KeplerHandler(pb)); + integ.addStepHandler(new KeplerHandler(pb)); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java index 2cb962057..74541c35c 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54StepInterpolatorTest.java @@ -64,14 +64,16 @@ public class HighamHall54StepInterpolatorTest HighamHall54Integrator integ = new HighamHall54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 158000); assertTrue(bos.size () < 159000); @@ -110,7 +112,7 @@ public class HighamHall54StepInterpolatorTest HighamHall54Integrator integ = new HighamHall54Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - integ.setStepHandler(new StepHandler() { + integ.addStepHandler(new StepHandler() { private static final long serialVersionUID = 9111679755950880352L; public void handleStep(StepInterpolator interpolator, boolean isLast) throws DerivativeException { diff --git a/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java index e77bbc132..f1e2b2942 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java @@ -59,7 +59,7 @@ public class MidpointIntegratorTest * Math.pow(2.0, -i); FirstOrderIntegrator integ = new MidpointIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], @@ -93,7 +93,7 @@ public class MidpointIntegratorTest FirstOrderIntegrator integ = new MidpointIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -113,7 +113,7 @@ public class MidpointIntegratorTest FirstOrderIntegrator integ = new MidpointIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/MidpointStepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/MidpointStepInterpolatorTest.java index 37afab9b4..a2c864db3 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/MidpointStepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/MidpointStepInterpolatorTest.java @@ -30,6 +30,7 @@ import junit.framework.TestSuite; import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.IntegratorException; +import org.apache.commons.math.ode.sampling.StepHandler; public class MidpointStepInterpolatorTest extends StepInterpolatorAbstractTest { @@ -53,14 +54,16 @@ public class MidpointStepInterpolatorTest TestProblem1 pb = new TestProblem1(); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; MidpointIntegrator integ = new MidpointIntegrator(step); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 98000); assertTrue(bos.size () < 99000); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/StepInterpolatorAbstractTest.java b/src/test/org/apache/commons/math/ode/nonstiff/StepInterpolatorAbstractTest.java index 941ffa67d..11cfccc13 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/StepInterpolatorAbstractTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/StepInterpolatorAbstractTest.java @@ -34,7 +34,7 @@ public class StepInterpolatorAbstractTest extends TestCase { final TestProblemAbstract problem, final double threshold) throws DerivativeException, IntegratorException { - integrator.setStepHandler(new StepHandler() { + integrator.addStepHandler(new StepHandler() { private static final long serialVersionUID = 2462564234755682953L; diff --git a/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java index f0089fc97..d865efd3b 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java @@ -62,7 +62,7 @@ public class ThreeEighthesIntegratorTest FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); EventHandler[] functions = pb.getEventsHandlers(); for (int l = 0; l < functions.length; ++l) { integ.addEventHandler(functions[l], @@ -95,7 +95,7 @@ public class ThreeEighthesIntegratorTest FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -114,7 +114,7 @@ public class ThreeEighthesIntegratorTest FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); - integ.setStepHandler(handler); + integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -131,7 +131,7 @@ public class ThreeEighthesIntegratorTest double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step); - integ.setStepHandler(new KeplerHandler(pb)); + integ.addStepHandler(new KeplerHandler(pb)); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); diff --git a/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesStepInterpolatorTest.java b/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesStepInterpolatorTest.java index f9770be3a..bc20b2f9c 100644 --- a/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesStepInterpolatorTest.java +++ b/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesStepInterpolatorTest.java @@ -30,6 +30,7 @@ import junit.framework.TestSuite; import org.apache.commons.math.ode.ContinuousOutputModel; import org.apache.commons.math.ode.DerivativeException; import org.apache.commons.math.ode.IntegratorException; +import org.apache.commons.math.ode.sampling.StepHandler; public class ThreeEighthesStepInterpolatorTest extends StepInterpolatorAbstractTest { @@ -53,14 +54,16 @@ public class ThreeEighthesStepInterpolatorTest TestProblem3 pb = new TestProblem3(0.9); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003; ThreeEighthesIntegrator integ = new ThreeEighthesIntegrator(step); - integ.setStepHandler(new ContinuousOutputModel()); + integ.addStepHandler(new ContinuousOutputModel()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(integ.getStepHandler()); + for (StepHandler handler : integ.getStepHandlers()) { + oos.writeObject(handler); + } assertTrue(bos.size () > 700000); assertTrue(bos.size () < 701000); diff --git a/src/test/org/apache/commons/math/ode/sampling/StepNormalizerTest.java b/src/test/org/apache/commons/math/ode/sampling/StepNormalizerTest.java index eb9d4b18c..c7f9b16d8 100644 --- a/src/test/org/apache/commons/math/ode/sampling/StepNormalizerTest.java +++ b/src/test/org/apache/commons/math/ode/sampling/StepNormalizerTest.java @@ -40,7 +40,7 @@ public class StepNormalizerTest throws DerivativeException, IntegratorException { double range = pb.getFinalTime() - pb.getInitialTime(); setLastSeen(false); - integ.setStepHandler(new StepNormalizer(range / 10.0, + integ.addStepHandler(new StepNormalizer(range / 10.0, new FixedStepHandler() { private boolean firstCall = true; public void handleStep(double t, @@ -67,7 +67,7 @@ public class StepNormalizerTest throws DerivativeException, IntegratorException { final double range = pb.getFinalTime() - pb.getInitialTime(); setLastSeen(false); - integ.setStepHandler(new StepNormalizer(range / 10.5, + integ.addStepHandler(new StepNormalizer(range / 10.5, new FixedStepHandler() { public void handleStep(double t, double[] y,