Added tests with DerivativeStructure field.

This commit is contained in:
Luc Maisonobe 2016-01-06 13:30:34 +01:00
parent 1d4d89e9fb
commit a2efc6b6b9
11 changed files with 417 additions and 99 deletions

View File

@ -20,6 +20,7 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.MaxCountExceededException;
import org.apache.commons.math4.exception.NoBracketingException;
@ -456,4 +457,144 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
}
}
@Test
public abstract void testPartialDerivatives();
protected <T extends RealFieldElement<T>> void doTestPartialDerivatives(final double epsilonY,
final double[] epsilonPartials) {
// parameters indices
final int parameters = 5;
final int order = 1;
final int parOmega = 0;
final int parTO = 1;
final int parY00 = 2;
final int parY01 = 3;
final int parT = 4;
DerivativeStructure omega = new DerivativeStructure(parameters, order, parOmega, 1.3);
DerivativeStructure t0 = new DerivativeStructure(parameters, order, parTO, 1.3);
DerivativeStructure[] y0 = new DerivativeStructure[] {
new DerivativeStructure(parameters, order, parY00, 3.0),
new DerivativeStructure(parameters, order, parY01, 4.0)
};
DerivativeStructure t = new DerivativeStructure(parameters, order, parT, 6.0);
SinCos sinCos = new SinCos(omega);
EmbeddedRungeKuttaFieldIntegrator<DerivativeStructure> integrator =
createIntegrator(omega.getField(),
t.subtract(t0).multiply(0.001).getReal(), t.subtract(t0).getReal(),
1.0e-12, 1.0e-12);
FieldODEStateAndDerivative<DerivativeStructure> result =
integrator.integrate(new FieldExpandableODE<DerivativeStructure>(sinCos),
new FieldODEState<DerivativeStructure>(t0, y0),
t);
// check values
for (int i = 0; i < sinCos.getDimension(); ++i) {
Assert.assertEquals(sinCos.theoreticalY(t.getReal())[i], result.getState()[i].getValue(), epsilonY);
}
// check derivatives
final double[][] derivatives = sinCos.getDerivatives(t.getReal());
for (int i = 0; i < sinCos.getDimension(); ++i) {
for (int parameter = 0; parameter < parameters; ++parameter) {
Assert.assertEquals(derivatives[i][parameter], dYdP(result.getState()[i], parameter), epsilonPartials[parameter]);
}
}
}
private double dYdP(final DerivativeStructure y, final int parameter) {
int[] orders = new int[y.getFreeParameters()];
orders[parameter] = 1;
return y.getPartialDerivative(orders);
}
private static class SinCos implements FieldFirstOrderDifferentialEquations<DerivativeStructure> {
private final DerivativeStructure omega;
private DerivativeStructure r;
private DerivativeStructure alpha;
private double dRdY00;
private double dRdY01;
private double dAlphadOmega;
private double dAlphadT0;
private double dAlphadY00;
private double dAlphadY01;
protected SinCos(final DerivativeStructure omega) {
this.omega = omega;
}
public int getDimension() {
return 2;
}
public void init(final DerivativeStructure t0, final DerivativeStructure[] y0,
final DerivativeStructure finalTime) {
// theoretical solution is y(t) = { r * sin(omega * t + alpha), r * cos(omega * t + alpha) }
// so we retrieve alpha by identification from the initial state
final DerivativeStructure r2 = y0[0].multiply(y0[0]).add(y0[1].multiply(y0[1]));
this.r = r2.sqrt();
this.dRdY00 = y0[0].divide(r).getReal();
this.dRdY01 = y0[1].divide(r).getReal();
this.alpha = y0[0].atan2(y0[1]).subtract(t0.multiply(omega));
this.dAlphadOmega = -t0.getReal();
this.dAlphadT0 = -omega.getReal();
this.dAlphadY00 = y0[1].divide(r2).getReal();
this.dAlphadY01 = y0[0].negate().divide(r2).getReal();
}
public DerivativeStructure[] computeDerivatives(final DerivativeStructure t, final DerivativeStructure[] y) {
return new DerivativeStructure[] {
omega.multiply(y[1]),
omega.multiply(y[0]).negate()
};
}
public double[] theoreticalY(final double t) {
final double theta = omega.getReal() * t + alpha.getReal();
return new double[] {
r.getReal() * FastMath.sin(theta), r.getReal() * FastMath.cos(theta)
};
}
public double[][] getDerivatives(final double t) {
// intermediate angle and state
final double theta = omega.getReal() * t + alpha.getReal();
final double sin = FastMath.sin(theta);
final double cos = FastMath.cos(theta);
final double y0 = r.getReal() * sin;
final double y1 = r.getReal() * cos;
// partial derivatives of the state first component
final double dY0dOmega = y1 * (t + dAlphadOmega);
final double dY0dT0 = y1 * dAlphadT0;
final double dY0dY00 = dRdY00 * sin + y1 * dAlphadY00;
final double dY0dY01 = dRdY01 * sin + y1 * dAlphadY01;
final double dY0dT = y1 * omega.getReal();
// partial derivatives of the state second component
final double dY1dOmega = - y0 * (t + dAlphadOmega);
final double dY1dT0 = - y0 * dAlphadT0;
final double dY1dY00 = dRdY00 * cos - y0 * dAlphadY00;
final double dY1dY01 = dRdY01 * cos - y0 * dAlphadY01;
final double dY1dT = - y0 * omega.getReal();
return new double[][] {
{ dY0dOmega, dY0dT0, dY0dY00, dY0dY01, dY0dT },
{ dY1dOmega, dY1dT0, dY1dY00, dY1dY01, dY1dT }
};
}
}
}

