fixed serialization of step interpolators to allow processing them

before the associated integrator update their internal state
(i.e. when currentState is still null)

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@780509 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-05-31 21:56:00 +00:00
parent 65472945b6
commit 1745726d15
4 changed files with 44 additions and 26 deletions

View File

@ -259,8 +259,9 @@ class DormandPrince853StepInterpolator
} catch (DerivativeException e) {
throw MathRuntimeException.createIOException(e);
}
out.writeInt(currentState.length);
for (int i = 0; i < currentState.length; ++i) {
final int dimension = (currentState == null) ? -1 : currentState.length;
out.writeInt(dimension);
for (int i = 0; i < dimension; ++i) {
out.writeDouble(yDotKLast[0][i]);
out.writeDouble(yDotKLast[1][i]);
out.writeDouble(yDotKLast[2][i]);
@ -279,9 +280,9 @@ class DormandPrince853StepInterpolator
// read the local attributes
yDotKLast = new double[3][];
final int dimension = in.readInt();
yDotKLast[0] = new double[dimension];
yDotKLast[1] = new double[dimension];
yDotKLast[2] = new double[dimension];
yDotKLast[0] = (dimension < 0) ? null : new double[dimension];
yDotKLast[1] = (dimension < 0) ? null : new double[dimension];
yDotKLast[2] = (dimension < 0) ? null : new double[dimension];
for (int i = 0; i < dimension; ++i) {
yDotKLast[0][i] = in.readDouble();

View File

@ -358,7 +358,7 @@ class GraggBulirschStoerStepInterpolator
public void writeExternal(final ObjectOutput out)
throws IOException {
final int dimension = currentState.length;
final int dimension = (currentState == null) ? -1 : currentState.length;
// save the state of the base class
writeBaseExternal(out);
@ -380,7 +380,7 @@ class GraggBulirschStoerStepInterpolator
// read the base class
final double t = readBaseExternal(in);
final int dimension = currentState.length;
final int dimension = (currentState == null) ? -1 : currentState.length;
// read the local attributes
final int degree = in.readInt();

View File

@ -133,9 +133,11 @@ abstract class RungeKuttaStepInterpolator
writeBaseExternal(out);
// save the local attributes
out.writeInt(yDotK.length);
for (int k = 0; k < yDotK.length; ++k) {
for (int i = 0; i < currentState.length; ++i) {
final int n = (currentState == null) ? -1 : currentState.length;
final int kMax = (yDotK == null) ? -1 : yDotK.length;
out.writeInt(kMax);
for (int k = 0; k < kMax; ++k) {
for (int i = 0; i < n; ++i) {
out.writeDouble(yDotK[k][i]);
}
}
@ -153,23 +155,28 @@ abstract class RungeKuttaStepInterpolator
final double t = readBaseExternal(in);
// read the local attributes
final int n = (currentState == null) ? -1 : currentState.length;
final int kMax = in.readInt();
yDotK = new double[kMax][];
yDotK = (kMax < 0) ? null : new double[kMax][];
for (int k = 0; k < kMax; ++k) {
yDotK[k] = new double[currentState.length];
for (int i = 0; i < currentState.length; ++i) {
yDotK[k] = (n < 0) ? null : new double[n];
for (int i = 0; i < n; ++i) {
yDotK[k][i] = in.readDouble();
}
}
equations = null;
if (currentState != null) {
try {
// we can now set the interpolated time and state
setInterpolatedTime(t);
} catch (DerivativeException e) {
throw MathRuntimeException.createIOException(e);
}
} else {
interpolatedTime = t;
}
}

View File

@ -351,15 +351,21 @@ public abstract class AbstractStepInterpolator
protected void writeBaseExternal(final ObjectOutput out)
throws IOException {
if (currentState == null) {
out.writeInt(-1);
} else {
out.writeInt(currentState.length);
}
out.writeDouble(previousTime);
out.writeDouble(currentTime);
out.writeDouble(h);
out.writeBoolean(forward);
if (currentState != null) {
for (int i = 0; i < currentState.length; ++i) {
out.writeDouble(currentState[i]);
}
}
out.writeDouble(interpolatedTime);
@ -393,15 +399,19 @@ public abstract class AbstractStepInterpolator
h = in.readDouble();
forward = in.readBoolean();
if (dimension < 0) {
currentState = null;
} else {
currentState = new double[dimension];
for (int i = 0; i < currentState.length; ++i) {
currentState[i] = in.readDouble();
}
}
// we do NOT handle the interpolated time and state here
interpolatedTime = Double.NaN;
interpolatedState = new double[dimension];
interpolatedDerivatives = new double[dimension];
interpolatedState = (dimension < 0) ? null : new double[dimension];
interpolatedDerivatives = (dimension < 0) ? null : new double[dimension];
finalized = true;