commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r591662 - /commons/proper/math/trunk/src/test/org/apache/commons/math/ode/
Date Sat, 03 Nov 2007 18:47:18 GMT
Author: luc
Date: Sat Nov  3 11:47:17 2007
New Revision: 591662

URL: http://svn.apache.org/viewvc?rev=591662&view=rev
Log:
improved tests coverage

Modified:
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/EulerIntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GillIntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/MidpointIntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblemHandler.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ThreeEighthesIntegratorTest.java

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -81,7 +81,7 @@
           * Math.pow(2.0, -i);
 
         FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
-        TestProblemHandler handler = new TestProblemHandler(pb);
+        TestProblemHandler handler = new TestProblemHandler(pb, integ);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
         for (int l = 0; l < functions.length; ++l) {
@@ -91,11 +91,12 @@
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
 
-        double error = handler.getMaximalError();
+        double error = handler.getMaximalValueError();
         if (i > 4) {
           assertTrue(error < Math.abs(previousError));
         }
         previousError = error;
+        assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
       }
 
     }
@@ -109,13 +110,14 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
 
     FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() < 2.0e-13);
-    assertTrue(handler.getMaximalError() < 4.0e-12);
+    assertTrue(handler.getMaximalValueError() < 4.0e-12);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals("classical Runge-Kutta", integ.getName());
   }
 
@@ -126,13 +128,14 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
 
     FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() > 0.0004);
-    assertTrue(handler.getMaximalError() > 0.005);
+    assertTrue(handler.getMaximalValueError() > 0.005);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
   }
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -63,7 +63,7 @@
       FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
                                                                  vecAbsoluteTolerance,
                                                                  vecRelativeTolerance);
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.setStepHandler(handler);
       integ.integrate(pb,
                       pb.getInitialTime(), pb.getInitialState(),
@@ -146,7 +146,7 @@
       RungeKuttaFehlbergIntegrator integ =
           new DormandPrince54Integrator(minStep, maxStep,
                                         scalAbsoluteTolerance, scalRelativeTolerance);
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.setSafety(0.8);
       integ.setMaxGrowth(5.0);
       integ.setMinReduction(0.3);
@@ -161,7 +161,8 @@
       // the 0.7 factor is only valid for this test
       // and has been obtained from trial and error
       // there is no general relation between local and global errors
-      assertTrue(handler.getMaximalError() < (0.7 * scalAbsoluteTolerance));
+      assertTrue(handler.getMaximalValueError() < (0.7 * scalAbsoluteTolerance));
+      assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
       int calls = pb.getCalls();
       assertTrue(calls <= previousCalls);
@@ -183,7 +184,7 @@
     FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
                                                                scalAbsoluteTolerance,
                                                                scalRelativeTolerance);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     SwitchingFunction[] functions = pb.getSwitchingFunctions();
     for (int l = 0; l < functions.length; ++l) {
@@ -194,7 +195,8 @@
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
-    assertTrue(handler.getMaximalError() < 5.0e-6);
+    assertTrue(handler.getMaximalValueError() < 5.0e-6);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
 
   }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -78,7 +78,7 @@
       FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                                   vecAbsoluteTolerance,
                                                                   vecRelativeTolerance);
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.setStepHandler(handler);
       integ.integrate(pb,
                       pb.getInitialTime(), pb.getInitialState(),
@@ -105,7 +105,7 @@
       FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                                   scalAbsoluteTolerance,
                                                                   scalRelativeTolerance);
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.setStepHandler(handler);
       integ.integrate(pb,
                       pb.getInitialTime(), pb.getInitialState(),
@@ -114,7 +114,8 @@
       // the 1.3 factor is only valid for this test
       // and has been obtained from trial and error
       // there is no general relation between local and global errors
-      assertTrue(handler.getMaximalError() < (1.3 * scalAbsoluteTolerance));
+      assertTrue(handler.getMaximalValueError() < (1.3 * scalAbsoluteTolerance));
+      assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
       int calls = pb.getCalls();
       assertTrue(calls <= previousCalls);
@@ -136,7 +137,7 @@
     FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                                 scalAbsoluteTolerance,
                                                                 scalRelativeTolerance);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     SwitchingFunction[] functions = pb.getSwitchingFunctions();
     for (int l = 0; l < functions.length; ++l) {
@@ -147,7 +148,8 @@
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
-    assertTrue(handler.getMaximalError() < 5.0e-8);
+    assertTrue(handler.getMaximalValueError() < 5.0e-8);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
 
   }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/EulerIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/EulerIntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/EulerIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/EulerIntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -59,7 +59,7 @@
           * Math.pow(2.0, -i);
 
         FirstOrderIntegrator integ = new EulerIntegrator(step);
