commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r476930 [20/22] - in /jakarta/commons/proper/math/trunk/src/mantissa: ./ src/ src/org/ src/org/spaceroots/ src/org/spaceroots/mantissa/ src/org/spaceroots/mantissa/algebra/ src/org/spaceroots/mantissa/estimation/ src/org/spaceroots/mantissa...
Date Sun, 19 Nov 2006 21:36:23 GMT
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,302 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+
+public class DormandPrince54IntegratorTest
+  extends TestCase {
+
+  public DormandPrince54IntegratorTest(String name) {
+    super(name);
+  }
+
+  public void testDimensionCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      DormandPrince54Integrator integrator = new DormandPrince54Integrator(0.0, 1.0,
+                                                                           1.0e-10, 1.0e-10);
+      integrator.integrate(pb,
+                           0.0, new double[pb.getDimension()+10],
+                           1.0, new double[pb.getDimension()+10]);
+      fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+
+  public void testMinStep()
+    throws DerivativeException, IntegratorException {
+
+    try {
+      TestProblem1 pb = new TestProblem1();
+      double minStep = 0.1 * (pb.getFinalTime() - pb.getInitialTime());
+      double maxStep = pb.getFinalTime() - pb.getInitialTime();
+      double scalAbsoluteTolerance = 1.0e-15;
+      double scalRelativeTolerance = 1.0e-15;
+
+      FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
+                                                                 scalAbsoluteTolerance,
+                                                                 scalRelativeTolerance);
+      TestProblemHandler handler = new TestProblemHandler(pb);
+      integ.setStepHandler(handler);
+      integ.integrate(pb,
+                      pb.getInitialTime(), pb.getInitialState(),
+                      pb.getFinalTime(), new double[pb.getDimension()]);
+      fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+
+  }
+
+  public void testSmallLastStep()
+    throws DerivativeException, IntegratorException {
+
+    TestProblemAbstract pb = new TestProblem5();
+    double minStep = 1.25;
+    double maxStep = Math.abs(pb.getFinalTime() - pb.getInitialTime());
+    double scalAbsoluteTolerance = 6.0e-4;
+    double scalRelativeTolerance = 6.0e-4;
+
+    AdaptiveStepsizeIntegrator integ =
+      new DormandPrince54Integrator(minStep, maxStep,
+                                    scalAbsoluteTolerance,
+                                    scalRelativeTolerance);
+
+    DP54SmallLastHandler handler = new DP54SmallLastHandler(minStep);
+    integ.setStepHandler(handler);
+    integ.setInitialStepSize(1.7);
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+    assertTrue(handler.wasLastSeen());
+
+  }
+
+  private class DP54SmallLastHandler implements StepHandler {
+
+    public DP54SmallLastHandler(double minStep) {
+      lastSeen = false;
+      this.minStep = minStep;
+    }
+
+    public boolean requiresDenseOutput() {
+      return false;
+    }
+
+    public void reset() {
+    }
+
+    public void handleStep(StepInterpolator interpolator, boolean isLast) {
+      if (isLast) {
+        lastSeen = true;
+        double h = interpolator.getCurrentTime() - interpolator.getPreviousTime();
+        assertTrue(Math.abs(h) < minStep);
+      }
+    }
+
+    public boolean wasLastSeen() {
+      return lastSeen;
+    }
+
+    private boolean lastSeen;
+    private double  minStep;
+
+  }
+
+  public void testIncreasingTolerance()
+    throws DerivativeException, IntegratorException {
+
+    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;
+
+      FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
+                                                                 scalAbsoluteTolerance,
+                                                                 scalRelativeTolerance);
+      TestProblemHandler handler = new TestProblemHandler(pb);
+      integ.setStepHandler(handler);
+      integ.integrate(pb,
+                      pb.getInitialTime(), pb.getInitialState(),
+                      pb.getFinalTime(), new double[pb.getDimension()]);
+
+      // 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));
+
+      int calls = pb.getCalls();
+      assertTrue(calls <= previousCalls);
+      previousCalls = calls;
+
+    }
+
+  }
+
+  public void testSwitchingFunctions()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem4 pb = new TestProblem4();
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+    FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
+                                                               scalAbsoluteTolerance,
+                                                               scalRelativeTolerance);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    integ.setStepHandler(handler);
+    SwitchingFunction[] functions = pb.getSwitchingFunctions();
+    if (functions != null) {
+      for (int l = 0; l < functions.length; ++l) {
+        integ.addSwitchingFunction(functions[l],
+                                   Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
+      }
+    }
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    assertTrue(handler.getMaximalError() < 5.0e-6);
+    assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
+
+  }
+
+  public void testKepler()
+    throws DerivativeException, IntegratorException {
+
+    final TestProblem3 pb  = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+
+    FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
+                                                               scalAbsoluteTolerance,
+                                                               scalRelativeTolerance);
+    integ.setStepHandler(new StepHandler() {
+                      private int nbSteps = 0;
+                      private double maxError = 0;
+                      public boolean requiresDenseOutput() {
+                        return true;
+                      }
+                      public void reset() {
+                        nbSteps = 0;
+                        maxError = 0;
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast)
+                        throws DerivativeException {
+
+                        ++nbSteps;
+                        for (int a = 1; a < 10; ++a) {
+
+                          double prev   = interpolator.getPreviousTime();
+                          double curr   = interpolator.getCurrentTime();
+                          double interp = ((10 - a) * prev + a * curr) / 10;
+                          interpolator.setInterpolatedTime(interp);
+
+                          double[] interpolatedY = interpolator.getInterpolatedState ();
+                          double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
+                          double dx = interpolatedY[0] - theoreticalY[0];
+                          double dy = interpolatedY[1] - theoreticalY[1];
+                          double error = dx * dx + dy * dy;
+                          if (error > maxError) {
+                            maxError = error;
+                          }
+                        }
+                        if (isLast) {
+                          assertTrue(maxError < 7.0e-10);
+                          assertTrue(nbSteps < 400);
+                        }
+                      }
+      });
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    assertTrue(pb.getCalls() < 2800);
+
+  }
+
+  public void testVariableSteps()
+    throws DerivativeException, IntegratorException {
+
+    final TestProblem3 pb  = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+
+    FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
+                                                               scalAbsoluteTolerance,
+                                                               scalRelativeTolerance);
+    integ.setStepHandler(new StepHandler() {
+                      private boolean firstTime = true;
+                      private double  minStep = 0;
+                      private double  maxStep = 0;
+                      public boolean requiresDenseOutput() {
+                        return false;
+                      }
+                      public void reset() {
+                        firstTime = true;
+                        minStep = 0;
+                        maxStep = 0;
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast) {
+
+                        double step = Math.abs(interpolator.getCurrentTime()
+                                               - interpolator.getPreviousTime());
+                        if (firstTime) {
+                          minStep   = Math.abs(step);
+                          maxStep   = minStep;
+                          firstTime = false;
+                        } else {
+                          if (step < minStep) {
+                            minStep = step;
+                          }
+                          if (step > maxStep) {
+                            maxStep = step;
+                          }
+                        }
+
+                        if (isLast) {
+                          assertTrue(minStep < (1.0 / 450.0));
+                          assertTrue(maxStep > (1.0 / 4.2));
+                        }
+                      }
+      });
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+  }
+
+  public static Test suite() {
+    return new TestSuite(DormandPrince54IntegratorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54StepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54StepInterpolatorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54StepInterpolatorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54StepInterpolatorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,87 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+import java.util.Random;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+
+public class DormandPrince54StepInterpolatorTest
+  extends TestCase {
+
+  public DormandPrince54StepInterpolatorTest(String name) {
+    super(name);
+  }
+
+  public void testSerialization()
+    throws DerivativeException, IntegratorException,
+           IOException, ClassNotFoundException {
+
+    TestProblem3 pb = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+    DormandPrince54Integrator integ = new DormandPrince54Integrator(minStep, maxStep,
+                                                                    scalAbsoluteTolerance,
+                                                                    scalRelativeTolerance);
+    integ.setStepHandler(new ContinuousOutputModel());
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    ObjectOutputStream    oos = new ObjectOutputStream(bos);
+    oos.writeObject(integ.getStepHandler());
+
+    assertTrue(bos.size () > 119500);
+    assertTrue(bos.size () < 120500);
+
+    ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
+    ObjectInputStream     ois = new ObjectInputStream(bis);
+    ContinuousOutputModel cm  = (ContinuousOutputModel) ois.readObject();
+
+    Random random = new Random(347588535632l);
+    double maxError = 0.0;
+    for (int i = 0; i < 1000; ++i) {
+      double r = random.nextDouble();
+      double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
+      cm.setInterpolatedTime(time);
+      double[] interpolatedY = cm.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(time);
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+    }
+
+    assertTrue(maxError < 7.0e-10);
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(DormandPrince54StepInterpolatorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54StepInterpolatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,312 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+
+public class DormandPrince853IntegratorTest
+  extends TestCase {
+
+  public DormandPrince853IntegratorTest(String name) {
+    super(name);
+  }
+
+  public void testDimensionCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      DormandPrince853Integrator integrator = new DormandPrince853Integrator(0.0, 1.0,
+                                                                             1.0e-10, 1.0e-10);
+      integrator.integrate(pb,
+                           0.0, new double[pb.getDimension()+10],
+                           1.0, new double[pb.getDimension()+10]);
+      fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+
+  public void testNullIntervalCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      DormandPrince853Integrator integrator = new DormandPrince853Integrator(0.0, 1.0,
+                                                                             1.0e-10, 1.0e-10);
+      integrator.integrate(pb,
+                           0.0, new double[pb.getDimension()],
+                           0.0, new double[pb.getDimension()]);
+      fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+
+  public void testMinStep()
+    throws DerivativeException, IntegratorException {
+
+    try {
+      TestProblem1 pb = new TestProblem1();
+      double minStep = 0.1 * (pb.getFinalTime() - pb.getInitialTime());
+      double maxStep = pb.getFinalTime() - pb.getInitialTime();
+      double scalAbsoluteTolerance = 1.0e-15;
+      double scalRelativeTolerance = 1.0e-15;
+
+      FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
+                                                                  scalAbsoluteTolerance,
+                                                                  scalRelativeTolerance);
+      TestProblemHandler handler = new TestProblemHandler(pb);
+      integ.setStepHandler(handler);
+      integ.integrate(pb,
+                      pb.getInitialTime(), pb.getInitialState(),
+                      pb.getFinalTime(), new double[pb.getDimension()]);
+      fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+
+  }
+
+  public void testIncreasingTolerance()
+    throws DerivativeException, IntegratorException {
+
+    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;
+
+      FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
+                                                                  scalAbsoluteTolerance,
+                                                                  scalRelativeTolerance);
+      TestProblemHandler handler = new TestProblemHandler(pb);
+      integ.setStepHandler(handler);
+      integ.integrate(pb,
+                      pb.getInitialTime(), pb.getInitialState(),
+                      pb.getFinalTime(), new double[pb.getDimension()]);
+
+      // 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));
+
+      int calls = pb.getCalls();
+      assertTrue(calls <= previousCalls);
+      previousCalls = calls;
+
+    }
+
+  }
+
+  public void testSwitchingFunctions()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem4 pb = new TestProblem4();
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-9;
+    double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+    FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
+                                                                scalAbsoluteTolerance,
+                                                                scalRelativeTolerance);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    integ.setStepHandler(handler);
+    SwitchingFunction[] functions = pb.getSwitchingFunctions();
+    if (functions != null) {
+      for (int l = 0; l < functions.length; ++l) {
+        integ.addSwitchingFunction(functions[l],
+                                   Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
+      }
+    }
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    assertTrue(handler.getMaximalError() < 5.0e-8);
+    assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
+
+  }
+
+  public void testKepler()
+    throws DerivativeException, IntegratorException {
+
+    final TestProblem3 pb  = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+
+    FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
+                                                                scalAbsoluteTolerance,
+                                                                scalRelativeTolerance);
+    integ.setStepHandler(new StepHandler() {
+                      private int nbSteps = 0;
+                      private double maxError = 0;
+                      public boolean requiresDenseOutput() {
+                        return true;
+                      }
+                      public void reset() {
+                        nbSteps = 0;
+                        maxError = 0;
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast)
+                        throws DerivativeException {
+
+                        ++nbSteps;
+                        for (int a = 1; a < 10; ++a) {
+
+                          double prev   = interpolator.getPreviousTime();
+                          double curr   = interpolator.getCurrentTime();
+                          double interp = ((10 - a) * prev + a * curr) / 10;
+                          interpolator.setInterpolatedTime(interp);
+
+                          double[] interpolatedY = interpolator.getInterpolatedState ();
+                          double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
+                          double dx = interpolatedY[0] - theoreticalY[0];
+                          double dy = interpolatedY[1] - theoreticalY[1];
+                          double error = dx * dx + dy * dy;
+                          if (error > maxError) {
+                            maxError = error;
+                          }
+                        }
+                        if (isLast) {
+                          assertTrue(maxError < 2.4e-10);
+                          assertTrue(nbSteps < 150);
+                        }
+                      }
+      });
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    assertTrue(pb.getCalls() < 2900);
+
+  }
+
+  public void testVariableSteps()
+    throws DerivativeException, IntegratorException {
+
+    final TestProblem3 pb  = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+
+    FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
+                                                               scalAbsoluteTolerance,
+                                                               scalRelativeTolerance);
+    integ.setStepHandler(new StepHandler() {
+                      private boolean firstTime = true;
+                      private double  minStep = 0;
+                      private double  maxStep = 0;
+                      public boolean requiresDenseOutput() {
+                        return false;
+                      }
+                      public void reset() {
+                        firstTime = true;
+                        minStep = 0;
+                        maxStep = 0;
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast) {
+
+                        double step = Math.abs(interpolator.getCurrentTime()
+                                               - interpolator.getPreviousTime());
+                        if (firstTime) {
+                          minStep   = Math.abs(step);
+                          maxStep   = minStep;
+                          firstTime = false;
+                        } else {
+                          if (step < minStep) {
+                            minStep = step;
+                          }
+                          if (step > maxStep) {
+                            maxStep = step;
+                          }
+                        }
+
+                        if (isLast) {
+                          assertTrue(minStep < (1.0 / 100.0));
+                          assertTrue(maxStep > (1.0 / 2.0));
+                        }
+                      }
+      });
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+  }
+
+  public void testNoDenseOutput()
+    throws DerivativeException, IntegratorException {
+    TestProblem1 pb1 = new TestProblem1();
+    TestProblem1 pb2 = (TestProblem1) pb1.clone();
+    double minStep = 0.1 * (pb1.getFinalTime() - pb1.getInitialTime());
+    double maxStep = pb1.getFinalTime() - pb1.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-4;
+    double scalRelativeTolerance = 1.0e-4;
+
+    FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
+                                                                scalAbsoluteTolerance,
+                                                                scalRelativeTolerance);
+    integ.setStepHandler(new StepHandler() {
+                      public boolean requiresDenseOutput() {
+                        return false;
+                      }
+                      public void reset() {
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast) {
+                      }
+      });
+    integ.integrate(pb1,
+                    pb1.getInitialTime(), pb1.getInitialState(),
+                    pb1.getFinalTime(), new double[pb1.getDimension()]);
+    int callsWithoutDenseOutput = pb1.getCalls();
+
+    integ.setStepHandler(new StepHandler() {
+                      public boolean requiresDenseOutput() {
+                        return true;
+                      }
+                      public void reset() {
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast)
+                        throws DerivativeException {
+                        double prev = interpolator.getPreviousTime();
+                        double curr = interpolator.getCurrentTime();
+                        interpolator.setInterpolatedTime(0.5*(prev + curr));
+                      }
+      });
+    integ.integrate(pb2,
+                    pb2.getInitialTime(), pb2.getInitialState(),
+                    pb2.getFinalTime(), new double[pb2.getDimension()]);
+    int callsWithDenseOutput = pb2.getCalls();
+
+    assertTrue(callsWithDenseOutput > callsWithoutDenseOutput);
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(DormandPrince853IntegratorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853StepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853StepInterpolatorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853StepInterpolatorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853StepInterpolatorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,87 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+import java.util.Random;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+
+public class DormandPrince853StepInterpolatorTest
+  extends TestCase {
+
+  public DormandPrince853StepInterpolatorTest(String name) {
+    super(name);
+  }
+
+  public void testSerialization()
+    throws DerivativeException, IntegratorException,
+           IOException, ClassNotFoundException {
+
+    TestProblem3 pb = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+    DormandPrince853Integrator integ = new DormandPrince853Integrator(minStep, maxStep,
+                                                                      scalAbsoluteTolerance,
+                                                                      scalRelativeTolerance);
+    integ.setStepHandler(new ContinuousOutputModel());
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    ObjectOutputStream    oos = new ObjectOutputStream(bos);
+    oos.writeObject(integ.getStepHandler());
+
+    assertTrue(bos.size () > 86000);
+    assertTrue(bos.size () < 87000);
+
+    ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
+    ObjectInputStream     ois = new ObjectInputStream(bis);
+    ContinuousOutputModel cm  = (ContinuousOutputModel) ois.readObject();
+
+    Random random = new Random(347588535632l);
+    double maxError = 0.0;
+    for (int i = 0; i < 1000; ++i) {
+      double r = random.nextDouble();
+      double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
+      cm.setInterpolatedTime(time);
+      double[] interpolatedY = cm.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(time);
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+    }
+
+    assertTrue(maxError < 2.4e-10);
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(DormandPrince853StepInterpolatorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853StepInterpolatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,169 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+
+import org.spaceroots.mantissa.estimation.EstimationException;
+import org.spaceroots.mantissa.fitting.PolynomialFitter;
+
+public class EulerIntegratorTest
+  extends TestCase {
+
+  public EulerIntegratorTest(String name) {
+    super(name);
+  }
+
+  public void testDimensionCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      new EulerIntegrator(0.01).integrate(pb,
+                                          0.0, new double[pb.getDimension()+10],
+                                          1.0, new double[pb.getDimension()+10]);
+        fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+  
+  public void testDecreasingSteps()
+    throws DerivativeException, IntegratorException {
+
+    TestProblemAbstract[] problems = TestProblemFactory.getProblems();
+    for (int k = 0; k < problems.length; ++k) {
+
+      double previousError = Double.NaN;
+      for (int i = 4; i < 10; ++i) {
+
+        TestProblemAbstract pb  = (TestProblemAbstract) problems[k].clone();
+        double step = (pb.getFinalTime() - pb.getInitialTime())
+          * Math.pow(2.0, -i);
+
+        FirstOrderIntegrator integ = new EulerIntegrator(step);
+        TestProblemHandler handler = new TestProblemHandler(pb);
+        integ.setStepHandler(handler);
+        SwitchingFunction[] functions = pb.getSwitchingFunctions();
+        if (functions != null) {
+          for (int l = 0; l < functions.length; ++l) {
+            integ.addSwitchingFunction(functions[l],
+                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
+          }
+        }
+        integ.integrate(pb,
+                        pb.getInitialTime(), pb.getInitialState(),
+                        pb.getFinalTime(), new double[pb.getDimension()]);
+
+        double error = handler.getMaximalError();
+        if (i > 4) {
+          assertTrue(error < Math.abs(previousError));
+        }
+        previousError = error;
+      
+      }
+
+    }
+
+  }
+
+  public void testOrder()
+  throws EstimationException, DerivativeException,
+         IntegratorException {
+    PolynomialFitter fitter = new PolynomialFitter(1,
+                                                   10, 1.0e-7, 1.0e-10,
+                                                   1.0e-10);
+
+    TestProblemAbstract[] problems = TestProblemFactory.getProblems();
+    for (int k = 0; k < problems.length; ++k) {
+
+      for (int i = 0; i < 10; ++i) {
+
+        TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
+        double step  = (pb.getFinalTime() - pb.getInitialTime())
+          * Math.pow(2.0, -(i + 1));
+
+        FirstOrderIntegrator integ = new EulerIntegrator(step);
+        TestProblemHandler handler = new TestProblemHandler(pb);
+        integ.setStepHandler(handler);
+        SwitchingFunction[] functions = pb.getSwitchingFunctions();
+        if (functions != null) {
+          for (int l = 0; l < functions.length; ++l) {
+            integ.addSwitchingFunction(functions[l],
+                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
+          }
+        }
+        integ.integrate(pb,
+                        pb.getInitialTime(), pb.getInitialState(),
+                        pb.getFinalTime(), new double[pb.getDimension()]);
+
+        fitter.addWeightedPair(1.0,
+                               Math.log(Math.abs(step)),
+                               Math.log(handler.getLastError()));
+
+      }
+
+      // this is an order 1 method
+      double[] coeffs = fitter.fit();
+      assertTrue(coeffs[1] > 0.2);
+      assertTrue(coeffs[1] < 1.8);
+
+    }
+
+  }
+
+  public void testSmallStep()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem1 pb  = new TestProblem1();
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
+
+    FirstOrderIntegrator integ = new EulerIntegrator(step);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    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);
+
+  }
+
+  public void testBigStep()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem1 pb  = new TestProblem1();
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
+
+    FirstOrderIntegrator integ = new EulerIntegrator(step);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    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);
+
+  }
+  
+  public static Test suite() {
+    return new TestSuite(EulerIntegratorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,170 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+import java.util.Random;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+
+public class EulerStepInterpolatorTest
+  extends TestCase {
+
+  public EulerStepInterpolatorTest(String name) {
+    super(name);
+  }
+
+  public void testNoReset() {
+
+    double[]   y    =   { 0.0, 1.0, -2.0 };
+    double[][] yDot = { { 1.0, 2.0, -2.0 } };
+    EulerStepInterpolator interpolator = new EulerStepInterpolator();
+    interpolator.reinitialize(new DummyEquations(), y, yDot, true);
+    interpolator.storeTime(0);
+    interpolator.shift();
+    interpolator.storeTime(1);
+
+    double[] result = interpolator.getInterpolatedState();
+    for (int i = 0; i < result.length; ++i) {
+      assertTrue(Math.abs(result[i] - y[i]) < 1.0e-10);
+    }
+
+  }
+
+  public void testInterpolationAtBounds()
+    throws DerivativeException {
+
+    double   t0 = 0;
+    double[] y0 = {0.0, 1.0, -2.0};
+
+    double[] y = new double[y0.length];
+    System.arraycopy(y0, 0, y, 0, y0.length);
+    double[][] yDot = { new double[y0.length] };
+    EulerStepInterpolator interpolator = new EulerStepInterpolator();
+    interpolator.reinitialize(new DummyEquations(), y, yDot, true);
+    interpolator.storeTime(t0);
+
+    double dt = 1.0;
+    y[0] =  1.0;
+    y[1] =  3.0;
+    y[2] = -4.0;
+    yDot[0][0] = (y[0] - y0[0]) / dt;
+    yDot[0][1] = (y[1] - y0[1]) / dt;
+    yDot[0][2] = (y[2] - y0[2]) / dt;
+    interpolator.shift();
+    interpolator.storeTime(t0 + dt);
+
+    interpolator.setInterpolatedTime(interpolator.getPreviousTime());
+    double[] result = interpolator.getInterpolatedState();
+    for (int i = 0; i < result.length; ++i) {
+      assertTrue(Math.abs(result[i] - y0[i]) < 1.0e-10);
+    }
+
+    interpolator.setInterpolatedTime(interpolator.getCurrentTime());
+    result = interpolator.getInterpolatedState();
+    for (int i = 0; i < result.length; ++i) {
+      assertTrue(Math.abs(result[i] - y[i]) < 1.0e-10);
+    }
+
+  }
+
+  public void testInterpolationInside()
+    throws DerivativeException {
+
+    double[]   y    =   { 1.0, 3.0, -4.0 };
+    double[][] yDot = { { 1.0, 2.0, -2.0 } };
+    EulerStepInterpolator interpolator = new EulerStepInterpolator();
+    interpolator.reinitialize(new DummyEquations(), y, yDot, true);
+    interpolator.storeTime(0);
+    interpolator.shift();
+    interpolator.storeTime(1);
+
+    interpolator.setInterpolatedTime(0.1);
+    double[] result = interpolator.getInterpolatedState();
+    assertTrue(Math.abs(result[0] - 0.1) < 1.0e-10);
+    assertTrue(Math.abs(result[1] - 1.2) < 1.0e-10);
+    assertTrue(Math.abs(result[2] + 2.2) < 1.0e-10);
+
+    interpolator.setInterpolatedTime(0.5);
+    result = interpolator.getInterpolatedState();
+    assertTrue(Math.abs(result[0] - 0.5) < 1.0e-10);
+    assertTrue(Math.abs(result[1] - 2.0) < 1.0e-10);
+    assertTrue(Math.abs(result[2] + 3.0) < 1.0e-10);
+
+  }
+
+  public void testSerialization()
+    throws DerivativeException, IntegratorException,
+           IOException, ClassNotFoundException {
+
+    TestProblem1 pb = new TestProblem1();
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
+    EulerIntegrator integ = new EulerIntegrator(step);
+    integ.setStepHandler(new ContinuousOutputModel());
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    ObjectOutputStream    oos = new ObjectOutputStream(bos);
+    oos.writeObject(integ.getStepHandler());
+
+    assertTrue(bos.size () > 82000);
+    assertTrue(bos.size () < 83000);
+
+    ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
+    ObjectInputStream     ois = new ObjectInputStream(bis);
+    ContinuousOutputModel cm  = (ContinuousOutputModel) ois.readObject();
+
+    Random random = new Random(347588535632l);
+    double maxError = 0.0;
+    for (int i = 0; i < 1000; ++i) {
+      double r = random.nextDouble();
+      double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
+      cm.setInterpolatedTime(time);
+      double[] interpolatedY = cm.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(time);
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+    }
+
+    assertTrue(maxError < 0.001);
+
+  }
+
+  private class DummyEquations
+    implements FirstOrderDifferentialEquations {
+    public int getDimension() {
+      return 0;
+    }
+    public void computeDerivatives(double t, double[] y, double[] yDot) {
+    }
+  }
+
+  public static Test suite() {
+    return new TestSuite(EulerStepInterpolatorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,110 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+
+public class FirstOrderConverterTest
+  extends TestCase {
+
+  public FirstOrderConverterTest(String name) {
+    super(name);
+  }
+
+  public void testDoubleDimension() {
+    for (int i = 1; i < 10; ++i) {
+      SecondOrderDifferentialEquations eqn2 = new Equations(i, 0.2);
+      FirstOrderConverter eqn1 = new FirstOrderConverter(eqn2);
+      assertTrue(eqn1.getDimension() == (2 * eqn2.getDimension()));
+    }
+  }
+  
+  public void testDecreasingSteps()
+    throws DerivativeException, IntegratorException {
+      
+    double previousError = Double.NaN;
+    for (int i = 0; i < 10; ++i) {
+
+      double step  = Math.pow(2.0, -(i + 1));
+      double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, step)
+                   - Math.sin(4.0);
+      if (i > 0) {
+        assertTrue(Math.abs(error) < Math.abs(previousError));
+      }
+      previousError = error;
+      
+    }
+  }
+
+  public void testSmallStep()
+    throws DerivativeException, IntegratorException {
+    double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, 1.0e-4)
+                   - Math.sin(4.0);
+    assertTrue(Math.abs(error) < 1.0e-10);
+  }
+
+  public void testBigStep()
+    throws DerivativeException, IntegratorException {
+    double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, 0.5)
+                   - Math.sin(4.0);
+    assertTrue(Math.abs(error) > 0.1);
+  }
+  
+  public static Test suite() {
+    return new TestSuite(FirstOrderConverterTest.class);
+  }
+
+  private class Equations
+    implements SecondOrderDifferentialEquations {
+      
+      private int n;
+
+      private double omega2;
+      
+      public Equations(int n, double omega) {
+        this.n = n;
+        omega2 = omega * omega;
+      }
+      
+      public int getDimension() {
+        return n;
+      }
+      
+      public void computeSecondDerivatives(double t, double[] y, double[] yDot,
+                                           double[] yDDot) {
+        for (int i = 0; i < n; ++i) {
+          yDDot[i] = -omega2 * y[i];
+        }
+    }
+      
+  }
+
+  private double integrateWithSpecifiedStep(double omega,
+                                            double t0, double t,
+                                            double step)
+  throws DerivativeException, IntegratorException {
+    double[] y0 = new double[2];
+    y0[0] = Math.sin(omega * t0);
+    y0[1] = omega * Math.cos(omega * t0);
+    ClassicalRungeKuttaIntegrator i = new ClassicalRungeKuttaIntegrator(step);
+    double[] y = new double[2];
+    i.integrate(new FirstOrderConverter(new Equations(1, omega)), t0, y0, t, y);
+    return y[0];
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,203 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+
+import org.spaceroots.mantissa.estimation.EstimationException;
+import org.spaceroots.mantissa.fitting.PolynomialFitter;
+
+public class GillIntegratorTest
+  extends TestCase {
+
+  public GillIntegratorTest(String name) {
+    super(name);
+  }
+
+  public void testDimensionCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      new GillIntegrator(0.01).integrate(pb,
+                                         0.0, new double[pb.getDimension()+10],
+                                         1.0, new double[pb.getDimension()+10]);
+        fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+  
+  public void testDecreasingSteps()
+    throws DerivativeException, IntegratorException  {
+      
+    TestProblemAbstract[] problems = TestProblemFactory.getProblems();
+    for (int k = 0; k < problems.length; ++k) {
+
+      double previousError = Double.NaN;
+      for (int i = 5; i < 10; ++i) {
+
+        TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
+        double step = (pb.getFinalTime() - pb.getInitialTime())
+          * Math.pow(2.0, -i);
+
+        FirstOrderIntegrator integ = new GillIntegrator(step);
+        TestProblemHandler handler = new TestProblemHandler(pb);
+        integ.setStepHandler(handler);
+        SwitchingFunction[] functions = pb.getSwitchingFunctions();
+        if (functions != null) {
+          for (int l = 0; l < functions.length; ++l) {
+            integ.addSwitchingFunction(functions[l],
+                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
+          }
+        }
+        integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                        pb.getFinalTime(), new double[pb.getDimension()]);
+
+        double error = handler.getMaximalError();
+        if (i > 5) {
+          assertTrue(error < Math.abs(previousError));
+        }
+        previousError = error;
+      }
+
+    }
+
+  }
+
+  public void testOrder()
+  throws EstimationException, DerivativeException,
+         IntegratorException {
+    PolynomialFitter fitter = new PolynomialFitter(1,
+                                                   10, 1.0e-7, 1.0e-10,
+                                                   1.0e-10);
+
+    TestProblemAbstract[] problems = TestProblemFactory.getProblems();
+    for (int k = 0; k < problems.length; ++k) {
+    
+      for (int i = 0; i < 10; ++i) {
+
+        TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
+        double step = (pb.getFinalTime() - pb.getInitialTime())
+          * Math.pow(2.0, -(i + 1));
+
+        FirstOrderIntegrator integ = new GillIntegrator(step);
+        TestProblemHandler handler = new TestProblemHandler(pb);
+        integ.setStepHandler(handler);
+        SwitchingFunction[] functions = pb.getSwitchingFunctions();
+        if (functions != null) {
+          for (int l = 0; l < functions.length; ++l) {
+            integ.addSwitchingFunction(functions[l],
+                                       Double.POSITIVE_INFINITY, 1.0e-6 * step);
+          }
+        }
+        integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
+                        pb.getFinalTime(), new double[pb.getDimension()]);
+
+        fitter.addWeightedPair(1.0,
+                               Math.log(Math.abs(step)),
+                               Math.log(handler.getLastError()));
+
+      }
+
+      // this is an order 4 method
+      double[] coeffs = fitter.fit();
+      assertTrue(coeffs[1] > 3.2);
+      assertTrue(coeffs[1] < 4.8);
+
+    }
+
+  }
+
+  public void testSmallStep()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem1 pb = new TestProblem1();
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
+
+    FirstOrderIntegrator integ = new GillIntegrator(step);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    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);
+
+  }
+
+  public void testBigStep()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem1 pb = new TestProblem1();
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
+
+    FirstOrderIntegrator integ = new GillIntegrator(step);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    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);
+
+  }
+
+  public void testKepler()
+    throws DerivativeException, IntegratorException {
+
+    final TestProblem3 pb  = new TestProblem3(0.9);
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003;
+
+    FirstOrderIntegrator integ = new GillIntegrator(step);
+    integ.setStepHandler(new StepHandler() {
+                      private double maxError = 0;
+                      public boolean requiresDenseOutput() {
+                        return false;
+                      }
+                      public void reset() {
+                        maxError = 0;
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast) {
+
+                        double[] interpolatedY = interpolator.getInterpolatedState ();
+                        double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getCurrentTime());
+                        double dx = interpolatedY[0] - theoreticalY[0];
+                        double dy = interpolatedY[1] - theoreticalY[1];
+                        double error = dx * dx + dy * dy;
+                        if (error > maxError) {
+                          maxError = error;
+                        }
+                        if (isLast) {
+                          // even with more than 1000 evaluations per period,
+                          // RK4 is not able to integrate such an eccentric
+                          // orbit with a good accuracy
+                          assertTrue(maxError > 0.001);
+                        }
+                      }
+      });
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+  }
+
+  public static Test suite() {
+    return new TestSuite(GillIntegratorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillStepInterpolatorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillStepInterpolatorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillStepInterpolatorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,82 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+import java.util.Random;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+
+public class GillStepInterpolatorTest
+  extends TestCase {
+
+  public GillStepInterpolatorTest(String name) {
+    super(name);
+  }
+
+  public void testSerialization()
+    throws DerivativeException, IntegratorException,
+           IOException, ClassNotFoundException {
+
+    TestProblem3 pb = new TestProblem3(0.9);
+    double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.0003;
+    GillIntegrator integ = new GillIntegrator(step);
+    integ.setStepHandler(new ContinuousOutputModel());
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    ObjectOutputStream    oos = new ObjectOutputStream(bos);
+    oos.writeObject(integ.getStepHandler());
+
+    assertTrue(bos.size () > 700000);
+    assertTrue(bos.size () < 701000);
+
+    ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
+    ObjectInputStream     ois = new ObjectInputStream(bis);
+    ContinuousOutputModel cm  = (ContinuousOutputModel) ois.readObject();
+
+    Random random = new Random(347588535632l);
+    double maxError = 0.0;
+    for (int i = 0; i < 1000; ++i) {
+      double r = random.nextDouble();
+      double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
+      cm.setInterpolatedTime(time);
+      double[] interpolatedY = cm.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(time);
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+    }
+
+    assertTrue(maxError < 0.003);
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(GillStepInterpolatorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillStepInterpolatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,263 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+
+public class GraggBulirschStoerIntegratorTest
+  extends TestCase {
+
+  public GraggBulirschStoerIntegratorTest(String name) {
+    super(name);
+  }
+
+  public void testDimensionCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      GraggBulirschStoerIntegrator integrator =
+        new GraggBulirschStoerIntegrator(0.0, 1.0, 1.0e-10, 1.0e-10);
+      integrator.integrate(pb,
+                           0.0, new double[pb.getDimension()+10],
+                           1.0, new double[pb.getDimension()+10]);
+      fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+
+  public void testNullIntervalCheck() {
+    try  {
+      TestProblem1 pb = new TestProblem1();
+      GraggBulirschStoerIntegrator integrator =
+        new GraggBulirschStoerIntegrator(0.0, 1.0, 1.0e-10, 1.0e-10);
+      integrator.integrate(pb,
+                           0.0, new double[pb.getDimension()],
+                           0.0, new double[pb.getDimension()]);
+      fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+  }
+
+  public void testMinStep()
+    throws DerivativeException, IntegratorException {
+
+    try {
+      TestProblem1 pb  = new TestProblem1();
+      double minStep   = 0.1 * (pb.getFinalTime() - pb.getInitialTime());
+      double maxStep   = pb.getFinalTime() - pb.getInitialTime();
+      double absTolerance = 1.0e-20;
+      double relTolerance = 1.0e-20;
+
+      FirstOrderIntegrator integ =
+        new GraggBulirschStoerIntegrator(minStep, maxStep,
+                                         absTolerance, relTolerance);
+      TestProblemHandler handler = new TestProblemHandler(pb);
+      integ.setStepHandler(handler);
+      integ.integrate(pb,
+                      pb.getInitialTime(), pb.getInitialState(),
+                      pb.getFinalTime(), new double[pb.getDimension()]);
+      fail("an exception should have been thrown");
+    } catch(DerivativeException de) {
+      fail("wrong exception caught");
+    } catch(IntegratorException ie) {
+    }
+
+  }
+
+  public void testIncreasingTolerance()
+    throws DerivativeException, IntegratorException {
+
+    int previousCalls = Integer.MAX_VALUE;
+    for (int i = -12; i < -4; ++i) {
+      TestProblem1 pb     = new TestProblem1();
+      double minStep      = 0;
+      double maxStep      = pb.getFinalTime() - pb.getInitialTime();
+      double absTolerance = Math.pow(10.0, i);
+      double relTolerance = absTolerance;
+
+      FirstOrderIntegrator integ =
+        new GraggBulirschStoerIntegrator(minStep, maxStep,
+                                         absTolerance, relTolerance);
+      TestProblemHandler handler = new TestProblemHandler(pb);
+      integ.setStepHandler(handler);
+      integ.integrate(pb,
+                      pb.getInitialTime(), pb.getInitialState(),
+                      pb.getFinalTime(), new double[pb.getDimension()]);
+
+      // 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;
+      assertTrue(ratio < 2.4);
+      assertTrue(ratio > 0.02);
+
+      int calls = pb.getCalls();
+      assertTrue(calls <= previousCalls);
+      previousCalls = calls;
+
+    }
+
+  }
+
+  public void testSwitchingFunctions()
+    throws DerivativeException, IntegratorException {
+
+    TestProblem4 pb = new TestProblem4();
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-10;
+    double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+    FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep,
+                                                                  scalAbsoluteTolerance,
+                                                                  scalRelativeTolerance);
+    TestProblemHandler handler = new TestProblemHandler(pb);
+    integ.setStepHandler(handler);
+    SwitchingFunction[] functions = pb.getSwitchingFunctions();
+    if (functions != null) {
+      for (int l = 0; l < functions.length; ++l) {
+        integ.addSwitchingFunction(functions[l],
+                                   Double.POSITIVE_INFINITY, 1.0e-8 * maxStep);
+      }
+    }
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    assertTrue(handler.getMaximalError() < 5.0e-8);
+    assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
+
+  }
+
+  public void testKepler()
+    throws DerivativeException, IntegratorException {
+
+    final TestProblem3 pb = new TestProblem3(0.9);
+    double minStep        = 0;
+    double maxStep        = pb.getFinalTime() - pb.getInitialTime();
+    double absTolerance   = 1.0e-6;
+    double relTolerance   = 1.0e-6;
+
+    FirstOrderIntegrator integ =
+      new GraggBulirschStoerIntegrator(minStep, maxStep,
+                                       absTolerance, relTolerance);
+    integ.setStepHandler(new StepHandler() {
+                      private int nbSteps = 0;
+                      private double maxError = 0;
+                      public boolean requiresDenseOutput() {
+                        return true;
+                      }
+                      public void reset() {
+                        nbSteps = 0;
+                        maxError = 0;
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast)
+                        throws DerivativeException {
+
+                        ++nbSteps;
+                        for (int a = 1; a < 100; ++a) {
+
+                          double prev   = interpolator.getPreviousTime();
+                          double curr   = interpolator.getCurrentTime();
+                          double interp = ((100 - a) * prev + a * curr) / 100;
+                          interpolator.setInterpolatedTime(interp);
+
+                          double[] interpolatedY = interpolator.getInterpolatedState ();
+                          double[] theoreticalY  = pb.computeTheoreticalState(interpolator.getInterpolatedTime());
+                          double dx = interpolatedY[0] - theoreticalY[0];
+                          double dy = interpolatedY[1] - theoreticalY[1];
+                          double error = dx * dx + dy * dy;
+                          if (error > maxError) {
+                            maxError = error;
+                          }
+                        }
+                        if (isLast) {
+                          assertTrue(maxError < 2.7e-6);
+                          assertTrue(nbSteps < 80);
+                        }
+                      }
+      });
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    assertTrue(pb.getCalls() < 2150);
+
+  }
+
+  public void testVariableSteps()
+    throws DerivativeException, IntegratorException {
+
+    final TestProblem3 pb = new TestProblem3(0.9);
+    double minStep        = 0;
+    double maxStep        = pb.getFinalTime() - pb.getInitialTime();
+    double absTolerance   = 1.0e-8;
+    double relTolerance   = 1.0e-8;
+    FirstOrderIntegrator integ =
+      new GraggBulirschStoerIntegrator(minStep, maxStep,
+                                       absTolerance, relTolerance);
+    integ.setStepHandler(new StepHandler() {
+                      private boolean firstTime = true;
+                      private double  minStep = 0;
+                      private double  maxStep = 0;
+                      public boolean requiresDenseOutput() {
+                        return false;
+                      }
+                      public void reset() {
+                        firstTime = true;
+                        minStep = 0;
+                        maxStep = 0;
+                      }
+                      public void handleStep(StepInterpolator interpolator,
+                                             boolean isLast) {
+
+                        double step = Math.abs(interpolator.getCurrentTime()
+                                               - interpolator.getPreviousTime());
+                        if (firstTime) {
+                          minStep   = Math.abs(step);
+                          maxStep   = minStep;
+                          firstTime = false;
+                        } else {
+                          if (step < minStep) {
+                            minStep = step;
+                          }
+                          if (step > maxStep) {
+                            maxStep = step;
+                          }
+                        }
+
+                        if (isLast) {
+                          assertTrue(minStep < 8.2e-3);
+                          assertTrue(maxStep > 1.7);
+                        }
+                      }
+      });
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+  }
+
+  public static Test suite() {
+    return new TestSuite(GraggBulirschStoerIntegratorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerStepInterpolatorTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerStepInterpolatorTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerStepInterpolatorTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.ode;
+
+import junit.framework.*;
+import java.util.Random;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.IOException;
+
+public class GraggBulirschStoerStepInterpolatorTest
+  extends TestCase {
+
+  public GraggBulirschStoerStepInterpolatorTest(String name) {
+    super(name);
+  }
+
+  public void testSerialization()
+    throws DerivativeException, IntegratorException,
+           IOException, ClassNotFoundException {
+
+    TestProblem3 pb  = new TestProblem3(0.9);
+    double minStep   = 0;
+    double maxStep   = pb.getFinalTime() - pb.getInitialTime();
+    double absTolerance = 1.0e-8;
+    double relTolerance = 1.0e-8;
+
+    GraggBulirschStoerIntegrator integ =
+      new GraggBulirschStoerIntegrator(minStep, maxStep,
+                                       absTolerance, relTolerance);
+    integ.setStepHandler(new ContinuousOutputModel());
+    integ.integrate(pb,
+                    pb.getInitialTime(), pb.getInitialState(),
+                    pb.getFinalTime(), new double[pb.getDimension()]);
+
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    ObjectOutputStream    oos = new ObjectOutputStream(bos);
+    oos.writeObject(integ.getStepHandler());
+
+    assertTrue(bos.size () > 34000);
+    assertTrue(bos.size () < 35000);
+
+    ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
+    ObjectInputStream     ois = new ObjectInputStream(bis);
+    ContinuousOutputModel cm  = (ContinuousOutputModel) ois.readObject();
+
+    Random random = new Random(347588535632l);
+    double maxError = 0.0;
+    for (int i = 0; i < 1000; ++i) {
+      double r = random.nextDouble();
+      double time = r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
+      cm.setInterpolatedTime(time);
+      double[] interpolatedY = cm.getInterpolatedState ();
+      double[] theoreticalY  = pb.computeTheoreticalState(time);
+      double dx = interpolatedY[0] - theoreticalY[0];
+      double dy = interpolatedY[1] - theoreticalY[1];
+      double error = dx * dx + dy * dy;
+      if (error > maxError) {
+        maxError = error;
+      }
+    }
+
+    assertTrue(maxError < 5.0e-11);
+
+  }
+
+  public static Test suite() {
+    return new TestSuite(GraggBulirschStoerStepInterpolatorTest.class);
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerStepInterpolatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message