commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r590660 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/ode/ test/org/apache/commons/math/ode/
Date Wed, 31 Oct 2007 13:16:34 GMT
Author: luc
Date: Wed Oct 31 06:16:32 2007
New Revision: 590660

URL: http://svn.apache.org/viewvc?rev=590660&view=rev
Log:
Replaced the misused clone method in step interpolators
by a dedicated copy method that handles steps finalization
automatically and hence may trigger DerivativeException.
This should simplify usage and avoid nasty errors caused
by forgotten finalization

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince853StepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DummyStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/EulerStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GillStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/HighamHall54StepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MidpointStepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/StepInterpolator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ThreeEighthesStepInterpolator.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54StepInterpolatorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853StepInterpolatorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolatorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54StepInterpolatorTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -38,7 +38,7 @@
  */
 
 public abstract class AbstractStepInterpolator
-  implements StepInterpolator, Cloneable {
+  implements StepInterpolator {
 
   /** previous time */
   protected double previousTime;
@@ -163,32 +163,31 @@
   }
 
   /** 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.
+   * @throws DerivativeException if this call induces an automatic
+   * step finalization that throws one
+   * @see #setInterpolatedTime(double)
+   */
+   public StepInterpolator copy() throws DerivativeException {
 
-  * <p>The copied interpolator should have been finalized before the
-  * copy, otherwise the copy will not be able to perform correctly any
-  * interpolation and will throw a {@link NullPointerException}
-  * later. Since we don't want this constructor to throw the
-  * exceptions finalization may involve and since we don't want this
-  * method to modify the state of the copied interpolator,
-  * finalization is <strong>not</strong> done automatically, it
-  * remains under user control.</p>
-
-  * <p>The copy is a deep copy: its arrays are separated from the
-  * original arrays of the instance.</p>
-
-  * <p>This method has been redeclared as public instead of protected.</p>
-
-  * @return a copy of the instance.
-
-  */
-  public Object clone() {
-    try {
-      return super.clone();
-    } catch (CloneNotSupportedException cnse) {
-      // should never happen
-      return null;
-    }
-  }
+     // finalize the step before performing copy
+     finalizeStep();
+
+     // create the new independent instance
+     return doCopy();
+
+   }
+
+   /** Really copy the finalized instance.
+    * <p>This method is called by {@link #copy()} after the
+    * step has been finalized. It must perform a deep copy
+    * to have an new instance completely independent for the
+    * original instance.
+    */
+   protected abstract StepInterpolator doCopy();
 
   /** Shift one step forward.
    * Copy the current time into the previous time, hence preparing the

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -68,13 +68,9 @@
     super(interpolator);
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new ClassicalRungeKuttaStepInterpolator(this);
   }
 

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java
Wed Oct 31 06:16:32 2007
@@ -92,11 +92,14 @@
 
   /** Append another model at the end of the instance.
    * @param model model to add at the end of the instance
+   * @exception DerivativeException if some step interpolators from
+   * the appended model cannot be copied
    * @exception IllegalArgumentException if the model to append is not
    * compatible with the instance (dimension of the state vector,
    * propagation direction, hole between the dates)
    */
-  public void append(ContinuousOutputModel model) {
+  public void append(ContinuousOutputModel model)
+    throws DerivativeException {
 
     if (model.steps.size() == 0) {
       return;
@@ -127,8 +130,7 @@
     }
 
     for (Iterator iter = model.steps.iterator(); iter.hasNext(); ) {
-      AbstractStepInterpolator ai = (AbstractStepInterpolator) iter.next();
-      steps.add(ai.clone());
+      steps.add(((AbstractStepInterpolator) iter.next()).copy());
     }
 
     index = steps.size() - 1;
@@ -176,8 +178,7 @@
       forward     = interpolator.isForward();
     }
 
-    ai.finalizeStep();
-    steps.add(ai.clone());
+    steps.add(ai.copy());
 
     if (isLast) {
       finalTime = ai.getCurrentTime();

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -77,15 +77,12 @@
 
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new DormandPrince54StepInterpolator(this);
   }
+
 
   /** Reinitialize the instance
    * @param equations set of differential equations being integrated

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince853StepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince853StepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince853StepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince853StepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -46,7 +46,6 @@
   public DormandPrince853StepInterpolator() {
     super();
     yDotKLast = null;
-    yTmp      = null;
     v         = null;
     vectorsInitialized = false;
   }
@@ -87,18 +86,11 @@
 
     }
 
-    // the step has been finalized, we don't need this anymore
-    yTmp = null;
-
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new DormandPrince853StepInterpolator(this);
   }
 
@@ -135,8 +127,6 @@
       yDotKLast[k] = new double[dimension];
     }
 
-    yTmp = new double[dimension];
-
     v = new double[7][];
     for (int k = 0; k < v.length; ++k) {
       v[k]  = new double[dimension];
@@ -225,7 +215,13 @@
   protected void doFinalize()
     throws DerivativeException {
 
+    if (currentState == null) {
+      // we are finalizing an uninitialized instance
+      return;
+    }
+
     double s;
+    double[] yTmp = new double[currentState.length];
 
     // k14
     for (int j = 0; j < currentState.length; ++j) {
@@ -311,9 +307,6 @@
   /** Last evaluations. */
   private double[][] yDotKLast;
 
-  /** Temporary state vector. */
-  private double[] yTmp;
-
   /** Vectors for interpolation. */
   private double[][] v;
 
@@ -407,6 +400,6 @@
 
   };
 
-  private static final long serialVersionUID = 4165537490327432186L;
+  private static final long serialVersionUID = 7152276390558450974L;
 
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DummyStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DummyStepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DummyStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DummyStepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -61,6 +61,21 @@
     super(y, forward);
   }
 
