commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r786877 [2/2] - in /commons/proper/math/trunk/src: java/org/apache/commons/math/ode/ java/org/apache/commons/math/ode/nonstiff/ java/org/apache/commons/math/ode/sampling/ test/org/apache/commons/math/ode/nonstiff/ test/org/apache/commons/ma...
Date Sat, 20 Jun 2009 18:15:54 GMT
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java?rev=786877&r1=786876&r2=786877&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java
Sat Jun 20 18:15:54 2009
@@ -29,137 +29,127 @@
 import org.apache.commons.math.ode.DerivativeException;
 import org.apache.commons.math.ode.FirstOrderIntegrator;
 import org.apache.commons.math.ode.IntegratorException;
-import org.apache.commons.math.ode.events.EventHandler;
 import org.junit.Test;
 
 public class AdamsMoultonIntegratorTest {
 
     @Test(expected=IntegratorException.class)
-    public void dimensionCheck()
-        throws DerivativeException, IntegratorException {
+    public void dimensionCheck() throws DerivativeException, IntegratorException {
         TestProblem1 pb = new TestProblem1();
-        new AdamsMoultonIntegrator(3, 0.01).integrate(pb,
-                                                      0.0, new double[pb.getDimension()+10],
-                                                      1.0, new double[pb.getDimension()+10]);
+        FirstOrderIntegrator integ =
+            new AdamsMoultonIntegrator(3, 0.0, 1.0, 1.0e-10, 1.0e-10);
+        integ.integrate(pb,
+                        0.0, new double[pb.getDimension()+10],
+                        1.0, new double[pb.getDimension()+10]);
     }
 
-    @Test
-    public void decreasingSteps()
-        throws DerivativeException, IntegratorException {
-
-        TestProblemAbstract[] problems = TestProblemFactory.getProblems();
-        for (int k = 0; k < problems.length; ++k) {
-
-            double previousError = Double.NaN;
-            for (int i = 6; i < 10; ++i) {
-
-                TestProblemAbstract pb  = (TestProblemAbstract) problems[k].clone();
-                double step = (pb.getFinalTime() - pb.getInitialTime()) * Math.pow(2.0, -i);
-
-                FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, step);
-                TestProblemHandler handler = new TestProblemHandler(pb, integ);
-                integ.addStepHandler(handler);
-                EventHandler[] functions = pb.getEventsHandlers();
-                for (int l = 0; l < functions.length; ++l) {
-                    integ.addEventHandler(functions[l],
-                                          Double.POSITIVE_INFINITY, 1.0e-3 * step, 1000);
-                }
-                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 > 6) && !(pb instanceof TestProblem4) && !(pb instanceof
TestProblem6)) {
-                    assertTrue(error <= Math.abs(1.05 * previousError));
-                }
-                previousError = error;
+    @Test(expected=IntegratorException.class)
+    public void testMinStep() throws DerivativeException, IntegratorException {
 
-            }
+          TestProblem1 pb = new TestProblem1();
+          double minStep = 0.1 * (pb.getFinalTime() - pb.getInitialTime());
+          double maxStep = pb.getFinalTime() - pb.getInitialTime();
+          double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
+          double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
 
-        }
+          FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, minStep, maxStep,
+                                                                    vecAbsoluteTolerance,
+                                                                    vecRelativeTolerance);
+          TestProblemHandler handler = new TestProblemHandler(pb, integ);
+          integ.addStepHandler(handler);
+          integ.integrate(pb,
+                          pb.getInitialTime(), pb.getInitialState(),
+                          pb.getFinalTime(), new double[pb.getDimension()]);
 
     }
 
     @Test
