commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r671168 - in /commons/proper/math/branches/MATH_2_0/src: java/org/apache/commons/math/ode/ java/org/apache/commons/math/ode/nonstiff/ site/xdoc/ test/org/apache/commons/math/ode/nonstiff/
Date Tue, 24 Jun 2008 13:38:29 GMT
Author: luc
Date: Tue Jun 24 06:38:28 2008
New Revision: 671168

URL: http://svn.apache.org/viewvc?rev=671168&view=rev
Log:
Changed return type for FirstOrderIntegrator.integrate() to double
in order to retrieve exact stop time. This allows to handle properly
integration interruption due to an EventHandler instance asking to
stop the integration when its associated event is triggered. The state
was already set to the current state at interruption time, but it was
difficult to get the corresponding time (it involved setting a step
handler monitoring the last step specially).

JIRA: MATH-213

Modified:
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
    commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java
Tue Jun 24 06:38:28 2008
@@ -330,9 +330,9 @@
   }
 
   /** {@inheritDoc} */
-  public abstract void integrate (FirstOrderDifferentialEquations equations,
-                                  double t0, double[] y0,
-                                  double t, double[] y)
+  public abstract double integrate (FirstOrderDifferentialEquations equations,
+                                    double t0, double[] y0,
+                                    double t, double[] y)
     throws DerivativeException, IntegratorException;
 
   /** {@inheritDoc} */

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java
Tue Jun 24 06:38:28 2008
@@ -96,13 +96,15 @@
    * (can be set to a value smaller than <code>t0</code> for backward integration)
    * @param y placeholder where to put the state vector at each successful
    *  step (and hence at the end of integration), can be the same object as y0
+   * @return stop time, will be the same as target time if integration reached its
+   * target, but may be different if some {@link EventHandler} stops it at some point.
    * @throws IntegratorException if the integrator cannot perform integration
    * @throws DerivativeException this exception is propagated to the caller if
    * the underlying user function triggers one
    */
-  public void integrate (FirstOrderDifferentialEquations equations,
-                         double t0, double[] y0,
-                         double t, double[] y)
+  public double integrate (FirstOrderDifferentialEquations equations,
+                           double t0, double[] y0,
+                           double t, double[] y)
     throws DerivativeException, IntegratorException;
 
   /** Get the current value of the step start time t<sub>i</sub>.

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
Tue Jun 24 06:38:28 2008
@@ -161,9 +161,9 @@
   }
 
   /** {@inheritDoc} */
-  public void integrate(final FirstOrderDifferentialEquations equations,
-                        final double t0, final double[] y0,
-                        final double t, final double[] y)
+  public double integrate(final FirstOrderDifferentialEquations equations,
+                          final double t0, final double[] y0,
+                          final double t, final double[] y)
   throws DerivativeException, IntegratorException {
 
     sanityChecks(equations, t0, y0, t, y);
@@ -318,7 +318,9 @@
 
     } while (! lastStep);
 
+    final double stopTime = stepStart;
     resetInternalState();
+    return stopTime;
 
   }
 

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
Tue Jun 24 06:38:28 2008
@@ -508,8 +508,8 @@
   }
 
   /** {@inheritDoc} */
-  public void integrate(final FirstOrderDifferentialEquations equations,
-                        final double t0, final double[] y0, final double t, final double[]
y)
+  public double integrate(final FirstOrderDifferentialEquations equations,
+                          final double t0, final double[] y0, final double t, final double[]
y)
   throws DerivativeException, IntegratorException {
 
     sanityChecks(equations, t0, y0, t, y);
@@ -941,6 +941,8 @@
 
     }
 
+    return stepStart;
+
   }
 
   /** maximal order. */

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
Tue Jun 24 06:38:28 2008
@@ -145,9 +145,9 @@
   }
 
   /** {@inheritDoc} */
-  public void integrate(final FirstOrderDifferentialEquations equations,
-                        final double t0, final double[] y0,
-                        final double t, final double[] y)
+  public double integrate(final FirstOrderDifferentialEquations equations,
+                          final double t0, final double[] y0,
+                          final double t, final double[] y)
   throws DerivativeException, IntegratorException {
 
     sanityChecks(equations, t0, y0, t, y);
@@ -257,7 +257,9 @@
 
     }
 
+    final double stopTime = stepStart;
     resetInternalState();
+    return stopTime;
 
   }
 

Modified: commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml Tue Jun 24 06:38:28 2008
@@ -39,6 +39,15 @@
   </properties>
   <body>
     <release version="2.0" date="TBD" description="TBD">
+      <action dev="luc" type="fix" issue="MATH-213" >
+        Changed return type for FirstOrderIntegrator.integrate() to double
+        in order to retrieve exact stop time. This allows to handle properly
+        integration interruption due to an EventHandler instance asking to
+        stop the integration when its associated event is triggered. The state
+        was already set to the current state at interruption time, but it was
+        difficult to get the corresponding time (it involved setting a step
+        handler monitoring the last step specially).
+      </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/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ClassicalRungeKuttaIntegratorTest.java
Tue Jun 24 06:38:28 2008
@@ -77,8 +77,7 @@
       for (int i = 4; i < 10; ++i) {
 
         TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
-        double step = (pb.getFinalTime() - pb.getInitialTime())
-          * Math.pow(2.0, -i);
+        double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i);
 
         FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
         TestProblemHandler handler = new TestProblemHandler(pb, integ);