+  /** 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
+   */
+  public DummyStepInterpolator(DummyStepInterpolator interpolator) {
+    super(interpolator);
+  }
+
+  /** Really copy the finalized instance.
+   */
+  protected StepInterpolator doCopy() {
+    return new DummyStepInterpolator(this);
+  }
+
   /** Compute the state at the interpolated time.
    * In this class, this method does nothing: the interpolated state
    * is always the state at the end of the current step.

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/EulerStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/EulerStepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/EulerStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/EulerStepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -61,15 +61,12 @@
     super(interpolator);
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new EulerStepInterpolator(this);
   }
+
 
   /** Compute the state at the interpolated time.
    * This is the main processing method that should be implemented by

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GillStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GillStepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GillStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GillStepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -66,15 +66,12 @@
     super(interpolator);
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new GillStepInterpolator(this);
   }
+
 
   /** Compute the state at the interpolated time.
    * This is the main processing method that should be implemented by

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -219,15 +219,12 @@
 
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new GraggBulirschStoerStepInterpolator(this);
   }
+
 
   /** Compute the interpolation coefficients for dense output.
    * @param mu degree of the interpolation polynom

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/HighamHall54StepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/HighamHall54StepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/HighamHall54StepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/HighamHall54StepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -52,15 +52,12 @@
     super(interpolator);
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new HighamHall54StepInterpolator(this);
   }
+
 
   /** Compute the state at the interpolated time.
    * @param theta normalized interpolation abscissa within the step

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MidpointStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MidpointStepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MidpointStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MidpointStepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -63,15 +63,12 @@
     super(interpolator);
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new MidpointStepInterpolator(this);
   }
+
 
   /** Compute the state at the interpolated time.
    * This is the main processing method that should be implemented by

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java
Wed Oct 31 06:16:32 2007
@@ -179,7 +179,7 @@
     // set up an interpolator sharing the integrator arrays
     AbstractStepInterpolator interpolator;
     if (handler.requiresDenseOutput() || (! switchesHandler.isEmpty())) {
-      RungeKuttaStepInterpolator rki = (RungeKuttaStepInterpolator) prototype.clone();
+      RungeKuttaStepInterpolator rki = (RungeKuttaStepInterpolator) prototype.copy();
       rki.reinitialize(equations, yTmp, yDotK, forward);
       interpolator = rki;
     } else {

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java
Wed Oct 31 06:16:32 2007
@@ -172,7 +172,7 @@
     // set up an interpolator sharing the integrator arrays
     AbstractStepInterpolator interpolator;
     if (handler.requiresDenseOutput() || (! switchesHandler.isEmpty())) {
-      RungeKuttaStepInterpolator rki = (RungeKuttaStepInterpolator) prototype.clone();
+      RungeKuttaStepInterpolator rki = (RungeKuttaStepInterpolator) prototype.copy();
       rki.reinitialize(equations, yTmp, yDotK, forward);
       interpolator = rki;
     } else {

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/StepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/StepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/StepInterpolator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/StepInterpolator.java Wed
Oct 31 06:16:32 2007
@@ -62,12 +62,14 @@
     
   /**
    * Set the time of the interpolated point.
-   * <p>Setting the time outside of the current step is now allowed
-   * (it was not allowed up to version 5.4 of Mantissa), but should be
-   * used with care since the accuracy of the interpolator will
+   * <p>Setting the time outside of the current step is now allowed, but
+   * should be used with care since the accuracy of the interpolator will
    * probably be very poor far from this step. This allowance has been
    * added to simplify implementation of search algorithms near the
    * step endpoints.</p>
+   * <p>Setting the time changes the instance internal state. If a
+   * specific state must be preserved, a copy of the instance must be
+   * created using {@link #copy()}.</p>
    * @param time time of the interpolated point
    * @throws DerivativeException if this call induces an automatic
    * step finalization that throws one
@@ -91,5 +93,16 @@
    * integration
    */
   public 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.