-    public void smallStep()
+    public void testIncreasingTolerance()
         throws DerivativeException, IntegratorException {
 
-        TestProblem1 pb  = new TestProblem1();
-        double range = pb.getFinalTime() - pb.getInitialTime();
-        double step = range * 0.001;
+        int previousCalls = Integer.MAX_VALUE;
+        for (int i = -12; i < -2; ++i) {
+            TestProblem1 pb = new TestProblem1();
+            double minStep = 0;
+            double maxStep = pb.getFinalTime() - pb.getInitialTime();
+            double scalAbsoluteTolerance = Math.pow(10.0, i);
+            double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
 
-        AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(3, step);
-        integ.setStarterIntegrator(new DormandPrince853Integrator(0, range, 1.0e-12, 1.0e-12));
-        TestProblemHandler handler = new TestProblemHandler(pb, integ);
-        integ.addStepHandler(handler);
-        integ.integrate(pb,
-                pb.getInitialTime(), pb.getInitialState(),
-                pb.getFinalTime(), new double[pb.getDimension()]);
+            FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, minStep, maxStep,
+                                                                      scalAbsoluteTolerance,
+                                                                      scalRelativeTolerance);
+            TestProblemHandler handler = new TestProblemHandler(pb, integ);
+            integ.addStepHandler(handler);
+            integ.integrate(pb,
+                            pb.getInitialTime(), pb.getInitialState(),
+                            pb.getFinalTime(), new double[pb.getDimension()]);
 
-        assertTrue(handler.getLastError() < 2.0e-10);
-        assertTrue(handler.getMaximalValueError() < 1.0e-9);
-        assertEquals(0, handler.getMaximalTimeError(), 1.0e-15);
-        assertEquals("Adams-Moulton", integ.getName());
+            // the 0.4 and 3.0 factors are 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.getMaximalValueError() > (0.4 * scalAbsoluteTolerance));
+            assertTrue(handler.getMaximalValueError() < (3.0 * scalAbsoluteTolerance));
+            assertEquals(0, handler.getMaximalTimeError(), 1.0e-16);
+
+            int calls = pb.getCalls();
+            assertEquals(integ.getEvaluations(), calls);
+            assertTrue(calls <= previousCalls);
+            previousCalls = calls;
+
+        }
 
     }
 
-    @Test
-    public void bigStep()
-        throws DerivativeException, IntegratorException {
+    @Test(expected = DerivativeException.class)
+    public void exceedMaxEvaluations() throws DerivativeException, IntegratorException {
 
         TestProblem1 pb  = new TestProblem1();
-        double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
+        double range = pb.getFinalTime() - pb.getInitialTime();
 
-        FirstOrderIntegrator integ = new AdamsMoultonIntegrator(3, step);
+        AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(3, 0, range, 1.0e-12, 1.0e-12);
         TestProblemHandler handler = new TestProblemHandler(pb, integ);
         integ.addStepHandler(handler);
+        integ.setMaxEvaluations(650);
         integ.integrate(pb,
-                pb.getInitialTime(), pb.getInitialState(),
-                pb.getFinalTime(), new double[pb.getDimension()]);
-
-        assertTrue(handler.getMaximalValueError() > 6.0e-6);
+                        pb.getInitialTime(), pb.getInitialState(),
+                        pb.getFinalTime(), new double[pb.getDimension()]);
 
     }
 
     @Test
-    public void backward()
-        throws DerivativeException, IntegratorException {
+    public void backward() throws DerivativeException, IntegratorException {
 
         TestProblem5 pb = new TestProblem5();
-        double step = Math.abs(pb.getFinalTime() - pb.getInitialTime()) * 0.001;
+        double range = Math.abs(pb.getFinalTime() - pb.getInitialTime());
 
-        FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, step);
+        FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, 0, range, 1.0e-12, 1.0e-12);
         TestProblemHandler handler = new TestProblemHandler(pb, integ);
         integ.addStepHandler(handler);
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
 
-        assertTrue(handler.getLastError() < 4.0e-12);
-        assertTrue(handler.getMaximalValueError() < 4.0e-12);
-        assertEquals(0, handler.getMaximalTimeError(), 1.0e-15);
+        assertTrue(handler.getLastError() < 1.0e-9);
+        assertTrue(handler.getMaximalValueError() < 1.0e-9);
+        assertEquals(0, handler.getMaximalTimeError(), 1.0e-16);
         assertEquals("Adams-Moulton", integ.getName());
     }
 
     @Test