-        TestProblemHandler handler = new TestProblemHandler(pb);
+        TestProblemHandler handler = new TestProblemHandler(pb, integ);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
         for (int l = 0; l < functions.length; ++l) {
@@ -70,12 +70,13 @@
                         pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
 
-        double error = handler.getMaximalError();
+        double error = handler.getMaximalValueError();
         if (i > 4) {
           assertTrue(error < Math.abs(previousError));
         }
         previousError = error;
-      
+        assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
+
       }
 
     }
@@ -89,14 +90,15 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
 
     FirstOrderIntegrator integ = new EulerIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
    assertTrue(handler.getLastError() < 2.0e-4);
-   assertTrue(handler.getMaximalError() < 1.0e-3);
+   assertTrue(handler.getMaximalValueError() < 1.0e-3);
+   assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    assertEquals("Euler", integ.getName());
 
   }
@@ -108,14 +110,15 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
 
     FirstOrderIntegrator integ = new EulerIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() > 0.01);
-    assertTrue(handler.getMaximalError() > 0.2);
+    assertTrue(handler.getMaximalValueError() > 0.2);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
   }
   

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GillIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GillIntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GillIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GillIntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -61,7 +61,7 @@
           * Math.pow(2.0, -i);
 
         FirstOrderIntegrator integ = new GillIntegrator(step);
-        TestProblemHandler handler = new TestProblemHandler(pb);
+        TestProblemHandler handler = new TestProblemHandler(pb, integ);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
         for (int l = 0; l < functions.length; ++l) {
@@ -71,11 +71,13 @@
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
 
-        double error = handler.getMaximalError();
+        double error = handler.getMaximalValueError();
         if (i > 5) {
           assertTrue(error < Math.abs(previousError));
         }
         previousError = error;
+        assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
+
       }
 
     }
@@ -89,13 +91,14 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
 
     FirstOrderIntegrator integ = new GillIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() < 2.0e-13);
-    assertTrue(handler.getMaximalError() < 4.0e-12);
+    assertTrue(handler.getMaximalValueError() < 4.0e-12);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals("Gill", integ.getName());
 
   }
@@ -107,13 +110,14 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
 
     FirstOrderIntegrator integ = new GillIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() > 0.0004);
-    assertTrue(handler.getMaximalError() > 0.005);
+    assertTrue(handler.getMaximalValueError() > 0.005);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
   }
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -77,7 +77,7 @@
       FirstOrderIntegrator integ =
         new GraggBulirschStoerIntegrator(minStep, maxStep,
                                          vecAbsoluteTolerance, vecRelativeTolerance);
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.setStepHandler(handler);
       integ.integrate(pb,
                       pb.getInitialTime(), pb.getInitialState(),
@@ -104,7 +104,7 @@
       FirstOrderIntegrator integ =
         new GraggBulirschStoerIntegrator(minStep, maxStep,
                                          absTolerance, relTolerance);
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.setStepHandler(handler);
       integ.integrate(pb,
                       pb.getInitialTime(), pb.getInitialState(),
@@ -113,9 +113,10 @@
       // the coefficients are only valid for this test
       // and have been obtained from trial and error
       // there is no general relation between local and global errors
-      double ratio =  handler.getMaximalError() / absTolerance;
+      double ratio =  handler.getMaximalValueError() / absTolerance;
       assertTrue(ratio < 2.4);
       assertTrue(ratio > 0.02);
+      assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
       int calls = pb.getCalls();
       assertTrue(calls <= previousCalls);
@@ -156,12 +157,12 @@
 
   private double getMaxError(FirstOrderIntegrator integrator, TestProblemAbstract pb)
     throws DerivativeException, IntegratorException {
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integrator);
       integrator.setStepHandler(handler);
       integrator.integrate(pb,
                            pb.getInitialTime(), pb.getInitialState(),
                            pb.getFinalTime(), new double[pb.getDimension()]);
-      return handler.getMaximalError();
+      return handler.getMaximalValueError();
   }
 
   public void testSwitchingFunctions()
@@ -176,7 +177,7 @@
     FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep,
                                                                   scalAbsoluteTolerance,
                                                                   scalRelativeTolerance);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     SwitchingFunction[] functions = pb.getSwitchingFunctions();
     for (int l = 0; l < functions.length; ++l) {
@@ -187,7 +188,8 @@
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
-    assertTrue(handler.getMaximalError() < 5.0e-8);
+    assertTrue(handler.getMaximalValueError() < 5.0e-8);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
 
   }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -85,7 +85,7 @@
       FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                               vecAbsoluteTolerance,
                                                               vecRelativeTolerance);
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.setStepHandler(handler);
       integ.integrate(pb,
                       pb.getInitialTime(), pb.getInitialState(),
@@ -112,7 +112,7 @@
       FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                               scalAbsoluteTolerance,
                                                               scalRelativeTolerance);