+   * @throws DerivativeException if this call induces an automatic
+   * step finalization that throws one
+   * @see #setInterpolatedTime(double)
+   */
+   public StepInterpolator copy() throws DerivativeException;
 
 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ThreeEighthesStepInterpolator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ThreeEighthesStepInterpolator.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ThreeEighthesStepInterpolator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ThreeEighthesStepInterpolator.java
Wed Oct 31 06:16:32 2007
@@ -68,15 +68,12 @@
     super(interpolator);
   }
 
-  /**
-   * Clone the instance.
-   * the copy is a deep copy: its arrays are separated from the
-   * original arrays of the instance
-   * @return a copy of the instance
+  /** Really copy the finalized instance.
    */
-  public Object clone() {
+  protected StepInterpolator doCopy() {
     return new ThreeEighthesStepInterpolator(this);
   }
+
 
   /** Compute the state at the interpolated time.
    * This is the main processing method that should be implemented by

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54StepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54StepInterpolatorTest.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54StepInterpolatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54StepInterpolatorTest.java
Wed Oct 31 06:16:32 2007
@@ -85,6 +85,50 @@
 
   }
 
+  public void testClone()
+    throws DerivativeException, IntegratorException {
+      TestProblem3 pb = new TestProblem3(0.9);
+      double minStep = 0;
+      double maxStep = pb.getFinalTime() - pb.getInitialTime();
+      double scalAbsoluteTolerance = 1.0e-8;
+      double scalRelativeTolerance = scalAbsoluteTolerance;
+      DormandPrince54Integrator integ = new DormandPrince54Integrator(minStep, maxStep,
+                                                                      scalAbsoluteTolerance,
+                                                                      scalRelativeTolerance);
+      integ.setStepHandler(new StepHandler() {
+          public void handleStep(StepInterpolator interpolator, boolean isLast)
+          throws DerivativeException {
+              StepInterpolator cloned = interpolator.copy();
+              double tA = cloned.getPreviousTime();
+              double tB = cloned.getCurrentTime();
+              double halfStep = Math.abs(tB - tA) / 2;
+              assertEquals(interpolator.getPreviousTime(), tA, 1.0e-12);
+              assertEquals(interpolator.getCurrentTime(), tB, 1.0e-12);
+              for (int i = 0; i < 10; ++i) {
+                  double t = (i * tB + (9 - i) * tA) / 9;
+                  interpolator.setInterpolatedTime(t);
+                  assertTrue(Math.abs(cloned.getInterpolatedTime() - t) > (halfStep /
10));
+                  cloned.setInterpolatedTime(t);
+                  assertEquals(t, cloned.getInterpolatedTime(), 1.0e-12);
+                  double[] referenceState = interpolator.getInterpolatedState();
+                  double[] cloneState     = cloned.getInterpolatedState();
+                  for (int j = 0; j < referenceState.length; ++j) {
+                      assertEquals(referenceState[j], cloneState[j], 1.0e-12);
+                  }
+              }
+          }
+          public boolean requiresDenseOutput() {
+              return true;
+          }
+          public void reset() {
+          }
+      });
+      integ.integrate(pb,
+              pb.getInitialTime(), pb.getInitialState(),
+              pb.getFinalTime(), new double[pb.getDimension()]);
+
+  }
+
   public static Test suite() {
     return new TestSuite(DormandPrince54StepInterpolatorTest.class);
   }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853StepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853StepInterpolatorTest.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853StepInterpolatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853StepInterpolatorTest.java
Wed Oct 31 06:16:32 2007
@@ -85,6 +85,50 @@
 
   }
 
+  public void testClone()
+  throws DerivativeException, IntegratorException {
+    TestProblem3 pb = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+    DormandPrince853Integrator integ = new DormandPrince853Integrator(minStep, maxStep,
+                                                                      scalAbsoluteTolerance,
+                                                                      scalRelativeTolerance);
+    integ.setStepHandler(new StepHandler() {
+        public void handleStep(StepInterpolator interpolator, boolean isLast)
+        throws DerivativeException {
+            StepInterpolator cloned = interpolator.copy();
+            double tA = cloned.getPreviousTime();
+            double tB = cloned.getCurrentTime();
+            double halfStep = Math.abs(tB - tA) / 2;
+            assertEquals(interpolator.getPreviousTime(), tA, 1.0e-12);
+            assertEquals(interpolator.getCurrentTime(), tB, 1.0e-12);
+            for (int i = 0; i < 10; ++i) {
+                double t = (i * tB + (9 - i) * tA) / 9;
+                interpolator.setInterpolatedTime(t);
+                assertTrue(Math.abs(cloned.getInterpolatedTime() - t) > (halfStep / 10));
+                cloned.setInterpolatedTime(t);
+                assertEquals(t, cloned.getInterpolatedTime(), 1.0e-12);
+                double[] referenceState = interpolator.getInterpolatedState();
+                double[] cloneState     = cloned.getInterpolatedState();
+                for (int j = 0; j < referenceState.length; ++j) {
+                    assertEquals(referenceState[j], cloneState[j], 1.0e-12);
+                }
+            }
+        }
+        public boolean requiresDenseOutput() {
+            return true;
+        }
+        public void reset() {
+        }
+    });
+    integ.integrate(pb,
+            pb.getInitialTime(), pb.getInitialState(),
+            pb.getFinalTime(), new double[pb.getDimension()]);
+
+  }
+
   public static Test suite() {
     return new TestSuite(DormandPrince853StepInterpolatorTest.class);
   }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolatorTest.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolatorTest.java
Wed Oct 31 06:16:32 2007
@@ -86,6 +86,50 @@
 
   }
 
+  public void testClone()
+  throws DerivativeException, IntegratorException {
+    TestProblem3 pb = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+    GraggBulirschStoerIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep,
+                                                                          scalAbsoluteTolerance,
+                                                                          scalRelativeTolerance);
+    integ.setStepHandler(new StepHandler() {
+        public void handleStep(StepInterpolator interpolator, boolean isLast)
+        throws DerivativeException {
+            StepInterpolator cloned = interpolator.copy();
+            double tA = cloned.getPreviousTime();
+            double tB = cloned.getCurrentTime();
+            double halfStep = Math.abs(tB - tA) / 2;
+            assertEquals(interpolator.getPreviousTime(), tA, 1.0e-12);
+            assertEquals(interpolator.getCurrentTime(), tB, 1.0e-12);
+            for (int i = 0; i < 10; ++i) {
+                double t = (i * tB + (9 - i) * tA) / 9;
+                interpolator.setInterpolatedTime(t);
+                assertTrue(Math.abs(cloned.getInterpolatedTime() - t) > (halfStep / 10));
+                cloned.setInterpolatedTime(t);
+                assertEquals(t, cloned.getInterpolatedTime(), 1.0e-12);
+                double[] referenceState = interpolator.getInterpolatedState();
+                double[] cloneState     = cloned.getInterpolatedState();
+                for (int j = 0; j < referenceState.length; ++j) {
+                    assertEquals(referenceState[j], cloneState[j], 1.0e-12);
+                }
+            }
+        }
+        public boolean requiresDenseOutput() {
+            return true;
+        }
+        public void reset() {
+        }
+    });
+    integ.integrate(pb,
+            pb.getInitialTime(), pb.getInitialState(),
+            pb.getFinalTime(), new double[pb.getDimension()]);
+
+  }
+
   public static Test suite() {
     return new TestSuite(GraggBulirschStoerStepInterpolatorTest.class);
   }

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54StepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54StepInterpolatorTest.java?rev=590660&r1=590659&r2=590660&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54StepInterpolatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54StepInterpolatorTest.java
Wed Oct 31 06:16:32 2007
@@ -85,6 +85,50 @@
 
   }
 
+  public void testClone()
+  throws DerivativeException, IntegratorException {
+    TestProblem3 pb = new TestProblem3(0.9);
+    double minStep = 0;
+    double maxStep = pb.getFinalTime() - pb.getInitialTime();
+    double scalAbsoluteTolerance = 1.0e-8;
+    double scalRelativeTolerance = scalAbsoluteTolerance;
+    HighamHall54Integrator integ = new HighamHall54Integrator(minStep, maxStep,
+                                                              scalAbsoluteTolerance,
+                                                              scalRelativeTolerance);
+    integ.setStepHandler(new StepHandler() {
+        public void handleStep(StepInterpolator interpolator, boolean isLast)
+        throws DerivativeException {
+            StepInterpolator cloned = interpolator.copy();
+            double tA = cloned.getPreviousTime();
+            double tB = cloned.getCurrentTime();
+            double halfStep = Math.abs(tB - tA) / 2;
+            assertEquals(interpolator.getPreviousTime(), tA, 1.0e-12);
+            assertEquals(interpolator.getCurrentTime(), tB, 1.0e-12);
+            for (int i = 0; i < 10; ++i) {
+                double t = (i * tB + (9 - i) * tA) / 9;
+                interpolator.setInterpolatedTime(t);
+                assertTrue(Math.abs(cloned.getInterpolatedTime() - t) > (halfStep / 10));
+                cloned.setInterpolatedTime(t);
+                assertEquals(t, cloned.getInterpolatedTime(), 1.0e-12);
+                double[] referenceState = interpolator.getInterpolatedState();
+                double[] cloneState     = cloned.getInterpolatedState();
+                for (int j = 0; j < referenceState.length; ++j) {
+                    assertEquals(referenceState[j], cloneState[j], 1.0e-12);
+                }
+            }
+        }
+        public boolean requiresDenseOutput() {
+            return true;
+        }
+        public void reset() {
+        }
+    });
+    integ.integrate(pb,
+            pb.getInitialTime(), pb.getInitialState(),
+            pb.getFinalTime(), new double[pb.getDimension()]);
+
+  }
+
   public static Test suite() {
     return new TestSuite(HighamHall54StepInterpolatorTest.class);
   }



Mime
View raw message