Changed return type for eventOccurred from int to an enumerate in ODE.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1175379 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
39d86e32e2
commit
c60827b0b7
|
@ -49,38 +49,43 @@ package org.apache.commons.math.ode.events;
|
|||
|
||||
public interface EventHandler {
|
||||
|
||||
/** Stop indicator.
|
||||
* <p>This value should be used as the return value of the {@link
|
||||
* #eventOccurred eventOccurred} method when the integration should be
|
||||
* stopped after the event ending the current step.</p>
|
||||
*/
|
||||
int STOP = 0;
|
||||
/** Enumerate for actions to be performed when an event occurs. */
|
||||
public enum Action {
|
||||
|
||||
/** Reset state indicator.
|
||||
* <p>This value should be used as the return value of the {@link
|
||||
* #eventOccurred eventOccurred} method when the integration should
|
||||
* go on after the event ending the current step, with a new state
|
||||
* vector (which will be retrieved thanks to the {@link #resetState
|
||||
* resetState} method).</p>
|
||||
*/
|
||||
int RESET_STATE = 1;
|
||||
/** Stop indicator.
|
||||
* <p>This value should be used as the return value of the {@link
|
||||
* #eventOccurred eventOccurred} method when the integration should be
|
||||
* stopped after the event ending the current step.</p>
|
||||
*/
|
||||
STOP,
|
||||
|
||||
/** Reset derivatives indicator.
|
||||
* <p>This value should be used as the return value of the {@link
|
||||
* #eventOccurred eventOccurred} method when the integration should
|
||||
* go on after the event ending the current step, with a new derivatives
|
||||
* vector (which will be retrieved thanks to the {@link
|
||||
* org.apache.commons.math.ode.FirstOrderDifferentialEquations#computeDerivatives}
|
||||
* method).</p>
|
||||
*/
|
||||
int RESET_DERIVATIVES = 2;
|
||||
/** Reset state indicator.
|
||||
* <p>This value should be used as the return value of the {@link
|
||||
* #eventOccurred eventOccurred} method when the integration should
|
||||
* go on after the event ending the current step, with a new state
|
||||
* vector (which will be retrieved thanks to the {@link #resetState
|
||||
* resetState} method).</p>
|
||||
*/
|
||||
RESET_STATE,
|
||||
|
||||
/** Continue indicator.
|
||||
* <p>This value should be used as the return value of the {@link
|
||||
* #eventOccurred eventOccurred} method when the integration should go
|
||||
* on after the event ending the current step.</p>
|
||||
*/
|
||||
int CONTINUE = 3;
|
||||
/** Reset derivatives indicator.
|
||||
* <p>This value should be used as the return value of the {@link
|
||||
* #eventOccurred eventOccurred} method when the integration should
|
||||
* go on after the event ending the current step, with a new derivatives
|
||||
* vector (which will be retrieved thanks to the {@link
|
||||
* org.apache.commons.math.ode.FirstOrderDifferentialEquations#computeDerivatives}
|
||||
* method).</p>
|
||||
*/
|
||||
RESET_DERIVATIVES,
|
||||
|
||||
/** Continue indicator.
|
||||
* <p>This value should be used as the return value of the {@link
|
||||
* #eventOccurred eventOccurred} method when the integration should go
|
||||
* on after the event ending the current step.</p>
|
||||
*/
|
||||
CONTINUE;
|
||||
|
||||
}
|
||||
|
||||
/** Compute the value of the switching function.
|
||||
|
||||
|
@ -158,7 +163,7 @@ public interface EventHandler {
|
|||
* value must be one of {@link #STOP}, {@link #RESET_STATE},
|
||||
* {@link #RESET_DERIVATIVES} or {@link #CONTINUE}
|
||||
*/
|
||||
int eventOccurred(double t, double[] y, boolean increasing);
|
||||
Action eventOccurred(double t, double[] y, boolean increasing);
|
||||
|
||||
/** Reset the state prior to continue the integration.
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.commons.math.analysis.solvers.PegasusSolver;
|
|||
import org.apache.commons.math.analysis.solvers.UnivariateRealSolver;
|
||||
import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils;
|
||||
import org.apache.commons.math.exception.ConvergenceException;
|
||||
import org.apache.commons.math.ode.events.EventHandler;
|
||||
import org.apache.commons.math.ode.sampling.StepInterpolator;
|
||||
import org.apache.commons.math.util.FastMath;
|
||||
|
||||
|
@ -81,7 +82,7 @@ public class EventState {
|
|||
private boolean increasing;
|
||||
|
||||
/** Next action indicator. */
|
||||
private int nextAction;
|
||||
private EventHandler.Action nextAction;
|
||||
|
||||
/** Root-finding algorithm to use to detect state events. */
|
||||
private final UnivariateRealSolver solver;
|
||||
|
@ -113,7 +114,7 @@ public class EventState {
|
|||
pendingEventTime = Double.NaN;
|
||||
previousEventTime = Double.NaN;
|
||||
increasing = true;
|
||||
nextAction = EventHandler.CONTINUE;
|
||||
nextAction = EventHandler.Action.CONTINUE;
|
||||
|
||||
}
|
||||
|
||||
|
@ -304,7 +305,7 @@ public class EventState {
|
|||
nextAction = handler.eventOccurred(t, y, !(increasing ^ forward));
|
||||
} else {
|
||||
g0Positive = g0 >= 0;
|
||||
nextAction = EventHandler.CONTINUE;
|
||||
nextAction = EventHandler.Action.CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -313,7 +314,7 @@ public class EventState {
|
|||
* @return true if the integration should be stopped
|
||||
*/
|
||||
public boolean stop() {
|
||||
return nextAction == EventHandler.STOP;
|
||||
return nextAction == EventHandler.Action.STOP;
|
||||
}
|
||||
|
||||
/** Let the event handler reset the state if it wants.
|
||||
|
@ -329,14 +330,14 @@ public class EventState {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (nextAction == EventHandler.RESET_STATE) {
|
||||
if (nextAction == EventHandler.Action.RESET_STATE) {
|
||||
handler.resetState(t, y);
|
||||
}
|
||||
pendingEvent = false;
|
||||
pendingEventTime = Double.NaN;
|
||||
|
||||
return (nextAction == EventHandler.RESET_STATE) ||
|
||||
(nextAction == EventHandler.RESET_DERIVATIVES);
|
||||
return (nextAction == EventHandler.Action.RESET_STATE) ||
|
||||
(nextAction == EventHandler.Action.RESET_DERIVATIVES);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -119,10 +119,10 @@ public TestProblem4 copy() {
|
|||
return sign * y[0];
|
||||
}
|
||||
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
// this sign change is needed because the state will be reset soon
|
||||
sign = -sign;
|
||||
return EventHandler.RESET_STATE;
|
||||
return Action.RESET_STATE;
|
||||
}
|
||||
|
||||
public void resetState(double t, double[] y) {
|
||||
|
@ -141,8 +141,8 @@ public TestProblem4 copy() {
|
|||
return t - 12.0;
|
||||
}
|
||||
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return EventHandler.STOP;
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return Action.STOP;
|
||||
}
|
||||
|
||||
public void resetState(double t, double[] y) {
|
||||
|
|
|
@ -39,8 +39,8 @@ public class EventStateTest {
|
|||
public double g(double t, double[] y) {
|
||||
return (t - r1) * (r2 - t);
|
||||
}
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return CONTINUE;
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return Action.CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -142,8 +142,8 @@ public class OverlappingEventsTest implements FirstOrderDifferentialEquations {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return STOP;
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return Action.STOP;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -78,9 +78,9 @@ public class ClassicalRungeKuttaIntegratorTest {
|
|||
return t - tEvent;
|
||||
}
|
||||
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
Assert.assertEquals(tEvent, t, 5.0e-6);
|
||||
return CONTINUE;
|
||||
return Action.CONTINUE;
|
||||
}
|
||||
}, Double.POSITIVE_INFINITY, 1.0e-20, 100);
|
||||
finalT = integrator.integrate(ode, t0, y0, tEvent + 120, y);
|
||||
|
|
|
@ -80,9 +80,9 @@ public class DormandPrince853IntegratorTest {
|
|||
return t - tEvent;
|
||||
}
|
||||
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
Assert.assertEquals(tEvent, t, 5.0e-6);
|
||||
return CONTINUE;
|
||||
return Action.CONTINUE;
|
||||
}
|
||||
}, Double.POSITIVE_INFINITY, 1.0e-20, 100);
|
||||
finalT = integrator.integrate(ode, t0, y0, tEvent + 120, y);
|
||||
|
|
|
@ -202,8 +202,8 @@ public class HighamHall54IntegratorTest {
|
|||
integ.addStepHandler(handler);
|
||||
|
||||
integ.addEventHandler(new EventHandler() {
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return EventHandler.CONTINUE;
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return Action.CONTINUE;
|
||||
}
|
||||
public double g(double t, double[] y) {
|
||||
double middle = (pb.getInitialTime() + pb.getFinalTime()) / 2;
|
||||
|
@ -246,8 +246,8 @@ public class HighamHall54IntegratorTest {
|
|||
integ.addStepHandler(handler);
|
||||
|
||||
integ.addEventHandler(new EventHandler() {
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return EventHandler.CONTINUE;
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return Action.CONTINUE;
|
||||
}
|
||||
public double g(double t, double[] y) {
|
||||
double middle = (pb.getInitialTime() + pb.getFinalTime()) / 2;
|
||||
|
|
|
@ -43,9 +43,9 @@ public class StepProblem
|
|||
this.rate = rate;
|
||||
}
|
||||
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
public Action eventOccurred(double t, double[] y, boolean increasing) {
|
||||
setRate(rateAfter);
|
||||
return RESET_DERIVATIVES;
|
||||
return Action.RESET_DERIVATIVES;
|
||||
}
|
||||
|
||||
public double g(double t, double[] y) {
|
||||
|
|
Loading…
Reference in New Issue