-      TestProblemHandler handler = new TestProblemHandler(pb);
+      TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.setStepHandler(handler);
       integ.integrate(pb,
                       pb.getInitialTime(), pb.getInitialState(),
@@ -121,7 +121,8 @@
       // the 1.3 factor is only valid for this test
       // and has been obtained from trial and error
       // there is no general relation between local and global errors
-      assertTrue(handler.getMaximalError() < (1.3 * scalAbsoluteTolerance));
+      assertTrue(handler.getMaximalValueError() < (1.3 * scalAbsoluteTolerance));
+      assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
       int calls = pb.getCalls();
       assertTrue(calls <= previousCalls);
@@ -143,7 +144,7 @@
     FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                             scalAbsoluteTolerance,
                                                             scalRelativeTolerance);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     SwitchingFunction[] functions = pb.getSwitchingFunctions();
     for (int l = 0; l < functions.length; ++l) {
@@ -154,7 +155,8 @@
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
-    assertTrue(handler.getMaximalError() < 1.0e-7);
+    assertTrue(handler.getMaximalValueError() < 1.0e-7);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
 
   }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/MidpointIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/MidpointIntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/MidpointIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/MidpointIntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -58,7 +58,7 @@
         double step = (pb.getFinalTime() - pb.getInitialTime())
           * Math.pow(2.0, -i);
         FirstOrderIntegrator integ = new MidpointIntegrator(step);
-        TestProblemHandler handler = new TestProblemHandler(pb);
+        TestProblemHandler handler = new TestProblemHandler(pb, integ);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
         for (int l = 0; l < functions.length; ++l) {
@@ -69,11 +69,13 @@
                         pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
 
-        double error = handler.getMaximalError();
+        double error = handler.getMaximalValueError();
         if (i > 4) {
           assertTrue(error < Math.abs(previousError));
         }
         previousError = error;
+        assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
+
       }
 
     }
@@ -87,14 +89,15 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
 
     FirstOrderIntegrator integ = new MidpointIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() < 2.0e-7);
-    assertTrue(handler.getMaximalError() < 1.0e-6);
+    assertTrue(handler.getMaximalValueError() < 1.0e-6);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals("midpoint", integ.getName());
 
   }
@@ -106,14 +109,15 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
 
     FirstOrderIntegrator integ = new MidpointIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb,
                     pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() > 0.01);
-    assertTrue(handler.getMaximalError() > 0.05);
+    assertTrue(handler.getMaximalValueError() > 0.05);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
   }
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblemHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblemHandler.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblemHandler.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblemHandler.java
Sat Nov  3 11:47:17 2007
@@ -31,8 +31,9 @@
   /** Associated problem. */
   private TestProblemAbstract problem;
 
-  /** Maximal error encountered during the integration. */
-  private double maxError;
+  /** Maximal errors encountered during the integration. */
+  private double maxValueError;
+  private double maxTimeError;
 
   /** Error at the end of the integration. */
   private double lastError;