View File

@ -22,6 +22,7 @@ import java.lang.reflect.Array;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
import org.apache.commons.math4.exception.DimensionMismatchException;
import org.apache.commons.math4.exception.MaxCountExceededException;
import org.apache.commons.math4.exception.NoBracketingException;
@ -518,4 +519,144 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
StepInterpolatorTestUtils.checkDerivativesConsistency(integ, pb, 1.0e-10);
}
@Test
public abstract void testPartialDerivatives();
protected <T extends RealFieldElement<T>> void doTestPartialDerivatives(final double epsilonY,
final double[] epsilonPartials) {
// parameters indices
final int parameters = 5;
final int order = 1;
final int parOmega = 0;
final int parTO = 1;
final int parY00 = 2;
final int parY01 = 3;
final int parT = 4;
DerivativeStructure omega = new DerivativeStructure(parameters, order, parOmega, 1.3);
DerivativeStructure t0 = new DerivativeStructure(parameters, order, parTO, 1.3);
DerivativeStructure[] y0 = new DerivativeStructure[] {
new DerivativeStructure(parameters, order, parY00, 3.0),
new DerivativeStructure(parameters, order, parY01, 4.0)
};
DerivativeStructure t = new DerivativeStructure(parameters, order, parT, 6.0);
SinCos sinCos = new SinCos(omega);
RungeKuttaFieldIntegrator<DerivativeStructure> integrator =
createIntegrator(omega.getField(), t.subtract(t0).multiply(0.001));
FieldODEStateAndDerivative<DerivativeStructure> result =
integrator.integrate(new FieldExpandableODE<DerivativeStructure>(sinCos),
new FieldODEState<DerivativeStructure>(t0, y0),
t);
// check values
for (int i = 0; i < sinCos.getDimension(); ++i) {
Assert.assertEquals(sinCos.theoreticalY(t.getReal())[i], result.getState()[i].getValue(), epsilonY);
}
// check derivatives
final double[][] derivatives = sinCos.getDerivatives(t.getReal());
for (int i = 0; i < sinCos.getDimension(); ++i) {
for (int parameter = 0; parameter < parameters; ++parameter) {
Assert.assertEquals(derivatives[i][parameter],
dYdP(result.getState()[i], parameter),
epsilonPartials[parameter]);
}
}
}
private double dYdP(final DerivativeStructure y, final int parameter) {
int[] orders = new int[y.getFreeParameters()];
orders[parameter] = 1;
return y.getPartialDerivative(orders);
}
private static class SinCos implements FieldFirstOrderDifferentialEquations<DerivativeStructure> {
private final DerivativeStructure omega;
private DerivativeStructure r;
private DerivativeStructure alpha;
private double dRdY00;
private double dRdY01;
private double dAlphadOmega;
private double dAlphadT0;
private double dAlphadY00;
private double dAlphadY01;
protected SinCos(final DerivativeStructure omega) {
this.omega = omega;
}
public int getDimension() {
return 2;
}
public void init(final DerivativeStructure t0, final DerivativeStructure[] y0,
final DerivativeStructure finalTime) {
// theoretical solution is y(t) = { r * sin(omega * t + alpha), r * cos(omega * t + alpha) }
// so we retrieve alpha by identification from the initial state
final DerivativeStructure r2 = y0[0].multiply(y0[0]).add(y0[1].multiply(y0[1]));
this.r = r2.sqrt();
this.dRdY00 = y0[0].divide(r).getReal();
this.dRdY01 = y0[1].divide(r).getReal();
this.alpha = y0[0].atan2(y0[1]).subtract(t0.multiply(omega));
this.dAlphadOmega = -t0.getReal();
this.dAlphadT0 = -omega.getReal();
this.dAlphadY00 = y0[1].divide(r2).getReal();
this.dAlphadY01 = y0[0].negate().divide(r2).getReal();
}
public DerivativeStructure[] computeDerivatives(final DerivativeStructure t, final DerivativeStructure[] y) {
return new DerivativeStructure[] {
omega.multiply(y[1]),
omega.multiply(y[0]).negate()
};
}
public double[] theoreticalY(final double t) {
final double theta = omega.getReal() * t + alpha.getReal();
return new double[] {
r.getReal() * FastMath.sin(theta), r.getReal() * FastMath.cos(theta)
};
}
public double[][] getDerivatives(final double t) {
// intermediate angle and state
final double theta = omega.getReal() * t + alpha.getReal();
final double sin = FastMath.sin(theta);
final double cos = FastMath.cos(theta);
final double y0 = r.getReal() * sin;
final double y1 = r.getReal() * cos;
// partial derivatives of the state first component
final double dY0dOmega = y1 * (t + dAlphadOmega);
final double dY0dT0 = y1 * dAlphadT0;
final double dY0dY00 = dRdY00 * sin + y1 * dAlphadY00;
final double dY0dY01 = dRdY01 * sin + y1 * dAlphadY01;
final double dY0dT = y1 * omega.getReal();
// partial derivatives of the state second component
final double dY1dOmega = - y0 * (t + dAlphadOmega);
final double dY1dT0 = - y0 * dAlphadT0;
final double dY1dY00 = dRdY00 * cos - y0 * dAlphadY00;
final double dY1dY01 = dRdY01 * cos - y0 * dAlphadY01;
final double dY1dT = - y0 * omega.getReal();
return new double[][] {
{ dY0dOmega, dY0dT0, dY0dY00, dY0dY01, dY0dT },
{ dY1dOmega, dY1dT0, dY1dY00, dY1dY01, dY1dT }
};
}
}
}

