Fixed a problem with getInterpolatedDerivatives returning zero derivatives when

an ODE step handler is configured to not use interpolation. It now returns a
constant but non-zero value consistent with at least one point inside the step


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@919479 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2010-03-05 16:35:56 +00:00
parent 1bb6d2ad6b
commit 81e8b4f0d1
9 changed files with 46 additions and 15 deletions

View File

@ -214,7 +214,7 @@ public abstract class EmbeddedRungeKuttaIntegrator
rki.reinitialize(this, yTmp, yDotK, forward);
interpolator = rki;
} else {
interpolator = new DummyStepInterpolator(yTmp, forward);
interpolator = new DummyStepInterpolator(yTmp, yDotK[stages - 1], forward);
}
interpolator.storeTime(t0);

View File

@ -624,7 +624,7 @@ public class GraggBulirschStoerIntegrator extends AdaptiveStepsizeIntegrator {
y1, yDot1,
yMidDots, forward);
} else {
interpolator = new DummyStepInterpolator(y, forward);
interpolator = new DummyStepInterpolator(y, yDot1, forward);
}
interpolator.storeTime(t0);

View File

@ -122,7 +122,7 @@ class GraggBulirschStoerStepInterpolator
* @param y1 reference to the integrator array holding the state at
* the end of the step
* @param y1Dot reference to the integrator array holding the slope
* at theend of the step
* at the end of the step
* @param yMidDots reference to the integrator array holding the
* derivatives at the middle point of the step
* @param forward integration direction indicator

View File

@ -120,7 +120,7 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator {
rki.reinitialize(this, yTmp, yDotK, forward);
interpolator = rki;
} else {
interpolator = new DummyStepInterpolator(yTmp, forward);
interpolator = new DummyStepInterpolator(yTmp, yDotK[stages - 1], forward);
}
interpolator.storeTime(t0);

View File

@ -40,8 +40,11 @@ import org.apache.commons.math.ode.DerivativeException;
public class DummyStepInterpolator
extends AbstractStepInterpolator {
/** Serializable version identifier */
private static final long serialVersionUID = 1708010296707839488L;
/** Serializable version identifier. */
private static final long serialVersionUID = 1708010296707839488L;
/** Current derivative. */
private double[] currentDerivative;
/** Simple constructor.
* This constructor builds an instance that is not usable yet, the
@ -55,15 +58,19 @@ public class DummyStepInterpolator
*/
public DummyStepInterpolator() {
super();
currentDerivative = null;
}
/** Simple constructor.
* @param y reference to the integrator array holding the state at
* the end of the step
* @param yDot reference to the integrator array holding the state
* derivative at some arbitrary point within the step
* @param forward integration direction indicator
*/
public DummyStepInterpolator(final double[] y, final boolean forward) {
public DummyStepInterpolator(final double[] y, final double[] yDot, final boolean forward) {
super(y, forward);
currentDerivative = yDot;
}
/** Copy constructor.
@ -73,6 +80,7 @@ public class DummyStepInterpolator
*/
public DummyStepInterpolator(final DummyStepInterpolator interpolator) {
super(interpolator);
currentDerivative = interpolator.currentDerivative.clone();
}
/** Really copy the finalized instance.
@ -96,7 +104,8 @@ public class DummyStepInterpolator
@Override
protected void computeInterpolatedStateAndDerivatives(final double theta, final double oneMinusThetaH)
throws DerivativeException {
System.arraycopy(currentState, 0, interpolatedState, 0, currentState.length);
System.arraycopy(currentState, 0, interpolatedState, 0, currentState.length);
System.arraycopy(currentDerivative, 0, interpolatedDerivatives, 0, currentDerivative.length);
}
/** Write the instance to an output channel.
@ -106,8 +115,16 @@ public class DummyStepInterpolator
@Override
public void writeExternal(final ObjectOutput out)
throws IOException {
// save the state of the base class
// save the state of the base class
writeBaseExternal(out);
if (currentDerivative != null) {
for (int i = 0; i < currentDerivative.length; ++i) {
out.writeDouble(currentDerivative[i]);
}
}
}
/** Read the instance from an input channel.
@ -121,6 +138,15 @@ public class DummyStepInterpolator
// read the base class
final double t = readBaseExternal(in);
if (currentState == null) {
currentDerivative = null;
} else {
currentDerivative = new double[currentState.length];
for (int i = 0; i < currentDerivative.length; ++i) {
currentDerivative[i] = in.readDouble();
}
}
// we can now set the interpolated time and state
setInterpolatedTime(t);

View File

@ -51,6 +51,11 @@ The <action> type attribute can be add,update,fix,remove.
used to solve Boundary Value Problems (BVP). There are no implementations (yet)
of BVP solvers in the library.
</action>
<action dev="luc" type="fix" >
Fixed a problem with getInterpolatedDerivatives returning zero derivatives when
an ODE step handler is configured to not use interpolation. It now returns a
constant but non-zero value consistent with at least one point inside the step
</action>
<action dev="luc" type="fix" issue="MATH-344" >
Fixed wrong return values when enpoints are roots in Brent solver with
a user provided initial guess

View File

@ -166,7 +166,7 @@ public class ContinuousOutputModelTest
}
private StepInterpolator buildInterpolator(double t0, double[] y0, double t1) {
DummyStepInterpolator interpolator = new DummyStepInterpolator(y0, t1 >= t0);
DummyStepInterpolator interpolator = new DummyStepInterpolator(y0, new double[y0.length], t1 >= t0);
interpolator.storeTime(t0);
interpolator.shift();
interpolator.storeTime(t1);

View File

@ -52,7 +52,7 @@ public class EventStateTest {
double t0 = r1 - 0.5 * gap;
es.reinitializeBegin(t0, new double[0]);
AbstractStepInterpolator interpolator =
new DummyStepInterpolator(new double[0], true);
new DummyStepInterpolator(new double[0], new double[0], true);
interpolator.storeTime(t0);
interpolator.shift();

View File

@ -38,7 +38,7 @@ public class DummyStepInterpolatorTest {
public void testNoReset() throws DerivativeException {
double[] y = { 0.0, 1.0, -2.0 };
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, true);
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true);
interpolator.storeTime(0);
interpolator.shift();
interpolator.storeTime(1);
@ -55,7 +55,7 @@ public class DummyStepInterpolatorTest {
throws DerivativeException {
double[] y = { 1.0, 3.0, -4.0 };
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, true);
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true);
interpolator.storeTime(0);
interpolator.shift();
interpolator.storeTime(1);
@ -79,7 +79,7 @@ public class DummyStepInterpolatorTest {
throws DerivativeException, IOException, ClassNotFoundException {
double[] y = { 0.0, 1.0, -2.0 };
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, true);
DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true);
interpolator.storeTime(0);
interpolator.shift();
interpolator.storeTime(1);
@ -132,7 +132,7 @@ public class DummyStepInterpolatorTest {
public BadStepInterpolator() {
}
public BadStepInterpolator(double[] y, boolean forward) {
super(y, forward);
super(y, new double[y.length], forward);
}
@Override
protected void doFinalize()