Author: luc
Date: Mon Apr 27 16:04:03 2009
New Revision: 769039
URL: http://svn.apache.org/viewvc?rev=769039&view=rev
Log:
event handlers in ODE now also provide the switching function variation
(increasing/decreasing) when an event occurs
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractIntegrator.java
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventHandler.java
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventState.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/StepProblem.java
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/TestProblem4.java
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractIntegrator.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractIntegrator.java?rev=769039&r1=769038&r2=769039&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractIntegrator.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractIntegrator.java
Mon Apr 27 16:04:03 2009
@@ -189,9 +189,9 @@
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 @@
}
/** {...@inheritdoc} */
- public int eventOccurred(double t, double[] y) {
+ public int eventOccurred(double t, double[] y, boolean increasing) {
return STOP;
}
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java?rev=769039&r1=769038&r2=769039&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java
Mon Apr 27 16:04:03 2009
@@ -198,7 +198,7 @@
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 @@
}
/** {...@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
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventHandler.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventHandler.java?rev=769039&r1=769038&r2=769039&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventHandler.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventHandler.java
Mon Apr 27 16:04:03 2009
@@ -132,12 +132,15 @@
* @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.
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventState.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventState.java?rev=769039&r1=769038&r2=769039&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventState.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventState.java
Mon Apr 27 16:04:03 2009
@@ -75,6 +75,9 @@
/** 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 @@
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 @@
// 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;
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=769039&r1=769038&r2=769039&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Apr 27 16:04:03 2009
@@ -285,6 +285,10 @@
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)
Modified:
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java?rev=769039&r1=769038&r2=769039&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java
(original)
+++
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/HighamHall54IntegratorTest.java
Mon Apr 27 16:04:03 2009
@@ -207,7 +207,7 @@
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 @@
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) {
Modified:
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/StepProblem.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/StepProblem.java?rev=769039&r1=769038&r2=769039&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/StepProblem.java
(original)
+++
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/StepProblem.java
Mon Apr 27 16:04:03 2009
@@ -43,7 +43,7 @@
this.rate = rate;
}
- public int eventOccurred(double t, double[] y) {
+ public int eventOccurred(double t, double[] y, boolean increasing) {
setRate(rateAfter);
return RESET_DERIVATIVES;
}
Modified:
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/TestProblem4.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/TestProblem4.java?rev=769039&r1=769038&r2=769039&view=diff
==============================================================================
---
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/TestProblem4.java
(original)
+++
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/TestProblem4.java
Mon Apr 27 16:04:03 2009
@@ -110,7 +110,7 @@
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 @@
return t - 12.0;
}
- public int eventOccurred(double t, double[] y) {
+ public int eventOccurred(double t, double[] y, boolean increasing) {
return EventHandler.STOP;
}