View File

@ -21,7 +21,6 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class ClassicalRungeKuttaFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
@ -30,70 +29,75 @@ public class ClassicalRungeKuttaFieldIntegratorTest extends AbstractRungeKuttaFi
return new ClassicalRungeKuttaFieldIntegrator<T>(field, step);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testMissedEndEvent() {
doTestMissedEndEvent(Decimal64Field.getInstance(), 5.0e-6, 1.0e-9);
}
@Test
@Override
public void testSanityChecks() {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testDecreasingSteps() {
doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
}
@Test
@Override
public void testSmallStep() {
doTestSmallStep(Decimal64Field.getInstance(), 2.0e-13, 4.0e-12, 1.0e-12, "classical Runge-Kutta");
}
@Test
@Override
public void testBigStep() {
doTestBigStep(Decimal64Field.getInstance(), 0.0004, 0.005, 1.0e-12, "classical Runge-Kutta");
}
@Test
@Override
public void testBackward() {
doTestBackward(Decimal64Field.getInstance(), 5.0e-10, 7.0e-10, 1.0e-12, "classical Runge-Kutta");
}
@Test
@Override
public void testKepler() {
doTestKepler(Decimal64Field.getInstance(), 5.82e-3, 1.0e-5);
}
@Test
@Override
public void testStepSize() {
doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testSingleStep() {
doTestSingleStep(Decimal64Field.getInstance(), 9.3e-9);
}
@Test
@Override
public void testTooLargeFirstStep() {
doTestTooLargeFirstStep(Decimal64Field.getInstance());
}
@Test
@Override
public void testUnstableDerivative() {
doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testDerivativesConsistency() {
doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(3.2e-10, new double[] { 2.1e-9, 5.9e-10, 7.0e-11, 7.0e-11, 5.9e-10 });
}
}

View File

@ -21,7 +21,6 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class DormandPrince54FieldIntegratorTest extends AbstractEmbeddedRungeKuttaFieldIntegratorTest {
@ -37,22 +36,22 @@ public class DormandPrince54FieldIntegratorTest extends AbstractEmbeddedRungeKut
return new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testSanityChecks() {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testBackward() {
doTestBackward(Decimal64Field.getInstance(), 1.6e-7, 1.6e-7, 1.0e-22, "Dormand-Prince 5(4)");
}
@Test
@Override
public void testKepler() {
doTestKepler(Decimal64Field.getInstance(), 3.1e-10);
}
@ -90,4 +89,9 @@ public class DormandPrince54FieldIntegratorTest extends AbstractEmbeddedRungeKut
doTestEventsNoConvergence(Decimal64Field.getInstance());
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(4.8e-12, new double[] { 2.3e-11, 6.3e-12, 9.0e-13, 7.4e-13, 6.3e-12 });
}
}

View File

@ -21,7 +21,6 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class DormandPrince853FieldIntegratorTest extends AbstractEmbeddedRungeKuttaFieldIntegratorTest {
@ -37,22 +36,22 @@ public class DormandPrince853FieldIntegratorTest extends AbstractEmbeddedRungeKu
return new DormandPrince853FieldIntegrator<T>(field, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testSanityChecks() {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testBackward() {
doTestBackward(Decimal64Field.getInstance(), 8.1e-8, 1.1e-7, 1.0e-12, "Dormand-Prince 8 (5, 3)");
}
@Test
@Override
public void testKepler() {
doTestKepler(Decimal64Field.getInstance(), 4.4e-11);
}
@ -90,4 +89,9 @@ public class DormandPrince853FieldIntegratorTest extends AbstractEmbeddedRungeKu
doTestEventsNoConvergence(Decimal64Field.getInstance());
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(2.6e-12, new double[] { 1.3e-11, 3.6e-12, 5.2e-13, 3.6e-12, 3.6e-12 });
}
}

View File

@ -21,7 +21,6 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class EulerFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
@ -30,71 +29,76 @@ public class EulerFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorT
return new EulerFieldIntegrator<T>(field, step);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testMissedEndEvent() {
doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 6.0e-5);
}
@Test
@Override
public void testSanityChecks() {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testDecreasingSteps() {
doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.5, 1.0e-10);
}
@Test
@Override
public void testSmallStep() {
doTestSmallStep(Decimal64Field.getInstance(), 2.0e-4, 1.0e-3, 1.0e-12, "Euler");
}
@Test
@Override
public void testBigStep() {
doTestBigStep(Decimal64Field.getInstance(), 0.01, 0.2, 1.0e-12, "Euler");
}
@Test
@Override
public void testBackward() {
doTestBackward(Decimal64Field.getInstance(),0.45, 0.45, 1.0e-12, "Euler");
}
@Test
@Override
public void testKepler() {
// Euler integrator is clearly not able to solve this problem
doTestKepler(Decimal64Field.getInstance(), 881.176, 0.001);
}
@Test
@Override
public void testStepSize() {
doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testSingleStep() {
doTestSingleStep(Decimal64Field.getInstance(), 0.21);
}
@Test
@Override
public void testTooLargeFirstStep() {
doTestTooLargeFirstStep(Decimal64Field.getInstance());
}
@Test
@Override
public void testUnstableDerivative() {
doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testDerivativesConsistency() {
doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(0.085, new double[] { 0.47, 0.13, 0.019, 0.019, 0.13 });
}
}

View File

@ -21,7 +21,6 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class GillFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
@ -30,70 +29,75 @@ public class GillFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTe
return new GillFieldIntegrator<T>(field, step);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testMissedEndEvent() {
doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 6.0e-5);
}
@Test
@Override
public void testSanityChecks() {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testDecreasingSteps() {
doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
}
@Test
@Override
public void testSmallStep() {
doTestSmallStep(Decimal64Field.getInstance(), 2.0e-13, 4.0e-12, 1.0e-12, "Gill");
}
@Test
@Override
public void testBigStep() {
doTestBigStep(Decimal64Field.getInstance(), 0.0004, 0.005, 1.0e-12, "Gill");
}
@Test
@Override
public void testBackward() {
doTestBackward(Decimal64Field.getInstance(), 5.0e-10, 7.0e-10, 1.0e-12, "Gill");
}
@Test
@Override
public void testKepler() {
doTestKepler(Decimal64Field.getInstance(), 1.72e-3, 1.0e-5);
}
@Test
@Override
public void testStepSize() {
doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testSingleStep() {
doTestSingleStep(Decimal64Field.getInstance(), 0.21);
}
@Test
@Override
public void testTooLargeFirstStep() {
doTestTooLargeFirstStep(Decimal64Field.getInstance());
}
@Test
@Override
public void testUnstableDerivative() {
doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testDerivativesConsistency() {
doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(3.2e-10, new double[] { 2.1e-9, 5.9e-10, 7.0e-11, 7.0e-11, 5.9e-10 });
}
}

View File

@ -21,7 +21,6 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class HighamHall54FieldIntegratorTest extends AbstractEmbeddedRungeKuttaFieldIntegratorTest {
@ -37,22 +36,22 @@ public class HighamHall54FieldIntegratorTest extends AbstractEmbeddedRungeKuttaF
return new HighamHall54FieldIntegrator<T>(field, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testSanityChecks() {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testBackward() {
doTestBackward(Decimal64Field.getInstance(), 5.0e-7, 5.0e-7, 1.0e-12, "Higham-Hall 5(4)");
}
@Test
@Override
public void testKepler() {
doTestKepler(Decimal64Field.getInstance(), 1.5e-4);
}
@ -90,4 +89,9 @@ public class HighamHall54FieldIntegratorTest extends AbstractEmbeddedRungeKuttaF
doTestEventsNoConvergence(Decimal64Field.getInstance());
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(1.2e-11, new double[] { 6.4e-11, 1.8e-11, 2.4e-12, 2.2e-12, 1.8e-11 });
}
}

View File

@ -25,7 +25,6 @@ import org.apache.commons.math4.exception.MaxCountExceededException;
import org.apache.commons.math4.exception.NoBracketingException;
import org.apache.commons.math4.exception.NumberIsTooSmallException;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class LutherFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
@ -34,85 +33,90 @@ public class LutherFieldIntegratorTest extends AbstractRungeKuttaFieldIntegrator
return new LutherFieldIntegrator<T>(field, step);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testMissedEndEvent()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 1.0e-15);
}
@Test
@Override
public void testSanityChecks()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testDecreasingSteps()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
}
@Test
@Override
public void testSmallStep()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
doTestSmallStep(Decimal64Field.getInstance(), 8.7e-17, 3.6e-15, 1.0e-12, "Luther");
}
@Test
@Override
public void testBigStep()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
doTestBigStep(Decimal64Field.getInstance(), 2.7e-5, 1.7e-3, 1.0e-12, "Luther");
}
@Test
@Override
public void testBackward()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
doTestBackward(Decimal64Field.getInstance(), 2.4e-13, 4.3e-13, 1.0e-12, "Luther");
}
@Test
@Override
public void testKepler()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
doTestKepler(Decimal64Field.getInstance(), 2.18e-7, 4.0e-10);
}
@Test
@Override
public void testStepSize()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
doTestStepSize(Decimal64Field.getInstance(), 1.0e-22);
}
@Test
@Override
public void testSingleStep() {
doTestSingleStep(Decimal64Field.getInstance(), 6.0e-12);
}
@Test
@Override
public void testTooLargeFirstStep() {
doTestTooLargeFirstStep(Decimal64Field.getInstance());
}
@Test
@Override
public void testUnstableDerivative() {
doTestUnstableDerivative(Decimal64Field.getInstance(), 4.0e-15);
}
@Test
@Override
public void testDerivativesConsistency() {
doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-20);
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(4.3e-13, new double[] { 2.2e-12, 5.6e-13, 9.4e-14, 9.4e-14, 5.6e-13 });
}
}

