commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r780509 - in /commons/proper/math/trunk/src/java/org/apache/commons/math/ode: nonstiff/ sampling/
Date Sun, 31 May 2009 21:56:01 GMT
Author: luc
Date: Sun May 31 21:56:00 2009
New Revision: 780509

URL: http://svn.apache.org/viewvc?rev=780509&view=rev
Log:
fixed serialization of step interpolators to allow processing them
before the associated integrator update their internal state
(i.e. when currentState is still null)

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java?rev=780509&r1=780508&r2=780509&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/DormandPrince853StepInterpolator.java
Sun May 31 21:56:00 2009
@@ -259,8 +259,9 @@
     } 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 @@
     // 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();

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java?rev=780509&r1=780508&r2=780509&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
Sun May 31 21:56:00 2009
@@ -358,7 +358,7 @@
   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 @@
 
     // 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();

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java?rev=780509&r1=780508&r2=780509&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaStepInterpolator.java
Sun May 31 21:56:00 2009
@@ -133,9 +133,11 @@
     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,22 +155,27 @@
     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;
 
-    try {
-      // we can now set the interpolated time and state
-      setInterpolatedTime(t);
-    } catch (DerivativeException e) {
-      throw MathRuntimeException.createIOException(e);
+    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;
     }
 
   }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java?rev=780509&r1=780508&r2=780509&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/sampling/AbstractStepInterpolator.java
Sun May 31 21:56:00 2009
@@ -351,14 +351,20 @@
   protected void writeBaseExternal(final ObjectOutput out)
     throws IOException {
 
-    out.writeInt(currentState.length);
+    if (currentState == null) {
+        out.writeInt(-1);
+    } else {
+        out.writeInt(currentState.length);
+    }
     out.writeDouble(previousTime);
     out.writeDouble(currentTime);
     out.writeDouble(h);
     out.writeBoolean(forward);
 
-    for (int i = 0; i < currentState.length; ++i) {
-      out.writeDouble(currentState[i]);
+    if (currentState != null) {
+        for (int i = 0; i < currentState.length; ++i) {
+            out.writeDouble(currentState[i]);
+        }
     }
 
     out.writeDouble(interpolatedTime);
@@ -393,15 +399,19 @@
     h             = in.readDouble();
     forward       = in.readBoolean();
 
-    currentState  = new double[dimension];
-    for (int i = 0; i < currentState.length; ++i) {
-      currentState[i] = in.readDouble();
+    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;
 



Mime
View raw message