@@ -40,12 +41,20 @@
   /** Time at the end of integration. */
   private double lastTime;
 
+  /** ODE solver used. */
+  private FirstOrderIntegrator integrator;
+
+  /** Expected start for step. */
+  private double expectedStepStart;
+
   /**
    * Simple constructor.
    * @param problem problem for which steps should be handled
+   * @param integrator ODE solver used
    */
-  public TestProblemHandler(TestProblemAbstract problem) {
+  public TestProblemHandler(TestProblemAbstract problem, FirstOrderIntegrator integrator)
{
     this.problem = problem;
+    this.integrator = integrator;
     reset();
   }
 
@@ -54,14 +63,20 @@
   }
 
   public void reset() {
-    maxError  = 0;
-    lastError = 0;
+    maxValueError = 0;
+    maxTimeError  = 0;
+    lastError     = 0;
+    expectedStepStart = problem.getInitialTime();
   }
 
   public void handleStep(StepInterpolator interpolator,
                          boolean isLast)
     throws DerivativeException {
 
+    double start = integrator.getCurrentStepStart();
+    maxTimeError = Math.max(maxTimeError, Math.abs(start - expectedStepStart));
+    expectedStepStart = start + integrator.getCurrentSignedStepsize();
+
     double pT = interpolator.getPreviousTime();
     double cT = interpolator.getCurrentTime();
     double[] errorScale = problem.getErrorScale();
@@ -90,8 +105,8 @@
       // update the errors
       for (int i = 0; i < interpolatedY.length; ++i) {
         double error = errorScale[i] * Math.abs(interpolatedY[i] - theoreticalY[i]);
-        if (error > maxError) {
-          maxError = error;
+        if (error > maxValueError) {
+          maxValueError = error;
         }
       }
 
@@ -99,11 +114,19 @@
   }
 
   /**
-   * Get the maximal error encountered during integration.
-   * @return maximal error
+   * Get the maximal value error encountered during integration.
+   * @return maximal value error
+   */
+  public double getMaximalValueError() {
+    return maxValueError;
+  }
+
+  /**
+   * Get the maximal time error encountered during integration.
+   * @return maximal time error
    */
-  public double getMaximalError() {
-    return maxError;
+  public double getMaximalTimeError() {
+    return maxTimeError;
   }
 
   /**

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ThreeEighthesIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ThreeEighthesIntegratorTest.java?rev=591662&r1=591661&r2=591662&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ThreeEighthesIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ThreeEighthesIntegratorTest.java
Sat Nov  3 11:47:17 2007
@@ -61,7 +61,7 @@
           * Math.pow(2.0, -i);
 
         FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step);
-        TestProblemHandler handler = new TestProblemHandler(pb);
+        TestProblemHandler handler = new TestProblemHandler(pb, integ);
         integ.setStepHandler(handler);
         SwitchingFunction[] functions = pb.getSwitchingFunctions();
         for (int l = 0; l < functions.length; ++l) {
@@ -71,11 +71,13 @@
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
 
-        double error = handler.getMaximalError();
+        double error = handler.getMaximalValueError();
         if (i > 4) {
           assertTrue(error < Math.abs(previousError));
         }
         previousError = error;
+        assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
+
       }
 
     }
@@ -89,13 +91,14 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
 
     FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() < 2.0e-13);
-    assertTrue(handler.getMaximalError() < 4.0e-12);
+    assertTrue(handler.getMaximalValueError() < 4.0e-12);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
     assertEquals("3/8", integ.getName());
 
   }
@@ -107,13 +110,14 @@
     double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
 
     FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step);
-    TestProblemHandler handler = new TestProblemHandler(pb);
+    TestProblemHandler handler = new TestProblemHandler(pb, integ);
     integ.setStepHandler(handler);
     integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                     pb.getFinalTime(), new double[pb.getDimension()]);
 
     assertTrue(handler.getLastError() > 0.0004);
-    assertTrue(handler.getMaximalError() > 0.005);
+    assertTrue(handler.getMaximalValueError() > 0.005);
+    assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
 
   }
 



Mime
View raw message