event handlers in ODE now also provide the switching function variation
(increasing/decreasing) when an event occurs git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@769039 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7d55da9f31
commit
6adb238e5a
|
@ -189,9 +189,9 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
|
|||
private static class EndTimeChecker implements EventHandler {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = -5211782540446301964L;
|
||||
private static final long serialVersionUID = -7029115498939113263L;
|
||||
|
||||
/** DEsiredt end time. */
|
||||
/** Desired end time. */
|
||||
private final double endTime;
|
||||
|
||||
/** Build an instance.
|
||||
|
@ -202,7 +202,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int eventOccurred(double t, double[] y) {
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return STOP;
|
||||
}
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ public abstract class MultistepIntegrator extends AbstractIntegrator {
|
|||
private class ResetCheckingWrapper implements EventHandler {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 4922660285376467937L;
|
||||
private static final long serialVersionUID = -3138614051962269485L;
|
||||
|
||||
/** Wrapped event handler. */
|
||||
private final EventHandler handler;
|
||||
|
@ -211,8 +211,9 @@ public abstract class MultistepIntegrator extends AbstractIntegrator {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int eventOccurred(double t, double[] y) throws EventException {
|
||||
final int action = handler.eventOccurred(t, y);
|
||||
public int eventOccurred(double t, double[] y, boolean increasing)
|
||||
throws EventException {
|
||||
final int action = handler.eventOccurred(t, y, increasing);
|
||||
if ((action == RESET_DERIVATIVES) || (action == RESET_STATE)) {
|
||||
// a singularity has been encountered
|
||||
// we need to restart the start phase
|
||||
|
|
|
@ -132,12 +132,15 @@ public interface EventHandler extends Serializable {
|
|||
|
||||
* @param t current value of the independent <i>time</i> variable
|
||||
* @param y array containing the current value of the state vector
|
||||
* @param increasing if true, the value of the switching function increases
|
||||
* when times increases around event (note that increase is measured with respect
|
||||
* to physical time, not with respect to propagation which may go backward in time)
|
||||
* @return indication of what the integrator should do next, this
|
||||
* value must be one of {@link #STOP}, {@link #RESET_STATE},
|
||||
* {@link #RESET_DERIVATIVES} or {@link #CONTINUE}
|
||||
* @exception EventException if the event occurrence triggers an error
|
||||
*/
|
||||
public int eventOccurred(double t, double[] y) throws EventException;
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) throws EventException;
|
||||
|
||||
/** Reset the state prior to continue the integration.
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@ public class EventState implements Serializable {
|
|||
/** Occurrence time of the previous event. */
|
||||
private double previousEventTime;
|
||||
|
||||
/** Integration direction. */
|
||||
private boolean forward;
|
||||
|
||||
/** Variation direction around pending event.
|
||||
* (this is considered with respect to the integration direction)
|
||||
*/
|
||||
|
@ -170,6 +173,7 @@ public class EventState implements Serializable {
|
|||
|
||||
try {
|
||||
|
||||
forward = interpolator.isForward();
|
||||
final double t1 = interpolator.getCurrentTime();
|
||||
final int n = Math.max(1, (int) Math.ceil(Math.abs(t1 - t0) / maxCheckInterval));
|
||||
final double h = (t1 - t0) / n;
|
||||
|
@ -280,7 +284,7 @@ public class EventState implements Serializable {
|
|||
// force the sign to its value "just after the event"
|
||||
previousEventTime = t;
|
||||
g0Positive = increasing;
|
||||
nextAction = handler.eventOccurred(t, y);
|
||||
nextAction = handler.eventOccurred(t, y, !(increasing ^ forward));
|
||||
} else {
|
||||
g0Positive = (g0 >= 0);
|
||||
nextAction = EventHandler.CONTINUE;
|
||||
|
|
|
@ -285,6 +285,10 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
difficult to get the corresponding time (it involved setting a step
|
||||
handler monitoring the last step specially).
|
||||
</action>
|
||||
<action dev="luc" type="update" >
|
||||
Events handlers in the ODE package now also provide the switching function
|
||||
variation (increasing/decreasing) when an event occurs
|
||||
</action>
|
||||
<action dev="luc" type="update">
|
||||
Clarified the ODE package by breaking in into several sub-packages and renaming
|
||||
classes (SwitchingFunctions/EventHandler, SwitchingFunctionsHandler/CombinedEventsManager)
|
||||
|
|
|
@ -207,7 +207,7 @@ public class HighamHall54IntegratorTest
|
|||
integ.addStepHandler(handler);
|
||||
|
||||
integ.addEventHandler(new EventHandler() {
|
||||
public int eventOccurred(double t, double[] y) {
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return EventHandler.CONTINUE;
|
||||
}
|
||||
public double g(double t, double[] y) throws EventException {
|
||||
|
@ -251,7 +251,7 @@ public class HighamHall54IntegratorTest
|
|||
integ.addStepHandler(handler);
|
||||
|
||||
integ.addEventHandler(new EventHandler() {
|
||||
public int eventOccurred(double t, double[] y) {
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return EventHandler.CONTINUE;
|
||||
}
|
||||
public double g(double t, double[] y) {
|
||||
|
|
|
@ -43,7 +43,7 @@ public class StepProblem
|
|||
this.rate = rate;
|
||||
}
|
||||
|
||||
public int eventOccurred(double t, double[] y) {
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
setRate(rateAfter);
|
||||
return RESET_DERIVATIVES;
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class TestProblem4
|
|||
return sign * y[0];
|
||||
}
|
||||
|
||||
public int eventOccurred(double t, double[] y) {
|
||||
public int 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;
|
||||
|
@ -134,7 +134,7 @@ public class TestProblem4
|
|||
return t - 12.0;
|
||||
}
|
||||
|
||||
public int eventOccurred(double t, double[] y) {
|
||||
public int eventOccurred(double t, double[] y, boolean increasing) {
|
||||
return EventHandler.STOP;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue