From de621a41510ad1bda5db9a511c0582313fe3b9bd Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Thu, 24 Apr 2008 14:44:00 +0000 Subject: [PATCH] added the getSwitchingFunctions and clearSwitchingfunctions to the integrator interface JIRA: MATH-202 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@651282 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/ode/AdaptiveStepsizeIntegrator.java | 21 +++++++++++++++++++ .../math/ode/FirstOrderIntegrator.java | 17 +++++++++++++++ .../math/ode/RungeKuttaIntegrator.java | 21 +++++++++++++++++++ .../math/ode/SwitchingFunctionsHandler.java | 21 +++++++++++++++++++ src/site/xdoc/changes.xml | 4 ++++ .../ClassicalRungeKuttaIntegratorTest.java | 3 +++ .../ode/DormandPrince54IntegratorTest.java | 3 +++ .../ode/DormandPrince853IntegratorTest.java | 3 +++ .../ode/GraggBulirschStoerIntegratorTest.java | 3 +++ .../math/ode/HighamHall54IntegratorTest.java | 3 +++ 10 files changed, 99 insertions(+) diff --git a/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java b/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java index ad5415598..ee68a479a 100644 --- a/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java +++ b/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java @@ -17,6 +17,8 @@ package org.apache.commons.math.ode; +import java.util.Collection; + /** * This abstract class holds the common part of all adaptive * stepsize integrators for Ordinary Differential Equations. @@ -154,6 +156,8 @@ public abstract class AdaptiveStepsizeIntegrator * @param convergence convergence threshold in the event time search * @param maxIterationCount upper limit of the iteration count in * the event time search + * @see #getSwitchingFunctions() + * @see #clearSwitchingFunctions() */ public void addSwitchingFunction(SwitchingFunction function, double maxCheckInterval, @@ -162,6 +166,23 @@ public abstract class AdaptiveStepsizeIntegrator switchesHandler.add(function, maxCheckInterval, convergence, maxIterationCount); } + /** Get all the switching functions that have been added to the integrator. + * @return an unmodifiable collection of the added switching functions + * @see #add(SwitchingFunction, double, double, int) + * @see #clearSwitchingFunctions() + */ + public Collection getSwitchingFunctions() { + return switchesHandler.getSwitchingFunctions(); + } + + /** Remove all the switching functions that have been added to the integrator. + * @see #add(SwitchingFunction, double, double, int) + * @see #getSwitchingFunctions() + */ + public void clearSwitchingFunctions() { + switchesHandler.clearSwitchingFunctions(); + } + /** Perform some sanity checks on the integration parameters. * @param equations differential equations set * @param t0 start time diff --git a/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java b/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java index b931d2288..13473ca1d 100644 --- a/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java +++ b/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java @@ -17,6 +17,8 @@ package org.apache.commons.math.ode; +import java.util.Collection; + /** This interface represents a first order integrator for * differential equations. @@ -59,12 +61,27 @@ public interface FirstOrderIntegrator { * @param convergence convergence threshold in the event time search * @param maxIterationCount upper limit of the iteration count in * the event time search + * @see #getSwitchingFunctions() + * @see #clearSwitchingFunctions() */ public void addSwitchingFunction(SwitchingFunction function, double maxCheckInterval, double convergence, int maxIterationCount); + /** Get all the switching functions that have been added to the integrator. + * @return an unmodifiable collection of the added switching functions + * @see #add(SwitchingFunction, double, double, int) + * @see #clearSwitchingFunctions() + */ + public Collection getSwitchingFunctions(); + + /** Remove all the switching functions that have been added to the integrator. + * @see #add(SwitchingFunction, double, double, int) + * @see #getSwitchingFunctions() + */ + public void clearSwitchingFunctions(); + /** Integrate the differential equations up to the given time. *

This method solves an Initial Value Problem (IVP).

*

Since this method stores some internal state variables made diff --git a/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java b/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java index ebd21404b..a81d10933 100644 --- a/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java +++ b/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java @@ -17,6 +17,8 @@ package org.apache.commons.math.ode; +import java.util.Collection; + /** * This class implements the common part of all fixed step Runge-Kutta * integrators for Ordinary Differential Equations. @@ -96,6 +98,8 @@ public abstract class RungeKuttaIntegrator * @param convergence convergence threshold in the event time search * @param maxIterationCount upper limit of the iteration count in * the event time search + * @see #getSwitchingFunctions() + * @see #clearSwitchingFunctions() */ public void addSwitchingFunction(SwitchingFunction function, double maxCheckInterval, @@ -104,6 +108,23 @@ public abstract class RungeKuttaIntegrator switchesHandler.add(function, maxCheckInterval, convergence, maxIterationCount); } + /** Get all the switching functions that have been added to the integrator. + * @return an unmodifiable collection of the added switching functions + * @see #add(SwitchingFunction, double, double, int) + * @see #clearSwitchingFunctions() + */ + public Collection getSwitchingFunctions() { + return switchesHandler.getSwitchingFunctions(); + } + + /** Remove all the switching functions that have been added to the integrator. + * @see #add(SwitchingFunction, double, double, int) + * @see #getSwitchingFunctions() + */ + public void clearSwitchingFunctions() { + switchesHandler.clearSwitchingFunctions(); + } + /** Perform some sanity checks on the integration parameters. * @param equations differential equations set * @param t0 start time diff --git a/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java b/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java index 3f2509a3f..9a89788b1 100644 --- a/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java +++ b/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java @@ -21,6 +21,8 @@ import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.FunctionEvaluationException; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -51,6 +53,8 @@ public class SwitchingFunctionsHandler { * @param convergence convergence threshold in the event time search * @param maxIterationCount upper limit of the iteration count in * the event time search + * @see #getSwitchingFunctions() + * @see #clearSwitchingFunctions() */ public void add(SwitchingFunction function, double maxCheckInterval, double convergence, int maxIterationCount) { @@ -58,6 +62,23 @@ public class SwitchingFunctionsHandler { convergence, maxIterationCount)); } + /** Get all the switching functions that have been added to the handler. + * @return an unmodifiable collection of the added switching functions + * @see #add(SwitchingFunction, double, double, int) + * @see #clearSwitchingFunctions() + */ + public Collection getSwitchingFunctions() { + return Collections.unmodifiableCollection(functions); + } + + /** Remove all the switching functions that have been added to the handler. + * @see #add(SwitchingFunction, double, double, int) + * @see #getSwitchingFunctions() + */ + public void clearSwitchingFunctions() { + functions.clear(); + } + /** Check if the handler does not have any condition. * @return true if handler is empty */ diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 6a7ea8103..6b6af8674 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -40,6 +40,10 @@ Commons Math Release Notes + + Added the getSwitchingFunctions and clearSwitchingFunctions to the + FirstOrderIntegrator interface and all its implementations + Removed deprecated features. This includes the following changes. Factory-based instantiation replaced by setter injection in 1.2 in several classes have been diff --git a/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java b/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java index 27e7e57de..8aa1c41a5 100644 --- a/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java @@ -88,6 +88,7 @@ public class ClassicalRungeKuttaIntegratorTest integ.addSwitchingFunction(functions[l], Double.POSITIVE_INFINITY, 1.0e-6 * step, 1000); } + assertEquals(functions.length, integ.getSwitchingFunctions().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -97,6 +98,8 @@ public class ClassicalRungeKuttaIntegratorTest } previousError = error; assertEquals(0, handler.getMaximalTimeError(), 1.0e-12); + integ.clearSwitchingFunctions(); + assertEquals(0, integ.getSwitchingFunctions().size()); } } diff --git a/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java b/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java index bb09a967e..82dc4cacb 100644 --- a/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java @@ -191,6 +191,7 @@ public class DormandPrince54IntegratorTest integ.addSwitchingFunction(functions[l], Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); } + assertEquals(functions.length, integ.getSwitchingFunctions().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -198,6 +199,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.clearSwitchingFunctions(); + assertEquals(0, integ.getSwitchingFunctions().size()); } diff --git a/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java b/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java index b5aaa297a..89c89947d 100644 --- a/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java @@ -144,6 +144,7 @@ public class DormandPrince853IntegratorTest integ.addSwitchingFunction(functions[l], Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); } + assertEquals(functions.length, integ.getSwitchingFunctions().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -151,6 +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.clearSwitchingFunctions(); + assertEquals(0, integ.getSwitchingFunctions().size()); } diff --git a/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java b/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java index 7d6a089ba..384e48006 100644 --- a/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java @@ -184,6 +184,7 @@ public class GraggBulirschStoerIntegratorTest integ.addSwitchingFunction(functions[l], Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); } + assertEquals(functions.length, integ.getSwitchingFunctions().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -191,6 +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.clearSwitchingFunctions(); + assertEquals(0, integ.getSwitchingFunctions().size()); } diff --git a/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java b/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java index d36310033..e48eeda20 100644 --- a/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java +++ b/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java @@ -153,6 +153,7 @@ public class HighamHall54IntegratorTest integ.addSwitchingFunction(functions[l], Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000); } + assertEquals(functions.length, integ.getSwitchingFunctions().size()); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); @@ -160,6 +161,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.clearSwitchingFunctions(); + assertEquals(0, integ.getSwitchingFunctions().size()); }