View File

@ -21,7 +21,6 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class MidpointFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
@ -30,70 +29,75 @@ public class MidpointFieldIntegratorTest extends AbstractRungeKuttaFieldIntegrat
return new MidpointFieldIntegrator<T>(field, step);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testMissedEndEvent() {
doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 6.0e-5);
}
@Test
@Override
public void testSanityChecks() {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testDecreasingSteps() {
doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
}
@Test
@Override
public void testSmallStep() {
doTestSmallStep(Decimal64Field.getInstance(), 2.0e-7, 1.0e-6, 1.0e-12, "midpoint");
}
@Test
@Override
public void testBigStep() {
doTestBigStep(Decimal64Field.getInstance(), 0.01, 0.05, 1.0e-12, "midpoint");
}
@Test
@Override
public void testBackward() {
doTestBackward(Decimal64Field.getInstance(), 6.0e-4, 6.0e-4, 1.0e-12, "midpoint");
}
@Test
@Override
public void testKepler() {
doTestKepler(Decimal64Field.getInstance(), 1.19, 0.01);
}
@Test
@Override
public void testStepSize() {
doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testSingleStep() {
doTestSingleStep(Decimal64Field.getInstance(), 0.21);
}
@Test
@Override
public void testTooLargeFirstStep() {
doTestTooLargeFirstStep(Decimal64Field.getInstance());
}
@Test
@Override
public void testUnstableDerivative() {
doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testDerivativesConsistency() {
doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(1.7e-4, new double[] { 1.0e-3, 2.8e-4, 3.8e-5, 2.8e-4, 2.8e-4 });
}
}

View File

@ -21,7 +21,6 @@ package org.apache.commons.math4.ode.nonstiff;
import org.apache.commons.math4.Field;
import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.util.Decimal64Field;
import org.junit.Test;
public class ThreeEighthesFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
@ -30,70 +29,75 @@ public class ThreeEighthesFieldIntegratorTest extends AbstractRungeKuttaFieldInt
return new ThreeEighthesFieldIntegrator<T>(field, step);
}
@Test
@Override
public void testNonFieldIntegratorConsistency() {
doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
}
@Test
@Override
public void testMissedEndEvent() {
doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 6.0e-5);
}
@Test
@Override
public void testSanityChecks() {
doTestSanityChecks(Decimal64Field.getInstance());
}
@Test
@Override
public void testDecreasingSteps() {
doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
}
@Test
@Override
public void testSmallStep() {
doTestSmallStep(Decimal64Field.getInstance(), 2.0e-13, 4.0e-12, 1.0e-12, "3/8");
}
@Test
@Override
public void testBigStep() {
doTestBigStep(Decimal64Field.getInstance(), 0.0004, 0.005, 1.0e-12, "3/8");
}
@Test
@Override
public void testBackward() {
doTestBackward(Decimal64Field.getInstance(), 5.0e-10, 7.0e-10, 1.0e-12, "3/8");
}
@Test
@Override
public void testKepler() {
doTestKepler(Decimal64Field.getInstance(), 0.0348, 1.0e-4);
}
@Test
@Override
public void testStepSize() {
doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testSingleStep() {
doTestSingleStep(Decimal64Field.getInstance(), 0.21);
}
@Test
@Override
public void testTooLargeFirstStep() {
doTestTooLargeFirstStep(Decimal64Field.getInstance());
}
@Test
@Override
public void testUnstableDerivative() {
doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
}
@Test
@Override
public void testDerivativesConsistency() {
doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
}
@Override
public void testPartialDerivatives() {
doTestPartialDerivatives(3.2e-10, new double[] { 2.1e-9, 5.9e-10, 7.0e-11, 5.9e-10, 5.9e-10 });
}
}