improved tests coverage

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@591662 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2007-11-03 18:47:17 +00:00
parent 2071918a7a
commit af62f7927f
10 changed files with 113 additions and 64 deletions

View File

@ -81,7 +81,7 @@ public class ClassicalRungeKuttaIntegratorTest
* Math.pow(2.0, -i); * Math.pow(2.0, -i);
FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -91,11 +91,12 @@ public class ClassicalRungeKuttaIntegratorTest
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
double error = handler.getMaximalError(); double error = handler.getMaximalValueError();
if (i > 4) { if (i > 4) {
assertTrue(error < Math.abs(previousError)); assertTrue(error < Math.abs(previousError));
} }
previousError = error; previousError = error;
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }
} }
@ -109,13 +110,14 @@ public class ClassicalRungeKuttaIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() < 2.0e-13); assertTrue(handler.getLastError() < 2.0e-13);
assertTrue(handler.getMaximalError() < 4.0e-12); assertTrue(handler.getMaximalValueError() < 4.0e-12);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals("classical Runge-Kutta", integ.getName()); assertEquals("classical Runge-Kutta", integ.getName());
} }
@ -126,13 +128,14 @@ public class ClassicalRungeKuttaIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step); FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() > 0.0004); assertTrue(handler.getLastError() > 0.0004);
assertTrue(handler.getMaximalError() > 0.005); assertTrue(handler.getMaximalValueError() > 0.005);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }

View File

@ -63,7 +63,7 @@ public class DormandPrince54IntegratorTest
FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep, FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
vecAbsoluteTolerance, vecAbsoluteTolerance,
vecRelativeTolerance); vecRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
@ -146,7 +146,7 @@ public class DormandPrince54IntegratorTest
RungeKuttaFehlbergIntegrator integ = RungeKuttaFehlbergIntegrator integ =
new DormandPrince54Integrator(minStep, maxStep, new DormandPrince54Integrator(minStep, maxStep,
scalAbsoluteTolerance, scalRelativeTolerance); scalAbsoluteTolerance, scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setSafety(0.8); integ.setSafety(0.8);
integ.setMaxGrowth(5.0); integ.setMaxGrowth(5.0);
integ.setMinReduction(0.3); integ.setMinReduction(0.3);
@ -161,7 +161,8 @@ public class DormandPrince54IntegratorTest
// the 0.7 factor is only valid for this test // the 0.7 factor is only valid for this test
// and has been obtained from trial and error // and has been obtained from trial and error
// there is no general relation between local and global errors // there is no general relation between local and global errors
assertTrue(handler.getMaximalError() < (0.7 * scalAbsoluteTolerance)); assertTrue(handler.getMaximalValueError() < (0.7 * scalAbsoluteTolerance));
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
int calls = pb.getCalls(); int calls = pb.getCalls();
assertTrue(calls <= previousCalls); assertTrue(calls <= previousCalls);
@ -183,7 +184,7 @@ public class DormandPrince54IntegratorTest
FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep, FirstOrderIntegrator integ = new DormandPrince54Integrator(minStep, maxStep,
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -194,7 +195,8 @@ public class DormandPrince54IntegratorTest
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getMaximalError() < 5.0e-6); assertTrue(handler.getMaximalValueError() < 5.0e-6);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep); assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
} }

View File

@ -78,7 +78,7 @@ public class DormandPrince853IntegratorTest
FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep, FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
vecAbsoluteTolerance, vecAbsoluteTolerance,
vecRelativeTolerance); vecRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
@ -105,7 +105,7 @@ public class DormandPrince853IntegratorTest
FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep, FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
@ -114,7 +114,8 @@ public class DormandPrince853IntegratorTest
// the 1.3 factor is only valid for this test // the 1.3 factor is only valid for this test
// and has been obtained from trial and error // and has been obtained from trial and error
// there is no general relation between local and global errors // there is no general relation between local and global errors
assertTrue(handler.getMaximalError() < (1.3 * scalAbsoluteTolerance)); assertTrue(handler.getMaximalValueError() < (1.3 * scalAbsoluteTolerance));
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
int calls = pb.getCalls(); int calls = pb.getCalls();
assertTrue(calls <= previousCalls); assertTrue(calls <= previousCalls);
@ -136,7 +137,7 @@ public class DormandPrince853IntegratorTest
FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep, FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep,
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -147,7 +148,8 @@ public class DormandPrince853IntegratorTest
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getMaximalError() < 5.0e-8); assertTrue(handler.getMaximalValueError() < 5.0e-8);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep); assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
} }

