commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1215524 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/ode/nonstiff/ site/xdoc/ test/java/org/apache/commons/math/ode/nonstiff/
Date Sat, 17 Dec 2011 16:55:26 GMT
Author: luc
Date: Sat Dec 17 16:55:25 2011
New Revision: 1215524

URL: http://svn.apache.org/viewvc?rev=1215524&view=rev
Log:
Check first step size in embedded Runge-Kutta integrators.

JIRA: MATH-727

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java?rev=1215524&r1=1215523&r2=1215524&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
Sat Dec 17 16:55:25 2011
@@ -247,6 +247,15 @@ public abstract class EmbeddedRungeKutta
         }
 
         stepSize = hNew;
+        if (forward) {
+            if (stepStart + stepSize >= t) {
+                stepSize = t - stepStart;
+            }
+        } else {
+            if (stepStart + stepSize <= t) {
+                stepSize = t - stepStart;
+            }
+        }
 
         // next stages
         for (int k = 1; k < stages; ++k) {

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=1215524&r1=1215523&r2=1215524&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sat Dec 17 16:55:25 2011
@@ -52,6 +52,9 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="luc" type="fix" issue="MATH-727">
+        Check first step size in embedded Runge-Kutta integrators, and truncate it if needed.
+      </action>
       <action dev="psteitz" type="fix" issue="MATH-723">
         Modified setSeed methods in Bitstream generators (MersenneTwister and Well
         generators) to clear the cache of normal deviates used by nextGaussian.

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java?rev=1215524&r1=1215523&r2=1215524&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
Sat Dec 17 16:55:25 2011
@@ -177,6 +177,32 @@ public class DormandPrince853IntegratorT
   }
 
   @Test
+  public void testTooLargeFirstStep() {
+
+      AdaptiveStepsizeIntegrator integ =
+              new DormandPrince853Integrator(0, Double.POSITIVE_INFINITY, Double.NaN, Double.NaN);
+      final double start = 0.0;
+      final double end   = 0.001;
+      FirstOrderDifferentialEquations equations = new FirstOrderDifferentialEquations() {
+
+          public int getDimension() {
+              return 1;
+          }
+
+          public void computeDerivatives(double t, double[] y, double[] yDot) {
+              Assert.assertTrue(t >= FastMath.nextAfter(start, Double.NEGATIVE_INFINITY));
+              Assert.assertTrue(t <= FastMath.nextAfter(end,   Double.POSITIVE_INFINITY));
+              yDot[0] = -100.0 * y[0];
+          }
+
+      };
+
+      integ.setStepSizeControl(0, 1.0, 1.0e-6, 1.0e-8);
+      integ.integrate(equations, start, new double[] { 1.0 }, end, new double[1]);
+
+  }
+
+  @Test
   public void testBackward()
       {
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java?rev=1215524&r1=1215523&r2=1215524&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java
Sat Dec 17 16:55:25 2011
@@ -256,6 +256,32 @@ public class GraggBulirschStoerIntegrato
   }
 
   @Test
+  public void testTooLargeFirstStep() {
+
+      AdaptiveStepsizeIntegrator integ =
+              new GraggBulirschStoerIntegrator(0, Double.POSITIVE_INFINITY, Double.NaN, Double.NaN);
+      final double start = 0.0;
+      final double end   = 0.001;
+      FirstOrderDifferentialEquations equations = new FirstOrderDifferentialEquations() {
+
+          public int getDimension() {
+              return 1;
+          }
+
+          public void computeDerivatives(double t, double[] y, double[] yDot) {
+              Assert.assertTrue(t >= FastMath.nextAfter(start, Double.NEGATIVE_INFINITY));
+              Assert.assertTrue(t <= FastMath.nextAfter(end,   Double.POSITIVE_INFINITY));
+              yDot[0] = -100.0 * y[0];
+          }
+
+      };
+
+      integ.setStepSizeControl(0, 1.0, 1.0e-6, 1.0e-8);
+      integ.integrate(equations, start, new double[] { 1.0 }, end, new double[1]);
+
+  }
+
+  @Test
   public void testUnstableDerivative() {
     final StepProblem stepProblem = new StepProblem(0.0, 1.0, 2.0);
     FirstOrderIntegrator integ =



Mime
View raw message