You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/06/10 23:44:33 UTC

svn commit: r783529 - in /commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff: AdamsMoultonIntegrator.java EmbeddedRungeKuttaIntegrator.java GraggBulirschStoerIntegrator.java RungeKuttaIntegrator.java

Author: luc
Date: Wed Jun 10 21:44:33 2009
New Revision: 783529

URL: http://svn.apache.org/viewvc?rev=783529&view=rev
Log:
prevent too small (sometimes exactly 0) steps to occur
when an event is within convergence tolerance to the step end

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java?rev=783529&r1=783528&r2=783529&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java Wed Jun 10 21:44:33 2009
@@ -309,8 +309,14 @@
                 interpolatorTmp.shift();
                 interpolatorTmp.storeTime(stepEnd);
                 if (manager.evaluateStep(interpolatorTmp)) {
-                    // reject the step to match exactly the next switch time
-                    hNew = manager.getEventTime() - stepStart;
+                    final double dt = manager.getEventTime() - stepStart;
+                    if (Math.abs(dt) <= Math.ulp(stepStart)) {
+                        // rejecting the step would lead to a too small next step, we accept it
+                        loop = false;
+                    } else {
+                        // reject the step to match exactly the next switch time
+                        hNew = dt;
+                    }
                 } else {
                     // accept the step
                     scaled    = correctedScaled;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java?rev=783529&r1=783528&r2=783529&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java Wed Jun 10 21:44:33 2009
@@ -268,8 +268,14 @@
           // discrete events handling
           interpolator.storeTime(stepStart + stepSize);
           if (manager.evaluateStep(interpolator)) {
-            // reject the step to match exactly the next switch time
-            hNew = manager.getEventTime() - stepStart;
+              final double dt = manager.getEventTime() - stepStart;
+              if (Math.abs(dt) <= Math.ulp(stepStart)) {
+                  // rejecting the step would lead to a too small next step, we accept it
+                  loop = false;
+              } else {
+                  // reject the step to match exactly the next switch time
+                  hNew = dt;
+              }
           } else {
             // accept the step
             loop = false;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java?rev=783529&r1=783528&r2=783529&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java Wed Jun 10 21:44:33 2009
@@ -831,8 +831,12 @@
           if (!reject) {
             interpolator.storeTime(stepStart + stepSize);
             if (eventsHandlersManager.evaluateStep(interpolator)) {
-              reject = true;
-              hNew = Math.abs(eventsHandlersManager.getEventTime() - stepStart);
+                final double dt = eventsHandlersManager.getEventTime() - stepStart;
+                if (Math.abs(dt) > Math.ulp(stepStart)) {
+                    // reject the step to match exactly the next switch time
+                    hNew = Math.abs(dt);
+                    reject = true;
+                }
             }
           }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java?rev=783529&r1=783528&r2=783529&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java Wed Jun 10 21:44:33 2009
@@ -158,7 +158,14 @@
         // discrete events handling
         interpolator.storeTime(stepStart + stepSize);
         if (manager.evaluateStep(interpolator)) {
-          stepSize = manager.getEventTime() - stepStart;
+            final double dt = manager.getEventTime() - stepStart;
+            if (Math.abs(dt) <= Math.ulp(stepStart)) {
+                // rejecting the step would lead to a too small next step, we accept it
+                loop = false;
+            } else {
+                // reject the step to match exactly the next switch time
+                stepSize = dt;
+            }
         } else {
           loop = false;
         }