View File

@ -59,7 +59,7 @@ public class EulerIntegratorTest
* Math.pow(2.0, -i); * Math.pow(2.0, -i);
FirstOrderIntegrator integ = new EulerIntegrator(step); FirstOrderIntegrator integ = new EulerIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -70,11 +70,12 @@ public class EulerIntegratorTest
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
double error = handler.getMaximalError(); double error = handler.getMaximalValueError();
if (i > 4) { if (i > 4) {
assertTrue(error < Math.abs(previousError)); assertTrue(error < Math.abs(previousError));
} }
previousError = error; previousError = error;
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }
@ -89,14 +90,15 @@ public class EulerIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
FirstOrderIntegrator integ = new EulerIntegrator(step); FirstOrderIntegrator integ = new EulerIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() < 2.0e-4); assertTrue(handler.getLastError() < 2.0e-4);
assertTrue(handler.getMaximalError() < 1.0e-3); assertTrue(handler.getMaximalValueError() < 1.0e-3);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals("Euler", integ.getName()); assertEquals("Euler", integ.getName());
} }
@ -108,14 +110,15 @@ public class EulerIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
FirstOrderIntegrator integ = new EulerIntegrator(step); FirstOrderIntegrator integ = new EulerIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() > 0.01); assertTrue(handler.getLastError() > 0.01);
assertTrue(handler.getMaximalError() > 0.2); assertTrue(handler.getMaximalValueError() > 0.2);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }

View File

@ -61,7 +61,7 @@ public class GillIntegratorTest
* Math.pow(2.0, -i); * Math.pow(2.0, -i);
FirstOrderIntegrator integ = new GillIntegrator(step); FirstOrderIntegrator integ = new GillIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -71,11 +71,13 @@ public class GillIntegratorTest
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
double error = handler.getMaximalError(); double error = handler.getMaximalValueError();
if (i > 5) { if (i > 5) {
assertTrue(error < Math.abs(previousError)); assertTrue(error < Math.abs(previousError));
} }
previousError = error; previousError = error;
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }
} }
@ -89,13 +91,14 @@ public class GillIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
FirstOrderIntegrator integ = new GillIntegrator(step); FirstOrderIntegrator integ = new GillIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() < 2.0e-13); assertTrue(handler.getLastError() < 2.0e-13);
assertTrue(handler.getMaximalError() < 4.0e-12); assertTrue(handler.getMaximalValueError() < 4.0e-12);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals("Gill", integ.getName()); assertEquals("Gill", integ.getName());
} }
@ -107,13 +110,14 @@ public class GillIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
FirstOrderIntegrator integ = new GillIntegrator(step); FirstOrderIntegrator integ = new GillIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() > 0.0004); assertTrue(handler.getLastError() > 0.0004);
assertTrue(handler.getMaximalError() > 0.005); assertTrue(handler.getMaximalValueError() > 0.005);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }

View File

@ -77,7 +77,7 @@ public class GraggBulirschStoerIntegratorTest
FirstOrderIntegrator integ = FirstOrderIntegrator integ =
new GraggBulirschStoerIntegrator(minStep, maxStep, new GraggBulirschStoerIntegrator(minStep, maxStep,
vecAbsoluteTolerance, vecRelativeTolerance); vecAbsoluteTolerance, vecRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
@ -104,7 +104,7 @@ public class GraggBulirschStoerIntegratorTest
FirstOrderIntegrator integ = FirstOrderIntegrator integ =
new GraggBulirschStoerIntegrator(minStep, maxStep, new GraggBulirschStoerIntegrator(minStep, maxStep,
absTolerance, relTolerance); absTolerance, relTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
@ -113,9 +113,10 @@ public class GraggBulirschStoerIntegratorTest
// the coefficients are only valid for this test // the coefficients are only valid for this test
// and have been obtained from trial and error // and have been obtained from trial and error
// there is no general relation between local and global errors // there is no general relation between local and global errors
double ratio = handler.getMaximalError() / absTolerance; double ratio = handler.getMaximalValueError() / absTolerance;
assertTrue(ratio < 2.4); assertTrue(ratio < 2.4);
assertTrue(ratio > 0.02); assertTrue(ratio > 0.02);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
int calls = pb.getCalls(); int calls = pb.getCalls();
assertTrue(calls <= previousCalls); assertTrue(calls <= previousCalls);
@ -156,12 +157,12 @@ public class GraggBulirschStoerIntegratorTest
private double getMaxError(FirstOrderIntegrator integrator, TestProblemAbstract pb) private double getMaxError(FirstOrderIntegrator integrator, TestProblemAbstract pb)
throws DerivativeException, IntegratorException { throws DerivativeException, IntegratorException {
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integrator);
integrator.setStepHandler(handler); integrator.setStepHandler(handler);
integrator.integrate(pb, integrator.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
return handler.getMaximalError(); return handler.getMaximalValueError();
} }
public void testSwitchingFunctions() public void testSwitchingFunctions()
@ -176,7 +177,7 @@ public class GraggBulirschStoerIntegratorTest
FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep, FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep,
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -187,7 +188,8 @@ public class GraggBulirschStoerIntegratorTest
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getMaximalError() < 5.0e-8); assertTrue(handler.getMaximalValueError() < 5.0e-8);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep); assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
} }

