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
This commit is contained in:
Luc Maisonobe 2008-04-24 14:44:00 +00:00
parent 9b8972d209
commit de621a4151
10 changed files with 99 additions and 0 deletions

View File

@ -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

View File

@ -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.
* <p>This method solves an Initial Value Problem (IVP).</p>
* <p>Since this method stores some internal state variables made

View File

@ -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

View File

@ -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
*/

View File

@ -40,6 +40,10 @@ Commons Math Release Notes</title>
</properties>
<body>
<release version="2.0" date="TBD" description="TBD">
<action dev="luc" type="add" issue="MATH-202">
Added the getSwitchingFunctions and clearSwitchingFunctions to the
FirstOrderIntegrator interface and all its implementations
</action>
<action dev="luc" type="update" >
Removed deprecated features. This includes the following changes. Factory-based
instantiation replaced by setter injection in 1.2 in several classes have been

View File

@ -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());
}
}

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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());
}