@@ -89,8 +88,11 @@
                                      Double.POSITIVE_INFINITY, 1.0e-6 * step, 1000);
         }
         assertEquals(functions.length, integ.getEventsHandlers().size());
-        integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
-                        pb.getFinalTime(), new double[pb.getDimension()]);
+        double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                                          pb.getFinalTime(), new double[pb.getDimension()]);
+        if (functions.length == 0) {
+            assertEquals(pb.getFinalTime(), stopTime, 1.0e-10);
+        }
 
         double error = handler.getMaximalValueError();
         if (i > 4) {

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince54IntegratorTest.java
Tue Jun 24 06:38:28 2008
@@ -241,9 +241,9 @@
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
     integ.setStepHandler(new VariableHandler());
-    integ.integrate(pb,
-                    pb.getInitialTime(), pb.getInitialState(),
-                    pb.getFinalTime(), new double[pb.getDimension()]);
+    double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                                      pb.getFinalTime(), new double[pb.getDimension()]);
+    assertEquals(pb.getFinalTime(), stopTime, 1.0e-10);
   }
 
   private static class KeplerHandler implements StepHandler {

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
Tue Jun 24 06:38:28 2008
@@ -191,9 +191,10 @@
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
     integ.setStepHandler(new VariableHandler());
-    integ.integrate(pb,
-                    pb.getInitialTime(), pb.getInitialState(),
-                    pb.getFinalTime(), new double[pb.getDimension()]);
+    double stopTime = integ.integrate(pb,
+                                      pb.getInitialTime(), pb.getInitialState(),
+                                      pb.getFinalTime(), new double[pb.getDimension()]);
+    assertEquals(pb.getFinalTime(), stopTime, 1.0e-10);
     assertEquals("Dormand-Prince 8 (5, 3)", integ.getName());
   }
 

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/EulerIntegratorTest.java
Tue Jun 24 06:38:28 2008
@@ -66,9 +66,11 @@
           integ.addEventHandler(functions[l],
                                      Double.POSITIVE_INFINITY, 1.0e-6 * step, 1000);
         }
-        integ.integrate(pb,
-                        pb.getInitialTime(), pb.getInitialState(),
-                        pb.getFinalTime(), new double[pb.getDimension()]);
+        double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                                          pb.getFinalTime(), new double[pb.getDimension()]);
+        if (functions.length == 0) {
+            assertEquals(pb.getFinalTime(), stopTime, 1.0e-10);
+        }
 
         double error = handler.getMaximalValueError();
         if (i > 4) {

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GillIntegratorTest.java
Tue Jun 24 06:38:28 2008
@@ -68,8 +68,11 @@
           integ.addEventHandler(functions[l],
                                      Double.POSITIVE_INFINITY, 1.0e-6 * step, 1000);
         }
-        integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
-                        pb.getFinalTime(), new double[pb.getDimension()]);
+        double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                                          pb.getFinalTime(), new double[pb.getDimension()]);
+        if (functions.length == 0) {
+            assertEquals(pb.getFinalTime(), stopTime, 1.0e-10);
+        }
 
         double error = handler.getMaximalValueError();
         if (i > 5) {

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegratorTest.java
Tue Jun 24 06:38:28 2008
@@ -231,9 +231,10 @@
       new GraggBulirschStoerIntegrator(minStep, maxStep,
                                        absTolerance, relTolerance);
     integ.setStepHandler(new VariableStepHandler());
-    integ.integrate(pb,
-                    pb.getInitialTime(), pb.getInitialState(),
-                    pb.getFinalTime(), new double[pb.getDimension()]);
+    double stopTime = integ.integrate(pb,
+                                      pb.getInitialTime(), pb.getInitialState(),
+                                      pb.getFinalTime(), new double[pb.getDimension()]);
+    assertEquals(pb.getFinalTime(), stopTime, 1.0e-10);
     assertEquals("Gragg-Bulirsch-Stoer", integ.getName());
   }
 

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/MidpointIntegratorTest.java
Tue Jun 24 06:38:28 2008
@@ -65,9 +65,12 @@
           integ.addEventHandler(functions[l],
                                      Double.POSITIVE_INFINITY, 1.0e-6 * step, 1000);
         }
-        integ.integrate(pb,
-                        pb.getInitialTime(), pb.getInitialState(),
-                        pb.getFinalTime(), new double[pb.getDimension()]);
+        double stopTime = integ.integrate(pb,
+                                          pb.getInitialTime(), pb.getInitialState(),
+                                          pb.getFinalTime(), new double[pb.getDimension()]);
+        if (functions.length == 0) {
+            assertEquals(pb.getFinalTime(), stopTime, 1.0e-10);
+        }
 
         double error = handler.getMaximalValueError();
         if (i > 4) {

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java?rev=671168&r1=671167&r2=671168&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/ode/nonstiff/ThreeEighthesIntegratorTest.java
Tue Jun 24 06:38:28 2008
@@ -68,8 +68,11 @@
           integ.addEventHandler(functions[l],
                                      Double.POSITIVE_INFINITY, 1.0e-6 * step, 1000);
         }
-        integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
-                        pb.getFinalTime(), new double[pb.getDimension()]);
+        double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                                          pb.getFinalTime(), new double[pb.getDimension()]);
+        if (functions.length == 0) {
+            assertEquals(pb.getFinalTime(), stopTime, 1.0e-10);
+        }
 
         double error = handler.getMaximalValueError();
         if (i > 4) {



Mime
View raw message