View File

@ -85,7 +85,7 @@ public class HighamHall54IntegratorTest
FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep, FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
vecAbsoluteTolerance, vecAbsoluteTolerance,
vecRelativeTolerance); vecRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
@ -112,7 +112,7 @@ public class HighamHall54IntegratorTest
FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep, FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
@ -121,7 +121,8 @@ public class HighamHall54IntegratorTest
// the 1.3 factor is only valid for this test // the 1.3 factor is only valid for this test
// and has been obtained from trial and error // and has been obtained from trial and error
// there is no general relation between local and global errors // there is no general relation between local and global errors
assertTrue(handler.getMaximalError() < (1.3 * scalAbsoluteTolerance)); assertTrue(handler.getMaximalValueError() < (1.3 * scalAbsoluteTolerance));
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
int calls = pb.getCalls(); int calls = pb.getCalls();
assertTrue(calls <= previousCalls); assertTrue(calls <= previousCalls);
@ -143,7 +144,7 @@ public class HighamHall54IntegratorTest
FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep, FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
scalAbsoluteTolerance, scalAbsoluteTolerance,
scalRelativeTolerance); scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -154,7 +155,8 @@ public class HighamHall54IntegratorTest
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getMaximalError() < 1.0e-7); assertTrue(handler.getMaximalValueError() < 1.0e-7);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep); assertEquals(12.0, handler.getLastTime(), 1.0e-8 * maxStep);
} }

View File

@ -58,7 +58,7 @@ public class MidpointIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -i); * Math.pow(2.0, -i);
FirstOrderIntegrator integ = new MidpointIntegrator(step); FirstOrderIntegrator integ = new MidpointIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -69,11 +69,13 @@ public class MidpointIntegratorTest
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
double error = handler.getMaximalError(); double error = handler.getMaximalValueError();
if (i > 4) { if (i > 4) {
assertTrue(error < Math.abs(previousError)); assertTrue(error < Math.abs(previousError));
} }
previousError = error; previousError = error;
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }
} }
@ -87,14 +89,15 @@ public class MidpointIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
FirstOrderIntegrator integ = new MidpointIntegrator(step); FirstOrderIntegrator integ = new MidpointIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() < 2.0e-7); assertTrue(handler.getLastError() < 2.0e-7);
assertTrue(handler.getMaximalError() < 1.0e-6); assertTrue(handler.getMaximalValueError() < 1.0e-6);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals("midpoint", integ.getName()); assertEquals("midpoint", integ.getName());
} }
@ -106,14 +109,15 @@ public class MidpointIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
FirstOrderIntegrator integ = new MidpointIntegrator(step); FirstOrderIntegrator integ = new MidpointIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(), pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() > 0.01); assertTrue(handler.getLastError() > 0.01);
assertTrue(handler.getMaximalError() > 0.05); assertTrue(handler.getMaximalValueError() > 0.05);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }

View File

