You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2015/12/03 18:16:32 UTC
[4/7] [math] Added tests for derivatives consistency.
Added tests for derivatives consistency.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/b50f1496
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/b50f1496
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/b50f1496
Branch: refs/heads/field-ode
Commit: b50f1496eabf27d46d788b49920efa664802715e
Parents: 9096002
Author: Luc Maisonobe <lu...@apache.org>
Authored: Thu Dec 3 18:12:41 2015 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Thu Dec 3 18:12:41 2015 +0100
----------------------------------------------------------------------
.../AbstractRungeKuttaFieldIntegratorTest.java | 11 +++
.../ClassicalRungeKuttaFieldIntegratorTest.java | 5 ++
.../ode/nonstiff/EulerFieldIntegratorTest.java | 5 ++
.../ode/nonstiff/GillFieldIntegratorTest.java | 82 ++++++++++----------
4 files changed, 62 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b50f1496/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
index a97a32d..3c35603 100644
--- a/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math3/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
@@ -42,6 +42,7 @@ import org.apache.commons.math3.ode.events.Action;
import org.apache.commons.math3.ode.events.FieldEventHandler;
import org.apache.commons.math3.ode.sampling.FieldStepHandler;
import org.apache.commons.math3.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math3.ode.sampling.StepInterpolatorTestUtils;
import org.apache.commons.math3.util.FastMath;
import org.apache.commons.math3.util.MathArrays;
import org.junit.Assert;
@@ -507,4 +508,14 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
Assert.assertEquals(8.0, result.getState()[0].getReal(), epsilon);
}
+ @Test
+ public abstract void testDerivativesConsistency();
+
+ protected <T extends RealFieldElement<T>> void doTestDerivativesConsistency(final Field<T> field, double epsilon) {
+ TestFieldProblem3<T> pb = new TestFieldProblem3<T>(field);
+ T step = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.001);
+ RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
+ StepInterpolatorTestUtils.checkDerivativesConsistency(integ, pb, 1.0e-10);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b50f1496/src/test/java/org/apache/commons/math3/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math3/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
index 1ed3766..3e4d3d7 100644
--- a/src/test/java/org/apache/commons/math3/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math3/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
@@ -91,4 +91,9 @@ public class ClassicalRungeKuttaFieldIntegratorTest extends AbstractRungeKuttaFi
doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
}
+ @Test
+ public void testDerivativesConsistency() {
+ doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b50f1496/src/test/java/org/apache/commons/math3/ode/nonstiff/EulerFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/ode/nonstiff/EulerFieldIntegratorTest.java b/src/test/java/org/apache/commons/math3/ode/nonstiff/EulerFieldIntegratorTest.java
index 2ed42bb..d4334e7 100644
--- a/src/test/java/org/apache/commons/math3/ode/nonstiff/EulerFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math3/ode/nonstiff/EulerFieldIntegratorTest.java
@@ -92,4 +92,9 @@ public class EulerFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorT
doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
}
+ @Test
+ public void testDerivativesConsistency() {
+ doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b50f1496/src/test/java/org/apache/commons/math3/ode/nonstiff/GillFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/ode/nonstiff/GillFieldIntegratorTest.java b/src/test/java/org/apache/commons/math3/ode/nonstiff/GillFieldIntegratorTest.java
index f820fe7..2aa6278 100644
--- a/src/test/java/org/apache/commons/math3/ode/nonstiff/GillFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math3/ode/nonstiff/GillFieldIntegratorTest.java
@@ -20,12 +20,7 @@ package org.apache.commons.math3.ode.nonstiff;
import org.apache.commons.math3.Field;
import org.apache.commons.math3.RealFieldElement;
-import org.apache.commons.math3.ode.FieldExpandableODE;
-import org.apache.commons.math3.ode.FieldODEState;
-import org.apache.commons.math3.ode.FieldODEStateAndDerivative;
import org.apache.commons.math3.util.Decimal64Field;
-import org.apache.commons.math3.util.MathArrays;
-import org.junit.Assert;
import org.junit.Test;
public class GillFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
@@ -45,55 +40,60 @@ public class GillFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTe
doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 6.0e-5);
}
- @Test
- public void testSanityChecks() {
- doTestSanityChecks(Decimal64Field.getInstance());
- }
+ @Test
+ public void testSanityChecks() {
+ doTestSanityChecks(Decimal64Field.getInstance());
+ }
- @Test
- public void testDecreasingSteps() {
- doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
- }
+ @Test
+ public void testDecreasingSteps() {
+ doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
+ }
- @Test
- public void testSmallStep() {
- doTestSmallStep(Decimal64Field.getInstance(), 2.0e-13, 4.0e-12, 1.0e-12, "Gill");
- }
+ @Test
+ public void testSmallStep() {
+ doTestSmallStep(Decimal64Field.getInstance(), 2.0e-13, 4.0e-12, 1.0e-12, "Gill");
+ }
- @Test
- public void testBigStep() {
- doTestBigStep(Decimal64Field.getInstance(), 0.0004, 0.005, 1.0e-12, "Gill");
+ @Test
+ public void testBigStep() {
+ doTestBigStep(Decimal64Field.getInstance(), 0.0004, 0.005, 1.0e-12, "Gill");
- }
+ }
- @Test
- public void testBackward() {
- doTestBackward(Decimal64Field.getInstance(), 5.0e-10, 7.0e-10, 1.0e-12, "Gill");
- }
+ @Test
+ public void testBackward() {
+ doTestBackward(Decimal64Field.getInstance(), 5.0e-10, 7.0e-10, 1.0e-12, "Gill");
+ }
- @Test
- public void testKepler() {
- doTestKepler(Decimal64Field.getInstance(), 1.72e-3, 1.0e-5);
- }
+ @Test
+ public void testKepler() {
+ doTestKepler(Decimal64Field.getInstance(), 1.72e-3, 1.0e-5);
+ }
- @Test
- public void testStepSize() {
- doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
- }
+ @Test
+ public void testStepSize() {
+ doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
+ }
- @Test
- public void testSingleStep() {
- doTestSingleStep(Decimal64Field.getInstance(), 0.21);
- }
+ @Test
+ public void testSingleStep() {
+ doTestSingleStep(Decimal64Field.getInstance(), 0.21);
+ }
- @Test
- public void testTooLargeFirstStep() {
- doTestTooLargeFirstStep(Decimal64Field.getInstance());
- }
+ @Test
+ public void testTooLargeFirstStep() {
+ doTestTooLargeFirstStep(Decimal64Field.getInstance());
+ }
@Test
public void testUnstableDerivative() {
doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
}
+ @Test
+ public void testDerivativesConsistency() {
+ doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
+ }
+
}