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 2016/01/06 14:50:17 UTC

[01/50] [abbrv] [math] Added tests for derivatives consistency.

Repository: commons-math
Updated Branches:
  refs/heads/master 7e1c299da -> e76bf903a


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/de903324
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/de903324
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/de903324

Branch: refs/heads/master
Commit: de903324903d441b3224b2170476629b979d2ad8
Parents: a961a2e
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:06 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:06 2016 +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/de903324/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
index f670a9f..cc66cd1 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
@@ -42,6 +42,7 @@ import org.apache.commons.math4.ode.events.Action;
 import org.apache.commons.math4.ode.events.FieldEventHandler;
 import org.apache.commons.math4.ode.sampling.FieldStepHandler;
 import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math4.ode.sampling.StepInterpolatorTestUtils;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.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/de903324/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
index 4c3ec47..f2ece27 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/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/de903324/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
index 76e830a..4d93ca3 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/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/de903324/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
index 91d38fe..7b4ad50 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
@@ -20,12 +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.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldODEState;
-import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
-import org.apache.commons.math4.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);
+    }
+
 }


[32/50] [abbrv] [math] Use immutable step interpolators.

Posted by lu...@apache.org.
Use immutable step interpolators.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/771eb6a6
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/771eb6a6
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/771eb6a6

Branch: refs/heads/master
Commit: 771eb6a606491375a61fee1aa537025edafacc34
Parents: 0ddec29
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:22:39 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:22:39 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/AbstractFieldIntegrator.java      |  15 +-
 .../math4/ode/ContinuousOutputFieldModel.java   |   6 +-
 .../ClassicalRungeKuttaFieldIntegrator.java     |  11 +-
 ...lassicalRungeKuttaFieldStepInterpolator.java |  42 ++--
 .../DormandPrince54FieldIntegrator.java         |  10 +-
 .../DormandPrince54FieldStepInterpolator.java   |  64 +++---
 .../DormandPrince853FieldIntegrator.java        |  10 +-
 .../DormandPrince853FieldStepInterpolator.java  | 227 ++++++++++---------
 .../EmbeddedRungeKuttaFieldIntegrator.java      |  22 +-
 .../ode/nonstiff/EulerFieldIntegrator.java      |  11 +-
 .../nonstiff/EulerFieldStepInterpolator.java    |  46 ++--
 .../math4/ode/nonstiff/GillFieldIntegrator.java |  11 +-
 .../ode/nonstiff/GillFieldStepInterpolator.java |  45 ++--
 .../nonstiff/HighamHall54FieldIntegrator.java   |  10 +-
 .../HighamHall54FieldStepInterpolator.java      |  59 +++--
 .../ode/nonstiff/LutherFieldIntegrator.java     |  11 +-
 .../nonstiff/LutherFieldStepInterpolator.java   |  62 +++--
 .../ode/nonstiff/MidpointFieldIntegrator.java   |  11 +-
 .../nonstiff/MidpointFieldStepInterpolator.java |  47 ++--
 .../ode/nonstiff/RungeKuttaFieldIntegrator.java |  22 +-
 .../RungeKuttaFieldStepInterpolator.java        |  79 ++++---
 .../nonstiff/ThreeEighthesFieldIntegrator.java  |  11 +-
 .../ThreeEighthesFieldStepInterpolator.java     |  41 ++--
 .../sampling/AbstractFieldStepInterpolator.java | 145 +++++-------
 .../ode/sampling/FieldStepInterpolator.java     |  11 -
 .../ode/ContinuousOutputFieldModelTest.java     | 219 ++++++++++++++++++
 ...ractRungeKuttaFieldStepInterpolatorTest.java |  71 ++----
 ...sicalRungKuttaFieldStepInterpolatorTest.java |  20 +-
 ...ormandPrince54FieldStepInterpolatorTest.java |  20 +-
 ...rmandPrince853FieldStepInterpolatorTest.java |  18 +-
 .../EulerFieldStepInterpolatorTest.java         |  19 +-
 .../nonstiff/GillFieldStepInterpolatorTest.java |  20 +-
 .../HighamHall54FieldStepInterpolatorTest.java  |  20 +-
 .../LutherFieldStepInterpolatorTest.java        |  18 +-
 .../MidpointFieldStepInterpolatorTest.java      |  20 +-
 .../ThreeEighthesFieldStepInterpolatorTest.java |  20 +-
 .../sampling/DummyFieldStepInterpolator.java    |  55 +++++
 37 files changed, 981 insertions(+), 568 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
index 07fa9a0..b4f321c 100644
--- a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
@@ -307,6 +307,7 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
                 }
             }
 
+            AbstractFieldStepInterpolator<T> restricted = interpolator;
             while (!occurringEvents.isEmpty()) {
 
                 // handle the chronologically first event
@@ -315,11 +316,10 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
                 iterator.remove();
 
                 // get state at event time
-                final FieldODEStateAndDerivative<T> eventState = interpolator.getInterpolatedState(currentEvent.getEventTime());
+                final FieldODEStateAndDerivative<T> eventState = restricted.getInterpolatedState(currentEvent.getEventTime());
 
                 // restrict the interpolator to the first part of the step, up to the event
-                interpolator.setSoftPreviousState(previousState);
-                interpolator.setSoftCurrentState(eventState);
+                restricted = restricted.restrictStep(previousState, eventState);
 
                 // advance all event states to current time
                 for (final FieldEventState<T> state : eventsStates) {
@@ -329,7 +329,7 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
 
                 // handle the first part of the step, up to the event
                 for (final FieldStepHandler<T> handler : stepHandlers) {
-                    handler.handleStep(interpolator, isLastStep);
+                    handler.handleStep(restricted, isLastStep);
                 }
 
                 if (isLastStep) {
@@ -351,11 +351,10 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
 
                 // prepare handling of the remaining part of the step
                 previousState = eventState;
-                interpolator.setSoftPreviousState(eventState);
-                interpolator.setSoftCurrentState(currentState);
+                restricted = restricted.restrictStep(eventState, currentState);
 
                 // check if the same event occurs again in the remaining part of the step
-                if (currentEvent.evaluateStep(interpolator)) {
+                if (currentEvent.evaluateStep(restricted)) {
                     // the event occurs during the current step
                     occurringEvents.add(currentEvent);
                 }
@@ -371,7 +370,7 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
 
             // handle the remaining part of the step, after all events if any
             for (FieldStepHandler<T> handler : stepHandlers) {
-                handler.handleStep(interpolator, isLastStep);
+                handler.handleStep(restricted, isLastStep);
             }
 
             return currentState;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java b/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
index 8f94e51..f26fded 100644
--- a/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
+++ b/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
@@ -80,7 +80,7 @@ import org.apache.commons.math4.util.FastMath;
  */
 
 public class ContinuousOutputFieldModel<T extends RealFieldElement<T>>
-  implements FieldStepHandler<T> {
+    implements FieldStepHandler<T> {
 
     /** Initial integration time. */
     private T initialTime;
@@ -156,7 +156,7 @@ public class ContinuousOutputFieldModel<T extends RealFieldElement<T>>
         }
 
         for (FieldStepInterpolator<T> interpolator : model.steps) {
-            steps.add(interpolator.copy());
+            steps.add(interpolator);
         }
 
         index = steps.size() - 1;
@@ -201,7 +201,7 @@ public class ContinuousOutputFieldModel<T extends RealFieldElement<T>>
             forward     = interpolator.isForward();
         }
 
-        steps.add(interpolator.copy());
+        steps.add(interpolator);
 
         if (isLast) {
             finalTime = interpolator.getCurrentState().getTime();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java
index a09c1fa..315924a 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 
 /**
@@ -100,8 +101,14 @@ public class ClassicalRungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
     /** {@inheritDoc} */
     @Override
     protected ClassicalRungeKuttaFieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new ClassicalRungeKuttaFieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState,
+                           final FieldEquationsMapper<T> mapper) {
+        return new ClassicalRungeKuttaFieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                               globalPreviousState, globalCurrentState,
+                                                               globalPreviousState, globalCurrentState,
+                                                               mapper);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java
index d096db2..9b70331 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java
@@ -62,26 +62,36 @@ class ClassicalRungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
     ClassicalRungeKuttaFieldStepInterpolator(final Field<T> field, final boolean forward,
+                                             final T[][] yDotK,
+                                             final FieldODEStateAndDerivative<T> globalPreviousState,
+                                             final FieldODEStateAndDerivative<T> globalCurrentState,
+                                             final FieldODEStateAndDerivative<T> softPreviousState,
+                                             final FieldODEStateAndDerivative<T> softCurrentState,
                                              final FieldEquationsMapper<T> mapper) {
-        super(field, forward, mapper);
-    }
-
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    ClassicalRungeKuttaFieldStepInterpolator(final ClassicalRungeKuttaFieldStepInterpolator<T> interpolator) {
-        super(interpolator);
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
     }
 
     /** {@inheritDoc} */
-    @Override
-    protected ClassicalRungeKuttaFieldStepInterpolator<T> doCopy() {
-        return new ClassicalRungeKuttaFieldStepInterpolator<T>(this);
+    protected ClassicalRungeKuttaFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                                 final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                                 final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                                 final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                                 final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                                 final FieldEquationsMapper<T> newMapper) {
+        return new ClassicalRungeKuttaFieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                               newGlobalPreviousState, newGlobalCurrentState,
+                                                               newSoftPreviousState, newSoftCurrentState,
+                                                               newMapper);
     }
 
     /** {@inheritDoc} */
@@ -89,9 +99,9 @@ class ClassicalRungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH) {
+                                                                                   final T thetaH, final T oneMinusThetaH) {
 
-        final T one                       = getField().getOne();
+        final T one                       = time.getField().getOne();
         final T oneMinusTheta             = one.subtract(theta);
         final T oneMinus2Theta            = one.subtract(theta.multiply(2));
         final T coeffDot1                 = oneMinusTheta.multiply(oneMinus2Theta);
@@ -102,7 +112,7 @@ class ClassicalRungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
 
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
             final T fourTheta2      = theta.multiply(theta).multiply(4);
-            final T s               = theta.multiply(h).divide(6.0);
+            final T s               = thetaH.divide(6.0);
             final T coeff1          = s.multiply(fourTheta2.subtract(theta.multiply(9)).add(6));
             final T coeff23         = s.multiply(theta.multiply(6).subtract(fourTheta2));
             final T coeff4          = s.multiply(fourTheta2.subtract(theta.multiply(3)));

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
index e454ca7..b8ec110 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 import org.apache.commons.math4.util.MathUtils;
 
@@ -189,8 +190,13 @@ public class DormandPrince54FieldIntegrator<T extends RealFieldElement<T>>
     /** {@inheritDoc} */
     @Override
     protected DormandPrince54FieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new DormandPrince54FieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState, final FieldEquationsMapper<T> mapper) {
+        return new DormandPrince54FieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                           globalPreviousState, globalCurrentState,
+                                                           globalPreviousState, globalCurrentState,
+                                                           mapper);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java
index 93b51d7..c9495e2 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java
@@ -75,11 +75,23 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
     DormandPrince54FieldStepInterpolator(final Field<T> field, final boolean forward,
+                                         final T[][] yDotK,
+                                         final FieldODEStateAndDerivative<T> globalPreviousState,
+                                         final FieldODEStateAndDerivative<T> globalCurrentState,
+                                         final FieldODEStateAndDerivative<T> softPreviousState,
+                                         final FieldODEStateAndDerivative<T> softCurrentState,
                                          final FieldEquationsMapper<T> mapper) {
-        super(field, forward, mapper);
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
         final T one = field.getOne();
         a70 = one.multiply(   35.0).divide( 384.0);
         a72 = one.multiply(  500.0).divide(1113.0);
@@ -94,43 +106,27 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
         d6  = one.multiply(    69997945.0).divide(    29380423.0);
     }
 
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    DormandPrince54FieldStepInterpolator(final DormandPrince54FieldStepInterpolator<T> interpolator) {
-
-        super(interpolator);
-        a70 = interpolator.a70;
-        a72 = interpolator.a72;
-        a73 = interpolator.a73;
-        a74 = interpolator.a74;
-        a75 = interpolator.a75;
-        d0  = interpolator.d0;
-        d2  = interpolator.d2;
-        d3  = interpolator.d3;
-        d4  = interpolator.d4;
-        d5  = interpolator.d5;
-        d6  = interpolator.d6;
-
-    }
-
     /** {@inheritDoc} */
-    @Override
-    protected DormandPrince54FieldStepInterpolator<T> doCopy() {
-        return new DormandPrince54FieldStepInterpolator<T>(this);
+    protected DormandPrince54FieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                                 final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                                 final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                                 final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                                 final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                                 final FieldEquationsMapper<T> newMapper) {
+        return new DormandPrince54FieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                           newGlobalPreviousState, newGlobalCurrentState,
+                                                           newSoftPreviousState, newSoftCurrentState,
+                                                           newMapper);
     }
-
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH) {
+                                                                                   final T thetaH, final T oneMinusThetaH) {
 
         // interpolate
-        final T one      = getField().getOne();
+        final T one      = time.getField().getOne();
         final T eta      = one.subtract(theta);
         final T twoTheta = theta.multiply(2);
         final T dot2     = one.subtract(twoTheta);
@@ -139,7 +135,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
         final T[] interpolatedState;
         final T[] interpolatedDerivatives;
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
-            final T f1        = h.multiply(theta);
+            final T f1        = thetaH;
             final T f2        = f1.multiply(eta);
             final T f3        = f2.multiply(theta);
             final T f4        = f3.multiply(eta);
@@ -147,7 +143,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
                                 subtract(f2.multiply(a70.subtract(1))).
                                 add(f3.multiply(a70.multiply(2).subtract(1))).
                                 add(f4.multiply(d0));
-            final T coeff1    = getField().getZero();
+            final T coeff1    = time.getField().getZero();
             final T coeff2    = f1.multiply(a72).
                                 subtract(f2.multiply(a72)).
                                 add(f3.multiply(a72.multiply(2))).
@@ -169,7 +165,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
                                 subtract(dot2.multiply(a70.subtract(1))).
                                 add(dot3.multiply(a70.multiply(2).subtract(1))).
                                 add(dot4.multiply(d0));
-            final T coeffDot1 = getField().getZero();
+            final T coeffDot1 = time.getField().getZero();
             final T coeffDot2 = a72.
                                 subtract(dot2.multiply(a72)).
                                 add(dot3.multiply(a72.multiply(2))).
@@ -200,7 +196,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
                                 subtract(f2.multiply(a70.subtract(1))).
                                 add(f3.multiply(a70.multiply(2).subtract(1))).
                                 add(f4.multiply(d0));
-            final T coeff1    = getField().getZero();
+            final T coeff1    = time.getField().getZero();
             final T coeff2    = f1.multiply(a72).
                                 subtract(f2.multiply(a72)).
                                 add(f3.multiply(a72.multiply(2))).
@@ -222,7 +218,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
                                 subtract(dot2.multiply(a70.subtract(1))).
                                 add(dot3.multiply(a70.multiply(2).subtract(1))).
                                 add(dot4.multiply(d0));
-            final T coeffDot1 = getField().getZero();
+            final T coeffDot1 = time.getField().getZero();
             final T coeffDot2 = a72.
                                 subtract(dot2.multiply(a72)).
                                 add(dot3.multiply(a72.multiply(2))).

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
index 9f8e36c..171b465 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 import org.apache.commons.math4.util.MathUtils;
 
@@ -395,8 +396,13 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
     /** {@inheritDoc} */
     @Override
     protected DormandPrince853FieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new DormandPrince853FieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState, final FieldEquationsMapper<T> mapper) {
+        return new DormandPrince853FieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                            globalPreviousState, globalCurrentState,
+                                                            globalPreviousState, globalCurrentState,
+                                                            mapper);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
index 68573fd..9f4b2b0 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
@@ -45,32 +45,43 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
     DormandPrince853FieldStepInterpolator(final Field<T> field, final boolean forward,
+                                          final T[][] yDotK,
+                                          final FieldODEStateAndDerivative<T> globalPreviousState,
+                                          final FieldODEStateAndDerivative<T> globalCurrentState,
+                                          final FieldODEStateAndDerivative<T> softPreviousState,
+                                          final FieldODEStateAndDerivative<T> softCurrentState,
                                           final FieldEquationsMapper<T> mapper) {
-        super(field, forward, mapper);
-
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
         // interpolation weights
-        d = MathArrays.buildArray(getField(), 7, 16);
+        d = MathArrays.buildArray(field, 7, 16);
 
         // this row is the same as the b array
-        d[0][ 0] = fraction(104257, 1920240);
-        d[0][ 1] = getField().getZero();
-        d[0][ 2] = getField().getZero();
-        d[0][ 3] = getField().getZero();
-        d[0][ 4] = getField().getZero();
-        d[0][ 5] = fraction(        3399327.0,          763840.0);
-        d[0][ 6] = fraction(       66578432.0,        35198415.0);
-        d[0][ 7] = fraction(    -1674902723.0,       288716400.0);
-        d[0][ 8] = fraction( 54980371265625.0, 176692375811392.0);
-        d[0][ 9] = fraction(        -734375.0,         4826304.0);
-        d[0][10] = fraction(      171414593.0,       851261400.0);
-        d[0][11] = fraction(         137909.0,         3084480.0);
-        d[0][12] = getField().getZero();
-        d[0][13] = getField().getZero();
-        d[0][14] = getField().getZero();
-        d[0][15] = getField().getZero();
+        d[0][ 0] = fraction(field, 104257, 1920240);
+        d[0][ 1] = field.getZero();
+        d[0][ 2] = field.getZero();
+        d[0][ 3] = field.getZero();
+        d[0][ 4] = field.getZero();
+        d[0][ 5] = fraction(field,         3399327.0,          763840.0);
+        d[0][ 6] = fraction(field,        66578432.0,        35198415.0);
+        d[0][ 7] = fraction(field,     -1674902723.0,       288716400.0);
+        d[0][ 8] = fraction(field,  54980371265625.0, 176692375811392.0);
+        d[0][ 9] = fraction(field,         -734375.0,         4826304.0);
+        d[0][10] = fraction(field,       171414593.0,       851261400.0);
+        d[0][11] = fraction(field,          137909.0,         3084480.0);
+        d[0][12] = field.getZero();
+        d[0][13] = field.getZero();
+        d[0][14] = field.getZero();
+        d[0][15] = field.getZero();
 
         d[1][ 0] = d[0][ 0].negate().add(1);
         d[1][ 1] = d[0][ 1].negate();
@@ -106,105 +117,97 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
         d[2][14] = d[0][14].multiply(2);             // really  0
         d[2][15] = d[0][15].multiply(2);             // really  0
 
-        d[3][ 0] = fraction(        -17751989329.0, 2106076560.0);
-        d[3][ 1] = getField().getZero();
-        d[3][ 2] = getField().getZero();
-        d[3][ 3] = getField().getZero();
-        d[3][ 4] = getField().getZero();
-        d[3][ 5] = fraction(          4272954039.0, 7539864640.0);
-        d[3][ 6] = fraction(       -118476319744.0, 38604839385.0);
-        d[3][ 7] = fraction(        755123450731.0, 316657731600.0);
-        d[3][ 8] = fraction( 3692384461234828125.0, 1744130441634250432.0);
-        d[3][ 9] = fraction(         -4612609375.0, 5293382976.0);
-        d[3][10] = fraction(       2091772278379.0, 933644586600.0);
-        d[3][11] = fraction(          2136624137.0, 3382989120.0);
-        d[3][12] = fraction(             -126493.0, 1421424.0);
-        d[3][13] = fraction(            98350000.0, 5419179.0);
-        d[3][14] = fraction(           -18878125.0, 2053168.0);
-        d[3][15] = fraction(         -1944542619.0, 438351368.0);
+        d[3][ 0] = fraction(field,         -17751989329.0, 2106076560.0);
+        d[3][ 1] = field.getZero();
+        d[3][ 2] = field.getZero();
+        d[3][ 3] = field.getZero();
+        d[3][ 4] = field.getZero();
+        d[3][ 5] = fraction(field,           4272954039.0, 7539864640.0);
+        d[3][ 6] = fraction(field,        -118476319744.0, 38604839385.0);
+        d[3][ 7] = fraction(field,         755123450731.0, 316657731600.0);
+        d[3][ 8] = fraction(field,  3692384461234828125.0, 1744130441634250432.0);
+        d[3][ 9] = fraction(field,          -4612609375.0, 5293382976.0);
+        d[3][10] = fraction(field,        2091772278379.0, 933644586600.0);
+        d[3][11] = fraction(field,           2136624137.0, 3382989120.0);
+        d[3][12] = fraction(field,              -126493.0, 1421424.0);
+        d[3][13] = fraction(field,             98350000.0, 5419179.0);
+        d[3][14] = fraction(field,            -18878125.0, 2053168.0);
+        d[3][15] = fraction(field,          -1944542619.0, 438351368.0);
 
-        d[4][ 0] = fraction(         32941697297.0, 3159114840.0);
-        d[4][ 1] = getField().getZero();
-        d[4][ 2] = getField().getZero();
-        d[4][ 3] = getField().getZero();
-        d[4][ 4] = getField().getZero();
-        d[4][ 5] = fraction(        456696183123.0, 1884966160.0);
-        d[4][ 6] = fraction(      19132610714624.0, 115814518155.0);
-        d[4][ 7] = fraction(    -177904688592943.0, 474986597400.0);
-        d[4][ 8] = fraction(-4821139941836765625.0, 218016305204281304.0);
-        d[4][ 9] = fraction(         30702015625.0, 3970037232.0);
-        d[4][10] = fraction(     -85916079474274.0, 2800933759800.0);
-        d[4][11] = fraction(         -5919468007.0, 634310460.0);
-        d[4][12] = fraction(             2479159.0, 157936.0);
-        d[4][13] = fraction(           -18750000.0, 602131.0);
-        d[4][14] = fraction(           -19203125.0, 2053168.0);
-        d[4][15] = fraction(         15700361463.0, 438351368.0);
+        d[4][ 0] = fraction(field,          32941697297.0, 3159114840.0);
+        d[4][ 1] = field.getZero();
+        d[4][ 2] = field.getZero();
+        d[4][ 3] = field.getZero();
+        d[4][ 4] = field.getZero();
+        d[4][ 5] = fraction(field,         456696183123.0, 1884966160.0);
+        d[4][ 6] = fraction(field,       19132610714624.0, 115814518155.0);
+        d[4][ 7] = fraction(field,     -177904688592943.0, 474986597400.0);
+        d[4][ 8] = fraction(field, -4821139941836765625.0, 218016305204281304.0);
+        d[4][ 9] = fraction(field,          30702015625.0, 3970037232.0);
+        d[4][10] = fraction(field,      -85916079474274.0, 2800933759800.0);
+        d[4][11] = fraction(field,          -5919468007.0, 634310460.0);
+        d[4][12] = fraction(field,              2479159.0, 157936.0);
+        d[4][13] = fraction(field,            -18750000.0, 602131.0);
+        d[4][14] = fraction(field,            -19203125.0, 2053168.0);
+        d[4][15] = fraction(field,          15700361463.0, 438351368.0);
 
-        d[5][ 0] = fraction(         12627015655.0, 631822968.0);
-        d[5][ 1] = getField().getZero();
-        d[5][ 2] = getField().getZero();
-        d[5][ 3] = getField().getZero();
-        d[5][ 4] = getField().getZero();
-        d[5][ 5] = fraction(        -72955222965.0, 188496616.0);
-        d[5][ 6] = fraction(     -13145744952320.0, 69488710893.0);
-        d[5][ 7] = fraction(      30084216194513.0, 56998391688.0);
-        d[5][ 8] = fraction( -296858761006640625.0, 25648977082856624.0);
-        d[5][ 9] = fraction(           569140625.0, 82709109.0);
-        d[5][10] = fraction(        -18684190637.0, 18672891732.0);
-        d[5][11] = fraction(            69644045.0, 89549712.0);
-        d[5][12] = fraction(           -11847025.0, 4264272.0);
-        d[5][13] = fraction(          -978650000.0, 16257537.0);
-        d[5][14] = fraction(           519371875.0, 6159504.0);
-        d[5][15] = fraction(          5256837225.0, 438351368.0);
+        d[5][ 0] = fraction(field,          12627015655.0, 631822968.0);
+        d[5][ 1] = field.getZero();
+        d[5][ 2] = field.getZero();
+        d[5][ 3] = field.getZero();
+        d[5][ 4] = field.getZero();
+        d[5][ 5] = fraction(field,         -72955222965.0, 188496616.0);
+        d[5][ 6] = fraction(field,      -13145744952320.0, 69488710893.0);
+        d[5][ 7] = fraction(field,       30084216194513.0, 56998391688.0);
+        d[5][ 8] = fraction(field,  -296858761006640625.0, 25648977082856624.0);
+        d[5][ 9] = fraction(field,            569140625.0, 82709109.0);
+        d[5][10] = fraction(field,         -18684190637.0, 18672891732.0);
+        d[5][11] = fraction(field,             69644045.0, 89549712.0);
+        d[5][12] = fraction(field,            -11847025.0, 4264272.0);
+        d[5][13] = fraction(field,           -978650000.0, 16257537.0);
+        d[5][14] = fraction(field,            519371875.0, 6159504.0);
+        d[5][15] = fraction(field,           5256837225.0, 438351368.0);
 
-        d[6][ 0] = fraction(          -450944925.0, 17550638.0);
-        d[6][ 1] = getField().getZero();
-        d[6][ 2] = getField().getZero();
-        d[6][ 3] = getField().getZero();
-        d[6][ 4] = getField().getZero();
-        d[6][ 5] = fraction(        -14532122925.0, 94248308.0);
-        d[6][ 6] = fraction(       -595876966400.0, 2573655959.0);
-        d[6][ 7] = fraction(        188748653015.0, 527762886.0);
-        d[6][ 8] = fraction( 2545485458115234375.0, 27252038150535163.0);
-        d[6][ 9] = fraction(         -1376953125.0, 36759604.0);
-        d[6][10] = fraction(         53995596795.0, 518691437.0);
-        d[6][11] = fraction(           210311225.0, 7047894.0);
-        d[6][12] = fraction(            -1718875.0, 39484.0);
-        d[6][13] = fraction(            58000000.0, 602131.0);
-        d[6][14] = fraction(            -1546875.0, 39484.0);
-        d[6][15] = fraction(         -1262172375.0, 8429834.0);
+        d[6][ 0] = fraction(field,           -450944925.0, 17550638.0);
+        d[6][ 1] = field.getZero();
+        d[6][ 2] = field.getZero();
+        d[6][ 3] = field.getZero();
+        d[6][ 4] = field.getZero();
+        d[6][ 5] = fraction(field,         -14532122925.0, 94248308.0);
+        d[6][ 6] = fraction(field,        -595876966400.0, 2573655959.0);
+        d[6][ 7] = fraction(field,         188748653015.0, 527762886.0);
+        d[6][ 8] = fraction(field,  2545485458115234375.0, 27252038150535163.0);
+        d[6][ 9] = fraction(field,          -1376953125.0, 36759604.0);
+        d[6][10] = fraction(field,          53995596795.0, 518691437.0);
+        d[6][11] = fraction(field,            210311225.0, 7047894.0);
+        d[6][12] = fraction(field,             -1718875.0, 39484.0);
+        d[6][13] = fraction(field,             58000000.0, 602131.0);
+        d[6][14] = fraction(field,             -1546875.0, 39484.0);
+        d[6][15] = fraction(field,          -1262172375.0, 8429834.0);
 
     }
 
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    DormandPrince853FieldStepInterpolator(final DormandPrince853FieldStepInterpolator<T> interpolator) {
-
-        super(interpolator);
-
-        d = MathArrays.buildArray(getField(), 4, -1);
-        for (int i = 0; i < d.length; ++i) {
-            d[i] = interpolator.d[i].clone();
-        }
-
+    /** {@inheritDoc} */
+    protected DormandPrince853FieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                               final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                               final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                               final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                               final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                               final FieldEquationsMapper<T> newMapper) {
+        return new DormandPrince853FieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                            newGlobalPreviousState, newGlobalCurrentState,
+                                                            newSoftPreviousState, newSoftCurrentState,
+                                                            newMapper);
     }
 
     /** Create a fraction.
+     * @param field field to which the elements belong
      * @param p numerator
      * @param q denominator
      * @return p/q computed in the instance field
      */
-    private T fraction(final double p, final double q) {
-        return getField().getOne().multiply(p).divide(q);
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    protected DormandPrince853FieldStepInterpolator<T> doCopy() {
-        return new DormandPrince853FieldStepInterpolator<T>(this);
+    private T fraction(final Field<T> field, final double p, final double q) {
+        return field.getZero().add(p).divide(q);
     }
 
     /** {@inheritDoc} */
@@ -212,10 +215,10 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH)
+                                                                                   final T thetaH, final T oneMinusThetaH)
         throws MaxCountExceededException {
 
-        final T one      = getField().getOne();
+        final T one      = time.getField().getOne();
         final T eta      = one.subtract(theta);
         final T twoTheta = theta.multiply(2);
         final T theta2   = theta.multiply(theta);
@@ -230,15 +233,15 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
 
 
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
-            final T f0 = theta.multiply(h);
+            final T f0 = thetaH;
             final T f1 = f0.multiply(eta);
             final T f2 = f1.multiply(theta);
             final T f3 = f2.multiply(eta);
             final T f4 = f3.multiply(theta);
             final T f5 = f4.multiply(eta);
             final T f6 = f5.multiply(theta);
-            final T[] p = MathArrays.buildArray(getField(), 16);
-            final T[] q = MathArrays.buildArray(getField(), 16);
+            final T[] p = MathArrays.buildArray(time.getField(), 16);
+            final T[] q = MathArrays.buildArray(time.getField(), 16);
             for (int i = 0; i < p.length; ++i) {
                 p[i] =     f0.multiply(d[0][i]).
                        add(f1.multiply(d[1][i])).
@@ -267,8 +270,8 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
             final T f4 = f3.multiply(theta);
             final T f5 = f4.multiply(eta);
             final T f6 = f5.multiply(theta);
-            final T[] p = MathArrays.buildArray(getField(), 16);
-            final T[] q = MathArrays.buildArray(getField(), 16);
+            final T[] p = MathArrays.buildArray(time.getField(), 16);
+            final T[] q = MathArrays.buildArray(time.getField(), 16);
             for (int i = 0; i < p.length; ++i) {
                 p[i] =     f0.multiply(d[0][i]).
                        add(f1.multiply(d[1][i])).

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
index 13bb070..c6e2444 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
@@ -183,10 +183,15 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
 
     /** Create an interpolator.
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
      * @param mapper equations mapper for the all equations
      * @return external weights for the high order method from Butcher array
      */
-    protected abstract RungeKuttaFieldStepInterpolator<T> createInterpolator(boolean forward,
+    protected abstract RungeKuttaFieldStepInterpolator<T> createInterpolator(boolean forward, T[][] yDotK,
+                                                                             final FieldODEStateAndDerivative<T> globalPreviousState,
+                                                                             final FieldODEStateAndDerivative<T> globalCurrentState,
                                                                              FieldEquationsMapper<T> mapper);
     /** Get the order of the method.
      * @return order of the method
@@ -226,11 +231,6 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
         final T[][] yDotK  = MathArrays.buildArray(getField(), stages, -1);
         final T[]   yTmp   = MathArrays.buildArray(getField(), y0.length);
 
-        // set up an interpolator sharing the integrator arrays
-        final RungeKuttaFieldStepInterpolator<T> interpolator =
-                        createInterpolator(forward, equations.getMapper());
-        interpolator.storeState(stepStart);
-
         // set up integration control objects
         T  hNew           = getField().getZero();
         boolean firstTime = true;
@@ -239,8 +239,6 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
         isLastStep = false;
         do {
 
-            interpolator.shift();
-
             // iterate over step size, ensuring local normalized error is smaller than 1
             T error = getField().getZero().add(10);
             while (error.subtract(1.0).getReal() >= 0) {
@@ -314,16 +312,12 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
             final FieldODEStateAndDerivative<T> stateTmp = new FieldODEStateAndDerivative<T>(stepEnd, yTmp, yDotTmp);
 
             // local error is small enough: accept the step, trigger events and step handlers
-            interpolator.setSlopes(yDotK);
-            interpolator.storeState(stateTmp);
             System.arraycopy(yTmp, 0, y, 0, y0.length);
-            stepStart = acceptStep(interpolator, finalTime);
+            stepStart = acceptStep(createInterpolator(forward, yDotK, stepStart, stateTmp, equations.getMapper()),
+                                   finalTime);
 
             if (!isLastStep) {
 
-                // prepare next step
-                interpolator.storeState(stepStart);
-
                 // stepsize control for next step
                 final T factor = MathUtils.min(maxGrowth,
                                                MathUtils.max(minReduction, safety.multiply(error.pow(exp))));

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java
index 96403e5..ce87431 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 
 /**
@@ -85,8 +86,14 @@ public class EulerFieldIntegrator<T extends RealFieldElement<T>> extends RungeKu
     /** {@inheritDoc} */
     @Override
     protected EulerFieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new EulerFieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState,
+                           final FieldEquationsMapper<T> mapper) {
+        return new EulerFieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                 globalPreviousState, globalCurrentState,
+                                                 globalPreviousState, globalCurrentState,
+                                                 mapper);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java
index 9046118..133e540 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java
@@ -52,26 +52,36 @@ class EulerFieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
     EulerFieldStepInterpolator(final Field<T> field, final boolean forward,
-                               final FieldEquationsMapper<T> mapper) {
-        super(field, forward, mapper);
-    }
-
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    EulerFieldStepInterpolator(final EulerFieldStepInterpolator<T> interpolator) {
-        super(interpolator);
+                                             final T[][] yDotK,
+                                             final FieldODEStateAndDerivative<T> globalPreviousState,
+                                             final FieldODEStateAndDerivative<T> globalCurrentState,
+                                             final FieldODEStateAndDerivative<T> softPreviousState,
+                                             final FieldODEStateAndDerivative<T> softCurrentState,
+                                             final FieldEquationsMapper<T> mapper) {
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
     }
 
     /** {@inheritDoc} */
-    @Override
-    protected EulerFieldStepInterpolator<T> doCopy() {
-        return new EulerFieldStepInterpolator<T>(this);
+    protected EulerFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                                 final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                                 final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                                 final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                                 final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                                 final FieldEquationsMapper<T> newMapper) {
+        return new EulerFieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                 newGlobalPreviousState, newGlobalCurrentState,
+                                                 newSoftPreviousState, newSoftCurrentState,
+                                                 newMapper);
     }
 
     /** {@inheritDoc} */
@@ -79,15 +89,15 @@ class EulerFieldStepInterpolator<T extends RealFieldElement<T>>
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH) {
+                                                                                   final T thetaH, final T oneMinusThetaH) {
         final T[] interpolatedState;
         final T[] interpolatedDerivatives;
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
-            interpolatedState       = previousStateLinearCombination(theta.multiply(h));
-            interpolatedDerivatives = derivativeLinearCombination(getField().getOne());
+            interpolatedState       = previousStateLinearCombination(thetaH);
+            interpolatedDerivatives = derivativeLinearCombination(time.getField().getOne());
         } else {
             interpolatedState       = currentStateLinearCombination(oneMinusThetaH.negate());
-            interpolatedDerivatives = derivativeLinearCombination(getField().getOne());
+            interpolatedDerivatives = derivativeLinearCombination(time.getField().getOne());
         }
 
         return new FieldODEStateAndDerivative<T>(time, interpolatedState, interpolatedDerivatives);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java
index 6996d05..1fc6688 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 
 
@@ -110,8 +111,14 @@ public class GillFieldIntegrator<T extends RealFieldElement<T>>
     /** {@inheritDoc} */
     @Override
     protected GillFieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new GillFieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState,
+                           final FieldEquationsMapper<T> mapper) {
+        return new GillFieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                globalPreviousState, globalCurrentState,
+                                                globalPreviousState, globalCurrentState,
+                                                mapper);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java
index 62590e7..fdb16cb 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java
@@ -67,42 +67,49 @@ class GillFieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
     GillFieldStepInterpolator(final Field<T> field, final boolean forward,
+                              final T[][] yDotK,
+                              final FieldODEStateAndDerivative<T> globalPreviousState,
+                              final FieldODEStateAndDerivative<T> globalCurrentState,
+                              final FieldODEStateAndDerivative<T> softPreviousState,
+                              final FieldODEStateAndDerivative<T> softCurrentState,
                               final FieldEquationsMapper<T> mapper) {
-        super(field, forward, mapper);
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
         final T sqrt = field.getZero().add(0.5).sqrt();
         one_minus_inv_sqrt_2 = field.getOne().subtract(sqrt);
         one_plus_inv_sqrt_2  = field.getOne().add(sqrt);
     }
 
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    GillFieldStepInterpolator(final GillFieldStepInterpolator<T> interpolator) {
-        super(interpolator);
-        one_minus_inv_sqrt_2 = interpolator.one_minus_inv_sqrt_2;
-        one_plus_inv_sqrt_2  = interpolator.one_plus_inv_sqrt_2;
-    }
-
     /** {@inheritDoc} */
-    @Override
-    protected GillFieldStepInterpolator<T> doCopy() {
-        return new GillFieldStepInterpolator<T>(this);
+    protected GillFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                  final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                  final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                  final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                  final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                  final FieldEquationsMapper<T> newMapper) {
+        return new GillFieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                newGlobalPreviousState, newGlobalCurrentState,
+                                                newSoftPreviousState, newSoftCurrentState,
+                                                newMapper);
     }
 
-
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH) {
+                                                                                   final T thetaH, final T oneMinusThetaH) {
 
-        final T one        = getField().getOne();
+        final T one        = time.getField().getOne();
         final T twoTheta   = theta.multiply(2);
         final T fourTheta2 = twoTheta.multiply(twoTheta);
         final T coeffDot1  = theta.multiply(twoTheta.subtract(3)).add(1);
@@ -114,7 +121,7 @@ class GillFieldStepInterpolator<T extends RealFieldElement<T>>
         final T[] interpolatedDerivatives;
 
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
-            final T s               = theta.multiply(h).divide(6.0);
+            final T s               = thetaH.divide(6.0);
             final T c23             = s.multiply(theta.multiply(6).subtract(fourTheta2));
             final T coeff1          = s.multiply(fourTheta2.subtract(theta.multiply(9)).add(6));
             final T coeff2          = c23.multiply(one_minus_inv_sqrt_2);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java
index 0e0c3b8..0f8353a 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 import org.apache.commons.math4.util.MathUtils;
 
@@ -164,8 +165,13 @@ public class HighamHall54FieldIntegrator<T extends RealFieldElement<T>>
     /** {@inheritDoc} */
     @Override
     protected HighamHall54FieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new HighamHall54FieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState, final FieldEquationsMapper<T> mapper) {
+        return new HighamHall54FieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                        globalPreviousState, globalCurrentState,
+                                                        globalPreviousState, globalCurrentState,
+                                                        mapper);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
index c278043..c5402c2 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
@@ -38,38 +38,47 @@ class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
-      */
+     */
     HighamHall54FieldStepInterpolator(final Field<T> field, final boolean forward,
+                                      final T[][] yDotK,
+                                      final FieldODEStateAndDerivative<T> globalPreviousState,
+                                      final FieldODEStateAndDerivative<T> globalCurrentState,
+                                      final FieldODEStateAndDerivative<T> softPreviousState,
+                                      final FieldODEStateAndDerivative<T> softCurrentState,
                                       final FieldEquationsMapper<T> mapper) {
-     super(field, forward, mapper);
-    }
-
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    HighamHall54FieldStepInterpolator(final HighamHall54FieldStepInterpolator<T> interpolator) {
-        super(interpolator);
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
     }
 
     /** {@inheritDoc} */
-    @Override
-    protected HighamHall54FieldStepInterpolator<T> doCopy() {
-        return new HighamHall54FieldStepInterpolator<T>(this);
+    protected HighamHall54FieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                          final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                          final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                          final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                          final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                          final FieldEquationsMapper<T> newMapper) {
+        return new HighamHall54FieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                        newGlobalPreviousState, newGlobalCurrentState,
+                                                        newSoftPreviousState, newSoftCurrentState,
+                                                        newMapper);
     }
 
-
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH) {
+                                                                                   final T thetaH, final T oneMinusThetaH) {
 
         final T bDot0 = theta.multiply(theta.multiply(theta.multiply( -10.0      ).add( 16.0       )).add(-15.0 /  2.0)).add(1);
-        final T bDot1 = getField().getZero();
+        final T bDot1 = time.getField().getZero();
         final T bDot2 = theta.multiply(theta.multiply(theta.multiply( 135.0 / 2.0).add(-729.0 / 8.0)).add(459.0 / 16.0));
         final T bDot3 = theta.multiply(theta.multiply(theta.multiply(-120.0      ).add( 152.0      )).add(-44.0       ));
         final T bDot4 = theta.multiply(theta.multiply(theta.multiply( 125.0 / 2.0).add(-625.0 / 8.0)).add(375.0 / 16.0));
@@ -78,19 +87,19 @@ class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
         final T[] interpolatedDerivatives;
 
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
-            final T hTheta = h.multiply(theta);
-            final T b0 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply( -5.0 / 2.0).add(  16.0 /  3.0)).add(-15.0 /  4.0)).add(1));
-            final T b1 = getField().getZero();
-            final T b2 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(135.0 / 8.0).add(-243.0 /  8.0)).add(459.0 / 32.0)));
-            final T b3 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(-30.0      ).add( 152.0 /  3.0)).add(-22.0       )));
-            final T b4 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(125.0 / 8.0).add(-625.0 / 24.0)).add(375.0 / 32.0)));
-            final T b5 = hTheta.multiply(theta.multiply(theta.multiply(                                   5.0 / 12.0 ).add( -5.0 / 16.0)));
+            final T b0 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply( -5.0 / 2.0).add(  16.0 /  3.0)).add(-15.0 /  4.0)).add(1));
+            final T b1 = time.getField().getZero();
+            final T b2 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(135.0 / 8.0).add(-243.0 /  8.0)).add(459.0 / 32.0)));
+            final T b3 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(-30.0      ).add( 152.0 /  3.0)).add(-22.0       )));
+            final T b4 = thetaH.multiply(theta.multiply(theta.multiply(theta.multiply(125.0 / 8.0).add(-625.0 / 24.0)).add(375.0 / 32.0)));
+            final T b5 = thetaH.multiply(theta.multiply(theta.multiply(                                   5.0 / 12.0 ).add( -5.0 / 16.0)));
             interpolatedState       = previousStateLinearCombination(b0, b1, b2, b3, b4, b5);
             interpolatedDerivatives = derivativeLinearCombination(bDot0, bDot1, bDot2, bDot3, bDot4, bDot5);
         } else {
             final T theta2 = theta.multiply(theta);
+            final T h      = thetaH.divide(theta);
             final T b0 = h.multiply( theta.multiply(theta.multiply(theta.multiply(theta.multiply(-5.0 / 2.0).add( 16.0 / 3.0)).add( -15.0 /  4.0)).add(  1.0       )).add(  -1.0 / 12.0));
-            final T b1 = getField().getZero();
+            final T b1 = time.getField().getZero();
             final T b2 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               135.0 / 8.0 ).add(-243.0 /  8.0)).add(459.0 / 32.0)).add( -27.0 / 32.0));
             final T b3 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               -30.0       ).add( 152.0 /  3.0)).add(-22.0       )).add(  4.0  /  3.0));
             final T b4 = h.multiply(theta2.multiply(theta.multiply(theta.multiply(                               125.0 / 8.0 ).add(-625.0 / 24.0)).add(375.0 / 32.0)).add(-125.0 / 96.0));

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java
index b8d78d9..1c3301c 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 
 
@@ -135,8 +136,14 @@ public class LutherFieldIntegrator<T extends RealFieldElement<T>>
     /** {@inheritDoc} */
     @Override
     protected LutherFieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new LutherFieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState,
+                           final FieldEquationsMapper<T> mapper) {
+        return new LutherFieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                  globalPreviousState, globalCurrentState,
+                                                  globalPreviousState, globalCurrentState,
+                                                  mapper);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
index a5dc565..22bc403 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
@@ -83,11 +83,23 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
     LutherFieldStepInterpolator(final Field<T> field, final boolean forward,
+                                final T[][] yDotK,
+                                final FieldODEStateAndDerivative<T> globalPreviousState,
+                                final FieldODEStateAndDerivative<T> globalCurrentState,
+                                final FieldODEStateAndDerivative<T> softPreviousState,
+                                final FieldODEStateAndDerivative<T> softCurrentState,
                                 final FieldEquationsMapper<T> mapper) {
-        super(field, forward, mapper);
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
         final T q = field.getZero().add(21).sqrt();
         c5a = q.multiply(  -49).add(  -49);
         c5b = q.multiply(  287).add(  392);
@@ -103,45 +115,27 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
         d6a = q.multiply(  -49).add(   49);
         d6b = q.multiply(  847).add(-1372);
         d6c = q.multiply(-1029).add( 2254);
-
-    }
-
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    LutherFieldStepInterpolator(final LutherFieldStepInterpolator<T> interpolator) {
-        super(interpolator);
-        c5a = interpolator.c5a;
-        c5b = interpolator.c5b;
-        c5c = interpolator.c5c;
-        c5d = interpolator.c5d;
-        c6a = interpolator.c6a;
-        c6b = interpolator.c6b;
-        c6c = interpolator.c6c;
-        c6d = interpolator.c6d;
-        d5a = interpolator.d5a;
-        d5b = interpolator.d5b;
-        d5c = interpolator.d5c;
-        d6a = interpolator.d6a;
-        d6b = interpolator.d6b;
-        d6c = interpolator.d6c;
     }
 
     /** {@inheritDoc} */
-    @Override
-    protected LutherFieldStepInterpolator<T> doCopy() {
-        return new LutherFieldStepInterpolator<T>(this);
+    protected LutherFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                    final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                    final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                    final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                    final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                    final FieldEquationsMapper<T> newMapper) {
+        return new LutherFieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                  newGlobalPreviousState, newGlobalCurrentState,
+                                                  newSoftPreviousState, newSoftCurrentState,
+                                                  newMapper);
     }
 
-
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH) {
+                                                                                   final T thetaH, final T oneMinusThetaH) {
 
         // the coefficients below have been computed by solving the
         // order conditions from a theorem from Butcher (1963), using
@@ -187,7 +181,7 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
         // At the end, we get the b_i as polynomials in theta.
 
         final T coeffDot1 =  theta.multiply(theta.multiply(theta.multiply(theta.multiply(   21        ).add( -47          )).add(   36         )).add( -54     /   5.0)).add(1);
-        final T coeffDot2 =  getField().getZero();
+        final T coeffDot2 =  time.getField().getZero();
         final T coeffDot3 =  theta.multiply(theta.multiply(theta.multiply(theta.multiply(  112        ).add(-608    /  3.0)).add(  320   / 3.0 )).add(-208    /  15.0));
         final T coeffDot4 =  theta.multiply(theta.multiply(theta.multiply(theta.multiply( -567  /  5.0).add( 972    /  5.0)).add( -486   / 5.0 )).add( 324    /  25.0));
         final T coeffDot5 =  theta.multiply(theta.multiply(theta.multiply(theta.multiply(c5a.divide(5)).add(c5b.divide(15))).add(c5c.divide(30))).add(c5d.divide(150)));
@@ -198,9 +192,9 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
 
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
 
-            final T s         = theta.multiply(h);
+            final T s         = thetaH;
             final T coeff1    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(  21    /  5.0).add( -47    /  4.0)).add(   12         )).add( -27    /   5.0)).add(1));
-            final T coeff2    = getField().getZero();
+            final T coeff2    = time.getField().getZero();
             final T coeff3    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply( 112    /  5.0).add(-152    /  3.0)).add(  320   / 9.0 )).add(-104    /  15.0)));
             final T coeff4    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(-567    / 25.0).add( 243    /  5.0)).add( -162   / 5.0 )).add( 162    /  25.0)));
             final T coeff5    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(c5a.divide(25)).add(c5b.divide(60))).add(c5c.divide(90))).add(c5d.divide(300))));
@@ -212,7 +206,7 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
 
             final T s         = oneMinusThetaH;
             final T coeff1    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply( -21   /   5.0).add(   151  /  20.0)).add( -89   /   20.0)).add(  19 /  20.0)).add(- 1 / 20.0));
-            final T coeff2    = getField().getZero();
+            final T coeff2    = time.getField().getZero();
             final T coeff3    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(-112   /   5.0).add(   424  /  15.0)).add( -328  /   45.0)).add( -16 /  45.0)).add(-16 /  45.0));
             final T coeff4    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply( 567   /  25.0).add(  -648  /  25.0)).add(  162  /   25.0))));
             final T coeff5    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(d5a.divide(25)).add(d5b.divide(300))).add(d5c.divide(900))).add( -49 / 180.0)).add(-49 / 180.0));

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java
index 2a2e5e6..af5a867 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 
 /**
@@ -85,8 +86,14 @@ public class MidpointFieldIntegrator<T extends RealFieldElement<T>> extends Rung
     /** {@inheritDoc} */
     @Override
     protected MidpointFieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new MidpointFieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState,
+                           final FieldEquationsMapper<T> mapper) {
+        return new MidpointFieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                    globalPreviousState, globalCurrentState,
+                                                    globalPreviousState, globalCurrentState,
+                                                    mapper);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java
index 23e00b6..5a01a35 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java
@@ -54,44 +54,53 @@ class MidpointFieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
-    MidpointFieldStepInterpolator(Field<T> field, final boolean forward,
-                                  final FieldEquationsMapper<T> mapper) {
-        super(field, forward, mapper);
-    }
-
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    MidpointFieldStepInterpolator(final MidpointFieldStepInterpolator<T> interpolator) {
-        super(interpolator);
+    MidpointFieldStepInterpolator(final Field<T> field, final boolean forward,
+                                             final T[][] yDotK,
+                                             final FieldODEStateAndDerivative<T> globalPreviousState,
+                                             final FieldODEStateAndDerivative<T> globalCurrentState,
+                                             final FieldODEStateAndDerivative<T> softPreviousState,
+                                             final FieldODEStateAndDerivative<T> softCurrentState,
+                                             final FieldEquationsMapper<T> mapper) {
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
     }
 
     /** {@inheritDoc} */
-    @Override
-    protected MidpointFieldStepInterpolator<T> doCopy() {
-        return new MidpointFieldStepInterpolator<T>(this);
+    protected MidpointFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                      final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                      final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                      final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                      final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                      final FieldEquationsMapper<T> newMapper) {
+        return new MidpointFieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                    newGlobalPreviousState, newGlobalCurrentState,
+                                                    newSoftPreviousState, newSoftCurrentState,
+                                                    newMapper);
     }
 
-
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH) {
+                                                                                   final T thetaH, final T oneMinusThetaH) {
 
         final T coeffDot2 = theta.multiply(2);
-        final T coeffDot1 = getField().getOne().subtract(coeffDot2);
+        final T coeffDot1 = time.getField().getOne().subtract(coeffDot2);
         final T[] interpolatedState;
         final T[] interpolatedDerivatives;
 
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
             final T coeff1 = theta.multiply(oneMinusThetaH);
-            final T coeff2 = theta.multiply(theta).multiply(h);
+            final T coeff2 = theta.multiply(thetaH);
             interpolatedState       = previousStateLinearCombination(coeff1, coeff2);
             interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2);
         } else {


[20/50] [abbrv] [math] Added tests for the Higham-Hall 5(4) integrator.

Posted by lu...@apache.org.
Added tests for the Higham-Hall 5(4) integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/7fc003df
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/7fc003df
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/7fc003df

Branch: refs/heads/master
Commit: 7fc003df8e22a4dcd2f16f5634fb9d8263ff5d04
Parents: d6a8ed5
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:32 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:32 2016 +0100

----------------------------------------------------------------------
 .../HighamHall54FieldIntegratorTest.java        | 93 ++++++++++++++++++++
 .../HighamHall54FieldStepInterpolatorTest.java  | 49 +++++++++++
 2 files changed, 142 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/7fc003df/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
new file mode 100644
index 0000000..d24d286
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.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 {
+
+    protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance) {
+        return new HighamHall54FieldIntegrator<T>(field, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
+    }
+
+    protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) {
+        return new HighamHall54FieldIntegrator<T>(field, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
+    }
+
+    @Test
+    public void testNonFieldIntegratorConsistency() {
+        doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testSanityChecks() {
+        doTestSanityChecks(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testBackward() {
+        doTestBackward(Decimal64Field.getInstance(), 5.0e-7, 5.0e-7, 1.0e-12, "Higham-Hall 5(4)");
+    }
+
+    @Test
+    public void testKepler() {
+        doTestKepler(Decimal64Field.getInstance(), 1.5e-4);
+    }
+
+    @Override
+    public void testForwardBackwardExceptions() {
+        doTestForwardBackwardExceptions(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testMinStep() {
+        doTestMinStep(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testIncreasingTolerance() {
+        // 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
+        doTestIncreasingTolerance(Decimal64Field.getInstance(), 1.3, 1.0e-12);
+    }
+
+    @Override
+    public void testEvents() {
+        doTestEvents(Decimal64Field.getInstance(), 1.0e-7, "Higham-Hall 5(4)");
+    }
+
+    @Override
+    public void testEventsErrors() {
+        doTestEventsErrors(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testEventsNoConvergence() {
+        doTestEventsNoConvergence(Decimal64Field.getInstance());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/7fc003df/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
new file mode 100644
index 0000000..0d9180b
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class HighamHall54FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
+        return new HighamHall54FieldStepInterpolator<T>(field, forward, mapper);
+    }
+
+    @Test
+    public void interpolationAtBounds() {
+        doInterpolationAtBounds(Decimal64Field.getInstance(), 4.9e-16);
+    }
+
+    @Test
+    public void interpolationInside() {
+        doInterpolationInside(Decimal64Field.getInstance(), 4.0e-13, 2.7e-15);
+    }
+
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.0e-50, 1.0e-50, 1.0e-50);
+    }
+
+}


[18/50] [abbrv] [math] Set up a shared interface for Butcher arrays used by integrators.

Posted by lu...@apache.org.
Set up a shared interface for Butcher arrays used by integrators.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a2718fc3
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a2718fc3
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a2718fc3

Branch: refs/heads/master
Commit: a2718fc3a9bc54d5932214b07514446a2fe4c5bf
Parents: 87edfd2
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:27 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:27 2016 +0100

----------------------------------------------------------------------
 .../ClassicalRungeKuttaFieldIntegrator.java     |  6 +--
 .../DormandPrince54FieldIntegrator.java         |  6 +--
 .../DormandPrince853FieldIntegrator.java        |  6 +--
 .../DormandPrince853FieldStepInterpolator.java  |  2 +-
 .../EmbeddedRungeKuttaFieldIntegrator.java      | 18 +-------
 .../ode/nonstiff/EulerFieldIntegrator.java      |  6 +--
 .../ode/nonstiff/FieldButcherArrayProvider.java | 46 ++++++++++++++++++++
 .../math4/ode/nonstiff/GillFieldIntegrator.java |  6 +--
 .../nonstiff/HighamHall54FieldIntegrator.java   |  6 +--
 .../ode/nonstiff/LutherFieldIntegrator.java     |  6 +--
 .../ode/nonstiff/MidpointFieldIntegrator.java   |  6 +--
 .../ode/nonstiff/RungeKuttaFieldIntegrator.java | 18 +-------
 .../nonstiff/ThreeEighthesFieldIntegrator.java  |  6 +--
 ...ractRungeKuttaFieldStepInterpolatorTest.java | 28 ++++++------
 14 files changed, 91 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java
index 4bb0f61..a09c1fa 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegrator.java
@@ -62,7 +62,7 @@ public class ClassicalRungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
         final T[] c = MathArrays.buildArray(getField(), 3);
         c[0] = getField().getOne().multiply(0.5);
         c[1] = c[0];
@@ -72,7 +72,7 @@ public class ClassicalRungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
         final T[][] a = MathArrays.buildArray(getField(), 3, -1);
         for (int i = 0; i < a.length; ++i) {
             a[i] = MathArrays.buildArray(getField(), i + 1);
@@ -88,7 +88,7 @@ public class ClassicalRungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
         final T[] b = MathArrays.buildArray(getField(), 4);
         b[0] = fraction(1, 6);
         b[1] = fraction(1, 3);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
index a12453d..743dbe4 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
@@ -130,7 +130,7 @@ public class DormandPrince54FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
         final T[] c = MathArrays.buildArray(getField(), 6);
         c[0] = fraction(1,  5);
         c[1] = fraction(3, 10);
@@ -143,7 +143,7 @@ public class DormandPrince54FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
         final T[][] a = MathArrays.buildArray(getField(), 6, -1);
         for (int i = 0; i < a.length; ++i) {
             a[i] = MathArrays.buildArray(getField(), i + 1);
@@ -174,7 +174,7 @@ public class DormandPrince54FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
         final T[] b = MathArrays.buildArray(getField(), 7);
         b[0] = fraction(   35,   384);
         b[1] = getField().getZero();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
index de5adda..6c754d7 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
@@ -191,7 +191,7 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
 
         final T sqrt6 = getField().getOne().multiply(6).sqrt();
 
@@ -218,7 +218,7 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
 
         final T sqrt6 = getField().getOne().multiply(6).sqrt();
 
@@ -371,7 +371,7 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
         final T[] b = MathArrays.buildArray(getField(), 16);
         b[ 0] = fraction(104257, 1929240);
         b[ 1] = getField().getZero();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
index 5c548a3..6487ccf 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
@@ -52,7 +52,7 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
         super(field, forward, mapper);
 
         // interpolation weights
-        d = MathArrays.buildArray(getField(), 4, 16);
+        d = MathArrays.buildArray(getField(), 7, 16);
 
         // this row is the same as the b array
         d[0][ 0] = fraction(104257, 1929240);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
index 1f3e87c..13bb070 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
@@ -68,7 +68,8 @@ import org.apache.commons.math4.util.MathUtils;
  */
 
 public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
-    extends AdaptiveStepsizeFieldIntegrator<T> {
+    extends AdaptiveStepsizeFieldIntegrator<T>
+    implements FieldButcherArrayProvider<T> {
 
     /** Index of the pre-computed derivative for <i>fsal</i> methods. */
     private final int fsal;
@@ -180,21 +181,6 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
         return getField().getOne().multiply(p).divide(q);
     }
 
-    /** Get the time steps from Butcher array (without the first zero).
-     * @return time steps from Butcher array (without the first zero
-     */
-    protected abstract T[] getC();
-
-    /** Get the internal weights from Butcher array (without the first empty row).
-     * @return internal weights from Butcher array (without the first empty row)
-     */
-    protected abstract T[][] getA();
-
-    /** Get the external weights for the high order method from Butcher array.
-     * @return external weights for the high order method from Butcher array
-     */
-    protected abstract T[] getB();
-
     /** Create an interpolator.
      * @param forward integration direction indicator
      * @param mapper equations mapper for the all equations

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java
index c28e3fe..96403e5 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegrator.java
@@ -64,19 +64,19 @@ public class EulerFieldIntegrator<T extends RealFieldElement<T>> extends RungeKu
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
         return MathArrays.buildArray(getField(), 0);
     }
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
         return MathArrays.buildArray(getField(), 0, 0);
     }
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
         final T[] b = MathArrays.buildArray(getField(), 1);
         b[0] = getField().getOne();
         return b;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/FieldButcherArrayProvider.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/FieldButcherArrayProvider.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/FieldButcherArrayProvider.java
new file mode 100644
index 0000000..69b38bc
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/FieldButcherArrayProvider.java
@@ -0,0 +1,46 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+import org.apache.commons.math4.RealFieldElement;
+
+/** This interface represents an integrator  based on Butcher arrays.
+ * @see RungeKuttaFieldIntegrator
+ * @see EmbeddedRungeKuttaFieldIntegrator
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+
+public interface FieldButcherArrayProvider<T extends RealFieldElement<T>> {
+
+    /** Get the time steps from Butcher array (without the first zero).
+     * @return time steps from Butcher array (without the first zero
+     */
+    T[] getC();
+
+    /** Get the internal weights from Butcher array (without the first empty row).
+     * @return internal weights from Butcher array (without the first empty row)
+     */
+    T[][] getA();
+
+    /** Get the external weights for the high order method from Butcher array.
+     * @return external weights for the high order method from Butcher array
+     */
+    T[] getB();
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java
index cf1ce89..6996d05 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegrator.java
@@ -62,7 +62,7 @@ public class GillFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
         final T[] c = MathArrays.buildArray(getField(), 3);
         c[0] = fraction(1, 2);
         c[1] = c[0];
@@ -72,7 +72,7 @@ public class GillFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
 
         final T two     = getField().getZero().add(2);
         final T sqrtTwo = two.sqrt();
@@ -92,7 +92,7 @@ public class GillFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
 
         final T two     = getField().getZero().add(2);
         final T sqrtTwo = two.sqrt();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java
index c04e9c6..0e0c3b8 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegrator.java
@@ -105,7 +105,7 @@ public class HighamHall54FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
         final T[] c = MathArrays.buildArray(getField(), 6);
         c[0] = fraction(2, 9);
         c[1] = fraction(1, 3);
@@ -118,7 +118,7 @@ public class HighamHall54FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
         final T[][] a = MathArrays.buildArray(getField(), 6, -1);
         for (int i = 0; i < a.length; ++i) {
             a[i] = MathArrays.buildArray(getField(), i + 1);
@@ -149,7 +149,7 @@ public class HighamHall54FieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
         final T[] b = MathArrays.buildArray(getField(), 7);
         b[0] = fraction(  1, 12);
         b[1] = getField().getZero();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java
index 84acede..b8d78d9 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegrator.java
@@ -71,7 +71,7 @@ public class LutherFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
         final T q = getField().getZero().add(21).sqrt();
         final T[] c = MathArrays.buildArray(getField(), 6);
         c[0] = getField().getOne();
@@ -85,7 +85,7 @@ public class LutherFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
         final T q = getField().getZero().add(21).sqrt();
         final T[][] a = MathArrays.buildArray(getField(), 6, -1);
         for (int i = 0; i < a.length; ++i) {
@@ -117,7 +117,7 @@ public class LutherFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
 
         final T[] b = MathArrays.buildArray(getField(), 7);
         b[0] = fraction( 1,  20);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java
index a32a961..2a2e5e6 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegrator.java
@@ -59,7 +59,7 @@ public class MidpointFieldIntegrator<T extends RealFieldElement<T>> extends Rung
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
         final T[] c = MathArrays.buildArray(getField(), 1);
         c[0] = getField().getOne().multiply(0.5);
         return c;
@@ -67,7 +67,7 @@ public class MidpointFieldIntegrator<T extends RealFieldElement<T>> extends Rung
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
         final T[][] a = MathArrays.buildArray(getField(), 1, 1);
         a[0][0] = fraction(1, 2);
         return a;
@@ -75,7 +75,7 @@ public class MidpointFieldIntegrator<T extends RealFieldElement<T>> extends Rung
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
         final T[] b = MathArrays.buildArray(getField(), 2);
         b[0] = getField().getZero();
         b[1] = getField().getOne();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
index d6f9026..3a5f9aa 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
@@ -58,7 +58,8 @@ import org.apache.commons.math4.util.MathArrays;
  */
 
 public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
-    extends AbstractFieldIntegrator<T> {
+    extends AbstractFieldIntegrator<T>
+    implements FieldButcherArrayProvider<T> {
 
     /** Time steps from Butcher array (without the first zero). */
     private final T[] c;
@@ -96,21 +97,6 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
         return getField().getZero().add(p).divide(q);
     }
 
-    /** Get the time steps from Butcher array (without the first zero).
-     * @return time steps from Butcher array (without the first zero
-     */
-    protected abstract T[] getC();
-
-    /** Get the internal weights from Butcher array (without the first empty row).
-     * @return internal weights from Butcher array (without the first empty row)
-     */
-    protected abstract T[][] getA();
-
-    /** Get the external weights for the high order method from Butcher array.
-     * @return external weights for the high order method from Butcher array
-     */
-    protected abstract T[] getB();
-
     /** Create an interpolator.
      * @param forward integration direction indicator
      * @param mapper equations mapper for the all equations

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
index e5bd0bc..b826290 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
@@ -61,7 +61,7 @@ public class ThreeEighthesFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getC() {
+    public T[] getC() {
         final T[] c = MathArrays.buildArray(getField(), 3);
         c[0] = fraction(1, 3);
         c[1] = c[0].add(c[0]);
@@ -71,7 +71,7 @@ public class ThreeEighthesFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[][] getA() {
+    public T[][] getA() {
         final T[][] a = MathArrays.buildArray(getField(), 3, -1);
         for (int i = 0; i < a.length; ++i) {
             a[i] = MathArrays.buildArray(getField(), i + 1);
@@ -87,7 +87,7 @@ public class ThreeEighthesFieldIntegrator<T extends RealFieldElement<T>>
 
     /** {@inheritDoc} */
     @Override
-    protected T[] getB() {
+    public T[] getB() {
         final T[] b = MathArrays.buildArray(getField(), 4);
         b[0] = fraction(1, 8);
         b[1] = fraction(3, 8);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2718fc3/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index a692717..6dfdeab 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -140,10 +140,10 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
         RungeKuttaFieldStepInterpolator<T> interpolator = createInterpolator(field, t1 > t0,
                                                                              new FieldExpandableODE<T>(eqn).getMapper());
         // get the Butcher arrays from the field integrator
-        RungeKuttaFieldIntegrator<T> fieldIntegrator = createFieldIntegrator(field, interpolator);
-        T[][] a = fieldIntegrator.getA();
-        T[]   b = fieldIntegrator.getB();
-        T[]   c = fieldIntegrator.getC();
+        FieldButcherArrayProvider<T> provider = createButcherArrayProvider(field, interpolator);
+        T[][] a = provider.getA();
+        T[]   b = provider.getB();
+        T[]   c = provider.getC();
 
         // store initial state
         T     t          = field.getZero().add(t0);
@@ -259,25 +259,23 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     }
 
-    private <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
-    createFieldIntegrator(final Field<T> field, final RungeKuttaFieldStepInterpolator<T> interpolator) {
-        RungeKuttaFieldIntegrator<T> integrator = null;
+    private <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field, final RungeKuttaFieldStepInterpolator<T> provider) {
+        FieldButcherArrayProvider<T> integrator = null;
         try {
-        String interpolatorName = interpolator.getClass().getName();
+        String interpolatorName = provider.getClass().getName();
         String integratorName = interpolatorName.replaceAll("StepInterpolator", "Integrator");
             @SuppressWarnings("unchecked")
-            Class<RungeKuttaFieldIntegrator<T>> clz = (Class<RungeKuttaFieldIntegrator<T>>) Class.forName(integratorName);
+            Class<FieldButcherArrayProvider<T>> clz = (Class<FieldButcherArrayProvider<T>>) Class.forName(integratorName);
             try {
                 integrator = clz.getConstructor(Field.class, RealFieldElement.class).
-                             newInstance(field, field.getOne());
+                                                newInstance(field, field.getOne());
             } catch (NoSuchMethodException nsme) {
                 try {
                     integrator = clz.getConstructor(Field.class,
-                                                    RealFieldElement.class,
-                                                    RealFieldElement.class,
-                                                    RealFieldElement.class).
-                                 newInstance(field, field.getZero().add(0.001),
-                                             field.getOne(), field.getOne(), field.getOne());
+                                                    Double.TYPE, Double.TYPE,
+                                                    Double.TYPE, Double.TYPE).
+                                 newInstance(field, 0.001, 1.0, 1.0, 1.0);
                 } catch (NoSuchMethodException e) {
                     Assert.fail(e.getLocalizedMessage());
                 }


[22/50] [abbrv] [math] Added tests for the Dormand-Prince 8(5, 3) integrator.

Posted by lu...@apache.org.
Added tests for the Dormand-Prince 8(5,3) integrator.

BEWARE! These test do not pass yet. The integrator is currently not
consistent with the regular double-based integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/f3cdf561
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/f3cdf561
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/f3cdf561

Branch: refs/heads/master
Commit: f3cdf561fd06b177a0b602b3ae6d6e845788c6bd
Parents: 2e4b80f
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:34 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:34 2016 +0100

----------------------------------------------------------------------
 .../DormandPrince853FieldIntegratorTest.java    | 93 ++++++++++++++++++++
 ...rmandPrince853FieldStepInterpolatorTest.java | 49 +++++++++++
 2 files changed, 142 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/f3cdf561/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
new file mode 100644
index 0000000..47a59ba
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.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 {
+
+    protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance) {
+        return new DormandPrince853FieldIntegrator<T>(field, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
+    }
+
+    protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) {
+        return new DormandPrince853FieldIntegrator<T>(field, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
+    }
+
+    @Test
+    public void testNonFieldIntegratorConsistency() {
+        doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testSanityChecks() {
+        doTestSanityChecks(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testBackward() {
+        doTestBackward(Decimal64Field.getInstance(), 1.1e-7, 1.1e-7, 1.0e-12, "Dormand-Prince 8 (5, 3)");
+    }
+
+    @Test
+    public void testKepler() {
+        doTestKepler(Decimal64Field.getInstance(), 2.4e-10);
+    }
+
+    @Override
+    public void testForwardBackwardExceptions() {
+        doTestForwardBackwardExceptions(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testMinStep() {
+        doTestMinStep(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testIncreasingTolerance() {
+        // 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
+        doTestIncreasingTolerance(Decimal64Field.getInstance(), 1.3, 1.0e-12);
+    }
+
+    @Override
+    public void testEvents() {
+        doTestEvents(Decimal64Field.getInstance(), 2.1e-7, "Dormand-Prince 8 (5, 3)");
+    }
+
+    @Override
+    public void testEventsErrors() {
+        doTestEventsErrors(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testEventsNoConvergence() {
+        doTestEventsNoConvergence(Decimal64Field.getInstance());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/f3cdf561/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
new file mode 100644
index 0000000..1aec284
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class DormandPrince853FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
+        return new DormandPrince853FieldStepInterpolator<T>(field, forward, mapper);
+    }
+
+    @Test
+    public void interpolationAtBounds() {
+        doInterpolationAtBounds(Decimal64Field.getInstance(), 1.0e-50);
+    }
+
+    @Test
+    public void interpolationInside() {
+        doInterpolationInside(Decimal64Field.getInstance(), 1.0e-50, 1.0e-50);
+    }
+
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.0e-50, 1.0e-50, 1.0e-50, 1.0e-50);
+    }
+
+}


[29/50] [abbrv] [math] Notify availability of field-based ode.

Posted by lu...@apache.org.
Notify availability of field-based ode.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/c246b37d
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/c246b37d
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/c246b37d

Branch: refs/heads/master
Commit: c246b37dbe38b16ded570b2280af8f21fb95618a
Parents: 11df45b
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:20:25 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:20:25 2016 +0100

----------------------------------------------------------------------
 src/site/xdoc/userguide/ode.xml | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/c246b37d/src/site/xdoc/userguide/ode.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/userguide/ode.xml b/src/site/xdoc/userguide/ode.xml
index b2fe395..3dc48bc 100644
--- a/src/site/xdoc/userguide/ode.xml
+++ b/src/site/xdoc/userguide/ode.xml
@@ -69,11 +69,27 @@
           derivatives being handled be secondary ODE (see below for an example).
         </p>
         <p>
+         Two parallel APIs are available. The first is devoted to solve ode for which the integration free
+         variable t and the state y(t) are primitive double and primitive double array respectively. Starting
+         with version 3.6, a second API is devoted to solve ode for which the integration free
+         variable t and the state y(t) are <code>RealFieldElement</code> and <code>RealFieldElement</code>
+         array respectively. This allow for example users to integrate ode where the computation values
+         are for example <code>DerivativeStructure</code> elements, hence automatically computing
+         partial derivatives with respect to some equations parameters without a need to set up the
+         variational equations. Another example is to use <code>Dfp</code> elements in order to solve
+         ode with extended precision. As of 3.6, the API are slightly different, mainly in the way they
+         handle arrays. Both API will become more similar in 4.0 and future versions as the older
+         primitive double API will be modified to match the newer field API. This cannot be done in
+         3.6 for compatibility reasons.
+        </p>
+        <p>
           The user should describe his problem in his own classes which should implement the
           <a href="../apidocs/org/apache/commons/math4/ode/FirstOrderDifferentialEquations.html">FirstOrderDifferentialEquations</a>
-          interface. Then he should pass it to the integrator he prefers among all the classes that implement
+          interface (or  <a href="../apidocs/org/apache/commons/math4/ode/FieldFirstOrderDifferentialEquations.html">FieldFirstOrderDifferentialEquations</a>
+          interface). Then he should pass it to the integrator he prefers among all the classes that implement
           the <a href="../apidocs/org/apache/commons/math4/ode/FirstOrderIntegrator.html">FirstOrderIntegrator</a>
-          interface. The following example shows how to implement the simple two-dimensional problem:
+          interface (or the <a href="../apidocs/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.html">FieldFirstOrderIntegrator</a>
+          interface). The following example shows how to implement the simple two-dimensional problem using double primitives:
           <ul>
             <li>y'<sub>0</sub>(t) = &#x3c9; &#xD7; (c<sub>1</sub> - y<sub>1</sub>(t))</li>
             <li>y'<sub>1</sub>(t) = &#x3c9; &#xD7; (y<sub>0</sub>(t) - c<sub>0</sub>)</li>


[21/50] [abbrv] [math] Added tests for the Dormand-Prince 5(4) integrator.

Posted by lu...@apache.org.
Added tests for the Dormand-Prince 5(4) integrator.

BEWARE! These test do not pass yet. The integrator is currently not
consistent with the regular double-based integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/2e4b80f8
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/2e4b80f8
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/2e4b80f8

Branch: refs/heads/master
Commit: 2e4b80f86606e8ee3e363ad4860afdd50503374c
Parents: 7fc003d
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:33 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:33 2016 +0100

----------------------------------------------------------------------
 .../DormandPrince54FieldIntegratorTest.java     | 93 ++++++++++++++++++++
 ...ormandPrince54FieldStepInterpolatorTest.java | 49 +++++++++++
 2 files changed, 142 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/2e4b80f8/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
new file mode 100644
index 0000000..4015ffe
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.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 {
+
+    protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance) {
+        return new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
+    }
+
+    protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) {
+        return new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
+    }
+
+    @Test
+    public void testNonFieldIntegratorConsistency() {
+        doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testSanityChecks() {
+        doTestSanityChecks(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testBackward() {
+        doTestBackward(Decimal64Field.getInstance(), 2.0e-7, 2.0e-7, 1.0e-12, "Dormand-Prince 5(4)");
+    }
+
+    @Test
+    public void testKepler() {
+        doTestKepler(Decimal64Field.getInstance(), 7.0e-10);
+    }
+
+    @Override
+    public void testForwardBackwardExceptions() {
+        doTestForwardBackwardExceptions(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testMinStep() {
+        doTestMinStep(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testIncreasingTolerance() {
+        // 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
+        doTestIncreasingTolerance(Decimal64Field.getInstance(), 0.7, 1.0e-12);
+    }
+
+    @Override
+    public void testEvents() {
+        doTestEvents(Decimal64Field.getInstance(), 5.0e-6, "Dormand-Prince 5(4)");
+    }
+
+    @Override
+    public void testEventsErrors() {
+        doTestEventsErrors(Decimal64Field.getInstance());
+    }
+
+    @Override
+    public void testEventsNoConvergence() {
+        doTestEventsNoConvergence(Decimal64Field.getInstance());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/2e4b80f8/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
new file mode 100644
index 0000000..9facccd
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class DormandPrince54FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
+        return new DormandPrince54FieldStepInterpolator<T>(field, forward, mapper);
+    }
+
+    @Test
+    public void interpolationAtBounds() {
+        doInterpolationAtBounds(Decimal64Field.getInstance(), 1.0e-50);
+    }
+
+    @Test
+    public void interpolationInside() {
+        doInterpolationInside(Decimal64Field.getInstance(), 4.0e-13, 2.7e-15);
+    }
+
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 4.2e-17, 2.3e-16, 6.7e-16, 8.4e-17);
+    }
+
+}


[14/50] [abbrv] [math] Fixed a parenthesis error in Higham-Hall 5(4) step interpolator.

Posted by lu...@apache.org.
Fixed a parenthesis error in Higham-Hall 5(4) step interpolator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/9e230797
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/9e230797
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/9e230797

Branch: refs/heads/master
Commit: 9e2307974840d5d20e4a590bbad9fc0514ac425d
Parents: 235a091
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:23 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:23 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/9e230797/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
index cc1b3c0..c278043 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
@@ -84,7 +84,7 @@ class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
             final T b2 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(135.0 / 8.0).add(-243.0 /  8.0)).add(459.0 / 32.0)));
             final T b3 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(-30.0      ).add( 152.0 /  3.0)).add(-22.0       )));
             final T b4 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(125.0 / 8.0).add(-625.0 / 24.0)).add(375.0 / 32.0)));
-            final T b5 = hTheta.multiply(theta.multiply(theta.multiply(                                   5.0 / 12.0)).add( -5.0 / 16.0));
+            final T b5 = hTheta.multiply(theta.multiply(theta.multiply(                                   5.0 / 12.0 ).add( -5.0 / 16.0)));
             interpolatedState       = previousStateLinearCombination(b0, b1, b2, b3, b4, b5);
             interpolatedDerivatives = derivativeLinearCombination(bDot0, bDot1, bDot2, bDot3, bDot4, bDot5);
         } else {


[05/50] [abbrv] [math] Fixed single integration step in step.

Posted by lu...@apache.org.
Fixed single integration step in step.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/5246aa05
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/5246aa05
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/5246aa05

Branch: refs/heads/master
Commit: 5246aa0529add36a2fba243dc23a8edb0ff61094
Parents: 548dfd8
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:11 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:11 2016 +0100

----------------------------------------------------------------------
 ...ractRungeKuttaFieldStepInterpolatorTest.java | 74 +++++++++++---------
 1 file changed, 41 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/5246aa05/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index 3e63c34..0ca38aa 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -95,37 +95,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
         RungeKuttaFieldStepInterpolator<T> interpolator = createInterpolator(field, t1 > t0,
                                                                              new FieldExpandableODE<T>(eqn).getMapper());
         // get the Butcher arrays from the field integrator
-        String interpolatorName = interpolator.getClass().getName();
-        String integratorName = interpolatorName.replaceAll("StepInterpolator", "Integrator");
-
-        RungeKuttaFieldIntegrator<T> fieldIntegrator = null;
-        try {
-            @SuppressWarnings("unchecked")
-            Class<RungeKuttaFieldIntegrator<T>> clz = (Class<RungeKuttaFieldIntegrator<T>>) Class.forName(integratorName);
-            try {
-                fieldIntegrator = clz.getConstructor(Field.class, RealFieldElement.class).newInstance(field,
-                                                                                                      field.getOne());
-            } catch (NoSuchMethodException nsme) {
-                try {
-                    fieldIntegrator = clz.getConstructor(Field.class, RealFieldElement.class,
-                                                         RealFieldElement.class, RealFieldElement.class).newInstance(field,
-                                                                                                                     field.getZero().add(0.001),
-                                                                                                                     field.getOne(),
-                                                                                                                     field.getOne(),
-                                                                                                                     field.getOne());
-                } catch (NoSuchMethodException e) {
-                    Assert.fail(e.getLocalizedMessage());
-                }
-            }
-        } catch (InvocationTargetException ite) {
-            Assert.fail(ite.getLocalizedMessage());
-        } catch (IllegalAccessException iae) {
-            Assert.fail(iae.getLocalizedMessage());
-        } catch (InstantiationException ie) {
-            Assert.fail(ie.getLocalizedMessage());
-        } catch (ClassNotFoundException cnfe) {
-            Assert.fail(cnfe.getLocalizedMessage());
-        }
+        RungeKuttaFieldIntegrator<T> fieldIntegrator = createFieldIntegrator(field, interpolator);
         T[][] a = fieldIntegrator.getA();
         T[]   b = fieldIntegrator.getB();
         T[]   c = fieldIntegrator.getC();
@@ -146,8 +116,8 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
         for (int k = 0; k < a.length; ++k) {
             for (int i = 0; i < y0.length; ++i) {
                 fieldY[i] = field.getZero().add(y0[i]);
-                for (int s = 0; s < k; ++s) {
-                    fieldY[i] = fieldY[i].add(h.multiply(a[s][i].multiply(fieldYDotK[s][i])));
+                for (int s = 0; s <= k; ++s) {
+                    fieldY[i] = fieldY[i].add(h.multiply(a[k][s].multiply(fieldYDotK[s][i])));
                 }
             }
             fieldYDotK[k + 1] = eqn.computeDerivatives(h.multiply(c[k]).add(t0), fieldY);
@@ -169,6 +139,44 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     }
 
+    private <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
+    createFieldIntegrator(final Field<T> field, final RungeKuttaFieldStepInterpolator<T> interpolator) {
+        RungeKuttaFieldIntegrator<T> integrator = null;
+        try {
+        String interpolatorName = interpolator.getClass().getName();
+        String integratorName = interpolatorName.replaceAll("StepInterpolator", "Integrator");
+            @SuppressWarnings("unchecked")
+            Class<RungeKuttaFieldIntegrator<T>> clz = (Class<RungeKuttaFieldIntegrator<T>>) Class.forName(integratorName);
+            try {
+                integrator = clz.getConstructor(Field.class, RealFieldElement.class).newInstance(field,
+                                                                                                      field.getOne());
+            } catch (NoSuchMethodException nsme) {
+                try {
+                    integrator = clz.getConstructor(Field.class,
+                                                    RealFieldElement.class,
+                                                    RealFieldElement.class,
+                                                    RealFieldElement.class).
+                                 newInstance(field, field.getZero().add(0.001),
+                                             field.getOne(), field.getOne(), field.getOne());
+                } catch (NoSuchMethodException e) {
+                    Assert.fail(e.getLocalizedMessage());
+                }
+            }
+
+        } catch (InvocationTargetException ite) {
+            Assert.fail(ite.getLocalizedMessage());
+        } catch (IllegalAccessException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (InstantiationException ie) {
+            Assert.fail(ie.getLocalizedMessage());
+        } catch (ClassNotFoundException cnfe) {
+            Assert.fail(cnfe.getLocalizedMessage());
+        }
+
+        return integrator;
+
+    }
+
     private static class SinCos<T extends RealFieldElement<T>> implements FieldFirstOrderDifferentialEquations<T> {
         private final Field<T> field;
         protected SinCos(final Field<T> field) {


[17/50] [abbrv] [math] Set up test framework for field-based embedded Runge-Kutta integrators.

Posted by lu...@apache.org.
Set up test framework for field-based embedded Runge-Kutta integrators.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/87edfd27
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/87edfd27
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/87edfd27

Branch: refs/heads/master
Commit: 87edfd2751ba8bf84f15aa1df288722c36ffcbf0
Parents: 7a5431e
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:26 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:26 2016 +0100

----------------------------------------------------------------------
 ...ctEmbeddedRungeKuttaFieldIntegratorTest.java | 445 +++++++++++++++++++
 1 file changed, 445 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/87edfd27/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
new file mode 100644
index 0000000..357d92a
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
@@ -0,0 +1,445 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+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.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
+import org.apache.commons.math4.ode.FieldFirstOrderIntegrator;
+import org.apache.commons.math4.ode.FieldODEState;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.TestFieldProblem1;
+import org.apache.commons.math4.ode.TestFieldProblem3;
+import org.apache.commons.math4.ode.TestFieldProblem4;
+import org.apache.commons.math4.ode.TestFieldProblem5;
+import org.apache.commons.math4.ode.TestFieldProblemHandler;
+import org.apache.commons.math4.ode.events.Action;
+import org.apache.commons.math4.ode.events.FieldEventHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
+
+    protected abstract <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance) ;
+
+    protected abstract <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance);
+
+    @Test
+    public abstract void testNonFieldIntegratorConsistency();
+
+    protected <T extends RealFieldElement<T>> void doTestNonFieldIntegratorConsistency(final Field<T> field) {
+        try {
+
+            // get the Butcher arrays from the field integrator
+            EmbeddedRungeKuttaFieldIntegrator<T> fieldIntegrator = createIntegrator(field, 0.001, 1.0, 1.0, 1.0);
+            T[][] fieldA = fieldIntegrator.getA();
+            T[]   fieldB = fieldIntegrator.getB();
+            T[]   fieldC = fieldIntegrator.getC();
+
+            String fieldName   = fieldIntegrator.getClass().getName();
+            String regularName = fieldName.replaceAll("Field", "");
+
+            // get the Butcher arrays from the regular integrator
+            @SuppressWarnings("unchecked")
+            Class<RungeKuttaIntegrator> c = (Class<RungeKuttaIntegrator>) Class.forName(regularName);
+            java.lang.reflect.Field jlrFieldA = c.getDeclaredField("STATIC_A");
+            jlrFieldA.setAccessible(true);
+            double[][] regularA = (double[][]) jlrFieldA.get(null);
+            java.lang.reflect.Field jlrFieldB = c.getDeclaredField("STATIC_B");
+            jlrFieldB.setAccessible(true);
+            double[]   regularB = (double[])   jlrFieldB.get(null);
+            java.lang.reflect.Field jlrFieldC = c.getDeclaredField("STATIC_C");
+            jlrFieldC.setAccessible(true);
+            double[]   regularC = (double[])   jlrFieldC.get(null);
+
+            Assert.assertEquals(regularA.length, fieldA.length);
+            for (int i = 0; i < regularA.length; ++i) {
+                checkArray(regularA[i], fieldA[i]);
+            }
+            checkArray(regularB, fieldB);
+            checkArray(regularC, fieldC);
+
+        } catch (ClassNotFoundException cnfe) {
+            Assert.fail(cnfe.getLocalizedMessage());
+        } catch (IllegalAccessException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (IllegalArgumentException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (SecurityException se) {
+            Assert.fail(se.getLocalizedMessage());
+        } catch (NoSuchFieldException nsfe) {
+            Assert.fail(nsfe.getLocalizedMessage());
+        }
+    }
+
+    private <T extends RealFieldElement<T>> void checkArray(double[] regularArray, T[] fieldArray) {
+        Assert.assertEquals(regularArray.length, fieldArray.length);
+        for (int i = 0; i < regularArray.length; ++i) {
+            if (regularArray[i] == 0) {
+                Assert.assertTrue(0.0 == fieldArray[i].getReal());
+            } else {
+                Assert.assertEquals(regularArray[i], fieldArray[i].getReal(), FastMath.ulp(regularArray[i]));
+            }
+        }
+    }
+
+    @Test
+    public abstract void testForwardBackwardExceptions();
+
+    protected <T extends RealFieldElement<T>> void doTestForwardBackwardExceptions(final Field<T> field) {
+        FieldFirstOrderDifferentialEquations<T> equations = new FieldFirstOrderDifferentialEquations<T>() {
+
+            public int getDimension() {
+                return 1;
+            }
+
+            public void init(T t0, T[] y0, T t) {
+            }
+
+            public T[] computeDerivatives(T t, T[] y) {
+                if (t.getReal() < -0.5) {
+                    throw new LocalException();
+                } else {
+                    throw new RuntimeException("oops");
+                }
+            }
+        };
+
+        EmbeddedRungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, 0.0, 1.0, 1.0e-10, 1.0e-10);
+
+        try  {
+            integrator.integrate(new FieldExpandableODE<>(equations),
+                                 new FieldODEState<T>(field.getOne().negate(),
+                                                      MathArrays.buildArray(field, 1)),
+                                 field.getZero());
+            Assert.fail("an exception should have been thrown");
+          } catch(LocalException de) {
+            // expected behavior
+          }
+
+          try  {
+              integrator.integrate(new FieldExpandableODE<>(equations),
+                                   new FieldODEState<T>(field.getZero(),
+                                                        MathArrays.buildArray(field, 1)),
+                                   field.getOne());
+               Assert.fail("an exception should have been thrown");
+          } catch(RuntimeException de) {
+            // expected behavior
+          }
+    }
+
+    protected static class LocalException extends RuntimeException {
+        private static final long serialVersionUID = 20151208L;
+    }
+
+    @Test(expected=NumberIsTooSmallException.class)
+    public abstract void testMinStep();
+
+    protected <T extends RealFieldElement<T>> void doTestMinStep(final Field<T> field)
+        throws NumberIsTooSmallException {
+
+        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        double minStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.1).getReal();
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
+        double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
+
+        FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                              vecAbsoluteTolerance, vecRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+        Assert.fail("an exception should have been thrown");
+
+    }
+
+    @Test
+    public abstract void testIncreasingTolerance();
+
+    protected <T extends RealFieldElement<T>> void doTestIncreasingTolerance(final Field<T> field,
+                                                                             double factor,
+                                                                             double epsilon) {
+
+        int previousCalls = Integer.MAX_VALUE;
+        for (int i = -12; i < -2; ++i) {
+            TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+            double minStep = 0;
+            double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+            double scalAbsoluteTolerance = FastMath.pow(10.0, i);
+            double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+            FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                                  scalAbsoluteTolerance, scalRelativeTolerance);
+            TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+            integ.addStepHandler(handler);
+            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+            Assert.assertTrue(handler.getMaximalValueError().getReal() < (factor * scalAbsoluteTolerance));
+            Assert.assertEquals(0, handler.getMaximalTimeError().getReal(), epsilon);
+
+            int calls = pb.getCalls();
+            Assert.assertEquals(integ.getEvaluations(), calls);
+            Assert.assertTrue(calls <= previousCalls);
+            previousCalls = calls;
+
+        }
+
+    }
+
+    @Test
+    public abstract void testEvents();
+
+    protected <T extends RealFieldElement<T>> void doTestEvents(final Field<T> field,
+                                                                final double epsilonMaxValue,
+                                                                final String name) {
+
+      TestFieldProblem4<T> pb = new TestFieldProblem4<T>(field);
+      double minStep = 0;
+      double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+      double scalAbsoluteTolerance = 1.0e-8;
+      double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+      FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                            scalAbsoluteTolerance, scalRelativeTolerance);
+      TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+      integ.addStepHandler(handler);
+      FieldEventHandler<T>[] functions = pb.getEventsHandlers();
+      double convergence = 1.0e-8 * maxStep;
+      for (int l = 0; l < functions.length; ++l) {
+          integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, convergence, 1000);
+      }
+      Assert.assertEquals(functions.length, integ.getEventHandlers().size());
+      integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+      Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
+      Assert.assertEquals(0, handler.getMaximalTimeError().getReal(), convergence);
+      Assert.assertEquals(12.0, handler.getLastTime().getReal(), convergence);
+      Assert.assertEquals(name, integ.getName());
+      integ.clearEventHandlers();
+      Assert.assertEquals(0, integ.getEventHandlers().size());
+
+    }
+
+    @Test(expected=LocalException.class)
+    public abstract void testEventsErrors();
+
+    protected <T extends RealFieldElement<T>> void doTestEventsErrors(final Field<T> field)
+        throws LocalException {
+        final TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double scalAbsoluteTolerance = 1.0e-8;
+        double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+        FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                              scalAbsoluteTolerance, scalRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+
+        integ.addEventHandler(new FieldEventHandler<T>() {
+          public void init(FieldODEStateAndDerivative<T> state0, T t) {
+          }
+          public Action eventOccurred(FieldODEStateAndDerivative<T> state, boolean increasing) {
+            return Action.CONTINUE;
+          }
+          public T g(FieldODEStateAndDerivative<T> state) {
+            T middle = pb.getInitialState().getTime().add(pb.getFinalTime()).multiply(0.5);
+            T offset = state.getTime().subtract(middle);
+            if (offset.getReal() > 0) {
+              throw new LocalException();
+            }
+            return offset;
+          }
+          public FieldODEState<T> resetState(FieldODEStateAndDerivative<T> state) {
+              return state;
+          }
+        }, Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000);
+
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+    }
+
+    @Test
+    public abstract void testEventsNoConvergence();
+
+    protected <T extends RealFieldElement<T>> void doTestEventsNoConvergence(final Field<T> field){
+
+        final TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double scalAbsoluteTolerance = 1.0e-8;
+        double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+        FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                              scalAbsoluteTolerance, scalRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+
+        integ.addEventHandler(new FieldEventHandler<T>() {
+            public void init(FieldODEStateAndDerivative<T> state0, T t) {
+            }
+            public Action eventOccurred(FieldODEStateAndDerivative<T> state, boolean increasing) {
+                return Action.CONTINUE;
+            }
+            public T g(FieldODEStateAndDerivative<T> state) {
+                T middle = pb.getInitialState().getTime().add(pb.getFinalTime()).multiply(0.5);
+                T offset = state.getTime().subtract(middle);
+                return (offset.getReal() > 0) ? offset.add(0.5) : offset.subtract(0.5);
+            }
+            public FieldODEState<T> resetState(FieldODEStateAndDerivative<T> state) {
+                return state;
+            }
+        }, Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 3);
+
+        try {
+            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+            Assert.fail("an exception should have been thrown");
+        } catch (MaxCountExceededException mcee) {
+            // Expected.
+        }
+
+    }
+
+    @Test
+    public abstract void testSanityChecks();
+
+    protected <T extends RealFieldElement<T>> void doTestSanityChecks(Field<T> field) {
+        TestFieldProblem3<T> pb = new TestFieldProblem3<T>(field);
+        try  {
+            EmbeddedRungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, 0,
+                                                                               pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
+                                                                               new double[4], new double[4]);
+            integrator.integrate(new FieldExpandableODE<>(pb),
+                                 new FieldODEState<T>(pb.getInitialState().getTime(),
+                                                      MathArrays.buildArray(field, 6)),
+                                 pb.getFinalTime());
+            Assert.fail("an exception should have been thrown");
+        } catch(DimensionMismatchException ie) {
+        }
+        try  {
+            EmbeddedRungeKuttaFieldIntegrator<T> integrator =
+                            createIntegrator(field, 0,
+                                             pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
+                                             new double[2], new double[4]);
+            integrator.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+            Assert.fail("an exception should have been thrown");
+        } catch(DimensionMismatchException ie) {
+        }
+        try  {
+            EmbeddedRungeKuttaFieldIntegrator<T> integrator =
+                            createIntegrator(field, 0,
+                                             pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
+                                             new double[4], new double[4]);
+            integrator.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getInitialState().getTime());
+            Assert.fail("an exception should have been thrown");
+        } catch(NumberIsTooSmallException ie) {
+        }
+    }
+
+    @Test
+    public abstract void testBackward();
+
+    protected <T extends RealFieldElement<T>> void doTestBackward(Field<T> field,
+                                                                  final double espilonLast,
+                                                                  final double epsilonMaxValue,
+                                                                  final double epsilonMaxTime,
+                                                                  final String name)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+
+        TestFieldProblem5<T> pb = new TestFieldProblem5<T>(field);
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).abs().getReal();
+        double scalAbsoluteTolerance = 1.0e-8;
+        double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+        EmbeddedRungeKuttaFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                                      scalAbsoluteTolerance,
+                                                                      scalRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+
+        Assert.assertEquals(0, handler.getLastError().getReal(),         espilonLast);
+        Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
+        Assert.assertEquals(0, handler.getMaximalTimeError().getReal(),  epsilonMaxTime);
+        Assert.assertEquals(name, integ.getName());
+
+    }
+
+    @Test
+    public abstract void testKepler();
+
+    protected <T extends RealFieldElement<T>> void doTestKepler(Field<T> field, double epsilon) {
+
+        final TestFieldProblem3<T> pb  = new TestFieldProblem3<T>(field, field.getZero().add(0.9));
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double[] vecAbsoluteTolerance = { 1.0e-8, 1.0e-8, 1.0e-10, 1.0e-10 };
+        double[] vecRelativeTolerance = { 1.0e-10, 1.0e-10, 1.0e-8, 1.0e-8 };
+
+        FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                              vecAbsoluteTolerance, vecRelativeTolerance);
+        integ.addStepHandler(new KeplerHandler<T>(pb, epsilon));
+        integ.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+    }
+
+    private static class KeplerHandler<T extends RealFieldElement<T>> implements FieldStepHandler<T> {
+        private T maxError;
+        private final TestFieldProblem3<T> pb;
+        private final double epsilon;
+        public KeplerHandler(TestFieldProblem3<T> pb, double epsilon) {
+            this.pb      = pb;
+            this.epsilon = epsilon;
+            maxError = pb.getField().getZero();
+        }
+        public void init(FieldODEStateAndDerivative<T> state0, T t) {
+            maxError = pb.getField().getZero();
+        }
+        public void handleStep(FieldStepInterpolator<T> interpolator, boolean isLast)
+                        throws MaxCountExceededException {
+
+            FieldODEStateAndDerivative<T> current = interpolator.getCurrentState();
+            T[] theoreticalY  = pb.computeTheoreticalState(current.getTime());
+            T dx = current.getState()[0].subtract(theoreticalY[0]);
+            T dy = current.getState()[1].subtract(theoreticalY[1]);
+            T error = dx.multiply(dx).add(dy.multiply(dy));
+            if (error.subtract(maxError).getReal() > 0) {
+                maxError = error;
+            }
+            if (isLast) {
+                Assert.assertEquals(0.0, maxError.getReal(), epsilon);
+            }
+        }
+    }
+
+}


[39/50] [abbrv] [math] Renamed interfaces for consistency with other classes.

Posted by lu...@apache.org.
Renamed interfaces for consistency with other classes.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/346a81d7
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/346a81d7
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/346a81d7

Branch: refs/heads/master
Commit: 346a81d770fcd5e7e401a8d1daa42acf6493c2f8
Parents: 0aa826e
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:15:09 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:15:09 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/AbstractFieldIntegrator.java      |   2 +-
 .../commons/math4/ode/FieldExpandableODE.java   |   8 +-
 .../FieldFirstOrderDifferentialEquations.java   |  73 -------
 .../math4/ode/FieldFirstOrderIntegrator.java    | 188 -------------------
 .../apache/commons/math4/ode/FieldODEState.java |   4 +-
 .../math4/ode/FieldODEStateAndDerivative.java   |   4 +-
 .../math4/ode/FieldSecondaryEquations.java      |   4 +-
 .../FirstOrderFieldDifferentialEquations.java   |  73 +++++++
 .../math4/ode/FirstOrderFieldIntegrator.java    | 188 +++++++++++++++++++
 .../ode/nonstiff/RungeKuttaFieldIntegrator.java |   4 +-
 .../sampling/AbstractFieldStepInterpolator.java |   2 +-
 .../math4/ode/sampling/FieldStepHandler.java    |   2 +-
 .../ode/sampling/FieldStepInterpolator.java     |   2 +-
 src/site/xdoc/userguide/ode.xml                 |   4 +-
 .../ode/ContinuousOutputFieldModelTest.java     |  14 +-
 .../math4/ode/FieldExpandableODETest.java       |  20 +-
 .../math4/ode/TestFieldProblemAbstract.java     |   2 +-
 .../math4/ode/TestFieldProblemHandler.java      |   4 +-
 ...ctEmbeddedRungeKuttaFieldIntegratorTest.java |  20 +-
 .../AbstractRungeKuttaFieldIntegratorTest.java  |  10 +-
 ...ractRungeKuttaFieldStepInterpolatorTest.java |  10 +-
 .../math4/ode/nonstiff/StepFieldProblem.java    |   4 +-
 .../ode/sampling/StepInterpolatorTestUtils.java |   4 +-
 23 files changed, 323 insertions(+), 323 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
index d741de5..41d7f15 100644
--- a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
@@ -47,7 +47,7 @@ import org.apache.commons.math4.util.IntegerSequence;
  * @param <T> the type of the field elements
  * @since 3.6
  */
-public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> implements FieldFirstOrderIntegrator<T> {
+public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> implements FirstOrderFieldIntegrator<T> {
 
     /** Default relative accuracy. */
     private static final double DEFAULT_RELATIVE_ACCURACY = 1e-14;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java b/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
index 5e31a04..e5dd205 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
@@ -38,11 +38,11 @@ import org.apache.commons.math4.util.MathArrays;
  * <p>
  * We want the integrator to use <em>only</em> the primary set to estimate the
  * errors and hence the step sizes. It should <em>not</em> use the secondary
- * equations in this computation. The {@link FieldFirstOrderIntegrator integrator} will
+ * equations in this computation. The {@link FirstOrderFieldIntegrator integrator} will
  * be able to know where the primary set ends and so where the secondary sets begin.
  * </p>
  *
- * @see FieldFirstOrderDifferentialEquations
+ * @see FirstOrderFieldDifferentialEquations
  * @see FieldSecondaryEquations
  *
  * @param <T> the type of the field elements
@@ -52,7 +52,7 @@ import org.apache.commons.math4.util.MathArrays;
 public class FieldExpandableODE<T extends RealFieldElement<T>> {
 
     /** Primary differential equation. */
-    private final FieldFirstOrderDifferentialEquations<T> primary;
+    private final FirstOrderFieldDifferentialEquations<T> primary;
 
     /** Components of the expandable ODE. */
     private List<FieldSecondaryEquations<T>> components;
@@ -63,7 +63,7 @@ public class FieldExpandableODE<T extends RealFieldElement<T>> {
     /** Build an expandable set from its primary ODE set.
      * @param primary the primary set of differential equations to be integrated.
      */
-    public FieldExpandableODE(final FieldFirstOrderDifferentialEquations<T> primary) {
+    public FieldExpandableODE(final FirstOrderFieldDifferentialEquations<T> primary) {
         this.primary    = primary;
         this.components = new ArrayList<FieldSecondaryEquations<T>>();
         this.mapper     = new FieldEquationsMapper<T>(null, primary.getDimension());

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderDifferentialEquations.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderDifferentialEquations.java b/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderDifferentialEquations.java
deleted file mode 100644
index 05944fa..0000000
--- a/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderDifferentialEquations.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.apache.commons.math4.ode;
-
-import org.apache.commons.math4.RealFieldElement;
-
-/** This interface represents a first order differential equations set.
- *
- * <p>This interface should be implemented by all real first order
- * differential equation problems before they can be handled by the
- * integrators {@link FirstOrderIntegrator#integrate} method.</p>
- *
- * <p>A first order differential equations problem, as seen by an
- * integrator is the time derivative <code>dY/dt</code> of a state
- * vector <code>Y</code>, both being one dimensional arrays. From the
- * integrator point of view, this derivative depends only on the
- * current time <code>t</code> and on the state vector
- * <code>Y</code>.</p>
- *
- * <p>For real problems, the derivative depends also on parameters
- * that do not belong to the state vector (dynamical model constants
- * for example). These constants are completely outside of the scope
- * of this interface, the classes that implement it are allowed to
- * handle them as they want.</p>
- *
- * @see FieldFirstOrderIntegrator
- *
- * @param <T> the type of the field elements
- * @since 3.6
- */
-
-public interface FieldFirstOrderDifferentialEquations<T extends RealFieldElement<T>> {
-
-    /** Get the dimension of the problem.
-     * @return dimension of the problem
-     */
-    int getDimension();
-
-    /** Initialize equations at the start of an ODE integration.
-     * <p>
-     * This method is called once at the start of the integration. It
-     * may be used by the equations to initialize some internal data
-     * if needed.
-     * </p>
-     * @param t0 value of the independent <I>time</I> variable at integration start
-     * @param y0 array containing the value of the state vector at integration start
-     * @param finalTime target time for the integration
-     */
-    void init(T t0, T[] y0, T finalTime);
-
-    /** Get the current time derivative of the state vector.
-     * @param t current value of the independent <I>time</I> variable
-     * @param y array containing the current value of the state vector
-     * @return time derivative of the state vector
-     */
-    T[] computeDerivatives(T t, T[] y);
-
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java b/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java
deleted file mode 100644
index 981d22b..0000000
--- a/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * 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.apache.commons.math4.ode;
-
-import java.util.Collection;
-
-import org.apache.commons.math4.RealFieldElement;
-import org.apache.commons.math4.analysis.solvers.BracketedRealFieldUnivariateSolver;
-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.ode.events.FieldEventHandler;
-import org.apache.commons.math4.ode.sampling.FieldStepHandler;
-
-/** This interface represents a first order integrator for
- * differential equations.
-
- * <p>The classes which are devoted to solve first order differential
- * equations should implement this interface. The problems which can
- * be handled should implement the {@link
- * FirstOrderDifferentialEquations} interface.</p>
- *
- * @see FieldFirstOrderDifferentialEquations
- * @param <T> the type of the field elements
- * @since 3.6
- */
-
-public interface FieldFirstOrderIntegrator<T extends RealFieldElement<T>> {
-
-    /** Get the name of the method.
-     * @return name of the method
-     */
-    String getName();
-
-    /** Add a step handler to this integrator.
-     * <p>The handler will be called by the integrator for each accepted
-     * step.</p>
-     * @param handler handler for the accepted steps
-     * @see #getStepHandlers()
-     * @see #clearStepHandlers()
-     */
-    void addStepHandler(FieldStepHandler<T> handler);
-
-    /** Get all the step handlers that have been added to the integrator.
-     * @return an unmodifiable collection of the added events handlers
-     * @see #addStepHandler(FieldStepHandler)
-     * @see #clearStepHandlers()
-     */
-    Collection<FieldStepHandler<T>> getStepHandlers();
-
-    /** Remove all the step handlers that have been added to the integrator.
-     * @see #addStepHandler(FieldStepHandler)
-     * @see #getStepHandlers()
-     */
-    void clearStepHandlers();
-
-    /** Add an event handler to the integrator.
-     * <p>
-     * The default solver is a 5<sup>th</sup> order {@link
-     * org.apache.commons.math4.analysis.solvers.FieldBracketingNthOrderBrentSolver}.
-     * </p>
-     * @param handler event handler
-     * @param maxCheckInterval maximal time interval between switching
-     * function checks (this interval prevents missing sign changes in
-     * case the integration steps becomes very large)
-     * @param convergence convergence threshold in the event time search
-     * @param maxIterationCount upper limit of the iteration count in
-     * the event time search events.
-     * @see #addEventHandler(FieldEventHandler, double, double, int,
-     * org.apache.commons.math4.analysis.solvers.BracketedRealFieldUnivariateSolver)
-     * @see #getEventHandlers()
-     * @see #clearEventHandlers()
-     */
-    void addEventHandler(FieldEventHandler<T>  handler, double maxCheckInterval,
-                         double convergence, int maxIterationCount);
-
-    /** Add an event handler to the integrator.
-     * @param handler event handler
-     * @param maxCheckInterval maximal time interval between switching
-     * function checks (this interval prevents missing sign changes in
-     * case the integration steps becomes very large)
-     * @param convergence convergence threshold in the event time search
-     * @param maxIterationCount upper limit of the iteration count in
-     * the event time search events.
-     * @param solver solver to use to locate the event
-     * @see #addEventHandler(FieldEventHandler, double, double, int)
-     * @see #getEventHandlers()
-     * @see #clearEventHandlers()
-     */
-    void addEventHandler(FieldEventHandler<T>  handler, double maxCheckInterval,
-                         double convergence, int maxIterationCount,
-                         BracketedRealFieldUnivariateSolver<T> solver);
-
-    /** Get all the event handlers that have been added to the integrator.
-     * @return an unmodifiable collection of the added events handlers
-     * @see #addEventHandler(FieldEventHandler, double, double, int)
-     * @see #clearEventHandlers()
-     */
-    Collection<FieldEventHandler<T> > getEventHandlers();
-
-    /** Remove all the event handlers that have been added to the integrator.
-     * @see #addEventHandler(FieldEventHandler, double, double, int)
-     * @see #getEventHandlers()
-     */
-    void clearEventHandlers();
-
-    /** Get the current value of the step start time t<sub>i</sub>.
-     * <p>This method can be called during integration (typically by
-     * the object implementing the {@link FirstOrderDifferentialEquations
-     * differential equations} problem) if the value of the current step that
-     * is attempted is needed.</p>
-     * <p>The result is undefined if the method is called outside of
-     * calls to <code>integrate</code>.</p>
-     * @return current value of the state at step start time t<sub>i</sub>
-     */
-    FieldODEStateAndDerivative<T> getCurrentStepStart();
-
-    /** Get the current signed value of the integration stepsize.
-     * <p>This method can be called during integration (typically by
-     * the object implementing the {@link FirstOrderDifferentialEquations
-     * differential equations} problem) if the signed value of the current stepsize
-     * that is tried is needed.</p>
-     * <p>The result is undefined if the method is called outside of
-     * calls to <code>integrate</code>.</p>
-     * @return current signed value of the stepsize
-     */
-    T getCurrentSignedStepsize();
-
-    /** Set the maximal number of differential equations function evaluations.
-     * <p>The purpose of this method is to avoid infinite loops which can occur
-     * for example when stringent error constraints are set or when lots of
-     * discrete events are triggered, thus leading to many rejected steps.</p>
-     * @param maxEvaluations maximal number of function evaluations (negative
-     * values are silently converted to maximal integer value, thus representing
-     * almost unlimited evaluations)
-     */
-    void setMaxEvaluations(int maxEvaluations);
-
-    /** Get the maximal number of functions evaluations.
-     * @return maximal number of functions evaluations
-     */
-    int getMaxEvaluations();
-
-    /** Get the number of evaluations of the differential equations function.
-     * <p>
-     * The number of evaluations corresponds to the last call to the
-     * <code>integrate</code> method. It is 0 if the method has not been called yet.
-     * </p>
-     * @return number of evaluations of the differential equations function
-     */
-    int getEvaluations();
-
-    /** Integrate the differential equations up to the given time.
-     * <p>This method solves an Initial Value Problem (IVP).</p>
-     * <p>Since this method stores some internal state variables made
-     * available in its public interface during integration ({@link
-     * #getCurrentSignedStepsize()}), it is <em>not</em> thread-safe.</p>
-     * @param equations differential equations to integrate
-     * @param initialState initial state (time, primary and secondary state vectors)
-     * @param finalTime target time for the integration
-     * (can be set to a value smaller than {@code t0} for backward integration)
-     * @return final state, its time will be the same as {@code finalTime} if
-     * integration reached its target, but may be different if some {@link
-     * org.apache.commons.math4.ode.events.FieldEventHandler} stops it at some point.
-     * @exception NumberIsTooSmallException if integration step is too small
-     * @exception MaxCountExceededException if the number of functions evaluations is exceeded
-     * @exception NoBracketingException if the location of an event cannot be bracketed
-     */
-    FieldODEStateAndDerivative<T> integrate(FieldExpandableODE<T> equations,
-                                            FieldODEState<T> initialState, T finalTime)
-        throws NumberIsTooSmallException, MaxCountExceededException, NoBracketingException;
-
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldODEState.java b/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
index a0d0342..ae3566e 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
@@ -23,9 +23,9 @@ import org.apache.commons.math4.util.MathArrays;
 
 /** Container for time, main and secondary state vectors.
 
- * @see FieldFirstOrderDifferentialEquations
+ * @see FirstOrderFieldDifferentialEquations
  * @see FieldSecondaryEquations
- * @see FieldFirstOrderIntegrator
+ * @see FirstOrderFieldIntegrator
  * @see FieldODEStateAndDerivative
  * @param <T> the type of the field elements
  * @since 3.6

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java b/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
index a10b544..7851bd5 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
@@ -21,9 +21,9 @@ import org.apache.commons.math4.RealFieldElement;
 
 /** Container for time, main and secondary state vectors as well as their derivatives.
 
- * @see FieldFirstOrderDifferentialEquations
+ * @see FirstOrderFieldDifferentialEquations
  * @see FieldSecondaryEquations
- * @see FieldFirstOrderIntegrator
+ * @see FirstOrderFieldIntegrator
  * @param <T> the type of the field elements
  * @since 3.6
  */

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/FieldSecondaryEquations.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldSecondaryEquations.java b/src/main/java/org/apache/commons/math4/ode/FieldSecondaryEquations.java
index 6bce859..c5f10b4 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldSecondaryEquations.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldSecondaryEquations.java
@@ -31,11 +31,11 @@ import org.apache.commons.math4.exception.MaxCountExceededException;
  * </p>
  * <p>
  * This interface allows users to add such equations to a primary set of {@link
- * FieldFirstOrderDifferentialEquations first order differential equations}
+ * FirstOrderFieldDifferentialEquations first order differential equations}
  * thanks to the {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryEquations)}
  * method.
  * </p>
- * @see FieldFirstOrderDifferentialEquations
+ * @see FirstOrderFieldDifferentialEquations
  * @see FieldExpandableODE
  * @param <T> the type of the field elements
  * @since 3.6

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/FirstOrderFieldDifferentialEquations.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FirstOrderFieldDifferentialEquations.java b/src/main/java/org/apache/commons/math4/ode/FirstOrderFieldDifferentialEquations.java
new file mode 100644
index 0000000..288e581
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/FirstOrderFieldDifferentialEquations.java
@@ -0,0 +1,73 @@
+/*
+ * 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.apache.commons.math4.ode;
+
+import org.apache.commons.math4.RealFieldElement;
+
+/** This interface represents a first order differential equations set.
+ *
+ * <p>This interface should be implemented by all real first order
+ * differential equation problems before they can be handled by the
+ * integrators {@link FirstOrderIntegrator#integrate} method.</p>
+ *
+ * <p>A first order differential equations problem, as seen by an
+ * integrator is the time derivative <code>dY/dt</code> of a state
+ * vector <code>Y</code>, both being one dimensional arrays. From the
+ * integrator point of view, this derivative depends only on the
+ * current time <code>t</code> and on the state vector
+ * <code>Y</code>.</p>
+ *
+ * <p>For real problems, the derivative depends also on parameters
+ * that do not belong to the state vector (dynamical model constants
+ * for example). These constants are completely outside of the scope
+ * of this interface, the classes that implement it are allowed to
+ * handle them as they want.</p>
+ *
+ * @see FirstOrderFieldIntegrator
+ *
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+
+public interface FirstOrderFieldDifferentialEquations<T extends RealFieldElement<T>> {
+
+    /** Get the dimension of the problem.
+     * @return dimension of the problem
+     */
+    int getDimension();
+
+    /** Initialize equations at the start of an ODE integration.
+     * <p>
+     * This method is called once at the start of the integration. It
+     * may be used by the equations to initialize some internal data
+     * if needed.
+     * </p>
+     * @param t0 value of the independent <I>time</I> variable at integration start
+     * @param y0 array containing the value of the state vector at integration start
+     * @param finalTime target time for the integration
+     */
+    void init(T t0, T[] y0, T finalTime);
+
+    /** Get the current time derivative of the state vector.
+     * @param t current value of the independent <I>time</I> variable
+     * @param y array containing the current value of the state vector
+     * @return time derivative of the state vector
+     */
+    T[] computeDerivatives(T t, T[] y);
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/FirstOrderFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FirstOrderFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/FirstOrderFieldIntegrator.java
new file mode 100644
index 0000000..2ebd9b9
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/FirstOrderFieldIntegrator.java
@@ -0,0 +1,188 @@
+/*
+ * 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.apache.commons.math4.ode;
+
+import java.util.Collection;
+
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.analysis.solvers.BracketedRealFieldUnivariateSolver;
+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.ode.events.FieldEventHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepHandler;
+
+/** This interface represents a first order integrator for
+ * differential equations.
+
+ * <p>The classes which are devoted to solve first order differential
+ * equations should implement this interface. The problems which can
+ * be handled should implement the {@link
+ * FirstOrderDifferentialEquations} interface.</p>
+ *
+ * @see FirstOrderFieldDifferentialEquations
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+
+public interface FirstOrderFieldIntegrator<T extends RealFieldElement<T>> {
+
+    /** Get the name of the method.
+     * @return name of the method
+     */
+    String getName();
+
+    /** Add a step handler to this integrator.
+     * <p>The handler will be called by the integrator for each accepted
+     * step.</p>
+     * @param handler handler for the accepted steps
+     * @see #getStepHandlers()
+     * @see #clearStepHandlers()
+     */
+    void addStepHandler(FieldStepHandler<T> handler);
+
+    /** Get all the step handlers that have been added to the integrator.
+     * @return an unmodifiable collection of the added events handlers
+     * @see #addStepHandler(FieldStepHandler)
+     * @see #clearStepHandlers()
+     */
+    Collection<FieldStepHandler<T>> getStepHandlers();
+
+    /** Remove all the step handlers that have been added to the integrator.
+     * @see #addStepHandler(FieldStepHandler)
+     * @see #getStepHandlers()
+     */
+    void clearStepHandlers();
+
+    /** Add an event handler to the integrator.
+     * <p>
+     * The default solver is a 5<sup>th</sup> order {@link
+     * org.apache.commons.math4.analysis.solvers.FieldBracketingNthOrderBrentSolver}.
+     * </p>
+     * @param handler event handler
+     * @param maxCheckInterval maximal time interval between switching
+     * function checks (this interval prevents missing sign changes in
+     * case the integration steps becomes very large)
+     * @param convergence convergence threshold in the event time search
+     * @param maxIterationCount upper limit of the iteration count in
+     * the event time search events.
+     * @see #addEventHandler(FieldEventHandler, double, double, int,
+     * org.apache.commons.math4.analysis.solvers.BracketedRealFieldUnivariateSolver)
+     * @see #getEventHandlers()
+     * @see #clearEventHandlers()
+     */
+    void addEventHandler(FieldEventHandler<T>  handler, double maxCheckInterval,
+                         double convergence, int maxIterationCount);
+
+    /** Add an event handler to the integrator.
+     * @param handler event handler
+     * @param maxCheckInterval maximal time interval between switching
+     * function checks (this interval prevents missing sign changes in
+     * case the integration steps becomes very large)
+     * @param convergence convergence threshold in the event time search
+     * @param maxIterationCount upper limit of the iteration count in
+     * the event time search events.
+     * @param solver solver to use to locate the event
+     * @see #addEventHandler(FieldEventHandler, double, double, int)
+     * @see #getEventHandlers()
+     * @see #clearEventHandlers()
+     */
+    void addEventHandler(FieldEventHandler<T>  handler, double maxCheckInterval,
+                         double convergence, int maxIterationCount,
+                         BracketedRealFieldUnivariateSolver<T> solver);
+
+    /** Get all the event handlers that have been added to the integrator.
+     * @return an unmodifiable collection of the added events handlers
+     * @see #addEventHandler(FieldEventHandler, double, double, int)
+     * @see #clearEventHandlers()
+     */
+    Collection<FieldEventHandler<T> > getEventHandlers();
+
+    /** Remove all the event handlers that have been added to the integrator.
+     * @see #addEventHandler(FieldEventHandler, double, double, int)
+     * @see #getEventHandlers()
+     */
+    void clearEventHandlers();
+
+    /** Get the current value of the step start time t<sub>i</sub>.
+     * <p>This method can be called during integration (typically by
+     * the object implementing the {@link FirstOrderDifferentialEquations
+     * differential equations} problem) if the value of the current step that
+     * is attempted is needed.</p>
+     * <p>The result is undefined if the method is called outside of
+     * calls to <code>integrate</code>.</p>
+     * @return current value of the state at step start time t<sub>i</sub>
+     */
+    FieldODEStateAndDerivative<T> getCurrentStepStart();
+
+    /** Get the current signed value of the integration stepsize.
+     * <p>This method can be called during integration (typically by
+     * the object implementing the {@link FirstOrderDifferentialEquations
+     * differential equations} problem) if the signed value of the current stepsize
+     * that is tried is needed.</p>
+     * <p>The result is undefined if the method is called outside of
+     * calls to <code>integrate</code>.</p>
+     * @return current signed value of the stepsize
+     */
+    T getCurrentSignedStepsize();
+
+    /** Set the maximal number of differential equations function evaluations.
+     * <p>The purpose of this method is to avoid infinite loops which can occur
+     * for example when stringent error constraints are set or when lots of
+     * discrete events are triggered, thus leading to many rejected steps.</p>
+     * @param maxEvaluations maximal number of function evaluations (negative
+     * values are silently converted to maximal integer value, thus representing
+     * almost unlimited evaluations)
+     */
+    void setMaxEvaluations(int maxEvaluations);
+
+    /** Get the maximal number of functions evaluations.
+     * @return maximal number of functions evaluations
+     */
+    int getMaxEvaluations();
+
+    /** Get the number of evaluations of the differential equations function.
+     * <p>
+     * The number of evaluations corresponds to the last call to the
+     * <code>integrate</code> method. It is 0 if the method has not been called yet.
+     * </p>
+     * @return number of evaluations of the differential equations function
+     */
+    int getEvaluations();
+
+    /** Integrate the differential equations up to the given time.
+     * <p>This method solves an Initial Value Problem (IVP).</p>
+     * <p>Since this method stores some internal state variables made
+     * available in its public interface during integration ({@link
+     * #getCurrentSignedStepsize()}), it is <em>not</em> thread-safe.</p>
+     * @param equations differential equations to integrate
+     * @param initialState initial state (time, primary and secondary state vectors)
+     * @param finalTime target time for the integration
+     * (can be set to a value smaller than {@code t0} for backward integration)
+     * @return final state, its time will be the same as {@code finalTime} if
+     * integration reached its target, but may be different if some {@link
+     * org.apache.commons.math4.ode.events.FieldEventHandler} stops it at some point.
+     * @exception NumberIsTooSmallException if integration step is too small
+     * @exception MaxCountExceededException if the number of functions evaluations is exceeded
+     * @exception NoBracketingException if the location of an event cannot be bracketed
+     */
+    FieldODEStateAndDerivative<T> integrate(FieldExpandableODE<T> equations,
+                                            FieldODEState<T> initialState, T finalTime)
+        throws NumberIsTooSmallException, MaxCountExceededException, NoBracketingException;
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
index d052f4b..45ad237 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
@@ -27,7 +27,7 @@ import org.apache.commons.math4.exception.NumberIsTooSmallException;
 import org.apache.commons.math4.ode.AbstractFieldIntegrator;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
 import org.apache.commons.math4.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
 import org.apache.commons.math4.ode.FieldODEState;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
@@ -230,7 +230,7 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
      * (can be set to a value smaller than {@code t0} for backward integration)
      * @return state vector at {@code t}
      */
-    public T[] singleStep(final FieldFirstOrderDifferentialEquations<T> equations,
+    public T[] singleStep(final FirstOrderFieldDifferentialEquations<T> equations,
                           final T t0, final T[] y0, final T t) {
 
         // create some internal working arrays

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
index b9a5de2..4385336 100644
--- a/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
@@ -30,7 +30,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
  * retrieve the state vector at intermediate times between the
  * previous and the current grid points (dense output).</p>
  *
- * @see org.apache.commons.math4.ode.FieldFirstOrderIntegrator
+ * @see org.apache.commons.math4.ode.FirstOrderFieldIntegrator
  * @see StepHandler
  *
  * @param <T> the type of the field elements

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepHandler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepHandler.java b/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepHandler.java
index 4a1e3c9..77b7ddd 100644
--- a/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepHandler.java
+++ b/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepHandler.java
@@ -34,7 +34,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
  * last one, store the points in an ephemeris, or forward them to
  * specialized processing or output methods.</p>
  *
- * @see org.apache.commons.math4.ode.FieldFirstOrderIntegrator
+ * @see org.apache.commons.math4.ode.FirstOrderFieldIntegrator
  * @see FieldStepInterpolator
  * @param <T> the type of the field elements
  * @since 3.6

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java
index a68d098..9a647e5 100644
--- a/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java
@@ -31,7 +31,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
  * (this feature is often called dense output).</p>
  *
  * @param <T> the type of the field elements
- * @see org.apache.commons.math4.ode.FieldFirstOrderIntegrator
+ * @see org.apache.commons.math4.ode.FirstOrderFieldIntegrator
  * @see FieldStepHandler
  * @since 3.6
  */

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/site/xdoc/userguide/ode.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/userguide/ode.xml b/src/site/xdoc/userguide/ode.xml
index 3dc48bc..ffbebc6 100644
--- a/src/site/xdoc/userguide/ode.xml
+++ b/src/site/xdoc/userguide/ode.xml
@@ -85,10 +85,10 @@
         <p>
           The user should describe his problem in his own classes which should implement the
           <a href="../apidocs/org/apache/commons/math4/ode/FirstOrderDifferentialEquations.html">FirstOrderDifferentialEquations</a>
-          interface (or  <a href="../apidocs/org/apache/commons/math4/ode/FieldFirstOrderDifferentialEquations.html">FieldFirstOrderDifferentialEquations</a>
+          interface (or  <a href="../apidocs/org/apache/commons/math4/ode/FirstOrderFieldDifferentialEquations.html">FirstOrderFieldDifferentialEquations</a>
           interface). Then he should pass it to the integrator he prefers among all the classes that implement
           the <a href="../apidocs/org/apache/commons/math4/ode/FirstOrderIntegrator.html">FirstOrderIntegrator</a>
-          interface (or the <a href="../apidocs/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.html">FieldFirstOrderIntegrator</a>
+          interface (or the <a href="../apidocs/org/apache/commons/math4/ode/FirstOrderFieldIntegrator.html">FirstOrderFieldIntegrator</a>
           interface). The following example shows how to implement the simple two-dimensional problem using double primitives:
           <ul>
             <li>y'<sub>0</sub>(t) = &#x3c9; &#xD7; (c<sub>1</sub> - y<sub>1</sub>(t))</li>

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java b/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
index fd87aba..870ee1e 100644
--- a/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
@@ -45,7 +45,7 @@ public class ContinuousOutputFieldModelTest {
         TestFieldProblem3<T> pb = new TestFieldProblem3<T>(field, field.getZero().add(0.9));
         double minStep = 0;
         double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
-        FieldFirstOrderIntegrator<T> integ = new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, 1.0e-8, 1.0e-8);
+        FirstOrderFieldIntegrator<T> integ = new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, 1.0e-8, 1.0e-8);
         integ.addStepHandler(new ContinuousOutputFieldModel<T>());
         integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
         ContinuousOutputFieldModel<T> cm = (ContinuousOutputFieldModel<T>) integ.getStepHandlers().iterator().next();
@@ -64,7 +64,7 @@ public class ContinuousOutputFieldModelTest {
         TestFieldProblem3<T> pb = new TestFieldProblem3<T>(field, field.getZero().add(0.9));
         double minStep = 0;
         double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
-        FieldFirstOrderIntegrator<T> integ = new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, 1.0e-8, 1.0e-8);
+        FirstOrderFieldIntegrator<T> integ = new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, 1.0e-8, 1.0e-8);
         ContinuousOutputFieldModel<T> cm = new ContinuousOutputFieldModel<T>();
         integ.addStepHandler(cm);
         integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
@@ -101,8 +101,8 @@ public class ContinuousOutputFieldModelTest {
     private <T extends RealFieldElement<T>> void doTestModelsMerging(final Field<T> field) {
 
         // theoretical solution: y[0] = cos(t), y[1] = sin(t)
-        FieldFirstOrderDifferentialEquations<T> problem =
-                        new FieldFirstOrderDifferentialEquations<T>() {
+        FirstOrderFieldDifferentialEquations<T> problem =
+                        new FirstOrderFieldDifferentialEquations<T>() {
             public T[] computeDerivatives(T t, T[] y) {
                 T[] yDot = MathArrays.buildArray(field, 2);
                 yDot[0] = y[1].negate();
@@ -118,7 +118,7 @@ public class ContinuousOutputFieldModelTest {
 
         // integrate backward from &pi; to 0;
         ContinuousOutputFieldModel<T> cm1 = new ContinuousOutputFieldModel<T>();
-        FieldFirstOrderIntegrator<T> integ1 =
+        FirstOrderFieldIntegrator<T> integ1 =
                         new DormandPrince853FieldIntegrator<T>(field, 0, 1.0, 1.0e-8, 1.0e-8);
         integ1.addStepHandler(cm1);
         T t0 = field.getZero().add(FastMath.PI);
@@ -131,7 +131,7 @@ public class ContinuousOutputFieldModelTest {
 
         // integrate backward from 2&pi; to &pi;
         ContinuousOutputFieldModel<T> cm2 = new ContinuousOutputFieldModel<T>();
-        FieldFirstOrderIntegrator<T> integ2 =
+        FirstOrderFieldIntegrator<T> integ2 =
                         new DormandPrince853FieldIntegrator<T>(field, 0, 0.1, 1.0e-12, 1.0e-12);
         integ2.addStepHandler(cm2);
         t0 = field.getZero().add(2.0 * FastMath.PI);
@@ -203,7 +203,7 @@ public class ContinuousOutputFieldModelTest {
         }
         final FieldODEStateAndDerivative<T> s0 = new FieldODEStateAndDerivative<T>(field.getZero().add(t0), fieldY, fieldY);
         final FieldODEStateAndDerivative<T> s1 = new FieldODEStateAndDerivative<T>(field.getZero().add(t1), fieldY, fieldY);
-        final FieldEquationsMapper<T> mapper   = new FieldExpandableODE<T>(new FieldFirstOrderDifferentialEquations<T>() {
+        final FieldEquationsMapper<T> mapper   = new FieldExpandableODE<T>(new FirstOrderFieldDifferentialEquations<T>() {
             public int getDimension() {
                 return s0.getStateDimension();
             }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java b/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java
index 8005274..79070d0 100644
--- a/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java
+++ b/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java
@@ -23,7 +23,7 @@ import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.exception.DimensionMismatchException;
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.ode.FieldSecondaryEquations;
 import org.apache.commons.math4.util.Decimal64Field;
@@ -39,7 +39,7 @@ public class FieldExpandableODETest {
     }
 
     private <T extends RealFieldElement<T>> void doTestOnlyMainEquation(final Field<T> field) {
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FirstOrderFieldDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
         FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
         Assert.assertEquals(main.getDimension(), equation.getMapper().getTotalDimension());
         Assert.assertEquals(1, equation.getMapper().getNumberOfEquations());
@@ -70,7 +70,7 @@ public class FieldExpandableODETest {
 
     private <T extends RealFieldElement<T>> void doTestMainAndSecondary(final Field<T> field) {
 
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FirstOrderFieldDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
         FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
         FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
         int i1 = equation.addSecondaryEquations(secondary1);
@@ -127,7 +127,7 @@ public class FieldExpandableODETest {
 
     private <T extends RealFieldElement<T>> void doTestMap(final Field<T> field) {
 
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FirstOrderFieldDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
         FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
         FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
         int i1 = equation.addSecondaryEquations(secondary1);
@@ -215,7 +215,7 @@ public class FieldExpandableODETest {
     private <T extends RealFieldElement<T>> void doTestExtractDimensionMismatch(final Field<T> field)
         throws DimensionMismatchException {
 
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FirstOrderFieldDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
         FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
         FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
         int i1 = equation.addSecondaryEquations(secondary1);
@@ -231,7 +231,7 @@ public class FieldExpandableODETest {
     private <T extends RealFieldElement<T>> void doTestInsertTooShortComplete(final Field<T> field)
         throws DimensionMismatchException {
 
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FirstOrderFieldDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
         FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
         FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
         int i1 = equation.addSecondaryEquations(secondary1);
@@ -248,7 +248,7 @@ public class FieldExpandableODETest {
     private <T extends RealFieldElement<T>> void doTestInsertWrongEquationData(final Field<T> field)
         throws DimensionMismatchException {
 
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FirstOrderFieldDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
         FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
         FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
         int i1 = equation.addSecondaryEquations(secondary1);
@@ -265,7 +265,7 @@ public class FieldExpandableODETest {
     private <T extends RealFieldElement<T>> void doTestNegativeIndex(final Field<T> field)
         throws MathIllegalArgumentException {
 
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FirstOrderFieldDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
         FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
         T[] complete = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
         equation.getMapper().extractEquationData(-1, complete);
@@ -279,14 +279,14 @@ public class FieldExpandableODETest {
     private <T extends RealFieldElement<T>> void doTestTooLargeIndex(final Field<T> field)
         throws MathIllegalArgumentException {
 
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FirstOrderFieldDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
         FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
         T[] complete = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
         equation.getMapper().extractEquationData(+1, complete);
     }
 
     private static class  Linear<T extends RealFieldElement<T>>
-        implements  FieldFirstOrderDifferentialEquations<T>, FieldSecondaryEquations<T> {
+        implements  FirstOrderFieldDifferentialEquations<T>, FieldSecondaryEquations<T> {
 
         private final Field<T> field;
         private final int dimension;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/TestFieldProblemAbstract.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/TestFieldProblemAbstract.java b/src/test/java/org/apache/commons/math4/ode/TestFieldProblemAbstract.java
index bc2abfe..9d1b78b 100644
--- a/src/test/java/org/apache/commons/math4/ode/TestFieldProblemAbstract.java
+++ b/src/test/java/org/apache/commons/math4/ode/TestFieldProblemAbstract.java
@@ -30,7 +30,7 @@ import org.apache.commons.math4.util.MathArrays;
  * @param <T> the type of the field elements
  */
 public abstract class TestFieldProblemAbstract<T extends RealFieldElement<T>>
-    implements FieldFirstOrderDifferentialEquations<T> {
+    implements FirstOrderFieldDifferentialEquations<T> {
 
     /** Field to which elements belong. */
     private Field<T> field;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/TestFieldProblemHandler.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/TestFieldProblemHandler.java b/src/test/java/org/apache/commons/math4/ode/TestFieldProblemHandler.java
index 3cafb54..c298bf3 100644
--- a/src/test/java/org/apache/commons/math4/ode/TestFieldProblemHandler.java
+++ b/src/test/java/org/apache/commons/math4/ode/TestFieldProblemHandler.java
@@ -45,7 +45,7 @@ public class TestFieldProblemHandler<T extends RealFieldElement<T>>
     private T lastTime;
 
     /** ODE solver used. */
-    private FieldFirstOrderIntegrator<T> integrator;
+    private FirstOrderFieldIntegrator<T> integrator;
 
     /** Expected start for step. */
     private T expectedStepStart;
@@ -55,7 +55,7 @@ public class TestFieldProblemHandler<T extends RealFieldElement<T>>
      * @param problem problem for which steps should be handled
      * @param integrator ODE solver used
      */
-    public TestFieldProblemHandler(TestFieldProblemAbstract<T> problem, FieldFirstOrderIntegrator<T> integrator) {
+    public TestFieldProblemHandler(TestFieldProblemAbstract<T> problem, FirstOrderFieldIntegrator<T> integrator) {
         this.problem      = problem;
         this.integrator   = integrator;
         maxValueError     = problem.getField().getZero();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
index 0f3449f..9314b27 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
@@ -26,8 +26,8 @@ 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.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
-import org.apache.commons.math4.ode.FieldFirstOrderIntegrator;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
+import org.apache.commons.math4.ode.FirstOrderFieldIntegrator;
 import org.apache.commons.math4.ode.FieldODEState;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.ode.TestFieldProblem1;
@@ -131,7 +131,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
     public abstract void testForwardBackwardExceptions();
 
     protected <T extends RealFieldElement<T>> void doTestForwardBackwardExceptions(final Field<T> field) {
-        FieldFirstOrderDifferentialEquations<T> equations = new FieldFirstOrderDifferentialEquations<T>() {
+        FirstOrderFieldDifferentialEquations<T> equations = new FirstOrderFieldDifferentialEquations<T>() {
 
             public int getDimension() {
                 return 1;
@@ -188,7 +188,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
         double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
         double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
 
-        FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
                                                               vecAbsoluteTolerance, vecRelativeTolerance);
         TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
         integ.addStepHandler(handler);
@@ -212,7 +212,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
             double scalAbsoluteTolerance = FastMath.pow(10.0, i);
             double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
 
-            FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+            FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
                                                                   scalAbsoluteTolerance, scalRelativeTolerance);
             TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
             integ.addStepHandler(handler);
@@ -243,7 +243,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
       double scalAbsoluteTolerance = 1.0e-8;
       double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
 
-      FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+      FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
                                                             scalAbsoluteTolerance, scalRelativeTolerance);
       TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
       integ.addStepHandler(handler);
@@ -275,7 +275,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
         double scalAbsoluteTolerance = 1.0e-8;
         double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
 
-        FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
                                                               scalAbsoluteTolerance, scalRelativeTolerance);
         TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
         integ.addStepHandler(handler);
@@ -314,7 +314,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
         double scalAbsoluteTolerance = 1.0e-8;
         double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
 
-        FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
                                                               scalAbsoluteTolerance, scalRelativeTolerance);
         TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
         integ.addStepHandler(handler);
@@ -422,7 +422,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
         double[] vecAbsoluteTolerance = { 1.0e-8, 1.0e-8, 1.0e-10, 1.0e-10 };
         double[] vecRelativeTolerance = { 1.0e-10, 1.0e-10, 1.0e-8, 1.0e-8 };
 
-        FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
                                                               vecAbsoluteTolerance, vecRelativeTolerance);
         integ.addStepHandler(new KeplerHandler<T>(pb, epsilon));
         integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
@@ -511,7 +511,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
         return y.getPartialDerivative(orders);
     }
 
-    private static class SinCos implements FieldFirstOrderDifferentialEquations<DerivativeStructure> {
+    private static class SinCos implements FirstOrderFieldDifferentialEquations<DerivativeStructure> {
 
         private final DerivativeStructure omega;
         private       DerivativeStructure r;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
index cc130d7..ae56e6b 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
@@ -28,7 +28,7 @@ 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.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
 import org.apache.commons.math4.ode.FieldODEState;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.ode.TestFieldProblem1;
@@ -126,7 +126,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
         k[0] = field.getZero().add(1.0e-4);
         k[1] = field.getZero().add(1.0e-5);
         k[2] = field.getZero().add(1.0e-6);
-        FieldFirstOrderDifferentialEquations<T> ode = new FieldFirstOrderDifferentialEquations<T>() {
+        FirstOrderFieldDifferentialEquations<T> ode = new FirstOrderFieldDifferentialEquations<T>() {
 
             public int getDimension() {
                 return k.length;
@@ -424,7 +424,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
             public void init(FieldODEStateAndDerivative<T> s0, T t) {
             }
         });
-        integ.integrate(new FieldExpandableODE<T>(new FieldFirstOrderDifferentialEquations<T>() {
+        integ.integrate(new FieldExpandableODE<T>(new FirstOrderFieldDifferentialEquations<T>() {
             public void init(T t0, T[] y0, T t) {
             }
             public T[] computeDerivatives(T t, T[] y) {
@@ -470,7 +470,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
         final T[] y0 = MathArrays.buildArray(field, 1);
         y0[0] = field.getOne();
         final T t   = field.getZero().add(0.001);
-        FieldFirstOrderDifferentialEquations<T> equations = new FieldFirstOrderDifferentialEquations<T>() {
+        FirstOrderFieldDifferentialEquations<T> equations = new FirstOrderFieldDifferentialEquations<T>() {
 
             public int getDimension() {
                 return 1;
@@ -573,7 +573,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
         return y.getPartialDerivative(orders);
     }
 
-    private static class SinCos implements FieldFirstOrderDifferentialEquations<DerivativeStructure> {
+    private static class SinCos implements FirstOrderFieldDifferentialEquations<DerivativeStructure> {
 
         private final DerivativeStructure omega;
         private       DerivativeStructure r;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index b670cda..100db47 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.EquationsMapper;
 import org.apache.commons.math4.ode.ExpandableStatefulODE;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
 import org.apache.commons.math4.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.ode.sampling.AbstractFieldStepInterpolator;
 import org.apache.commons.math4.util.FastMath;
@@ -103,7 +103,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                                                                                      double epsilonSin, double epsilonCos,
                                                                                      double epsilonSinDot, double epsilonCosDot) {
 
-        FieldFirstOrderDifferentialEquations<T> eqn = new SinCos<T>(field);
+        FirstOrderFieldDifferentialEquations<T> eqn = new SinCos<T>(field);
         RungeKuttaFieldStepInterpolator<T> fieldInterpolator =
                         setUpInterpolator(field, eqn, 0.0, new double[] { 0.0, 1.0 }, 0.125);
         RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator, eqn);
@@ -142,7 +142,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     private <T extends RealFieldElement<T>>
     RungeKuttaFieldStepInterpolator<T> setUpInterpolator(final Field<T> field,
-                                                         final FieldFirstOrderDifferentialEquations<T> eqn,
+                                                         final FirstOrderFieldDifferentialEquations<T> eqn,
                                                          final double t0, final double[] y0,
                                                          final double t1) {
 
@@ -192,7 +192,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     private <T extends RealFieldElement<T>>
     RungeKuttaStepInterpolator convertInterpolator(final RungeKuttaFieldStepInterpolator<T> fieldInterpolator,
-                                                   final FieldFirstOrderDifferentialEquations<T> eqn) {
+                                                   final FirstOrderFieldDifferentialEquations<T> eqn) {
 
         RungeKuttaStepInterpolator regularInterpolator = null;
         try {
@@ -284,7 +284,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     }
 
-    private static class SinCos<T extends RealFieldElement<T>> implements FieldFirstOrderDifferentialEquations<T> {
+    private static class SinCos<T extends RealFieldElement<T>> implements FirstOrderFieldDifferentialEquations<T> {
         private final Field<T> field;
         protected SinCos(final Field<T> field) {
             this.field = field;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/nonstiff/StepFieldProblem.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/StepFieldProblem.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/StepFieldProblem.java
index 3307cba..0368c85 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/StepFieldProblem.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/StepFieldProblem.java
@@ -19,7 +19,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.ode.FieldFirstOrderDifferentialEquations;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
 import org.apache.commons.math4.ode.FieldODEState;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.ode.events.Action;
@@ -28,7 +28,7 @@ import org.apache.commons.math4.util.MathArrays;
 
 
 public class StepFieldProblem<T extends RealFieldElement<T>>
-    implements FieldFirstOrderDifferentialEquations<T>, FieldEventHandler<T> {
+    implements FirstOrderFieldDifferentialEquations<T>, FieldEventHandler<T> {
 
     public StepFieldProblem(Field<T> field, T rateBefore, T rateAfter, T switchTime) {
         this.field      = field;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/346a81d7/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java b/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java
index 9798b9d..5c592d3 100644
--- a/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java
+++ b/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java
@@ -23,7 +23,7 @@ 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.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldFirstOrderIntegrator;
+import org.apache.commons.math4.ode.FirstOrderFieldIntegrator;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.ode.FirstOrderIntegrator;
 import org.apache.commons.math4.ode.TestFieldProblemAbstract;
@@ -95,7 +95,7 @@ public class StepInterpolatorTestUtils {
 
     }
 
-    public static <T extends RealFieldElement<T>> void checkDerivativesConsistency(final FieldFirstOrderIntegrator<T> integrator,
+    public static <T extends RealFieldElement<T>> void checkDerivativesConsistency(final FirstOrderFieldIntegrator<T> integrator,
                                                                                    final TestFieldProblemAbstract<T> problem,
                                                                                    final double threshold) {
         integrator.addStepHandler(new FieldStepHandler<T>() {


[37/50] [abbrv] [math] Fixed test as the master brnahc generates different exceptions.

Posted by lu...@apache.org.
Fixed test as the master brnahc generates different exceptions.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/6e4265d6
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/6e4265d6
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/6e4265d6

Branch: refs/heads/master
Commit: 6e4265d61c22aa0a5b627e8bb4814fff382a7170
Parents: a2efc6b
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:39:56 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:39:56 2016 +0100

----------------------------------------------------------------------
 .../commons/math4/ode/ContinuousOutputFieldModelTest.java      | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/6e4265d6/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java b/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
index f7bbe5c..fd87aba 100644
--- a/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
@@ -21,6 +21,8 @@ import java.util.Random;
 
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.ode.nonstiff.DormandPrince54FieldIntegrator;
 import org.apache.commons.math4.ode.nonstiff.DormandPrince853FieldIntegrator;
 import org.apache.commons.math4.ode.sampling.DummyFieldStepInterpolator;
@@ -185,7 +187,9 @@ public class ContinuousOutputFieldModelTest {
             ContinuousOutputFieldModel<T> otherCm = new ContinuousOutputFieldModel<T>();
             otherCm.handleStep(buildInterpolator(field, t0, t1, y), true);
             cm.append(otherCm);
-        } catch(IllegalArgumentException iae) {
+        } catch(DimensionMismatchException dme) {
+            return true; // there was an allowable error
+        } catch(MathIllegalArgumentException miae) {
             return true; // there was an allowable error
         }
         return false; // no allowable error


[08/50] [abbrv] [math] Added test for classical 3/8 step interpolator.

Posted by lu...@apache.org.
Added test for classical 3/8 step interpolator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/756ba33a
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/756ba33a
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/756ba33a

Branch: refs/heads/master
Commit: 756ba33a2059b2ecaa00b921648391b3daf8742c
Parents: 7139af3
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:16 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:16 2016 +0100

----------------------------------------------------------------------
 .../ThreeEighthesFieldStepInterpolatorTest.java | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/756ba33a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
new file mode 100644
index 0000000..9a6d818
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class ThreeEighthesFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
+        return new ThreeEighthesFieldStepInterpolator<T>(field, forward, mapper);
+    }
+
+    @Test
+    public void interpolationAtBounds() {
+        doInterpolationAtBounds(Decimal64Field.getInstance(), 1.0e-15);
+    }
+
+    @Test
+    public void interpolationInside() {
+        doInterpolationInside(Decimal64Field.getInstance(), 2.6e-7, 3.6e-6);
+    }
+
+}


[26/50] [abbrv] [math] Fixed field-based Dormand-Prince 8(5, 3) step interpolator.

Posted by lu...@apache.org.
Fixed field-based Dormand-Prince 8(5,3) step interpolator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/7a1c10a1
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/7a1c10a1
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/7a1c10a1

Branch: refs/heads/master
Commit: 7a1c10a162fd6e0043f523af98d57549573c1982
Parents: 73b7659
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:39 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:39 2016 +0100

----------------------------------------------------------------------
 .../DormandPrince853FieldStepInterpolator.java  | 63 ++++++++++++++++----
 ...ctEmbeddedRungeKuttaFieldIntegratorTest.java | 14 +++++
 .../DormandPrince853FieldIntegratorTest.java    |  4 +-
 ...rmandPrince853FieldStepInterpolatorTest.java |  4 +-
 4 files changed, 70 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/7a1c10a1/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
index 6487ccf..68573fd 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
@@ -55,7 +55,7 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
         d = MathArrays.buildArray(getField(), 7, 16);
 
         // this row is the same as the b array
-        d[0][ 0] = fraction(104257, 1929240);
+        d[0][ 0] = fraction(104257, 1920240);
         d[0][ 1] = getField().getZero();
         d[0][ 2] = getField().getZero();
         d[0][ 3] = getField().getZero();
@@ -101,10 +101,10 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
         d[2][ 9] = d[0][ 9].multiply(2);
         d[2][10] = d[0][10].multiply(2);
         d[2][11] = d[0][11].multiply(2);
-        d[2][12] = d[0][12].multiply(2); // really 0
-        d[2][13] = d[0][13].multiply(2); // really 0
-        d[2][14] = d[0][14].multiply(2); // really 0
-        d[2][15] = d[0][15].multiply(2); // really 0
+        d[2][12] = d[0][12].multiply(2).subtract(1); // really -1
+        d[2][13] = d[0][13].multiply(2);             // really  0
+        d[2][14] = d[0][14].multiply(2);             // really  0
+        d[2][15] = d[0][15].multiply(2);             // really  0
 
         d[3][ 0] = fraction(        -17751989329.0, 2106076560.0);
         d[3][ 1] = getField().getZero();
@@ -215,7 +215,7 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
                                                                                    final T oneMinusThetaH)
         throws MaxCountExceededException {
 
-        final T one      = theta.getField().getOne();
+        final T one      = getField().getOne();
         final T eta      = one.subtract(theta);
         final T twoTheta = theta.multiply(2);
         final T theta2   = theta.multiply(theta);
@@ -228,6 +228,7 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
         final T[] interpolatedState;
         final T[] interpolatedDerivatives;
 
+
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
             final T f0 = theta.multiply(h);
             final T f1 = f0.multiply(eta);
@@ -236,18 +237,58 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
             final T f4 = f3.multiply(theta);
             final T f5 = f4.multiply(eta);
             final T f6 = f5.multiply(theta);
-            interpolatedState       = previousStateLinearCombination(f0, f1, f2, f3, f4, f5, f6);
-            interpolatedDerivatives = derivativeLinearCombination(one, dot1, dot2, dot3, dot4, dot5, dot6);
+            final T[] p = MathArrays.buildArray(getField(), 16);
+            final T[] q = MathArrays.buildArray(getField(), 16);
+            for (int i = 0; i < p.length; ++i) {
+                p[i] =     f0.multiply(d[0][i]).
+                       add(f1.multiply(d[1][i])).
+                       add(f2.multiply(d[2][i])).
+                       add(f3.multiply(d[3][i])).
+                       add(f4.multiply(d[4][i])).
+                       add(f5.multiply(d[5][i])).
+                       add(f6.multiply(d[6][i]));
+                q[i] =                    d[0][i].
+                        add(dot1.multiply(d[1][i])).
+                        add(dot2.multiply(d[2][i])).
+                        add(dot3.multiply(d[3][i])).
+                        add(dot4.multiply(d[4][i])).
+                        add(dot5.multiply(d[5][i])).
+                        add(dot6.multiply(d[6][i]));
+            }
+            interpolatedState       = previousStateLinearCombination(p[0], p[1], p[ 2], p[ 3], p[ 4], p[ 5], p[ 6], p[ 7],
+                                                                     p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
+            interpolatedDerivatives = derivativeLinearCombination(q[0], q[1], q[ 2], q[ 3], q[ 4], q[ 5], q[ 6], q[ 7],
+                                                                  q[8], q[9], q[10], q[11], q[12], q[13], q[14], q[15]);
         } else {
-            final T f0 = oneMinusThetaH;
+            final T f0 = oneMinusThetaH.negate();
             final T f1 = f0.multiply(theta).negate();
             final T f2 = f1.multiply(theta);
             final T f3 = f2.multiply(eta);
             final T f4 = f3.multiply(theta);
             final T f5 = f4.multiply(eta);
             final T f6 = f5.multiply(theta);
-            interpolatedState       = currentStateLinearCombination(f0, f1, f2, f3, f4, f5, f6);
-            interpolatedDerivatives = derivativeLinearCombination(one, dot1, dot2, dot3, dot4, dot5, dot6);
+            final T[] p = MathArrays.buildArray(getField(), 16);
+            final T[] q = MathArrays.buildArray(getField(), 16);
+            for (int i = 0; i < p.length; ++i) {
+                p[i] =     f0.multiply(d[0][i]).
+                       add(f1.multiply(d[1][i])).
+                       add(f2.multiply(d[2][i])).
+                       add(f3.multiply(d[3][i])).
+                       add(f4.multiply(d[4][i])).
+                       add(f5.multiply(d[5][i])).
+                       add(f6.multiply(d[6][i]));
+                q[i] =                    d[0][i].
+                        add(dot1.multiply(d[1][i])).
+                        add(dot2.multiply(d[2][i])).
+                        add(dot3.multiply(d[3][i])).
+                        add(dot4.multiply(d[4][i])).
+                        add(dot5.multiply(d[5][i])).
+                        add(dot6.multiply(d[6][i]));
+            }
+            interpolatedState       = currentStateLinearCombination(p[0], p[1], p[ 2], p[ 3], p[ 4], p[ 5], p[ 6], p[ 7],
+                                                                    p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
+            interpolatedDerivatives = derivativeLinearCombination(q[0], q[1], q[ 2], q[ 3], q[ 4], q[ 5], q[ 6], q[ 7],
+                                                                  q[8], q[9], q[10], q[11], q[12], q[13], q[14], q[15]);
         }
 
         return new FieldODEStateAndDerivative<T>(time, interpolatedState, interpolatedDerivatives);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/7a1c10a1/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
index 357d92a..3f2b0be 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
@@ -64,6 +64,20 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
             T[][] fieldA = fieldIntegrator.getA();
             T[]   fieldB = fieldIntegrator.getB();
             T[]   fieldC = fieldIntegrator.getC();
+            if (fieldIntegrator instanceof DormandPrince853FieldIntegrator) {
+                // special case for Dormand-Prince 8(5,3), the array in the regular
+                // integrator is smaller because as of 3.X, the interpolation steps
+                // are not performed by the integrator itself
+                T[][] reducedFieldA = MathArrays.buildArray(field, 12, -1);
+                T[]   reducedFieldB = MathArrays.buildArray(field, 13);
+                T[]   reducedFieldC = MathArrays.buildArray(field, 12);
+                System.arraycopy(fieldA, 0, reducedFieldA, 0, reducedFieldA.length);
+                System.arraycopy(fieldB, 0, reducedFieldB, 0, reducedFieldB.length);
+                System.arraycopy(fieldC, 0, reducedFieldC, 0, reducedFieldC.length);
+                fieldA = reducedFieldA;
+                fieldB = reducedFieldB;
+                fieldC = reducedFieldC;
+            }
 
             String fieldName   = fieldIntegrator.getClass().getName();
             String regularName = fieldName.replaceAll("Field", "");

http://git-wip-us.apache.org/repos/asf/commons-math/blob/7a1c10a1/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
index 47a59ba..ca777ba 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
@@ -49,12 +49,12 @@ public class DormandPrince853FieldIntegratorTest extends AbstractEmbeddedRungeKu
 
     @Test
     public void testBackward() {
-        doTestBackward(Decimal64Field.getInstance(), 1.1e-7, 1.1e-7, 1.0e-12, "Dormand-Prince 8 (5, 3)");
+        doTestBackward(Decimal64Field.getInstance(), 8.1e-8, 1.1e-7, 1.0e-12, "Dormand-Prince 8 (5, 3)");
     }
 
     @Test
     public void testKepler() {
-        doTestKepler(Decimal64Field.getInstance(), 2.4e-10);
+        doTestKepler(Decimal64Field.getInstance(), 4.4e-11);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/commons-math/blob/7a1c10a1/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
index 1aec284..bbef7b4 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
@@ -38,12 +38,12 @@ public class DormandPrince853FieldStepInterpolatorTest extends AbstractRungeKutt
 
     @Test
     public void interpolationInside() {
-        doInterpolationInside(Decimal64Field.getInstance(), 1.0e-50, 1.0e-50);
+        doInterpolationInside(Decimal64Field.getInstance(), 3.1e-17, 3.4e-16);
     }
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.0e-50, 1.0e-50, 1.0e-50, 1.0e-50);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 3.4e-12, 5.7e-11, 1.9e-10, 3.1e-9);
     }
 
 }


[03/50] [abbrv] [math] Added tests for 3/8 integrator.

Posted by lu...@apache.org.
Added tests for 3/8 integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/eef2ed31
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/eef2ed31
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/eef2ed31

Branch: refs/heads/master
Commit: eef2ed3144d873a56cf5f62cd81dddea87d37544
Parents: 34f1f6a
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:09 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:09 2016 +0100

----------------------------------------------------------------------
 .../ThreeEighthesFieldIntegratorTest.java       | 99 ++++++++++++++++++++
 1 file changed, 99 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/eef2ed31/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
new file mode 100644
index 0000000..3feb0cd
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.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 {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, T step) {
+        return new ThreeEighthesFieldIntegrator<T>(field, step);
+    }
+
+    @Test
+    public void testNonFieldIntegratorConsistency() {
+        doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testMissedEndEvent() {
+        doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 6.0e-5);
+    }
+
+    @Test
+    public void testSanityChecks() {
+        doTestSanityChecks(Decimal64Field.getInstance());
+    }
+
+    @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, "3/8");
+    }
+
+    @Test
+    public void testBigStep() {
+        doTestBigStep(Decimal64Field.getInstance(), 0.0004, 0.005, 1.0e-12, "3/8");
+
+    }
+
+    @Test
+    public void testBackward() {
+        doTestBackward(Decimal64Field.getInstance(), 5.0e-10, 7.0e-10, 1.0e-12, "3/8");
+    }
+
+    @Test
+    public void testKepler() {
+        doTestKepler(Decimal64Field.getInstance(), 0.0348, 1.0e-4);
+    }
+
+    @Test
+    public void testStepSize() {
+        doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
+    }
+
+    @Test
+    public void testSingleStep() {
+        doTestSingleStep(Decimal64Field.getInstance(), 0.21);
+    }
+
+    @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);
+    }
+
+}


[38/50] [abbrv] [math] Reintroduced @Override as master needs at least Java 7.

Posted by lu...@apache.org.
Reintroduced @Override as master needs at least Java 7.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/0aa826e8
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0aa826e8
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0aa826e8

Branch: refs/heads/master
Commit: 0aa826e84b14f6f39b23a057986c1329657b9c46
Parents: 6e4265d
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:40:45 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:40:45 2016 +0100

----------------------------------------------------------------------
 .../commons/math4/ode/AbstractFieldIntegrator.java    | 14 ++++++++++++++
 .../commons/math4/ode/ContinuousOutputFieldModel.java |  1 +
 .../commons/math4/ode/events/FieldEventState.java     |  1 +
 .../ClassicalRungeKuttaFieldStepInterpolator.java     |  1 +
 .../DormandPrince54FieldStepInterpolator.java         |  1 +
 .../DormandPrince853FieldStepInterpolator.java        |  1 +
 .../ode/nonstiff/EulerFieldStepInterpolator.java      |  1 +
 .../math4/ode/nonstiff/GillFieldStepInterpolator.java |  1 +
 .../nonstiff/HighamHall54FieldStepInterpolator.java   |  1 +
 .../ode/nonstiff/LutherFieldStepInterpolator.java     |  1 +
 .../ode/nonstiff/MidpointFieldStepInterpolator.java   |  1 +
 .../ode/nonstiff/RungeKuttaFieldStepInterpolator.java |  1 +
 .../nonstiff/ThreeEighthesFieldStepInterpolator.java  |  1 +
 .../ode/sampling/AbstractFieldStepInterpolator.java   |  4 ++++
 .../math4/ode/sampling/FieldStepNormalizer.java       |  1 +
 15 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
index 81f4085..d741de5 100644
--- a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
@@ -108,26 +108,31 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
     }
 
     /** {@inheritDoc} */
+    @Override
     public String getName() {
         return name;
     }
 
     /** {@inheritDoc} */
+    @Override
     public void addStepHandler(final FieldStepHandler<T> handler) {
         stepHandlers.add(handler);
     }
 
     /** {@inheritDoc} */
+    @Override
     public Collection<FieldStepHandler<T>> getStepHandlers() {
         return Collections.unmodifiableCollection(stepHandlers);
     }
 
     /** {@inheritDoc} */
+    @Override
     public void clearStepHandlers() {
         stepHandlers.clear();
     }
 
     /** {@inheritDoc} */
+    @Override
     public void addEventHandler(final FieldEventHandler<T> handler,
                                 final double maxCheckInterval,
                                 final double convergence,
@@ -141,6 +146,7 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
     }
 
     /** {@inheritDoc} */
+    @Override
     public void addEventHandler(final FieldEventHandler<T> handler,
                                 final double maxCheckInterval,
                                 final double convergence,
@@ -151,6 +157,7 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
     }
 
     /** {@inheritDoc} */
+    @Override
     public Collection<FieldEventHandler<T>> getEventHandlers() {
         final List<FieldEventHandler<T>> list = new ArrayList<FieldEventHandler<T>>(eventsStates.size());
         for (FieldEventState<T> state : eventsStates) {
@@ -160,31 +167,37 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
     }
 
     /** {@inheritDoc} */
+    @Override
     public void clearEventHandlers() {
         eventsStates.clear();
     }
 
     /** {@inheritDoc} */
+    @Override
     public FieldODEStateAndDerivative<T> getCurrentStepStart() {
         return stepStart;
     }
 
     /** {@inheritDoc} */
+    @Override
     public T getCurrentSignedStepsize() {
         return stepSize;
     }
 
     /** {@inheritDoc} */
+    @Override
     public void setMaxEvaluations(int maxEvaluations) {
         evaluations = evaluations.withMaximalCount((maxEvaluations < 0) ? Integer.MAX_VALUE : maxEvaluations);
     }
 
     /** {@inheritDoc} */
+    @Override
     public int getMaxEvaluations() {
         return evaluations.getMaximalCount();
     }
 
     /** {@inheritDoc} */
+    @Override
     public int getEvaluations() {
         return evaluations.getCount();
     }
@@ -294,6 +307,7 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
             SortedSet<FieldEventState<T>> occurringEvents = new TreeSet<FieldEventState<T>>(new Comparator<FieldEventState<T>>() {
 
                 /** {@inheritDoc} */
+                @Override
                 public int compare(FieldEventState<T> es0, FieldEventState<T> es1) {
                     return orderingSign * Double.compare(es0.getEventTime().getReal(), es1.getEventTime().getReal());
                 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java b/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
index e9a1a29..e8b96a1 100644
--- a/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
+++ b/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
@@ -176,6 +176,7 @@ public class ContinuousOutputFieldModel<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     public void init(final FieldODEStateAndDerivative<T> initialState, final T t) {
         initialTime = initialState.getTime();
         finalTime   = t;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java b/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java
index 49b25bd..cfbbd43 100644
--- a/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java
+++ b/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java
@@ -204,6 +204,7 @@ public class FieldEventState<T extends RealFieldElement<T>> {
 
         final RealFieldUnivariateFunction<T> f = new RealFieldUnivariateFunction<T>() {
             /** {@inheritDoc} */
+            @Override
             public T value(final T t) {
                 return handler.g(interpolator.getInterpolatedState(t));
             }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java
index 9b70331..522530b 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldStepInterpolator.java
@@ -82,6 +82,7 @@ class ClassicalRungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected ClassicalRungeKuttaFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                                  final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                                  final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java
index c9495e2..16a2fe4 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolator.java
@@ -107,6 +107,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected DormandPrince54FieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                                  final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                                  final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
index 9f4b2b0..e4d7ee5 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolator.java
@@ -188,6 +188,7 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected DormandPrince853FieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                                final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                                final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java
index 133e540..e57865a 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolator.java
@@ -72,6 +72,7 @@ class EulerFieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected EulerFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                                  final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                                  final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java
index fdb16cb..bb00d04 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolator.java
@@ -90,6 +90,7 @@ class GillFieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected GillFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                   final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                   final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
index c5402c2..a915e26 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolator.java
@@ -58,6 +58,7 @@ class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected HighamHall54FieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                           final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                           final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
index 22bc403..438e09e 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
@@ -118,6 +118,7 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected LutherFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                     final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                     final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java
index 5a01a35..03bd70d 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolator.java
@@ -74,6 +74,7 @@ class MidpointFieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected MidpointFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                       final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                       final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java
index 9595ee2..20bff18 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java
@@ -69,6 +69,7 @@ abstract class RungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected RungeKuttaFieldStepInterpolator<T> create(boolean newForward,
                                                         FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                         FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java
index 6faffd1..69df7f8 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java
@@ -84,6 +84,7 @@ class ThreeEighthesFieldStepInterpolator<T extends RealFieldElement<T>>
     }
 
     /** {@inheritDoc} */
+    @Override
     protected ThreeEighthesFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
                                                            final FieldODEStateAndDerivative<T> newGlobalPreviousState,
                                                            final FieldODEStateAndDerivative<T> newGlobalCurrentState,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
index 0486cef..b9a5de2 100644
--- a/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
@@ -128,16 +128,19 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
     }
 
     /** {@inheritDoc} */
+    @Override
     public FieldODEStateAndDerivative<T> getPreviousState() {
         return softPreviousState;
     }
 
     /** {@inheritDoc} */
+    @Override
     public FieldODEStateAndDerivative<T> getCurrentState() {
         return softCurrentState;
     }
 
     /** {@inheritDoc} */
+    @Override
     public FieldODEStateAndDerivative<T> getInterpolatedState(final T time) {
         final T thetaH         = time.subtract(globalPreviousState.getTime());
         final T oneMinusThetaH = globalCurrentState.getTime().subtract(time);
@@ -146,6 +149,7 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
     }
 
     /** {@inheritDoc} */
+    @Override
     public boolean isForward() {
         return forward;
     }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0aa826e8/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepNormalizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepNormalizer.java b/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepNormalizer.java
index 8551e14..9038080 100644
--- a/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepNormalizer.java
+++ b/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepNormalizer.java
@@ -168,6 +168,7 @@ public class FieldStepNormalizer<T extends RealFieldElement<T>> implements Field
     }
 
     /** {@inheritDoc} */
+    @Override
     public void init(final FieldODEStateAndDerivative<T> initialState, final T finalTime) {
 
         first   = null;


[49/50] [abbrv] [math] Renamed abstract test classes to match build environment filters.

Posted by lu...@apache.org.
Renamed abstract test classes to match build environment filters.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/9d47e0f9
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/9d47e0f9
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/9d47e0f9

Branch: refs/heads/master
Commit: 9d47e0f911981bee44146aa40ade3571f64e2d3f
Parents: f0a39a8
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:27:52 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:27:52 2016 +0100

----------------------------------------------------------------------
 .../AbstractAdamsFieldIntegratorTest.java       | 260 --------
 ...ractRungeKuttaFieldStepInterpolatorTest.java | 305 ---------
 .../AdamsBashforthFieldIntegratorTest.java      |   2 +-
 .../AdamsFieldIntegratorAbstractTest.java       | 260 ++++++++
 .../AdamsMoultonFieldIntegratorTest.java        |   2 +-
 ...sicalRungKuttaFieldStepInterpolatorTest.java |   2 +-
 .../ClassicalRungeKuttaFieldIntegratorTest.java |   2 +-
 .../DormandPrince54FieldIntegratorTest.java     |   2 +-
 ...ormandPrince54FieldStepInterpolatorTest.java |   2 +-
 .../DormandPrince853FieldIntegratorTest.java    |   2 +-
 ...rmandPrince853FieldStepInterpolatorTest.java |   2 +-
 ...edRungeKuttaFieldIntegratorAbstractTest.java | 600 +++++++++++++++++
 .../ode/nonstiff/EulerFieldIntegratorTest.java  |   2 +-
 .../EulerFieldStepInterpolatorTest.java         |   2 +-
 .../ode/nonstiff/GillFieldIntegratorTest.java   |   2 +-
 .../nonstiff/GillFieldStepInterpolatorTest.java |   2 +-
 .../HighamHall54FieldIntegratorTest.java        |   2 +-
 .../HighamHall54FieldStepInterpolatorTest.java  |   2 +-
 .../ode/nonstiff/LutherFieldIntegratorTest.java |   2 +-
 .../LutherFieldStepInterpolatorTest.java        |   2 +-
 .../nonstiff/MidpointFieldIntegratorTest.java   |   2 +-
 .../MidpointFieldStepInterpolatorTest.java      |   2 +-
 .../RungeKuttaFieldIntegratorAbstractTest.java  | 662 +++++++++++++++++++
 ...eKuttaFieldStepInterpolatorAbstractTest.java | 305 +++++++++
 .../ThreeEighthesFieldIntegratorTest.java       |   2 +-
 .../ThreeEighthesFieldStepInterpolatorTest.java |   2 +-
 26 files changed, 1847 insertions(+), 585 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
deleted file mode 100644
index 606c9e8..0000000
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * 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.apache.commons.math4.ode.nonstiff;
-
-
-import org.apache.commons.math4.Field;
-import org.apache.commons.math4.RealFieldElement;
-import org.apache.commons.math4.exception.MathIllegalStateException;
-import org.apache.commons.math4.exception.MaxCountExceededException;
-import org.apache.commons.math4.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.ode.AbstractFieldIntegrator;
-import org.apache.commons.math4.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldODEState;
-import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
-import org.apache.commons.math4.ode.FirstOrderFieldIntegrator;
-import org.apache.commons.math4.ode.MultistepFieldIntegrator;
-import org.apache.commons.math4.ode.TestFieldProblem1;
-import org.apache.commons.math4.ode.TestFieldProblem5;
-import org.apache.commons.math4.ode.TestFieldProblem6;
-import org.apache.commons.math4.ode.TestFieldProblemAbstract;
-import org.apache.commons.math4.ode.TestFieldProblemHandler;
-import org.apache.commons.math4.ode.sampling.FieldStepHandler;
-import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
-import org.apache.commons.math4.util.FastMath;
-import org.junit.Assert;
-import org.junit.Test;
-
-public abstract class AbstractAdamsFieldIntegratorTest {
-
-    protected abstract <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
-    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
-                     final double scalAbsoluteTolerance, final double scalRelativeTolerance);
-
-    protected abstract <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
-    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
-                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance);
-
-    @Test(expected=NumberIsTooSmallException.class)
-    public abstract void testMinStep();
-
-    protected <T extends RealFieldElement<T>> void doDimensionCheck(final Field<T> field) {
-        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
-
-        double minStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.1).getReal();
-        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
-        double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
-        double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
-
-        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 4, minStep, maxStep,
-                                                              vecAbsoluteTolerance,
-                                                              vecRelativeTolerance);
-        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
-        integ.addStepHandler(handler);
-        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
-
-    }
-
-    @Test
-    public abstract void testIncreasingTolerance();
-
-    protected <T extends RealFieldElement<T>> void doTestIncreasingTolerance(final Field<T> field,
-                                                                             double ratioMin, double ratioMax) {
-
-        int previousCalls = Integer.MAX_VALUE;
-        for (int i = -12; i < -2; ++i) {
-            TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
-            double minStep = 0;
-            double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
-            double scalAbsoluteTolerance = FastMath.pow(10.0, i);
-            double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
-
-            FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 4, minStep, maxStep,
-                                                                  scalAbsoluteTolerance,
-                                                                  scalRelativeTolerance);
-            TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
-            integ.addStepHandler(handler);
-            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
-
-            Assert.assertTrue(handler.getMaximalValueError().getReal() > ratioMin * scalAbsoluteTolerance);
-            Assert.assertTrue(handler.getMaximalValueError().getReal() < ratioMax * scalAbsoluteTolerance);
-
-            int calls = pb.getCalls();
-            Assert.assertEquals(integ.getEvaluations(), calls);
-            Assert.assertTrue(calls <= previousCalls);
-            previousCalls = calls;
-
-        }
-
-    }
-
-    @Test(expected = MaxCountExceededException.class)
-    public abstract void exceedMaxEvaluations();
-
-    protected <T extends RealFieldElement<T>> void doExceedMaxEvaluations(final Field<T> field, final int max) {
-
-        TestFieldProblem1<T> pb  = new TestFieldProblem1<T>(field);
-        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
-
-        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 2, 0, range, 1.0e-12, 1.0e-12);
-        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
-        integ.addStepHandler(handler);
-        integ.setMaxEvaluations(max);
-        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
-
-    }
-
-    @Test
-    public abstract void backward();
-
-    protected <T extends RealFieldElement<T>> void doBackward(final Field<T> field,
-                                                              final double epsilonLast,
-                                                              final double epsilonMaxValue,
-                                                              final double epsilonMaxTime,
-                                                              final String name) {
-
-        TestFieldProblem5<T> pb = new TestFieldProblem5<T>(field);
-        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
-
-        AdamsFieldIntegrator<T> integ = createIntegrator(field, 4, 0, range, 1.0e-12, 1.0e-12);
-        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
-        integ.addStepHandler(handler);
-        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
-
-        Assert.assertEquals(0.0, handler.getLastError().getReal(), epsilonLast);
-        Assert.assertEquals(0.0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
-        Assert.assertEquals(0, handler.getMaximalTimeError().getReal(), epsilonMaxTime);
-        Assert.assertEquals(name, integ.getName());
-    }
-
-    @Test
-    public abstract void polynomial();
-
-    protected <T extends RealFieldElement<T>> void doPolynomial(final Field<T> field,
-                                                                final int nLimit,
-                                                                final double epsilonBad,
-                                                                final double epsilonGood) {
-        TestFieldProblem6<T> pb = new TestFieldProblem6<T>(field);
-        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).abs().getReal();
-
-        for (int nSteps = 2; nSteps < 8; ++nSteps) {
-            AdamsFieldIntegrator<T> integ = createIntegrator(field, nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-4, 1.0e-4);
-            integ.setStarterIntegrator(new PerfectStarter<T>(pb, nSteps));
-            TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
-            integ.addStepHandler(handler);
-            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
-            if (nSteps < nLimit) {
-                Assert.assertTrue(handler.getMaximalValueError().getReal() > epsilonBad);
-            } else {
-                Assert.assertTrue(handler.getMaximalValueError().getReal() < epsilonGood);
-            }
-        }
-
-    }
-
-    @Test(expected=MathIllegalStateException.class)
-    public abstract void testStartFailure();
-
-    protected <T extends RealFieldElement<T>> void doTestStartFailure(final Field<T> field) {
-        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
-        double minStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.0001).getReal();
-        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
-        double scalAbsoluteTolerance = 1.0e-6;
-        double scalRelativeTolerance = 1.0e-7;
-
-        MultistepFieldIntegrator<T> integ = createIntegrator(field, 6, minStep, maxStep,
-                                                             scalAbsoluteTolerance,
-                                                             scalRelativeTolerance);
-        integ.setStarterIntegrator(new DormandPrince853FieldIntegrator<T>(field, maxStep * 0.5, maxStep, 0.1, 0.1));
-        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
-        integ.addStepHandler(handler);
-        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
-
-    }
-
-    private static class PerfectStarter<T extends RealFieldElement<T>> extends AbstractFieldIntegrator<T> {
-
-        private final PerfectInterpolator<T> interpolator;
-        private final int nbSteps;
-
-        public PerfectStarter(final TestFieldProblemAbstract<T> problem, final int nbSteps) {
-            super(problem.getField(), "perfect-starter");
-            this.interpolator = new PerfectInterpolator<T>(problem);
-            this.nbSteps      = nbSteps;
-        }
-
-        public FieldODEStateAndDerivative<T> integrate(FieldExpandableODE<T> equations,
-                                                       FieldODEState<T> initialState, T finalTime) {
-            T tStart = initialState.getTime().add(finalTime.subtract(initialState.getTime()).multiply(0.01));
-            getEvaluationsCounter().increment(nbSteps);
-            interpolator.setCurrentTime(initialState.getTime());
-            for (int i = 0; i < nbSteps; ++i) {
-                T tK = initialState.getTime().multiply(nbSteps - 1 - (i + 1)).add(tStart.multiply(i + 1)).divide(nbSteps - 1);
-                interpolator.setPreviousTime(interpolator.getCurrentTime());
-                interpolator.setCurrentTime(tK);
-                for (FieldStepHandler<T> handler : getStepHandlers()) {
-                    handler.handleStep(interpolator, i == nbSteps - 1);
-                }
-            }
-            return interpolator.getInterpolatedState(tStart);
-        }
-
-    }
-
-    private static class PerfectInterpolator<T extends RealFieldElement<T>> implements FieldStepInterpolator<T> {
-        private final TestFieldProblemAbstract<T> problem;
-        private T previousTime;
-        private T currentTime;
-
-        public PerfectInterpolator(final TestFieldProblemAbstract<T> problem) {
-            this.problem = problem;
-        }
-
-        public void setPreviousTime(T previousTime) {
-            this.previousTime = previousTime;
-        }
-
-        public void setCurrentTime(T currentTime) {
-            this.currentTime = currentTime;
-        }
-
-        public T getCurrentTime() {
-            return currentTime;
-        }
-
-        public boolean isForward() {
-            return problem.getFinalTime().subtract(problem.getInitialState().getTime()).getReal() >= 0;
-        }
-
-        public FieldODEStateAndDerivative<T> getPreviousState() {
-            return getInterpolatedState(previousTime);
-        }
-
-        public FieldODEStateAndDerivative<T> getCurrentState() {
-            return getInterpolatedState(currentTime);
-        }
-
-        public FieldODEStateAndDerivative<T> getInterpolatedState(T time) {
-            T[] y    = problem.computeTheoreticalState(time);
-            T[] yDot = problem.computeDerivatives(time, y);
-            return new FieldODEStateAndDerivative<T>(time, y, yDot);
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
deleted file mode 100644
index 100db47..0000000
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * 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.apache.commons.math4.ode.nonstiff;
-
-
-import org.apache.commons.math4.Field;
-import org.apache.commons.math4.RealFieldElement;
-import org.apache.commons.math4.ode.AbstractIntegrator;
-import org.apache.commons.math4.ode.EquationsMapper;
-import org.apache.commons.math4.ode.ExpandableStatefulODE;
-import org.apache.commons.math4.ode.FieldEquationsMapper;
-import org.apache.commons.math4.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
-import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
-import org.apache.commons.math4.ode.sampling.AbstractFieldStepInterpolator;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
-import org.junit.Assert;
-import org.junit.Test;
-
-public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
-
-    protected abstract <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-        createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
-                           FieldODEStateAndDerivative<T> globalPreviousState,
-                           FieldODEStateAndDerivative<T> globalCurrentState,
-                           FieldODEStateAndDerivative<T> softPreviousState,
-                           FieldODEStateAndDerivative<T> softCurrentState,
-                           FieldEquationsMapper<T> mapper);
-
-    protected abstract <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
-        createButcherArrayProvider(final Field<T> field);
-
-    @Test
-    public abstract void interpolationAtBounds();
-
-    protected <T extends RealFieldElement<T>> void doInterpolationAtBounds(final Field<T> field, double epsilon) {
-
-        RungeKuttaFieldStepInterpolator<T> interpolator = setUpInterpolator(field,
-                                                                            new SinCos<T>(field),
-                                                                            0.0, new double[] { 0.0, 1.0 }, 0.125);
-
-        Assert.assertEquals(0.0, interpolator.getPreviousState().getTime().getReal(), 1.0e-15);
-        for (int i = 0; i < 2; ++i) {
-            Assert.assertEquals(interpolator.getPreviousState().getState()[i].getReal(),
-                                interpolator.getInterpolatedState(interpolator.getPreviousState().getTime()).getState()[i].getReal(),
-                                epsilon);
-        }
-        Assert.assertEquals(0.125, interpolator.getCurrentState().getTime().getReal(), 1.0e-15);
-        for (int i = 0; i < 2; ++i) {
-            Assert.assertEquals(interpolator.getCurrentState().getState()[i].getReal(),
-                                interpolator.getInterpolatedState(interpolator.getCurrentState().getTime()).getState()[i].getReal(),
-                                epsilon);
-        }
-
-    }
-
-    @Test
-    public abstract void interpolationInside();
-
-    protected <T extends RealFieldElement<T>> void doInterpolationInside(final Field<T> field,
-                                                                         double epsilonSin, double epsilonCos) {
-
-        RungeKuttaFieldStepInterpolator<T> interpolator = setUpInterpolator(field,
-                                                                            new SinCos<T>(field),
-                                                                            0.0, new double[] { 0.0, 1.0 }, 0.0125);
-
-        int n = 100;
-        double maxErrorSin = 0;
-        double maxErrorCos = 0;
-        for (int i = 0; i <= n; ++i) {
-            T t =     interpolator.getPreviousState().getTime().multiply(n - i).
-                  add(interpolator.getCurrentState().getTime().multiply(i)).
-                  divide(n);
-            FieldODEStateAndDerivative<T> state = interpolator.getInterpolatedState(t);
-            maxErrorSin = FastMath.max(maxErrorSin, state.getState()[0].subtract(t.sin()).abs().getReal());
-            maxErrorCos = FastMath.max(maxErrorCos, state.getState()[1].subtract(t.cos()).abs().getReal());
-        }
-        Assert.assertEquals(0.0, maxErrorSin, epsilonSin);
-        Assert.assertEquals(0.0, maxErrorCos, epsilonCos);
-
-    }
-
-    @Test
-    public abstract void nonFieldInterpolatorConsistency();
-
-    protected <T extends RealFieldElement<T>> void doNonFieldInterpolatorConsistency(final Field<T> field,
-                                                                                     double epsilonSin, double epsilonCos,
-                                                                                     double epsilonSinDot, double epsilonCosDot) {
-
-        FirstOrderFieldDifferentialEquations<T> eqn = new SinCos<T>(field);
-        RungeKuttaFieldStepInterpolator<T> fieldInterpolator =
-                        setUpInterpolator(field, eqn, 0.0, new double[] { 0.0, 1.0 }, 0.125);
-        RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator, eqn);
-
-        int n = 100;
-        double maxErrorSin    = 0;
-        double maxErrorCos    = 0;
-        double maxErrorSinDot = 0;
-        double maxErrorCosDot = 0;
-        for (int i = 0; i <= n; ++i) {
-
-            T t =     fieldInterpolator.getPreviousState().getTime().multiply(n - i).
-                  add(fieldInterpolator.getCurrentState().getTime().multiply(i)).
-                  divide(n);
-
-            FieldODEStateAndDerivative<T> state = fieldInterpolator.getInterpolatedState(t);
-            T[] fieldY    = state.getState();
-            T[] fieldYDot = state.getDerivative();
-
-            regularInterpolator.setInterpolatedTime(t.getReal());
-            double[] regularY     = regularInterpolator.getInterpolatedState();
-            double[] regularYDot  = regularInterpolator.getInterpolatedDerivatives();
-
-            maxErrorSin    = FastMath.max(maxErrorSin,    fieldY[0].subtract(regularY[0]).abs().getReal());
-            maxErrorCos    = FastMath.max(maxErrorCos,    fieldY[1].subtract(regularY[1]).abs().getReal());
-            maxErrorSinDot = FastMath.max(maxErrorSinDot, fieldYDot[0].subtract(regularYDot[0]).abs().getReal());
-            maxErrorCosDot = FastMath.max(maxErrorCosDot, fieldYDot[1].subtract(regularYDot[1]).abs().getReal());
-
-        }
-        Assert.assertEquals(0.0, maxErrorSin,    epsilonSin);
-        Assert.assertEquals(0.0, maxErrorCos,    epsilonCos);
-        Assert.assertEquals(0.0, maxErrorSinDot, epsilonSinDot);
-        Assert.assertEquals(0.0, maxErrorCosDot, epsilonCosDot);
-
-    }
-
-    private <T extends RealFieldElement<T>>
-    RungeKuttaFieldStepInterpolator<T> setUpInterpolator(final Field<T> field,
-                                                         final FirstOrderFieldDifferentialEquations<T> eqn,
-                                                         final double t0, final double[] y0,
-                                                         final double t1) {
-
-        // get the Butcher arrays from the field integrator
-        FieldButcherArrayProvider<T> provider = createButcherArrayProvider(field);
-        T[][] a = provider.getA();
-        T[]   b = provider.getB();
-        T[]   c = provider.getC();
-
-        // store initial state
-        T     t          = field.getZero().add(t0);
-        T[]   fieldY     = MathArrays.buildArray(field, eqn.getDimension());
-        T[][] fieldYDotK = MathArrays.buildArray(field, b.length, -1);
-        for (int i = 0; i < y0.length; ++i) {
-            fieldY[i] = field.getZero().add(y0[i]);
-        }
-        fieldYDotK[0] = eqn.computeDerivatives(t, fieldY);
-        FieldODEStateAndDerivative<T> s0 = new FieldODEStateAndDerivative<T>(t, fieldY, fieldYDotK[0]);
-
-        // perform one integration step, in order to get consistent derivatives
-        T h = field.getZero().add(t1 - t0);
-        for (int k = 0; k < a.length; ++k) {
-            for (int i = 0; i < y0.length; ++i) {
-                fieldY[i] = field.getZero().add(y0[i]);
-                for (int s = 0; s <= k; ++s) {
-                    fieldY[i] = fieldY[i].add(h.multiply(a[k][s].multiply(fieldYDotK[s][i])));
-                }
-            }
-            fieldYDotK[k + 1] = eqn.computeDerivatives(h.multiply(c[k]).add(t0), fieldY);
-        }
-
-        // store state at step end
-        t = field.getZero().add(t1);
-        for (int i = 0; i < y0.length; ++i) {
-            fieldY[i] = field.getZero().add(y0[i]);
-            for (int s = 0; s < b.length; ++s) {
-                fieldY[i] = fieldY[i].add(h.multiply(b[s].multiply(fieldYDotK[s][i])));
-            }
-        }
-        FieldODEStateAndDerivative<T> s1 = new FieldODEStateAndDerivative<T>(t, fieldY,
-                                                                             eqn.computeDerivatives(t, fieldY));
-
-        return createInterpolator(field, t1 > t0, fieldYDotK, s0, s1, s0, s1,
-                                  new FieldExpandableODE<T>(eqn).getMapper());
-
-    }
-
-    private <T extends RealFieldElement<T>>
-    RungeKuttaStepInterpolator convertInterpolator(final RungeKuttaFieldStepInterpolator<T> fieldInterpolator,
-                                                   final FirstOrderFieldDifferentialEquations<T> eqn) {
-
-        RungeKuttaStepInterpolator regularInterpolator = null;
-        try {
-
-            String interpolatorName = fieldInterpolator.getClass().getName();
-            String integratorName = interpolatorName.replaceAll("Field", "");
-            @SuppressWarnings("unchecked")
-            Class<RungeKuttaStepInterpolator> clz = (Class<RungeKuttaStepInterpolator>) Class.forName(integratorName);
-            regularInterpolator = clz.newInstance();
-
-            double[][] yDotArray = null;
-            java.lang.reflect.Field fYD = RungeKuttaFieldStepInterpolator.class.getDeclaredField("yDotK");
-            fYD.setAccessible(true);
-            @SuppressWarnings("unchecked")
-            T[][] fieldYDotk = (T[][]) fYD.get(fieldInterpolator);
-            yDotArray = new double[fieldYDotk.length][];
-            for (int i = 0; i < yDotArray.length; ++i) {
-                yDotArray[i] = new double[fieldYDotk[i].length];
-                for (int j = 0; j < yDotArray[i].length; ++j) {
-                    yDotArray[i][j] = fieldYDotk[i][j].getReal();
-                }
-            }
-            double[] y = new double[yDotArray[0].length];
-
-            EquationsMapper primaryMapper = null;
-            EquationsMapper[] secondaryMappers = null;
-            java.lang.reflect.Field fMapper = AbstractFieldStepInterpolator.class.getDeclaredField("mapper");
-            fMapper.setAccessible(true);
-            @SuppressWarnings("unchecked")
-            FieldEquationsMapper<T> mapper = (FieldEquationsMapper<T>) fMapper.get(fieldInterpolator);
-            java.lang.reflect.Field fStart = FieldEquationsMapper.class.getDeclaredField("start");
-            fStart.setAccessible(true);
-            int[] start = (int[]) fStart.get(mapper);
-            primaryMapper = new EquationsMapper(start[0], start[1]);
-            secondaryMappers = new EquationsMapper[mapper.getNumberOfEquations() - 1];
-            for (int i = 0; i < secondaryMappers.length; ++i) {
-                secondaryMappers[i] = new EquationsMapper(start[i + 1], start[i + 2]);
-            }
-
-            AbstractIntegrator dummyIntegrator = new AbstractIntegrator("dummy") {
-                @Override
-                public void integrate(ExpandableStatefulODE equations, double t) {
-                    Assert.fail("this method should not be called");
-                }
-                @Override
-                public void computeDerivatives(final double t, final double[] y, final double[] yDot) {
-                    T fieldT = fieldInterpolator.getCurrentState().getTime().getField().getZero().add(t);
-                    T[] fieldY = MathArrays.buildArray(fieldInterpolator.getCurrentState().getTime().getField(), y.length);
-                    for (int i = 0; i < y.length; ++i) {
-                        fieldY[i] = fieldInterpolator.getCurrentState().getTime().getField().getZero().add(y[i]);
-                    }
-                    T[] fieldYDot = eqn.computeDerivatives(fieldT, fieldY);
-                    for (int i = 0; i < yDot.length; ++i) {
-                        yDot[i] = fieldYDot[i].getReal();
-                    }
-                }
-            };
-            regularInterpolator.reinitialize(dummyIntegrator, y, yDotArray,
-                                             fieldInterpolator.isForward(),
-                                             primaryMapper, secondaryMappers);
-
-            T[] fieldPreviousY = fieldInterpolator.getPreviousState().getState();
-            for (int i = 0; i < y.length; ++i) {
-                y[i] = fieldPreviousY[i].getReal();
-            }
-            regularInterpolator.storeTime(fieldInterpolator.getPreviousState().getTime().getReal());
-
-            regularInterpolator.shift();
-
-            T[] fieldCurrentY = fieldInterpolator.getCurrentState().getState();
-            for (int i = 0; i < y.length; ++i) {
-                y[i] = fieldCurrentY[i].getReal();
-            }
-            regularInterpolator.storeTime(fieldInterpolator.getCurrentState().getTime().getReal());
-
-        } catch (ClassNotFoundException cnfe) {
-            Assert.fail(cnfe.getLocalizedMessage());
-        } catch (InstantiationException ie) {
-            Assert.fail(ie.getLocalizedMessage());
-        } catch (IllegalAccessException iae) {
-            Assert.fail(iae.getLocalizedMessage());
-        } catch (NoSuchFieldException nsfe) {
-            Assert.fail(nsfe.getLocalizedMessage());
-        } catch (IllegalArgumentException iae) {
-            Assert.fail(iae.getLocalizedMessage());
-        }
-
-        return regularInterpolator;
-
-    }
-
-    private static class SinCos<T extends RealFieldElement<T>> implements FirstOrderFieldDifferentialEquations<T> {
-        private final Field<T> field;
-        protected SinCos(final Field<T> field) {
-            this.field = field;
-        }
-        public int getDimension() {
-            return 2;
-        }
-        public void init(final T t0, final T[] y0, final T finalTime) {
-        }
-        public T[] computeDerivatives(final T t, final T[] y) {
-            T[] yDot = MathArrays.buildArray(field, 2);
-            yDot[0] = y[1];
-            yDot[1] = y[0].negate();
-            return yDot;
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
index e9a046c..ed69ccd 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.exception.NumberIsTooSmallException;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class AdamsBashforthFieldIntegratorTest extends AbstractAdamsFieldIntegratorTest {
+public class AdamsBashforthFieldIntegratorTest extends AdamsFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
     createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegratorAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegratorAbstractTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegratorAbstractTest.java
new file mode 100644
index 0000000..340dd48
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegratorAbstractTest.java
@@ -0,0 +1,260 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.MathIllegalStateException;
+import org.apache.commons.math4.exception.MaxCountExceededException;
+import org.apache.commons.math4.exception.NumberIsTooSmallException;
+import org.apache.commons.math4.ode.AbstractFieldIntegrator;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FieldODEState;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.FirstOrderFieldIntegrator;
+import org.apache.commons.math4.ode.MultistepFieldIntegrator;
+import org.apache.commons.math4.ode.TestFieldProblem1;
+import org.apache.commons.math4.ode.TestFieldProblem5;
+import org.apache.commons.math4.ode.TestFieldProblem6;
+import org.apache.commons.math4.ode.TestFieldProblemAbstract;
+import org.apache.commons.math4.ode.TestFieldProblemHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math4.util.FastMath;
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class AdamsFieldIntegratorAbstractTest {
+
+    protected abstract <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
+    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance);
+
+    protected abstract <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
+    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance);
+
+    @Test(expected=NumberIsTooSmallException.class)
+    public abstract void testMinStep();
+
+    protected <T extends RealFieldElement<T>> void doDimensionCheck(final Field<T> field) {
+        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+
+        double minStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.1).getReal();
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
+        double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
+
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 4, minStep, maxStep,
+                                                              vecAbsoluteTolerance,
+                                                              vecRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+    }
+
+    @Test
+    public abstract void testIncreasingTolerance();
+
+    protected <T extends RealFieldElement<T>> void doTestIncreasingTolerance(final Field<T> field,
+                                                                             double ratioMin, double ratioMax) {
+
+        int previousCalls = Integer.MAX_VALUE;
+        for (int i = -12; i < -2; ++i) {
+            TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+            double minStep = 0;
+            double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+            double scalAbsoluteTolerance = FastMath.pow(10.0, i);
+            double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+            FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 4, minStep, maxStep,
+                                                                  scalAbsoluteTolerance,
+                                                                  scalRelativeTolerance);
+            TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+            integ.addStepHandler(handler);
+            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+            Assert.assertTrue(handler.getMaximalValueError().getReal() > ratioMin * scalAbsoluteTolerance);
+            Assert.assertTrue(handler.getMaximalValueError().getReal() < ratioMax * scalAbsoluteTolerance);
+
+            int calls = pb.getCalls();
+            Assert.assertEquals(integ.getEvaluations(), calls);
+            Assert.assertTrue(calls <= previousCalls);
+            previousCalls = calls;
+
+        }
+
+    }
+
+    @Test(expected = MaxCountExceededException.class)
+    public abstract void exceedMaxEvaluations();
+
+    protected <T extends RealFieldElement<T>> void doExceedMaxEvaluations(final Field<T> field, final int max) {
+
+        TestFieldProblem1<T> pb  = new TestFieldProblem1<T>(field);
+        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 2, 0, range, 1.0e-12, 1.0e-12);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.setMaxEvaluations(max);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+    }
+
+    @Test
+    public abstract void backward();
+
+    protected <T extends RealFieldElement<T>> void doBackward(final Field<T> field,
+                                                              final double epsilonLast,
+                                                              final double epsilonMaxValue,
+                                                              final double epsilonMaxTime,
+                                                              final String name) {
+
+        TestFieldProblem5<T> pb = new TestFieldProblem5<T>(field);
+        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+
+        AdamsFieldIntegrator<T> integ = createIntegrator(field, 4, 0, range, 1.0e-12, 1.0e-12);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+        Assert.assertEquals(0.0, handler.getLastError().getReal(), epsilonLast);
+        Assert.assertEquals(0.0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
+        Assert.assertEquals(0, handler.getMaximalTimeError().getReal(), epsilonMaxTime);
+        Assert.assertEquals(name, integ.getName());
+    }
+
+    @Test
+    public abstract void polynomial();
+
+    protected <T extends RealFieldElement<T>> void doPolynomial(final Field<T> field,
+                                                                final int nLimit,
+                                                                final double epsilonBad,
+                                                                final double epsilonGood) {
+        TestFieldProblem6<T> pb = new TestFieldProblem6<T>(field);
+        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).abs().getReal();
+
+        for (int nSteps = 2; nSteps < 8; ++nSteps) {
+            AdamsFieldIntegrator<T> integ = createIntegrator(field, nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-4, 1.0e-4);
+            integ.setStarterIntegrator(new PerfectStarter<T>(pb, nSteps));
+            TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+            integ.addStepHandler(handler);
+            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+            if (nSteps < nLimit) {
+                Assert.assertTrue(handler.getMaximalValueError().getReal() > epsilonBad);
+            } else {
+                Assert.assertTrue(handler.getMaximalValueError().getReal() < epsilonGood);
+            }
+        }
+
+    }
+
+    @Test(expected=MathIllegalStateException.class)
+    public abstract void testStartFailure();
+
+    protected <T extends RealFieldElement<T>> void doTestStartFailure(final Field<T> field) {
+        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        double minStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.0001).getReal();
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double scalAbsoluteTolerance = 1.0e-6;
+        double scalRelativeTolerance = 1.0e-7;
+
+        MultistepFieldIntegrator<T> integ = createIntegrator(field, 6, minStep, maxStep,
+                                                             scalAbsoluteTolerance,
+                                                             scalRelativeTolerance);
+        integ.setStarterIntegrator(new DormandPrince853FieldIntegrator<T>(field, maxStep * 0.5, maxStep, 0.1, 0.1));
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+    }
+
+    private static class PerfectStarter<T extends RealFieldElement<T>> extends AbstractFieldIntegrator<T> {
+
+        private final PerfectInterpolator<T> interpolator;
+        private final int nbSteps;
+
+        public PerfectStarter(final TestFieldProblemAbstract<T> problem, final int nbSteps) {
+            super(problem.getField(), "perfect-starter");
+            this.interpolator = new PerfectInterpolator<T>(problem);
+            this.nbSteps      = nbSteps;
+        }
+
+        public FieldODEStateAndDerivative<T> integrate(FieldExpandableODE<T> equations,
+                                                       FieldODEState<T> initialState, T finalTime) {
+            T tStart = initialState.getTime().add(finalTime.subtract(initialState.getTime()).multiply(0.01));
+            getEvaluationsCounter().increment(nbSteps);
+            interpolator.setCurrentTime(initialState.getTime());
+            for (int i = 0; i < nbSteps; ++i) {
+                T tK = initialState.getTime().multiply(nbSteps - 1 - (i + 1)).add(tStart.multiply(i + 1)).divide(nbSteps - 1);
+                interpolator.setPreviousTime(interpolator.getCurrentTime());
+                interpolator.setCurrentTime(tK);
+                for (FieldStepHandler<T> handler : getStepHandlers()) {
+                    handler.handleStep(interpolator, i == nbSteps - 1);
+                }
+            }
+            return interpolator.getInterpolatedState(tStart);
+        }
+
+    }
+
+    private static class PerfectInterpolator<T extends RealFieldElement<T>> implements FieldStepInterpolator<T> {
+        private final TestFieldProblemAbstract<T> problem;
+        private T previousTime;
+        private T currentTime;
+
+        public PerfectInterpolator(final TestFieldProblemAbstract<T> problem) {
+            this.problem = problem;
+        }
+
+        public void setPreviousTime(T previousTime) {
+            this.previousTime = previousTime;
+        }
+
+        public void setCurrentTime(T currentTime) {
+            this.currentTime = currentTime;
+        }
+
+        public T getCurrentTime() {
+            return currentTime;
+        }
+
+        public boolean isForward() {
+            return problem.getFinalTime().subtract(problem.getInitialState().getTime()).getReal() >= 0;
+        }
+
+        public FieldODEStateAndDerivative<T> getPreviousState() {
+            return getInterpolatedState(previousTime);
+        }
+
+        public FieldODEStateAndDerivative<T> getCurrentState() {
+            return getInterpolatedState(currentTime);
+        }
+
+        public FieldODEStateAndDerivative<T> getInterpolatedState(T time) {
+            T[] y    = problem.computeTheoreticalState(time);
+            T[] yDot = problem.computeDerivatives(time, y);
+            return new FieldODEStateAndDerivative<T>(time, y, yDot);
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java
index c44124a..51eb7ef 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.exception.NumberIsTooSmallException;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class AdamsMoultonFieldIntegratorTest extends AbstractAdamsFieldIntegratorTest {
+public class AdamsMoultonFieldIntegratorTest extends AdamsFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
     createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
index 527fe25..bbe30c2 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class ClassicalRungKuttaFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class ClassicalRungKuttaFieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
index eec1b56..3cd0e35 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class ClassicalRungeKuttaFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
+public class ClassicalRungeKuttaFieldIntegratorTest extends RungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, T step) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
index 75416ce..da90803 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class DormandPrince54FieldIntegratorTest extends AbstractEmbeddedRungeKuttaFieldIntegratorTest {
+public class DormandPrince54FieldIntegratorTest extends EmbeddedRungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, final double minStep, final double maxStep,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
index ee17388..9b6d607 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class DormandPrince54FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class DormandPrince54FieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
index 065b24a..bc73968 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class DormandPrince853FieldIntegratorTest extends AbstractEmbeddedRungeKuttaFieldIntegratorTest {
+public class DormandPrince853FieldIntegratorTest extends EmbeddedRungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, final double minStep, final double maxStep,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
index a104867..5591b4d 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class DormandPrince853FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class DormandPrince853FieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegratorAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegratorAbstractTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegratorAbstractTest.java
new file mode 100644
index 0000000..045e77d
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegratorAbstractTest.java
@@ -0,0 +1,600 @@
+/*
+ * 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.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;
+import org.apache.commons.math4.exception.NumberIsTooSmallException;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
+import org.apache.commons.math4.ode.FirstOrderFieldIntegrator;
+import org.apache.commons.math4.ode.FieldODEState;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.TestFieldProblem1;
+import org.apache.commons.math4.ode.TestFieldProblem3;
+import org.apache.commons.math4.ode.TestFieldProblem4;
+import org.apache.commons.math4.ode.TestFieldProblem5;
+import org.apache.commons.math4.ode.TestFieldProblemHandler;
+import org.apache.commons.math4.ode.events.Action;
+import org.apache.commons.math4.ode.events.FieldEventHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class EmbeddedRungeKuttaFieldIntegratorAbstractTest {
+
+    protected abstract <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance);
+
+    protected abstract <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance);
+
+    @Test
+    public abstract void testNonFieldIntegratorConsistency();
+
+    protected <T extends RealFieldElement<T>> void doTestNonFieldIntegratorConsistency(final Field<T> field) {
+        try {
+
+            // get the Butcher arrays from the field integrator
+            EmbeddedRungeKuttaFieldIntegrator<T> fieldIntegrator = createIntegrator(field, 0.001, 1.0, 1.0, 1.0);
+            T[][] fieldA = fieldIntegrator.getA();
+            T[]   fieldB = fieldIntegrator.getB();
+            T[]   fieldC = fieldIntegrator.getC();
+            if (fieldIntegrator instanceof DormandPrince853FieldIntegrator) {
+                // special case for Dormand-Prince 8(5,3), the array in the regular
+                // integrator is smaller because as of 3.X, the interpolation steps
+                // are not performed by the integrator itself
+                T[][] reducedFieldA = MathArrays.buildArray(field, 12, -1);
+                T[]   reducedFieldB = MathArrays.buildArray(field, 13);
+                T[]   reducedFieldC = MathArrays.buildArray(field, 12);
+                System.arraycopy(fieldA, 0, reducedFieldA, 0, reducedFieldA.length);
+                System.arraycopy(fieldB, 0, reducedFieldB, 0, reducedFieldB.length);
+                System.arraycopy(fieldC, 0, reducedFieldC, 0, reducedFieldC.length);
+                fieldA = reducedFieldA;
+                fieldB = reducedFieldB;
+                fieldC = reducedFieldC;
+            }
+
+            String fieldName   = fieldIntegrator.getClass().getName();
+            String regularName = fieldName.replaceAll("Field", "");
+
+            // get the Butcher arrays from the regular integrator
+            @SuppressWarnings("unchecked")
+            Class<RungeKuttaIntegrator> c = (Class<RungeKuttaIntegrator>) Class.forName(regularName);
+            java.lang.reflect.Field jlrFieldA = c.getDeclaredField("STATIC_A");
+            jlrFieldA.setAccessible(true);
+            double[][] regularA = (double[][]) jlrFieldA.get(null);
+            java.lang.reflect.Field jlrFieldB = c.getDeclaredField("STATIC_B");
+            jlrFieldB.setAccessible(true);
+            double[]   regularB = (double[])   jlrFieldB.get(null);
+            java.lang.reflect.Field jlrFieldC = c.getDeclaredField("STATIC_C");
+            jlrFieldC.setAccessible(true);
+            double[]   regularC = (double[])   jlrFieldC.get(null);
+
+            Assert.assertEquals(regularA.length, fieldA.length);
+            for (int i = 0; i < regularA.length; ++i) {
+                checkArray(regularA[i], fieldA[i]);
+            }
+            checkArray(regularB, fieldB);
+            checkArray(regularC, fieldC);
+
+        } catch (ClassNotFoundException cnfe) {
+            Assert.fail(cnfe.getLocalizedMessage());
+        } catch (IllegalAccessException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (IllegalArgumentException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (SecurityException se) {
+            Assert.fail(se.getLocalizedMessage());
+        } catch (NoSuchFieldException nsfe) {
+            Assert.fail(nsfe.getLocalizedMessage());
+        }
+    }
+
+    private <T extends RealFieldElement<T>> void checkArray(double[] regularArray, T[] fieldArray) {
+        Assert.assertEquals(regularArray.length, fieldArray.length);
+        for (int i = 0; i < regularArray.length; ++i) {
+            if (regularArray[i] == 0) {
+                Assert.assertTrue(0.0 == fieldArray[i].getReal());
+            } else {
+                Assert.assertEquals(regularArray[i], fieldArray[i].getReal(), FastMath.ulp(regularArray[i]));
+            }
+        }
+    }
+
+    @Test
+    public abstract void testForwardBackwardExceptions();
+
+    protected <T extends RealFieldElement<T>> void doTestForwardBackwardExceptions(final Field<T> field) {
+        FirstOrderFieldDifferentialEquations<T> equations = new FirstOrderFieldDifferentialEquations<T>() {
+
+            public int getDimension() {
+                return 1;
+            }
+
+            public void init(T t0, T[] y0, T t) {
+            }
+
+            public T[] computeDerivatives(T t, T[] y) {
+                if (t.getReal() < -0.5) {
+                    throw new LocalException();
+                } else {
+                    throw new RuntimeException("oops");
+                }
+            }
+        };
+
+        EmbeddedRungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, 0.0, 1.0, 1.0e-10, 1.0e-10);
+
+        try  {
+            integrator.integrate(new FieldExpandableODE<T>(equations),
+                                 new FieldODEState<T>(field.getOne().negate(),
+                                                      MathArrays.buildArray(field, 1)),
+                                 field.getZero());
+            Assert.fail("an exception should have been thrown");
+          } catch(LocalException de) {
+            // expected behavior
+          }
+
+          try  {
+              integrator.integrate(new FieldExpandableODE<T>(equations),
+                                   new FieldODEState<T>(field.getZero(),
+                                                        MathArrays.buildArray(field, 1)),
+                                   field.getOne());
+               Assert.fail("an exception should have been thrown");
+          } catch(RuntimeException de) {
+            // expected behavior
+          }
+    }
+
+    protected static class LocalException extends RuntimeException {
+        private static final long serialVersionUID = 20151208L;
+    }
+
+    @Test(expected=NumberIsTooSmallException.class)
+    public abstract void testMinStep();
+
+    protected <T extends RealFieldElement<T>> void doTestMinStep(final Field<T> field)
+        throws NumberIsTooSmallException {
+
+        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        double minStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.1).getReal();
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
+        double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
+
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                              vecAbsoluteTolerance, vecRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+        Assert.fail("an exception should have been thrown");
+
+    }
+
+    @Test
+    public abstract void testIncreasingTolerance();
+
+    protected <T extends RealFieldElement<T>> void doTestIncreasingTolerance(final Field<T> field,
+                                                                             double factor,
+                                                                             double epsilon) {
+
+        int previousCalls = Integer.MAX_VALUE;
+        for (int i = -12; i < -2; ++i) {
+            TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+            double minStep = 0;
+            double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+            double scalAbsoluteTolerance = FastMath.pow(10.0, i);
+            double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+            FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                                  scalAbsoluteTolerance, scalRelativeTolerance);
+            TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+            integ.addStepHandler(handler);
+            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+            Assert.assertTrue(handler.getMaximalValueError().getReal() < (factor * scalAbsoluteTolerance));
+            Assert.assertEquals(0, handler.getMaximalTimeError().getReal(), epsilon);
+
+            int calls = pb.getCalls();
+            Assert.assertEquals(integ.getEvaluations(), calls);
+            Assert.assertTrue(calls <= previousCalls);
+            previousCalls = calls;
+
+        }
+
+    }
+
+    @Test
+    public abstract void testEvents();
+
+    protected <T extends RealFieldElement<T>> void doTestEvents(final Field<T> field,
+                                                                final double epsilonMaxValue,
+                                                                final String name) {
+
+      TestFieldProblem4<T> pb = new TestFieldProblem4<T>(field);
+      double minStep = 0;
+      double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+      double scalAbsoluteTolerance = 1.0e-8;
+      double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+      FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                            scalAbsoluteTolerance, scalRelativeTolerance);
+      TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+      integ.addStepHandler(handler);
+      FieldEventHandler<T>[] functions = pb.getEventsHandlers();
+      double convergence = 1.0e-8 * maxStep;
+      for (int l = 0; l < functions.length; ++l) {
+          integ.addEventHandler(functions[l], Double.POSITIVE_INFINITY, convergence, 1000);
+      }
+      Assert.assertEquals(functions.length, integ.getEventHandlers().size());
+      integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+      Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
+      Assert.assertEquals(0, handler.getMaximalTimeError().getReal(), convergence);
+      Assert.assertEquals(12.0, handler.getLastTime().getReal(), convergence);
+      Assert.assertEquals(name, integ.getName());
+      integ.clearEventHandlers();
+      Assert.assertEquals(0, integ.getEventHandlers().size());
+
+    }
+
+    @Test(expected=LocalException.class)
+    public abstract void testEventsErrors();
+
+    protected <T extends RealFieldElement<T>> void doTestEventsErrors(final Field<T> field)
+        throws LocalException {
+        final TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double scalAbsoluteTolerance = 1.0e-8;
+        double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                              scalAbsoluteTolerance, scalRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+
+        integ.addEventHandler(new FieldEventHandler<T>() {
+          public void init(FieldODEStateAndDerivative<T> state0, T t) {
+          }
+          public Action eventOccurred(FieldODEStateAndDerivative<T> state, boolean increasing) {
+            return Action.CONTINUE;
+          }
+          public T g(FieldODEStateAndDerivative<T> state) {
+            T middle = pb.getInitialState().getTime().add(pb.getFinalTime()).multiply(0.5);
+            T offset = state.getTime().subtract(middle);
+            if (offset.getReal() > 0) {
+              throw new LocalException();
+            }
+            return offset;
+          }
+          public FieldODEState<T> resetState(FieldODEStateAndDerivative<T> state) {
+              return state;
+          }
+        }, Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 1000);
+
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+    }
+
+    @Test
+    public abstract void testEventsNoConvergence();
+
+    protected <T extends RealFieldElement<T>> void doTestEventsNoConvergence(final Field<T> field){
+
+        final TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double scalAbsoluteTolerance = 1.0e-8;
+        double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                              scalAbsoluteTolerance, scalRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+
+        integ.addEventHandler(new FieldEventHandler<T>() {
+            public void init(FieldODEStateAndDerivative<T> state0, T t) {
+            }
+            public Action eventOccurred(FieldODEStateAndDerivative<T> state, boolean increasing) {
+                return Action.CONTINUE;
+            }
+            public T g(FieldODEStateAndDerivative<T> state) {
+                T middle = pb.getInitialState().getTime().add(pb.getFinalTime()).multiply(0.5);
+                T offset = state.getTime().subtract(middle);
+                return (offset.getReal() > 0) ? offset.add(0.5) : offset.subtract(0.5);
+            }
+            public FieldODEState<T> resetState(FieldODEStateAndDerivative<T> state) {
+                return state;
+            }
+        }, Double.POSITIVE_INFINITY, 1.0e-8 * maxStep, 3);
+
+        try {
+            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+            Assert.fail("an exception should have been thrown");
+        } catch (MaxCountExceededException mcee) {
+            // Expected.
+        }
+
+    }
+
+    @Test
+    public abstract void testSanityChecks();
+
+    protected <T extends RealFieldElement<T>> void doTestSanityChecks(Field<T> field) {
+        TestFieldProblem3<T> pb = new TestFieldProblem3<T>(field);
+        try  {
+            EmbeddedRungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, 0,
+                                                                               pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
+                                                                               new double[4], new double[4]);
+            integrator.integrate(new FieldExpandableODE<T>(pb),
+                                 new FieldODEState<T>(pb.getInitialState().getTime(),
+                                                      MathArrays.buildArray(field, 6)),
+                                 pb.getFinalTime());
+            Assert.fail("an exception should have been thrown");
+        } catch(DimensionMismatchException ie) {
+        }
+        try  {
+            EmbeddedRungeKuttaFieldIntegrator<T> integrator =
+                            createIntegrator(field, 0,
+                                             pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
+                                             new double[2], new double[4]);
+            integrator.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+            Assert.fail("an exception should have been thrown");
+        } catch(DimensionMismatchException ie) {
+        }
+        try  {
+            EmbeddedRungeKuttaFieldIntegrator<T> integrator =
+                            createIntegrator(field, 0,
+                                             pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
+                                             new double[4], new double[4]);
+            integrator.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getInitialState().getTime());
+            Assert.fail("an exception should have been thrown");
+        } catch(NumberIsTooSmallException ie) {
+        }
+    }
+
+    @Test
+    public abstract void testBackward();
+
+    protected <T extends RealFieldElement<T>> void doTestBackward(Field<T> field,
+                                                                  final double epsilonLast,
+                                                                  final double epsilonMaxValue,
+                                                                  final double epsilonMaxTime,
+                                                                  final String name)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+
+        TestFieldProblem5<T> pb = new TestFieldProblem5<T>(field);
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).abs().getReal();
+        double scalAbsoluteTolerance = 1.0e-8;
+        double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+        EmbeddedRungeKuttaFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                                      scalAbsoluteTolerance,
+                                                                      scalRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+        Assert.assertEquals(0, handler.getLastError().getReal(),         epsilonLast);
+        Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
+        Assert.assertEquals(0, handler.getMaximalTimeError().getReal(),  epsilonMaxTime);
+        Assert.assertEquals(name, integ.getName());
+
+    }
+
+    @Test
+    public abstract void testKepler();
+
+    protected <T extends RealFieldElement<T>> void doTestKepler(Field<T> field, double epsilon) {
+
+        final TestFieldProblem3<T> pb  = new TestFieldProblem3<T>(field, field.getZero().add(0.9));
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double[] vecAbsoluteTolerance = { 1.0e-8, 1.0e-8, 1.0e-10, 1.0e-10 };
+        double[] vecRelativeTolerance = { 1.0e-10, 1.0e-10, 1.0e-8, 1.0e-8 };
+
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
+                                                              vecAbsoluteTolerance, vecRelativeTolerance);
+        integ.addStepHandler(new KeplerHandler<T>(pb, epsilon));
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+    }
+
+    private static class KeplerHandler<T extends RealFieldElement<T>> implements FieldStepHandler<T> {
+        private T maxError;
+        private final TestFieldProblem3<T> pb;
+        private final double epsilon;
+        public KeplerHandler(TestFieldProblem3<T> pb, double epsilon) {
+            this.pb      = pb;
+            this.epsilon = epsilon;
+            maxError = pb.getField().getZero();
+        }
+        public void init(FieldODEStateAndDerivative<T> state0, T t) {
+            maxError = pb.getField().getZero();
+        }
+        public void handleStep(FieldStepInterpolator<T> interpolator, boolean isLast)
+                        throws MaxCountExceededException {
+
+            FieldODEStateAndDerivative<T> current = interpolator.getCurrentState();
+            T[] theoreticalY  = pb.computeTheoreticalState(current.getTime());
+            T dx = current.getState()[0].subtract(theoreticalY[0]);
+            T dy = current.getState()[1].subtract(theoreticalY[1]);
+            T error = dx.multiply(dx).add(dy.multiply(dy));
+            if (error.subtract(maxError).getReal() > 0) {
+                maxError = error;
+            }
+            if (isLast) {
+                Assert.assertEquals(0.0, maxError.getReal(), epsilon);
+            }
+        }
+    }
+
+    @Test
+    public abstract void testPartialDerivatives();
+
+    protected 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 FirstOrderFieldDifferentialEquations<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 }
+            };
+
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
index 1a44551..9a48986 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class EulerFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
+public class EulerFieldIntegratorTest extends RungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, T step) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
index 0458f5c..c5d1c3b 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class EulerFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class EulerFieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
index a04c6eb..877321b 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class GillFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
+public class GillFieldIntegratorTest extends RungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, T step) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
index 54f0098..87a9b10 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class GillFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class GillFieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,


[28/50] [abbrv] [math] Removed unneeded field.

Posted by lu...@apache.org.
Removed unneeded field.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/11df45b7
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/11df45b7
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/11df45b7

Branch: refs/heads/master
Commit: 11df45b7bdf0e836df475cd480f5287f4256f493
Parents: 2773215
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:41 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:41 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/math4/ode/AbstractFieldIntegrator.java    | 4 ----
 1 file changed, 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/11df45b7/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
index 878f435..07fa9a0 100644
--- a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
@@ -67,9 +67,6 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
     /** Indicator for last step. */
     protected boolean isLastStep;
 
-    /** Indicator that a state or derivative reset was triggered by some event. */
-    protected boolean resetOccurred;
-
     /** Field to which the time and state vector elements belong. */
     private final Field<T> field;
 
@@ -348,7 +345,6 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
                         // invalidate the derivatives, we need to recompute them
                         final T[] y    = equations.getMapper().mapState(newState);
                         final T[] yDot = computeDerivatives(newState.getTime(), y);
-                        resetOccurred = true;
                         return equations.getMapper().mapStateAndDerivative(newState.getTime(), y, yDot);
                     }
                 }


[10/50] [abbrv] [math] Added test for classical midpoint step interpolator.

Posted by lu...@apache.org.
Added test for classical midpoint step interpolator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/2f8b15ad
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/2f8b15ad
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/2f8b15ad

Branch: refs/heads/master
Commit: 2f8b15ad07b438413f9b8513ed50fd5cf14ceadb
Parents: ba6f4a4
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:18 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:18 2016 +0100

----------------------------------------------------------------------
 .../MidpointFieldStepInterpolatorTest.java      | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/2f8b15ad/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
new file mode 100644
index 0000000..bb2a335
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class MidpointFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
+        return new MidpointFieldStepInterpolator<T>(field, forward, mapper);
+    }
+
+    @Test
+    public void interpolationAtBounds() {
+        doInterpolationAtBounds(Decimal64Field.getInstance(), 1.0e-15);
+    }
+
+    @Test
+    public void interpolationInside() {
+        doInterpolationInside(Decimal64Field.getInstance(), 3.3e-4, 1.1e-5);
+    }
+
+}


[31/50] [abbrv] [math] Use immutable step interpolators.

Posted by lu...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
index 3a5f9aa..d052f4b 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
@@ -99,10 +99,15 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
 
     /** Create an interpolator.
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
      * @param mapper equations mapper for the all equations
      * @return external weights for the high order method from Butcher array
      */
-    protected abstract RungeKuttaFieldStepInterpolator<T> createInterpolator(boolean forward,
+    protected abstract RungeKuttaFieldStepInterpolator<T> createInterpolator(boolean forward, T[][] yDotK,
+                                                                             final FieldODEStateAndDerivative<T> globalPreviousState,
+                                                                             final FieldODEStateAndDerivative<T> globalCurrentState,
                                                                              FieldEquationsMapper<T> mapper);
 
     /** {@inheritDoc} */
@@ -124,11 +129,6 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
         final T[][] yDotK  = MathArrays.buildArray(getField(), stages, -1);
         final T[]   yTmp   = MathArrays.buildArray(getField(), y0.length);
 
-        // set up an interpolator sharing the integrator arrays
-        final RungeKuttaFieldStepInterpolator<T> interpolator =
-                        createInterpolator(forward, equations.getMapper());
-        interpolator.storeState(stepStart);
-
         // set up integration control objects
         if (forward) {
             if (stepStart.getTime().add(step).subtract(finalTime).getReal() >= 0) {
@@ -148,8 +148,6 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
         isLastStep = false;
         do {
 
-            interpolator.shift();
-
             // first stage
             y        = equations.getMapper().mapState(stepStart);
             yDotK[0] = equations.getMapper().mapDerivative(stepStart);
@@ -182,16 +180,12 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
             final FieldODEStateAndDerivative<T> stateTmp = new FieldODEStateAndDerivative<T>(stepEnd, yTmp, yDotTmp);
 
             // discrete events handling
-            interpolator.setSlopes(yDotK);
-            interpolator.storeState(stateTmp);
             System.arraycopy(yTmp, 0, y, 0, y0.length);
-            stepStart = acceptStep(interpolator, finalTime);
+            stepStart = acceptStep(createInterpolator(forward, yDotK, stepStart, stateTmp, equations.getMapper()),
+                                   finalTime);
 
             if (!isLastStep) {
 
-                // prepare next step
-                interpolator.storeState(stepStart);
-
                 // stepsize control for next step
                 final T  nextT      = stepStart.getTime().add(stepSize);
                 final boolean nextIsLast = forward ?

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java
index 26d8fb9..9595ee2 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.ode.sampling.AbstractFieldStepInterpolator;
 import org.apache.commons.math4.util.MathArrays;
 
@@ -40,57 +41,63 @@ abstract class RungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
     private final Field<T> field;
 
     /** Slopes at the intermediate points. */
-    private T[][] yDotK;
+    private final T[][] yDotK;
 
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
     protected RungeKuttaFieldStepInterpolator(final Field<T> field, final boolean forward,
+                                              final T[][] yDotK,
+                                              final FieldODEStateAndDerivative<T> globalPreviousState,
+                                              final FieldODEStateAndDerivative<T> globalCurrentState,
+                                              final FieldODEStateAndDerivative<T> softPreviousState,
+                                              final FieldODEStateAndDerivative<T> softCurrentState,
                                               final FieldEquationsMapper<T> mapper) {
-        super(forward, mapper);
+        super(forward, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
         this.field = field;
-        this.yDotK = null;
-    }
-
-    /** Copy constructor.
-     * <p>The copy is a deep copy: its arrays are separated from the
-     * original arrays of the instance.</p>
-
-     * @param interpolator interpolator to copy from.
-
-     */
-    RungeKuttaFieldStepInterpolator(final RungeKuttaFieldStepInterpolator<T> interpolator) {
-
-        super(interpolator);
-        field = interpolator.field;
-
-        if (yDotK != null) {
-            yDotK = MathArrays.buildArray(field, interpolator.yDotK.length, -1);
-            for (int k = 0; k < yDotK.length; ++k) {
-                yDotK[k] = interpolator.yDotK[k].clone();
-            }
-
-        } else {
-            yDotK = null;
+        this.yDotK = MathArrays.buildArray(field, yDotK.length, -1);
+        for (int i = 0; i < yDotK.length; ++i) {
+            this.yDotK[i] = yDotK[i].clone();
         }
-
     }
 
-    /** Get the field to which the time and state vector elements belong.
-     * @return to which the time and state vector elements belong
-     */
-    protected Field<T> getField() {
-        return field;
+    /** {@inheritDoc} */
+    protected RungeKuttaFieldStepInterpolator<T> create(boolean newForward,
+                                                        FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                        FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                        FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                        FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                        FieldEquationsMapper<T> newMapper) {
+        return create(field, newForward, yDotK,
+                      newGlobalPreviousState, newGlobalCurrentState,
+                      newSoftPreviousState, newSoftCurrentState,
+                      newMapper);
     }
 
-    /** Store the slopes at the intermediate points.
-     * @param slopes slopes at the intermediate points
+    /** Create a new instance.
+     * @param newField field to which the time and state vector elements belong
+     * @param newForward integration direction indicator
+     * @param newYDotK slopes at the intermediate points
+     * @param newGlobalPreviousState start of the global step
+     * @param newGlobalCurrentState end of the global step
+     * @param newSoftPreviousState start of the restricted step
+     * @param newSoftCurrentState end of the restricted step
+     * @param newMapper equations mapper for the all equations
+     * @return a new instance
      */
-    void setSlopes(final T[][] slopes) {
-        this.yDotK = slopes.clone();
-    }
+    protected abstract RungeKuttaFieldStepInterpolator<T> create(Field<T> newField, boolean newForward, T[][] newYDotK,
+                                                                 FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                                 FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                                 FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                                 FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                                 FieldEquationsMapper<T> newMapper);
 
     /** Compute a state by linear combination added to previous state.
      * @param coefficients coefficients to apply to the method staged derivatives

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
index b826290..255b2da 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
@@ -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.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.MathArrays;
 
 /**
@@ -99,8 +100,14 @@ public class ThreeEighthesFieldIntegrator<T extends RealFieldElement<T>>
     /** {@inheritDoc} */
     @Override
     protected ThreeEighthesFieldStepInterpolator<T>
-        createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
-        return new ThreeEighthesFieldStepInterpolator<T>(getField(), forward, mapper);
+        createInterpolator(final boolean forward, T[][] yDotK,
+                           final FieldODEStateAndDerivative<T> globalPreviousState,
+                           final FieldODEStateAndDerivative<T> globalCurrentState,
+                           final FieldEquationsMapper<T> mapper) {
+        return new ThreeEighthesFieldStepInterpolator<T>(getField(), forward, yDotK,
+                                                         globalPreviousState, globalCurrentState,
+                                                         globalPreviousState, globalCurrentState,
+                                                         mapper);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java
index bf0ad46..6faffd1 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolator.java
@@ -64,35 +64,44 @@ class ThreeEighthesFieldStepInterpolator<T extends RealFieldElement<T>>
     /** Simple constructor.
      * @param field field to which the time and state vector elements belong
      * @param forward integration direction indicator
+     * @param yDotK slopes at the intermediate points
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param mapper equations mapper for the all equations
      */
     ThreeEighthesFieldStepInterpolator(final Field<T> field, final boolean forward,
+                                       final T[][] yDotK,
+                                       final FieldODEStateAndDerivative<T> globalPreviousState,
+                                       final FieldODEStateAndDerivative<T> globalCurrentState,
+                                       final FieldODEStateAndDerivative<T> softPreviousState,
+                                       final FieldODEStateAndDerivative<T> softCurrentState,
                                        final FieldEquationsMapper<T> mapper) {
-        super(field, forward, mapper);
-    }
-
-    /** Copy constructor.
-     * @param interpolator interpolator to copy from. The copy is a deep
-     * copy: its arrays are separated from the original arrays of the
-     * instance
-     */
-    ThreeEighthesFieldStepInterpolator(final ThreeEighthesFieldStepInterpolator<T> interpolator) {
-        super(interpolator);
+        super(field, forward, yDotK,
+              globalPreviousState, globalCurrentState, softPreviousState, softCurrentState,
+              mapper);
     }
 
     /** {@inheritDoc} */
-    @Override
-    protected ThreeEighthesFieldStepInterpolator<T> doCopy() {
-        return new ThreeEighthesFieldStepInterpolator<T>(this);
+    protected ThreeEighthesFieldStepInterpolator<T> create(final Field<T> newField, final boolean newForward, final T[][] newYDotK,
+                                                           final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                           final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                           final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                           final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                           final FieldEquationsMapper<T> newMapper) {
+        return new ThreeEighthesFieldStepInterpolator<T>(newField, newForward, newYDotK,
+                                                         newGlobalPreviousState, newGlobalCurrentState,
+                                                         newSoftPreviousState, newSoftCurrentState,
+                                                         newMapper);
     }
 
-
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> mapper,
                                                                                    final T time, final T theta,
-                                                                                   final T oneMinusThetaH) {
+                                                                                   final T thetaH, final T oneMinusThetaH) {
 
         final T coeffDot3  = theta.multiply(0.75);
         final T coeffDot1  = coeffDot3.multiply(theta.multiply(4).subtract(5)).add(1);
@@ -102,7 +111,7 @@ class ThreeEighthesFieldStepInterpolator<T extends RealFieldElement<T>>
         final T[] interpolatedDerivatives;
 
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
-            final T s          = theta.multiply(h).divide(8);
+            final T s          = thetaH.divide(8);
             final T fourTheta2 = theta.multiply(theta).multiply(4);
             final T coeff1     = s.multiply(fourTheta2.multiply(2).subtract(theta.multiply(15)).add(8));
             final T coeff2     = s.multiply(theta.multiply(5).subtract(fourTheta2)).multiply(3);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
index 00740f4..0486cef 100644
--- a/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/sampling/AbstractFieldStepInterpolator.java
@@ -40,118 +40,76 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T>>
     implements FieldStepInterpolator<T> {
 
-    /** Current time step. */
-    protected T h;
-
     /** Global previous state. */
-    private FieldODEStateAndDerivative<T> globalPreviousState;
+    private final FieldODEStateAndDerivative<T> globalPreviousState;
 
     /** Global current state. */
-    private FieldODEStateAndDerivative<T> globalCurrentState;
+    private final FieldODEStateAndDerivative<T> globalCurrentState;
 
     /** Soft previous state. */
-    private FieldODEStateAndDerivative<T> softPreviousState;
+    private final FieldODEStateAndDerivative<T> softPreviousState;
 
     /** Soft current state. */
-    private FieldODEStateAndDerivative<T> softCurrentState;
+    private final FieldODEStateAndDerivative<T> softCurrentState;
 
     /** integration direction. */
-    private boolean forward;
+    private final boolean forward;
 
     /** Mapper for ODE equations primary and secondary components. */
     private FieldEquationsMapper<T> mapper;
 
     /** Simple constructor.
      * @param isForward integration direction indicator
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
      * @param equationsMapper mapper for ODE equations primary and secondary components
      */
     protected AbstractFieldStepInterpolator(final boolean isForward,
+                                            final FieldODEStateAndDerivative<T> globalPreviousState,
+                                            final FieldODEStateAndDerivative<T> globalCurrentState,
+                                            final FieldODEStateAndDerivative<T> softPreviousState,
+                                            final FieldODEStateAndDerivative<T> softCurrentState,
                                             final FieldEquationsMapper<T> equationsMapper) {
-        globalPreviousState = null;
-        globalCurrentState  = null;
-        softPreviousState   = null;
-        softCurrentState    = null;
-        h                   = null;
-        this.forward        = isForward;
-        this.mapper         = equationsMapper;
-    }
-
-    /** Copy constructor.
-     * <p>The copy is a deep copy: its arrays are separated from the
-     * original arrays of the instance.</p>
-     * @param interpolator interpolator to copy from.
-     */
-    protected AbstractFieldStepInterpolator(final AbstractFieldStepInterpolator<T> interpolator) {
-
-        globalPreviousState = interpolator.globalPreviousState;
-        globalCurrentState  = interpolator.globalCurrentState;
-        softPreviousState   = interpolator.softPreviousState;
-        softCurrentState    = interpolator.softCurrentState;
-        h                   = interpolator.h;
-        forward             = interpolator.forward;
-        mapper              = interpolator.mapper;
-
-    }
-
-    /** {@inheritDoc} */
-    public FieldStepInterpolator<T> copy() throws MaxCountExceededException {
-
-        // create the new independent instance
-        return doCopy();
-
-    }
-
-    /** Really copy the instance.
-     * @return a copy of the instance
-     */
-    protected abstract FieldStepInterpolator<T> doCopy();
-
-    /** Shift one step forward.
-     * Copy the current time into the previous time, hence preparing the
-     * interpolator for future calls to {@link #storeTime storeTime}
-     */
-    public void shift() {
-        globalPreviousState = globalCurrentState;
-        softPreviousState   = globalPreviousState;
-        softCurrentState    = globalCurrentState;
-    }
-
-    /** Store the current step state.
-     * @param state current state
-     */
-    public void storeState(final FieldODEStateAndDerivative<T> state) {
-        globalCurrentState = state;
-        softCurrentState   = globalCurrentState;
-        if (globalPreviousState != null) {
-            h = globalCurrentState.getTime().subtract(globalPreviousState.getTime());
-        }
+        this.forward             = isForward;
+        this.globalPreviousState = globalPreviousState;
+        this.globalCurrentState  = globalCurrentState;
+        this.softPreviousState   = softPreviousState;
+        this.softCurrentState    = softCurrentState;
+        this.mapper              = equationsMapper;
     }
 
-    /** Restrict step range to a limited part of the global step.
+    /** Create a new restricted version of the instance.
      * <p>
-     * This method can be used to restrict a step and make it appear
-     * as if the original step was smaller. Calling this method
-     * <em>only</em> changes the value returned by {@link #getPreviousState()},
-     * it does not change any other property
+     * The instance is not changed at all.
      * </p>
-     * @param softPreviousState start of the restricted step
+     * @param previousState start of the restricted step
+     * @param currentState end of the restricted step
+     * @return restricted version of the instance
+     * @see #getPreviousState()
+     * @see #getCurrentState()
      */
-    public void setSoftPreviousState(final FieldODEStateAndDerivative<T> softPreviousState) {
-        this.softPreviousState = softPreviousState;
+    public AbstractFieldStepInterpolator<T> restrictStep(final FieldODEStateAndDerivative<T> previousState,
+                                                         final FieldODEStateAndDerivative<T> currentState) {
+        return create(forward, globalPreviousState, globalCurrentState, previousState, currentState, mapper);
     }
 
-    /** Restrict step range to a limited part of the global step.
-     * <p>
-     * This method can be used to restrict a step and make it appear
-     * as if the original step was smaller. Calling this method
-     * <em>only</em> changes the value returned by {@link #getCurrentState()},
-     * it does not change any other property
-     * </p>
-     * @param softCurrentState end of the restricted step
+    /** Create a new instance.
+     * @param newForward integration direction indicator
+     * @param newGlobalPreviousState start of the global step
+     * @param newGlobalCurrentState end of the global step
+     * @param newSoftPreviousState start of the restricted step
+     * @param newSoftCurrentState end of the restricted step
+     * @param newMapper equations mapper for the all equations
+     * @return a new instance
      */
-    public void setSoftCurrentState(final FieldODEStateAndDerivative<T> softCurrentState) {
-        this.softCurrentState  = softCurrentState;
-    }
+    protected abstract AbstractFieldStepInterpolator<T> create(boolean newForward,
+                                                               FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                               FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                               FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                               FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                               FieldEquationsMapper<T> newMapper);
 
     /**
      * Get the previous global grid point state.
@@ -169,25 +127,22 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
         return globalCurrentState;
     }
 
-    /** {@inheritDoc}
-     * @see #setSoftPreviousState(FieldODEStateAndDerivative)
-     */
+    /** {@inheritDoc} */
     public FieldODEStateAndDerivative<T> getPreviousState() {
         return softPreviousState;
     }
 
-    /** {@inheritDoc}
-     * @see #setSoftCurrentState(FieldODEStateAndDerivative)
-     */
+    /** {@inheritDoc} */
     public FieldODEStateAndDerivative<T> getCurrentState() {
         return softCurrentState;
     }
 
     /** {@inheritDoc} */
     public FieldODEStateAndDerivative<T> getInterpolatedState(final T time) {
+        final T thetaH         = time.subtract(globalPreviousState.getTime());
         final T oneMinusThetaH = globalCurrentState.getTime().subtract(time);
-        final T theta = (h.getReal() == 0) ? h.getField().getZero() : h.subtract(oneMinusThetaH).divide(h);
-        return computeInterpolatedStateAndDerivatives(mapper, time, theta, oneMinusThetaH);
+        final T theta          = thetaH.divide(globalCurrentState.getTime().subtract(globalPreviousState.getTime()));
+        return computeInterpolatedStateAndDerivatives(mapper, time, theta, thetaH, oneMinusThetaH);
     }
 
     /** {@inheritDoc} */
@@ -202,13 +157,15 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
      * @param time interpolation time
      * @param theta normalized interpolation abscissa within the step
      * (theta is zero at the previous time step and one at the current time step)
+     * @param thetaH time gap between the previous time and the interpolated time
      * @param oneMinusThetaH time gap between the interpolated time and
      * the current time
      * @return interpolated state and derivatives
      * @exception MaxCountExceededException if the number of functions evaluations is exceeded
      */
     protected abstract FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(FieldEquationsMapper<T> equationsMapper,
-                                                                                            T time, T theta, T oneMinusThetaH)
+                                                                                            T time, T theta,
+                                                                                            T thetaH, T oneMinusThetaH)
         throws MaxCountExceededException;
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java
index b1e08e3..a68d098 100644
--- a/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/sampling/FieldStepInterpolator.java
@@ -18,7 +18,6 @@
 package org.apache.commons.math4.ode.sampling;
 
 import org.apache.commons.math4.RealFieldElement;
-import org.apache.commons.math4.exception.MaxCountExceededException;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 
 /** This interface represents an interpolator over the last step
@@ -74,14 +73,4 @@ public interface FieldStepInterpolator<T extends RealFieldElement<T>> {
    */
   boolean isForward();
 
-  /** Copy the instance.
-   * <p>The copied instance is guaranteed to be independent from the
-   * original one. Both can be used with different settings for
-   * interpolated time without any side effect.</p>
-   * @return a deep copy of the instance, which can be used independently.
-   * @exception MaxCountExceededException if the number of functions evaluations is exceeded
-   * during step finalization
-   */
-   FieldStepInterpolator<T> copy() throws MaxCountExceededException;
-
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java b/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
new file mode 100644
index 0000000..f7bbe5c
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/ContinuousOutputFieldModelTest.java
@@ -0,0 +1,219 @@
+/*
+ * 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.apache.commons.math4.ode;
+
+import java.util.Random;
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.nonstiff.DormandPrince54FieldIntegrator;
+import org.apache.commons.math4.ode.nonstiff.DormandPrince853FieldIntegrator;
+import org.apache.commons.math4.ode.sampling.DummyFieldStepInterpolator;
+import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
+import org.apache.commons.math4.util.MathUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ContinuousOutputFieldModelTest {
+
+    @Test
+    public void testBoundaries() {
+        doTestBoundaries(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestBoundaries(final Field<T> field) {
+        TestFieldProblem3<T> pb = new TestFieldProblem3<T>(field, field.getZero().add(0.9));
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        FieldFirstOrderIntegrator<T> integ = new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, 1.0e-8, 1.0e-8);
+        integ.addStepHandler(new ContinuousOutputFieldModel<T>());
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+        ContinuousOutputFieldModel<T> cm = (ContinuousOutputFieldModel<T>) integ.getStepHandlers().iterator().next();
+        cm.getInterpolatedState(pb.getInitialState().getTime().multiply(2).subtract(pb.getFinalTime()));
+        cm.getInterpolatedState(pb.getFinalTime().multiply(2).subtract(pb.getInitialState().getTime()));
+        cm.getInterpolatedState(pb.getInitialState().getTime().add(pb.getFinalTime()).multiply(0.5));
+    }
+
+    @Test
+    public void testRandomAccess() {
+        doTestRandomAccess(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestRandomAccess(final Field<T> field)  {
+
+        TestFieldProblem3<T> pb = new TestFieldProblem3<T>(field, field.getZero().add(0.9));
+        double minStep = 0;
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        FieldFirstOrderIntegrator<T> integ = new DormandPrince54FieldIntegrator<T>(field, minStep, maxStep, 1.0e-8, 1.0e-8);
+        ContinuousOutputFieldModel<T> cm = new ContinuousOutputFieldModel<T>();
+        integ.addStepHandler(cm);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+        Random random = new Random(347588535632l);
+        T maxError    = field.getZero();
+        T maxErrorDot = field.getZero();
+        for (int i = 0; i < 1000; ++i) {
+            double r = random.nextDouble();
+            T time = pb.getInitialState().getTime().multiply(r).add(pb.getFinalTime().multiply(1.0 - r));
+            FieldODEStateAndDerivative<T> interpolated = cm.getInterpolatedState(time);
+            T[] theoreticalY = pb.computeTheoreticalState(time);
+            T[] theoreticalYDot  = pb.doComputeDerivatives(time, theoreticalY);
+            T dx = interpolated.getState()[0].subtract(theoreticalY[0]);
+            T dy = interpolated.getState()[1].subtract(theoreticalY[1]);
+            T error = dx.multiply(dx).add(dy.multiply(dy));
+            maxError = MathUtils.max(maxError, error);
+            T dxDot = interpolated.getDerivative()[0].subtract(theoreticalYDot[0]);
+            T dyDot = interpolated.getDerivative()[1].subtract(theoreticalYDot[1]);
+            T errorDot = dxDot.multiply(dxDot).add(dyDot.multiply(dyDot));
+            maxErrorDot = MathUtils.max(maxErrorDot, errorDot);
+        }
+
+        Assert.assertEquals(0.0, maxError.getReal(),    1.0e-9);
+        Assert.assertEquals(0.0, maxErrorDot.getReal(), 4.0e-7);
+
+    }
+
+    @Test
+    public void testModelsMerging() {
+        doTestModelsMerging(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestModelsMerging(final Field<T> field) {
+
+        // theoretical solution: y[0] = cos(t), y[1] = sin(t)
+        FieldFirstOrderDifferentialEquations<T> problem =
+                        new FieldFirstOrderDifferentialEquations<T>() {
+            public T[] computeDerivatives(T t, T[] y) {
+                T[] yDot = MathArrays.buildArray(field, 2);
+                yDot[0] = y[1].negate();
+                yDot[1] = y[0];
+                return yDot;
+            }
+            public int getDimension() {
+                return 2;
+            }
+            public void init(T t0, T[] y0, T finalTime) {
+            }
+        };
+
+        // integrate backward from &pi; to 0;
+        ContinuousOutputFieldModel<T> cm1 = new ContinuousOutputFieldModel<T>();
+        FieldFirstOrderIntegrator<T> integ1 =
+                        new DormandPrince853FieldIntegrator<T>(field, 0, 1.0, 1.0e-8, 1.0e-8);
+        integ1.addStepHandler(cm1);
+        T t0 = field.getZero().add(FastMath.PI);
+        T[] y0 = MathArrays.buildArray(field, 2);
+        y0[0] = field.getOne().negate();
+        y0[1] = field.getZero();
+        integ1.integrate(new FieldExpandableODE<T>(problem),
+                         new FieldODEState<T>(t0, y0),
+                         field.getZero());
+
+        // integrate backward from 2&pi; to &pi;
+        ContinuousOutputFieldModel<T> cm2 = new ContinuousOutputFieldModel<T>();
+        FieldFirstOrderIntegrator<T> integ2 =
+                        new DormandPrince853FieldIntegrator<T>(field, 0, 0.1, 1.0e-12, 1.0e-12);
+        integ2.addStepHandler(cm2);
+        t0 = field.getZero().add(2.0 * FastMath.PI);
+        y0[0] = field.getOne();
+        y0[1] = field.getZero();
+        integ2.integrate(new FieldExpandableODE<T>(problem),
+                         new FieldODEState<T>(t0, y0),
+                         field.getZero().add(FastMath.PI));
+
+        // merge the two half circles
+        ContinuousOutputFieldModel<T> cm = new ContinuousOutputFieldModel<T>();
+        cm.append(cm2);
+        cm.append(new ContinuousOutputFieldModel<T>());
+        cm.append(cm1);
+
+        // check circle
+        Assert.assertEquals(2.0 * FastMath.PI, cm.getInitialTime().getReal(), 1.0e-12);
+        Assert.assertEquals(0, cm.getFinalTime().getReal(), 1.0e-12);
+        for (double t = 0; t < 2.0 * FastMath.PI; t += 0.1) {
+            FieldODEStateAndDerivative<T> interpolated = cm.getInterpolatedState(field.getZero().add(t));
+            Assert.assertEquals(FastMath.cos(t), interpolated.getState()[0].getReal(), 1.0e-7);
+            Assert.assertEquals(FastMath.sin(t), interpolated.getState()[1].getReal(), 1.0e-7);
+        }
+
+    }
+
+    @Test
+    public void testErrorConditions() {
+        doTestErrorConditions(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestErrorConditions(final Field<T> field) {
+        ContinuousOutputFieldModel<T> cm = new ContinuousOutputFieldModel<T>();
+        cm.handleStep(buildInterpolator(field, 0, 1, new double[] { 0.0, 1.0, -2.0 }), true);
+
+        // dimension mismatch
+        Assert.assertTrue(checkAppendError(field, cm, 1.0, 2.0, new double[] { 0.0, 1.0 }));
+
+        // hole between time ranges
+        Assert.assertTrue(checkAppendError(field, cm, 10.0, 20.0, new double[] { 0.0, 1.0, -2.0 }));
+
+        // propagation direction mismatch
+        Assert.assertTrue(checkAppendError(field, cm, 1.0, 0.0, new double[] { 0.0, 1.0, -2.0 }));
+
+        // no errors
+        Assert.assertFalse(checkAppendError(field, cm, 1.0, 2.0, new double[] { 0.0, 1.0, -2.0 }));
+
+    }
+
+    private <T extends RealFieldElement<T>> boolean checkAppendError(Field<T> field, ContinuousOutputFieldModel<T> cm,
+                                                                     double t0, double t1, double[] y) {
+        try {
+            ContinuousOutputFieldModel<T> otherCm = new ContinuousOutputFieldModel<T>();
+            otherCm.handleStep(buildInterpolator(field, t0, t1, y), true);
+            cm.append(otherCm);
+        } catch(IllegalArgumentException iae) {
+            return true; // there was an allowable error
+        }
+        return false; // no allowable error
+    }
+
+    private <T extends RealFieldElement<T>> FieldStepInterpolator<T> buildInterpolator(Field<T> field,
+                                                                                       double t0, double t1, double[] y) {
+        T[] fieldY = MathArrays.buildArray(field, y.length);
+        for (int i = 0; i < y.length; ++i) {
+            fieldY[i] = field.getZero().add(y[i]);
+        }
+        final FieldODEStateAndDerivative<T> s0 = new FieldODEStateAndDerivative<T>(field.getZero().add(t0), fieldY, fieldY);
+        final FieldODEStateAndDerivative<T> s1 = new FieldODEStateAndDerivative<T>(field.getZero().add(t1), fieldY, fieldY);
+        final FieldEquationsMapper<T> mapper   = new FieldExpandableODE<T>(new FieldFirstOrderDifferentialEquations<T>() {
+            public int getDimension() {
+                return s0.getStateDimension();
+            }
+            public void init(T t0, T[] y0, T finalTime) {
+            }
+            public T[] computeDerivatives(T t, T[] y) {
+                return y;
+            }
+        }).getMapper();
+        return new DummyFieldStepInterpolator<T>(t1 >= t0, s0, s1, s0, s1, mapper);
+    }
+
+    public void checkValue(double value, double reference) {
+        Assert.assertTrue(FastMath.abs(value - reference) < 1.0e-10);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index 4716b81..b670cda 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -18,8 +18,6 @@
 package org.apache.commons.math4.ode.nonstiff;
 
 
-import java.lang.reflect.InvocationTargetException;
-
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.AbstractIntegrator;
@@ -38,7 +36,15 @@ import org.junit.Test;
 public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected abstract <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-        createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper);
+        createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                           FieldODEStateAndDerivative<T> globalPreviousState,
+                           FieldODEStateAndDerivative<T> globalCurrentState,
+                           FieldODEStateAndDerivative<T> softPreviousState,
+                           FieldODEStateAndDerivative<T> softCurrentState,
+                           FieldEquationsMapper<T> mapper);
+
+    protected abstract <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+        createButcherArrayProvider(final Field<T> field);
 
     @Test
     public abstract void interpolationAtBounds();
@@ -140,10 +146,8 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                                                          final double t0, final double[] y0,
                                                          final double t1) {
 
-        RungeKuttaFieldStepInterpolator<T> interpolator = createInterpolator(field, t1 > t0,
-                                                                             new FieldExpandableODE<T>(eqn).getMapper());
         // get the Butcher arrays from the field integrator
-        FieldButcherArrayProvider<T> provider = createButcherArrayProvider(field, interpolator);
+        FieldButcherArrayProvider<T> provider = createButcherArrayProvider(field);
         T[][] a = provider.getA();
         T[]   b = provider.getB();
         T[]   c = provider.getC();
@@ -156,8 +160,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
             fieldY[i] = field.getZero().add(y0[i]);
         }
         fieldYDotK[0] = eqn.computeDerivatives(t, fieldY);
-        interpolator.storeState(new FieldODEStateAndDerivative<T>(t, fieldY, fieldYDotK[0]));
-        interpolator.shift();
+        FieldODEStateAndDerivative<T> s0 = new FieldODEStateAndDerivative<T>(t, fieldY, fieldYDotK[0]);
 
         // perform one integration step, in order to get consistent derivatives
         T h = field.getZero().add(t1 - t0);
@@ -170,20 +173,20 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
             }
             fieldYDotK[k + 1] = eqn.computeDerivatives(h.multiply(c[k]).add(t0), fieldY);
         }
-        interpolator.setSlopes(fieldYDotK);
 
         // store state at step end
+        t = field.getZero().add(t1);
         for (int i = 0; i < y0.length; ++i) {
             fieldY[i] = field.getZero().add(y0[i]);
             for (int s = 0; s < b.length; ++s) {
                 fieldY[i] = fieldY[i].add(h.multiply(b[s].multiply(fieldYDotK[s][i])));
             }
         }
-        interpolator.storeState(new FieldODEStateAndDerivative<T>(field.getZero().add(t1),
-                                                                  fieldY,
-                                                                  eqn.computeDerivatives(field.getZero().add(t1), fieldY)));
+        FieldODEStateAndDerivative<T> s1 = new FieldODEStateAndDerivative<T>(t, fieldY,
+                                                                             eqn.computeDerivatives(t, fieldY));
 
-        return interpolator;
+        return createInterpolator(field, t1 > t0, fieldYDotK, s0, s1, s0, s1,
+                                  new FieldExpandableODE<T>(eqn).getMapper());
 
     }
 
@@ -236,10 +239,10 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                 }
                 @Override
                 public void computeDerivatives(final double t, final double[] y, final double[] yDot) {
-                    T fieldT = fieldInterpolator.getField().getZero().add(t);
-                    T[] fieldY = MathArrays.buildArray(fieldInterpolator.getField(), y.length);
+                    T fieldT = fieldInterpolator.getCurrentState().getTime().getField().getZero().add(t);
+                    T[] fieldY = MathArrays.buildArray(fieldInterpolator.getCurrentState().getTime().getField(), y.length);
                     for (int i = 0; i < y.length; ++i) {
-                        fieldY[i] = fieldInterpolator.getField().getZero().add(y[i]);
+                        fieldY[i] = fieldInterpolator.getCurrentState().getTime().getField().getZero().add(y[i]);
                     }
                     T[] fieldYDot = eqn.computeDerivatives(fieldT, fieldY);
                     for (int i = 0; i < yDot.length; ++i) {
@@ -281,42 +284,6 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     }
 
-    private <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
-    createButcherArrayProvider(final Field<T> field, final RungeKuttaFieldStepInterpolator<T> provider) {
-        FieldButcherArrayProvider<T> integrator = null;
-        try {
-        String interpolatorName = provider.getClass().getName();
-        String integratorName = interpolatorName.replaceAll("StepInterpolator", "Integrator");
-            @SuppressWarnings("unchecked")
-            Class<FieldButcherArrayProvider<T>> clz = (Class<FieldButcherArrayProvider<T>>) Class.forName(integratorName);
-            try {
-                integrator = clz.getConstructor(Field.class, RealFieldElement.class).
-                                                newInstance(field, field.getOne());
-            } catch (NoSuchMethodException nsme) {
-                try {
-                    integrator = clz.getConstructor(Field.class,
-                                                    Double.TYPE, Double.TYPE,
-                                                    Double.TYPE, Double.TYPE).
-                                 newInstance(field, 0.001, 1.0, 1.0, 1.0);
-                } catch (NoSuchMethodException e) {
-                    Assert.fail(e.getLocalizedMessage());
-                }
-            }
-
-        } catch (InvocationTargetException ite) {
-            Assert.fail(ite.getLocalizedMessage());
-        } catch (IllegalAccessException iae) {
-            Assert.fail(iae.getLocalizedMessage());
-        } catch (InstantiationException ie) {
-            Assert.fail(ie.getLocalizedMessage());
-        } catch (ClassNotFoundException cnfe) {
-            Assert.fail(cnfe.getLocalizedMessage());
-        }
-
-        return integrator;
-
-    }
-
     private static class SinCos<T extends RealFieldElement<T>> implements FieldFirstOrderDifferentialEquations<T> {
         private final Field<T> field;
         protected SinCos(final Field<T> field) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
index d559200..527fe25 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
@@ -21,14 +21,28 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class ClassicalRungKuttaFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new ClassicalRungeKuttaFieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState,
+                       FieldEquationsMapper<T> mapper) {
+        return new ClassicalRungeKuttaFieldStepInterpolator<T>(field, forward, yDotK,
+                                                               globalPreviousState, globalCurrentState,
+                                                               softPreviousState, softCurrentState,
+                                                               mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new ClassicalRungeKuttaFieldIntegrator<T>(field, field.getOne());
     }
 
     @Test
@@ -43,7 +57,7 @@ public class ClassicalRungKuttaFieldStepInterpolatorTest extends AbstractRungeKu
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 2.8e-17, 1.2e-16, 2.3e-16, 1.0e-50);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 2.8e-17, 1.2e-16, 3.4e-16, 2.1e-17);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
index 2aeac54..ee17388 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
@@ -21,14 +21,28 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class DormandPrince54FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new DormandPrince54FieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState,
+                       FieldEquationsMapper<T> mapper) {
+        return new DormandPrince54FieldStepInterpolator<T>(field, forward, yDotK,
+                                                           globalPreviousState, globalCurrentState,
+                                                           softPreviousState, softCurrentState,
+                                                           mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new DormandPrince54FieldIntegrator<T>(field, 0, 1, 1, 1);
     }
 
     @Test
@@ -43,7 +57,7 @@ public class DormandPrince54FieldStepInterpolatorTest extends AbstractRungeKutta
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 2.8e-17, 2.3e-16, 4.5e-16, 5.6e-17);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 2.8e-17, 2.3e-16, 5.6e-16, 5.6e-17);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
index bbef7b4..a104867 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldStepInterpolatorTest.java
@@ -21,14 +21,28 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class DormandPrince853FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new DormandPrince853FieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState,
+                       FieldEquationsMapper<T> mapper) {
+        return new DormandPrince853FieldStepInterpolator<T>(field, forward, yDotK,
+                                                            globalPreviousState, globalCurrentState,
+                                                            softPreviousState, softCurrentState,
+                                                            mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new DormandPrince853FieldIntegrator<T>(field, 0, 1, 1, 1);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
index b7fa85e..0458f5c 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
@@ -21,14 +21,27 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class EulerFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new EulerFieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState, FieldEquationsMapper<T> mapper) {
+        return new EulerFieldStepInterpolator<T>(field, forward, yDotK,
+                                                 globalPreviousState, globalCurrentState,
+                                                 softPreviousState, softCurrentState,
+                                                 mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new EulerFieldIntegrator<T>(field, field.getOne());
     }
 
     @Test
@@ -43,7 +56,7 @@ public class EulerFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepI
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.0e-50, 1.0e-50, 1.0e-50, 1.0e-50);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 7.0e-18, 1.0e-50, 1.0e-50, 1.0e-50);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
index 7dcc874..54f0098 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
@@ -21,14 +21,28 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class GillFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new GillFieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState,
+                       FieldEquationsMapper<T> mapper) {
+        return new GillFieldStepInterpolator<T>(field, forward, yDotK,
+                                                globalPreviousState, globalCurrentState,
+                                                softPreviousState, softCurrentState,
+                                                mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new GillFieldIntegrator<T>(field, field.getOne());
     }
 
     @Test
@@ -43,7 +57,7 @@ public class GillFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepIn
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.0e-50, 1.0e-50, 1.0e-50);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.0e-50, 3.4e-16, 2.1e-17);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
index 0d9180b..4bbe6f0 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
@@ -21,14 +21,28 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class HighamHall54FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new HighamHall54FieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState,
+                       FieldEquationsMapper<T> mapper) {
+        return new HighamHall54FieldStepInterpolator<T>(field, forward, yDotK,
+                                                        globalPreviousState, globalCurrentState,
+                                                        softPreviousState, softCurrentState,
+                                                        mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new HighamHall54FieldIntegrator<T>(field, 0, 1, 1, 1);
     }
 
     @Test
@@ -43,7 +57,7 @@ public class HighamHall54FieldStepInterpolatorTest extends AbstractRungeKuttaFie
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.0e-50, 1.0e-50, 1.0e-50);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.3e-16, 1.0e-50, 3.6e-15, 2.1e-16);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
index 4add8ca..39ebdb9 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
@@ -21,14 +21,28 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class LutherFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new LutherFieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState,
+                       FieldEquationsMapper<T> mapper) {
+        return new LutherFieldStepInterpolator<T>(field, forward, yDotK,
+                                                  globalPreviousState, globalCurrentState,
+                                                  softPreviousState, softCurrentState,
+                                                  mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new LutherFieldIntegrator<T>(field, field.getOne());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
index 20dee47..6779c4a 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
@@ -21,14 +21,28 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class MidpointFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new MidpointFieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState,
+                       FieldEquationsMapper<T> mapper) {
+        return new MidpointFieldStepInterpolator<T>(field, forward, yDotK,
+                                                    globalPreviousState, globalCurrentState,
+                                                    softPreviousState, softCurrentState,
+                                                    mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new MidpointFieldIntegrator<T>(field, field.getOne());
     }
 
     @Test
@@ -43,7 +57,7 @@ public class MidpointFieldStepInterpolatorTest extends AbstractRungeKuttaFieldSt
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.0e-50, 1.0e-50, 1.0e-50, 1.0e-50);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.0e-50, 1.0e-50, 7.0e-18);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
index 6b956fa..6891e02 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
@@ -21,14 +21,28 @@ package org.apache.commons.math4.ode.nonstiff;
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
 public class ThreeEighthesFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
-    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new ThreeEighthesFieldStepInterpolator<T>(field, forward, mapper);
+    createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                       FieldODEStateAndDerivative<T> globalPreviousState,
+                       FieldODEStateAndDerivative<T> globalCurrentState,
+                       FieldODEStateAndDerivative<T> softPreviousState,
+                       FieldODEStateAndDerivative<T> softCurrentState,
+                       FieldEquationsMapper<T> mapper) {
+        return new ThreeEighthesFieldStepInterpolator<T>(field, forward, yDotK,
+                                                         globalPreviousState, globalCurrentState,
+                                                         softPreviousState, softCurrentState,
+                                                         mapper);
+    }
+
+    protected <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+    createButcherArrayProvider(final Field<T> field) {
+        return new ThreeEighthesFieldIntegrator<T>(field, field.getOne());
     }
 
     @Test
@@ -43,7 +57,7 @@ public class ThreeEighthesFieldStepInterpolatorTest extends AbstractRungeKuttaFi
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.2e-16, 1.0e-50, 1.0e-50);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.2e-16, 3.4e-16, 1.4e-17);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/771eb6a6/src/test/java/org/apache/commons/math4/ode/sampling/DummyFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/sampling/DummyFieldStepInterpolator.java b/src/test/java/org/apache/commons/math4/ode/sampling/DummyFieldStepInterpolator.java
new file mode 100644
index 0000000..f546745
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/sampling/DummyFieldStepInterpolator.java
@@ -0,0 +1,55 @@
+/*
+ * 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.apache.commons.math4.ode.sampling;
+
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+
+public class DummyFieldStepInterpolator<T extends RealFieldElement<T>>
+    extends AbstractFieldStepInterpolator<T> {
+
+    public DummyFieldStepInterpolator(final boolean forward,
+                                      final FieldODEStateAndDerivative<T> globalPreviousState,
+                                      final FieldODEStateAndDerivative<T> globalCurrentState,
+                                      final FieldODEStateAndDerivative<T> softPreviousState,
+                                      final FieldODEStateAndDerivative<T> softCurrentState,
+                                      final FieldEquationsMapper<T> mapper) {
+        super(forward, globalPreviousState, globalCurrentState, softPreviousState, softCurrentState, mapper);
+    }
+
+    @Override
+    protected AbstractFieldStepInterpolator<T> create(final boolean newForward,
+                                                      final FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                      final FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                      final FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                      final FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                      final FieldEquationsMapper<T> newMapper) {
+        return new DummyFieldStepInterpolator<T>(newForward,
+                                                 newGlobalPreviousState, newGlobalCurrentState,
+                                                 newSoftPreviousState, newSoftCurrentState,
+                                                 newMapper);
+    }
+
+    @Override
+    protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(FieldEquationsMapper<T> equationsMapper,
+                                                                                   T time, T theta, T thetaH, T oneMinusThetaH) {
+        return getGlobalCurrentState();
+    }
+
+}


[25/50] [abbrv] [math] Fixed test thresholds.

Posted by lu...@apache.org.
Fixed test thresholds.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/73b76598
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/73b76598
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/73b76598

Branch: refs/heads/master
Commit: 73b76598e776bbe7962e18cea087bdca1d560769
Parents: 60afd02
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:38 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:38 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/73b76598/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
index 9a853cd..d25c4ad 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
@@ -69,15 +69,15 @@ public class DormandPrince54FieldIntegratorTest extends AbstractEmbeddedRungeKut
 
     @Override
     public void testIncreasingTolerance() {
-        // the 0.5 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
         // there is no general relation between local and global errors
-        doTestIncreasingTolerance(Decimal64Field.getInstance(), 0.5, 1.0e-12);
+        doTestIncreasingTolerance(Decimal64Field.getInstance(), 0.7, 1.0e-12);
     }
 
     @Override
     public void testEvents() {
-        doTestEvents(Decimal64Field.getInstance(), 3.10e-8, "Dormand-Prince 5(4)");
+        doTestEvents(Decimal64Field.getInstance(), 1.7e-7, "Dormand-Prince 5(4)");
     }
 
     @Override


[27/50] [abbrv] [math] Fixed syntax incompatible with Java 5.

Posted by lu...@apache.org.
Fixed syntax incompatible with Java 5.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/27732156
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/27732156
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/27732156

Branch: refs/heads/master
Commit: 277321564dd18c68fce97594652d5aea50ff221c
Parents: 7a1c10a
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:40 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:40 2016 +0100

----------------------------------------------------------------------
 .../commons/math4/ode/FieldExpandableODE.java       |  2 +-
 ...stractEmbeddedRungeKuttaFieldIntegratorTest.java | 16 ++++++++--------
 .../AbstractRungeKuttaFieldIntegratorTest.java      | 14 +++++++-------
 ...AbstractRungeKuttaFieldStepInterpolatorTest.java |  6 +++---
 .../ode/sampling/StepInterpolatorTestUtils.java     |  2 +-
 5 files changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/27732156/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java b/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
index 882f93c..2a8d6c0 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
@@ -92,7 +92,7 @@ public class FieldExpandableODE<T extends RealFieldElement<T>> {
     public int addSecondaryEquations(final FieldSecondaryEquations<T> secondary) {
 
         components.add(secondary);
-        mapper = new FieldEquationsMapper<>(mapper, secondary.getDimension());
+        mapper = new FieldEquationsMapper<T>(mapper, secondary.getDimension());
 
         return components.size() - 1;
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/27732156/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
index 3f2b0be..26a7364 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
@@ -151,7 +151,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
         EmbeddedRungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, 0.0, 1.0, 1.0e-10, 1.0e-10);
 
         try  {
-            integrator.integrate(new FieldExpandableODE<>(equations),
+            integrator.integrate(new FieldExpandableODE<T>(equations),
                                  new FieldODEState<T>(field.getOne().negate(),
                                                       MathArrays.buildArray(field, 1)),
                                  field.getZero());
@@ -161,7 +161,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
           }
 
           try  {
-              integrator.integrate(new FieldExpandableODE<>(equations),
+              integrator.integrate(new FieldExpandableODE<T>(equations),
                                    new FieldODEState<T>(field.getZero(),
                                                         MathArrays.buildArray(field, 1)),
                                    field.getOne());
@@ -191,7 +191,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
                                                               vecAbsoluteTolerance, vecRelativeTolerance);
         TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
         integ.addStepHandler(handler);
-        integ.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
         Assert.fail("an exception should have been thrown");
 
     }
@@ -352,7 +352,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
             EmbeddedRungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, 0,
                                                                                pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
                                                                                new double[4], new double[4]);
-            integrator.integrate(new FieldExpandableODE<>(pb),
+            integrator.integrate(new FieldExpandableODE<T>(pb),
                                  new FieldODEState<T>(pb.getInitialState().getTime(),
                                                       MathArrays.buildArray(field, 6)),
                                  pb.getFinalTime());
@@ -364,7 +364,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
                             createIntegrator(field, 0,
                                              pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
                                              new double[2], new double[4]);
-            integrator.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+            integrator.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
             Assert.fail("an exception should have been thrown");
         } catch(DimensionMismatchException ie) {
         }
@@ -373,7 +373,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
                             createIntegrator(field, 0,
                                              pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal(),
                                              new double[4], new double[4]);
-            integrator.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getInitialState().getTime());
+            integrator.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getInitialState().getTime());
             Assert.fail("an exception should have been thrown");
         } catch(NumberIsTooSmallException ie) {
         }
@@ -401,7 +401,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
                                                                       scalRelativeTolerance);
         TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
         integ.addStepHandler(handler);
-        integ.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
 
         Assert.assertEquals(0, handler.getLastError().getReal(),         espilonLast);
         Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
@@ -424,7 +424,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
         FieldFirstOrderIntegrator<T> integ = createIntegrator(field, minStep, maxStep,
                                                               vecAbsoluteTolerance, vecRelativeTolerance);
         integ.addStepHandler(new KeplerHandler<T>(pb, epsilon));
-        integ.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
     }
 
     private static class KeplerHandler<T extends RealFieldElement<T>> implements FieldStepHandler<T> {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/27732156/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
index cc66cd1..80d6251 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
@@ -201,7 +201,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
         RungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, field.getZero().add(0.01));
         try  {
             TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
-            integrator.integrate(new FieldExpandableODE<>(pb),
+            integrator.integrate(new FieldExpandableODE<T>(pb),
                                  new FieldODEState<T>(field.getZero(), MathArrays.buildArray(field, pb.getDimension() + 10)),
                                  field.getOne());
             Assert.fail("an exception should have been thrown");
@@ -209,7 +209,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
         }
         try  {
             TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
-            integrator.integrate(new FieldExpandableODE<>(pb),
+            integrator.integrate(new FieldExpandableODE<T>(pb),
                                  new FieldODEState<T>(field.getZero(), MathArrays.buildArray(field, pb.getDimension())),
                                  field.getZero());
             Assert.fail("an exception should have been thrown");
@@ -349,7 +349,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
         RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
         TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
         integ.addStepHandler(handler);
-        integ.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
 
         Assert.assertEquals(0, handler.getLastError().getReal(),         espilonLast);
         Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
@@ -370,7 +370,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
 
         RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
         integ.addStepHandler(new KeplerHandler<T>(pb, expectedMaxError, epsilon));
-        integ.integrate(new FieldExpandableODE<>(pb), pb.getInitialState(), pb.getFinalTime());
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
     }
 
     private static class KeplerHandler<T extends RealFieldElement<T>> implements FieldStepHandler<T> {
@@ -488,7 +488,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
 
         };
 
-        integ.integrate(new FieldExpandableODE<>(equations), new FieldODEState<T>(t0, y0), t);
+        integ.integrate(new FieldExpandableODE<T>(equations), new FieldODEState<T>(t0, y0), t);
 
     }
 
@@ -502,8 +502,8 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
                                                                       field.getZero().add(2.0));
       RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, field.getZero().add(0.3));
       integ.addEventHandler(stepProblem, 1.0, 1.0e-12, 1000);
-      FieldODEStateAndDerivative<T> result = integ.integrate(new FieldExpandableODE<>(stepProblem),
-                                                             new FieldODEState<>(field.getZero(), MathArrays.buildArray(field, 1)),
+      FieldODEStateAndDerivative<T> result = integ.integrate(new FieldExpandableODE<T>(stepProblem),
+                                                             new FieldODEState<T>(field.getZero(), MathArrays.buildArray(field, 1)),
                                                              field.getZero().add(10.0));
       Assert.assertEquals(8.0, result.getState()[0].getReal(), epsilon);
     }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/27732156/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index 64e91a2..4716b81 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -46,7 +46,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
     protected <T extends RealFieldElement<T>> void doInterpolationAtBounds(final Field<T> field, double epsilon) {
 
         RungeKuttaFieldStepInterpolator<T> interpolator = setUpInterpolator(field,
-                                                                            new SinCos<>(field),
+                                                                            new SinCos<T>(field),
                                                                             0.0, new double[] { 0.0, 1.0 }, 0.125);
 
         Assert.assertEquals(0.0, interpolator.getPreviousState().getTime().getReal(), 1.0e-15);
@@ -71,7 +71,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                                                                          double epsilonSin, double epsilonCos) {
 
         RungeKuttaFieldStepInterpolator<T> interpolator = setUpInterpolator(field,
-                                                                            new SinCos<>(field),
+                                                                            new SinCos<T>(field),
                                                                             0.0, new double[] { 0.0, 1.0 }, 0.0125);
 
         int n = 100;
@@ -97,7 +97,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                                                                                      double epsilonSin, double epsilonCos,
                                                                                      double epsilonSinDot, double epsilonCosDot) {
 
-        FieldFirstOrderDifferentialEquations<T> eqn = new SinCos<>(field);
+        FieldFirstOrderDifferentialEquations<T> eqn = new SinCos<T>(field);
         RungeKuttaFieldStepInterpolator<T> fieldInterpolator =
                         setUpInterpolator(field, eqn, 0.0, new double[] { 0.0, 1.0 }, 0.125);
         RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator, eqn);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/27732156/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java b/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java
index 98d799c..9798b9d 100644
--- a/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java
+++ b/src/test/java/org/apache/commons/math4/ode/sampling/StepInterpolatorTestUtils.java
@@ -137,7 +137,7 @@ public class StepInterpolatorTestUtils {
 
         });
 
-        integrator.integrate(new FieldExpandableODE<>(problem), problem.getInitialState(), problem.getFinalTime());
+        integrator.integrate(new FieldExpandableODE<T>(problem), problem.getInitialState(), problem.getFinalTime());
 
     }
 }


[45/50] [abbrv] [math] Field-based implementation of Adams-Moulton ODE integrator.

Posted by lu...@apache.org.
Field-based implementation of Adams-Moulton ODE integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/82cf2774
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/82cf2774
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/82cf2774

Branch: refs/heads/master
Commit: 82cf2774a215ae46477e4b35decf77321e20ab34
Parents: 2a690ee
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:19:07 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:19:07 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/MultistepFieldIntegrator.java     |  27 ++
 .../nonstiff/AdamsBashforthFieldIntegrator.java |  58 +--
 .../nonstiff/AdamsFieldStepInterpolator.java    |  63 ++-
 .../nonstiff/AdamsMoultonFieldIntegrator.java   | 416 +++++++++++++++++++
 .../AbstractAdamsFieldIntegratorTest.java       |   9 +-
 .../AdamsBashforthFieldIntegratorTest.java      |   6 +-
 .../nonstiff/AdamsBashforthIntegratorTest.java  |   6 +-
 .../AdamsMoultonFieldIntegratorTest.java        |  78 ++++
 8 files changed, 579 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/82cf2774/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
index feec974..d1ad3c8 100644
--- a/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
@@ -316,6 +316,33 @@ public abstract class MultistepFieldIntegrator<T extends RealFieldElement<T>>
       return nSteps;
     }
 
+    /** Rescale the instance.
+     * <p>Since the scaled and Nordsieck arrays are shared with the caller,
+     * this method has the side effect of rescaling this arrays in the caller too.</p>
+     * @param newStepSize new step size to use in the scaled and Nordsieck arrays
+     */
+    protected void rescale(final T newStepSize) {
+
+        final T ratio = newStepSize.divide(getStepSize());
+        for (int i = 0; i < scaled.length; ++i) {
+            scaled[i] = scaled[i].multiply(ratio);
+        }
+
+        final T[][] nData = nordsieck.getDataRef();
+        T power = ratio;
+        for (int i = 0; i < nData.length; ++i) {
+            power = power.multiply(ratio);
+            final T[] nDataI = nData[i];
+            for (int j = 0; j < nDataI.length; ++j) {
+                nDataI[j] = nDataI[j].multiply(power);
+            }
+        }
+
+        setStepSize(newStepSize);
+
+    }
+
+
     /** Compute step grow/shrink factor according to normalized error.
      * @param error normalized error of the current step
      * @return grow/shrink factor for next step

http://git-wip-us.apache.org/repos/asf/commons-math/blob/82cf2774/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java
index db6bf4f..977573e 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java
@@ -255,9 +255,11 @@ public class AdamsBashforthFieldIntegrator<T extends RealFieldElement<T>> extend
         start(equations, getStepStart(), finalTime);
 
         // reuse the step that was chosen by the starter integrator
-        AdamsFieldStepInterpolator<T> interpolator =
-                        new AdamsFieldStepInterpolator<T>(getStepSize(), getStepStart(), scaled, nordsieck,
-                                                          forward, equations.getMapper());
+        FieldODEStateAndDerivative<T> stepStart = getStepStart();
+        FieldODEStateAndDerivative<T> stepEnd   =
+                        AdamsFieldStepInterpolator.taylor(stepStart,
+                                                          stepStart.getTime().add(getStepSize()),
+                                                          getStepSize(), scaled, nordsieck);
 
         // main integration loop
         setIsLastStep(false);
@@ -270,7 +272,6 @@ public class AdamsBashforthFieldIntegrator<T extends RealFieldElement<T>> extend
             while (error.subtract(1.0).getReal() >= 0.0) {
 
                 // predict a first estimate of the state at step end
-                final FieldODEStateAndDerivative<T> stepEnd = interpolator.getCurrentState();
                 predictedY = stepEnd.getState();
 
                 // evaluate the derivative
@@ -290,26 +291,32 @@ public class AdamsBashforthFieldIntegrator<T extends RealFieldElement<T>> extend
                     // reject the step and attempt to reduce error by stepsize control
                     final T factor = computeStepGrowShrinkFactor(error);
                     rescale(filterStep(getStepSize().multiply(factor), forward, false));
-                    interpolator = new AdamsFieldStepInterpolator<T>(getStepSize(), getStepStart(), scaled, nordsieck,
-                                                                     forward, equations.getMapper());
+                    stepEnd = AdamsFieldStepInterpolator.taylor(getStepStart(),
+                                                                getStepStart().getTime().add(getStepSize()),
+                                                                getStepSize(),
+                                                                scaled,
+                                                                nordsieck);
 
                 }
             }
 
             // discrete events handling
-            System.arraycopy(predictedY, 0, y, 0, y.length);
-            setStepStart(acceptStep(interpolator, finalTime));
+            setStepStart(acceptStep(new AdamsFieldStepInterpolator<T>(getStepSize(), stepEnd,
+                                                                      predictedScaled, predictedNordsieck, forward,
+                                                                      getStepStart(), stepEnd,
+                                                                      equations.getMapper()),
+                                    finalTime));
             scaled    = predictedScaled;
             nordsieck = predictedNordsieck;
 
             if (!isLastStep()) {
 
+                System.arraycopy(predictedY, 0, y, 0, y.length);
+
                 if (resetOccurred()) {
                     // some events handler has triggered changes that
                     // invalidate the derivatives, we need to restart from scratch
                     start(equations, getStepStart(), finalTime);
-                    interpolator = new AdamsFieldStepInterpolator<T>(getStepSize(), getStepStart(), scaled, nordsieck,
-                                                                     forward, equations.getMapper());
                 }
 
                 // stepsize control for next step
@@ -330,8 +337,8 @@ public class AdamsBashforthFieldIntegrator<T extends RealFieldElement<T>> extend
                 }
 
                 rescale(hNew);
-                interpolator = new AdamsFieldStepInterpolator<T>(getStepSize(), getStepStart(), scaled, nordsieck,
-                                                                 forward, equations.getMapper());
+                stepEnd = AdamsFieldStepInterpolator.taylor(getStepStart(), getStepStart().getTime().add(getStepSize()),
+                                                            getStepSize(), scaled, nordsieck);
 
             }
 
@@ -344,31 +351,4 @@ public class AdamsBashforthFieldIntegrator<T extends RealFieldElement<T>> extend
 
     }
 
-    /** Rescale the instance.
-     * <p>Since the scaled and Nordsieck arrays are shared with the caller,
-     * this method has the side effect of rescaling this arrays in the caller too.</p>
-     * @param newStepSize new step size to use in the scaled and Nordsieck arrays
-     */
-    public void rescale(final T newStepSize) {
-
-        final T ratio = newStepSize.divide(getStepSize());
-        for (int i = 0; i < scaled.length; ++i) {
-            scaled[i] = scaled[i].multiply(ratio);
-        }
-
-        final T[][] nData = nordsieck.getDataRef();
-        T power = ratio;
-        for (int i = 0; i < nData.length; ++i) {
-            power = power.multiply(ratio);
-            final T[] nDataI = nData[i];
-            for (int j = 0; j < nDataI.length; ++j) {
-                nDataI[j] = nDataI[j].multiply(power);
-            }
-        }
-
-        setStepSize(newStepSize);
-
-    }
-
-
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/82cf2774/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java
index 78c3c8e..b4b5357 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java
@@ -43,6 +43,14 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
     /** Step size used in the first scaled derivative and Nordsieck vector. */
     private T scalingH;
 
+    /** Reference state.
+     * <p>Sometimes, the reference state is the same as globalPreviousState,
+     * sometimes it is the same as globalCurrentState, so we use a separate
+     * field to avoid any confusion.
+     * </p>
+     */
+    private final FieldODEStateAndDerivative<T> reference;
+
     /** First scaled derivative. */
     private final T[] scaled;
 
@@ -51,22 +59,7 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
 
     /** Simple constructor.
      * @param stepSize step size used in the scaled and Nordsieck arrays
-     * @param referenceState reference state from which Taylor expansion are estimated
-     * @param scaled first scaled derivative
-     * @param nordsieck Nordsieck vector
-     * @param isForward integration direction indicator
-     * @param equationsMapper mapper for ODE equations primary and secondary components
-     */
-    AdamsFieldStepInterpolator(final T stepSize, final FieldODEStateAndDerivative<T> referenceState,
-                               final T[] scaled, final Array2DRowFieldMatrix<T> nordsieck,
-                               final boolean isForward, final FieldEquationsMapper<T> equationsMapper) {
-        this(stepSize, scaled, nordsieck, isForward,
-             referenceState, taylor(referenceState, referenceState.getTime().add(stepSize), stepSize, scaled, nordsieck),
-             equationsMapper);
-    }
-
-    /** Simple constructor.
-     * @param stepSize step size used in the scaled and Nordsieck arrays
+     * @param reference reference state from which Taylor expansion are estimated
      * @param scaled first scaled derivative
      * @param nordsieck Nordsieck vector
      * @param isForward integration direction indicator
@@ -74,19 +67,20 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
      * @param globalCurrentState end of the global step
      * @param equationsMapper mapper for ODE equations primary and secondary components
      */
-    private AdamsFieldStepInterpolator(final T stepSize, final T[] scaled,
-                                       final Array2DRowFieldMatrix<T> nordsieck,
-                                       final boolean isForward,
-                                       final FieldODEStateAndDerivative<T> globalPreviousState,
-                                       final FieldODEStateAndDerivative<T> globalCurrentState,
-                                       final FieldEquationsMapper<T> equationsMapper) {
-        this(stepSize, scaled, nordsieck,
+    AdamsFieldStepInterpolator(final T stepSize, final FieldODEStateAndDerivative<T> reference,
+                               final T[] scaled, final Array2DRowFieldMatrix<T> nordsieck,
+                               final boolean isForward,
+                               final FieldODEStateAndDerivative<T> globalPreviousState,
+                               final FieldODEStateAndDerivative<T> globalCurrentState,
+                               final FieldEquationsMapper<T> equationsMapper) {
+        this(stepSize, reference, scaled, nordsieck,
              isForward, globalPreviousState, globalCurrentState,
              globalPreviousState, globalCurrentState, equationsMapper);
     }
 
     /** Simple constructor.
      * @param stepSize step size used in the scaled and Nordsieck arrays
+     * @param reference reference state from which Taylor expansion are estimated
      * @param scaled first scaled derivative
      * @param nordsieck Nordsieck vector
      * @param isForward integration direction indicator
@@ -96,8 +90,8 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
      * @param softCurrentState end of the restricted step
      * @param equationsMapper mapper for ODE equations primary and secondary components
      */
-    private AdamsFieldStepInterpolator(final T stepSize, final T[] scaled,
-                                       final Array2DRowFieldMatrix<T> nordsieck,
+    private AdamsFieldStepInterpolator(final T stepSize, final FieldODEStateAndDerivative<T> reference,
+                                       final T[] scaled, final Array2DRowFieldMatrix<T> nordsieck,
                                        final boolean isForward,
                                        final FieldODEStateAndDerivative<T> globalPreviousState,
                                        final FieldODEStateAndDerivative<T> globalCurrentState,
@@ -107,6 +101,7 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
         super(isForward, globalPreviousState, globalCurrentState,
               softPreviousState, softCurrentState, equationsMapper);
         this.scalingH  = stepSize;
+        this.reference = reference;
         this.scaled    = scaled.clone();
         this.nordsieck = new Array2DRowFieldMatrix<T>(nordsieck.getData(), false);
     }
@@ -126,7 +121,7 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
                                                    FieldODEStateAndDerivative<T> newSoftPreviousState,
                                                    FieldODEStateAndDerivative<T> newSoftCurrentState,
                                                    FieldEquationsMapper<T> newMapper) {
-        return new AdamsFieldStepInterpolator<T>(scalingH, scaled, nordsieck,
+        return new AdamsFieldStepInterpolator<T>(scalingH, reference, scaled, nordsieck,
                                                  newForward,
                                                  newGlobalPreviousState, newGlobalCurrentState,
                                                  newSoftPreviousState, newSoftCurrentState,
@@ -139,11 +134,11 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
     protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> equationsMapper,
                                                                                    final T time, final T theta,
                                                                                    final T thetaH, final T oneMinusThetaH) {
-        return taylor(getPreviousState(), time, scalingH, scaled, nordsieck);
+        return taylor(reference, time, scalingH, scaled, nordsieck);
     }
 
     /** Estimate state by applying Taylor formula.
-     * @param referenceState reference state
+     * @param reference reference state
      * @param time time at which state must be estimated
      * @param stepSize step size used in the scaled and Nordsieck arrays
      * @param scaled first scaled derivative
@@ -151,12 +146,12 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
      * @return estimated state
      * @param <S> the type of the field elements
      */
-    private static <S extends RealFieldElement<S>> FieldODEStateAndDerivative<S> taylor(final FieldODEStateAndDerivative<S> referenceState,
-                                                                                        final S time, final S stepSize,
-                                                                                        final S[] scaled,
-                                                                                        final Array2DRowFieldMatrix<S> nordsieck) {
+    public static <S extends RealFieldElement<S>> FieldODEStateAndDerivative<S> taylor(final FieldODEStateAndDerivative<S> reference,
+                                                                                       final S time, final S stepSize,
+                                                                                       final S[] scaled,
+                                                                                       final Array2DRowFieldMatrix<S> nordsieck) {
 
-        final S x = time.subtract(referenceState.getTime());
+        final S x = time.subtract(reference.getTime());
         final S normalizedAbscissa = x.divide(stepSize);
 
         S[] stateVariation = MathArrays.buildArray(time.getField(), scaled.length);
@@ -178,7 +173,7 @@ class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends Abstract
             }
         }
 
-        S[] estimatedState = referenceState.getState();
+        S[] estimatedState = reference.getState();
         for (int j = 0; j < stateVariation.length; ++j) {
             stateVariation[j]    = stateVariation[j].add(scaled[j].multiply(normalizedAbscissa));
             estimatedState[j] = estimatedState[j].add(stateVariation[j]);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/82cf2774/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java
new file mode 100644
index 0000000..b09942d
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java
@@ -0,0 +1,416 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+import java.util.Arrays;
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+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.linear.Array2DRowFieldMatrix;
+import org.apache.commons.math4.linear.FieldMatrixPreservingVisitor;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FieldODEState;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.util.MathArrays;
+import org.apache.commons.math4.util.MathUtils;
+
+
+/**
+ * This class implements implicit Adams-Moulton integrators for Ordinary
+ * Differential Equations.
+ *
+ * <p>Adams-Moulton methods (in fact due to Adams alone) are implicit
+ * multistep ODE solvers. This implementation is a variation of the classical
+ * one: it uses adaptive stepsize to implement error control, whereas
+ * classical implementations are fixed step size. The value of state vector
+ * at step n+1 is a simple combination of the value at step n and of the
+ * derivatives at steps n+1, n, n-1 ... Since y'<sub>n+1</sub> is needed to
+ * compute y<sub>n+1</sub>, another method must be used to compute a first
+ * estimate of y<sub>n+1</sub>, then compute y'<sub>n+1</sub>, then compute
+ * a final estimate of y<sub>n+1</sub> using the following formulas. Depending
+ * on the number k of previous steps one wants to use for computing the next
+ * value, different formulas are available for the final estimate:</p>
+ * <ul>
+ *   <li>k = 1: y<sub>n+1</sub> = y<sub>n</sub> + h y'<sub>n+1</sub></li>
+ *   <li>k = 2: y<sub>n+1</sub> = y<sub>n</sub> + h (y'<sub>n+1</sub>+y'<sub>n</sub>)/2</li>
+ *   <li>k = 3: y<sub>n+1</sub> = y<sub>n</sub> + h (5y'<sub>n+1</sub>+8y'<sub>n</sub>-y'<sub>n-1</sub>)/12</li>
+ *   <li>k = 4: y<sub>n+1</sub> = y<sub>n</sub> + h (9y'<sub>n+1</sub>+19y'<sub>n</sub>-5y'<sub>n-1</sub>+y'<sub>n-2</sub>)/24</li>
+ *   <li>...</li>
+ * </ul>
+ *
+ * <p>A k-steps Adams-Moulton method is of order k+1.</p>
+ *
+ * <h3>Implementation details</h3>
+ *
+ * <p>We define scaled derivatives s<sub>i</sub>(n) at step n as:
+ * <pre>
+ * s<sub>1</sub>(n) = h y'<sub>n</sub> for first derivative
+ * s<sub>2</sub>(n) = h<sup>2</sup>/2 y''<sub>n</sub> for second derivative
+ * s<sub>3</sub>(n) = h<sup>3</sup>/6 y'''<sub>n</sub> for third derivative
+ * ...
+ * s<sub>k</sub>(n) = h<sup>k</sup>/k! y<sup>(k)</sup><sub>n</sub> for k<sup>th</sup> derivative
+ * </pre></p>
+ *
+ * <p>The definitions above use the classical representation with several previous first
+ * derivatives. Lets define
+ * <pre>
+ *   q<sub>n</sub> = [ s<sub>1</sub>(n-1) s<sub>1</sub>(n-2) ... s<sub>1</sub>(n-(k-1)) ]<sup>T</sup>
+ * </pre>
+ * (we omit the k index in the notation for clarity). With these definitions,
+ * Adams-Moulton methods can be written:
+ * <ul>
+ *   <li>k = 1: y<sub>n+1</sub> = y<sub>n</sub> + s<sub>1</sub>(n+1)</li>
+ *   <li>k = 2: y<sub>n+1</sub> = y<sub>n</sub> + 1/2 s<sub>1</sub>(n+1) + [ 1/2 ] q<sub>n+1</sub></li>
+ *   <li>k = 3: y<sub>n+1</sub> = y<sub>n</sub> + 5/12 s<sub>1</sub>(n+1) + [ 8/12 -1/12 ] q<sub>n+1</sub></li>
+ *   <li>k = 4: y<sub>n+1</sub> = y<sub>n</sub> + 9/24 s<sub>1</sub>(n+1) + [ 19/24 -5/24 1/24 ] q<sub>n+1</sub></li>
+ *   <li>...</li>
+ * </ul></p>
+ *
+ * <p>Instead of using the classical representation with first derivatives only (y<sub>n</sub>,
+ * s<sub>1</sub>(n+1) and q<sub>n+1</sub>), our implementation uses the Nordsieck vector with
+ * higher degrees scaled derivatives all taken at the same step (y<sub>n</sub>, s<sub>1</sub>(n)
+ * and r<sub>n</sub>) where r<sub>n</sub> is defined as:
+ * <pre>
+ * r<sub>n</sub> = [ s<sub>2</sub>(n), s<sub>3</sub>(n) ... s<sub>k</sub>(n) ]<sup>T</sup>
+ * </pre>
+ * (here again we omit the k index in the notation for clarity)
+ * </p>
+ *
+ * <p>Taylor series formulas show that for any index offset i, s<sub>1</sub>(n-i) can be
+ * computed from s<sub>1</sub>(n), s<sub>2</sub>(n) ... s<sub>k</sub>(n), the formula being exact
+ * for degree k polynomials.
+ * <pre>
+ * s<sub>1</sub>(n-i) = s<sub>1</sub>(n) + &sum;<sub>j&gt;0</sub> (j+1) (-i)<sup>j</sup> s<sub>j+1</sub>(n)
+ * </pre>
+ * The previous formula can be used with several values for i to compute the transform between
+ * classical representation and Nordsieck vector. The transform between r<sub>n</sub>
+ * and q<sub>n</sub> resulting from the Taylor series formulas above is:
+ * <pre>
+ * q<sub>n</sub> = s<sub>1</sub>(n) u + P r<sub>n</sub>
+ * </pre>
+ * where u is the [ 1 1 ... 1 ]<sup>T</sup> vector and P is the (k-1)&times;(k-1) matrix built
+ * with the (j+1) (-i)<sup>j</sup> terms with i being the row number starting from 1 and j being
+ * the column number starting from 1:
+ * <pre>
+ *        [  -2   3   -4    5  ... ]
+ *        [  -4  12  -32   80  ... ]
+ *   P =  [  -6  27 -108  405  ... ]
+ *        [  -8  48 -256 1280  ... ]
+ *        [          ...           ]
+ * </pre></p>
+ *
+ * <p>Using the Nordsieck vector has several advantages:
+ * <ul>
+ *   <li>it greatly simplifies step interpolation as the interpolator mainly applies
+ *   Taylor series formulas,</li>
+ *   <li>it simplifies step changes that occur when discrete events that truncate
+ *   the step are triggered,</li>
+ *   <li>it allows to extend the methods in order to support adaptive stepsize.</li>
+ * </ul></p>
+ *
+ * <p>The predicted Nordsieck vector at step n+1 is computed from the Nordsieck vector at step
+ * n as follows:
+ * <ul>
+ *   <li>Y<sub>n+1</sub> = y<sub>n</sub> + s<sub>1</sub>(n) + u<sup>T</sup> r<sub>n</sub></li>
+ *   <li>S<sub>1</sub>(n+1) = h f(t<sub>n+1</sub>, Y<sub>n+1</sub>)</li>
+ *   <li>R<sub>n+1</sub> = (s<sub>1</sub>(n) - S<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub></li>
+ * </ul>
+ * where A is a rows shifting matrix (the lower left part is an identity matrix):
+ * <pre>
+ *        [ 0 0   ...  0 0 | 0 ]
+ *        [ ---------------+---]
+ *        [ 1 0   ...  0 0 | 0 ]
+ *    A = [ 0 1   ...  0 0 | 0 ]
+ *        [       ...      | 0 ]
+ *        [ 0 0   ...  1 0 | 0 ]
+ *        [ 0 0   ...  0 1 | 0 ]
+ * </pre>
+ * From this predicted vector, the corrected vector is computed as follows:
+ * <ul>
+ *   <li>y<sub>n+1</sub> = y<sub>n</sub> + S<sub>1</sub>(n+1) + [ -1 +1 -1 +1 ... &plusmn;1 ] r<sub>n+1</sub></li>
+ *   <li>s<sub>1</sub>(n+1) = h f(t<sub>n+1</sub>, y<sub>n+1</sub>)</li>
+ *   <li>r<sub>n+1</sub> = R<sub>n+1</sub> + (s<sub>1</sub>(n+1) - S<sub>1</sub>(n+1)) P<sup>-1</sup> u</li>
+ * </ul>
+ * where the upper case Y<sub>n+1</sub>, S<sub>1</sub>(n+1) and R<sub>n+1</sub> represent the
+ * predicted states whereas the lower case y<sub>n+1</sub>, s<sub>n+1</sub> and r<sub>n+1</sub>
+ * represent the corrected states.</p>
+ *
+ * <p>The P<sup>-1</sup>u vector and the P<sup>-1</sup> A P matrix do not depend on the state,
+ * they only depend on k and therefore are precomputed once for all.</p>
+ *
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+public class AdamsMoultonFieldIntegrator<T extends RealFieldElement<T>> extends AdamsFieldIntegrator<T> {
+
+    /** Integrator method name. */
+    private static final String METHOD_NAME = "Adams-Moulton";
+
+    /**
+     * Build an Adams-Moulton integrator with the given order and error control parameters.
+     * @param field field to which the time and state vector elements belong
+     * @param nSteps number of steps of the method excluding the one being computed
+     * @param minStep minimal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param maxStep maximal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param scalAbsoluteTolerance allowed absolute error
+     * @param scalRelativeTolerance allowed relative error
+     * @exception NumberIsTooSmallException if order is 1 or less
+     */
+    public AdamsMoultonFieldIntegrator(final Field<T> field, final int nSteps,
+                                       final double minStep, final double maxStep,
+                                       final double scalAbsoluteTolerance,
+                                       final double scalRelativeTolerance)
+        throws NumberIsTooSmallException {
+        super(field, METHOD_NAME, nSteps, nSteps + 1, minStep, maxStep,
+              scalAbsoluteTolerance, scalRelativeTolerance);
+    }
+
+    /**
+     * Build an Adams-Moulton integrator with the given order and error control parameters.
+     * @param field field to which the time and state vector elements belong
+     * @param nSteps number of steps of the method excluding the one being computed
+     * @param minStep minimal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param maxStep maximal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param vecAbsoluteTolerance allowed absolute error
+     * @param vecRelativeTolerance allowed relative error
+     * @exception IllegalArgumentException if order is 1 or less
+     */
+    public AdamsMoultonFieldIntegrator(final Field<T> field, final int nSteps,
+                                       final double minStep, final double maxStep,
+                                       final double[] vecAbsoluteTolerance,
+                                       final double[] vecRelativeTolerance)
+        throws IllegalArgumentException {
+        super(field, METHOD_NAME, nSteps, nSteps + 1, minStep, maxStep,
+              vecAbsoluteTolerance, vecRelativeTolerance);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public FieldODEStateAndDerivative<T> integrate(final FieldExpandableODE<T> equations,
+                                                   final FieldODEState<T> initialState,
+                                                   final T finalTime)
+        throws NumberIsTooSmallException, DimensionMismatchException,
+               MaxCountExceededException, NoBracketingException {
+
+        sanityChecks(initialState, finalTime);
+        final T   t0 = initialState.getTime();
+        final T[] y  = equations.getMapper().mapState(initialState);
+        setStepStart(initIntegration(equations, t0, y, finalTime));
+        final boolean forward = finalTime.subtract(initialState.getTime()).getReal() > 0;
+
+        // compute the initial Nordsieck vector using the configured starter integrator
+        start(equations, getStepStart(), finalTime);
+
+        // reuse the step that was chosen by the starter integrator
+        FieldODEStateAndDerivative<T> stepStart = getStepStart();
+        FieldODEStateAndDerivative<T> stepEnd   =
+                        AdamsFieldStepInterpolator.taylor(stepStart,
+                                                          stepStart.getTime().add(getStepSize()),
+                                                          getStepSize(), scaled, nordsieck);
+
+        // main integration loop
+        setIsLastStep(false);
+        do {
+
+            T[] predictedY = null;
+            final T[] predictedScaled = MathArrays.buildArray(getField(), y.length);
+            Array2DRowFieldMatrix<T> predictedNordsieck = null;
+            T error = getField().getZero().add(10);
+            while (error.subtract(1.0).getReal() >= 0.0) {
+
+                // predict a first estimate of the state at step end (P in the PECE sequence)
+                predictedY = stepEnd.getState();
+
+                // evaluate a first estimate of the derivative (first E in the PECE sequence)
+                final T[] yDot = computeDerivatives(stepEnd.getTime(), predictedY);
+
+                // update Nordsieck vector
+                for (int j = 0; j < predictedScaled.length; ++j) {
+                    predictedScaled[j] = getStepSize().multiply(yDot[j]);
+                }
+                predictedNordsieck = updateHighOrderDerivativesPhase1(nordsieck);
+                updateHighOrderDerivativesPhase2(scaled, predictedScaled, predictedNordsieck);
+
+                // apply correction (C in the PECE sequence)
+                error = predictedNordsieck.walkInOptimizedOrder(new Corrector(y, predictedScaled, predictedY));
+
+                if (error.subtract(1.0).getReal() >= 0.0) {
+                    // reject the step and attempt to reduce error by stepsize control
+                    final T factor = computeStepGrowShrinkFactor(error);
+                    rescale(filterStep(getStepSize().multiply(factor), forward, false));
+                    stepEnd = AdamsFieldStepInterpolator.taylor(getStepStart(),
+                                                                getStepStart().getTime().add(getStepSize()),
+                                                                getStepSize(),
+                                                                scaled,
+                                                                nordsieck);
+                }
+            }
+
+            // evaluate a final estimate of the derivative (second E in the PECE sequence)
+            final T[] correctedYDot = computeDerivatives(stepEnd.getTime(), predictedY);
+
+            // update Nordsieck vector
+            final T[] correctedScaled = MathArrays.buildArray(getField(), y.length);
+            for (int j = 0; j < correctedScaled.length; ++j) {
+                correctedScaled[j] = getStepSize().multiply(correctedYDot[j]);
+            }
+            updateHighOrderDerivativesPhase2(predictedScaled, correctedScaled, predictedNordsieck);
+
+            // discrete events handling
+            stepEnd = new FieldODEStateAndDerivative<T>(stepEnd.getTime(), predictedY, correctedYDot);
+            setStepStart(acceptStep(new AdamsFieldStepInterpolator<T>(getStepSize(), stepEnd,
+                                                                      correctedScaled, predictedNordsieck, forward,
+                                                                      getStepStart(), stepEnd,
+                                                                      equations.getMapper()),
+                                    finalTime));
+            scaled    = correctedScaled;
+            nordsieck = predictedNordsieck;
+
+            if (!isLastStep()) {
+
+                System.arraycopy(predictedY, 0, y, 0, y.length);
+
+                if (resetOccurred()) {
+                    // some events handler has triggered changes that
+                    // invalidate the derivatives, we need to restart from scratch
+                    start(equations, getStepStart(), finalTime);
+                }
+
+                // stepsize control for next step
+                final T  factor     = computeStepGrowShrinkFactor(error);
+                final T  scaledH    = getStepSize().multiply(factor);
+                final T  nextT      = getStepStart().getTime().add(scaledH);
+                final boolean nextIsLast = forward ?
+                                           nextT.subtract(finalTime).getReal() >= 0 :
+                                           nextT.subtract(finalTime).getReal() <= 0;
+                T hNew = filterStep(scaledH, forward, nextIsLast);
+
+                final T  filteredNextT      = getStepStart().getTime().add(hNew);
+                final boolean filteredNextIsLast = forward ?
+                                                   filteredNextT.subtract(finalTime).getReal() >= 0 :
+                                                   filteredNextT.subtract(finalTime).getReal() <= 0;
+                if (filteredNextIsLast) {
+                    hNew = finalTime.subtract(getStepStart().getTime());
+                }
+
+                rescale(hNew);
+                stepEnd = AdamsFieldStepInterpolator.taylor(getStepStart(), getStepStart().getTime().add(getStepSize()),
+                                                            getStepSize(), scaled, nordsieck);
+
+            }
+
+        } while (!isLastStep());
+
+        final FieldODEStateAndDerivative<T> finalState = getStepStart();
+        setStepStart(null);
+        setStepSize(null);
+        return finalState;
+
+    }
+
+    /** Corrector for current state in Adams-Moulton method.
+     * <p>
+     * This visitor implements the Taylor series formula:
+     * <pre>
+     * Y<sub>n+1</sub> = y<sub>n</sub> + s<sub>1</sub>(n+1) + [ -1 +1 -1 +1 ... &plusmn;1 ] r<sub>n+1</sub>
+     * </pre>
+     * </p>
+     */
+    private class Corrector implements FieldMatrixPreservingVisitor<T> {
+
+        /** Previous state. */
+        private final T[] previous;
+
+        /** Current scaled first derivative. */
+        private final T[] scaled;
+
+        /** Current state before correction. */
+        private final T[] before;
+
+        /** Current state after correction. */
+        private final T[] after;
+
+        /** Simple constructor.
+         * @param previous previous state
+         * @param scaled current scaled first derivative
+         * @param state state to correct (will be overwritten after visit)
+         */
+        Corrector(final T[] previous, final T[] scaled, final T[] state) {
+            this.previous = previous;
+            this.scaled   = scaled;
+            this.after    = state;
+            this.before   = state.clone();
+        }
+
+        /** {@inheritDoc} */
+        public void start(int rows, int columns,
+                          int startRow, int endRow, int startColumn, int endColumn) {
+            Arrays.fill(after, getField().getZero());
+        }
+
+        /** {@inheritDoc} */
+        public void visit(int row, int column, T value) {
+            if ((row & 0x1) == 0) {
+                after[column] = after[column].subtract(value);
+            } else {
+                after[column] = after[column].add(value);
+            }
+        }
+
+        /**
+         * End visiting the Nordsieck vector.
+         * <p>The correction is used to control stepsize. So its amplitude is
+         * considered to be an error, which must be normalized according to
+         * error control settings. If the normalized value is greater than 1,
+         * the correction was too large and the step must be rejected.</p>
+         * @return the normalized correction, if greater than 1, the step
+         * must be rejected
+         */
+        public T end() {
+
+            T error = getField().getZero();
+            for (int i = 0; i < after.length; ++i) {
+                after[i] = after[i].add(previous[i].add(scaled[i]));
+                if (i < mainSetDimension) {
+                    final T yScale = MathUtils.max(previous[i].abs(), after[i].abs());
+                    final T tol = (vecAbsoluteTolerance == null) ?
+                                  yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
+                                  yScale.multiply(vecRelativeTolerance[i]).add(vecAbsoluteTolerance[i]);
+                    final T ratio  = after[i].subtract(before[i]).divide(tol); // (corrected-predicted)/tol
+                    error = error.add(ratio.multiply(ratio));
+                }
+            }
+
+            return error.divide(mainSetDimension).sqrt();
+
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/82cf2774/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
index 0d22831..606c9e8 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
@@ -74,10 +74,10 @@ public abstract class AbstractAdamsFieldIntegratorTest {
     public abstract void testIncreasingTolerance();
 
     protected <T extends RealFieldElement<T>> void doTestIncreasingTolerance(final Field<T> field,
-                                                                             int ratioMin, int ratioMax) {
+                                                                             double ratioMin, double ratioMax) {
 
         int previousCalls = Integer.MAX_VALUE;
-        for (int i = -12; i < -5; ++i) {
+        for (int i = -12; i < -2; ++i) {
             TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
             double minStep = 0;
             double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
@@ -106,7 +106,7 @@ public abstract class AbstractAdamsFieldIntegratorTest {
     @Test(expected = MaxCountExceededException.class)
     public abstract void exceedMaxEvaluations();
 
-    protected <T extends RealFieldElement<T>> void doExceedMaxEvaluations(final Field<T> field) {
+    protected <T extends RealFieldElement<T>> void doExceedMaxEvaluations(final Field<T> field, final int max) {
 
         TestFieldProblem1<T> pb  = new TestFieldProblem1<T>(field);
         double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
@@ -114,7 +114,7 @@ public abstract class AbstractAdamsFieldIntegratorTest {
         FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 2, 0, range, 1.0e-12, 1.0e-12);
         TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
         integ.addStepHandler(handler);
-        integ.setMaxEvaluations(650);
+        integ.setMaxEvaluations(max);
         integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
 
     }
@@ -132,7 +132,6 @@ public abstract class AbstractAdamsFieldIntegratorTest {
         double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
 
         AdamsFieldIntegrator<T> integ = createIntegrator(field, 4, 0, range, 1.0e-12, 1.0e-12);
-        integ.setStarterIntegrator(new PerfectStarter<T>(pb, (integ.getNSteps() + 5) / 2));
         TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
         integ.addStepHandler(handler);
         integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());

http://git-wip-us.apache.org/repos/asf/commons-math/blob/82cf2774/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
index 408e646..e9a046c 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
@@ -49,15 +49,15 @@ public class AdamsBashforthFieldIntegratorTest extends AbstractAdamsFieldIntegra
 
     @Test
     public void testIncreasingTolerance() {
-        // the 7 and 121 factors are only valid for this test
+        // the 2.6 and 122 factors are only valid for this test
         // and has been obtained from trial and error
         // there are no general relationship between local and global errors
-        doTestIncreasingTolerance(Decimal64Field.getInstance(), 7, 121);
+        doTestIncreasingTolerance(Decimal64Field.getInstance(), 2.6, 122);
     }
 
     @Test(expected = MaxCountExceededException.class)
     public void exceedMaxEvaluations() {
-        doExceedMaxEvaluations(Decimal64Field.getInstance());
+        doExceedMaxEvaluations(Decimal64Field.getInstance(), 650);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/commons-math/blob/82cf2774/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegratorTest.java
index 85c7e43..f655238 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthIntegratorTest.java
@@ -77,7 +77,7 @@ public class AdamsBashforthIntegratorTest {
     public void testIncreasingTolerance() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException {
 
         int previousCalls = Integer.MAX_VALUE;
-        for (int i = -12; i < -5; ++i) {
+        for (int i = -12; i < -2; ++i) {
             TestProblem1 pb = new TestProblem1();
             double minStep = 0;
             double maxStep = pb.getFinalTime() - pb.getInitialTime();
@@ -93,10 +93,10 @@ public class AdamsBashforthIntegratorTest {
                             pb.getInitialTime(), pb.getInitialState(),
                             pb.getFinalTime(), new double[pb.getDimension()]);
 
-            // the 8 and 122 factors are only valid for this test
+            // the 2.6 and 122 factors are only valid for this test
             // and has been obtained from trial and error
             // there are no general relationship between local and global errors
-            Assert.assertTrue(handler.getMaximalValueError() > (  8 * scalAbsoluteTolerance));
+            Assert.assertTrue(handler.getMaximalValueError() > (2.6 * scalAbsoluteTolerance));
             Assert.assertTrue(handler.getMaximalValueError() < (122 * scalAbsoluteTolerance));
 
             int calls = pb.getCalls();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/82cf2774/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java
new file mode 100644
index 0000000..c44124a
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.MathIllegalStateException;
+import org.apache.commons.math4.exception.MaxCountExceededException;
+import org.apache.commons.math4.exception.NumberIsTooSmallException;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class AdamsMoultonFieldIntegratorTest extends AbstractAdamsFieldIntegratorTest {
+
+    protected <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
+    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance) {
+        return new AdamsMoultonFieldIntegrator<T>(field, nSteps, minStep, maxStep,
+                        scalAbsoluteTolerance, scalRelativeTolerance);
+    }
+
+    protected <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
+    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) {
+        return new AdamsMoultonFieldIntegrator<T>(field, nSteps, minStep, maxStep,
+                        vecAbsoluteTolerance, vecRelativeTolerance);
+    }
+
+    @Test(expected=NumberIsTooSmallException.class)
+    public void testMinStep() {
+        doDimensionCheck(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testIncreasingTolerance() {
+        // the 0.45 and 8.69 factors are only valid for this test
+        // and has been obtained from trial and error
+        // there are no general relationship between local and global errors
+        doTestIncreasingTolerance(Decimal64Field.getInstance(), 0.45, 8.69);
+    }
+
+    @Test(expected = MaxCountExceededException.class)
+    public void exceedMaxEvaluations() {
+        doExceedMaxEvaluations(Decimal64Field.getInstance(), 650);
+    }
+
+    @Test
+    public void backward() {
+        doBackward(Decimal64Field.getInstance(), 3.0e-9, 3.0e-9, 1.0e-16, "Adams-Moulton");
+    }
+
+    @Test
+    public void polynomial() {
+        doPolynomial(Decimal64Field.getInstance(), 5, 2.2e-05, 1.1e-11);
+    }
+
+    @Test(expected=MathIllegalStateException.class)
+    public void testStartFailure() {
+        doTestStartFailure(Decimal64Field.getInstance());
+    }
+
+}


[44/50] [abbrv] [math] typo.

Posted by lu...@apache.org.
typo.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/2a690ee8
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/2a690ee8
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/2a690ee8

Branch: refs/heads/master
Commit: 2a690ee895304076f6b0c984f52afed0cae37bf1
Parents: 305934d
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:18:56 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:18:56 2016 +0100

----------------------------------------------------------------------
 src/site/xdoc/userguide/ode.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/2a690ee8/src/site/xdoc/userguide/ode.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/userguide/ode.xml b/src/site/xdoc/userguide/ode.xml
index ffbebc6..4d20b1f 100644
--- a/src/site/xdoc/userguide/ode.xml
+++ b/src/site/xdoc/userguide/ode.xml
@@ -315,7 +315,7 @@ public int eventOccurred(double t, double[] y, boolean increasing) {
           href="../apidocs/org/apache/commons/math4/ode/JacobianMatrices.html">JacobianMatrices</a> class can do most of
           this as long as the local derivatives are provided to it. It will set up the variational equations, register
           them as secondary equations into the ODE, and it will set up the initial values and retrieve the intermediate
-          and finale values as Jacobian matrices.
+          and final values as Jacobian matrices.
         </p>
         <p>
           If for example the original state dimension is 6 and there are 3 parameters, the compound state will be a 60


[34/50] [abbrv] [math] Fixed additional equations mapping.

Posted by lu...@apache.org.
Fixed additional equations mapping.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/49747dc1
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/49747dc1
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/49747dc1

Branch: refs/heads/master
Commit: 49747dc1d34a48e966ceb424f40f0b7994d1cea7
Parents: 5672ebe
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:29:52 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:29:52 2016 +0100

----------------------------------------------------------------------
 .../commons/math4/ode/FieldEquationsMapper.java |  33 +-
 .../commons/math4/ode/FieldExpandableODE.java   |  12 +-
 .../apache/commons/math4/ode/FieldODEState.java |  16 +-
 .../math4/ode/FieldODEStateAndDerivative.java   |   3 +-
 .../ode/nonstiff/FieldExpandableODETest.java    | 344 +++++++++++++++++++
 5 files changed, 361 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/49747dc1/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java b/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java
index 7a6c0d5..1febe7d 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java
@@ -57,7 +57,7 @@ public class FieldEquationsMapper<T extends RealFieldElement<T>> implements Seri
         if (mapper == null) {
             start[0] = 0;
         } else {
-            System.arraycopy(mapper.start, 0, start, 0, index);
+            System.arraycopy(mapper.start, 0, start, 0, index + 1);
         }
         start[index + 1] = start[index] + dimension;
     }
@@ -88,7 +88,7 @@ public class FieldEquationsMapper<T extends RealFieldElement<T>> implements Seri
         int index = 0;
         insertEquationData(index, state.getState(), y);
         while (++index < getNumberOfEquations()) {
-            insertEquationData(index, state.getSecondaryState(index - 1), y);
+            insertEquationData(index, state.getSecondaryState(index), y);
         }
         return y;
     }
@@ -102,38 +102,11 @@ public class FieldEquationsMapper<T extends RealFieldElement<T>> implements Seri
         int index = 0;
         insertEquationData(index, state.getDerivative(), yDot);
         while (++index < getNumberOfEquations()) {
-            insertEquationData(index, state.getSecondaryDerivative(index - 1), yDot);
+            insertEquationData(index, state.getSecondaryDerivative(index), yDot);
         }
         return yDot;
     }
 
-    /** Map a flat array to a state.
-     * @param t time
-     * @param y array to map, including primary and secondary components
-     * @return mapped state
-     * @exception DimensionMismatchException if array does not match total dimension
-     */
-    public FieldODEState<T> mapState(final T t, final T[] y)
-        throws DimensionMismatchException {
-
-        if (y.length != getTotalDimension()) {
-            throw new DimensionMismatchException(y.length, getTotalDimension());
-        }
-
-        final int n = getNumberOfEquations();
-        int index = 0;
-        final T[] state = extractEquationData(index, y);
-        if (n < 2) {
-            return new FieldODEState<T>(t, state);
-        } else {
-            final T[][] secondaryState = MathArrays.buildArray(t.getField(), n - 1, -1);
-            while (++index < n) {
-                secondaryState[index - 1] = extractEquationData(index, y);
-            }
-            return new FieldODEState<T>(t, state, secondaryState);
-        }
-    }
-
     /** Map flat arrays to a state and derivative.
      * @param t time
      * @param y state array to map, including primary and secondary components

http://git-wip-us.apache.org/repos/asf/commons-math/blob/49747dc1/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java b/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
index 2a8d6c0..5e31a04 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldExpandableODE.java
@@ -69,13 +69,6 @@ public class FieldExpandableODE<T extends RealFieldElement<T>> {
         this.mapper     = new FieldEquationsMapper<T>(null, primary.getDimension());
     }
 
-    /** Get the primary set of differential equations.
-     * @return primary set of differential equations
-     */
-    public FieldFirstOrderDifferentialEquations<T> getPrimary() {
-        return primary;
-    }
-
     /** Get the mapper for the set of equations.
      * @return mapper for the set of equations
      */
@@ -87,14 +80,15 @@ public class FieldExpandableODE<T extends RealFieldElement<T>> {
      * @param secondary secondary equations set
      * @return index of the secondary equation in the expanded state, to be used
      * as the parameter to {@link FieldODEState#getSecondaryState(int)} and
-     * {@link FieldODEStateAndDerivative#getSecondaryDerivative(int)}
+     * {@link FieldODEStateAndDerivative#getSecondaryDerivative(int)} (beware index
+     * 0 corresponds to main state, additional states start at 1)
      */
     public int addSecondaryEquations(final FieldSecondaryEquations<T> secondary) {
 
         components.add(secondary);
         mapper = new FieldEquationsMapper<T>(mapper, secondary.getDimension());
 
-        return components.size() - 1;
+        return components.size();
 
     }
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/49747dc1/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldODEState.java b/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
index 70132f6..a0d0342 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
@@ -59,9 +59,9 @@ public class FieldODEState<T extends RealFieldElement<T>> {
      * @param secondaryState state at time (may be null)
      */
     public FieldODEState(T time, T[] state, T[][] secondaryState) {
-        this.time                = time;
-        this.state               = state.clone();
-        this.secondaryState      = copy(time.getField(), secondaryState);
+        this.time           = time;
+        this.state          = state.clone();
+        this.secondaryState = copy(time.getField(), secondaryState);
     }
 
     /** Copy a two-dimensions array.
@@ -77,11 +77,11 @@ public class FieldODEState<T extends RealFieldElement<T>> {
         }
 
         // allocate the array
-        final T[][] copied = MathArrays.buildArray(field, original.length, original[0].length);
+        final T[][] copied = MathArrays.buildArray(field, original.length, -1);
 
         // copy content
         for (int i = 0; i < original.length; ++i) {
-            System.arraycopy(original[i], 0, copied[i], 0, original[i].length);
+            copied[i] = original[i].clone();
         }
 
         return copied;
@@ -119,19 +119,21 @@ public class FieldODEState<T extends RealFieldElement<T>> {
     /** Get secondary state dimension.
      * @param index index of the secondary set as returned
      * by {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryEquations)}
+     * (beware index 0 corresponds to main state, additional states start at 1)
      * @return secondary state dimension
      */
     public int getSecondaryStateDimension(final int index) {
-        return secondaryState[index].length;
+        return index == 0 ? state.length : secondaryState[index - 1].length;
     }
 
     /** Get secondary state at time.
      * @param index index of the secondary set as returned
      * by {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryEquations)}
+     * (beware index 0 corresponds to main state, additional states start at 1)
      * @return secondary state at time
      */
     public T[] getSecondaryState(final int index) {
-        return secondaryState[index].clone();
+        return index == 0 ? state.clone() : secondaryState[index - 1].clone();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/49747dc1/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java b/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
index 179146a..a10b544 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
@@ -72,10 +72,11 @@ public class FieldODEStateAndDerivative<T extends RealFieldElement<T>> extends F
     /** Get derivative of the secondary state at time.
      * @param index index of the secondary set as returned
      * by {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryEquations)}
+     * (beware index 0 corresponds to main state, additional states start at 1)
      * @return derivative of the secondary state at time
      */
     public T[] getSecondaryDerivative(final int index) {
-        return secondaryDerivative[index].clone();
+        return index == 0 ? derivative.clone() : secondaryDerivative[index - 1].clone();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/49747dc1/src/test/java/org/apache/commons/math4/ode/nonstiff/FieldExpandableODETest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/FieldExpandableODETest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/FieldExpandableODETest.java
new file mode 100644
index 0000000..064e3e2
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/FieldExpandableODETest.java
@@ -0,0 +1,344 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+import org.apache.commons.math4.exception.MathIllegalArgumentException;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.FieldSecondaryEquations;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.apache.commons.math4.util.MathArrays;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class FieldExpandableODETest {
+
+    @Test
+    public void testOnlyMainEquation() {
+        doTestOnlyMainEquation(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestOnlyMainEquation(final Field<T> field) {
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<>(main);
+        Assert.assertEquals(main.getDimension(), equation.getMapper().getTotalDimension());
+        Assert.assertEquals(1, equation.getMapper().getNumberOfEquations());
+        T t0 = field.getZero().add(10);
+        T t  = field.getZero().add(100);
+        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        for (int i = 0; i < complete.length; ++i) {
+            complete[i] = field.getZero().add(i);
+        }
+        equation.init(t0, complete, t);
+        T[] completeDot = equation.computeDerivatives(t0, complete);
+        FieldODEStateAndDerivative<T> state = equation.getMapper().mapStateAndDerivative(t0, complete, completeDot);
+        Assert.assertEquals(0, state.getNumberOfSecondaryStates());
+        T[] mainState    = state.getState();
+        T[] mainStateDot = state.getDerivative();
+        Assert.assertEquals(main.getDimension(), mainState.length);
+        for (int i = 0; i < main.getDimension(); ++i) {
+            Assert.assertEquals(i, mainState[i].getReal(),   1.0e-15);
+            Assert.assertEquals(i, mainStateDot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(i, completeDot[i].getReal(),  1.0e-15);
+        }
+    }
+
+    @Test
+    public void testMainAndSecondary() {
+        doTestMainAndSecondary(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestMainAndSecondary(final Field<T> field) {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        FieldSecondaryEquations<T> secondary2 = new Linear<T>(field, 5, main.getDimension() + secondary1.getDimension());
+        int i2 = equation.addSecondaryEquations(secondary2);
+        Assert.assertEquals(main.getDimension() + secondary1.getDimension() + secondary2.getDimension(),
+                            equation.getMapper().getTotalDimension());
+        Assert.assertEquals(3, equation.getMapper().getNumberOfEquations());
+        Assert.assertEquals(1, i1);
+        Assert.assertEquals(2, i2);
+
+        T t0 = field.getZero().add(10);
+        T t  = field.getZero().add(100);
+        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        for (int i = 0; i < complete.length; ++i) {
+            complete[i] = field.getZero().add(i);
+        }
+        equation.init(t0, complete, t);
+        T[] completeDot = equation.computeDerivatives(t0, complete);
+
+        T[] mainState    = equation.getMapper().extractEquationData(0,  complete);
+        T[] mainStateDot = equation.getMapper().extractEquationData(0,  completeDot);
+        Assert.assertEquals(main.getDimension(), mainState.length);
+        for (int i = 0; i < main.getDimension(); ++i) {
+            Assert.assertEquals(i, mainState[i].getReal(),   1.0e-15);
+            Assert.assertEquals(i, mainStateDot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(i, completeDot[i].getReal(),  1.0e-15);
+        }
+
+        T[] secondaryState1    = equation.getMapper().extractEquationData(i1,  complete);
+        T[] secondaryState1Dot = equation.getMapper().extractEquationData(i1,  completeDot);
+        Assert.assertEquals(secondary1.getDimension(), secondaryState1.length);
+        for (int i = 0; i < secondary1.getDimension(); ++i) {
+            Assert.assertEquals(i + main.getDimension(), secondaryState1[i].getReal(),   1.0e-15);
+            Assert.assertEquals(-i, secondaryState1Dot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(-i, completeDot[i + main.getDimension()].getReal(),  1.0e-15);
+        }
+
+        T[] secondaryState2    = equation.getMapper().extractEquationData(i2,  complete);
+        T[] secondaryState2Dot = equation.getMapper().extractEquationData(i2,  completeDot);
+        Assert.assertEquals(secondary2.getDimension(), secondaryState2.length);
+        for (int i = 0; i < secondary2.getDimension(); ++i) {
+            Assert.assertEquals(i + main.getDimension() + secondary1.getDimension(), secondaryState2[i].getReal(),   1.0e-15);
+            Assert.assertEquals(-i, secondaryState2Dot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(-i, completeDot[i + main.getDimension() + secondary1.getDimension()].getReal(),  1.0e-15);
+        }
+
+    }
+
+    @Test
+    public void testMap() {
+        doTestMap(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestMap(final Field<T> field) {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        FieldSecondaryEquations<T> secondary2 = new Linear<T>(field, 5, main.getDimension() + secondary1.getDimension());
+        int i2 = equation.addSecondaryEquations(secondary2);
+        Assert.assertEquals(main.getDimension() + secondary1.getDimension() + secondary2.getDimension(),
+                            equation.getMapper().getTotalDimension());
+        Assert.assertEquals(3, equation.getMapper().getNumberOfEquations());
+        Assert.assertEquals(1, i1);
+        Assert.assertEquals(2, i2);
+
+        T t0 = field.getZero().add(10);
+        T t  = field.getZero().add(100);
+        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        for (int i = 0; i < complete.length; ++i) {
+            complete[i] = field.getZero().add(i);
+        }
+        equation.init(t0, complete, t);
+        T[] completeDot = equation.computeDerivatives(t0, complete);
+
+        try {
+            equation.getMapper().mapStateAndDerivative(t0, MathArrays.buildArray(field, complete.length + 1), completeDot);
+            Assert.fail("an exception should have been thrown");
+        } catch (DimensionMismatchException dme) {
+            // expected
+        }
+        try {
+            equation.getMapper().mapStateAndDerivative(t0, complete, MathArrays.buildArray(field, completeDot.length + 1));
+            Assert.fail("an exception should have been thrown");
+        } catch (DimensionMismatchException dme) {
+            // expected
+        }
+        FieldODEStateAndDerivative<T> state = equation.getMapper().mapStateAndDerivative(t0, complete, completeDot);
+        Assert.assertEquals(2, state.getNumberOfSecondaryStates());
+        Assert.assertEquals(main.getDimension(),       state.getSecondaryStateDimension(0));
+        Assert.assertEquals(secondary1.getDimension(), state.getSecondaryStateDimension(i1));
+        Assert.assertEquals(secondary2.getDimension(), state.getSecondaryStateDimension(i2));
+
+        T[] mainState             = state.getState();
+        T[] mainStateDot          = state.getDerivative();
+        T[] mainStateAlternate    = state.getSecondaryState(0);
+        T[] mainStateDotAlternate = state.getSecondaryDerivative(0);
+        Assert.assertEquals(main.getDimension(), mainState.length);
+        for (int i = 0; i < main.getDimension(); ++i) {
+            Assert.assertEquals(i, mainState[i].getReal(),             1.0e-15);
+            Assert.assertEquals(i, mainStateDot[i].getReal(),          1.0e-15);
+            Assert.assertEquals(i, mainStateAlternate[i].getReal(),    1.0e-15);
+            Assert.assertEquals(i, mainStateDotAlternate[i].getReal(), 1.0e-15);
+            Assert.assertEquals(i, completeDot[i].getReal(),           1.0e-15);
+        }
+
+        T[] secondaryState1    = state.getSecondaryState(i1);
+        T[] secondaryState1Dot = state.getSecondaryDerivative(i1);
+        Assert.assertEquals(secondary1.getDimension(), secondaryState1.length);
+        for (int i = 0; i < secondary1.getDimension(); ++i) {
+            Assert.assertEquals(i + main.getDimension(), secondaryState1[i].getReal(),   1.0e-15);
+            Assert.assertEquals(-i, secondaryState1Dot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(-i, completeDot[i + main.getDimension()].getReal(),  1.0e-15);
+        }
+
+        T[] secondaryState2    = state.getSecondaryState(i2);
+        T[] secondaryState2Dot = state.getSecondaryDerivative(i2);
+        Assert.assertEquals(secondary2.getDimension(), secondaryState2.length);
+        for (int i = 0; i < secondary2.getDimension(); ++i) {
+            Assert.assertEquals(i + main.getDimension() + secondary1.getDimension(), secondaryState2[i].getReal(),   1.0e-15);
+            Assert.assertEquals(-i, secondaryState2Dot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(-i, completeDot[i + main.getDimension() + secondary1.getDimension()].getReal(),  1.0e-15);
+        }
+
+        T[] remappedState = equation.getMapper().mapState(state);
+        T[] remappedDerivative = equation.getMapper().mapDerivative(state);
+        Assert.assertEquals(equation.getMapper().getTotalDimension(), remappedState.length);
+        Assert.assertEquals(equation.getMapper().getTotalDimension(), remappedDerivative.length);
+        for (int i = 0; i < remappedState.length; ++i) {
+            Assert.assertEquals(complete[i].getReal(),    remappedState[i].getReal(),      1.0e-15);
+            Assert.assertEquals(completeDot[i].getReal(), remappedDerivative[i].getReal(), 1.0e-15);
+        }
+    }
+
+    @Test(expected=DimensionMismatchException.class)
+    public void testExtractDimensionMismatch() {
+        doTestExtractDimensionMismatch(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestExtractDimensionMismatch(final Field<T> field)
+        throws DimensionMismatchException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        T[] tooShort    = MathArrays.buildArray(field, main.getDimension());
+        equation.getMapper().extractEquationData(i1, tooShort);
+    }
+
+    @Test(expected=DimensionMismatchException.class)
+    public void testInsertTooShortComplete() {
+        doTestInsertTooShortComplete(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestInsertTooShortComplete(final Field<T> field)
+        throws DimensionMismatchException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        T[] equationData = MathArrays.buildArray(field, secondary1.getDimension());
+        T[] tooShort     = MathArrays.buildArray(field, main.getDimension());
+        equation.getMapper().insertEquationData(i1, equationData, tooShort);
+    }
+
+    @Test(expected=DimensionMismatchException.class)
+    public void testInsertWrongEquationData() {
+        doTestInsertWrongEquationData(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestInsertWrongEquationData(final Field<T> field)
+        throws DimensionMismatchException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        T[] wrongEquationData = MathArrays.buildArray(field, secondary1.getDimension() + 1);
+        T[] complete          = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        equation.getMapper().insertEquationData(i1, wrongEquationData, complete);
+    }
+
+    @Test(expected=MathIllegalArgumentException.class)
+    public void testNegativeIndex() {
+        doTestNegativeIndex(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestNegativeIndex(final Field<T> field)
+        throws MathIllegalArgumentException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        T[] complete = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        equation.getMapper().extractEquationData(-1, complete);
+    }
+
+    @Test(expected=MathIllegalArgumentException.class)
+    public void testTooLargeIndex() {
+        doTestTooLargeIndex(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestTooLargeIndex(final Field<T> field)
+        throws MathIllegalArgumentException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        T[] complete = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        equation.getMapper().extractEquationData(+1, complete);
+    }
+
+    private static class  Linear<T extends RealFieldElement<T>>
+        implements  FieldFirstOrderDifferentialEquations<T>, FieldSecondaryEquations<T> {
+
+        private final Field<T> field;
+        private final int dimension;
+        private final int start;
+
+        private Linear(final Field<T> field, final int dimension, final int start) {
+            this.field     = field;
+            this.dimension = dimension;
+            this.start     = start;
+        }
+
+        public int getDimension() {
+            return dimension;
+        }
+
+        public void init(final T t0, final T[] y0, final T finalTime) {
+            Assert.assertEquals(dimension, y0.length);
+            Assert.assertEquals(10.0,  t0.getReal(), 1.0e-15);
+            Assert.assertEquals(100.0, finalTime.getReal(), 1.0e-15);
+            for (int i = 0; i < y0.length; ++i) {
+                Assert.assertEquals(i, y0[i].getReal(), 1.0e-15);
+            }
+        }
+
+        public T[] computeDerivatives(final T t, final T[] y) {
+            final T[] yDot = MathArrays.buildArray(field, dimension);
+            for (int i = 0; i < dimension; ++i) {
+                yDot[i] = field.getZero().add(i);
+            }
+            return yDot;
+        }
+
+        public void init(final T t0, final T[] primary0, final T[] secondary0, final T finalTime) {
+            Assert.assertEquals(dimension, secondary0.length);
+            Assert.assertEquals(10.0,  t0.getReal(), 1.0e-15);
+            Assert.assertEquals(100.0, finalTime.getReal(), 1.0e-15);
+            for (int i = 0; i < primary0.length; ++i) {
+                Assert.assertEquals(i, primary0[i].getReal(), 1.0e-15);
+            }
+            for (int i = 0; i < secondary0.length; ++i) {
+                Assert.assertEquals(start + i, secondary0[i].getReal(), 1.0e-15);
+            }
+        }
+
+        public T[] computeDerivatives(final T t, final T[] primary, final T[] primaryDot, final T[] secondary) {
+            final T[] secondaryDot = MathArrays.buildArray(field, dimension);
+            for (int i = 0; i < dimension; ++i) {
+                secondaryDot[i] = field.getZero().subtract(i);
+            }
+            return secondaryDot;
+        }
+
+    }
+
+}


[19/50] [abbrv] [math] Prevent NullPointerException in tests.

Posted by lu...@apache.org.
Prevent NullPointerException in tests.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/d6a8ed57
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/d6a8ed57
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/d6a8ed57

Branch: refs/heads/master
Commit: d6a8ed57b8e1fdeaa3b6bb4360b6de0d66dc6450
Parents: a2718fc
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:31 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:31 2016 +0100

----------------------------------------------------------------------
 ...ractRungeKuttaFieldStepInterpolatorTest.java | 32 +++++++++++++++++---
 1 file changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/d6a8ed57/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index 6dfdeab..64e91a2 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -22,7 +22,9 @@ import java.lang.reflect.InvocationTargetException;
 
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.AbstractIntegrator;
 import org.apache.commons.math4.ode.EquationsMapper;
+import org.apache.commons.math4.ode.ExpandableStatefulODE;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
 import org.apache.commons.math4.ode.FieldExpandableODE;
 import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
@@ -70,7 +72,7 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
         RungeKuttaFieldStepInterpolator<T> interpolator = setUpInterpolator(field,
                                                                             new SinCos<>(field),
-                                                                            0.0, new double[] { 0.0, 1.0 }, 0.125);
+                                                                            0.0, new double[] { 0.0, 1.0 }, 0.0125);
 
         int n = 100;
         double maxErrorSin = 0;
@@ -95,9 +97,10 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                                                                                      double epsilonSin, double epsilonCos,
                                                                                      double epsilonSinDot, double epsilonCosDot) {
 
+        FieldFirstOrderDifferentialEquations<T> eqn = new SinCos<>(field);
         RungeKuttaFieldStepInterpolator<T> fieldInterpolator =
-                        setUpInterpolator(field, new SinCos<>(field), 0.0, new double[] { 0.0, 1.0 }, 0.125);
-        RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator);
+                        setUpInterpolator(field, eqn, 0.0, new double[] { 0.0, 1.0 }, 0.125);
+        RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator, eqn);
 
         int n = 100;
         double maxErrorSin    = 0;
@@ -185,7 +188,8 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
     }
 
     private <T extends RealFieldElement<T>>
-    RungeKuttaStepInterpolator convertInterpolator(final RungeKuttaFieldStepInterpolator<T> fieldInterpolator) {
+    RungeKuttaStepInterpolator convertInterpolator(final RungeKuttaFieldStepInterpolator<T> fieldInterpolator,
+                                                   final FieldFirstOrderDifferentialEquations<T> eqn) {
 
         RungeKuttaStepInterpolator regularInterpolator = null;
         try {
@@ -225,7 +229,25 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
                 secondaryMappers[i] = new EquationsMapper(start[i + 1], start[i + 2]);
             }
 
-            regularInterpolator.reinitialize(null, y, yDotArray,
+            AbstractIntegrator dummyIntegrator = new AbstractIntegrator("dummy") {
+                @Override
+                public void integrate(ExpandableStatefulODE equations, double t) {
+                    Assert.fail("this method should not be called");
+                }
+                @Override
+                public void computeDerivatives(final double t, final double[] y, final double[] yDot) {
+                    T fieldT = fieldInterpolator.getField().getZero().add(t);
+                    T[] fieldY = MathArrays.buildArray(fieldInterpolator.getField(), y.length);
+                    for (int i = 0; i < y.length; ++i) {
+                        fieldY[i] = fieldInterpolator.getField().getZero().add(y[i]);
+                    }
+                    T[] fieldYDot = eqn.computeDerivatives(fieldT, fieldY);
+                    for (int i = 0; i < yDot.length; ++i) {
+                        yDot[i] = fieldYDot[i].getReal();
+                    }
+                }
+            };
+            regularInterpolator.reinitialize(dummyIntegrator, y, yDotArray,
                                              fieldInterpolator.isForward(),
                                              primaryMapper, secondaryMappers);
 


[11/50] [abbrv] [math] Added test for Luther step interpolator.

Posted by lu...@apache.org.
Added test for Luther step interpolator.

BEWARE! This test does not work yet. It confirms there is a problem
in the step interpolator for Luther integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/b5c1893a
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/b5c1893a
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/b5c1893a

Branch: refs/heads/master
Commit: b5c1893a7069b3771855a58c6feb8a32cc2d3cd8
Parents: 2f8b15a
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:19 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:19 2016 +0100

----------------------------------------------------------------------
 .../LutherFieldStepInterpolatorTest.java        | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/b5c1893a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
new file mode 100644
index 0000000..de16bb9
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class LutherFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
+        return new LutherFieldStepInterpolator<T>(field, forward, mapper);
+    }
+
+    @Test
+    public void interpolationAtBounds() {
+        doInterpolationAtBounds(Decimal64Field.getInstance(), 1.0e-15);
+    }
+
+    @Test
+    public void interpolationInside() {
+        doInterpolationInside(Decimal64Field.getInstance(), 3.3e-14, 7.9e-13);
+    }
+
+}


[15/50] [abbrv] [math] Fixed exception handling for too many iterations in event search.

Posted by lu...@apache.org.
Fixed exception handling for too many iterations in event search.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/084ab518
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/084ab518
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/084ab518

Branch: refs/heads/master
Commit: 084ab518eecbac7b9b9a711d21021bd7df13dda8
Parents: 9e23079
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:24 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:24 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/events/FieldEventState.java       | 174 ++++++++-----------
 1 file changed, 70 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/084ab518/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java b/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java
index ffd0d7b..49b25bd 100644
--- a/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java
+++ b/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java
@@ -191,100 +191,91 @@ public class FieldEventState<T extends RealFieldElement<T>> {
     public boolean evaluateStep(final FieldStepInterpolator<T> interpolator)
         throws MaxCountExceededException, NoBracketingException {
 
-        try {
-            forward = interpolator.isForward();
-            final FieldODEStateAndDerivative<T> s1 = interpolator.getCurrentState();
-            final T t1 = s1.getTime();
-            final T dt = t1.subtract(t0);
-            if (dt.abs().subtract(convergence).getReal() < 0) {
-                // we cannot do anything on such a small step, don't trigger any events
-                return false;
+        forward = interpolator.isForward();
+        final FieldODEStateAndDerivative<T> s1 = interpolator.getCurrentState();
+        final T t1 = s1.getTime();
+        final T dt = t1.subtract(t0);
+        if (dt.abs().subtract(convergence).getReal() < 0) {
+            // we cannot do anything on such a small step, don't trigger any events
+            return false;
+        }
+        final int n = FastMath.max(1, (int) FastMath.ceil(FastMath.abs(dt.getReal()) / maxCheckInterval));
+        final T   h = dt.divide(n);
+
+        final RealFieldUnivariateFunction<T> f = new RealFieldUnivariateFunction<T>() {
+            /** {@inheritDoc} */
+            public T value(final T t) {
+                return handler.g(interpolator.getInterpolatedState(t));
             }
-            final int n = FastMath.max(1, (int) FastMath.ceil(FastMath.abs(dt.getReal()) / maxCheckInterval));
-            final T   h = dt.divide(n);
-
-            final RealFieldUnivariateFunction<T> f = new RealFieldUnivariateFunction<T>() {
-                /** {@inheritDoc} */
-                public T value(final T t) throws LocalMaxCountExceededException {
-                    try {
-                        return handler.g(interpolator.getInterpolatedState(t));
-                    } catch (MaxCountExceededException mcee) {
-                        throw new LocalMaxCountExceededException(mcee);
-                    }
-                }
-            };
-
-            T ta = t0;
-            T ga = g0;
-            for (int i = 0; i < n; ++i) {
-
-                // evaluate handler value at the end of the substep
-                final T tb = (i == n - 1) ? t1 : t0.add(h.multiply(i + 1));
-                final T gb = handler.g(interpolator.getInterpolatedState(tb));
-
-                // check events occurrence
-                if (g0Positive ^ (gb.getReal() >= 0)) {
-                    // there is a sign change: an event is expected during this step
-
-                    // variation direction, with respect to the integration direction
-                    increasing = gb.subtract(ga).getReal() >= 0;
-
-                    // find the event time making sure we select a solution just at or past the exact root
-                    final T root = forward ?
-                                   solver.solve(maxIterationCount, f, ta, tb, AllowedSolution.RIGHT_SIDE) :
-                                   solver.solve(maxIterationCount, f, tb, ta, AllowedSolution.LEFT_SIDE);
-
-                    if (previousEventTime != null &&
-                        root.subtract(ta).abs().subtract(convergence).getReal() <= 0 &&
-                        root.subtract(previousEventTime).abs().subtract(convergence).getReal() <= 0) {
-                        // we have either found nothing or found (again ?) a past event,
-                        // retry the substep excluding this value, and taking care to have the
-                        // required sign in case the g function is noisy around its zero and
-                        // crosses the axis several times
-                        do {
-                            ta = forward ? ta.add(convergence) : ta.subtract(convergence);
-                            ga = f.value(ta);
-                        } while ((g0Positive ^ (ga.getReal() >= 0)) && (forward ^ (ta.subtract(tb).getReal() >= 0)));
-
-                        if (forward ^ (ta.subtract(tb).getReal() >= 0)) {
-                            // we were able to skip this spurious root
-                            --i;
-                        } else {
-                            // we can't avoid this root before the end of the step,
-                            // we have to handle it despite it is close to the former one
-                            // maybe we have two very close roots
-                            pendingEventTime = root;
-                            pendingEvent     = true;
-                            return true;
-                        }
-                    } else if (previousEventTime == null ||
-                               previousEventTime.subtract(root).abs().subtract(convergence).getReal() > 0) {
+        };
+
+        T ta = t0;
+        T ga = g0;
+        for (int i = 0; i < n; ++i) {
+
+            // evaluate handler value at the end of the substep
+            final T tb = (i == n - 1) ? t1 : t0.add(h.multiply(i + 1));
+            final T gb = handler.g(interpolator.getInterpolatedState(tb));
+
+            // check events occurrence
+            if (g0Positive ^ (gb.getReal() >= 0)) {
+                // there is a sign change: an event is expected during this step
+
+                // variation direction, with respect to the integration direction
+                increasing = gb.subtract(ga).getReal() >= 0;
+
+                // find the event time making sure we select a solution just at or past the exact root
+                final T root = forward ?
+                               solver.solve(maxIterationCount, f, ta, tb, AllowedSolution.RIGHT_SIDE) :
+                               solver.solve(maxIterationCount, f, tb, ta, AllowedSolution.LEFT_SIDE);
+
+                if (previousEventTime != null &&
+                    root.subtract(ta).abs().subtract(convergence).getReal() <= 0 &&
+                    root.subtract(previousEventTime).abs().subtract(convergence).getReal() <= 0) {
+                    // we have either found nothing or found (again ?) a past event,
+                    // retry the substep excluding this value, and taking care to have the
+                    // required sign in case the g function is noisy around its zero and
+                    // crosses the axis several times
+                    do {
+                        ta = forward ? ta.add(convergence) : ta.subtract(convergence);
+                        ga = f.value(ta);
+                    } while ((g0Positive ^ (ga.getReal() >= 0)) && (forward ^ (ta.subtract(tb).getReal() >= 0)));
+
+                    if (forward ^ (ta.subtract(tb).getReal() >= 0)) {
+                        // we were able to skip this spurious root
+                        --i;
+                    } else {
+                        // we can't avoid this root before the end of the step,
+                        // we have to handle it despite it is close to the former one
+                        // maybe we have two very close roots
                         pendingEventTime = root;
                         pendingEvent     = true;
                         return true;
-                    } else {
-                        // no sign change: there is no event for now
-                        ta = tb;
-                        ga = gb;
                     }
-
+                } else if (previousEventTime == null ||
+                           previousEventTime.subtract(root).abs().subtract(convergence).getReal() > 0) {
+                    pendingEventTime = root;
+                    pendingEvent     = true;
+                    return true;
                 } else {
                     // no sign change: there is no event for now
                     ta = tb;
                     ga = gb;
                 }
 
+            } else {
+                // no sign change: there is no event for now
+                ta = tb;
+                ga = gb;
             }
 
-            // no event during the whole step
-            pendingEvent     = false;
-            pendingEventTime = null;
-            return false;
-
-        } catch (LocalMaxCountExceededException lmcee) {
-            throw lmcee.getException();
         }
 
+        // no event during the whole step
+        pendingEvent     = false;
+        pendingEventTime = null;
+        return false;
+
     }
 
     /** Get the occurrence time of the event triggered in the current step.
@@ -350,29 +341,4 @@ public class FieldEventState<T extends RealFieldElement<T>> {
 
     }
 
-    /** Local wrapper to propagate exceptions. */
-    private static class LocalMaxCountExceededException extends RuntimeException {
-
-        /** Serializable UID. */
-        private static final long serialVersionUID = 20151113L;
-
-        /** Wrapped exception. */
-        private final MaxCountExceededException wrapped;
-
-        /** Simple constructor.
-         * @param exception exception to wrap
-         */
-        LocalMaxCountExceededException(final MaxCountExceededException exception) {
-            wrapped = exception;
-        }
-
-        /** Get the wrapped exception.
-         * @return wrapped exception
-         */
-        public MaxCountExceededException getException() {
-            return wrapped;
-        }
-
-    }
-
 }


[46/50] [abbrv] [math] updated copyright year

Posted by lu...@apache.org.
updated copyright year


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/8361fd7f
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/8361fd7f
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/8361fd7f

Branch: refs/heads/master
Commit: 8361fd7f9c9af12136185a45d4d104ef0334db91
Parents: 82cf277
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:20:00 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:20:00 2016 +0100

----------------------------------------------------------------------
 NOTICE.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/8361fd7f/NOTICE.txt
----------------------------------------------------------------------
diff --git a/NOTICE.txt b/NOTICE.txt
index ce791e4..be158fe 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
 Apache Commons Math
-Copyright 2001-2015 The Apache Software Foundation
+Copyright 2001-2016 The Apache Software Foundation
 
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).


[42/50] [abbrv] [math] Base classes for field-based multistep integrators.

Posted by lu...@apache.org.
Base classes for field-based multistep integrators.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/dd9dc945
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/dd9dc945
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/dd9dc945

Branch: refs/heads/master
Commit: dd9dc9457722787992347ae54d9a8fe8d4b91d2e
Parents: 2a49849
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:18:26 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:18:26 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/MultistepFieldIntegrator.java     | 427 +++++++++++++++++++
 .../ode/nonstiff/AdamsFieldIntegrator.java      | 146 +++++++
 .../nonstiff/AdamsFieldStepInterpolator.java    | 193 +++++++++
 .../AdamsNordsieckFieldTransformer.java         | 362 ++++++++++++++++
 .../AbstractAdamsFieldIntegratorTest.java       | 261 ++++++++++++
 5 files changed, 1389 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/dd9dc945/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
new file mode 100644
index 0000000..feec974
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
@@ -0,0 +1,427 @@
+/*
+ * 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.apache.commons.math4.ode;
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+import org.apache.commons.math4.exception.MathIllegalStateException;
+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.exception.util.LocalizedFormats;
+import org.apache.commons.math4.linear.Array2DRowFieldMatrix;
+import org.apache.commons.math4.ode.nonstiff.AdaptiveStepsizeFieldIntegrator;
+import org.apache.commons.math4.ode.nonstiff.DormandPrince853FieldIntegrator;
+import org.apache.commons.math4.ode.sampling.FieldStepHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
+import org.apache.commons.math4.util.MathUtils;
+
+/**
+ * This class is the base class for multistep integrators for Ordinary
+ * Differential Equations.
+ * <p>We define scaled derivatives s<sub>i</sub>(n) at step n as:
+ * <pre>
+ * s<sub>1</sub>(n) = h y'<sub>n</sub> for first derivative
+ * s<sub>2</sub>(n) = h<sup>2</sup>/2 y''<sub>n</sub> for second derivative
+ * s<sub>3</sub>(n) = h<sup>3</sup>/6 y'''<sub>n</sub> for third derivative
+ * ...
+ * s<sub>k</sub>(n) = h<sup>k</sup>/k! y<sup>(k)</sup><sub>n</sub> for k<sup>th</sup> derivative
+ * </pre></p>
+ * <p>Rather than storing several previous steps separately, this implementation uses
+ * the Nordsieck vector with higher degrees scaled derivatives all taken at the same
+ * step (y<sub>n</sub>, s<sub>1</sub>(n) and r<sub>n</sub>) where r<sub>n</sub> is defined as:
+ * <pre>
+ * r<sub>n</sub> = [ s<sub>2</sub>(n), s<sub>3</sub>(n) ... s<sub>k</sub>(n) ]<sup>T</sup>
+ * </pre>
+ * (we omit the k index in the notation for clarity)</p>
+ * <p>
+ * Multistep integrators with Nordsieck representation are highly sensitive to
+ * large step changes because when the step is multiplied by factor a, the
+ * k<sup>th</sup> component of the Nordsieck vector is multiplied by a<sup>k</sup>
+ * and the last components are the least accurate ones. The default max growth
+ * factor is therefore set to a quite low value: 2<sup>1/order</sup>.
+ * </p>
+ *
+ * @see org.apache.commons.math4.ode.nonstiff.AdamsBashforthFieldIntegrator
+ * @see org.apache.commons.math4.ode.nonstiff.AdamsMoultonFieldIntegrator
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+public abstract class MultistepFieldIntegrator<T extends RealFieldElement<T>>
+    extends AdaptiveStepsizeFieldIntegrator<T> {
+
+    /** First scaled derivative (h y'). */
+    protected T[] scaled;
+
+    /** Nordsieck matrix of the higher scaled derivatives.
+     * <p>(h<sup>2</sup>/2 y'', h<sup>3</sup>/6 y''' ..., h<sup>k</sup>/k! y<sup>(k)</sup>)</p>
+     */
+    protected Array2DRowFieldMatrix<T> nordsieck;
+
+    /** Starter integrator. */
+    private FirstOrderFieldIntegrator<T> starter;
+
+    /** Number of steps of the multistep method (excluding the one being computed). */
+    private final int nSteps;
+
+    /** Stepsize control exponent. */
+    private double exp;
+
+    /** Safety factor for stepsize control. */
+    private double safety;
+
+    /** Minimal reduction factor for stepsize control. */
+    private double minReduction;
+
+    /** Maximal growth factor for stepsize control. */
+    private double maxGrowth;
+
+    /**
+     * Build a multistep integrator with the given stepsize bounds.
+     * <p>The default starter integrator is set to the {@link
+     * DormandPrince853FieldIntegrator Dormand-Prince 8(5,3)} integrator with
+     * some defaults settings.</p>
+     * <p>
+     * The default max growth factor is set to a quite low value: 2<sup>1/order</sup>.
+     * </p>
+     * @param field field to which the time and state vector elements belong
+     * @param name name of the method
+     * @param nSteps number of steps of the multistep method
+     * (excluding the one being computed)
+     * @param order order of the method
+     * @param minStep minimal step (must be positive even for backward
+     * integration), the last step can be smaller than this
+     * @param maxStep maximal step (must be positive even for backward
+     * integration)
+     * @param scalAbsoluteTolerance allowed absolute error
+     * @param scalRelativeTolerance allowed relative error
+     * @exception NumberIsTooSmallException if number of steps is smaller than 2
+     */
+    protected MultistepFieldIntegrator(final Field<T> field, final String name,
+                                       final int nSteps, final int order,
+                                       final double minStep, final double maxStep,
+                                       final double scalAbsoluteTolerance,
+                                       final double scalRelativeTolerance)
+        throws NumberIsTooSmallException {
+
+        super(field, name, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
+
+        if (nSteps < 2) {
+            throw new NumberIsTooSmallException(
+                  LocalizedFormats.INTEGRATION_METHOD_NEEDS_AT_LEAST_TWO_PREVIOUS_POINTS,
+                  nSteps, 2, true);
+        }
+
+        starter = new DormandPrince853FieldIntegrator<T>(field, minStep, maxStep,
+                                                         scalAbsoluteTolerance,
+                                                         scalRelativeTolerance);
+        this.nSteps = nSteps;
+
+        exp = -1.0 / order;
+
+        // set the default values of the algorithm control parameters
+        setSafety(0.9);
+        setMinReduction(0.2);
+        setMaxGrowth(FastMath.pow(2.0, -exp));
+
+    }
+
+    /**
+     * Build a multistep integrator with the given stepsize bounds.
+     * <p>The default starter integrator is set to the {@link
+     * DormandPrince853FieldIntegrator Dormand-Prince 8(5,3)} integrator with
+     * some defaults settings.</p>
+     * <p>
+     * The default max growth factor is set to a quite low value: 2<sup>1/order</sup>.
+     * </p>
+     * @param field field to which the time and state vector elements belong
+     * @param name name of the method
+     * @param nSteps number of steps of the multistep method
+     * (excluding the one being computed)
+     * @param order order of the method
+     * @param minStep minimal step (must be positive even for backward
+     * integration), the last step can be smaller than this
+     * @param maxStep maximal step (must be positive even for backward
+     * integration)
+     * @param vecAbsoluteTolerance allowed absolute error
+     * @param vecRelativeTolerance allowed relative error
+     */
+    protected MultistepFieldIntegrator(final Field<T> field, final String name, final int nSteps,
+                                       final int order,
+                                       final double minStep, final double maxStep,
+                                       final double[] vecAbsoluteTolerance,
+                                       final double[] vecRelativeTolerance) {
+        super(field, name, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
+        starter = new DormandPrince853FieldIntegrator<T>(field, minStep, maxStep,
+                                                         vecAbsoluteTolerance,
+                                                         vecRelativeTolerance);
+        this.nSteps = nSteps;
+
+        exp = -1.0 / order;
+
+        // set the default values of the algorithm control parameters
+        setSafety(0.9);
+        setMinReduction(0.2);
+        setMaxGrowth(FastMath.pow(2.0, -exp));
+
+    }
+
+    /**
+     * Get the starter integrator.
+     * @return starter integrator
+     */
+    public FirstOrderFieldIntegrator<T> getStarterIntegrator() {
+        return starter;
+    }
+
+    /**
+     * Set the starter integrator.
+     * <p>The various step and event handlers for this starter integrator
+     * will be managed automatically by the multi-step integrator. Any
+     * user configuration for these elements will be cleared before use.</p>
+     * @param starterIntegrator starter integrator
+     */
+    public void setStarterIntegrator(FirstOrderFieldIntegrator<T> starterIntegrator) {
+        this.starter = starterIntegrator;
+    }
+
+    /** Start the integration.
+     * <p>This method computes one step using the underlying starter integrator,
+     * and initializes the Nordsieck vector at step start. The starter integrator
+     * purpose is only to establish initial conditions, it does not really change
+     * time by itself. The top level multistep integrator remains in charge of
+     * handling time propagation and events handling as it will starts its own
+     * computation right from the beginning. In a sense, the starter integrator
+     * can be seen as a dummy one and so it will never trigger any user event nor
+     * call any user step handler.</p>
+     * @param equations complete set of differential equations to integrate
+     * @param initialState initial state (time, primary and secondary state vectors)
+     * @param t target time for the integration
+     * (can be set to a value smaller than <code>t0</code> for backward integration)
+     * @exception DimensionMismatchException if arrays dimension do not match equations settings
+     * @exception NumberIsTooSmallException if integration step is too small
+     * @exception MaxCountExceededException if the number of functions evaluations is exceeded
+     * @exception NoBracketingException if the location of an event cannot be bracketed
+     */
+    protected void start(final FieldExpandableODE<T> equations, final FieldODEState<T> initialState, final T t)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+
+        // make sure NO user event nor user step handler is triggered,
+        // this is the task of the top level integrator, not the task
+        // of the starter integrator
+        starter.clearEventHandlers();
+        starter.clearStepHandlers();
+
+        // set up one specific step handler to extract initial Nordsieck vector
+        starter.addStepHandler(new FieldNordsieckInitializer(equations.getMapper(), (nSteps + 3) / 2));
+
+        // start integration, expecting a InitializationCompletedMarkerException
+        try {
+
+            starter.integrate(equations, initialState, t);
+
+            // we should not reach this step
+            throw new MathIllegalStateException(LocalizedFormats.MULTISTEP_STARTER_STOPPED_EARLY);
+
+        } catch (InitializationCompletedMarkerException icme) { // NOPMD
+            // this is the expected nominal interruption of the start integrator
+
+            // count the evaluations used by the starter
+            getEvaluationsCounter().increment(starter.getEvaluations());
+
+        }
+
+        // remove the specific step handler
+        starter.clearStepHandlers();
+
+    }
+
+    /** Initialize the high order scaled derivatives at step start.
+     * @param h step size to use for scaling
+     * @param t first steps times
+     * @param y first steps states
+     * @param yDot first steps derivatives
+     * @return Nordieck vector at first step (h<sup>2</sup>/2 y''<sub>n</sub>,
+     * h<sup>3</sup>/6 y'''<sub>n</sub> ... h<sup>k</sup>/k! y<sup>(k)</sup><sub>n</sub>)
+     */
+    protected abstract Array2DRowFieldMatrix<T> initializeHighOrderDerivatives(final T h, final T[] t,
+                                                                               final T[][] y,
+                                                                               final T[][] yDot);
+
+    /** Get the minimal reduction factor for stepsize control.
+     * @return minimal reduction factor
+     */
+    public double getMinReduction() {
+        return minReduction;
+    }
+
+    /** Set the minimal reduction factor for stepsize control.
+     * @param minReduction minimal reduction factor
+     */
+    public void setMinReduction(final double minReduction) {
+        this.minReduction = minReduction;
+    }
+
+    /** Get the maximal growth factor for stepsize control.
+     * @return maximal growth factor
+     */
+    public double getMaxGrowth() {
+        return maxGrowth;
+    }
+
+    /** Set the maximal growth factor for stepsize control.
+     * @param maxGrowth maximal growth factor
+     */
+    public void setMaxGrowth(final double maxGrowth) {
+        this.maxGrowth = maxGrowth;
+    }
+
+    /** Get the safety factor for stepsize control.
+     * @return safety factor
+     */
+    public double getSafety() {
+      return safety;
+    }
+
+    /** Set the safety factor for stepsize control.
+     * @param safety safety factor
+     */
+    public void setSafety(final double safety) {
+      this.safety = safety;
+    }
+
+    /** Get the number of steps of the multistep method (excluding the one being computed).
+     * @return number of steps of the multistep method (excluding the one being computed)
+     */
+    public int getNSteps() {
+      return nSteps;
+    }
+
+    /** Compute step grow/shrink factor according to normalized error.
+     * @param error normalized error of the current step
+     * @return grow/shrink factor for next step
+     */
+    protected T computeStepGrowShrinkFactor(final T error) {
+        return MathUtils.min(error.getField().getZero().add(maxGrowth),
+                             MathUtils.max(error.getField().getZero().add(minReduction),
+                                           error.pow(exp).multiply(safety)));
+    }
+
+    /** Specialized step handler storing the first step.
+     */
+    private class FieldNordsieckInitializer implements FieldStepHandler<T> {
+
+        /** Equation mapper. */
+        private final FieldEquationsMapper<T> mapper;
+
+        /** Steps counter. */
+        private int count;
+
+        /** Saved start. */
+        private FieldODEStateAndDerivative<T> savedStart;
+
+        /** First steps times. */
+        private final T[] t;
+
+        /** First steps states. */
+        private final T[][] y;
+
+        /** First steps derivatives. */
+        private final T[][] yDot;
+
+        /** Simple constructor.
+         * @param mapper equation mapper
+         * @param nbStartPoints number of start points (including the initial point)
+         */
+        FieldNordsieckInitializer(final FieldEquationsMapper<T> mapper, final int nbStartPoints) {
+            this.mapper = mapper;
+            this.count  = 0;
+            this.t      = MathArrays.buildArray(getField(), nbStartPoints);
+            this.y      = MathArrays.buildArray(getField(), nbStartPoints, -1);
+            this.yDot   = MathArrays.buildArray(getField(), nbStartPoints, -1);
+        }
+
+        /** {@inheritDoc} */
+        public void handleStep(FieldStepInterpolator<T> interpolator, boolean isLast)
+            throws MaxCountExceededException {
+
+
+            if (count == 0) {
+                // first step, we need to store also the point at the beginning of the step
+                final FieldODEStateAndDerivative<T> prev = interpolator.getPreviousState();
+                savedStart  = prev;
+                t[count]    = prev.getTime();
+                y[count]    = mapper.mapState(prev);
+                yDot[count] = mapper.mapDerivative(prev);
+            }
+
+            // store the point at the end of the step
+            ++count;
+            final FieldODEStateAndDerivative<T> curr = interpolator.getCurrentState();
+            t[count]    = curr.getTime();
+            y[count]    = mapper.mapState(curr);
+            yDot[count] = mapper.mapDerivative(curr);
+
+            if (count == t.length - 1) {
+
+                // this was the last point we needed, we can compute the derivatives
+                setStepSize(t[t.length - 1].subtract(t[0]).divide(t.length - 1));
+
+                // first scaled derivative
+                scaled = MathArrays.buildArray(getField(), yDot[0].length);
+                for (int j = 0; j < scaled.length; ++j) {
+                    scaled[j] = yDot[0][j].multiply(getStepSize());
+                }
+
+                // higher order derivatives
+                nordsieck = initializeHighOrderDerivatives(getStepSize(), t, y, yDot);
+
+                // stop the integrator now that all needed steps have been handled
+                setStepStart(savedStart);
+                throw new InitializationCompletedMarkerException();
+
+            }
+
+        }
+
+        /** {@inheritDoc} */
+        public void init(final FieldODEStateAndDerivative<T> initialState, T finalTime) {
+            // nothing to do
+        }
+
+    }
+
+    /** Marker exception used ONLY to stop the starter integrator after first step. */
+    private static class InitializationCompletedMarkerException
+        extends RuntimeException {
+
+        /** Serializable version identifier. */
+        private static final long serialVersionUID = -1914085471038046418L;
+
+        /** Simple constructor. */
+        InitializationCompletedMarkerException() {
+            super((Throwable) null);
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/dd9dc945/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java
new file mode 100644
index 0000000..9039ca1
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java
@@ -0,0 +1,146 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+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.linear.Array2DRowFieldMatrix;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FieldODEState;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.MultistepFieldIntegrator;
+
+
+/** Base class for {@link AdamsBashforthFieldIntegrator Adams-Bashforth} and
+ * {@link AdamsMoultonFieldIntegrator Adams-Moulton} integrators.
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+public abstract class AdamsFieldIntegrator<T extends RealFieldElement<T>> extends MultistepFieldIntegrator<T> {
+
+    /** Transformer. */
+    private final AdamsNordsieckFieldTransformer<T> transformer;
+
+    /**
+     * Build an Adams integrator with the given order and step control parameters.
+     * @param field field to which the time and state vector elements belong
+     * @param name name of the method
+     * @param nSteps number of steps of the method excluding the one being computed
+     * @param order order of the method
+     * @param minStep minimal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param maxStep maximal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param scalAbsoluteTolerance allowed absolute error
+     * @param scalRelativeTolerance allowed relative error
+     * @exception NumberIsTooSmallException if order is 1 or less
+     */
+    public AdamsFieldIntegrator(final Field<T> field, final String name,
+                                final int nSteps, final int order,
+                                final double minStep, final double maxStep,
+                                final double scalAbsoluteTolerance,
+                                final double scalRelativeTolerance)
+        throws NumberIsTooSmallException {
+        super(field, name, nSteps, order, minStep, maxStep,
+              scalAbsoluteTolerance, scalRelativeTolerance);
+        transformer = AdamsNordsieckFieldTransformer.getInstance(field, nSteps);
+    }
+
+    /**
+     * Build an Adams integrator with the given order and step control parameters.
+     * @param field field to which the time and state vector elements belong
+     * @param name name of the method
+     * @param nSteps number of steps of the method excluding the one being computed
+     * @param order order of the method
+     * @param minStep minimal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param maxStep maximal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param vecAbsoluteTolerance allowed absolute error
+     * @param vecRelativeTolerance allowed relative error
+     * @exception IllegalArgumentException if order is 1 or less
+     */
+    public AdamsFieldIntegrator(final Field<T> field, final String name,
+                                final int nSteps, final int order,
+                                final double minStep, final double maxStep,
+                                final double[] vecAbsoluteTolerance,
+                                final double[] vecRelativeTolerance)
+        throws IllegalArgumentException {
+        super(field, name, nSteps, order, minStep, maxStep,
+              vecAbsoluteTolerance, vecRelativeTolerance);
+        transformer = AdamsNordsieckFieldTransformer.getInstance(field, nSteps);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public abstract FieldODEStateAndDerivative<T> integrate(final FieldExpandableODE<T> equations,
+                                                            final FieldODEState<T> initialState,
+                                                            final T finalTime)
+        throws NumberIsTooSmallException, DimensionMismatchException,
+               MaxCountExceededException, NoBracketingException;
+
+    /** {@inheritDoc} */
+    @Override
+    protected Array2DRowFieldMatrix<T> initializeHighOrderDerivatives(final T h, final T[] t,
+                                                                      final T[][] y,
+                                                                      final T[][] yDot) {
+        return transformer.initializeHighOrderDerivatives(h, t, y, yDot);
+    }
+
+    /** Update the high order scaled derivatives for Adams integrators (phase 1).
+     * <p>The complete update of high order derivatives has a form similar to:
+     * <pre>
+     * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
+     * </pre>
+     * this method computes the P<sup>-1</sup> A P r<sub>n</sub> part.</p>
+     * @param highOrder high order scaled derivatives
+     * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
+     * @return updated high order derivatives
+     * @see #updateHighOrderDerivativesPhase2(double[], double[], Array2DRowFieldMatrix)
+     */
+    public Array2DRowFieldMatrix<T> updateHighOrderDerivativesPhase1(final Array2DRowFieldMatrix<T> highOrder) {
+        return transformer.updateHighOrderDerivativesPhase1(highOrder);
+    }
+
+    /** Update the high order scaled derivatives Adams integrators (phase 2).
+     * <p>The complete update of high order derivatives has a form similar to:
+     * <pre>
+     * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
+     * </pre>
+     * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
+     * <p>Phase 1 of the update must already have been performed.</p>
+     * @param start first order scaled derivatives at step start
+     * @param end first order scaled derivatives at step end
+     * @param highOrder high order scaled derivatives, will be modified
+     * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
+     * @see #updateHighOrderDerivativesPhase1(Array2DRowFieldMatrix)
+     */
+    public void updateHighOrderDerivativesPhase2(final T[] start, final T[] end,
+                                                 final Array2DRowFieldMatrix<T> highOrder) {
+        transformer.updateHighOrderDerivativesPhase2(start, end, highOrder);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/dd9dc945/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java
new file mode 100644
index 0000000..78c3c8e
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldStepInterpolator.java
@@ -0,0 +1,193 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+import java.util.Arrays;
+
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.linear.Array2DRowFieldMatrix;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.sampling.AbstractFieldStepInterpolator;
+import org.apache.commons.math4.util.MathArrays;
+
+/**
+ * This class implements an interpolator for Adams integrators using Nordsieck representation.
+ *
+ * <p>This interpolator computes dense output around the current point.
+ * The interpolation equation is based on Taylor series formulas.
+ *
+ * @see AdamsBashforthFieldIntegrator
+ * @see AdamsMoultonFieldIntegrator
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+
+class AdamsFieldStepInterpolator<T extends RealFieldElement<T>> extends AbstractFieldStepInterpolator<T> {
+
+    /** Step size used in the first scaled derivative and Nordsieck vector. */
+    private T scalingH;
+
+    /** First scaled derivative. */
+    private final T[] scaled;
+
+    /** Nordsieck vector. */
+    private final Array2DRowFieldMatrix<T> nordsieck;
+
+    /** Simple constructor.
+     * @param stepSize step size used in the scaled and Nordsieck arrays
+     * @param referenceState reference state from which Taylor expansion are estimated
+     * @param scaled first scaled derivative
+     * @param nordsieck Nordsieck vector
+     * @param isForward integration direction indicator
+     * @param equationsMapper mapper for ODE equations primary and secondary components
+     */
+    AdamsFieldStepInterpolator(final T stepSize, final FieldODEStateAndDerivative<T> referenceState,
+                               final T[] scaled, final Array2DRowFieldMatrix<T> nordsieck,
+                               final boolean isForward, final FieldEquationsMapper<T> equationsMapper) {
+        this(stepSize, scaled, nordsieck, isForward,
+             referenceState, taylor(referenceState, referenceState.getTime().add(stepSize), stepSize, scaled, nordsieck),
+             equationsMapper);
+    }
+
+    /** Simple constructor.
+     * @param stepSize step size used in the scaled and Nordsieck arrays
+     * @param scaled first scaled derivative
+     * @param nordsieck Nordsieck vector
+     * @param isForward integration direction indicator
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param equationsMapper mapper for ODE equations primary and secondary components
+     */
+    private AdamsFieldStepInterpolator(final T stepSize, final T[] scaled,
+                                       final Array2DRowFieldMatrix<T> nordsieck,
+                                       final boolean isForward,
+                                       final FieldODEStateAndDerivative<T> globalPreviousState,
+                                       final FieldODEStateAndDerivative<T> globalCurrentState,
+                                       final FieldEquationsMapper<T> equationsMapper) {
+        this(stepSize, scaled, nordsieck,
+             isForward, globalPreviousState, globalCurrentState,
+             globalPreviousState, globalCurrentState, equationsMapper);
+    }
+
+    /** Simple constructor.
+     * @param stepSize step size used in the scaled and Nordsieck arrays
+     * @param scaled first scaled derivative
+     * @param nordsieck Nordsieck vector
+     * @param isForward integration direction indicator
+     * @param globalPreviousState start of the global step
+     * @param globalCurrentState end of the global step
+     * @param softPreviousState start of the restricted step
+     * @param softCurrentState end of the restricted step
+     * @param equationsMapper mapper for ODE equations primary and secondary components
+     */
+    private AdamsFieldStepInterpolator(final T stepSize, final T[] scaled,
+                                       final Array2DRowFieldMatrix<T> nordsieck,
+                                       final boolean isForward,
+                                       final FieldODEStateAndDerivative<T> globalPreviousState,
+                                       final FieldODEStateAndDerivative<T> globalCurrentState,
+                                       final FieldODEStateAndDerivative<T> softPreviousState,
+                                       final FieldODEStateAndDerivative<T> softCurrentState,
+                                       final FieldEquationsMapper<T> equationsMapper) {
+        super(isForward, globalPreviousState, globalCurrentState,
+              softPreviousState, softCurrentState, equationsMapper);
+        this.scalingH  = stepSize;
+        this.scaled    = scaled.clone();
+        this.nordsieck = new Array2DRowFieldMatrix<T>(nordsieck.getData(), false);
+    }
+
+    /** Create a new instance.
+     * @param newForward integration direction indicator
+     * @param newGlobalPreviousState start of the global step
+     * @param newGlobalCurrentState end of the global step
+     * @param newSoftPreviousState start of the restricted step
+     * @param newSoftCurrentState end of the restricted step
+     * @param newMapper equations mapper for the all equations
+     * @return a new instance
+     */
+    protected AdamsFieldStepInterpolator<T> create(boolean newForward,
+                                                   FieldODEStateAndDerivative<T> newGlobalPreviousState,
+                                                   FieldODEStateAndDerivative<T> newGlobalCurrentState,
+                                                   FieldODEStateAndDerivative<T> newSoftPreviousState,
+                                                   FieldODEStateAndDerivative<T> newSoftCurrentState,
+                                                   FieldEquationsMapper<T> newMapper) {
+        return new AdamsFieldStepInterpolator<T>(scalingH, scaled, nordsieck,
+                                                 newForward,
+                                                 newGlobalPreviousState, newGlobalCurrentState,
+                                                 newSoftPreviousState, newSoftCurrentState,
+                                                 newMapper);
+
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    protected FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(final FieldEquationsMapper<T> equationsMapper,
+                                                                                   final T time, final T theta,
+                                                                                   final T thetaH, final T oneMinusThetaH) {
+        return taylor(getPreviousState(), time, scalingH, scaled, nordsieck);
+    }
+
+    /** Estimate state by applying Taylor formula.
+     * @param referenceState reference state
+     * @param time time at which state must be estimated
+     * @param stepSize step size used in the scaled and Nordsieck arrays
+     * @param scaled first scaled derivative
+     * @param nordsieck Nordsieck vector
+     * @return estimated state
+     * @param <S> the type of the field elements
+     */
+    private static <S extends RealFieldElement<S>> FieldODEStateAndDerivative<S> taylor(final FieldODEStateAndDerivative<S> referenceState,
+                                                                                        final S time, final S stepSize,
+                                                                                        final S[] scaled,
+                                                                                        final Array2DRowFieldMatrix<S> nordsieck) {
+
+        final S x = time.subtract(referenceState.getTime());
+        final S normalizedAbscissa = x.divide(stepSize);
+
+        S[] stateVariation = MathArrays.buildArray(time.getField(), scaled.length);
+        Arrays.fill(stateVariation, time.getField().getZero());
+        S[] estimatedDerivatives = MathArrays.buildArray(time.getField(), scaled.length);
+        Arrays.fill(estimatedDerivatives, time.getField().getZero());
+
+        // apply Taylor formula from high order to low order,
+        // for the sake of numerical accuracy
+        final S[][] nData = nordsieck.getDataRef();
+        for (int i = nData.length - 1; i >= 0; --i) {
+            final int order = i + 2;
+            final S[] nDataI = nData[i];
+            final S power = normalizedAbscissa.pow(order);
+            for (int j = 0; j < nDataI.length; ++j) {
+                final S d = nDataI[j].multiply(power);
+                stateVariation[j]          = stateVariation[j].add(d);
+                estimatedDerivatives[j] = estimatedDerivatives[j].add(d.multiply(order));
+            }
+        }
+
+        S[] estimatedState = referenceState.getState();
+        for (int j = 0; j < stateVariation.length; ++j) {
+            stateVariation[j]    = stateVariation[j].add(scaled[j].multiply(normalizedAbscissa));
+            estimatedState[j] = estimatedState[j].add(stateVariation[j]);
+            estimatedDerivatives[j] =
+                estimatedDerivatives[j].add(scaled[j].multiply(normalizedAbscissa)).divide(x);
+        }
+
+        return new FieldODEStateAndDerivative<S>(time, estimatedState, estimatedDerivatives);
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/dd9dc945/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java
new file mode 100644
index 0000000..93ec85e
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java
@@ -0,0 +1,362 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.linear.Array2DRowFieldMatrix;
+import org.apache.commons.math4.linear.ArrayFieldVector;
+import org.apache.commons.math4.linear.FieldDecompositionSolver;
+import org.apache.commons.math4.linear.FieldLUDecomposition;
+import org.apache.commons.math4.linear.FieldMatrix;
+import org.apache.commons.math4.util.MathArrays;
+
+/** Transformer to Nordsieck vectors for Adams integrators.
+ * <p>This class is used by {@link AdamsBashforthIntegrator Adams-Bashforth} and
+ * {@link AdamsMoultonIntegrator Adams-Moulton} integrators to convert between
+ * classical representation with several previous first derivatives and Nordsieck
+ * representation with higher order scaled derivatives.</p>
+ *
+ * <p>We define scaled derivatives s<sub>i</sub>(n) at step n as:
+ * <pre>
+ * s<sub>1</sub>(n) = h y'<sub>n</sub> for first derivative
+ * s<sub>2</sub>(n) = h<sup>2</sup>/2 y''<sub>n</sub> for second derivative
+ * s<sub>3</sub>(n) = h<sup>3</sup>/6 y'''<sub>n</sub> for third derivative
+ * ...
+ * s<sub>k</sub>(n) = h<sup>k</sup>/k! y<sup>(k)</sup><sub>n</sub> for k<sup>th</sup> derivative
+ * </pre></p>
+ *
+ * <p>With the previous definition, the classical representation of multistep methods
+ * uses first derivatives only, i.e. it handles y<sub>n</sub>, s<sub>1</sub>(n) and
+ * q<sub>n</sub> where q<sub>n</sub> is defined as:
+ * <pre>
+ *   q<sub>n</sub> = [ s<sub>1</sub>(n-1) s<sub>1</sub>(n-2) ... s<sub>1</sub>(n-(k-1)) ]<sup>T</sup>
+ * </pre>
+ * (we omit the k index in the notation for clarity).</p>
+ *
+ * <p>Another possible representation uses the Nordsieck vector with
+ * higher degrees scaled derivatives all taken at the same step, i.e it handles y<sub>n</sub>,
+ * s<sub>1</sub>(n) and r<sub>n</sub>) where r<sub>n</sub> is defined as:
+ * <pre>
+ * r<sub>n</sub> = [ s<sub>2</sub>(n), s<sub>3</sub>(n) ... s<sub>k</sub>(n) ]<sup>T</sup>
+ * </pre>
+ * (here again we omit the k index in the notation for clarity)
+ * </p>
+ *
+ * <p>Taylor series formulas show that for any index offset i, s<sub>1</sub>(n-i) can be
+ * computed from s<sub>1</sub>(n), s<sub>2</sub>(n) ... s<sub>k</sub>(n), the formula being exact
+ * for degree k polynomials.
+ * <pre>
+ * s<sub>1</sub>(n-i) = s<sub>1</sub>(n) + &sum;<sub>j&gt;0</sub> (j+1) (-i)<sup>j</sup> s<sub>j+1</sub>(n)
+ * </pre>
+ * The previous formula can be used with several values for i to compute the transform between
+ * classical representation and Nordsieck vector at step end. The transform between r<sub>n</sub>
+ * and q<sub>n</sub> resulting from the Taylor series formulas above is:
+ * <pre>
+ * q<sub>n</sub> = s<sub>1</sub>(n) u + P r<sub>n</sub>
+ * </pre>
+ * where u is the [ 1 1 ... 1 ]<sup>T</sup> vector and P is the (k-1)&times;(k-1) matrix built
+ * with the (j+1) (-i)<sup>j</sup> terms with i being the row number starting from 1 and j being
+ * the column number starting from 1:
+ * <pre>
+ *        [  -2   3   -4    5  ... ]
+ *        [  -4  12  -32   80  ... ]
+ *   P =  [  -6  27 -108  405  ... ]
+ *        [  -8  48 -256 1280  ... ]
+ *        [          ...           ]
+ * </pre></p>
+ *
+ * <p>Changing -i into +i in the formula above can be used to compute a similar transform between
+ * classical representation and Nordsieck vector at step start. The resulting matrix is simply
+ * the absolute value of matrix P.</p>
+ *
+ * <p>For {@link AdamsBashforthIntegrator Adams-Bashforth} method, the Nordsieck vector
+ * at step n+1 is computed from the Nordsieck vector at step n as follows:
+ * <ul>
+ *   <li>y<sub>n+1</sub> = y<sub>n</sub> + s<sub>1</sub>(n) + u<sup>T</sup> r<sub>n</sub></li>
+ *   <li>s<sub>1</sub>(n+1) = h f(t<sub>n+1</sub>, y<sub>n+1</sub>)</li>
+ *   <li>r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub></li>
+ * </ul>
+ * where A is a rows shifting matrix (the lower left part is an identity matrix):
+ * <pre>
+ *        [ 0 0   ...  0 0 | 0 ]
+ *        [ ---------------+---]
+ *        [ 1 0   ...  0 0 | 0 ]
+ *    A = [ 0 1   ...  0 0 | 0 ]
+ *        [       ...      | 0 ]
+ *        [ 0 0   ...  1 0 | 0 ]
+ *        [ 0 0   ...  0 1 | 0 ]
+ * </pre></p>
+ *
+ * <p>For {@link AdamsMoultonIntegrator Adams-Moulton} method, the predicted Nordsieck vector
+ * at step n+1 is computed from the Nordsieck vector at step n as follows:
+ * <ul>
+ *   <li>Y<sub>n+1</sub> = y<sub>n</sub> + s<sub>1</sub>(n) + u<sup>T</sup> r<sub>n</sub></li>
+ *   <li>S<sub>1</sub>(n+1) = h f(t<sub>n+1</sub>, Y<sub>n+1</sub>)</li>
+ *   <li>R<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub></li>
+ * </ul>
+ * From this predicted vector, the corrected vector is computed as follows:
+ * <ul>
+ *   <li>y<sub>n+1</sub> = y<sub>n</sub> + S<sub>1</sub>(n+1) + [ -1 +1 -1 +1 ... &plusmn;1 ] r<sub>n+1</sub></li>
+ *   <li>s<sub>1</sub>(n+1) = h f(t<sub>n+1</sub>, y<sub>n+1</sub>)</li>
+ *   <li>r<sub>n+1</sub> = R<sub>n+1</sub> + (s<sub>1</sub>(n+1) - S<sub>1</sub>(n+1)) P<sup>-1</sup> u</li>
+ * </ul>
+ * where the upper case Y<sub>n+1</sub>, S<sub>1</sub>(n+1) and R<sub>n+1</sub> represent the
+ * predicted states whereas the lower case y<sub>n+1</sub>, s<sub>n+1</sub> and r<sub>n+1</sub>
+ * represent the corrected states.</p>
+ *
+ * <p>We observe that both methods use similar update formulas. In both cases a P<sup>-1</sup>u
+ * vector and a P<sup>-1</sup> A P matrix are used that do not depend on the state,
+ * they only depend on k. This class handles these transformations.</p>
+ *
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+public class AdamsNordsieckFieldTransformer<T extends RealFieldElement<T>> {
+
+    /** Cache for already computed coefficients. */
+    private static final Map<Integer,
+                         Map<Field<? extends RealFieldElement<?>>,
+                                   AdamsNordsieckFieldTransformer<? extends RealFieldElement<?>>>> CACHE =
+        new HashMap<Integer, Map<Field<? extends RealFieldElement<?>>,
+                                 AdamsNordsieckFieldTransformer<? extends RealFieldElement<?>>>>();
+
+    /** Field to which the time and state vector elements belong. */
+    private final Field<T> field;
+
+    /** Update matrix for the higher order derivatives h<sup>2</sup>/2 y'', h<sup>3</sup>/6 y''' ... */
+    private final Array2DRowFieldMatrix<T> update;
+
+    /** Update coefficients of the higher order derivatives wrt y'. */
+    private final T[] c1;
+
+    /** Simple constructor.
+     * @param field field to which the time and state vector elements belong
+     * @param n number of steps of the multistep method
+     * (excluding the one being computed)
+     */
+    private AdamsNordsieckFieldTransformer(final Field<T> field, final int n) {
+
+        this.field = field;
+        final int rows = n - 1;
+
+        // compute coefficients
+        FieldMatrix<T> bigP = buildP(rows);
+        FieldDecompositionSolver<T> pSolver =
+            new FieldLUDecomposition<T>(bigP).getSolver();
+
+        T[] u = MathArrays.buildArray(field, rows);
+        Arrays.fill(u, field.getOne());
+        c1 = pSolver.solve(new ArrayFieldVector<T>(u, false)).toArray();
+
+        // update coefficients are computed by combining transform from
+        // Nordsieck to multistep, then shifting rows to represent step advance
+        // then applying inverse transform
+        T[][] shiftedP = bigP.getData();
+        for (int i = shiftedP.length - 1; i > 0; --i) {
+            // shift rows
+            shiftedP[i] = shiftedP[i - 1];
+        }
+        shiftedP[0] = MathArrays.buildArray(field, rows);
+        Arrays.fill(shiftedP[0], field.getZero());
+        update = new Array2DRowFieldMatrix<T>(pSolver.solve(new Array2DRowFieldMatrix<T>(shiftedP, false)).getData());
+
+    }
+
+    /** Get the Nordsieck transformer for a given field and number of steps.
+     * @param field field to which the time and state vector elements belong
+     * @param nSteps number of steps of the multistep method
+     * (excluding the one being computed)
+     * @return Nordsieck transformer for the specified field and number of steps
+     * @param <T> the type of the field elements
+     */
+    public static <T extends RealFieldElement<T>> AdamsNordsieckFieldTransformer<T>
+    getInstance(final Field<T> field, final int nSteps) {
+        synchronized(CACHE) {
+            Map<Field<? extends RealFieldElement<?>>,
+                      AdamsNordsieckFieldTransformer<? extends RealFieldElement<?>>> map = CACHE.get(nSteps);
+            if (map == null) {
+                map = new HashMap<Field<? extends RealFieldElement<?>>,
+                                        AdamsNordsieckFieldTransformer<? extends RealFieldElement<?>>>();
+                CACHE.put(nSteps, map);
+            }
+            @SuppressWarnings("unchecked")
+            AdamsNordsieckFieldTransformer<T> t = (AdamsNordsieckFieldTransformer<T>) map.get(field);
+            if (t == null) {
+                t = new AdamsNordsieckFieldTransformer<T>(field, nSteps);
+                map.put(field, t);
+            }
+            return t;
+
+        }
+    }
+
+    /** Build the P matrix.
+     * <p>The P matrix general terms are shifted (j+1) (-i)<sup>j</sup> terms
+     * with i being the row number starting from 1 and j being the column
+     * number starting from 1:
+     * <pre>
+     *        [  -2   3   -4    5  ... ]
+     *        [  -4  12  -32   80  ... ]
+     *   P =  [  -6  27 -108  405  ... ]
+     *        [  -8  48 -256 1280  ... ]
+     *        [          ...           ]
+     * </pre></p>
+     * @param rows number of rows of the matrix
+     * @return P matrix
+     */
+    private FieldMatrix<T> buildP(final int rows) {
+
+        final T[][] pData = MathArrays.buildArray(field, rows, rows);
+
+        for (int i = 1; i <= pData.length; ++i) {
+            // build the P matrix elements from Taylor series formulas
+            final T[] pI = pData[i - 1];
+            final int factor = -i;
+            T aj = field.getZero().add(factor);
+            for (int j = 1; j <= pI.length; ++j) {
+                pI[j - 1] = aj.multiply(j + 1);
+                aj = aj.multiply(factor);
+            }
+        }
+
+        return new Array2DRowFieldMatrix<T>(pData, false);
+
+    }
+
+    /** Initialize the high order scaled derivatives at step start.
+     * @param h step size to use for scaling
+     * @param t first steps times
+     * @param y first steps states
+     * @param yDot first steps derivatives
+     * @return Nordieck vector at start of first step (h<sup>2</sup>/2 y''<sub>n</sub>,
+     * h<sup>3</sup>/6 y'''<sub>n</sub> ... h<sup>k</sup>/k! y<sup>(k)</sup><sub>n</sub>)
+     */
+
+    public Array2DRowFieldMatrix<T> initializeHighOrderDerivatives(final T h, final T[] t,
+                                                                   final T[][] y,
+                                                                   final T[][] yDot) {
+
+        // using Taylor series with di = ti - t0, we get:
+        //  y(ti)  - y(t0)  - di y'(t0) =   di^2 / h^2 s2 + ... +   di^k     / h^k sk + O(h^k)
+        //  y'(ti) - y'(t0)             = 2 di   / h^2 s2 + ... + k di^(k-1) / h^k sk + O(h^(k-1))
+        // we write these relations for i = 1 to i= 1+n/2 as a set of n + 2 linear
+        // equations depending on the Nordsieck vector [s2 ... sk rk], so s2 to sk correspond
+        // to the appropriately truncated Taylor expansion, and rk is the Taylor remainder.
+        // The goal is to have s2 to sk as accurate as possible considering the fact the sum is
+        // truncated and we don't want the error terms to be included in s2 ... sk, so we need
+        // to solve also for the remainder
+        final T[][] a     = MathArrays.buildArray(field, c1.length + 1, c1.length + 1);
+        final T[][] b     = MathArrays.buildArray(field, c1.length + 1, y[0].length);
+        final T[]   y0    = y[0];
+        final T[]   yDot0 = yDot[0];
+        for (int i = 1; i < y.length; ++i) {
+
+            final T di    = t[i].subtract(t[0]);
+            final T ratio = di.divide(h);
+            T dikM1Ohk    = h.reciprocal();
+
+            // linear coefficients of equations
+            // y(ti) - y(t0) - di y'(t0) and y'(ti) - y'(t0)
+            final T[] aI    = a[2 * i - 2];
+            final T[] aDotI = (2 * i - 1) < a.length ? a[2 * i - 1] : null;
+            for (int j = 0; j < aI.length; ++j) {
+                dikM1Ohk = dikM1Ohk.multiply(ratio);
+                aI[j]    = di.multiply(dikM1Ohk);
+                if (aDotI != null) {
+                    aDotI[j]  = dikM1Ohk.multiply(j + 2);
+                }
+            }
+
+            // expected value of the previous equations
+            final T[] yI    = y[i];
+            final T[] yDotI = yDot[i];
+            final T[] bI    = b[2 * i - 2];
+            final T[] bDotI = (2 * i - 1) < b.length ? b[2 * i - 1] : null;
+            for (int j = 0; j < yI.length; ++j) {
+                bI[j]    = yI[j].subtract(y0[j]).subtract(di.multiply(yDot0[j]));
+                if (bDotI != null) {
+                    bDotI[j] = yDotI[j].subtract(yDot0[j]);
+                }
+            }
+
+        }
+
+        // solve the linear system to get the best estimate of the Nordsieck vector [s2 ... sk],
+        // with the additional terms s(k+1) and c grabbing the parts after the truncated Taylor expansion
+        final FieldLUDecomposition<T> decomposition = new FieldLUDecomposition<T>(new Array2DRowFieldMatrix<T>(a, false));
+        final FieldMatrix<T> x = decomposition.getSolver().solve(new Array2DRowFieldMatrix<T>(b, false));
+
+        // extract just the Nordsieck vector [s2 ... sk]
+        final Array2DRowFieldMatrix<T> truncatedX =
+                        new Array2DRowFieldMatrix<T>(field, x.getRowDimension() - 1, x.getColumnDimension());
+        for (int i = 0; i < truncatedX.getRowDimension(); ++i) {
+            for (int j = 0; j < truncatedX.getColumnDimension(); ++j) {
+                truncatedX.setEntry(i, j, x.getEntry(i, j));
+            }
+        }
+        return truncatedX;
+
+    }
+
+    /** Update the high order scaled derivatives for Adams integrators (phase 1).
+     * <p>The complete update of high order derivatives has a form similar to:
+     * <pre>
+     * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
+     * </pre>
+     * this method computes the P<sup>-1</sup> A P r<sub>n</sub> part.</p>
+     * @param highOrder high order scaled derivatives
+     * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
+     * @return updated high order derivatives
+     * @see #updateHighOrderDerivativesPhase2(double[], double[], Array2DRowFieldMatrix)
+     */
+    public Array2DRowFieldMatrix<T> updateHighOrderDerivativesPhase1(final Array2DRowFieldMatrix<T> highOrder) {
+        return update.multiply(highOrder);
+    }
+
+    /** Update the high order scaled derivatives Adams integrators (phase 2).
+     * <p>The complete update of high order derivatives has a form similar to:
+     * <pre>
+     * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub>
+     * </pre>
+     * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
+     * <p>Phase 1 of the update must already have been performed.</p>
+     * @param start first order scaled derivatives at step start
+     * @param end first order scaled derivatives at step end
+     * @param highOrder high order scaled derivatives, will be modified
+     * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
+     * @see #updateHighOrderDerivativesPhase1(Array2DRowFieldMatrix)
+     */
+    public void updateHighOrderDerivativesPhase2(final T[] start,
+                                                 final T[] end,
+                                                 final Array2DRowFieldMatrix<T> highOrder) {
+        final T[][] data = highOrder.getDataRef();
+        for (int i = 0; i < data.length; ++i) {
+            final T[] dataI = data[i];
+            final T c1I = c1[i];
+            for (int j = 0; j < dataI.length; ++j) {
+                dataI[j] = dataI[j].add(c1I.multiply(start[j].subtract(end[j])));
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/dd9dc945/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
new file mode 100644
index 0000000..0d22831
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractAdamsFieldIntegratorTest.java
@@ -0,0 +1,261 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.MathIllegalStateException;
+import org.apache.commons.math4.exception.MaxCountExceededException;
+import org.apache.commons.math4.exception.NumberIsTooSmallException;
+import org.apache.commons.math4.ode.AbstractFieldIntegrator;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FieldODEState;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.FirstOrderFieldIntegrator;
+import org.apache.commons.math4.ode.MultistepFieldIntegrator;
+import org.apache.commons.math4.ode.TestFieldProblem1;
+import org.apache.commons.math4.ode.TestFieldProblem5;
+import org.apache.commons.math4.ode.TestFieldProblem6;
+import org.apache.commons.math4.ode.TestFieldProblemAbstract;
+import org.apache.commons.math4.ode.TestFieldProblemHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math4.util.FastMath;
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class AbstractAdamsFieldIntegratorTest {
+
+    protected abstract <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
+    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance);
+
+    protected abstract <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
+    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance);
+
+    @Test(expected=NumberIsTooSmallException.class)
+    public abstract void testMinStep();
+
+    protected <T extends RealFieldElement<T>> void doDimensionCheck(final Field<T> field) {
+        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+
+        double minStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.1).getReal();
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
+        double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
+
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 4, minStep, maxStep,
+                                                              vecAbsoluteTolerance,
+                                                              vecRelativeTolerance);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+    }
+
+    @Test
+    public abstract void testIncreasingTolerance();
+
+    protected <T extends RealFieldElement<T>> void doTestIncreasingTolerance(final Field<T> field,
+                                                                             int ratioMin, int ratioMax) {
+
+        int previousCalls = Integer.MAX_VALUE;
+        for (int i = -12; i < -5; ++i) {
+            TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+            double minStep = 0;
+            double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+            double scalAbsoluteTolerance = FastMath.pow(10.0, i);
+            double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+
+            FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 4, minStep, maxStep,
+                                                                  scalAbsoluteTolerance,
+                                                                  scalRelativeTolerance);
+            TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+            integ.addStepHandler(handler);
+            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+            Assert.assertTrue(handler.getMaximalValueError().getReal() > ratioMin * scalAbsoluteTolerance);
+            Assert.assertTrue(handler.getMaximalValueError().getReal() < ratioMax * scalAbsoluteTolerance);
+
+            int calls = pb.getCalls();
+            Assert.assertEquals(integ.getEvaluations(), calls);
+            Assert.assertTrue(calls <= previousCalls);
+            previousCalls = calls;
+
+        }
+
+    }
+
+    @Test(expected = MaxCountExceededException.class)
+    public abstract void exceedMaxEvaluations();
+
+    protected <T extends RealFieldElement<T>> void doExceedMaxEvaluations(final Field<T> field) {
+
+        TestFieldProblem1<T> pb  = new TestFieldProblem1<T>(field);
+        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+
+        FirstOrderFieldIntegrator<T> integ = createIntegrator(field, 2, 0, range, 1.0e-12, 1.0e-12);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.setMaxEvaluations(650);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+    }
+
+    @Test
+    public abstract void backward();
+
+    protected <T extends RealFieldElement<T>> void doBackward(final Field<T> field,
+                                                              final double epsilonLast,
+                                                              final double epsilonMaxValue,
+                                                              final double epsilonMaxTime,
+                                                              final String name) {
+
+        TestFieldProblem5<T> pb = new TestFieldProblem5<T>(field);
+        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+
+        AdamsFieldIntegrator<T> integ = createIntegrator(field, 4, 0, range, 1.0e-12, 1.0e-12);
+        integ.setStarterIntegrator(new PerfectStarter<T>(pb, (integ.getNSteps() + 5) / 2));
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+        Assert.assertEquals(0.0, handler.getLastError().getReal(), epsilonLast);
+        Assert.assertEquals(0.0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
+        Assert.assertEquals(0, handler.getMaximalTimeError().getReal(), epsilonMaxTime);
+        Assert.assertEquals(name, integ.getName());
+    }
+
+    @Test
+    public abstract void polynomial();
+
+    protected <T extends RealFieldElement<T>> void doPolynomial(final Field<T> field,
+                                                                final int nLimit,
+                                                                final double epsilonBad,
+                                                                final double epsilonGood) {
+        TestFieldProblem6<T> pb = new TestFieldProblem6<T>(field);
+        double range = pb.getFinalTime().subtract(pb.getInitialState().getTime()).abs().getReal();
+
+        for (int nSteps = 2; nSteps < 8; ++nSteps) {
+            AdamsFieldIntegrator<T> integ = createIntegrator(field, nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-4, 1.0e-4);
+            integ.setStarterIntegrator(new PerfectStarter<T>(pb, nSteps));
+            TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+            integ.addStepHandler(handler);
+            integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+            if (nSteps < nLimit) {
+                Assert.assertTrue(handler.getMaximalValueError().getReal() > epsilonBad);
+            } else {
+                Assert.assertTrue(handler.getMaximalValueError().getReal() < epsilonGood);
+            }
+        }
+
+    }
+
+    @Test(expected=MathIllegalStateException.class)
+    public abstract void testStartFailure();
+
+    protected <T extends RealFieldElement<T>> void doTestStartFailure(final Field<T> field) {
+        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        double minStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.0001).getReal();
+        double maxStep = pb.getFinalTime().subtract(pb.getInitialState().getTime()).getReal();
+        double scalAbsoluteTolerance = 1.0e-6;
+        double scalRelativeTolerance = 1.0e-7;
+
+        MultistepFieldIntegrator<T> integ = createIntegrator(field, 6, minStep, maxStep,
+                                                             scalAbsoluteTolerance,
+                                                             scalRelativeTolerance);
+        integ.setStarterIntegrator(new DormandPrince853FieldIntegrator<T>(field, maxStep * 0.5, maxStep, 0.1, 0.1));
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+    }
+
+    private static class PerfectStarter<T extends RealFieldElement<T>> extends AbstractFieldIntegrator<T> {
+
+        private final PerfectInterpolator<T> interpolator;
+        private final int nbSteps;
+
+        public PerfectStarter(final TestFieldProblemAbstract<T> problem, final int nbSteps) {
+            super(problem.getField(), "perfect-starter");
+            this.interpolator = new PerfectInterpolator<T>(problem);
+            this.nbSteps      = nbSteps;
+        }
+
+        public FieldODEStateAndDerivative<T> integrate(FieldExpandableODE<T> equations,
+                                                       FieldODEState<T> initialState, T finalTime) {
+            T tStart = initialState.getTime().add(finalTime.subtract(initialState.getTime()).multiply(0.01));
+            getEvaluationsCounter().increment(nbSteps);
+            interpolator.setCurrentTime(initialState.getTime());
+            for (int i = 0; i < nbSteps; ++i) {
+                T tK = initialState.getTime().multiply(nbSteps - 1 - (i + 1)).add(tStart.multiply(i + 1)).divide(nbSteps - 1);
+                interpolator.setPreviousTime(interpolator.getCurrentTime());
+                interpolator.setCurrentTime(tK);
+                for (FieldStepHandler<T> handler : getStepHandlers()) {
+                    handler.handleStep(interpolator, i == nbSteps - 1);
+                }
+            }
+            return interpolator.getInterpolatedState(tStart);
+        }
+
+    }
+
+    private static class PerfectInterpolator<T extends RealFieldElement<T>> implements FieldStepInterpolator<T> {
+        private final TestFieldProblemAbstract<T> problem;
+        private T previousTime;
+        private T currentTime;
+
+        public PerfectInterpolator(final TestFieldProblemAbstract<T> problem) {
+            this.problem = problem;
+        }
+
+        public void setPreviousTime(T previousTime) {
+            this.previousTime = previousTime;
+        }
+
+        public void setCurrentTime(T currentTime) {
+            this.currentTime = currentTime;
+        }
+
+        public T getCurrentTime() {
+            return currentTime;
+        }
+
+        public boolean isForward() {
+            return problem.getFinalTime().subtract(problem.getInitialState().getTime()).getReal() >= 0;
+        }
+
+        public FieldODEStateAndDerivative<T> getPreviousState() {
+            return getInterpolatedState(previousTime);
+        }
+
+        public FieldODEStateAndDerivative<T> getCurrentState() {
+            return getInterpolatedState(currentTime);
+        }
+
+        public FieldODEStateAndDerivative<T> getInterpolatedState(T time) {
+            T[] y    = problem.computeTheoreticalState(time);
+            T[] yDot = problem.computeDerivatives(time, y);
+            return new FieldODEStateAndDerivative<T>(time, y, yDot);
+        }
+
+    }
+
+}


[16/50] [abbrv] [math] Fixed state copying after event detection.

Posted by lu...@apache.org.
Fixed state copying after event detection.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/7a5431ec
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/7a5431ec
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/7a5431ec

Branch: refs/heads/master
Commit: 7a5431ecb6efd9ae83c3469f040817d01cdef1c3
Parents: 084ab51
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:25 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:25 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/7a5431ec/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
index c8de1ad..1f3e87c 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
@@ -260,7 +260,8 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
             while (error.subtract(1.0).getReal() >= 0) {
 
                 // first stage
-                yDotK[0] = stepStart.getDerivative();
+                y        = equations.getMapper().mapState(stepStart);
+                yDotK[0] = equations.getMapper().mapDerivative(stepStart);
 
                 if (firstTime) {
                     final T[] scale = MathArrays.buildArray(getField(), mainSetDimension);
@@ -331,7 +332,6 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
             interpolator.storeState(stateTmp);
             System.arraycopy(yTmp, 0, y, 0, y0.length);
             stepStart = acceptStep(interpolator, finalTime);
-            System.arraycopy(y, 0, yTmp, 0, y.length);
 
             if (!isLastStep) {
 


[35/50] [abbrv] [math] Fixed syntax not compatible with Java 5.

Posted by lu...@apache.org.
Fixed syntax not compatible with Java 5.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/1d4d89e9
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/1d4d89e9
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/1d4d89e9

Branch: refs/heads/master
Commit: 1d4d89e9fb191af54a8f2eac924a2fcb285f760b
Parents: 49747dc
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:30:12 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:30:12 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/FieldExpandableODETest.java       | 344 +++++++++++++++++++
 .../ode/nonstiff/FieldExpandableODETest.java    | 344 -------------------
 2 files changed, 344 insertions(+), 344 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/1d4d89e9/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java b/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java
new file mode 100644
index 0000000..8005274
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/FieldExpandableODETest.java
@@ -0,0 +1,344 @@
+/*
+ * 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.apache.commons.math4.ode;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+import org.apache.commons.math4.exception.MathIllegalArgumentException;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.FieldSecondaryEquations;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.apache.commons.math4.util.MathArrays;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class FieldExpandableODETest {
+
+    @Test
+    public void testOnlyMainEquation() {
+        doTestOnlyMainEquation(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestOnlyMainEquation(final Field<T> field) {
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        Assert.assertEquals(main.getDimension(), equation.getMapper().getTotalDimension());
+        Assert.assertEquals(1, equation.getMapper().getNumberOfEquations());
+        T t0 = field.getZero().add(10);
+        T t  = field.getZero().add(100);
+        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        for (int i = 0; i < complete.length; ++i) {
+            complete[i] = field.getZero().add(i);
+        }
+        equation.init(t0, complete, t);
+        T[] completeDot = equation.computeDerivatives(t0, complete);
+        FieldODEStateAndDerivative<T> state = equation.getMapper().mapStateAndDerivative(t0, complete, completeDot);
+        Assert.assertEquals(0, state.getNumberOfSecondaryStates());
+        T[] mainState    = state.getState();
+        T[] mainStateDot = state.getDerivative();
+        Assert.assertEquals(main.getDimension(), mainState.length);
+        for (int i = 0; i < main.getDimension(); ++i) {
+            Assert.assertEquals(i, mainState[i].getReal(),   1.0e-15);
+            Assert.assertEquals(i, mainStateDot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(i, completeDot[i].getReal(),  1.0e-15);
+        }
+    }
+
+    @Test
+    public void testMainAndSecondary() {
+        doTestMainAndSecondary(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestMainAndSecondary(final Field<T> field) {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        FieldSecondaryEquations<T> secondary2 = new Linear<T>(field, 5, main.getDimension() + secondary1.getDimension());
+        int i2 = equation.addSecondaryEquations(secondary2);
+        Assert.assertEquals(main.getDimension() + secondary1.getDimension() + secondary2.getDimension(),
+                            equation.getMapper().getTotalDimension());
+        Assert.assertEquals(3, equation.getMapper().getNumberOfEquations());
+        Assert.assertEquals(1, i1);
+        Assert.assertEquals(2, i2);
+
+        T t0 = field.getZero().add(10);
+        T t  = field.getZero().add(100);
+        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        for (int i = 0; i < complete.length; ++i) {
+            complete[i] = field.getZero().add(i);
+        }
+        equation.init(t0, complete, t);
+        T[] completeDot = equation.computeDerivatives(t0, complete);
+
+        T[] mainState    = equation.getMapper().extractEquationData(0,  complete);
+        T[] mainStateDot = equation.getMapper().extractEquationData(0,  completeDot);
+        Assert.assertEquals(main.getDimension(), mainState.length);
+        for (int i = 0; i < main.getDimension(); ++i) {
+            Assert.assertEquals(i, mainState[i].getReal(),   1.0e-15);
+            Assert.assertEquals(i, mainStateDot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(i, completeDot[i].getReal(),  1.0e-15);
+        }
+
+        T[] secondaryState1    = equation.getMapper().extractEquationData(i1,  complete);
+        T[] secondaryState1Dot = equation.getMapper().extractEquationData(i1,  completeDot);
+        Assert.assertEquals(secondary1.getDimension(), secondaryState1.length);
+        for (int i = 0; i < secondary1.getDimension(); ++i) {
+            Assert.assertEquals(i + main.getDimension(), secondaryState1[i].getReal(),   1.0e-15);
+            Assert.assertEquals(-i, secondaryState1Dot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(-i, completeDot[i + main.getDimension()].getReal(),  1.0e-15);
+        }
+
+        T[] secondaryState2    = equation.getMapper().extractEquationData(i2,  complete);
+        T[] secondaryState2Dot = equation.getMapper().extractEquationData(i2,  completeDot);
+        Assert.assertEquals(secondary2.getDimension(), secondaryState2.length);
+        for (int i = 0; i < secondary2.getDimension(); ++i) {
+            Assert.assertEquals(i + main.getDimension() + secondary1.getDimension(), secondaryState2[i].getReal(),   1.0e-15);
+            Assert.assertEquals(-i, secondaryState2Dot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(-i, completeDot[i + main.getDimension() + secondary1.getDimension()].getReal(),  1.0e-15);
+        }
+
+    }
+
+    @Test
+    public void testMap() {
+        doTestMap(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestMap(final Field<T> field) {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        FieldSecondaryEquations<T> secondary2 = new Linear<T>(field, 5, main.getDimension() + secondary1.getDimension());
+        int i2 = equation.addSecondaryEquations(secondary2);
+        Assert.assertEquals(main.getDimension() + secondary1.getDimension() + secondary2.getDimension(),
+                            equation.getMapper().getTotalDimension());
+        Assert.assertEquals(3, equation.getMapper().getNumberOfEquations());
+        Assert.assertEquals(1, i1);
+        Assert.assertEquals(2, i2);
+
+        T t0 = field.getZero().add(10);
+        T t  = field.getZero().add(100);
+        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        for (int i = 0; i < complete.length; ++i) {
+            complete[i] = field.getZero().add(i);
+        }
+        equation.init(t0, complete, t);
+        T[] completeDot = equation.computeDerivatives(t0, complete);
+
+        try {
+            equation.getMapper().mapStateAndDerivative(t0, MathArrays.buildArray(field, complete.length + 1), completeDot);
+            Assert.fail("an exception should have been thrown");
+        } catch (DimensionMismatchException dme) {
+            // expected
+        }
+        try {
+            equation.getMapper().mapStateAndDerivative(t0, complete, MathArrays.buildArray(field, completeDot.length + 1));
+            Assert.fail("an exception should have been thrown");
+        } catch (DimensionMismatchException dme) {
+            // expected
+        }
+        FieldODEStateAndDerivative<T> state = equation.getMapper().mapStateAndDerivative(t0, complete, completeDot);
+        Assert.assertEquals(2, state.getNumberOfSecondaryStates());
+        Assert.assertEquals(main.getDimension(),       state.getSecondaryStateDimension(0));
+        Assert.assertEquals(secondary1.getDimension(), state.getSecondaryStateDimension(i1));
+        Assert.assertEquals(secondary2.getDimension(), state.getSecondaryStateDimension(i2));
+
+        T[] mainState             = state.getState();
+        T[] mainStateDot          = state.getDerivative();
+        T[] mainStateAlternate    = state.getSecondaryState(0);
+        T[] mainStateDotAlternate = state.getSecondaryDerivative(0);
+        Assert.assertEquals(main.getDimension(), mainState.length);
+        for (int i = 0; i < main.getDimension(); ++i) {
+            Assert.assertEquals(i, mainState[i].getReal(),             1.0e-15);
+            Assert.assertEquals(i, mainStateDot[i].getReal(),          1.0e-15);
+            Assert.assertEquals(i, mainStateAlternate[i].getReal(),    1.0e-15);
+            Assert.assertEquals(i, mainStateDotAlternate[i].getReal(), 1.0e-15);
+            Assert.assertEquals(i, completeDot[i].getReal(),           1.0e-15);
+        }
+
+        T[] secondaryState1    = state.getSecondaryState(i1);
+        T[] secondaryState1Dot = state.getSecondaryDerivative(i1);
+        Assert.assertEquals(secondary1.getDimension(), secondaryState1.length);
+        for (int i = 0; i < secondary1.getDimension(); ++i) {
+            Assert.assertEquals(i + main.getDimension(), secondaryState1[i].getReal(),   1.0e-15);
+            Assert.assertEquals(-i, secondaryState1Dot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(-i, completeDot[i + main.getDimension()].getReal(),  1.0e-15);
+        }
+
+        T[] secondaryState2    = state.getSecondaryState(i2);
+        T[] secondaryState2Dot = state.getSecondaryDerivative(i2);
+        Assert.assertEquals(secondary2.getDimension(), secondaryState2.length);
+        for (int i = 0; i < secondary2.getDimension(); ++i) {
+            Assert.assertEquals(i + main.getDimension() + secondary1.getDimension(), secondaryState2[i].getReal(),   1.0e-15);
+            Assert.assertEquals(-i, secondaryState2Dot[i].getReal(), 1.0e-15);
+            Assert.assertEquals(-i, completeDot[i + main.getDimension() + secondary1.getDimension()].getReal(),  1.0e-15);
+        }
+
+        T[] remappedState = equation.getMapper().mapState(state);
+        T[] remappedDerivative = equation.getMapper().mapDerivative(state);
+        Assert.assertEquals(equation.getMapper().getTotalDimension(), remappedState.length);
+        Assert.assertEquals(equation.getMapper().getTotalDimension(), remappedDerivative.length);
+        for (int i = 0; i < remappedState.length; ++i) {
+            Assert.assertEquals(complete[i].getReal(),    remappedState[i].getReal(),      1.0e-15);
+            Assert.assertEquals(completeDot[i].getReal(), remappedDerivative[i].getReal(), 1.0e-15);
+        }
+    }
+
+    @Test(expected=DimensionMismatchException.class)
+    public void testExtractDimensionMismatch() {
+        doTestExtractDimensionMismatch(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestExtractDimensionMismatch(final Field<T> field)
+        throws DimensionMismatchException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        T[] tooShort    = MathArrays.buildArray(field, main.getDimension());
+        equation.getMapper().extractEquationData(i1, tooShort);
+    }
+
+    @Test(expected=DimensionMismatchException.class)
+    public void testInsertTooShortComplete() {
+        doTestInsertTooShortComplete(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestInsertTooShortComplete(final Field<T> field)
+        throws DimensionMismatchException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        T[] equationData = MathArrays.buildArray(field, secondary1.getDimension());
+        T[] tooShort     = MathArrays.buildArray(field, main.getDimension());
+        equation.getMapper().insertEquationData(i1, equationData, tooShort);
+    }
+
+    @Test(expected=DimensionMismatchException.class)
+    public void testInsertWrongEquationData() {
+        doTestInsertWrongEquationData(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestInsertWrongEquationData(final Field<T> field)
+        throws DimensionMismatchException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
+        int i1 = equation.addSecondaryEquations(secondary1);
+        T[] wrongEquationData = MathArrays.buildArray(field, secondary1.getDimension() + 1);
+        T[] complete          = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        equation.getMapper().insertEquationData(i1, wrongEquationData, complete);
+    }
+
+    @Test(expected=MathIllegalArgumentException.class)
+    public void testNegativeIndex() {
+        doTestNegativeIndex(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestNegativeIndex(final Field<T> field)
+        throws MathIllegalArgumentException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        T[] complete = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        equation.getMapper().extractEquationData(-1, complete);
+    }
+
+    @Test(expected=MathIllegalArgumentException.class)
+    public void testTooLargeIndex() {
+        doTestTooLargeIndex(Decimal64Field.getInstance());
+    }
+
+    private <T extends RealFieldElement<T>> void doTestTooLargeIndex(final Field<T> field)
+        throws MathIllegalArgumentException {
+
+        FieldFirstOrderDifferentialEquations<T> main = new Linear<T>(field, 3, 0);
+        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
+        T[] complete = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
+        equation.getMapper().extractEquationData(+1, complete);
+    }
+
+    private static class  Linear<T extends RealFieldElement<T>>
+        implements  FieldFirstOrderDifferentialEquations<T>, FieldSecondaryEquations<T> {
+
+        private final Field<T> field;
+        private final int dimension;
+        private final int start;
+
+        private Linear(final Field<T> field, final int dimension, final int start) {
+            this.field     = field;
+            this.dimension = dimension;
+            this.start     = start;
+        }
+
+        public int getDimension() {
+            return dimension;
+        }
+
+        public void init(final T t0, final T[] y0, final T finalTime) {
+            Assert.assertEquals(dimension, y0.length);
+            Assert.assertEquals(10.0,  t0.getReal(), 1.0e-15);
+            Assert.assertEquals(100.0, finalTime.getReal(), 1.0e-15);
+            for (int i = 0; i < y0.length; ++i) {
+                Assert.assertEquals(i, y0[i].getReal(), 1.0e-15);
+            }
+        }
+
+        public T[] computeDerivatives(final T t, final T[] y) {
+            final T[] yDot = MathArrays.buildArray(field, dimension);
+            for (int i = 0; i < dimension; ++i) {
+                yDot[i] = field.getZero().add(i);
+            }
+            return yDot;
+        }
+
+        public void init(final T t0, final T[] primary0, final T[] secondary0, final T finalTime) {
+            Assert.assertEquals(dimension, secondary0.length);
+            Assert.assertEquals(10.0,  t0.getReal(), 1.0e-15);
+            Assert.assertEquals(100.0, finalTime.getReal(), 1.0e-15);
+            for (int i = 0; i < primary0.length; ++i) {
+                Assert.assertEquals(i, primary0[i].getReal(), 1.0e-15);
+            }
+            for (int i = 0; i < secondary0.length; ++i) {
+                Assert.assertEquals(start + i, secondary0[i].getReal(), 1.0e-15);
+            }
+        }
+
+        public T[] computeDerivatives(final T t, final T[] primary, final T[] primaryDot, final T[] secondary) {
+            final T[] secondaryDot = MathArrays.buildArray(field, dimension);
+            for (int i = 0; i < dimension; ++i) {
+                secondaryDot[i] = field.getZero().subtract(i);
+            }
+            return secondaryDot;
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/1d4d89e9/src/test/java/org/apache/commons/math4/ode/nonstiff/FieldExpandableODETest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/FieldExpandableODETest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/FieldExpandableODETest.java
deleted file mode 100644
index 064e3e2..0000000
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/FieldExpandableODETest.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/*
- * 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.apache.commons.math4.ode.nonstiff;
-
-
-import org.apache.commons.math4.Field;
-import org.apache.commons.math4.RealFieldElement;
-import org.apache.commons.math4.exception.DimensionMismatchException;
-import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.ode.FieldExpandableODE;
-import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
-import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
-import org.apache.commons.math4.ode.FieldSecondaryEquations;
-import org.apache.commons.math4.util.Decimal64Field;
-import org.apache.commons.math4.util.MathArrays;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class FieldExpandableODETest {
-
-    @Test
-    public void testOnlyMainEquation() {
-        doTestOnlyMainEquation(Decimal64Field.getInstance());
-    }
-
-    private <T extends RealFieldElement<T>> void doTestOnlyMainEquation(final Field<T> field) {
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
-        FieldExpandableODE<T> equation = new FieldExpandableODE<>(main);
-        Assert.assertEquals(main.getDimension(), equation.getMapper().getTotalDimension());
-        Assert.assertEquals(1, equation.getMapper().getNumberOfEquations());
-        T t0 = field.getZero().add(10);
-        T t  = field.getZero().add(100);
-        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
-        for (int i = 0; i < complete.length; ++i) {
-            complete[i] = field.getZero().add(i);
-        }
-        equation.init(t0, complete, t);
-        T[] completeDot = equation.computeDerivatives(t0, complete);
-        FieldODEStateAndDerivative<T> state = equation.getMapper().mapStateAndDerivative(t0, complete, completeDot);
-        Assert.assertEquals(0, state.getNumberOfSecondaryStates());
-        T[] mainState    = state.getState();
-        T[] mainStateDot = state.getDerivative();
-        Assert.assertEquals(main.getDimension(), mainState.length);
-        for (int i = 0; i < main.getDimension(); ++i) {
-            Assert.assertEquals(i, mainState[i].getReal(),   1.0e-15);
-            Assert.assertEquals(i, mainStateDot[i].getReal(), 1.0e-15);
-            Assert.assertEquals(i, completeDot[i].getReal(),  1.0e-15);
-        }
-    }
-
-    @Test
-    public void testMainAndSecondary() {
-        doTestMainAndSecondary(Decimal64Field.getInstance());
-    }
-
-    private <T extends RealFieldElement<T>> void doTestMainAndSecondary(final Field<T> field) {
-
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
-        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
-        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
-        int i1 = equation.addSecondaryEquations(secondary1);
-        FieldSecondaryEquations<T> secondary2 = new Linear<T>(field, 5, main.getDimension() + secondary1.getDimension());
-        int i2 = equation.addSecondaryEquations(secondary2);
-        Assert.assertEquals(main.getDimension() + secondary1.getDimension() + secondary2.getDimension(),
-                            equation.getMapper().getTotalDimension());
-        Assert.assertEquals(3, equation.getMapper().getNumberOfEquations());
-        Assert.assertEquals(1, i1);
-        Assert.assertEquals(2, i2);
-
-        T t0 = field.getZero().add(10);
-        T t  = field.getZero().add(100);
-        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
-        for (int i = 0; i < complete.length; ++i) {
-            complete[i] = field.getZero().add(i);
-        }
-        equation.init(t0, complete, t);
-        T[] completeDot = equation.computeDerivatives(t0, complete);
-
-        T[] mainState    = equation.getMapper().extractEquationData(0,  complete);
-        T[] mainStateDot = equation.getMapper().extractEquationData(0,  completeDot);
-        Assert.assertEquals(main.getDimension(), mainState.length);
-        for (int i = 0; i < main.getDimension(); ++i) {
-            Assert.assertEquals(i, mainState[i].getReal(),   1.0e-15);
-            Assert.assertEquals(i, mainStateDot[i].getReal(), 1.0e-15);
-            Assert.assertEquals(i, completeDot[i].getReal(),  1.0e-15);
-        }
-
-        T[] secondaryState1    = equation.getMapper().extractEquationData(i1,  complete);
-        T[] secondaryState1Dot = equation.getMapper().extractEquationData(i1,  completeDot);
-        Assert.assertEquals(secondary1.getDimension(), secondaryState1.length);
-        for (int i = 0; i < secondary1.getDimension(); ++i) {
-            Assert.assertEquals(i + main.getDimension(), secondaryState1[i].getReal(),   1.0e-15);
-            Assert.assertEquals(-i, secondaryState1Dot[i].getReal(), 1.0e-15);
-            Assert.assertEquals(-i, completeDot[i + main.getDimension()].getReal(),  1.0e-15);
-        }
-
-        T[] secondaryState2    = equation.getMapper().extractEquationData(i2,  complete);
-        T[] secondaryState2Dot = equation.getMapper().extractEquationData(i2,  completeDot);
-        Assert.assertEquals(secondary2.getDimension(), secondaryState2.length);
-        for (int i = 0; i < secondary2.getDimension(); ++i) {
-            Assert.assertEquals(i + main.getDimension() + secondary1.getDimension(), secondaryState2[i].getReal(),   1.0e-15);
-            Assert.assertEquals(-i, secondaryState2Dot[i].getReal(), 1.0e-15);
-            Assert.assertEquals(-i, completeDot[i + main.getDimension() + secondary1.getDimension()].getReal(),  1.0e-15);
-        }
-
-    }
-
-    @Test
-    public void testMap() {
-        doTestMap(Decimal64Field.getInstance());
-    }
-
-    private <T extends RealFieldElement<T>> void doTestMap(final Field<T> field) {
-
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
-        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
-        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
-        int i1 = equation.addSecondaryEquations(secondary1);
-        FieldSecondaryEquations<T> secondary2 = new Linear<T>(field, 5, main.getDimension() + secondary1.getDimension());
-        int i2 = equation.addSecondaryEquations(secondary2);
-        Assert.assertEquals(main.getDimension() + secondary1.getDimension() + secondary2.getDimension(),
-                            equation.getMapper().getTotalDimension());
-        Assert.assertEquals(3, equation.getMapper().getNumberOfEquations());
-        Assert.assertEquals(1, i1);
-        Assert.assertEquals(2, i2);
-
-        T t0 = field.getZero().add(10);
-        T t  = field.getZero().add(100);
-        T[] complete    = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
-        for (int i = 0; i < complete.length; ++i) {
-            complete[i] = field.getZero().add(i);
-        }
-        equation.init(t0, complete, t);
-        T[] completeDot = equation.computeDerivatives(t0, complete);
-
-        try {
-            equation.getMapper().mapStateAndDerivative(t0, MathArrays.buildArray(field, complete.length + 1), completeDot);
-            Assert.fail("an exception should have been thrown");
-        } catch (DimensionMismatchException dme) {
-            // expected
-        }
-        try {
-            equation.getMapper().mapStateAndDerivative(t0, complete, MathArrays.buildArray(field, completeDot.length + 1));
-            Assert.fail("an exception should have been thrown");
-        } catch (DimensionMismatchException dme) {
-            // expected
-        }
-        FieldODEStateAndDerivative<T> state = equation.getMapper().mapStateAndDerivative(t0, complete, completeDot);
-        Assert.assertEquals(2, state.getNumberOfSecondaryStates());
-        Assert.assertEquals(main.getDimension(),       state.getSecondaryStateDimension(0));
-        Assert.assertEquals(secondary1.getDimension(), state.getSecondaryStateDimension(i1));
-        Assert.assertEquals(secondary2.getDimension(), state.getSecondaryStateDimension(i2));
-
-        T[] mainState             = state.getState();
-        T[] mainStateDot          = state.getDerivative();
-        T[] mainStateAlternate    = state.getSecondaryState(0);
-        T[] mainStateDotAlternate = state.getSecondaryDerivative(0);
-        Assert.assertEquals(main.getDimension(), mainState.length);
-        for (int i = 0; i < main.getDimension(); ++i) {
-            Assert.assertEquals(i, mainState[i].getReal(),             1.0e-15);
-            Assert.assertEquals(i, mainStateDot[i].getReal(),          1.0e-15);
-            Assert.assertEquals(i, mainStateAlternate[i].getReal(),    1.0e-15);
-            Assert.assertEquals(i, mainStateDotAlternate[i].getReal(), 1.0e-15);
-            Assert.assertEquals(i, completeDot[i].getReal(),           1.0e-15);
-        }
-
-        T[] secondaryState1    = state.getSecondaryState(i1);
-        T[] secondaryState1Dot = state.getSecondaryDerivative(i1);
-        Assert.assertEquals(secondary1.getDimension(), secondaryState1.length);
-        for (int i = 0; i < secondary1.getDimension(); ++i) {
-            Assert.assertEquals(i + main.getDimension(), secondaryState1[i].getReal(),   1.0e-15);
-            Assert.assertEquals(-i, secondaryState1Dot[i].getReal(), 1.0e-15);
-            Assert.assertEquals(-i, completeDot[i + main.getDimension()].getReal(),  1.0e-15);
-        }
-
-        T[] secondaryState2    = state.getSecondaryState(i2);
-        T[] secondaryState2Dot = state.getSecondaryDerivative(i2);
-        Assert.assertEquals(secondary2.getDimension(), secondaryState2.length);
-        for (int i = 0; i < secondary2.getDimension(); ++i) {
-            Assert.assertEquals(i + main.getDimension() + secondary1.getDimension(), secondaryState2[i].getReal(),   1.0e-15);
-            Assert.assertEquals(-i, secondaryState2Dot[i].getReal(), 1.0e-15);
-            Assert.assertEquals(-i, completeDot[i + main.getDimension() + secondary1.getDimension()].getReal(),  1.0e-15);
-        }
-
-        T[] remappedState = equation.getMapper().mapState(state);
-        T[] remappedDerivative = equation.getMapper().mapDerivative(state);
-        Assert.assertEquals(equation.getMapper().getTotalDimension(), remappedState.length);
-        Assert.assertEquals(equation.getMapper().getTotalDimension(), remappedDerivative.length);
-        for (int i = 0; i < remappedState.length; ++i) {
-            Assert.assertEquals(complete[i].getReal(),    remappedState[i].getReal(),      1.0e-15);
-            Assert.assertEquals(completeDot[i].getReal(), remappedDerivative[i].getReal(), 1.0e-15);
-        }
-    }
-
-    @Test(expected=DimensionMismatchException.class)
-    public void testExtractDimensionMismatch() {
-        doTestExtractDimensionMismatch(Decimal64Field.getInstance());
-    }
-
-    private <T extends RealFieldElement<T>> void doTestExtractDimensionMismatch(final Field<T> field)
-        throws DimensionMismatchException {
-
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
-        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
-        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
-        int i1 = equation.addSecondaryEquations(secondary1);
-        T[] tooShort    = MathArrays.buildArray(field, main.getDimension());
-        equation.getMapper().extractEquationData(i1, tooShort);
-    }
-
-    @Test(expected=DimensionMismatchException.class)
-    public void testInsertTooShortComplete() {
-        doTestInsertTooShortComplete(Decimal64Field.getInstance());
-    }
-
-    private <T extends RealFieldElement<T>> void doTestInsertTooShortComplete(final Field<T> field)
-        throws DimensionMismatchException {
-
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
-        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
-        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
-        int i1 = equation.addSecondaryEquations(secondary1);
-        T[] equationData = MathArrays.buildArray(field, secondary1.getDimension());
-        T[] tooShort     = MathArrays.buildArray(field, main.getDimension());
-        equation.getMapper().insertEquationData(i1, equationData, tooShort);
-    }
-
-    @Test(expected=DimensionMismatchException.class)
-    public void testInsertWrongEquationData() {
-        doTestInsertWrongEquationData(Decimal64Field.getInstance());
-    }
-
-    private <T extends RealFieldElement<T>> void doTestInsertWrongEquationData(final Field<T> field)
-        throws DimensionMismatchException {
-
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
-        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
-        FieldSecondaryEquations<T> secondary1 = new Linear<T>(field, 3, main.getDimension());
-        int i1 = equation.addSecondaryEquations(secondary1);
-        T[] wrongEquationData = MathArrays.buildArray(field, secondary1.getDimension() + 1);
-        T[] complete          = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
-        equation.getMapper().insertEquationData(i1, wrongEquationData, complete);
-    }
-
-    @Test(expected=MathIllegalArgumentException.class)
-    public void testNegativeIndex() {
-        doTestNegativeIndex(Decimal64Field.getInstance());
-    }
-
-    private <T extends RealFieldElement<T>> void doTestNegativeIndex(final Field<T> field)
-        throws MathIllegalArgumentException {
-
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
-        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
-        T[] complete = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
-        equation.getMapper().extractEquationData(-1, complete);
-    }
-
-    @Test(expected=MathIllegalArgumentException.class)
-    public void testTooLargeIndex() {
-        doTestTooLargeIndex(Decimal64Field.getInstance());
-    }
-
-    private <T extends RealFieldElement<T>> void doTestTooLargeIndex(final Field<T> field)
-        throws MathIllegalArgumentException {
-
-        FieldFirstOrderDifferentialEquations<T> main = new Linear<>(field, 3, 0);
-        FieldExpandableODE<T> equation = new FieldExpandableODE<T>(main);
-        T[] complete = MathArrays.buildArray(field, equation.getMapper().getTotalDimension());
-        equation.getMapper().extractEquationData(+1, complete);
-    }
-
-    private static class  Linear<T extends RealFieldElement<T>>
-        implements  FieldFirstOrderDifferentialEquations<T>, FieldSecondaryEquations<T> {
-
-        private final Field<T> field;
-        private final int dimension;
-        private final int start;
-
-        private Linear(final Field<T> field, final int dimension, final int start) {
-            this.field     = field;
-            this.dimension = dimension;
-            this.start     = start;
-        }
-
-        public int getDimension() {
-            return dimension;
-        }
-
-        public void init(final T t0, final T[] y0, final T finalTime) {
-            Assert.assertEquals(dimension, y0.length);
-            Assert.assertEquals(10.0,  t0.getReal(), 1.0e-15);
-            Assert.assertEquals(100.0, finalTime.getReal(), 1.0e-15);
-            for (int i = 0; i < y0.length; ++i) {
-                Assert.assertEquals(i, y0[i].getReal(), 1.0e-15);
-            }
-        }
-
-        public T[] computeDerivatives(final T t, final T[] y) {
-            final T[] yDot = MathArrays.buildArray(field, dimension);
-            for (int i = 0; i < dimension; ++i) {
-                yDot[i] = field.getZero().add(i);
-            }
-            return yDot;
-        }
-
-        public void init(final T t0, final T[] primary0, final T[] secondary0, final T finalTime) {
-            Assert.assertEquals(dimension, secondary0.length);
-            Assert.assertEquals(10.0,  t0.getReal(), 1.0e-15);
-            Assert.assertEquals(100.0, finalTime.getReal(), 1.0e-15);
-            for (int i = 0; i < primary0.length; ++i) {
-                Assert.assertEquals(i, primary0[i].getReal(), 1.0e-15);
-            }
-            for (int i = 0; i < secondary0.length; ++i) {
-                Assert.assertEquals(start + i, secondary0[i].getReal(), 1.0e-15);
-            }
-        }
-
-        public T[] computeDerivatives(final T t, final T[] primary, final T[] primaryDot, final T[] secondary) {
-            final T[] secondaryDot = MathArrays.buildArray(field, dimension);
-            for (int i = 0; i < dimension; ++i) {
-                secondaryDot[i] = field.getZero().subtract(i);
-            }
-            return secondaryDot;
-        }
-
-    }
-
-}


[24/50] [abbrv] [math] Fixed field-based Dormand-Prince 8(5, 3) integrator constants.

Posted by lu...@apache.org.
Fixed field-based Dormand-Prince 8(5,3) integrator constants.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/60afd02a
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/60afd02a
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/60afd02a

Branch: refs/heads/master
Commit: 60afd02a508bf721734eba66d1ddf412fb6d0970
Parents: 53af147
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:37 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:37 2016 +0100

----------------------------------------------------------------------
 .../DormandPrince853FieldIntegrator.java        | 54 ++++++++++----------
 1 file changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/60afd02a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
index 6c754d7..9f8e36c 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegrator.java
@@ -230,7 +230,7 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
         a[ 0][ 0] = sqrt6.add(-6).divide(-67.5);
 
         a[ 1][ 0] = sqrt6.add(-6).divide(-180);
-        a[ 1][ 1] = sqrt6.add(-6).divide( -40);
+        a[ 1][ 1] = sqrt6.add(-6).divide( -60);
 
         a[ 2][ 0] = sqrt6.add(-6).divide(-120);
         a[ 2][ 1] = getField().getZero();
@@ -259,7 +259,7 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
         a[ 6][ 2] = getField().getZero();
         a[ 6][ 3] = sqrt6.multiply( 4784).add(51544).divide(371293);
         a[ 6][ 4] = sqrt6.multiply(-4784).add(51544).divide(371293);
-        a[ 6][ 5] = fraction(-5688, 371283);
+        a[ 6][ 5] = fraction(-5688, 371293);
         a[ 6][ 6] = fraction( 3072, 371293);
 
         a[ 7][ 0] = fraction(58656157643.0, 93983540625.0);
@@ -320,47 +320,47 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
         a[11][11] = fraction(137909.0, 3084480.0);
 
         // the following stages are for interpolation only
-        a[12][ 0] = fraction(      13481885573.0, 240030000000.0)     .subtract(a[11][0]);
+        a[12][ 0] = fraction(      13481885573.0, 240030000000.0);
         a[12][ 1] = getField().getZero();
         a[12][ 2] = getField().getZero();
         a[12][ 3] = getField().getZero();
         a[12][ 4] = getField().getZero();
-        a[12][ 5] = getField().getZero()                              .subtract(a[11][5]);
-        a[12][ 6] = fraction(     139418837528.0, 549975234375.0)     .subtract(a[11][6]);
-        a[12][ 7] = fraction(  -11108320068443.0, 45111937500000.0)   .subtract(a[11][7]);
-        a[12][ 8] = fraction(-1769651421925959.0, 14249385146080000.0).subtract(a[11][8]);
-        a[12][ 9] = fraction(         57799439.0, 377055000.0)        .subtract(a[11][9]);
-        a[12][10] = fraction(     793322643029.0, 96734250000000.0)   .subtract(a[11][10]);
-        a[12][11] = fraction(       1458939311.0, 192780000000.0)     .subtract(a[11][11]);
+        a[12][ 5] = getField().getZero();
+        a[12][ 6] = fraction(     139418837528.0, 549975234375.0);
+        a[12][ 7] = fraction(  -11108320068443.0, 45111937500000.0);
+        a[12][ 8] = fraction(-1769651421925959.0, 14249385146080000.0);
+        a[12][ 9] = fraction(         57799439.0, 377055000.0);
+        a[12][10] = fraction(     793322643029.0, 96734250000000.0);
+        a[12][11] = fraction(       1458939311.0, 192780000000.0);
         a[12][12]  = fraction(            -4149.0, 500000.0);
 
-        a[13][ 0] = fraction(    1595561272731.0, 50120273500000.0)   .subtract(a[11][0]);
+        a[13][ 0] = fraction(    1595561272731.0, 50120273500000.0);
         a[13][ 1] = getField().getZero();
         a[13][ 2] = getField().getZero();
         a[13][ 3] = getField().getZero();
         a[13][ 4] = getField().getZero();
-        a[13][ 5] = fraction(     975183916491.0, 34457688031250.0)   .subtract(a[11][5]);
-        a[13][ 6] = fraction(   38492013932672.0, 718912673015625.0)  .subtract(a[11][6]);
-        a[13][ 7] = fraction(-1114881286517557.0, 20298710767500000.0).subtract(a[11][7]);
-        a[13][ 8] = getField().getZero()                              .subtract(a[11][8]);
-        a[13][ 9] = getField().getZero()                              .subtract(a[11][9]);
-        a[13][10] = fraction(   -2538710946863.0, 23431227861250000.0).subtract(a[11][10]);
-        a[13][11] = fraction(       8824659001.0, 23066716781250.0)   .subtract(a[11][11]);
+        a[13][ 5] = fraction(     975183916491.0, 34457688031250.0);
+        a[13][ 6] = fraction(   38492013932672.0, 718912673015625.0);
+        a[13][ 7] = fraction(-1114881286517557.0, 20298710767500000.0);
+        a[13][ 8] = getField().getZero();
+        a[13][ 9] = getField().getZero();
+        a[13][10] = fraction(   -2538710946863.0, 23431227861250000.0);
+        a[13][11] = fraction(       8824659001.0, 23066716781250.0);
         a[13][12] = fraction(     -11518334563.0, 33831184612500.0);
         a[13][13] = fraction(       1912306948.0, 13532473845.0);
 
-        a[14][ 0] = fraction(     -13613986967.0, 31741908048.0)      .subtract(a[11][0]);
+        a[14][ 0] = fraction(     -13613986967.0, 31741908048.0);
         a[14][ 1] = getField().getZero();
         a[14][ 2] = getField().getZero();
         a[14][ 3] = getField().getZero();
         a[14][ 4] = getField().getZero();
-        a[14][ 5] = fraction(      -4755612631.0, 1012344804.0)       .subtract(a[11][5]);
-        a[14][ 6] = fraction(   42939257944576.0, 5588559685701.0)    .subtract(a[11][6]);
-        a[14][ 7] = fraction(   77881972900277.0, 19140370552944.0)   .subtract(a[11][7]);
-        a[14][ 8] = fraction(   22719829234375.0, 63689648654052.0)   .subtract(a[11][8]);
-        a[14][ 9] = getField().getZero()                              .subtract(a[11][9]);
-        a[14][10] = getField().getZero()                              .subtract(a[11][10]);
-        a[14][11] = getField().getZero()                              .subtract(a[11][11]);
+        a[14][ 5] = fraction(      -4755612631.0, 1012344804.0);
+        a[14][ 6] = fraction(   42939257944576.0, 5588559685701.0);
+        a[14][ 7] = fraction(   77881972900277.0, 19140370552944.0);
+        a[14][ 8] = fraction(   22719829234375.0, 63689648654052.0);
+        a[14][ 9] = getField().getZero();
+        a[14][10] = getField().getZero();
+        a[14][11] = getField().getZero();
         a[14][12] = fraction(      -1199007803.0, 857031517296.0);
         a[14][13] = fraction(     157882067000.0, 53564469831.0);
         a[14][14] = fraction(    -290468882375.0, 31741908048.0);
@@ -373,7 +373,7 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
     @Override
     public T[] getB() {
         final T[] b = MathArrays.buildArray(getField(), 16);
-        b[ 0] = fraction(104257, 1929240);
+        b[ 0] = fraction(104257, 1920240);
         b[ 1] = getField().getZero();
         b[ 2] = getField().getZero();
         b[ 3] = getField().getZero();


[47/50] [abbrv] [math] Javadoc.

Posted by lu...@apache.org.
Javadoc.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/f0a39a86
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/f0a39a86
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/f0a39a86

Branch: refs/heads/master
Commit: f0a39a86864410beb84cf8898ea70f9fab7420e0
Parents: 8361fd7
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:20:29 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:20:29 2016 +0100

----------------------------------------------------------------------
 .../commons/math4/geometry/euclidean/threed/FieldRotation.java   | 4 ++--
 .../apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java  | 2 +-
 .../math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/f0a39a86/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java
index 4c7c888..2dc6933 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotation.java
@@ -112,7 +112,7 @@ public class FieldRotation<T extends RealFieldElement<T>> implements Serializabl
      * @param angle rotation angle.
      * @exception MathIllegalArgumentException if the axis norm is zero
      * @deprecated as of 3.6, replaced with {@link
-     * #FieldRotation(FieldVector3D, RealFieldElement, RotationConvention)
+     * #FieldRotation(FieldVector3D, RealFieldElement, RotationConvention)}
      */
     @Deprecated
     public FieldRotation(final FieldVector3D<T> axis, final T angle)
@@ -1401,7 +1401,7 @@ public class FieldRotation<T extends RealFieldElement<T>> implements Serializabl
     /** Apply the inverse of the instance to another rotation.
      * <p>
      * Calling this method is equivalent to call
-     * {@link #composeInverse(FieldRotation<T>, RotationConvention)
+     * {@link #composeInverse(FieldRotation, RotationConvention)
      * composeInverse(r, RotationConvention.VECTOR_OPERATOR)}.
      * </p>
      * @param r rotation to apply the rotation to

http://git-wip-us.apache.org/repos/asf/commons-math/blob/f0a39a86/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java
index 9039ca1..cb2061b 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsFieldIntegrator.java
@@ -119,7 +119,7 @@ public abstract class AdamsFieldIntegrator<T extends RealFieldElement<T>> extend
      * @param highOrder high order scaled derivatives
      * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
      * @return updated high order derivatives
-     * @see #updateHighOrderDerivativesPhase2(double[], double[], Array2DRowFieldMatrix)
+     * @see #updateHighOrderDerivativesPhase2(RealFieldElement[], RealFieldElement[], Array2DRowFieldMatrix)
      */
     public Array2DRowFieldMatrix<T> updateHighOrderDerivativesPhase1(final Array2DRowFieldMatrix<T> highOrder) {
         return transformer.updateHighOrderDerivativesPhase1(highOrder);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/f0a39a86/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java
index 93ec85e..c1e5bee 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsNordsieckFieldTransformer.java
@@ -327,7 +327,7 @@ public class AdamsNordsieckFieldTransformer<T extends RealFieldElement<T>> {
      * @param highOrder high order scaled derivatives
      * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
      * @return updated high order derivatives
-     * @see #updateHighOrderDerivativesPhase2(double[], double[], Array2DRowFieldMatrix)
+     * @see #updateHighOrderDerivativesPhase2(RealFieldElement[], RealFieldElement[], Array2DRowFieldMatrix)
      */
     public Array2DRowFieldMatrix<T> updateHighOrderDerivativesPhase1(final Array2DRowFieldMatrix<T> highOrder) {
         return update.multiply(highOrder);


[40/50] [abbrv] [math] Avoid protected fields.

Posted by lu...@apache.org.
Avoid protected fields.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/355b55e4
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/355b55e4
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/355b55e4

Branch: refs/heads/master
Commit: 355b55e4c6fa22a98983b745579c43077cc387b6
Parents: 346a81d
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:17:44 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:17:44 2016 +0100

----------------------------------------------------------------------
 .../math4/ode/AbstractFieldIntegrator.java      | 61 ++++++++++++++++++--
 .../commons/math4/ode/AbstractIntegrator.java   |  1 +
 .../AdaptiveStepsizeFieldIntegrator.java        |  4 +-
 .../EmbeddedRungeKuttaFieldIntegrator.java      | 50 ++++++++--------
 .../ode/nonstiff/RungeKuttaFieldIntegrator.java | 46 +++++++--------
 5 files changed, 108 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/355b55e4/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
index 41d7f15..c61da98 100644
--- a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
@@ -56,16 +56,19 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
     private static final double DEFAULT_FUNCTION_VALUE_ACCURACY = 1e-15;
 
     /** Step handler. */
-    protected Collection<FieldStepHandler<T>> stepHandlers;
+    private Collection<FieldStepHandler<T>> stepHandlers;
 
     /** Current step start. */
-    protected FieldODEStateAndDerivative<T> stepStart;
+    private FieldODEStateAndDerivative<T> stepStart;
 
     /** Current stepsize. */
-    protected T stepSize;
+    private T stepSize;
 
     /** Indicator for last step. */
-    protected boolean isLastStep;
+    private boolean isLastStep;
+
+    /** Indicator that a state or derivative reset was triggered by some event. */
+    private boolean resetOccurred;
 
     /** Field to which the time and state vector elements belong. */
     private final Field<T> field;
@@ -352,6 +355,7 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
                 }
 
                 FieldODEState<T> newState = null;
+                resetOccurred = false;
                 for (final FieldEventState<T> state : eventsStates) {
                     newState = state.reset(eventState);
                     if (newState != null) {
@@ -359,6 +363,7 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
                         // invalidate the derivatives, we need to recompute them
                         final T[] y    = equations.getMapper().mapState(newState);
                         final T[] yDot = computeDerivatives(newState.getTime(), y);
+                        resetOccurred = true;
                         return equations.getMapper().mapStateAndDerivative(newState.getTime(), y, yDot);
                     }
                 }
@@ -411,4 +416,52 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
 
     }
 
+    /** Check if a reset occurred while last step was accepted.
+     * @return true if a reset occurred while last step was accepted
+     */
+    protected boolean resetOccurred() {
+        return resetOccurred;
+    }
+
+    /** Set the current step size.
+     * @param stepSize step size to set
+     */
+    protected void setStepSize(final T stepSize) {
+        this.stepSize = stepSize;
+    }
+
+    /** Get the current step size.
+     * @return current step size
+     */
+    protected T getStepSize() {
+        return stepSize;
+    }
+    /** Set current step start.
+     * @param stepStart step start
+     */
+    protected void setStepStart(final FieldODEStateAndDerivative<T> stepStart) {
+        this.stepStart = stepStart;
+    }
+
+    /** Getcurrent step start.
+     * @return current step start
+     */
+    protected FieldODEStateAndDerivative<T> getStepStart() {
+        return stepStart;
+    }
+
+    /** Set the last state flag.
+     * @param isLastStep if true, this step is the last one
+     */
+    protected void setIsLastStep(final boolean isLastStep) {
+        this.isLastStep = isLastStep;
+    }
+
+    /** Check if this step is the last one.
+     * @return true if this step is the last one
+     */
+    protected boolean isLastStep() {
+        return isLastStep;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/355b55e4/src/main/java/org/apache/commons/math4/ode/AbstractIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/AbstractIntegrator.java b/src/main/java/org/apache/commons/math4/ode/AbstractIntegrator.java
index 4227917..072889a 100644
--- a/src/main/java/org/apache/commons/math4/ode/AbstractIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/AbstractIntegrator.java
@@ -399,6 +399,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator {
                 }
 
                 boolean needReset = false;
+                resetOccurred = false;
                 for (final EventState state : eventsStates) {
                     needReset =  needReset || state.reset(eventT, eventYComplete);
                 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/355b55e4/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java
index 3cdf2bb..ca774c3 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java
@@ -345,8 +345,8 @@ public abstract class AdaptiveStepsizeFieldIntegrator<T extends RealFieldElement
 
     /** Reset internal state to dummy values. */
     protected void resetInternalState() {
-        stepStart = null;
-        stepSize  = minStep.multiply(maxStep).sqrt();
+        setStepStart(null);
+        setStepSize(minStep.multiply(maxStep).sqrt());
     }
 
     /** Get the minimal step.

http://git-wip-us.apache.org/repos/asf/commons-math/blob/355b55e4/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
index c6e2444..acba7a5 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java
@@ -222,7 +222,7 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
         sanityChecks(initialState, finalTime);
         final T   t0 = initialState.getTime();
         final T[] y0 = equations.getMapper().mapState(initialState);
-        stepStart    = initIntegration(equations, t0, y0, finalTime);
+        setStepStart(initIntegration(equations, t0, y0, finalTime));
         final boolean forward = finalTime.subtract(initialState.getTime()).getReal() > 0;
 
         // create some internal working arrays
@@ -236,7 +236,7 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
         boolean firstTime = true;
 
         // main integration loop
-        isLastStep = false;
+        setIsLastStep(false);
         do {
 
             // iterate over step size, ensuring local normalized error is smaller than 1
@@ -244,8 +244,8 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
             while (error.subtract(1.0).getReal() >= 0) {
 
                 // first stage
-                y        = equations.getMapper().mapState(stepStart);
-                yDotK[0] = equations.getMapper().mapDerivative(stepStart);
+                y        = equations.getMapper().mapState(getStepStart());
+                yDotK[0] = equations.getMapper().mapDerivative(getStepStart());
 
                 if (firstTime) {
                     final T[] scale = MathArrays.buildArray(getField(), mainSetDimension);
@@ -258,18 +258,18 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
                             scale[i] = y[i].abs().multiply(vecRelativeTolerance[i]).add(vecAbsoluteTolerance[i]);
                         }
                     }
-                    hNew = initializeStep(forward, getOrder(), scale, stepStart, equations.getMapper());
+                    hNew = initializeStep(forward, getOrder(), scale, getStepStart(), equations.getMapper());
                     firstTime = false;
                 }
 
-                stepSize = hNew;
+                setStepSize(hNew);
                 if (forward) {
-                    if (stepStart.getTime().add(stepSize).subtract(finalTime).getReal() >= 0) {
-                        stepSize = finalTime.subtract(stepStart.getTime());
+                    if (getStepStart().getTime().add(getStepSize()).subtract(finalTime).getReal() >= 0) {
+                        setStepSize(finalTime.subtract(getStepStart().getTime()));
                     }
                 } else {
-                    if (stepStart.getTime().add(stepSize).subtract(finalTime).getReal() <= 0) {
-                        stepSize = finalTime.subtract(stepStart.getTime());
+                    if (getStepStart().getTime().add(getStepSize()).subtract(finalTime).getReal() <= 0) {
+                        setStepSize(finalTime.subtract(getStepStart().getTime()));
                     }
                 }
 
@@ -281,10 +281,10 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
                         for (int l = 1; l < k; ++l) {
                             sum = sum.add(yDotK[l][j].multiply(a[k-1][l]));
                         }
-                        yTmp[j] = y[j].add(stepSize.multiply(sum));
+                        yTmp[j] = y[j].add(getStepSize().multiply(sum));
                     }
 
-                    yDotK[k] = computeDerivatives(stepStart.getTime().add(stepSize.multiply(c[k-1])), yTmp);
+                    yDotK[k] = computeDerivatives(getStepStart().getTime().add(getStepSize().multiply(c[k-1])), yTmp);
 
                 }
 
@@ -294,53 +294,53 @@ public abstract class EmbeddedRungeKuttaFieldIntegrator<T extends RealFieldEleme
                     for (int l = 1; l < stages; ++l) {
                         sum = sum.add(yDotK[l][j].multiply(b[l]));
                     }
-                    yTmp[j] = y[j].add(stepSize.multiply(sum));
+                    yTmp[j] = y[j].add(getStepSize().multiply(sum));
                 }
 
                 // estimate the error at the end of the step
-                error = estimateError(yDotK, y, yTmp, stepSize);
+                error = estimateError(yDotK, y, yTmp, getStepSize());
                 if (error.subtract(1.0).getReal() >= 0) {
                     // reject the step and attempt to reduce error by stepsize control
                     final T factor = MathUtils.min(maxGrowth,
                                                    MathUtils.max(minReduction, safety.multiply(error.pow(exp))));
-                    hNew = filterStep(stepSize.multiply(factor), forward, false);
+                    hNew = filterStep(getStepSize().multiply(factor), forward, false);
                 }
 
             }
-            final T   stepEnd = stepStart.getTime().add(stepSize);
+            final T   stepEnd = getStepStart().getTime().add(getStepSize());
             final T[] yDotTmp = (fsal >= 0) ? yDotK[fsal] : computeDerivatives(stepEnd, yTmp);
             final FieldODEStateAndDerivative<T> stateTmp = new FieldODEStateAndDerivative<T>(stepEnd, yTmp, yDotTmp);
 
             // local error is small enough: accept the step, trigger events and step handlers
             System.arraycopy(yTmp, 0, y, 0, y0.length);
-            stepStart = acceptStep(createInterpolator(forward, yDotK, stepStart, stateTmp, equations.getMapper()),
-                                   finalTime);
+            setStepStart(acceptStep(createInterpolator(forward, yDotK, getStepStart(), stateTmp, equations.getMapper()),
+                                    finalTime));
 
-            if (!isLastStep) {
+            if (!isLastStep()) {
 
                 // stepsize control for next step
                 final T factor = MathUtils.min(maxGrowth,
                                                MathUtils.max(minReduction, safety.multiply(error.pow(exp))));
-                final T  scaledH    = stepSize.multiply(factor);
-                final T  nextT      = stepStart.getTime().add(scaledH);
+                final T  scaledH    = getStepSize().multiply(factor);
+                final T  nextT      = getStepStart().getTime().add(scaledH);
                 final boolean nextIsLast = forward ?
                                            nextT.subtract(finalTime).getReal() >= 0 :
                                            nextT.subtract(finalTime).getReal() <= 0;
                 hNew = filterStep(scaledH, forward, nextIsLast);
 
-                final T  filteredNextT      = stepStart.getTime().add(hNew);
+                final T  filteredNextT      = getStepStart().getTime().add(hNew);
                 final boolean filteredNextIsLast = forward ?
                                                    filteredNextT.subtract(finalTime).getReal() >= 0 :
                                                    filteredNextT.subtract(finalTime).getReal() <= 0;
                 if (filteredNextIsLast) {
-                    hNew = finalTime.subtract(stepStart.getTime());
+                    hNew = finalTime.subtract(getStepStart().getTime());
                 }
 
             }
 
-        } while (!isLastStep);
+        } while (!isLastStep());
 
-        final FieldODEStateAndDerivative<T> finalState = stepStart;
+        final FieldODEStateAndDerivative<T> finalState = getStepStart();
         resetInternalState();
         return finalState;
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/355b55e4/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
index 45ad237..8956fa4 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegrator.java
@@ -120,7 +120,7 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
         sanityChecks(initialState, finalTime);
         final T   t0 = initialState.getTime();
         final T[] y0 = equations.getMapper().mapState(initialState);
-        stepStart    = initIntegration(equations, t0, y0, finalTime);
+        setStepStart(initIntegration(equations, t0, y0, finalTime));
         final boolean forward = finalTime.subtract(initialState.getTime()).getReal() > 0;
 
         // create some internal working arrays
@@ -131,26 +131,26 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
 
         // set up integration control objects
         if (forward) {
-            if (stepStart.getTime().add(step).subtract(finalTime).getReal() >= 0) {
-                stepSize = finalTime.subtract(stepStart.getTime());
+            if (getStepStart().getTime().add(step).subtract(finalTime).getReal() >= 0) {
+                setStepSize(finalTime.subtract(getStepStart().getTime()));
             } else {
-                stepSize = step;
+                setStepSize(step);
             }
         } else {
-            if (stepStart.getTime().subtract(step).subtract(finalTime).getReal() <= 0) {
-                stepSize = finalTime.subtract(stepStart.getTime());
+            if (getStepStart().getTime().subtract(step).subtract(finalTime).getReal() <= 0) {
+                setStepSize(finalTime.subtract(getStepStart().getTime()));
             } else {
-                stepSize = step.negate();
+                setStepSize(step.negate());
             }
         }
 
         // main integration loop
-        isLastStep = false;
+        setIsLastStep(false);
         do {
 
             // first stage
-            y        = equations.getMapper().mapState(stepStart);
-            yDotK[0] = equations.getMapper().mapDerivative(stepStart);
+            y        = equations.getMapper().mapState(getStepStart());
+            yDotK[0] = equations.getMapper().mapDerivative(getStepStart());
 
             // next stages
             for (int k = 1; k < stages; ++k) {
@@ -160,10 +160,10 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
                     for (int l = 1; l < k; ++l) {
                         sum = sum.add(yDotK[l][j].multiply(a[k-1][l]));
                     }
-                    yTmp[j] = y[j].add(stepSize.multiply(sum));
+                    yTmp[j] = y[j].add(getStepSize().multiply(sum));
                 }
 
-                yDotK[k] = computeDerivatives(stepStart.getTime().add(stepSize.multiply(c[k-1])), yTmp);
+                yDotK[k] = computeDerivatives(getStepStart().getTime().add(getStepSize().multiply(c[k-1])), yTmp);
 
             }
 
@@ -173,34 +173,34 @@ public abstract class RungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
                 for (int l = 1; l < stages; ++l) {
                     sum = sum.add(yDotK[l][j].multiply(b[l]));
                 }
-                yTmp[j] = y[j].add(stepSize.multiply(sum));
+                yTmp[j] = y[j].add(getStepSize().multiply(sum));
             }
-            final T stepEnd   = stepStart.getTime().add(stepSize);
+            final T stepEnd   = getStepStart().getTime().add(getStepSize());
             final T[] yDotTmp = computeDerivatives(stepEnd, yTmp);
             final FieldODEStateAndDerivative<T> stateTmp = new FieldODEStateAndDerivative<T>(stepEnd, yTmp, yDotTmp);
 
             // discrete events handling
             System.arraycopy(yTmp, 0, y, 0, y0.length);
-            stepStart = acceptStep(createInterpolator(forward, yDotK, stepStart, stateTmp, equations.getMapper()),
-                                   finalTime);
+            setStepStart(acceptStep(createInterpolator(forward, yDotK, getStepStart(), stateTmp, equations.getMapper()),
+                                    finalTime));
 
-            if (!isLastStep) {
+            if (!isLastStep()) {
 
                 // stepsize control for next step
-                final T  nextT      = stepStart.getTime().add(stepSize);
+                final T  nextT      = getStepStart().getTime().add(getStepSize());
                 final boolean nextIsLast = forward ?
                                            (nextT.subtract(finalTime).getReal() >= 0) :
                                            (nextT.subtract(finalTime).getReal() <= 0);
                 if (nextIsLast) {
-                    stepSize = finalTime.subtract(stepStart.getTime());
+                    setStepSize(finalTime.subtract(getStepStart().getTime()));
                 }
             }
 
-        } while (!isLastStep);
+        } while (!isLastStep());
 
-        final FieldODEStateAndDerivative<T> finalState = stepStart;
-        stepStart = null;
-        stepSize  = null;
+        final FieldODEStateAndDerivative<T> finalState = getStepStart();
+        setStepStart(null);
+        setStepSize(null);
         return finalState;
 
     }


[50/50] [abbrv] [math] Reintroduced @Override as master needs at least Java 7.

Posted by lu...@apache.org.
Reintroduced @Override as master needs at least Java 7.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/e76bf903
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/e76bf903
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/e76bf903

Branch: refs/heads/master
Commit: e76bf903a268c242011618730cba7a7bae8d380c
Parents: 9d47e0f
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:29:16 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:29:16 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/math4/ode/MultistepFieldIntegrator.java     | 2 ++
 .../commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java    | 2 ++
 2 files changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/e76bf903/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
index d1ad3c8..fdb1d90 100644
--- a/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/MultistepFieldIntegrator.java
@@ -388,6 +388,7 @@ public abstract class MultistepFieldIntegrator<T extends RealFieldElement<T>>
         }
 
         /** {@inheritDoc} */
+        @Override
         public void handleStep(FieldStepInterpolator<T> interpolator, boolean isLast)
             throws MaxCountExceededException {
 
@@ -431,6 +432,7 @@ public abstract class MultistepFieldIntegrator<T extends RealFieldElement<T>>
         }
 
         /** {@inheritDoc} */
+        @Override
         public void init(final FieldODEStateAndDerivative<T> initialState, T finalTime) {
             // nothing to do
         }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/e76bf903/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java
index b09942d..c659cc0 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsMoultonFieldIntegrator.java
@@ -370,12 +370,14 @@ public class AdamsMoultonFieldIntegrator<T extends RealFieldElement<T>> extends
         }
 
         /** {@inheritDoc} */
+        @Override
         public void start(int rows, int columns,
                           int startRow, int endRow, int startColumn, int endColumn) {
             Arrays.fill(after, getField().getZero());
         }
 
         /** {@inheritDoc} */
+        @Override
         public void visit(int row, int column, T value) {
             if ((row & 0x1) == 0) {
                 after[column] = after[column].subtract(value);


[07/50] [abbrv] [math] Added test for classical Rung-Kutta step interpolator.

Posted by lu...@apache.org.
Added test for classical Rung-Kutta step interpolator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/7139af33
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/7139af33
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/7139af33

Branch: refs/heads/master
Commit: 7139af330bcc4cab7c19de4ff75b4d29f1618a56
Parents: 272a255
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:15 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:15 2016 +0100

----------------------------------------------------------------------
 ...sicalRungKuttaFieldStepInterpolatorTest.java | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/7139af33/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
new file mode 100644
index 0000000..a91c015
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class ClassicalRungKuttaFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
+        return new ClassicalRungeKuttaFieldStepInterpolator<T>(field, forward, mapper);
+    }
+
+    @Test
+    public void interpolationAtBounds() {
+        doInterpolationAtBounds(Decimal64Field.getInstance(), 1.0e-15);
+    }
+
+    @Test
+    public void interpolationInside() {
+        doInterpolationInside(Decimal64Field.getInstance(), 2.6e-7, 3.6e-6);
+    }
+
+}


[13/50] [abbrv] [math] Added new consistency tests.

Posted by lu...@apache.org.
Added new consistency tests.

We want the field-based integrators to be consistent with the regular
double-based integrators.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/235a0914
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/235a0914
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/235a0914

Branch: refs/heads/master
Commit: 235a0914e97fb3da2750a745c77fc01166bbb59f
Parents: c23335b
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:22 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:22 2016 +0100

----------------------------------------------------------------------
 ...ractRungeKuttaFieldStepInterpolatorTest.java | 124 ++++++++++++++++++-
 ...sicalRungKuttaFieldStepInterpolatorTest.java |   5 +
 .../EulerFieldStepInterpolatorTest.java         |   5 +
 .../nonstiff/GillFieldStepInterpolatorTest.java |   5 +
 .../LutherFieldStepInterpolatorTest.java        |   5 +
 .../MidpointFieldStepInterpolatorTest.java      |   5 +
 .../ThreeEighthesFieldStepInterpolatorTest.java |   5 +
 7 files changed, 152 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/235a0914/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
index 0ca38aa..a692717 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldStepInterpolatorTest.java
@@ -22,10 +22,12 @@ import java.lang.reflect.InvocationTargetException;
 
 import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.EquationsMapper;
 import org.apache.commons.math4.ode.FieldEquationsMapper;
 import org.apache.commons.math4.ode.FieldExpandableODE;
 import org.apache.commons.math4.ode.FieldFirstOrderDifferentialEquations;
 import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.sampling.AbstractFieldStepInterpolator;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathArrays;
 import org.junit.Assert;
@@ -86,6 +88,49 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     }
 
+    @Test
+    public abstract void nonFieldInterpolatorConsistency();
+
+    protected <T extends RealFieldElement<T>> void doNonFieldInterpolatorConsistency(final Field<T> field,
+                                                                                     double epsilonSin, double epsilonCos,
+                                                                                     double epsilonSinDot, double epsilonCosDot) {
+
+        RungeKuttaFieldStepInterpolator<T> fieldInterpolator =
+                        setUpInterpolator(field, new SinCos<>(field), 0.0, new double[] { 0.0, 1.0 }, 0.125);
+        RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator);
+
+        int n = 100;
+        double maxErrorSin    = 0;
+        double maxErrorCos    = 0;
+        double maxErrorSinDot = 0;
+        double maxErrorCosDot = 0;
+        for (int i = 0; i <= n; ++i) {
+
+            T t =     fieldInterpolator.getPreviousState().getTime().multiply(n - i).
+                  add(fieldInterpolator.getCurrentState().getTime().multiply(i)).
+                  divide(n);
+
+            FieldODEStateAndDerivative<T> state = fieldInterpolator.getInterpolatedState(t);
+            T[] fieldY    = state.getState();
+            T[] fieldYDot = state.getDerivative();
+
+            regularInterpolator.setInterpolatedTime(t.getReal());
+            double[] regularY     = regularInterpolator.getInterpolatedState();
+            double[] regularYDot  = regularInterpolator.getInterpolatedDerivatives();
+
+            maxErrorSin    = FastMath.max(maxErrorSin,    fieldY[0].subtract(regularY[0]).abs().getReal());
+            maxErrorCos    = FastMath.max(maxErrorCos,    fieldY[1].subtract(regularY[1]).abs().getReal());
+            maxErrorSinDot = FastMath.max(maxErrorSinDot, fieldYDot[0].subtract(regularYDot[0]).abs().getReal());
+            maxErrorCosDot = FastMath.max(maxErrorCosDot, fieldYDot[1].subtract(regularYDot[1]).abs().getReal());
+
+        }
+        Assert.assertEquals(0.0, maxErrorSin,    epsilonSin);
+        Assert.assertEquals(0.0, maxErrorCos,    epsilonCos);
+        Assert.assertEquals(0.0, maxErrorSinDot, epsilonSinDot);
+        Assert.assertEquals(0.0, maxErrorCosDot, epsilonCosDot);
+
+    }
+
     private <T extends RealFieldElement<T>>
     RungeKuttaFieldStepInterpolator<T> setUpInterpolator(final Field<T> field,
                                                          final FieldFirstOrderDifferentialEquations<T> eqn,
@@ -139,6 +184,81 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
 
     }
 
+    private <T extends RealFieldElement<T>>
+    RungeKuttaStepInterpolator convertInterpolator(final RungeKuttaFieldStepInterpolator<T> fieldInterpolator) {
+
+        RungeKuttaStepInterpolator regularInterpolator = null;
+        try {
+
+            String interpolatorName = fieldInterpolator.getClass().getName();
+            String integratorName = interpolatorName.replaceAll("Field", "");
+            @SuppressWarnings("unchecked")
+            Class<RungeKuttaStepInterpolator> clz = (Class<RungeKuttaStepInterpolator>) Class.forName(integratorName);
+            regularInterpolator = clz.newInstance();
+
+            double[][] yDotArray = null;
+            java.lang.reflect.Field fYD = RungeKuttaFieldStepInterpolator.class.getDeclaredField("yDotK");
+            fYD.setAccessible(true);
+            @SuppressWarnings("unchecked")
+            T[][] fieldYDotk = (T[][]) fYD.get(fieldInterpolator);
+            yDotArray = new double[fieldYDotk.length][];
+            for (int i = 0; i < yDotArray.length; ++i) {
+                yDotArray[i] = new double[fieldYDotk[i].length];
+                for (int j = 0; j < yDotArray[i].length; ++j) {
+                    yDotArray[i][j] = fieldYDotk[i][j].getReal();
+                }
+            }
+            double[] y = new double[yDotArray[0].length];
+
+            EquationsMapper primaryMapper = null;
+            EquationsMapper[] secondaryMappers = null;
+            java.lang.reflect.Field fMapper = AbstractFieldStepInterpolator.class.getDeclaredField("mapper");
+            fMapper.setAccessible(true);
+            @SuppressWarnings("unchecked")
+            FieldEquationsMapper<T> mapper = (FieldEquationsMapper<T>) fMapper.get(fieldInterpolator);
+            java.lang.reflect.Field fStart = FieldEquationsMapper.class.getDeclaredField("start");
+            fStart.setAccessible(true);
+            int[] start = (int[]) fStart.get(mapper);
+            primaryMapper = new EquationsMapper(start[0], start[1]);
+            secondaryMappers = new EquationsMapper[mapper.getNumberOfEquations() - 1];
+            for (int i = 0; i < secondaryMappers.length; ++i) {
+                secondaryMappers[i] = new EquationsMapper(start[i + 1], start[i + 2]);
+            }
+
+            regularInterpolator.reinitialize(null, y, yDotArray,
+                                             fieldInterpolator.isForward(),
+                                             primaryMapper, secondaryMappers);
+
+            T[] fieldPreviousY = fieldInterpolator.getPreviousState().getState();
+            for (int i = 0; i < y.length; ++i) {
+                y[i] = fieldPreviousY[i].getReal();
+            }
+            regularInterpolator.storeTime(fieldInterpolator.getPreviousState().getTime().getReal());
+
+            regularInterpolator.shift();
+
+            T[] fieldCurrentY = fieldInterpolator.getCurrentState().getState();
+            for (int i = 0; i < y.length; ++i) {
+                y[i] = fieldCurrentY[i].getReal();
+            }
+            regularInterpolator.storeTime(fieldInterpolator.getCurrentState().getTime().getReal());
+
+        } catch (ClassNotFoundException cnfe) {
+            Assert.fail(cnfe.getLocalizedMessage());
+        } catch (InstantiationException ie) {
+            Assert.fail(ie.getLocalizedMessage());
+        } catch (IllegalAccessException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (NoSuchFieldException nsfe) {
+            Assert.fail(nsfe.getLocalizedMessage());
+        } catch (IllegalArgumentException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        }
+
+        return regularInterpolator;
+
+    }
+
     private <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
     createFieldIntegrator(final Field<T> field, final RungeKuttaFieldStepInterpolator<T> interpolator) {
         RungeKuttaFieldIntegrator<T> integrator = null;
@@ -148,8 +268,8 @@ public abstract class AbstractRungeKuttaFieldStepInterpolatorTest {
             @SuppressWarnings("unchecked")
             Class<RungeKuttaFieldIntegrator<T>> clz = (Class<RungeKuttaFieldIntegrator<T>>) Class.forName(integratorName);
             try {
-                integrator = clz.getConstructor(Field.class, RealFieldElement.class).newInstance(field,
-                                                                                                      field.getOne());
+                integrator = clz.getConstructor(Field.class, RealFieldElement.class).
+                             newInstance(field, field.getOne());
             } catch (NoSuchMethodException nsme) {
                 try {
                     integrator = clz.getConstructor(Field.class,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/235a0914/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
index a91c015..d559200 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungKuttaFieldStepInterpolatorTest.java
@@ -41,4 +41,9 @@ public class ClassicalRungKuttaFieldStepInterpolatorTest extends AbstractRungeKu
         doInterpolationInside(Decimal64Field.getInstance(), 2.6e-7, 3.6e-6);
     }
 
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 2.8e-17, 1.2e-16, 2.3e-16, 1.0e-50);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/235a0914/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
index 6731827..b7fa85e 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
@@ -41,4 +41,9 @@ public class EulerFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepI
         doInterpolationInside(Decimal64Field.getInstance(), 3.3e-4, 7.9e-3);
     }
 
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.0e-50, 1.0e-50, 1.0e-50, 1.0e-50);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/235a0914/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
index 3334d4f..7dcc874 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
@@ -41,4 +41,9 @@ public class GillFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepIn
         doInterpolationInside(Decimal64Field.getInstance(), 2.6e-7, 3.6e-6);
     }
 
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.0e-50, 1.0e-50, 1.0e-50);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/235a0914/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
index 4fd73c0..4add8ca 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
@@ -41,4 +41,9 @@ public class LutherFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStep
         doInterpolationInside(Decimal64Field.getInstance(), 1.1e-7, 9.6e-9);
     }
 
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 8.4e-17, 2.3e-16, 2.1e-14, 1.3e-15);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/235a0914/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
index bb2a335..20dee47 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
@@ -41,4 +41,9 @@ public class MidpointFieldStepInterpolatorTest extends AbstractRungeKuttaFieldSt
         doInterpolationInside(Decimal64Field.getInstance(), 3.3e-4, 1.1e-5);
     }
 
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.0e-50, 1.0e-50, 1.0e-50, 1.0e-50);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/235a0914/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
index 9a6d818..6b956fa 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
@@ -41,4 +41,9 @@ public class ThreeEighthesFieldStepInterpolatorTest extends AbstractRungeKuttaFi
         doInterpolationInside(Decimal64Field.getInstance(), 2.6e-7, 3.6e-6);
     }
 
+    @Test
+    public void nonFieldInterpolatorConsistency() {
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 1.4e-17, 1.2e-16, 1.0e-50, 1.0e-50);
+    }
+
 }


[06/50] [abbrv] [math] Missing class parameter.

Posted by lu...@apache.org.
Missing class parameter.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/272a2550
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/272a2550
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/272a2550

Branch: refs/heads/master
Commit: 272a25500464aeb1a8b45657413cd2f93b7c53c5
Parents: 5246aa0
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:13 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:13 2016 +0100

----------------------------------------------------------------------
 .../commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/272a2550/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
index 9b10979..6731827 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldStepInterpolatorTest.java
@@ -28,7 +28,7 @@ public class EulerFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepI
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
-        return new EulerFieldStepInterpolator<>(field, forward, mapper);
+        return new EulerFieldStepInterpolator<T>(field, forward, mapper);
     }
 
     @Test


[43/50] [abbrv] [math] Field-based Adams-Bashforth integrator.

Posted by lu...@apache.org.
Field-based Adams-Bashforth integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/305934df
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/305934df
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/305934df

Branch: refs/heads/master
Commit: 305934dfbd2b37deb50cf93732e442c51bb1603b
Parents: dd9dc94
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:18:39 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:18:39 2016 +0100

----------------------------------------------------------------------
 .../nonstiff/AdamsBashforthFieldIntegrator.java | 374 +++++++++++++++++++
 .../AdamsBashforthFieldIntegratorTest.java      |  78 ++++
 2 files changed, 452 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/305934df/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java
new file mode 100644
index 0000000..db6bf4f
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegrator.java
@@ -0,0 +1,374 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+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.linear.Array2DRowFieldMatrix;
+import org.apache.commons.math4.linear.FieldMatrix;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FieldODEState;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.util.MathArrays;
+
+
+/**
+ * This class implements explicit Adams-Bashforth integrators for Ordinary
+ * Differential Equations.
+ *
+ * <p>Adams-Bashforth methods (in fact due to Adams alone) are explicit
+ * multistep ODE solvers. This implementation is a variation of the classical
+ * one: it uses adaptive stepsize to implement error control, whereas
+ * classical implementations are fixed step size. The value of state vector
+ * at step n+1 is a simple combination of the value at step n and of the
+ * derivatives at steps n, n-1, n-2 ... Depending on the number k of previous
+ * steps one wants to use for computing the next value, different formulas
+ * are available:</p>
+ * <ul>
+ *   <li>k = 1: y<sub>n+1</sub> = y<sub>n</sub> + h y'<sub>n</sub></li>
+ *   <li>k = 2: y<sub>n+1</sub> = y<sub>n</sub> + h (3y'<sub>n</sub>-y'<sub>n-1</sub>)/2</li>
+ *   <li>k = 3: y<sub>n+1</sub> = y<sub>n</sub> + h (23y'<sub>n</sub>-16y'<sub>n-1</sub>+5y'<sub>n-2</sub>)/12</li>
+ *   <li>k = 4: y<sub>n+1</sub> = y<sub>n</sub> + h (55y'<sub>n</sub>-59y'<sub>n-1</sub>+37y'<sub>n-2</sub>-9y'<sub>n-3</sub>)/24</li>
+ *   <li>...</li>
+ * </ul>
+ *
+ * <p>A k-steps Adams-Bashforth method is of order k.</p>
+ *
+ * <h3>Implementation details</h3>
+ *
+ * <p>We define scaled derivatives s<sub>i</sub>(n) at step n as:
+ * <pre>
+ * s<sub>1</sub>(n) = h y'<sub>n</sub> for first derivative
+ * s<sub>2</sub>(n) = h<sup>2</sup>/2 y''<sub>n</sub> for second derivative
+ * s<sub>3</sub>(n) = h<sup>3</sup>/6 y'''<sub>n</sub> for third derivative
+ * ...
+ * s<sub>k</sub>(n) = h<sup>k</sup>/k! y<sup>(k)</sup><sub>n</sub> for k<sup>th</sup> derivative
+ * </pre></p>
+ *
+ * <p>The definitions above use the classical representation with several previous first
+ * derivatives. Lets define
+ * <pre>
+ *   q<sub>n</sub> = [ s<sub>1</sub>(n-1) s<sub>1</sub>(n-2) ... s<sub>1</sub>(n-(k-1)) ]<sup>T</sup>
+ * </pre>
+ * (we omit the k index in the notation for clarity). With these definitions,
+ * Adams-Bashforth methods can be written:
+ * <ul>
+ *   <li>k = 1: y<sub>n+1</sub> = y<sub>n</sub> + s<sub>1</sub>(n)</li>
+ *   <li>k = 2: y<sub>n+1</sub> = y<sub>n</sub> + 3/2 s<sub>1</sub>(n) + [ -1/2 ] q<sub>n</sub></li>
+ *   <li>k = 3: y<sub>n+1</sub> = y<sub>n</sub> + 23/12 s<sub>1</sub>(n) + [ -16/12 5/12 ] q<sub>n</sub></li>
+ *   <li>k = 4: y<sub>n+1</sub> = y<sub>n</sub> + 55/24 s<sub>1</sub>(n) + [ -59/24 37/24 -9/24 ] q<sub>n</sub></li>
+ *   <li>...</li>
+ * </ul></p>
+ *
+ * <p>Instead of using the classical representation with first derivatives only (y<sub>n</sub>,
+ * s<sub>1</sub>(n) and q<sub>n</sub>), our implementation uses the Nordsieck vector with
+ * higher degrees scaled derivatives all taken at the same step (y<sub>n</sub>, s<sub>1</sub>(n)
+ * and r<sub>n</sub>) where r<sub>n</sub> is defined as:
+ * <pre>
+ * r<sub>n</sub> = [ s<sub>2</sub>(n), s<sub>3</sub>(n) ... s<sub>k</sub>(n) ]<sup>T</sup>
+ * </pre>
+ * (here again we omit the k index in the notation for clarity)
+ * </p>
+ *
+ * <p>Taylor series formulas show that for any index offset i, s<sub>1</sub>(n-i) can be
+ * computed from s<sub>1</sub>(n), s<sub>2</sub>(n) ... s<sub>k</sub>(n), the formula being exact
+ * for degree k polynomials.
+ * <pre>
+ * s<sub>1</sub>(n-i) = s<sub>1</sub>(n) + &sum;<sub>j&gt;0</sub> (j+1) (-i)<sup>j</sup> s<sub>j+1</sub>(n)
+ * </pre>
+ * The previous formula can be used with several values for i to compute the transform between
+ * classical representation and Nordsieck vector. The transform between r<sub>n</sub>
+ * and q<sub>n</sub> resulting from the Taylor series formulas above is:
+ * <pre>
+ * q<sub>n</sub> = s<sub>1</sub>(n) u + P r<sub>n</sub>
+ * </pre>
+ * where u is the [ 1 1 ... 1 ]<sup>T</sup> vector and P is the (k-1)&times;(k-1) matrix built
+ * with the (j+1) (-i)<sup>j</sup> terms with i being the row number starting from 1 and j being
+ * the column number starting from 1:
+ * <pre>
+ *        [  -2   3   -4    5  ... ]
+ *        [  -4  12  -32   80  ... ]
+ *   P =  [  -6  27 -108  405  ... ]
+ *        [  -8  48 -256 1280  ... ]
+ *        [          ...           ]
+ * </pre></p>
+ *
+ * <p>Using the Nordsieck vector has several advantages:
+ * <ul>
+ *   <li>it greatly simplifies step interpolation as the interpolator mainly applies
+ *   Taylor series formulas,</li>
+ *   <li>it simplifies step changes that occur when discrete events that truncate
+ *   the step are triggered,</li>
+ *   <li>it allows to extend the methods in order to support adaptive stepsize.</li>
+ * </ul></p>
+ *
+ * <p>The Nordsieck vector at step n+1 is computed from the Nordsieck vector at step n as follows:
+ * <ul>
+ *   <li>y<sub>n+1</sub> = y<sub>n</sub> + s<sub>1</sub>(n) + u<sup>T</sup> r<sub>n</sub></li>
+ *   <li>s<sub>1</sub>(n+1) = h f(t<sub>n+1</sub>, y<sub>n+1</sub>)</li>
+ *   <li>r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub></li>
+ * </ul>
+ * where A is a rows shifting matrix (the lower left part is an identity matrix):
+ * <pre>
+ *        [ 0 0   ...  0 0 | 0 ]
+ *        [ ---------------+---]
+ *        [ 1 0   ...  0 0 | 0 ]
+ *    A = [ 0 1   ...  0 0 | 0 ]
+ *        [       ...      | 0 ]
+ *        [ 0 0   ...  1 0 | 0 ]
+ *        [ 0 0   ...  0 1 | 0 ]
+ * </pre></p>
+ *
+ * <p>The P<sup>-1</sup>u vector and the P<sup>-1</sup> A P matrix do not depend on the state,
+ * they only depend on k and therefore are precomputed once for all.</p>
+ *
+ * @param <T> the type of the field elements
+ * @since 3.6
+ */
+public class AdamsBashforthFieldIntegrator<T extends RealFieldElement<T>> extends AdamsFieldIntegrator<T> {
+
+    /** Integrator method name. */
+    private static final String METHOD_NAME = "Adams-Bashforth";
+
+    /**
+     * Build an Adams-Bashforth integrator with the given order and step control parameters.
+     * @param field field to which the time and state vector elements belong
+     * @param nSteps number of steps of the method excluding the one being computed
+     * @param minStep minimal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param maxStep maximal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param scalAbsoluteTolerance allowed absolute error
+     * @param scalRelativeTolerance allowed relative error
+     * @exception NumberIsTooSmallException if order is 1 or less
+     */
+    public AdamsBashforthFieldIntegrator(final Field<T> field, final int nSteps,
+                                         final double minStep, final double maxStep,
+                                         final double scalAbsoluteTolerance,
+                                         final double scalRelativeTolerance)
+        throws NumberIsTooSmallException {
+        super(field, METHOD_NAME, nSteps, nSteps, minStep, maxStep,
+              scalAbsoluteTolerance, scalRelativeTolerance);
+    }
+
+    /**
+     * Build an Adams-Bashforth integrator with the given order and step control parameters.
+     * @param field field to which the time and state vector elements belong
+     * @param nSteps number of steps of the method excluding the one being computed
+     * @param minStep minimal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param maxStep maximal step (sign is irrelevant, regardless of
+     * integration direction, forward or backward), the last step can
+     * be smaller than this
+     * @param vecAbsoluteTolerance allowed absolute error
+     * @param vecRelativeTolerance allowed relative error
+     * @exception IllegalArgumentException if order is 1 or less
+     */
+    public AdamsBashforthFieldIntegrator(final Field<T> field, final int nSteps,
+                                         final double minStep, final double maxStep,
+                                         final double[] vecAbsoluteTolerance,
+                                         final double[] vecRelativeTolerance)
+        throws IllegalArgumentException {
+        super(field, METHOD_NAME, nSteps, nSteps, minStep, maxStep,
+              vecAbsoluteTolerance, vecRelativeTolerance);
+    }
+
+    /** Estimate error.
+     * <p>
+     * Error is estimated by interpolating back to previous state using
+     * the state Taylor expansion and comparing to real previous state.
+     * </p>
+     * @param previousState state vector at step start
+     * @param predictedState predicted state vector at step end
+     * @param predictedScaled predicted value of the scaled derivatives at step end
+     * @param predictedNordsieck predicted value of the Nordsieck vector at step end
+     * @return estimated normalized local discretization error
+     */
+    private T errorEstimation(final T[] previousState,
+                              final T[] predictedState,
+                              final T[] predictedScaled,
+                              final FieldMatrix<T> predictedNordsieck) {
+
+        T error = getField().getZero();
+        for (int i = 0; i < mainSetDimension; ++i) {
+            final T yScale = predictedState[i].abs();
+            final T tol = (vecAbsoluteTolerance == null) ?
+                          yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
+                          yScale.multiply(vecRelativeTolerance[i]).add(vecAbsoluteTolerance[i]);
+
+            // apply Taylor formula from high order to low order,
+            // for the sake of numerical accuracy
+            T variation = getField().getZero();
+            int sign = predictedNordsieck.getRowDimension() % 2 == 0 ? -1 : 1;
+            for (int k = predictedNordsieck.getRowDimension() - 1; k >= 0; --k) {
+                variation = variation.add(predictedNordsieck.getEntry(k, i).multiply(sign));
+                sign      = -sign;
+            }
+            variation = variation.subtract(predictedScaled[i]);
+
+            final T ratio  = predictedState[i].subtract(previousState[i]).add(variation).divide(tol);
+            error = error.add(ratio.multiply(ratio));
+
+        }
+
+        return error.divide(mainSetDimension).sqrt();
+
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public FieldODEStateAndDerivative<T> integrate(final FieldExpandableODE<T> equations,
+                                                   final FieldODEState<T> initialState,
+                                                   final T finalTime)
+        throws NumberIsTooSmallException, DimensionMismatchException,
+               MaxCountExceededException, NoBracketingException {
+
+        sanityChecks(initialState, finalTime);
+        final T   t0 = initialState.getTime();
+        final T[] y  = equations.getMapper().mapState(initialState);
+        setStepStart(initIntegration(equations, t0, y, finalTime));
+        final boolean forward = finalTime.subtract(initialState.getTime()).getReal() > 0;
+
+        // compute the initial Nordsieck vector using the configured starter integrator
+        start(equations, getStepStart(), finalTime);
+
+        // reuse the step that was chosen by the starter integrator
+        AdamsFieldStepInterpolator<T> interpolator =
+                        new AdamsFieldStepInterpolator<T>(getStepSize(), getStepStart(), scaled, nordsieck,
+                                                          forward, equations.getMapper());
+
+        // main integration loop
+        setIsLastStep(false);
+        do {
+
+            T[] predictedY = null;
+            final T[] predictedScaled = MathArrays.buildArray(getField(), y.length);
+            Array2DRowFieldMatrix<T> predictedNordsieck = null;
+            T error = getField().getZero().add(10);
+            while (error.subtract(1.0).getReal() >= 0.0) {
+
+                // predict a first estimate of the state at step end
+                final FieldODEStateAndDerivative<T> stepEnd = interpolator.getCurrentState();
+                predictedY = stepEnd.getState();
+
+                // evaluate the derivative
+                final T[] yDot = computeDerivatives(stepEnd.getTime(), predictedY);
+
+                // predict Nordsieck vector at step end
+                for (int j = 0; j < predictedScaled.length; ++j) {
+                    predictedScaled[j] = getStepSize().multiply(yDot[j]);
+                }
+                predictedNordsieck = updateHighOrderDerivativesPhase1(nordsieck);
+                updateHighOrderDerivativesPhase2(scaled, predictedScaled, predictedNordsieck);
+
+                // evaluate error
+                error = errorEstimation(y, predictedY, predictedScaled, predictedNordsieck);
+
+                if (error.subtract(1.0).getReal() >= 0.0) {
+                    // reject the step and attempt to reduce error by stepsize control
+                    final T factor = computeStepGrowShrinkFactor(error);
+                    rescale(filterStep(getStepSize().multiply(factor), forward, false));
+                    interpolator = new AdamsFieldStepInterpolator<T>(getStepSize(), getStepStart(), scaled, nordsieck,
+                                                                     forward, equations.getMapper());
+
+                }
+            }
+
+            // discrete events handling
+            System.arraycopy(predictedY, 0, y, 0, y.length);
+            setStepStart(acceptStep(interpolator, finalTime));
+            scaled    = predictedScaled;
+            nordsieck = predictedNordsieck;
+
+            if (!isLastStep()) {
+
+                if (resetOccurred()) {
+                    // some events handler has triggered changes that
+                    // invalidate the derivatives, we need to restart from scratch
+                    start(equations, getStepStart(), finalTime);
+                    interpolator = new AdamsFieldStepInterpolator<T>(getStepSize(), getStepStart(), scaled, nordsieck,
+                                                                     forward, equations.getMapper());
+                }
+
+                // stepsize control for next step
+                final T       factor     = computeStepGrowShrinkFactor(error);
+                final T       scaledH    = getStepSize().multiply(factor);
+                final T       nextT      = getStepStart().getTime().add(scaledH);
+                final boolean nextIsLast = forward ?
+                                           nextT.subtract(finalTime).getReal() >= 0 :
+                                           nextT.subtract(finalTime).getReal() <= 0;
+                T hNew = filterStep(scaledH, forward, nextIsLast);
+
+                final T       filteredNextT      = getStepStart().getTime().add(hNew);
+                final boolean filteredNextIsLast = forward ?
+                                                   filteredNextT.subtract(finalTime).getReal() >= 0 :
+                                                   filteredNextT.subtract(finalTime).getReal() <= 0;
+                if (filteredNextIsLast) {
+                    hNew = finalTime.subtract(getStepStart().getTime());
+                }
+
+                rescale(hNew);
+                interpolator = new AdamsFieldStepInterpolator<T>(getStepSize(), getStepStart(), scaled, nordsieck,
+                                                                 forward, equations.getMapper());
+
+            }
+
+        } while (!isLastStep());
+
+        final FieldODEStateAndDerivative<T> finalState = getStepStart();
+        setStepStart(null);
+        setStepSize(null);
+        return finalState;
+
+    }
+
+    /** Rescale the instance.
+     * <p>Since the scaled and Nordsieck arrays are shared with the caller,
+     * this method has the side effect of rescaling this arrays in the caller too.</p>
+     * @param newStepSize new step size to use in the scaled and Nordsieck arrays
+     */
+    public void rescale(final T newStepSize) {
+
+        final T ratio = newStepSize.divide(getStepSize());
+        for (int i = 0; i < scaled.length; ++i) {
+            scaled[i] = scaled[i].multiply(ratio);
+        }
+
+        final T[][] nData = nordsieck.getDataRef();
+        T power = ratio;
+        for (int i = 0; i < nData.length; ++i) {
+            power = power.multiply(ratio);
+            final T[] nDataI = nData[i];
+            for (int j = 0; j < nDataI.length; ++j) {
+                nDataI[j] = nDataI[j].multiply(power);
+            }
+        }
+
+        setStepSize(newStepSize);
+
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/305934df/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
new file mode 100644
index 0000000..408e646
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.MathIllegalStateException;
+import org.apache.commons.math4.exception.MaxCountExceededException;
+import org.apache.commons.math4.exception.NumberIsTooSmallException;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class AdamsBashforthFieldIntegratorTest extends AbstractAdamsFieldIntegratorTest {
+
+    protected <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
+    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance) {
+        return new AdamsBashforthFieldIntegrator<T>(field, nSteps, minStep, maxStep,
+                        scalAbsoluteTolerance, scalRelativeTolerance);
+    }
+
+    protected <T extends RealFieldElement<T>> AdamsFieldIntegrator<T>
+    createIntegrator(Field<T> field, final int nSteps, final double minStep, final double maxStep,
+                     final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) {
+        return new AdamsBashforthFieldIntegrator<T>(field, nSteps, minStep, maxStep,
+                        vecAbsoluteTolerance, vecRelativeTolerance);
+    }
+
+    @Test(expected=NumberIsTooSmallException.class)
+    public void testMinStep() {
+        doDimensionCheck(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testIncreasingTolerance() {
+        // the 7 and 121 factors are only valid for this test
+        // and has been obtained from trial and error
+        // there are no general relationship between local and global errors
+        doTestIncreasingTolerance(Decimal64Field.getInstance(), 7, 121);
+    }
+
+    @Test(expected = MaxCountExceededException.class)
+    public void exceedMaxEvaluations() {
+        doExceedMaxEvaluations(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void backward() {
+        doBackward(Decimal64Field.getInstance(), 4.3e-8, 4.3e-8, 1.0e-16, "Adams-Bashforth");
+    }
+
+    @Test
+    public void polynomial() {
+        doPolynomial(Decimal64Field.getInstance(), 5, 0.004, 6.0e-10);
+    }
+
+    @Test(expected=MathIllegalStateException.class)
+    public void testStartFailure() {
+        doTestStartFailure(Decimal64Field.getInstance());
+    }
+
+}


[12/50] [abbrv] [math] Fixed Luther step interpolator error.

Posted by lu...@apache.org.
Fixed Luther step interpolator error.

Now all tests related to the Luther integrator and step interpolator
pass.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/c23335ba
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/c23335ba
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/c23335ba

Branch: refs/heads/master
Commit: c23335bae449d804f21e949b220aa03c2f24f460
Parents: b5c1893
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:21 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:21 2016 +0100

----------------------------------------------------------------------
 .../nonstiff/LutherFieldStepInterpolator.java   | 34 ++++++++++----------
 .../ode/nonstiff/LutherFieldIntegratorTest.java | 16 ++++-----
 .../LutherFieldStepInterpolatorTest.java        |  2 +-
 3 files changed, 26 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/c23335ba/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
index 47eef54..a5dc565 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolator.java
@@ -88,13 +88,13 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
     LutherFieldStepInterpolator(final Field<T> field, final boolean forward,
                                 final FieldEquationsMapper<T> mapper) {
         super(field, forward, mapper);
-        final T q = field.getOne().multiply(21).sqrt();
+        final T q = field.getZero().add(21).sqrt();
         c5a = q.multiply(  -49).add(  -49);
         c5b = q.multiply(  287).add(  392);
         c5c = q.multiply( -357).add( -637);
         c5d = q.multiply(  343).add(  833);
         c6a = q.multiply(   49).add(  -49);
-        c6b = q.multiply( -287).add( -392);
+        c6b = q.multiply( -287).add(  392);
         c6c = q.multiply(  357).add( -637);
         c6d = q.multiply( -343).add(  833);
         d5a = q.multiply(   49).add(   49);
@@ -192,32 +192,32 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
         final T coeffDot4 =  theta.multiply(theta.multiply(theta.multiply(theta.multiply( -567  /  5.0).add( 972    /  5.0)).add( -486   / 5.0 )).add( 324    /  25.0));
         final T coeffDot5 =  theta.multiply(theta.multiply(theta.multiply(theta.multiply(c5a.divide(5)).add(c5b.divide(15))).add(c5c.divide(30))).add(c5d.divide(150)));
         final T coeffDot6 =  theta.multiply(theta.multiply(theta.multiply(theta.multiply(c6a.divide(5)).add(c6b.divide(15))).add(c6c.divide(30))).add(c6d.divide(150)));
-        final T coeffDot7 =  theta.multiply(theta.multiply(theta.multiply(                                              3 )).add(   -3         )).add(   3   /   5.0);
+        final T coeffDot7 =  theta.multiply(theta.multiply(theta.multiply(                                             3.0 ).add(   -3         )).add(   3   /   5.0));
         final T[] interpolatedState;
         final T[] interpolatedDerivatives;
 
         if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
 
-            final T s         = theta.multiply(theta.multiply(h));
-            final T coeff1    = s.multiply(theta.multiply(theta.multiply(theta.multiply(  21    /  5.0).add( -47    /  4.0)).add(   12         )).add( -27    /   5.0)).add(1);
+            final T s         = theta.multiply(h);
+            final T coeff1    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(  21    /  5.0).add( -47    /  4.0)).add(   12         )).add( -27    /   5.0)).add(1));
             final T coeff2    = getField().getZero();
-            final T coeff3    = s.multiply(theta.multiply(theta.multiply(theta.multiply( 112    /  5.0).add(-152    /  3.0)).add(  320   / 9.0 )).add(-104    /  15.0));
-            final T coeff4    = s.multiply(theta.multiply(theta.multiply(theta.multiply(-567    / 25.0).add( 243    /  5.0)).add( -162   / 5.0 )).add( 162    /  25.0));
-            final T coeff5    = s.multiply(theta.multiply(theta.multiply(theta.multiply(c5a.divide(25)).add(c5b.divide(60))).add(c5c.divide(90))).add(c5d.divide(300)));
-            final T coeff6    = s.multiply(theta.multiply(theta.multiply(theta.multiply(c5a.divide(25)).add(c6b.divide(60))).add(c6c.divide(90))).add(c6d.divide(300)));
-            final T coeff7    = s.multiply(theta.multiply(theta.multiply(                              3            /  4.0)).add(   -1         )).add(   3     /  10.0);
+            final T coeff3    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply( 112    /  5.0).add(-152    /  3.0)).add(  320   / 9.0 )).add(-104    /  15.0)));
+            final T coeff4    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(-567    / 25.0).add( 243    /  5.0)).add( -162   / 5.0 )).add( 162    /  25.0)));
+            final T coeff5    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(c5a.divide(25)).add(c5b.divide(60))).add(c5c.divide(90))).add(c5d.divide(300))));
+            final T coeff6    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(c6a.divide(25)).add(c6b.divide(60))).add(c6c.divide(90))).add(c6d.divide(300))));
+            final T coeff7    = s.multiply(theta.multiply(theta.multiply(theta.multiply(                                      3    /  4.0 ).add(   -1         )).add(   3    /  10.0)));
             interpolatedState       = previousStateLinearCombination(coeff1, coeff2, coeff3, coeff4, coeff5, coeff6, coeff7);
             interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4, coeffDot5, coeffDot6, coeffDot7);
         } else {
 
-            final T s         = oneMinusThetaH.multiply(theta);
-            final T coeff1    = s.multiply(theta.multiply(theta.multiply(theta.multiply( -21   /   5.0).add(   151  /  20.0)).add(  -89   /  20.0)).add(  19 /  20.0)).add( -1 /  20.0);
+            final T s         = oneMinusThetaH;
+            final T coeff1    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply( -21   /   5.0).add(   151  /  20.0)).add( -89   /   20.0)).add(  19 /  20.0)).add(- 1 / 20.0));
             final T coeff2    = getField().getZero();
-            final T coeff3    = s.multiply(theta.multiply(theta.multiply(theta.multiply(-112   /   5.0).add(   424  /  15.0)).add( -328   /  45.0)).add( -16 /  45.0)).add(-16 /  45.0);
-            final T coeff4    = s.multiply(theta.multiply(theta.multiply(theta.multiply( 567   /  25.0).add(  -648  /  25.0)).add(  162   /  25.0)));
-            final T coeff5    = s.multiply(theta.multiply(theta.multiply(theta.multiply(d5a.divide(25)).add(d5b.divide(300))).add(d5c.divide(900))).add( -49 / 180.0)).add(-49 / 180.0);
-            final T coeff6    = s.multiply(theta.multiply(theta.multiply(theta.multiply(d6a.divide(25)).add(d6b.divide(300))).add(d6c.divide(900))).add( -49 / 180.0)).add(-49 / 180.0);
-            final T coeff7    = s.multiply(theta.multiply(theta.multiply(                             -3            /   4.0 ).add(    1   /   4.0)).add(  -1 /  20.0)).add( -1 /  20.0);
+            final T coeff3    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(-112   /   5.0).add(   424  /  15.0)).add( -328  /   45.0)).add( -16 /  45.0)).add(-16 /  45.0));
+            final T coeff4    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply( 567   /  25.0).add(  -648  /  25.0)).add(  162  /   25.0))));
+            final T coeff5    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(d5a.divide(25)).add(d5b.divide(300))).add(d5c.divide(900))).add( -49 / 180.0)).add(-49 / 180.0));
+            final T coeff6    = s.multiply(theta.multiply(theta.multiply(theta.multiply(theta.multiply(d6a.divide(25)).add(d6b.divide(300))).add(d6c.divide(900))).add( -49 / 180.0)).add(-49 / 180.0));
+            final T coeff7    = s.multiply(               theta.multiply(theta.multiply(theta.multiply(                        -3  /   4.0 ).add(   1   /    4.0)).add(  -1 /  20.0)).add( -1 /  20.0));
             interpolatedState       = currentStateLinearCombination(coeff1, coeff2, coeff3, coeff4, coeff5, coeff6, coeff7);
             interpolatedDerivatives = derivativeLinearCombination(coeffDot1, coeffDot2, coeffDot3, coeffDot4, coeffDot5, coeffDot6, coeffDot7);
         }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/c23335ba/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
index 3a668b8..8d7040b 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
@@ -64,40 +64,40 @@ public class LutherFieldIntegratorTest extends AbstractRungeKuttaFieldIntegrator
     public void testSmallStep()
          throws DimensionMismatchException, NumberIsTooSmallException,
                 MaxCountExceededException, NoBracketingException {
-        doTestSmallStep(Decimal64Field.getInstance(), 9.0e-17, 4.0e-15, 1.0e-12, "Luther");
+        doTestSmallStep(Decimal64Field.getInstance(), 8.7e-17, 3.6e-15, 1.0e-12, "Luther");
     }
 
     @Test
     public void testBigStep()
         throws DimensionMismatchException, NumberIsTooSmallException,
                MaxCountExceededException, NoBracketingException {
-        doTestBigStep(Decimal64Field.getInstance(), 0.00002, 0.001, 1.0e-12, "Luther");
+        doTestBigStep(Decimal64Field.getInstance(), 2.7e-5, 1.7e-3, 1.0e-12, "Luther");
     }
 
     @Test
     public void testBackward()
         throws DimensionMismatchException, NumberIsTooSmallException,
                MaxCountExceededException, NoBracketingException {
-        doTestBackward(Decimal64Field.getInstance(), 3.0e-13, 5.0e-13, 1.0e-12, "Luther");
+        doTestBackward(Decimal64Field.getInstance(), 2.4e-13, 4.3e-13, 1.0e-12, "Luther");
     }
 
     @Test
     public void testKepler()
         throws DimensionMismatchException, NumberIsTooSmallException,
                MaxCountExceededException, NoBracketingException {
-        doTestKepler(Decimal64Field.getInstance(), 2.2e-7, 1.0e-8);
+        doTestKepler(Decimal64Field.getInstance(), 2.18e-7, 4.0e-10);
     }
 
     @Test
     public void testStepSize()
         throws DimensionMismatchException, NumberIsTooSmallException,
                MaxCountExceededException, NoBracketingException {
-        doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
+        doTestStepSize(Decimal64Field.getInstance(), 1.0e-22);
     }
 
     @Test
     public void testSingleStep() {
-        doTestSingleStep(Decimal64Field.getInstance(), 1.0e-11);
+        doTestSingleStep(Decimal64Field.getInstance(), 6.0e-12);
     }
 
     @Test
@@ -107,12 +107,12 @@ public class LutherFieldIntegratorTest extends AbstractRungeKuttaFieldIntegrator
 
     @Test
     public void testUnstableDerivative() {
-        doTestUnstableDerivative(Decimal64Field.getInstance(), 1.0e-12);
+        doTestUnstableDerivative(Decimal64Field.getInstance(), 4.0e-15);
     }
 
     @Test
     public void testDerivativesConsistency() {
-        doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-10);
+        doTestDerivativesConsistency(Decimal64Field.getInstance(), 1.0e-20);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/c23335ba/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
index de16bb9..4fd73c0 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
@@ -38,7 +38,7 @@ public class LutherFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStep
 
     @Test
     public void interpolationInside() {
-        doInterpolationInside(Decimal64Field.getInstance(), 3.3e-14, 7.9e-13);
+        doInterpolationInside(Decimal64Field.getInstance(), 1.1e-7, 9.6e-9);
     }
 
 }


[48/50] [abbrv] [math] Renamed abstract test classes to match build environment filters.

Posted by lu...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
index 3679f80..0630fcc 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class HighamHall54FieldIntegratorTest extends AbstractEmbeddedRungeKuttaFieldIntegratorTest {
+public class HighamHall54FieldIntegratorTest extends EmbeddedRungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, final double minStep, final double maxStep,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
index 4bbe6f0..12c9473 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class HighamHall54FieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class HighamHall54FieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
index 23fce20..9f459cf 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.exception.NoBracketingException;
 import org.apache.commons.math4.exception.NumberIsTooSmallException;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class LutherFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
+public class LutherFieldIntegratorTest extends RungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, T step) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
index 39ebdb9..e35e1ec 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class LutherFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class LutherFieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
index f6aadae..d983146 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class MidpointFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
+public class MidpointFieldIntegratorTest extends RungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, T step) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
index 6779c4a..b1008e5 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class MidpointFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class MidpointFieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegratorAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegratorAbstractTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegratorAbstractTest.java
new file mode 100644
index 0000000..788f732
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldIntegratorAbstractTest.java
@@ -0,0 +1,662 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+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;
+import org.apache.commons.math4.exception.NumberIsTooSmallException;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
+import org.apache.commons.math4.ode.FieldODEState;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.TestFieldProblem1;
+import org.apache.commons.math4.ode.TestFieldProblem2;
+import org.apache.commons.math4.ode.TestFieldProblem3;
+import org.apache.commons.math4.ode.TestFieldProblem4;
+import org.apache.commons.math4.ode.TestFieldProblem5;
+import org.apache.commons.math4.ode.TestFieldProblem6;
+import org.apache.commons.math4.ode.TestFieldProblemAbstract;
+import org.apache.commons.math4.ode.TestFieldProblemHandler;
+import org.apache.commons.math4.ode.events.Action;
+import org.apache.commons.math4.ode.events.FieldEventHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepHandler;
+import org.apache.commons.math4.ode.sampling.FieldStepInterpolator;
+import org.apache.commons.math4.ode.sampling.StepInterpolatorTestUtils;
+import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class RungeKuttaFieldIntegratorAbstractTest {
+
+    protected abstract <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
+        createIntegrator(Field<T> field, T step);
+
+    @Test
+    public abstract void testNonFieldIntegratorConsistency();
+
+    protected <T extends RealFieldElement<T>> void doTestNonFieldIntegratorConsistency(final Field<T> field) {
+        try {
+
+            // get the Butcher arrays from the field integrator
+            RungeKuttaFieldIntegrator<T> fieldIntegrator = createIntegrator(field, field.getZero().add(1));
+            T[][] fieldA = fieldIntegrator.getA();
+            T[]   fieldB = fieldIntegrator.getB();
+            T[]   fieldC = fieldIntegrator.getC();
+
+            String fieldName   = fieldIntegrator.getClass().getName();
+            String regularName = fieldName.replaceAll("Field", "");
+
+            // get the Butcher arrays from the regular integrator
+            @SuppressWarnings("unchecked")
+            Class<RungeKuttaIntegrator> c = (Class<RungeKuttaIntegrator>) Class.forName(regularName);
+            java.lang.reflect.Field jlrFieldA = c.getDeclaredField("STATIC_A");
+            jlrFieldA.setAccessible(true);
+            double[][] regularA = (double[][]) jlrFieldA.get(null);
+            java.lang.reflect.Field jlrFieldB = c.getDeclaredField("STATIC_B");
+            jlrFieldB.setAccessible(true);
+            double[]   regularB = (double[])   jlrFieldB.get(null);
+            java.lang.reflect.Field jlrFieldC = c.getDeclaredField("STATIC_C");
+            jlrFieldC.setAccessible(true);
+            double[]   regularC = (double[])   jlrFieldC.get(null);
+
+            Assert.assertEquals(regularA.length, fieldA.length);
+            for (int i = 0; i < regularA.length; ++i) {
+                checkArray(regularA[i], fieldA[i]);
+            }
+            checkArray(regularB, fieldB);
+            checkArray(regularC, fieldC);
+
+        } catch (ClassNotFoundException cnfe) {
+            Assert.fail(cnfe.getLocalizedMessage());
+        } catch (IllegalAccessException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (IllegalArgumentException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (SecurityException se) {
+            Assert.fail(se.getLocalizedMessage());
+        } catch (NoSuchFieldException nsfe) {
+            Assert.fail(nsfe.getLocalizedMessage());
+        }
+    }
+
+    private <T extends RealFieldElement<T>> void checkArray(double[] regularArray, T[] fieldArray) {
+        Assert.assertEquals(regularArray.length, fieldArray.length);
+        for (int i = 0; i < regularArray.length; ++i) {
+            if (regularArray[i] == 0) {
+                Assert.assertTrue(0.0 == fieldArray[i].getReal());
+            } else {
+                Assert.assertEquals(regularArray[i], fieldArray[i].getReal(), FastMath.ulp(regularArray[i]));
+            }
+        }
+    }
+
+    @Test
+    public abstract void testMissedEndEvent();
+
+    protected <T extends RealFieldElement<T>> void doTestMissedEndEvent(final Field<T> field,
+                                                                        final double epsilonT, final double epsilonY)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+            MaxCountExceededException, NoBracketingException {
+        final T   t0     = field.getZero().add(1878250320.0000029);
+        final T   tEvent = field.getZero().add(1878250379.9999986);
+        final T[] k      = MathArrays.buildArray(field, 3);
+        k[0] = field.getZero().add(1.0e-4);
+        k[1] = field.getZero().add(1.0e-5);
+        k[2] = field.getZero().add(1.0e-6);
+        FirstOrderFieldDifferentialEquations<T> ode = new FirstOrderFieldDifferentialEquations<T>() {
+
+            public int getDimension() {
+                return k.length;
+            }
+
+            public void init(T t0, T[] y0, T t) {
+            }
+
+            public T[] computeDerivatives(T t, T[] y) {
+                T[] yDot = MathArrays.buildArray(field, k.length);
+                for (int i = 0; i < y.length; ++i) {
+                    yDot[i] = k[i].multiply(y[i]);
+                }
+                return yDot;
+            }
+        };
+
+        RungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, field.getZero().add(60.0));
+
+        T[] y0   = MathArrays.buildArray(field, k.length);
+        for (int i = 0; i < y0.length; ++i) {
+            y0[i] = field.getOne().add(i);
+        }
+
+        FieldODEStateAndDerivative<T> result = integrator.integrate(new FieldExpandableODE<T>(ode),
+                                                                    new FieldODEState<T>(t0, y0),
+                                                                    tEvent);
+        Assert.assertEquals(tEvent.getReal(), result.getTime().getReal(), epsilonT);
+        T[] y = result.getState();
+        for (int i = 0; i < y.length; ++i) {
+            Assert.assertEquals(y0[i].multiply(k[i].multiply(result.getTime().subtract(t0)).exp()).getReal(),
+                                y[i].getReal(),
+                                epsilonY);
+        }
+
+        integrator.addEventHandler(new FieldEventHandler<T>() {
+
+            public void init(FieldODEStateAndDerivative<T> state0, T t) {
+            }
+
+            public FieldODEState<T> resetState(FieldODEStateAndDerivative<T> state) {
+                return state;
+            }
+
+            public T g(FieldODEStateAndDerivative<T> state) {
+                return state.getTime().subtract(tEvent);
+            }
+
+            public Action eventOccurred(FieldODEStateAndDerivative<T> state, boolean increasing) {
+                Assert.assertEquals(tEvent.getReal(), state.getTime().getReal(), epsilonT);
+                return Action.CONTINUE;
+            }
+        }, Double.POSITIVE_INFINITY, 1.0e-20, 100);
+        result = integrator.integrate(new FieldExpandableODE<T>(ode),
+                                      new FieldODEState<T>(t0, y0),
+                                      tEvent.add(120));
+        Assert.assertEquals(tEvent.add(120).getReal(), result.getTime().getReal(), epsilonT);
+        y = result.getState();
+        for (int i = 0; i < y.length; ++i) {
+            Assert.assertEquals(y0[i].multiply(k[i].multiply(result.getTime().subtract(t0)).exp()).getReal(),
+                                y[i].getReal(),
+                                epsilonY);
+        }
+
+    }
+
+    @Test
+    public abstract void testSanityChecks();
+
+    protected <T extends RealFieldElement<T>> void doTestSanityChecks(Field<T> field)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        RungeKuttaFieldIntegrator<T> integrator = createIntegrator(field, field.getZero().add(0.01));
+        try  {
+            TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+            integrator.integrate(new FieldExpandableODE<T>(pb),
+                                 new FieldODEState<T>(field.getZero(), MathArrays.buildArray(field, pb.getDimension() + 10)),
+                                 field.getOne());
+            Assert.fail("an exception should have been thrown");
+        } catch(DimensionMismatchException ie) {
+        }
+        try  {
+            TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+            integrator.integrate(new FieldExpandableODE<T>(pb),
+                                 new FieldODEState<T>(field.getZero(), MathArrays.buildArray(field, pb.getDimension())),
+                                 field.getZero());
+            Assert.fail("an exception should have been thrown");
+        } catch(NumberIsTooSmallException ie) {
+        }
+    }
+
+    @Test
+    public abstract void testDecreasingSteps();
+
+    protected <T extends RealFieldElement<T>> void doTestDecreasingSteps(Field<T> field,
+                                                                         final double safetyValueFactor,
+                                                                         final double safetyTimeFactor,
+                                                                         final double epsilonT)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+
+        @SuppressWarnings("unchecked")
+        TestFieldProblemAbstract<T>[] allProblems =
+                        (TestFieldProblemAbstract<T>[]) Array.newInstance(TestFieldProblemAbstract.class, 6);
+        allProblems[0] = new TestFieldProblem1<T>(field);
+        allProblems[1] = new TestFieldProblem2<T>(field);
+        allProblems[2] = new TestFieldProblem3<T>(field);
+        allProblems[3] = new TestFieldProblem4<T>(field);
+        allProblems[4] = new TestFieldProblem5<T>(field);
+        allProblems[5] = new TestFieldProblem6<T>(field);
+        for (TestFieldProblemAbstract<T> pb :  allProblems) {
+
+            T previousValueError = null;
+            T previousTimeError  = null;
+            for (int i = 4; i < 10; ++i) {
+
+                T step = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(FastMath.pow(2.0, -i));
+
+                RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
+                TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+                integ.addStepHandler(handler);
+                FieldEventHandler<T>[] functions = pb.getEventsHandlers();
+                for (int l = 0; l < functions.length; ++l) {
+                    integ.addEventHandler(functions[l],
+                                          Double.POSITIVE_INFINITY, 1.0e-6 * step.getReal(), 1000);
+                }
+                Assert.assertEquals(functions.length, integ.getEventHandlers().size());
+                FieldODEStateAndDerivative<T> stop = integ.integrate(new FieldExpandableODE<T>(pb),
+                                                                     pb.getInitialState(),
+                                                                     pb.getFinalTime());
+                if (functions.length == 0) {
+                    Assert.assertEquals(pb.getFinalTime().getReal(), stop.getTime().getReal(), epsilonT);
+                }
+
+                T error = handler.getMaximalValueError();
+                if (i > 4) {
+                    Assert.assertTrue(error.subtract(previousValueError.abs().multiply(safetyValueFactor)).getReal() < 0);
+                }
+                previousValueError = error;
+
+                T timeError = handler.getMaximalTimeError();
+                if (i > 4) {
+                    Assert.assertTrue(timeError.subtract(previousTimeError.abs().multiply(safetyTimeFactor)).getReal() <= 0);
+                }
+                previousTimeError = timeError;
+
+                integ.clearEventHandlers();
+                Assert.assertEquals(0, integ.getEventHandlers().size());
+            }
+
+        }
+
+    }
+
+    @Test
+    public abstract void testSmallStep();
+
+    protected <T extends RealFieldElement<T>> void doTestSmallStep(Field<T> field,
+                                                                   final double epsilonLast,
+                                                                   final double epsilonMaxValue,
+                                                                   final double epsilonMaxTime,
+                                                                   final String name)
+         throws DimensionMismatchException, NumberIsTooSmallException,
+                MaxCountExceededException, NoBracketingException {
+
+        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        T step = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.001);
+
+        RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+        Assert.assertEquals(0, handler.getLastError().getReal(),         epsilonLast);
+        Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
+        Assert.assertEquals(0, handler.getMaximalTimeError().getReal(),  epsilonMaxTime);
+        Assert.assertEquals(name, integ.getName());
+
+    }
+
+    @Test
+    public abstract void testBigStep();
+
+    protected <T extends RealFieldElement<T>> void doTestBigStep(Field<T> field,
+                                                                 final double belowLast,
+                                                                 final double belowMaxValue,
+                                                                 final double epsilonMaxTime,
+                                                                 final String name)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+
+        TestFieldProblem1<T> pb = new TestFieldProblem1<T>(field);
+        T step = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.2);
+
+        RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+        Assert.assertTrue(handler.getLastError().getReal()         > belowLast);
+        Assert.assertTrue(handler.getMaximalValueError().getReal() > belowMaxValue);
+        Assert.assertEquals(0, handler.getMaximalTimeError().getReal(),  epsilonMaxTime);
+        Assert.assertEquals(name, integ.getName());
+
+    }
+
+    @Test
+    public abstract void testBackward();
+
+    protected <T extends RealFieldElement<T>> void doTestBackward(Field<T> field,
+                                                                  final double epsilonLast,
+                                                                  final double epsilonMaxValue,
+                                                                  final double epsilonMaxTime,
+                                                                  final String name)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+
+        TestFieldProblem5<T> pb = new TestFieldProblem5<T>(field);
+        T step = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.001).abs();
+
+        RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
+        TestFieldProblemHandler<T> handler = new TestFieldProblemHandler<T>(pb, integ);
+        integ.addStepHandler(handler);
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+
+        Assert.assertEquals(0, handler.getLastError().getReal(),         epsilonLast);
+        Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
+        Assert.assertEquals(0, handler.getMaximalTimeError().getReal(),  epsilonMaxTime);
+        Assert.assertEquals(name, integ.getName());
+
+    }
+
+    @Test
+    public abstract void testKepler();
+
+    protected <T extends RealFieldElement<T>> void doTestKepler(Field<T> field, double expectedMaxError, double epsilon)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+
+        final TestFieldProblem3<T> pb  = new TestFieldProblem3<T>(field, field.getZero().add(0.9));
+        T step = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.0003);
+
+        RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
+        integ.addStepHandler(new KeplerHandler<T>(pb, expectedMaxError, epsilon));
+        integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
+    }
+
+    private static class KeplerHandler<T extends RealFieldElement<T>> implements FieldStepHandler<T> {
+        private T maxError;
+        private final TestFieldProblem3<T> pb;
+        private final double expectedMaxError;
+        private final double epsilon;
+        public KeplerHandler(TestFieldProblem3<T> pb, double expectedMaxError, double epsilon) {
+            this.pb               = pb;
+            this.expectedMaxError = expectedMaxError;
+            this.epsilon          = epsilon;
+            maxError = pb.getField().getZero();
+        }
+        public void init(FieldODEStateAndDerivative<T> state0, T t) {
+            maxError = pb.getField().getZero();
+        }
+        public void handleStep(FieldStepInterpolator<T> interpolator, boolean isLast)
+                        throws MaxCountExceededException {
+
+            FieldODEStateAndDerivative<T> current = interpolator.getCurrentState();
+            T[] theoreticalY  = pb.computeTheoreticalState(current.getTime());
+            T dx = current.getState()[0].subtract(theoreticalY[0]);
+            T dy = current.getState()[1].subtract(theoreticalY[1]);
+            T error = dx.multiply(dx).add(dy.multiply(dy));
+            if (error.subtract(maxError).getReal() > 0) {
+                maxError = error;
+            }
+            if (isLast) {
+                Assert.assertEquals(expectedMaxError, maxError.getReal(), epsilon);
+            }
+        }
+    }
+
+    @Test
+    public abstract void testStepSize();
+
+    protected <T extends RealFieldElement<T>> void doTestStepSize(final Field<T> field, final double epsilon)
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        final T step = field.getZero().add(1.23456);
+        RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, step);
+        integ.addStepHandler(new FieldStepHandler<T>() {
+            public void handleStep(FieldStepInterpolator<T> interpolator, boolean isLast) {
+                if (! isLast) {
+                    Assert.assertEquals(step.getReal(),
+                                        interpolator.getCurrentState().getTime().subtract(interpolator.getPreviousState().getTime()).getReal(),
+                                        epsilon);
+                }
+            }
+            public void init(FieldODEStateAndDerivative<T> s0, T t) {
+            }
+        });
+        integ.integrate(new FieldExpandableODE<T>(new FirstOrderFieldDifferentialEquations<T>() {
+            public void init(T t0, T[] y0, T t) {
+            }
+            public T[] computeDerivatives(T t, T[] y) {
+                T[] dot = MathArrays.buildArray(t.getField(), 1);
+                dot[0] = t.getField().getOne();
+                return dot;
+            }
+            public int getDimension() {
+                return 1;
+            }
+        }), new FieldODEState<T>(field.getZero(), MathArrays.buildArray(field, 1)), field.getZero().add(5.0));
+    }
+
+    @Test
+    public abstract void testSingleStep();
+
+    protected <T extends RealFieldElement<T>> void doTestSingleStep(final Field<T> field, final double epsilon) {
+
+        final TestFieldProblem3<T> pb  = new TestFieldProblem3<T>(field, field.getZero().add(0.9));
+        T h = pb.getFinalTime().subtract(pb.getInitialState().getTime()).multiply(0.0003);
+
+        RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, field.getZero().add(Double.NaN));
+        T   t = pb.getInitialState().getTime();
+        T[] y = pb.getInitialState().getState();
+        for (int i = 0; i < 100; ++i) {
+            y = integ.singleStep(pb, t, y, t.add(h));
+            t = t.add(h);
+        }
+        T[] yth = pb.computeTheoreticalState(t);
+        T dx = y[0].subtract(yth[0]);
+        T dy = y[1].subtract(yth[1]);
+        T error = dx.multiply(dx).add(dy.multiply(dy));
+        Assert.assertEquals(0.0, error.getReal(), epsilon);
+    }
+
+    @Test
+    public abstract void testTooLargeFirstStep();
+
+    protected <T extends RealFieldElement<T>> void doTestTooLargeFirstStep(final Field<T> field) {
+
+        RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, field.getZero().add(0.5));
+        final T t0 = field.getZero();
+        final T[] y0 = MathArrays.buildArray(field, 1);
+        y0[0] = field.getOne();
+        final T t   = field.getZero().add(0.001);
+        FirstOrderFieldDifferentialEquations<T> equations = new FirstOrderFieldDifferentialEquations<T>() {
+
+            public int getDimension() {
+                return 1;
+            }
+
+            public void init(T t0, T[] y0, T t) {
+            }
+
+            public T[] computeDerivatives(T t, T[] y) {
+                Assert.assertTrue(t.getReal() >= FastMath.nextAfter(t0.getReal(), Double.NEGATIVE_INFINITY));
+                Assert.assertTrue(t.getReal() <= FastMath.nextAfter(t.getReal(),   Double.POSITIVE_INFINITY));
+                T[] yDot = MathArrays.buildArray(field, 1);
+                yDot[0] = y[0].multiply(-100.0);
+                return yDot;
+            }
+
+        };
+
+        integ.integrate(new FieldExpandableODE<T>(equations), new FieldODEState<T>(t0, y0), t);
+
+    }
+
+    @Test
+    public abstract void testUnstableDerivative();
+
+    protected <T extends RealFieldElement<T>> void doTestUnstableDerivative(Field<T> field, double epsilon) {
+      final StepFieldProblem<T> stepProblem = new StepFieldProblem<T>(field,
+                                                                      field.getZero().add(0.0),
+                                                                      field.getZero().add(1.0),
+                                                                      field.getZero().add(2.0));
+      RungeKuttaFieldIntegrator<T> integ = createIntegrator(field, field.getZero().add(0.3));
+      integ.addEventHandler(stepProblem, 1.0, 1.0e-12, 1000);
+      FieldODEStateAndDerivative<T> result = integ.integrate(new FieldExpandableODE<T>(stepProblem),
+                                                             new FieldODEState<T>(field.getZero(), MathArrays.buildArray(field, 1)),
+                                                             field.getZero().add(10.0));
+      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);
+    }
+
+    @Test
+    public abstract void testPartialDerivatives();
+
+    protected 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 FirstOrderFieldDifferentialEquations<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 }
+            };
+
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolatorAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolatorAbstractTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolatorAbstractTest.java
new file mode 100644
index 0000000..0205a8d
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/RungeKuttaFieldStepInterpolatorAbstractTest.java
@@ -0,0 +1,305 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.AbstractIntegrator;
+import org.apache.commons.math4.ode.EquationsMapper;
+import org.apache.commons.math4.ode.ExpandableStatefulODE;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.ode.FieldExpandableODE;
+import org.apache.commons.math4.ode.FirstOrderFieldDifferentialEquations;
+import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
+import org.apache.commons.math4.ode.sampling.AbstractFieldStepInterpolator;
+import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.util.MathArrays;
+import org.junit.Assert;
+import org.junit.Test;
+
+public abstract class RungeKuttaFieldStepInterpolatorAbstractTest {
+
+    protected abstract <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+        createInterpolator(Field<T> field, boolean forward, T[][] yDotK,
+                           FieldODEStateAndDerivative<T> globalPreviousState,
+                           FieldODEStateAndDerivative<T> globalCurrentState,
+                           FieldODEStateAndDerivative<T> softPreviousState,
+                           FieldODEStateAndDerivative<T> softCurrentState,
+                           FieldEquationsMapper<T> mapper);
+
+    protected abstract <T extends RealFieldElement<T>> FieldButcherArrayProvider<T>
+        createButcherArrayProvider(final Field<T> field);
+
+    @Test
+    public abstract void interpolationAtBounds();
+
+    protected <T extends RealFieldElement<T>> void doInterpolationAtBounds(final Field<T> field, double epsilon) {
+
+        RungeKuttaFieldStepInterpolator<T> interpolator = setUpInterpolator(field,
+                                                                            new SinCos<T>(field),
+                                                                            0.0, new double[] { 0.0, 1.0 }, 0.125);
+
+        Assert.assertEquals(0.0, interpolator.getPreviousState().getTime().getReal(), 1.0e-15);
+        for (int i = 0; i < 2; ++i) {
+            Assert.assertEquals(interpolator.getPreviousState().getState()[i].getReal(),
+                                interpolator.getInterpolatedState(interpolator.getPreviousState().getTime()).getState()[i].getReal(),
+                                epsilon);
+        }
+        Assert.assertEquals(0.125, interpolator.getCurrentState().getTime().getReal(), 1.0e-15);
+        for (int i = 0; i < 2; ++i) {
+            Assert.assertEquals(interpolator.getCurrentState().getState()[i].getReal(),
+                                interpolator.getInterpolatedState(interpolator.getCurrentState().getTime()).getState()[i].getReal(),
+                                epsilon);
+        }
+
+    }
+
+    @Test
+    public abstract void interpolationInside();
+
+    protected <T extends RealFieldElement<T>> void doInterpolationInside(final Field<T> field,
+                                                                         double epsilonSin, double epsilonCos) {
+
+        RungeKuttaFieldStepInterpolator<T> interpolator = setUpInterpolator(field,
+                                                                            new SinCos<T>(field),
+                                                                            0.0, new double[] { 0.0, 1.0 }, 0.0125);
+
+        int n = 100;
+        double maxErrorSin = 0;
+        double maxErrorCos = 0;
+        for (int i = 0; i <= n; ++i) {
+            T t =     interpolator.getPreviousState().getTime().multiply(n - i).
+                  add(interpolator.getCurrentState().getTime().multiply(i)).
+                  divide(n);
+            FieldODEStateAndDerivative<T> state = interpolator.getInterpolatedState(t);
+            maxErrorSin = FastMath.max(maxErrorSin, state.getState()[0].subtract(t.sin()).abs().getReal());
+            maxErrorCos = FastMath.max(maxErrorCos, state.getState()[1].subtract(t.cos()).abs().getReal());
+        }
+        Assert.assertEquals(0.0, maxErrorSin, epsilonSin);
+        Assert.assertEquals(0.0, maxErrorCos, epsilonCos);
+
+    }
+
+    @Test
+    public abstract void nonFieldInterpolatorConsistency();
+
+    protected <T extends RealFieldElement<T>> void doNonFieldInterpolatorConsistency(final Field<T> field,
+                                                                                     double epsilonSin, double epsilonCos,
+                                                                                     double epsilonSinDot, double epsilonCosDot) {
+
+        FirstOrderFieldDifferentialEquations<T> eqn = new SinCos<T>(field);
+        RungeKuttaFieldStepInterpolator<T> fieldInterpolator =
+                        setUpInterpolator(field, eqn, 0.0, new double[] { 0.0, 1.0 }, 0.125);
+        RungeKuttaStepInterpolator regularInterpolator = convertInterpolator(fieldInterpolator, eqn);
+
+        int n = 100;
+        double maxErrorSin    = 0;
+        double maxErrorCos    = 0;
+        double maxErrorSinDot = 0;
+        double maxErrorCosDot = 0;
+        for (int i = 0; i <= n; ++i) {
+
+            T t =     fieldInterpolator.getPreviousState().getTime().multiply(n - i).
+                  add(fieldInterpolator.getCurrentState().getTime().multiply(i)).
+                  divide(n);
+
+            FieldODEStateAndDerivative<T> state = fieldInterpolator.getInterpolatedState(t);
+            T[] fieldY    = state.getState();
+            T[] fieldYDot = state.getDerivative();
+
+            regularInterpolator.setInterpolatedTime(t.getReal());
+            double[] regularY     = regularInterpolator.getInterpolatedState();
+            double[] regularYDot  = regularInterpolator.getInterpolatedDerivatives();
+
+            maxErrorSin    = FastMath.max(maxErrorSin,    fieldY[0].subtract(regularY[0]).abs().getReal());
+            maxErrorCos    = FastMath.max(maxErrorCos,    fieldY[1].subtract(regularY[1]).abs().getReal());
+            maxErrorSinDot = FastMath.max(maxErrorSinDot, fieldYDot[0].subtract(regularYDot[0]).abs().getReal());
+            maxErrorCosDot = FastMath.max(maxErrorCosDot, fieldYDot[1].subtract(regularYDot[1]).abs().getReal());
+
+        }
+        Assert.assertEquals(0.0, maxErrorSin,    epsilonSin);
+        Assert.assertEquals(0.0, maxErrorCos,    epsilonCos);
+        Assert.assertEquals(0.0, maxErrorSinDot, epsilonSinDot);
+        Assert.assertEquals(0.0, maxErrorCosDot, epsilonCosDot);
+
+    }
+
+    private <T extends RealFieldElement<T>>
+    RungeKuttaFieldStepInterpolator<T> setUpInterpolator(final Field<T> field,
+                                                         final FirstOrderFieldDifferentialEquations<T> eqn,
+                                                         final double t0, final double[] y0,
+                                                         final double t1) {
+
+        // get the Butcher arrays from the field integrator
+        FieldButcherArrayProvider<T> provider = createButcherArrayProvider(field);
+        T[][] a = provider.getA();
+        T[]   b = provider.getB();
+        T[]   c = provider.getC();
+
+        // store initial state
+        T     t          = field.getZero().add(t0);
+        T[]   fieldY     = MathArrays.buildArray(field, eqn.getDimension());
+        T[][] fieldYDotK = MathArrays.buildArray(field, b.length, -1);
+        for (int i = 0; i < y0.length; ++i) {
+            fieldY[i] = field.getZero().add(y0[i]);
+        }
+        fieldYDotK[0] = eqn.computeDerivatives(t, fieldY);
+        FieldODEStateAndDerivative<T> s0 = new FieldODEStateAndDerivative<T>(t, fieldY, fieldYDotK[0]);
+
+        // perform one integration step, in order to get consistent derivatives
+        T h = field.getZero().add(t1 - t0);
+        for (int k = 0; k < a.length; ++k) {
+            for (int i = 0; i < y0.length; ++i) {
+                fieldY[i] = field.getZero().add(y0[i]);
+                for (int s = 0; s <= k; ++s) {
+                    fieldY[i] = fieldY[i].add(h.multiply(a[k][s].multiply(fieldYDotK[s][i])));
+                }
+            }
+            fieldYDotK[k + 1] = eqn.computeDerivatives(h.multiply(c[k]).add(t0), fieldY);
+        }
+
+        // store state at step end
+        t = field.getZero().add(t1);
+        for (int i = 0; i < y0.length; ++i) {
+            fieldY[i] = field.getZero().add(y0[i]);
+            for (int s = 0; s < b.length; ++s) {
+                fieldY[i] = fieldY[i].add(h.multiply(b[s].multiply(fieldYDotK[s][i])));
+            }
+        }
+        FieldODEStateAndDerivative<T> s1 = new FieldODEStateAndDerivative<T>(t, fieldY,
+                                                                             eqn.computeDerivatives(t, fieldY));
+
+        return createInterpolator(field, t1 > t0, fieldYDotK, s0, s1, s0, s1,
+                                  new FieldExpandableODE<T>(eqn).getMapper());
+
+    }
+
+    private <T extends RealFieldElement<T>>
+    RungeKuttaStepInterpolator convertInterpolator(final RungeKuttaFieldStepInterpolator<T> fieldInterpolator,
+                                                   final FirstOrderFieldDifferentialEquations<T> eqn) {
+
+        RungeKuttaStepInterpolator regularInterpolator = null;
+        try {
+
+            String interpolatorName = fieldInterpolator.getClass().getName();
+            String integratorName = interpolatorName.replaceAll("Field", "");
+            @SuppressWarnings("unchecked")
+            Class<RungeKuttaStepInterpolator> clz = (Class<RungeKuttaStepInterpolator>) Class.forName(integratorName);
+            regularInterpolator = clz.newInstance();
+
+            double[][] yDotArray = null;
+            java.lang.reflect.Field fYD = RungeKuttaFieldStepInterpolator.class.getDeclaredField("yDotK");
+            fYD.setAccessible(true);
+            @SuppressWarnings("unchecked")
+            T[][] fieldYDotk = (T[][]) fYD.get(fieldInterpolator);
+            yDotArray = new double[fieldYDotk.length][];
+            for (int i = 0; i < yDotArray.length; ++i) {
+                yDotArray[i] = new double[fieldYDotk[i].length];
+                for (int j = 0; j < yDotArray[i].length; ++j) {
+                    yDotArray[i][j] = fieldYDotk[i][j].getReal();
+                }
+            }
+            double[] y = new double[yDotArray[0].length];
+
+            EquationsMapper primaryMapper = null;
+            EquationsMapper[] secondaryMappers = null;
+            java.lang.reflect.Field fMapper = AbstractFieldStepInterpolator.class.getDeclaredField("mapper");
+            fMapper.setAccessible(true);
+            @SuppressWarnings("unchecked")
+            FieldEquationsMapper<T> mapper = (FieldEquationsMapper<T>) fMapper.get(fieldInterpolator);
+            java.lang.reflect.Field fStart = FieldEquationsMapper.class.getDeclaredField("start");
+            fStart.setAccessible(true);
+            int[] start = (int[]) fStart.get(mapper);
+            primaryMapper = new EquationsMapper(start[0], start[1]);
+            secondaryMappers = new EquationsMapper[mapper.getNumberOfEquations() - 1];
+            for (int i = 0; i < secondaryMappers.length; ++i) {
+                secondaryMappers[i] = new EquationsMapper(start[i + 1], start[i + 2]);
+            }
+
+            AbstractIntegrator dummyIntegrator = new AbstractIntegrator("dummy") {
+                @Override
+                public void integrate(ExpandableStatefulODE equations, double t) {
+                    Assert.fail("this method should not be called");
+                }
+                @Override
+                public void computeDerivatives(final double t, final double[] y, final double[] yDot) {
+                    T fieldT = fieldInterpolator.getCurrentState().getTime().getField().getZero().add(t);
+                    T[] fieldY = MathArrays.buildArray(fieldInterpolator.getCurrentState().getTime().getField(), y.length);
+                    for (int i = 0; i < y.length; ++i) {
+                        fieldY[i] = fieldInterpolator.getCurrentState().getTime().getField().getZero().add(y[i]);
+                    }
+                    T[] fieldYDot = eqn.computeDerivatives(fieldT, fieldY);
+                    for (int i = 0; i < yDot.length; ++i) {
+                        yDot[i] = fieldYDot[i].getReal();
+                    }
+                }
+            };
+            regularInterpolator.reinitialize(dummyIntegrator, y, yDotArray,
+                                             fieldInterpolator.isForward(),
+                                             primaryMapper, secondaryMappers);
+
+            T[] fieldPreviousY = fieldInterpolator.getPreviousState().getState();
+            for (int i = 0; i < y.length; ++i) {
+                y[i] = fieldPreviousY[i].getReal();
+            }
+            regularInterpolator.storeTime(fieldInterpolator.getPreviousState().getTime().getReal());
+
+            regularInterpolator.shift();
+
+            T[] fieldCurrentY = fieldInterpolator.getCurrentState().getState();
+            for (int i = 0; i < y.length; ++i) {
+                y[i] = fieldCurrentY[i].getReal();
+            }
+            regularInterpolator.storeTime(fieldInterpolator.getCurrentState().getTime().getReal());
+
+        } catch (ClassNotFoundException cnfe) {
+            Assert.fail(cnfe.getLocalizedMessage());
+        } catch (InstantiationException ie) {
+            Assert.fail(ie.getLocalizedMessage());
+        } catch (IllegalAccessException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        } catch (NoSuchFieldException nsfe) {
+            Assert.fail(nsfe.getLocalizedMessage());
+        } catch (IllegalArgumentException iae) {
+            Assert.fail(iae.getLocalizedMessage());
+        }
+
+        return regularInterpolator;
+
+    }
+
+    private static class SinCos<T extends RealFieldElement<T>> implements FirstOrderFieldDifferentialEquations<T> {
+        private final Field<T> field;
+        protected SinCos(final Field<T> field) {
+            this.field = field;
+        }
+        public int getDimension() {
+            return 2;
+        }
+        public void init(final T t0, final T[] y0, final T finalTime) {
+        }
+        public T[] computeDerivatives(final T t, final T[] y) {
+            T[] yDot = MathArrays.buildArray(field, 2);
+            yDot[0] = y[1];
+            yDot[1] = y[0].negate();
+            return yDot;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
index c00c987..fd481ba 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.math4.Field;
 import org.apache.commons.math4.RealFieldElement;
 import org.apache.commons.math4.util.Decimal64Field;
 
-public class ThreeEighthesFieldIntegratorTest extends AbstractRungeKuttaFieldIntegratorTest {
+public class ThreeEighthesFieldIntegratorTest extends RungeKuttaFieldIntegratorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, T step) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d47e0f9/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
index 6891e02..86ed2f9 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldStepInterpolatorTest.java
@@ -25,7 +25,7 @@ import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
 import org.apache.commons.math4.util.Decimal64Field;
 import org.junit.Test;
 
-public class ThreeEighthesFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+public class ThreeEighthesFieldStepInterpolatorTest extends RungeKuttaFieldStepInterpolatorAbstractTest {
 
     protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
     createInterpolator(Field<T> field, boolean forward, T[][] yDotK,


[09/50] [abbrv] [math] Added test for Gill step interpolator.

Posted by lu...@apache.org.
Added test for Gill step interpolator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/ba6f4a44
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/ba6f4a44
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/ba6f4a44

Branch: refs/heads/master
Commit: ba6f4a44799a1ed0f7aea6762b658f7d5ef05f1b
Parents: 756ba33
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:17 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:17 2016 +0100

----------------------------------------------------------------------
 .../nonstiff/GillFieldStepInterpolatorTest.java | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/ba6f4a44/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
new file mode 100644
index 0000000..3334d4f
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldStepInterpolatorTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.ode.FieldEquationsMapper;
+import org.apache.commons.math4.util.Decimal64Field;
+import org.junit.Test;
+
+public class GillFieldStepInterpolatorTest extends AbstractRungeKuttaFieldStepInterpolatorTest {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldStepInterpolator<T>
+    createInterpolator(Field<T> field, boolean forward, FieldEquationsMapper<T> mapper) {
+        return new GillFieldStepInterpolator<T>(field, forward, mapper);
+    }
+
+    @Test
+    public void interpolationAtBounds() {
+        doInterpolationAtBounds(Decimal64Field.getInstance(), 1.0e-15);
+    }
+
+    @Test
+    public void interpolationInside() {
+        doInterpolationInside(Decimal64Field.getInstance(), 2.6e-7, 3.6e-6);
+    }
+
+}


[36/50] [abbrv] [math] Added tests with DerivativeStructure field.

Posted by lu...@apache.org.
Added tests with DerivativeStructure field.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a2efc6b6
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a2efc6b6
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a2efc6b6

Branch: refs/heads/master
Commit: a2efc6b6b998a511666079b6d4c63ac38f215648
Parents: 1d4d89e
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:30:34 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:30:34 2016 +0100

----------------------------------------------------------------------
 ...ctEmbeddedRungeKuttaFieldIntegratorTest.java | 141 +++++++++++++++++++
 .../AbstractRungeKuttaFieldIntegratorTest.java  | 141 +++++++++++++++++++
 .../ClassicalRungeKuttaFieldIntegratorTest.java |  32 +++--
 .../DormandPrince54FieldIntegratorTest.java     |  14 +-
 .../DormandPrince853FieldIntegratorTest.java    |  14 +-
 .../ode/nonstiff/EulerFieldIntegratorTest.java  |  32 +++--
 .../ode/nonstiff/GillFieldIntegratorTest.java   |  32 +++--
 .../HighamHall54FieldIntegratorTest.java        |  14 +-
 .../ode/nonstiff/LutherFieldIntegratorTest.java |  32 +++--
 .../nonstiff/MidpointFieldIntegratorTest.java   |  32 +++--
 .../ThreeEighthesFieldIntegratorTest.java       |  32 +++--
 11 files changed, 417 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
index 26a7364..0f3449f 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
@@ -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 }
+            };
+
+        }
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
index 80d6251..cc130d7 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
@@ -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 }
+            };
+
+        }
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
index f2ece27..eec1b56 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ClassicalRungeKuttaFieldIntegratorTest.java
@@ -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 });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
index d25c4ad..75416ce 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
@@ -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 });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
index ca777ba..065b24a 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince853FieldIntegratorTest.java
@@ -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 });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
index 4d93ca3..1a44551 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/EulerFieldIntegratorTest.java
@@ -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 });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
index 7b4ad50..a04c6eb 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/GillFieldIntegratorTest.java
@@ -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 });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
index d24d286..3679f80 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/HighamHall54FieldIntegratorTest.java
@@ -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 });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
index 8d7040b..23fce20 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
@@ -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 });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
index cc8eb8d..f6aadae 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
@@ -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 });
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a2efc6b6/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
index 3feb0cd..c00c987 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegratorTest.java
@@ -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 });
+    }
+
 }


[02/50] [abbrv] [math] Added tests for midpoint integrator.

Posted by lu...@apache.org.
Added tests for midpoint integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/34f1f6a4
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/34f1f6a4
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/34f1f6a4

Branch: refs/heads/master
Commit: 34f1f6a485cf3dbe9270cbf0232cab986ba13cd2
Parents: de90332
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:07 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:07 2016 +0100

----------------------------------------------------------------------
 .../nonstiff/MidpointFieldIntegratorTest.java   | 99 ++++++++++++++++++++
 1 file changed, 99 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/34f1f6a4/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
new file mode 100644
index 0000000..cc8eb8d
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/MidpointFieldIntegratorTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.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 {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, T step) {
+        return new MidpointFieldIntegrator<T>(field, step);
+    }
+
+    @Test
+    public void testNonFieldIntegratorConsistency() {
+        doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testMissedEndEvent() {
+        doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 6.0e-5);
+    }
+
+    @Test
+    public void testSanityChecks() {
+        doTestSanityChecks(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testDecreasingSteps() {
+        doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
+    }
+
+    @Test
+    public void testSmallStep() {
+        doTestSmallStep(Decimal64Field.getInstance(), 2.0e-7, 1.0e-6, 1.0e-12, "midpoint");
+    }
+
+    @Test
+    public void testBigStep() {
+        doTestBigStep(Decimal64Field.getInstance(), 0.01, 0.05, 1.0e-12, "midpoint");
+
+    }
+
+    @Test
+    public void testBackward() {
+        doTestBackward(Decimal64Field.getInstance(), 6.0e-4, 6.0e-4, 1.0e-12, "midpoint");
+    }
+
+    @Test
+    public void testKepler() {
+        doTestKepler(Decimal64Field.getInstance(), 1.19, 0.01);
+    }
+
+    @Test
+    public void testStepSize() {
+        doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
+    }
+
+    @Test
+    public void testSingleStep() {
+        doTestSingleStep(Decimal64Field.getInstance(), 0.21);
+    }
+
+    @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);
+    }
+
+}


[41/50] [abbrv] [math] typos.

Posted by lu...@apache.org.
typos.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/2a498498
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/2a498498
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/2a498498

Branch: refs/heads/master
Commit: 2a4984980af61442ce8b9009c8c86bb94b2bab4c
Parents: 355b55e
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 14:18:08 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 14:18:08 2016 +0100

----------------------------------------------------------------------
 .../AbstractEmbeddedRungeKuttaFieldIntegratorTest.java       | 6 +++---
 .../ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java  | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/2a498498/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
index 9314b27..61372f5 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractEmbeddedRungeKuttaFieldIntegratorTest.java
@@ -48,7 +48,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
 
     protected abstract <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, final double minStep, final double maxStep,
-                     final double scalAbsoluteTolerance, final double scalRelativeTolerance) ;
+                     final double scalAbsoluteTolerance, final double scalRelativeTolerance);
 
     protected abstract <T extends RealFieldElement<T>> EmbeddedRungeKuttaFieldIntegrator<T>
     createIntegrator(Field<T> field, final double minStep, final double maxStep,
@@ -384,7 +384,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
     public abstract void testBackward();
 
     protected <T extends RealFieldElement<T>> void doTestBackward(Field<T> field,
-                                                                  final double espilonLast,
+                                                                  final double epsilonLast,
                                                                   final double epsilonMaxValue,
                                                                   final double epsilonMaxTime,
                                                                   final String name)
@@ -404,7 +404,7 @@ public abstract class AbstractEmbeddedRungeKuttaFieldIntegratorTest {
         integ.addStepHandler(handler);
         integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
 
-        Assert.assertEquals(0, handler.getLastError().getReal(),         espilonLast);
+        Assert.assertEquals(0, handler.getLastError().getReal(),         epsilonLast);
         Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
         Assert.assertEquals(0, handler.getMaximalTimeError().getReal(),  epsilonMaxTime);
         Assert.assertEquals(name, integ.getName());

http://git-wip-us.apache.org/repos/asf/commons-math/blob/2a498498/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
index ae56e6b..d79a19f 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/AbstractRungeKuttaFieldIntegratorTest.java
@@ -285,7 +285,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
     public abstract void testSmallStep();
 
     protected <T extends RealFieldElement<T>> void doTestSmallStep(Field<T> field,
-                                                                   final double espilonLast,
+                                                                   final double epsilonLast,
                                                                    final double epsilonMaxValue,
                                                                    final double epsilonMaxTime,
                                                                    final String name)
@@ -300,7 +300,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
         integ.addStepHandler(handler);
         integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
 
-        Assert.assertEquals(0, handler.getLastError().getReal(),         espilonLast);
+        Assert.assertEquals(0, handler.getLastError().getReal(),         epsilonLast);
         Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
         Assert.assertEquals(0, handler.getMaximalTimeError().getReal(),  epsilonMaxTime);
         Assert.assertEquals(name, integ.getName());
@@ -337,7 +337,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
     public abstract void testBackward();
 
     protected <T extends RealFieldElement<T>> void doTestBackward(Field<T> field,
-                                                                  final double espilonLast,
+                                                                  final double epsilonLast,
                                                                   final double epsilonMaxValue,
                                                                   final double epsilonMaxTime,
                                                                   final String name)
@@ -352,7 +352,7 @@ public abstract class AbstractRungeKuttaFieldIntegratorTest {
         integ.addStepHandler(handler);
         integ.integrate(new FieldExpandableODE<T>(pb), pb.getInitialState(), pb.getFinalTime());
 
-        Assert.assertEquals(0, handler.getLastError().getReal(),         espilonLast);
+        Assert.assertEquals(0, handler.getLastError().getReal(),         epsilonLast);
         Assert.assertEquals(0, handler.getMaximalValueError().getReal(), epsilonMaxValue);
         Assert.assertEquals(0, handler.getMaximalTimeError().getReal(),  epsilonMaxTime);
         Assert.assertEquals(name, integ.getName());


[30/50] [abbrv] [math] Prevent NullPointerException.

Posted by lu...@apache.org.
Prevent NullPointerException.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/0ddec291
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0ddec291
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0ddec291

Branch: refs/heads/master
Commit: 0ddec2917a8543e1f58e85e317ab4d07bd94f786
Parents: c246b37
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:22:26 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:22:26 2016 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/math4/ode/FieldODEState.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/0ddec291/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldODEState.java b/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
index 1c7bbe6..de01d97 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
@@ -113,7 +113,7 @@ public class FieldODEState<T extends RealFieldElement<T>> {
      * @return number of secondary states.
      */
     public int getNumberOfSecondaryStates() {
-        return secondaryState.length;
+        return secondaryState == null ? 0 : secondaryState.length;
     }
 
     /** Get secondary state dimension.


[23/50] [abbrv] [math] Fixed Dormand-Prince 5(4) field integrator constants.

Posted by lu...@apache.org.
Fixed Dormand-Prince 5(4) field integrator constants.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/53af1473
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/53af1473
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/53af1473

Branch: refs/heads/master
Commit: 53af14730cd52af888a37c35c326d735f54c76c3
Parents: f3cdf56
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:36 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:36 2016 +0100

----------------------------------------------------------------------
 .../ode/nonstiff/DormandPrince54FieldIntegrator.java      |  4 ++--
 .../ode/nonstiff/DormandPrince54FieldIntegratorTest.java  | 10 +++++-----
 .../DormandPrince54FieldStepInterpolatorTest.java         |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/53af1473/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
index 743dbe4..e454ca7 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegrator.java
@@ -134,7 +134,7 @@ public class DormandPrince54FieldIntegrator<T extends RealFieldElement<T>>
         final T[] c = MathArrays.buildArray(getField(), 6);
         c[0] = fraction(1,  5);
         c[1] = fraction(3, 10);
-        c[2] = fraction(5,  5);
+        c[2] = fraction(4,  5);
         c[3] = fraction(8,  9);
         c[4] = getField().getOne();
         c[5] = getField().getOne();
@@ -149,7 +149,7 @@ public class DormandPrince54FieldIntegrator<T extends RealFieldElement<T>>
             a[i] = MathArrays.buildArray(getField(), i + 1);
         }
         a[0][0] = fraction(     1,     5);
-        a[1][0] = fraction(     3,     4);
+        a[1][0] = fraction(     3,    40);
         a[1][1] = fraction(     9,    40);
         a[2][0] = fraction(    44,    45);
         a[2][1] = fraction(   -56,    15);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/53af1473/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
index 4015ffe..9a853cd 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldIntegratorTest.java
@@ -49,12 +49,12 @@ public class DormandPrince54FieldIntegratorTest extends AbstractEmbeddedRungeKut
 
     @Test
     public void testBackward() {
-        doTestBackward(Decimal64Field.getInstance(), 2.0e-7, 2.0e-7, 1.0e-12, "Dormand-Prince 5(4)");
+        doTestBackward(Decimal64Field.getInstance(), 1.6e-7, 1.6e-7, 1.0e-22, "Dormand-Prince 5(4)");
     }
 
     @Test
     public void testKepler() {
-        doTestKepler(Decimal64Field.getInstance(), 7.0e-10);
+        doTestKepler(Decimal64Field.getInstance(), 3.1e-10);
     }
 
     @Override
@@ -69,15 +69,15 @@ public class DormandPrince54FieldIntegratorTest extends AbstractEmbeddedRungeKut
 
     @Override
     public void testIncreasingTolerance() {
-        // the 0.7 factor is only valid for this test
+        // the 0.5 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
-        doTestIncreasingTolerance(Decimal64Field.getInstance(), 0.7, 1.0e-12);
+        doTestIncreasingTolerance(Decimal64Field.getInstance(), 0.5, 1.0e-12);
     }
 
     @Override
     public void testEvents() {
-        doTestEvents(Decimal64Field.getInstance(), 5.0e-6, "Dormand-Prince 5(4)");
+        doTestEvents(Decimal64Field.getInstance(), 3.10e-8, "Dormand-Prince 5(4)");
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/commons-math/blob/53af1473/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
index 9facccd..2aeac54 100644
--- a/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/DormandPrince54FieldStepInterpolatorTest.java
@@ -38,12 +38,12 @@ public class DormandPrince54FieldStepInterpolatorTest extends AbstractRungeKutta
 
     @Test
     public void interpolationInside() {
-        doInterpolationInside(Decimal64Field.getInstance(), 4.0e-13, 2.7e-15);
+        doInterpolationInside(Decimal64Field.getInstance(), 9.5e-14, 1.8e-15);
     }
 
     @Test
     public void nonFieldInterpolatorConsistency() {
-        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 4.2e-17, 2.3e-16, 6.7e-16, 8.4e-17);
+        doNonFieldInterpolatorConsistency(Decimal64Field.getInstance(), 2.8e-17, 2.3e-16, 4.5e-16, 5.6e-17);
     }
 
 }


[33/50] [abbrv] [math] fixed Javadoc.

Posted by lu...@apache.org.
fixed Javadoc.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/5672ebe9
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/5672ebe9
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/5672ebe9

Branch: refs/heads/master
Commit: 5672ebe9123cd0c97524f95bcce6d8d634142cc8
Parents: 771eb6a
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 13:29:26 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 13:29:26 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/math4/ode/AbstractFieldIntegrator.java   | 4 ++--
 .../commons/math4/ode/ContinuousOutputFieldModel.java       | 9 ++++-----
 .../apache/commons/math4/ode/FieldFirstOrderIntegrator.java | 2 +-
 .../java/org/apache/commons/math4/ode/FieldODEState.java    | 2 +-
 .../commons/math4/ode/FieldODEStateAndDerivative.java       | 2 +-
 .../math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java | 4 ++--
 .../math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java    | 2 +-
 7 files changed, 12 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/5672ebe9/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
index b4f321c..81f4085 100644
--- a/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/AbstractFieldIntegrator.java
@@ -246,8 +246,8 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
      * @exception DimensionMismatchException if arrays dimensions do not match equations settings
      * @exception MaxCountExceededException if the number of functions evaluations is exceeded
      * @exception NullPointerException if the ODE equations have not been set (i.e. if this method
-     * is called outside of a call to {@link #integrate(ExpandableStatefulODE, double)} or {@link
-     * #integrate(FirstOrderDifferentialEquations, double, double[], double, double[])})
+     * is called outside of a call to {@link #integrate(FieldExpandableODE, FieldODEState,
+     * RealFieldElement) integrate}
      */
     public T[] computeDerivatives(final T t, final T[] y)
         throws DimensionMismatchException, MaxCountExceededException, NullPointerException {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/5672ebe9/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java b/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
index f26fded..e9a1a29 100644
--- a/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
+++ b/src/main/java/org/apache/commons/math4/ode/ContinuousOutputFieldModel.java
@@ -38,11 +38,10 @@ import org.apache.commons.math4.util.FastMath;
  * view. It is called iteratively during the integration process and
  * stores a copy of all steps information in a sorted collection for
  * later use. Once the integration process is over, the user can use
- * the {@link #setInterpolatedTime setInterpolatedTime} and {@link
- * #getInterpolatedState getInterpolatedState} to retrieve this
- * information at any time. It is important to wait for the
- * integration to be over before attempting to call {@link
- * #setInterpolatedTime setInterpolatedTime} because some internal
+ * the {@link #getInterpolatedState(RealFieldElement) getInterpolatedState}
+ * method to retrieve this information at any time. It is important to wait
+ * for the integration to be over before attempting to call {@link
+ * #getInterpolatedState(RealFieldElement)} because some internal
  * variables are set only once the last step has been handled.</p>
  *
  * <p>This is useful for example if the main loop of the user

http://git-wip-us.apache.org/repos/asf/commons-math/blob/5672ebe9/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java b/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java
index 2ab6831..981d22b 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldFirstOrderIntegrator.java
@@ -82,7 +82,7 @@ public interface FieldFirstOrderIntegrator<T extends RealFieldElement<T>> {
      * @param maxIterationCount upper limit of the iteration count in
      * the event time search events.
      * @see #addEventHandler(FieldEventHandler, double, double, int,
-     * org.apache.commons.math4.analysis.solvers.FieldBracketingNthOrderBrentSolver)
+     * org.apache.commons.math4.analysis.solvers.BracketedRealFieldUnivariateSolver)
      * @see #getEventHandlers()
      * @see #clearEventHandlers()
      */

http://git-wip-us.apache.org/repos/asf/commons-math/blob/5672ebe9/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldODEState.java b/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
index de01d97..70132f6 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldODEState.java
@@ -45,7 +45,7 @@ public class FieldODEState<T extends RealFieldElement<T>> {
     /** Simple constructor.
      * <p>Calling this constructor is equivalent to call {@link
      * #FieldODEState(RealFieldElement, RealFieldElement[], RealFieldElement[][])
-     * FieldODEState(time, state, null).</p>
+     * FieldODEState(time, state, null)}.</p>
      * @param time time
      * @param state state at time
      */

http://git-wip-us.apache.org/repos/asf/commons-math/blob/5672ebe9/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java b/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
index d04aa04..179146a 100644
--- a/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
+++ b/src/main/java/org/apache/commons/math4/ode/FieldODEStateAndDerivative.java
@@ -40,7 +40,7 @@ public class FieldODEStateAndDerivative<T extends RealFieldElement<T>> extends F
      * <p>Calling this constructor is equivalent to call {@link
      * #FieldODEStateAndDerivative(RealFieldElement, RealFieldElement[], RealFieldElement[],
      * RealFieldElement[][], RealFieldElement[][]) FieldODEStateAndDerivative(time, state,
-     * derivative, null, null).</p>
+     * derivative, null, null)}.</p>
      * @param time time
      * @param state state at time
      * @param derivative derivative of the state at time

http://git-wip-us.apache.org/repos/asf/commons-math/blob/5672ebe9/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java
index 1ee753a..3cdf2bb 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java
@@ -146,7 +146,7 @@ public abstract class AdaptiveStepsizeFieldIntegrator<T extends RealFieldElement
      * <p>
      * A side effect of this method is to also reset the initial
      * step so it will be automatically computed by the integrator
-     * if {@link #setInitialStepSize(double) setInitialStepSize}
+     * if {@link #setInitialStepSize(RealFieldElement) setInitialStepSize}
      * is not called by the user.
      * </p>
      * @param minimalStep minimal step (must be positive even for backward
@@ -175,7 +175,7 @@ public abstract class AdaptiveStepsizeFieldIntegrator<T extends RealFieldElement
      * <p>
      * A side effect of this method is to also reset the initial
      * step so it will be automatically computed by the integrator
-     * if {@link #setInitialStepSize(double) setInitialStepSize}
+     * if {@link #setInitialStepSize(RealFieldElement) setInitialStepSize}
      * is not called by the user.
      * </p>
      * @param minimalStep minimal step (must be positive even for backward

http://git-wip-us.apache.org/repos/asf/commons-math/blob/5672ebe9/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
index 255b2da..4a786f5 100644
--- a/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math4/ode/nonstiff/ThreeEighthesFieldIntegrator.java
@@ -41,7 +41,7 @@ import org.apache.commons.math4.util.MathArrays;
  *
  * @see EulerFieldIntegrator
  * @see ClassicalRungeKuttaFieldIntegrator
- * @see GillfieldIntegrator
+ * @see GillFieldIntegrator
  * @see MidpointFieldIntegrator
  * @see LutherFieldIntegrator
  * @param <T> the type of the field elements


[04/50] [abbrv] [math] Added test for Luther integrator.

Posted by lu...@apache.org.
Added test for Luther integrator.

BEWARE! This test does not work yet. The integrator seems to be wrong
for now, probably at step interpolation level because the Butcher arrays
are consisten with the regulat integrator.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/548dfd8b
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/548dfd8b
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/548dfd8b

Branch: refs/heads/master
Commit: 548dfd8bead389790d1c438d54afaa1f060f0eba
Parents: eef2ed3
Author: Luc Maisonobe <lu...@apache.org>
Authored: Wed Jan 6 12:41:10 2016 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Wed Jan 6 12:41:10 2016 +0100

----------------------------------------------------------------------
 .../ode/nonstiff/LutherFieldIntegratorTest.java | 118 +++++++++++++++++++
 1 file changed, 118 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/548dfd8b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
new file mode 100644
index 0000000..3a668b8
--- /dev/null
+++ b/src/test/java/org/apache/commons/math4/ode/nonstiff/LutherFieldIntegratorTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.apache.commons.math4.ode.nonstiff;
+
+
+import org.apache.commons.math4.Field;
+import org.apache.commons.math4.RealFieldElement;
+import org.apache.commons.math4.exception.DimensionMismatchException;
+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 {
+
+    protected <T extends RealFieldElement<T>> RungeKuttaFieldIntegrator<T>
+    createIntegrator(Field<T> field, T step) {
+        return new LutherFieldIntegrator<T>(field, step);
+    }
+
+    @Test
+    public void testNonFieldIntegratorConsistency() {
+        doTestNonFieldIntegratorConsistency(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testMissedEndEvent()
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        doTestMissedEndEvent(Decimal64Field.getInstance(), 1.0e-15, 1.0e-15);
+    }
+
+    @Test
+    public void testSanityChecks()
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        doTestSanityChecks(Decimal64Field.getInstance());
+    }
+
+    @Test
+    public void testDecreasingSteps()
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        doTestDecreasingSteps(Decimal64Field.getInstance(), 1.0, 1.0, 1.0e-10);
+    }
+
+    @Test
+    public void testSmallStep()
+         throws DimensionMismatchException, NumberIsTooSmallException,
+                MaxCountExceededException, NoBracketingException {
+        doTestSmallStep(Decimal64Field.getInstance(), 9.0e-17, 4.0e-15, 1.0e-12, "Luther");
+    }
+
+    @Test
+    public void testBigStep()
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        doTestBigStep(Decimal64Field.getInstance(), 0.00002, 0.001, 1.0e-12, "Luther");
+    }
+
+    @Test
+    public void testBackward()
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        doTestBackward(Decimal64Field.getInstance(), 3.0e-13, 5.0e-13, 1.0e-12, "Luther");
+    }
+
+    @Test
+    public void testKepler()
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        doTestKepler(Decimal64Field.getInstance(), 2.2e-7, 1.0e-8);
+    }
+
+    @Test
+    public void testStepSize()
+        throws DimensionMismatchException, NumberIsTooSmallException,
+               MaxCountExceededException, NoBracketingException {
+        doTestStepSize(Decimal64Field.getInstance(), 1.0e-12);
+    }
+
+    @Test
+    public void testSingleStep() {
+        doTestSingleStep(Decimal64Field.getInstance(), 1.0e-11);
+    }
+
+    @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);
+    }
+
+}