@ -31,8 +31,9 @@ class TestProblemHandler
/** Associated problem. */ /** Associated problem. */
private TestProblemAbstract problem; private TestProblemAbstract problem;
/** Maximal error encountered during the integration. */ /** Maximal errors encountered during the integration. */
private double maxError; private double maxValueError;
private double maxTimeError;
/** Error at the end of the integration. */ /** Error at the end of the integration. */
private double lastError; private double lastError;
@ -40,12 +41,20 @@ class TestProblemHandler
/** Time at the end of integration. */ /** Time at the end of integration. */
private double lastTime; private double lastTime;
/** ODE solver used. */
private FirstOrderIntegrator integrator;
/** Expected start for step. */
private double expectedStepStart;
/** /**
* Simple constructor. * Simple constructor.
* @param problem problem for which steps should be handled * @param problem problem for which steps should be handled
* @param integrator ODE solver used
*/ */
public TestProblemHandler(TestProblemAbstract problem) { public TestProblemHandler(TestProblemAbstract problem, FirstOrderIntegrator integrator) {
this.problem = problem; this.problem = problem;
this.integrator = integrator;
reset(); reset();
} }
@ -54,14 +63,20 @@ class TestProblemHandler
} }
public void reset() { public void reset() {
maxError = 0; maxValueError = 0;
lastError = 0; maxTimeError = 0;
lastError = 0;
expectedStepStart = problem.getInitialTime();
} }
public void handleStep(StepInterpolator interpolator, public void handleStep(StepInterpolator interpolator,
boolean isLast) boolean isLast)
throws DerivativeException { throws DerivativeException {
double start = integrator.getCurrentStepStart();
maxTimeError = Math.max(maxTimeError, Math.abs(start - expectedStepStart));
expectedStepStart = start + integrator.getCurrentSignedStepsize();
double pT = interpolator.getPreviousTime(); double pT = interpolator.getPreviousTime();
double cT = interpolator.getCurrentTime(); double cT = interpolator.getCurrentTime();
double[] errorScale = problem.getErrorScale(); double[] errorScale = problem.getErrorScale();
@ -90,8 +105,8 @@ class TestProblemHandler
// update the errors // update the errors
for (int i = 0; i < interpolatedY.length; ++i) { for (int i = 0; i < interpolatedY.length; ++i) {
double error = errorScale[i] * Math.abs(interpolatedY[i] - theoreticalY[i]); double error = errorScale[i] * Math.abs(interpolatedY[i] - theoreticalY[i]);
if (error > maxError) { if (error > maxValueError) {
maxError = error; maxValueError = error;
} }
} }
@ -99,11 +114,19 @@ class TestProblemHandler
} }
/** /**
* Get the maximal error encountered during integration. * Get the maximal value error encountered during integration.
* @return maximal error * @return maximal value error
*/ */
public double getMaximalError() { public double getMaximalValueError() {
return maxError; return maxValueError;
}
/**
* Get the maximal time error encountered during integration.
* @return maximal time error
*/
public double getMaximalTimeError() {
return maxTimeError;
} }
/** /**

View File

@ -61,7 +61,7 @@ public class ThreeEighthesIntegratorTest
* Math.pow(2.0, -i); * Math.pow(2.0, -i);
FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step); FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions(); SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) { for (int l = 0; l < functions.length; ++l) {
@ -71,11 +71,13 @@ public class ThreeEighthesIntegratorTest
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
double error = handler.getMaximalError(); double error = handler.getMaximalValueError();
if (i > 4) { if (i > 4) {
assertTrue(error < Math.abs(previousError)); assertTrue(error < Math.abs(previousError));
} }
previousError = error; previousError = error;
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }
} }
@ -89,13 +91,14 @@ public class ThreeEighthesIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;
FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step); FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() < 2.0e-13); assertTrue(handler.getLastError() < 2.0e-13);
assertTrue(handler.getMaximalError() < 4.0e-12); assertTrue(handler.getMaximalValueError() < 4.0e-12);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
assertEquals("3/8", integ.getName()); assertEquals("3/8", integ.getName());
} }
@ -107,13 +110,14 @@ public class ThreeEighthesIntegratorTest
double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2; double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;
FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step); FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb); TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.setStepHandler(handler); integ.setStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]); pb.getFinalTime(), new double[pb.getDimension()]);
assertTrue(handler.getLastError() > 0.0004); assertTrue(handler.getLastError() > 0.0004);
assertTrue(handler.getMaximalError() > 0.005); assertTrue(handler.getMaximalValueError() > 0.005);
assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
} }