commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r781157 - /commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventState.java
Date Tue, 02 Jun 2009 20:42:15 GMT
Author: luc
Date: Tue Jun  2 20:42:15 2009
New Revision: 781157

URL: http://svn.apache.org/viewvc?rev=781157&view=rev
Log:
fixed corner cases when events occur right at integration start
(which in fact always happen when a resetting event forces a restart just after the event
has occurred)

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/events/EventState.java

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=781157&r1=781156&r2=781157&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
Tue Jun  2 20:42:15 2009
@@ -211,13 +211,21 @@
                     final BrentSolver solver = new BrentSolver();
                     solver.setAbsoluteAccuracy(convergence);
                     solver.setMaximalIterationCount(maxIterationCount);
-                    final double root = (ta <= tb) ? solver.solve(f, ta, tb) : solver.solve(f,
tb, ta);
-                    if (Math.abs(root - ta) <= convergence) {
-                        // we have found (again ?) a past event, we simply ignore it
+                    double root;
+                    try {
+                        root = (ta <= tb) ? solver.solve(f, ta, tb) : solver.solve(f,
tb, ta);
+                    } catch (IllegalArgumentException iae) {
+                        // the interval did not really bracket a root
+                        root = Double.NaN;
+                    }
+                    if (Double.isNaN(root) ||
+                        ((Math.abs(root - ta) <= convergence) &&
+                         (Math.abs(root - previousEventTime) <= convergence))) {
+                        // we have either found nothing or found (again ?) a past event,
we simply ignore it
                         ta = tb;
                         ga = gb;
                     } else if (Double.isNaN(previousEventTime) ||
-                        (Math.abs(previousEventTime - root) > convergence)) {
+                               (Math.abs(previousEventTime - root) > convergence)) {
                         pendingEventTime = root;
                         if (pendingEvent && (Math.abs(t1 - pendingEventTime) <=
convergence)) {
                             // we were already waiting for this event which was



Mime
View raw message