-    public void polynomial()
-        throws DerivativeException, IntegratorException {
-        final TestProblem6 pb = new TestProblem6();
-        double step = Math.abs(pb.getFinalTime() - pb.getInitialTime()) * 0.02;
+    public void polynomial() throws DerivativeException, IntegratorException {
+        TestProblem6 pb = new TestProblem6();
+        double range = Math.abs(pb.getFinalTime() - pb.getInitialTime());
 
-        for (int order = 2; order < 9; ++order) {
-            AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(order, step);
-            integ.setStarterIntegrator(new DormandPrince853Integrator(1.0e-3 * step, 1.0e3
* step,
-                                                                      1.0e-5, 1.0e-5));
-            final TestProblemHandler handler = new TestProblemHandler(pb, integ);
+        for (int order = 2; order < 8; ++order) {
+            AdamsMoultonIntegrator integ =
+                new AdamsMoultonIntegrator(order, 1.0e-6 * range, 0.1 * range, 1.0e-9, 1.0e-9);
+            TestProblemHandler handler = new TestProblemHandler(pb, integ);
             integ.addStepHandler(handler);
             integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                             pb.getFinalTime(), new double[pb.getDimension()]);
             if (order < 5) {
-                assertTrue(handler.getMaximalValueError() > 1.0e-6);
+                assertTrue(integ.getEvaluations() > 150);
             } else {
-                assertTrue(handler.getMaximalValueError() < 4.0e-13);
+                assertTrue(integ.getEvaluations() < 90);
             }
         }
 
@@ -171,12 +161,14 @@
                IOException, ClassNotFoundException {
 
         TestProblem6 pb = new TestProblem6();
-        double step = Math.abs(pb.getFinalTime() - pb.getInitialTime()) * 0.01;
+        double range = Math.abs(pb.getFinalTime() - pb.getInitialTime());
 
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         ObjectOutputStream    oos = new ObjectOutputStream(bos);
-        oos.writeObject(new AdamsMoultonIntegrator(8, step));
-        
+        oos.writeObject(new AdamsMoultonIntegrator(5, 0, range, 1.0e-12, 1.0e-12));
+        assertTrue(bos.size() > 2800);
+        assertTrue(bos.size() < 3000);
+
         ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
         ObjectInputStream     ois = new ObjectInputStream(bis);
         FirstOrderIntegrator integ  = (AdamsMoultonIntegrator) ois.readObject();
@@ -185,7 +177,7 @@
         integ.addStepHandler(handler);
         integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                         pb.getFinalTime(), new double[pb.getDimension()]);
-        assertTrue(handler.getMaximalValueError() < 2.0e-13);
+        assertTrue(handler.getMaximalValueError() < 8.0e-11);
 
     }
 

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/sampling/NordsieckStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/sampling/NordsieckStepInterpolatorTest.java?rev=786877&r1=786876&r2=786877&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/sampling/NordsieckStepInterpolatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/sampling/NordsieckStepInterpolatorTest.java
Sat Jun 20 18:15:54 2009
@@ -40,9 +40,8 @@
     public void derivativesConsistency()
     throws DerivativeException, IntegratorException {
         TestProblem3 pb = new TestProblem3();
-        double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
-        AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(5, step);
-        StepInterpolatorTestUtils.checkDerivativesConsistency(integ, pb, 1.0e-10);
+        AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(5, 0.0, 1.0, 1.0e-10,
1.0e-10);
+        StepInterpolatorTestUtils.checkDerivativesConsistency(integ, pb, 7e-10);
     }
 
     @Test
@@ -51,8 +50,7 @@
     IOException, ClassNotFoundException {
 
         TestProblem1 pb = new TestProblem1();
-        double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
-        AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(5, step);
+        AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(5, 0.0, 1.0, 1.0e-10,
1.0e-10);
         integ.addStepHandler(new ContinuousOutputModel());
         integ.integrate(pb,
                         pb.getInitialTime(), pb.getInitialState(),
@@ -64,8 +62,8 @@
             oos.writeObject(handler);
         }
 
-        assertTrue(bos.size () > 148000);
-        assertTrue(bos.size () < 149000);
+        assertTrue(bos.size () >  16000);
+        assertTrue(bos.size () <  17000);
 
         ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
         ObjectInputStream     ois = new ObjectInputStream(bis);



Mime
View raw message