commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r919479 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/ode/nonstiff/ main/java/org/apache/commons/math/ode/sampling/ site/xdoc/ test/java/org/apache/commons/math/ode/ test/java/org/apache/commons/math/ode/events/ tes...
Date Fri, 05 Mar 2010 16:35:57 GMT
Author: luc
Date: Fri Mar  5 16:35:56 2010
New Revision: 919479

URL: http://svn.apache.org/viewvc?rev=919479&view=rev
Log:
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

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java
Fri Mar  5 16:35:56 2010
@@ -214,7 +214,7 @@
       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);
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerIntegrator.java
Fri Mar  5 16:35:56 2010
@@ -624,7 +624,7 @@
                                                             y1, yDot1,
                                                             yMidDots, forward);
     } else {
-      interpolator = new DummyStepInterpolator(y, forward);
+      interpolator = new DummyStepInterpolator(y, yDot1, forward);
     }
     interpolator.storeTime(t0);
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/GraggBulirschStoerStepInterpolator.java
Fri Mar  5 16:35:56 2010
@@ -122,7 +122,7 @@
    * @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

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java
Fri Mar  5 16:35:56 2010
@@ -120,7 +120,7 @@
       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);
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/sampling/DummyStepInterpolator.java
Fri Mar  5 16:35:56 2010
@@ -40,8 +40,11 @@
 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 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 DummyStepInterpolator(final DummyStepInterpolator interpolator) {
     super(interpolator);
+    currentDerivative = interpolator.currentDerivative.clone();
   }
 
   /** Really copy the finalized instance.
@@ -96,7 +104,8 @@
   @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 @@
   @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 @@
     // 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);
 

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Fri Mar  5 16:35:56 2010
@@ -51,6 +51,11 @@
         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

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/ContinuousOutputModelTest.java
Fri Mar  5 16:35:56 2010
@@ -166,7 +166,7 @@
   }
 
   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);

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/events/EventStateTest.java
Fri Mar  5 16:35:56 2010
@@ -52,7 +52,7 @@
         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();

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=919479&r1=919478&r2=919479&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
Fri Mar  5 16:35:56 2010
@@ -38,7 +38,7 @@
   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 @@
     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 @@
   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 BadStepInterpolator() {
       }
       public BadStepInterpolator(double[] y, boolean forward) {
-          super(y, forward);
+          super(y, new double[y.length], forward);
       }
       @Override
       protected void doFinalize()



Mime
View raw message