commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r512066 [1/5] - in /jakarta/commons/proper/math/trunk/src: java/org/apache/commons/math/ode/ mantissa/src/org/spaceroots/mantissa/ode/ mantissa/src/org/spaceroots/mantissa/ode/doc-files/ mantissa/tests-src/org/spaceroots/mantissa/ode/ test/...
Date Mon, 26 Feb 2007 23:12:45 GMT
Author: luc
Date: Mon Feb 26 15:12:40 2007
New Revision: 512066

URL: http://svn.apache.org/viewvc?view=rev&rev=512066
Log:
added the ode package from Mantissa

Added:
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DerivativeException.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54Integrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince853Integrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince853StepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DummyStepHandler.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DummyStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/EulerIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/EulerStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/FirstOrderConverter.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/FirstOrderDifferentialEquations.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/FirstOrderIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/FixedStepHandler.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GillIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GillStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/HighamHall54Integrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/HighamHall54StepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/IntegratorException.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MidpointIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MidpointStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/SecondOrderDifferentialEquations.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/SecondOrderIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/StepHandler.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/StepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/StepNormalizer.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/SwitchState.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/SwitchingFunction.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/SwitchingFunctionsHandler.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ThreeEighthesIntegrator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ThreeEighthesStepInterpolator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/package.html   (with props)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/
      - copied from r511516, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaIntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaStepInterpolatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ContinuousOutputModelTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ContinuousOutputModelTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54IntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54IntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince54StepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince54StepInterpolatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853IntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853IntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/DormandPrince853StepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/DormandPrince853StepInterpolatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/EulerIntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerIntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/EulerStepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/EulerStepInterpolatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/FirstOrderConverterTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/FirstOrderConverterTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GillIntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillIntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GillStepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GillStepInterpolatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerIntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/GraggBulirschStoerStepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/GraggBulirschStoerStepInterpolatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54IntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/HighamHall54IntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/HighamHall54StepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/HighamHall54StepInterpolatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/MidpointIntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/MidpointIntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/MidpointStepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/MidpointStepInterpolatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/StepNormalizerTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/StepNormalizerTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/StepProblem.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/StepProblem.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblem1.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem1.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblem2.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem2.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblem3.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem3.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblem4.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem4.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblem5.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblem5.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblemAbstract.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblemAbstract.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblemFactory.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblemFactory.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/TestProblemHandler.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/TestProblemHandler.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ThreeEighthesIntegratorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ThreeEighthesIntegratorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/ThreeEighthesStepInterpolatorTest.java
      - copied, changed from r512064, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/ThreeEighthesStepInterpolatorTest.java
Removed:
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/AbstractStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/AdaptiveStepsizeIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/ClassicalRungeKuttaStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/ContinuousOutputModel.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/DerivativeException.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/DormandPrince54Integrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/DormandPrince54StepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/DormandPrince853Integrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/DormandPrince853StepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/DummyStepHandler.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/DummyStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/EulerIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/EulerStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/FirstOrderConverter.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/FirstOrderDifferentialEquations.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/FirstOrderIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/FixedStepHandler.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/GillIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/GillStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/GraggBulirschStoerIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/GraggBulirschStoerStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/HighamHall54Integrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/HighamHall54StepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/IntegratorException.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/MidpointIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/MidpointStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/RungeKuttaFehlbergIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/RungeKuttaIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/RungeKuttaStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/SecondOrderDifferentialEquations.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/SecondOrderIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/StepHandler.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/StepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/StepNormalizer.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/SwitchState.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/SwitchingFunction.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/SwitchingFunctionsHandler.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/ThreeEighthesIntegrator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/ThreeEighthesStepInterpolator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/doc-files/
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/ode/package.html
    jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/ode/
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/AllTests.java

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java?view=auto&rev=512066
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java Mon Feb 26 15:12:40 2007
@@ -0,0 +1,431 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.ode;
+
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.IOException;
+
+/** This abstract class represents an interpolator over the last step
+ * during an ODE integration.
+ *
+ * <p>The various ODE integrators provide objects extending this class
+ * to the step handlers. The handlers can use these objects to
+ * retrieve the state vector at intermediate times between the
+ * previous and the current grid points (dense output).</p>
+ *
+ * @see FirstOrderIntegrator
+ * @see SecondOrderIntegrator
+ * @see StepHandler
+ *
+ * @version $Id: AbstractStepInterpolator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+ *
+ */
+
+public abstract class AbstractStepInterpolator
+  implements StepInterpolator, Cloneable {
+
+  /** previous time */
+  protected double previousTime;
+
+  /** current time */
+  protected double currentTime;
+
+  /** current time step */
+  protected double h;
+
+  /** current state */
+  protected double[] currentState;
+
+  /** interpolated time */
+  protected double interpolatedTime;
+
+  /** interpolated state */
+  protected double[] interpolatedState;
+
+  /** indicate if the step has been finalized or not. */
+  private boolean finalized;
+
+  /** integration direction. */
+  private boolean forward;
+
+  /** Simple constructor.
+   * This constructor builds an instance that is not usable yet, the
+   * {@link #reinitialize} method should be called before using the
+   * instance in order to initialize the internal arrays. This
+   * constructor is used only in order to delay the initialization in
+   * some cases. As an example, the {@link
+   * RungeKuttaFehlbergIntegrator} uses the prototyping design pattern
+   * to create the step interpolators by cloning an uninitialized
+   * model and latter initializing the copy.
+   */
+  protected AbstractStepInterpolator() {
+    previousTime      = Double.NaN;
+    currentTime       = Double.NaN;
+    h                 = Double.NaN;
+    interpolatedTime  = Double.NaN;
+    currentState      = null;
+    interpolatedState = null;
+    finalized         = false;
+    this.forward      = true;
+  }
+
+  /** Simple constructor.
+   * @param y reference to the integrator array holding the state at
+   * the end of the step
+   * @param forward integration direction indicator
+   */
+  protected AbstractStepInterpolator(double[] y, boolean forward) {
+
+    previousTime      = Double.NaN;
+    currentTime       = Double.NaN;
+    h                 = Double.NaN;
+    interpolatedTime  = Double.NaN;
+
+    currentState      = y;
+    interpolatedState = new double[y.length];
+
+    finalized         = false;
+    this.forward      = forward;
+
+  }
+
+  /** Copy constructor.
+
+   * <p>The copied interpolator should have been finalized before the
+   * copy, otherwise the copy will not be able to perform correctly
+   * any derivative computation 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>
+
+   * @param interpolator interpolator to copy from.
+
+   */
+  protected AbstractStepInterpolator(AbstractStepInterpolator interpolator) {
+
+    previousTime      = interpolator.previousTime;
+    currentTime       = interpolator.currentTime;
+    h                 = interpolator.h;
+    interpolatedTime  = interpolator.interpolatedTime;
+
+    if (interpolator.currentState != null) {
+      currentState      = (double[]) interpolator.currentState.clone();
+      interpolatedState = (double[]) interpolator.interpolatedState.clone();
+    } else {
+      currentState      = null;
+      interpolatedState = null;
+    }
+
+    finalized = interpolator.finalized;
+    forward   = interpolator.forward;
+
+  }
+
+  /** Reinitialize the instance
+   * @param y reference to the integrator array holding the state at
+   * the end of the step
+   * @param forward integration direction indicator
+   */
+  protected void reinitialize(double[] y, boolean forward) {
+
+    previousTime      = Double.NaN;
+    currentTime       = Double.NaN;
+    h                 = Double.NaN;
+    interpolatedTime  = Double.NaN;
+
+    currentState      = y;
+    interpolatedState = new double[y.length];
+
+    finalized         = false;
+    this.forward      = forward;
+
+  }
+
+  /** Copy the instance.
+
+  * <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;
+    }
+  }
+
+  /** Shift one step forward.
+   * Copy the current time into the previous time, hence preparing the
+   * interpolator for future calls to {@link #storeTime storeTime}
+   */
+  public void shift() {
+    previousTime = currentTime;
+  }
+
+  /** Store the current step time.
+   * @param t current time
+   */
+  public void storeTime(double t) {
+
+    currentTime      = t;
+    h                = currentTime - previousTime;
+    interpolatedTime = t;
+    System.arraycopy(currentState, 0, interpolatedState, 0,
+                     currentState.length);
+
+    // the step is not finalized anymore
+    finalized = false;
+
+  }
+
+  /**
+   * Get the previous grid point time.
+   * @return previous grid point time
+   */
+  public double getPreviousTime() {
+    return previousTime;
+  }
+    
+  /**
+   * Get the current grid point time.
+   * @return current grid point time
+   */
+  public double getCurrentTime() {
+    return currentTime;
+  }
+    
+  /**
+   * Get the time of the interpolated point.
+   * If {@link #setInterpolatedTime} has not been called, it returns
+   * the current grid point time.
+   * @return interpolation point time
+   */
+  public double getInterpolatedTime() {
+    return interpolatedTime;
+  }
+    
+  /**
+   * 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
+   * probably be very poor far from this step. This allowance has been
+   * added to simplify implementation of search algorithms near the
+   * step endpoints.</p>
+   * @param time time of the interpolated point
+   * @throws DerivativeException if this call induces an automatic
+   * step finalization that throws one
+   */
+  public void setInterpolatedTime(double time)
+    throws DerivativeException {
+    interpolatedTime = time;
+    double oneMinusThetaH = currentTime - interpolatedTime;
+    computeInterpolatedState((h - oneMinusThetaH) / h, oneMinusThetaH);
+  }
+
+  /** Check if the natural integration direction is forward.
+   * <p>This method provides the integration direction as specified by the
+   * integrator itself, it avoid some nasty problems in degenerated
+   * cases like null steps due to cancellation at step initialization,
+   * step control or switching function triggering.</p>
+   * @return true if the integration variable (time) increases during
+   * integration
+   */
+  public boolean isForward() {
+    return forward;
+  }
+
+  /** Compute the state at the interpolated time.
+   * This is the main processing method that should be implemented by
+   * the derived classes to perform the interpolation.
+   * @param theta normalized interpolation abscissa within the step
+   * (theta is zero at the previous time step and one at the current time step)
+   * @param oneMinusThetaH time gap between the interpolated time and
+   * the current time
+   * @throws DerivativeException this exception is propagated to the caller if the
+   * underlying user function triggers one
+   */
+  protected abstract void computeInterpolatedState(double theta,
+                                                   double oneMinusThetaH)
+    throws DerivativeException;
+    
+  /**
+   * Get the state vector of the interpolated point.
+   * @return state vector at time {@link #getInterpolatedTime}
+   */
+  public double[] getInterpolatedState() {
+    return (double[]) interpolatedState.clone();
+  }
+
+
+  /**
+   * Finalize the step.
+
+   * <p>Some Runge-Kutta-Fehlberg integrators need fewer functions
+   * evaluations than their counterpart step interpolators. These
+   * interpolators should perform the last evaluations they need by
+   * themselves only if they need them. This method triggers these
+   * extra evaluations. It can be called directly by the user step
+   * handler and it is called automatically if {@link
+   * #setInterpolatedTime} is called.</p>
+
+   * <p>Once this method has been called, <strong>no</strong> other
+   * evaluation will be performed on this step. If there is a need to
+   * have some side effects between the step handler and the
+   * differential equations (for example update some data in the
+   * equations once the step has been done), it is advised to call
+   * this method explicitly from the step handler before these side
+   * effects are set up. If the step handler induces no side effect,
+   * then this method can safely be ignored, it will be called
+   * transparently as needed.</p>
+
+   * <p><strong>Warning</strong>: since the step interpolator provided
+   * to the step handler as a parameter of the {@link
+   * StepHandler#handleStep handleStep} is valid only for the duration
+   * of the {@link StepHandler#handleStep handleStep} call, one cannot
+   * simply store a reference and reuse it later. One should first
+   * finalize the instance, then copy this finalized instance into a
+   * new object that can be kept.</p>
+
+   * <p>This method calls the protected {@link #doFinalize doFinalize}
+   * method if it has never been called during this step and set a
+   * flag indicating that it has been called once. It is the {@link
+   * #doFinalize doFinalize} method which should perform the
+   * evaluations. This wrapping prevents from calling {@link
+   * #doFinalize doFinalize} several times and hence evaluating the
+   * differential equations too often. Therefore, subclasses are not
+   * allowed not reimplement it, they should rather reimplement {@link
+   * #doFinalize doFinalize}.</p>
+
+   * @throws DerivativeException this exception is propagated to the
+   * caller if the underlying user function triggers one
+
+   */
+  public final void finalizeStep()
+    throws DerivativeException {
+    if (! finalized) {
+      doFinalize();
+      finalized = true;
+    }
+  }
+
+  /**
+   * Really finalize the step.
+   * The default implementation of this method does nothing.
+   * @throws DerivativeException this exception is propagated to the
+   * caller if the underlying user function triggers one
+   */
+  protected void doFinalize()
+    throws DerivativeException {
+  }
+
+  public abstract void writeExternal(ObjectOutput out)
+    throws IOException;
+
+  public abstract void readExternal(ObjectInput in)
+    throws IOException;
+
+  /** Save the base state of the instance.
+   * This method performs step finalization if it has not been done
+   * before.
+   * @param out stream where to save the state
+   * @exception IOException in case of write error
+   */
+  protected void writeBaseExternal(ObjectOutput out)
+    throws IOException {
+
+    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]);
+    }
+
+    out.writeDouble(interpolatedTime);
+
+    // we do not store the interpolated state,
+    // it will be recomputed as needed after reading
+
+    // finalize the step (and don't bother saving the now true flag)
+    try {
+      finalizeStep();
+    } catch (DerivativeException e) {
+      throw new IOException(e.getMessage());
+    }
+
+  }
+
+  /** Read the base state of the instance.
+   * This method does <strong>neither</strong> set the interpolated
+   * time nor state. It is up to the derived class to reset it
+   * properly calling the {@link #setInterpolatedTime} method later,
+   * once all rest of the object state has been set up properly.
+   * @param in stream where to read the state from
+   * @return interpolated time be set later by the caller
+   * @exception IOException in case of read error
+   */
+  protected double readBaseExternal(ObjectInput in)
+    throws IOException {
+
+    int dimension = in.readInt();
+    previousTime  = in.readDouble();
+    currentTime   = in.readDouble();
+    h             = in.readDouble();
+    forward       = in.readBoolean();
+
+    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];
+
+    finalized = true;
+
+    return in.readDouble();
+
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AbstractStepInterpolator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java?view=auto&rev=512066
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java Mon Feb 26 15:12:40 2007
@@ -0,0 +1,317 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.ode;
+
+/**
+ * This abstract class holds the common part of all adaptive
+ * stepsize integrators for Ordinary Differential Equations.
+
+ * <p>These algorithms perform integration with stepsize control, which
+ * means the user does not specify the integration step but rather a
+ * tolerance on error. The error threshold is computed as
+ * <pre>
+ * threshold_i = absTol_i + relTol_i * max (abs (ym), abs (ym+1))
+ * </pre>
+ * where absTol_i is the absolute tolerance for component i of the
+ * state vector and relTol_i is the relative tolerance for the same
+ * component. The user can also use only two scalar values absTol and
+ * relTol which will be used for all components.</p>
+
+ * <p>If the estimated error for ym+1 is such that
+ * <pre>
+ * sqrt((sum (errEst_i / threshold_i)^2 ) / n) < 1
+ * </pre>
+
+ * (where n is the state vector dimension) then the step is accepted,
+ * otherwise the step is rejected and a new attempt is made with a new
+ * stepsize.</p>
+
+ * @version $Id: AdaptiveStepsizeIntegrator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public abstract class AdaptiveStepsizeIntegrator
+  implements FirstOrderIntegrator {
+
+  /** Build an integrator with the given stepsize bounds.
+   * The default step handler does nothing.
+   * @param minStep minimal step (must be positive even for backward
+   * integration), the last step can be smaller than this
+   * @param maxStep maximal step (must be positive even for backward
+   * integration)
+   * @param scalAbsoluteTolerance allowed absolute error
+   * @param scalRelativeTolerance allowed relative error
+   */
+  public AdaptiveStepsizeIntegrator(double minStep, double maxStep,
+                                    double scalAbsoluteTolerance,
+                                    double scalRelativeTolerance) {
+
+    this.minStep     = minStep;
+    this.maxStep     = maxStep;
+    this.initialStep = -1.0;
+
+    this.scalAbsoluteTolerance = scalAbsoluteTolerance;
+    this.scalRelativeTolerance = scalRelativeTolerance;
+    this.vecAbsoluteTolerance  = null;
+    this.vecRelativeTolerance  = null;
+
+    // set the default step handler
+    handler = DummyStepHandler.getInstance();
+
+    switchesHandler = new SwitchingFunctionsHandler();
+
+  }
+
+  /** Build an integrator with the given stepsize bounds.
+   * The default step handler does nothing.
+   * @param minStep minimal step (must be positive even for backward
+   * integration), the last step can be smaller than this
+   * @param maxStep maximal step (must be positive even for backward
+   * integration)
+   * @param vecAbsoluteTolerance allowed absolute error
+   * @param vecRelativeTolerance allowed relative error
+   */
+  public AdaptiveStepsizeIntegrator(double minStep, double maxStep,
+                                    double[] vecAbsoluteTolerance,
+                                    double[] vecRelativeTolerance) {
+
+    this.minStep     = minStep;
+    this.maxStep     = maxStep;
+    this.initialStep = -1.0;
+
+    this.scalAbsoluteTolerance = 0;
+    this.scalRelativeTolerance = 0;
+    this.vecAbsoluteTolerance  = vecAbsoluteTolerance;
+    this.vecRelativeTolerance  = vecRelativeTolerance;
+
+    // set the default step handler
+    handler = DummyStepHandler.getInstance();
+
+    switchesHandler = new SwitchingFunctionsHandler();
+
+  }
+
+  /** Set the initial step size.
+   * <p>This method allows the user to specify an initial positive
+   * step size instead of letting the integrator guess it by
+   * itself. If this method is not called before integration is
+   * started, the initial step size will be estimated by the
+   * integrator.</p>
+   * @param initialStepSize initial step size to use (must be positive even
+   * for backward integration ; providing a negative value or a value
+   * outside of the min/max step interval will lead the integrator to
+   * ignore the value and compute the initial step size by itself)
+   */
+  public void setInitialStepSize(double initialStepSize) {
+    if ((initialStepSize < minStep) || (initialStepSize > maxStep)) {
+      initialStep = -1.0;
+    } else {
+      initialStep = initialStepSize;
+    }
+  }
+
+  /** Set the step handler for this integrator.
+   * The handler will be called by the integrator for each accepted
+   * step.
+   * @param handler handler for the accepted steps
+   */
+  public void setStepHandler (StepHandler handler) {
+    this.handler = handler;
+  }
+
+  /** Get the step handler for this integrator.
+   * @return the step handler for this integrator
+   */
+  public StepHandler getStepHandler() {
+    return handler;
+  }
+
+  /** Add a switching function to the integrator.
+   * @param function switching function
+   * @param maxCheckInterval maximal time interval between switching
+   * function checks (this interval prevents missing sign changes in
+   * case the integration steps becomes very large)
+   * @param convergence convergence threshold in the event time search
+   */
+  public void addSwitchingFunction(SwitchingFunction function,
+                                   double maxCheckInterval,
+                                   double convergence) {
+    switchesHandler.add(function, maxCheckInterval, convergence);
+  }
+
+  /** Initialize the integration step.
+   * @param equations differential equations set
+   * @param forward forward integration indicator
+   * @param order order of the method
+   * @param scale scaling vector for the state vector
+   * @param t0 start time
+   * @param y0 state vector at t0
+   * @param yDot0 first time derivative of y0
+   * @param y1 work array for a state vector
+   * @param yDot1 work array for the first time derivative of y1
+   * @return first integration step
+   * @exception DerivativeException this exception is propagated to
+   * the caller if the underlying user function triggers one
+   */
+  public double initializeStep(FirstOrderDifferentialEquations equations,
+                               boolean forward, int order, double[] scale,
+                               double t0, double[] y0, double[] yDot0,
+                               double[] y1, double[] yDot1)
+    throws DerivativeException {
+
+    if (initialStep > 0) {
+      // use the user provided value
+      return forward ? initialStep : -initialStep;
+    }
+
+    // very rough first guess : h = 0.01 * ||y/scale|| / ||y'/scale||
+    // this guess will be used to perform an Euler step
+    double ratio;
+    double yOnScale2 = 0;
+    double yDotOnScale2 = 0;
+    for (int j = 0; j < y0.length; ++j) {
+      ratio         = y0[j] / scale[j];
+      yOnScale2    += ratio * ratio;
+      ratio         = yDot0[j] / scale[j];
+      yDotOnScale2 += ratio * ratio;
+    }
+
+    double h = ((yOnScale2 < 1.0e-10) || (yDotOnScale2 < 1.0e-10))
+      ? 1.0e-6 : (0.01 * Math.sqrt(yOnScale2 / yDotOnScale2));
+    if (! forward) {
+      h = -h;
+    }
+
+    // perform an Euler step using the preceding rough guess
+    for (int j = 0; j < y0.length; ++j) {
+      y1[j] = y0[j] + h * yDot0[j];
+    }
+    equations.computeDerivatives(t0 + h, y1, yDot1);
+
+    // estimate the second derivative of the solution
+    double yDDotOnScale = 0;
+    for (int j = 0; j < y0.length; ++j) {
+      ratio         = (yDot1[j] - yDot0[j]) / scale[j];
+      yDDotOnScale += ratio * ratio;
+    }
+    yDDotOnScale = Math.sqrt(yDDotOnScale) / h;
+
+    // step size is computed such that
+    // h^order * max (||y'/tol||, ||y''/tol||) = 0.01
+    double maxInv2 = Math.max(Math.sqrt(yDotOnScale2), yDDotOnScale);
+    double h1 = (maxInv2 < 1.0e-15)
+      ? Math.max(1.0e-6, 0.001 * Math.abs(h))
+      : Math.pow(0.01 / maxInv2, 1.0 / order);
+    h = Math.min(100.0 * Math.abs(h), h1);
+    h = Math.max(h, 1.0e-12 * Math.abs(t0));  // avoids cancellation when computing t1 - t0
+    if (h < getMinStep()) {
+      h = getMinStep();
+    }
+    if (h > getMaxStep()) {
+      h = getMaxStep();
+    }
+    if (! forward) {
+      h = -h;
+    }
+
+    return h;
+
+  }
+
+  /** Filter the integration step.
+   * @param h signed step
+   * @param acceptSmall if true, steps smaller than the minimal value
+   * are silently increased up to this value, if false such small
+   * steps generate an exception
+   * @return a bounded integration step (h if no bound is reach, or a bounded value)
+   * @exception IntegratorException if the step is too small and acceptSmall is false
+   */
+  protected double filterStep(double h, boolean acceptSmall)
+    throws IntegratorException {
+
+    if (Math.abs(h) < minStep) {
+      if (acceptSmall) {
+        h = (h < 0) ? -minStep : minStep;
+      } else {
+        throw new IntegratorException("minimal step size ({0}) reached,"
+                                      + " integration needs {1}",
+                                      new String[] {
+                                        Double.toString(minStep),
+                                        Double.toString(Math.abs(h))
+                                      });
+      }
+    }
+
+    if (h > maxStep) {
+      h = maxStep;
+    } else if (h < -maxStep) {
+      h = -maxStep;
+    }
+
+    return h;
+
+  }
+
+  public abstract void integrate (FirstOrderDifferentialEquations equations,
+                                  double t0, double[] y0,
+                                  double t, double[] y)
+    throws DerivativeException, IntegratorException;
+
+  /** Get the minimal step.
+   * @return minimal step
+   */
+  public double getMinStep() {
+    return minStep;
+  }
+
+  /** Get the maximal step.
+   * @return maximal step
+   */
+  public double getMaxStep() {
+    return maxStep;
+  }
+
+  /** Minimal step. */
+  private double minStep;
+
+  /** Maximal step. */
+  private double maxStep;
+
+  /** User supplied initial step. */
+  private double initialStep;
+
+  /** Allowed absolute scalar error. */
+  protected double scalAbsoluteTolerance;
+
+  /** Allowed relative scalar error. */
+  protected double scalRelativeTolerance;
+
+  /** Allowed absolute vectorial error. */
+  protected double[] vecAbsoluteTolerance;
+
+  /** Allowed relative vectorial error. */
+  protected double[] vecRelativeTolerance;
+
+  /** Step handler. */
+  protected StepHandler handler;
+
+  /** Switching functions handler. */
+  protected SwitchingFunctionsHandler switchesHandler;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaIntegrator.java?view=auto&rev=512066
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaIntegrator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaIntegrator.java Mon Feb 26 15:12:40 2007
@@ -0,0 +1,82 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.ode;
+
+/**
+ * This class implements the classical fourth order Runge-Kutta
+ * integrator for Ordinary Differential Equations (it is the most
+ * often used Runge-Kutta method).
+
+ * <p>This method is an explicit Runge-Kutta method, its Butcher-array
+ * is the following one :
+ * <pre>
+ *    0  |  0    0    0    0
+ *   1/2 | 1/2   0    0    0
+ *   1/2 |  0   1/2   0    0
+ *    1  |  0    0    1    0
+ *       |--------------------
+ *       | 1/6  1/3  1/3  1/6
+ * </pre>
+ * </p>
+
+ * @see EulerIntegrator
+ * @see GillIntegrator
+ * @see MidpointIntegrator
+ * @see ThreeEighthesIntegrator
+
+ * @version $Id: ClassicalRungeKuttaIntegrator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class ClassicalRungeKuttaIntegrator
+  extends RungeKuttaIntegrator {
+
+  private static final String methodName = "classical Runge-Kutta";
+
+  private static final double[] c = {
+    1.0 / 2.0, 1.0 / 2.0, 1.0
+  };
+
+  private static final double[][] a = {
+    { 1.0 / 2.0 },
+    { 0.0, 1.0 / 2.0 },
+    { 0.0, 0.0, 1.0 }
+  };
+
+  private static final double[] b = {
+    1.0 / 6.0, 1.0 / 3.0, 1.0 / 3.0, 1.0 / 6.0
+  };
+
+  /** Simple constructor.
+   * Build a fourth-order Runge-Kutta integrator with the given
+   * step.
+   * @param step integration step
+   */
+  public ClassicalRungeKuttaIntegrator(double step) {
+    super(false, c, a, b, new ClassicalRungeKuttaStepInterpolator(), step);
+  }
+
+  /** Get the name of the method.
+   * @return name of the method
+   */
+  public String getName() {
+    return methodName;
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaIntegrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java?view=auto&rev=512066
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java Mon Feb 26 15:12:40 2007
@@ -0,0 +1,113 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.ode;
+
+/**
+ * This class implements a step interpolator for the classical fourth
+ * order Runge-Kutta integrator.
+
+ * <p>This interpolator allows to compute dense output inside the last
+ * step computed. The interpolation equation is consistent with the
+ * integration scheme :
+
+ * <pre>
+ *   y(t_n + theta h) = y (t_n + h)
+ *                    + (1 - theta) (h/6) [ (-4 theta^2 + 5 theta - 1) y'_1
+ *                                          +(4 theta^2 - 2 theta - 2) (y'_2 + y'_3)
+ *                                          -(4 theta^2 +   theta + 1) y'_4
+ *                                        ]
+ * </pre>
+
+ * where theta belongs to [0 ; 1] and where y'_1 to y'_4 are the four
+ * evaluations of the derivatives already computed during the
+ * step.</p>
+
+ * @see ClassicalRungeKuttaIntegrator
+
+ * @version $Id: ClassicalRungeKuttaStepInterpolator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+class ClassicalRungeKuttaStepInterpolator
+  extends RungeKuttaStepInterpolator {
+    
+  /** Simple constructor.
+   * This constructor builds an instance that is not usable yet, the
+   * {@link RungeKuttaStepInterpolator#reinitialize} method should be
+   * called before using the instance in order to initialize the
+   * internal arrays. This constructor is used only in order to delay
+   * the initialization in some cases. The {@link RungeKuttaIntegrator}
+   * class uses the prototyping design pattern to create the step
+   * interpolators by cloning an uninitialized model and latter initializing
+   * the copy.
+   */
+  public ClassicalRungeKuttaStepInterpolator() {
+  }
+
+  /** 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 ClassicalRungeKuttaStepInterpolator(ClassicalRungeKuttaStepInterpolator interpolator) {
+    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
+   */
+  public Object clone() {
+    return new ClassicalRungeKuttaStepInterpolator(this);
+  }
+
+  /** Compute the state at the interpolated time.
+   * This is the main processing method that should be implemented by
+   * the derived classes to perform the interpolation.
+   * @param theta normalized interpolation abscissa within the step
+   * (theta is zero at the previous time step and one at the current time step)
+   * @param oneMinusThetaH time gap between the interpolated time and
+   * the current time
+   * @throws DerivativeException this exception is propagated to the caller if the
+   * underlying user function triggers one
+   */
+  protected void computeInterpolatedState(double theta,
+                                          double oneMinusThetaH)
+    throws DerivativeException {
+
+    double fourTheta = 4 * theta;
+    double s         = oneMinusThetaH / 6.0;
+    double coeff1    = s * ((-fourTheta + 5) * theta - 1);
+    double coeff23   = s * (( fourTheta - 2) * theta - 2);
+    double coeff4    = s * ((-fourTheta - 1) * theta - 1);
+
+    for (int i = 0; i < interpolatedState.length; ++i) {
+      interpolatedState[i] = currentState[i]
+                            + coeff1  * yDotK[0][i]
+                            + coeff23 * (yDotK[1][i] + yDotK[2][i])
+                            + coeff4  * yDotK[3][i];
+     }
+
+  }
+
+  private static final long serialVersionUID = -6576285612589783992L;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ClassicalRungeKuttaStepInterpolator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java?view=auto&rev=512066
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java Mon Feb 26 15:12:40 2007
@@ -0,0 +1,376 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.ode;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.io.Serializable;
+
+/**
+ * This class stores all information provided by an ODE integrator
+ * during the integration process and build a continuous model of the
+ * solution from this.
+
+ * <p>This class act as a step handler from the integrator point of
+ * view. It is called iteratively during the integration process and
+ * stores a copy of all steps information in a sorted collection for
+ * later use. Once the integration process is over, the user can use
+ * the {@link #setInterpolatedTime setInterpolatedTime} and {@link
+ * #getInterpolatedState getInterpolatedState} to retrieve this
+ * information at any time. It is important to wait for the
+ * integration to be over before attempting to call {@link
+ * #setInterpolatedTime setInterpolatedTime} because some internal
+ * variables are set only once the last step has been handled.</p>
+
+ * <p>This is useful for example if the main loop of the user
+ * application should remain independant from the integration process
+ * or if one needs to mimic the behaviour of an analytical model
+ * despite a numerical model is used (i.e. one needs the ability to
+ * get the model value at any time or to navigate through the
+ * data).</p>
+
+ * <p>If problem modelization is done with several separate
+ * integration phases for contiguous intervals, the same
+ * ContinuousOutputModel can be used as step handler for all
+ * integration phases as long as they are performed in order and in
+ * the same direction. As an example, one can extrapolate the
+ * trajectory of a satellite with one model (i.e. one set of
+ * differential equations) up to the beginning of a maneuver, use
+ * another more complex model including thrusters modelization and
+ * accurate attitude control during the maneuver, and revert to the
+ * first model after the end of the maneuver. If the same continuous
+ * output model handles the steps of all integration phases, the user
+ * do not need to bother when the maneuver begins or ends, he has all
+ * the data available in a transparent manner.</p>
+
+ * <p>An important feature of this class is that it implements the
+ * <code>Serializable</code> interface. This means that the result of
+ * an integration can be serialized and reused later (if stored into a
+ * persistent medium like a filesystem or a database) or elsewhere (if
+ * sent to another application). Only the result of the integration is
+ * stored, there is no reference to the integrated problem by
+ * itself.</p>
+
+ * <p>One should be aware that the amount of data stored in a
+ * ContinuousOutputModel instance can be important if the state vector
+ * is large, if the integration interval is long or if the steps are
+ * small (which can result from small tolerance settings in {@link
+ * AdaptiveStepsizeIntegrator adaptive step size integrators}).</p>
+
+ * @see StepHandler
+ * @see StepInterpolator
+
+ * @version $Id: ContinuousOutputModel.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class ContinuousOutputModel
+  implements StepHandler, Serializable {
+
+  /** Simple constructor.
+   * Build an empty continuous output model.
+   */
+  public ContinuousOutputModel() {
+    steps = new ArrayList();
+    reset();
+  }
+
+  /** Append another model at the end of the instance.
+   * @param model model to add at the end of the instance
+   * @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) {
+
+    if (model.steps.size() == 0) {
+      return;
+    }
+
+    if (steps.size() == 0) {
+      initialTime = model.initialTime;
+      forward     = model.forward;
+    } else {
+
+      if (getInterpolatedState().length != model.getInterpolatedState().length) {
+        throw new IllegalArgumentException("state vector dimension mismatch");
+      }
+
+      if (forward ^ model.forward) {
+        throw new IllegalArgumentException("propagation direction mismatch");
+      }
+
+      StepInterpolator lastInterpolator = (StepInterpolator) steps.get(index);
+      double current  = lastInterpolator.getCurrentTime();
+      double previous = lastInterpolator.getPreviousTime();
+      double step = current - previous;
+      double gap = model.getInitialTime() - current;
+      if (Math.abs(gap) > 1.0e-3 * Math.abs(step)) {
+        throw new IllegalArgumentException("hole between time ranges");
+      }
+
+    }
+
+    for (Iterator iter = model.steps.iterator(); iter.hasNext(); ) {
+      AbstractStepInterpolator ai = (AbstractStepInterpolator) iter.next();
+      steps.add(ai.clone());
+    }
+
+    index = steps.size() - 1;
+    finalTime = ((StepInterpolator) steps.get(index)).getCurrentTime();
+
+  }
+
+  /** Determines whether this handler needs dense output.
+   * <p>The essence of this class is to provide dense output over all
+   * steps, hence it requires the internal steps to provide themselves
+   * dense output. The method therefore returns always true.</p>
+   * @return always true
+   */
+  public boolean requiresDenseOutput() {
+    return true;
+  }
+
+  /** Reset the step handler.
+   * Initialize the internal data as required before the first step is
+   * handled.
+   */
+  public void reset() {
+    initialTime = Double.NaN;
+    finalTime   = Double.NaN;
+    forward     = true;
+    index       = 0;
+    steps.clear();
+   }
+
+  /** Handle the last accepted step.
+   * A copy of the information provided by the last step is stored in
+   * the instance for later use.
+   * @param interpolator interpolator for the last accepted step.
+   * @param isLast true if the step is the last one
+   * @throws DerivativeException this exception is propagated to the
+   * caller if the underlying user function triggers one
+   */
+  public void handleStep(StepInterpolator interpolator, boolean isLast)
+    throws DerivativeException {
+
+    AbstractStepInterpolator ai = (AbstractStepInterpolator) interpolator;
+
+    if (steps.size() == 0) {
+      initialTime = interpolator.getPreviousTime();
+      forward     = interpolator.isForward();
+    }
+
+    ai.finalizeStep();
+    steps.add(ai.clone());
+
+    if (isLast) {
+      finalTime = ai.getCurrentTime();
+      index     = steps.size() - 1;
+    }
+
+  }
+
+  /**
+   * Get the initial integration time.
+   * @return initial integration time
+   */
+  public double getInitialTime() {
+    return initialTime;
+  }
+    
+  /**
+   * Get the final integration time.
+   * @return final integration time
+   */
+  public double getFinalTime() {
+    return finalTime;
+  }
+
+  /**
+   * Get the time of the interpolated point.
+   * If {@link #setInterpolatedTime} has not been called, it returns
+   * the final integration time.
+   * @return interpolation point time
+   */
+  public double getInterpolatedTime() {
+    return ((StepInterpolator) steps.get(index)).getInterpolatedTime();
+  }
+    
+  /** Set the time of the interpolated point.
+   * <p>This method should <strong>not</strong> be called before the
+   * integration is over because some internal variables are set only
+   * once the last step has been handled.</p>
+   * <p>Setting the time outside of the integration interval is now
+   * allowed (it was not allowed up to version 5.9 of Mantissa), but
+   * should be used with care since the accuracy of the interpolator
+   * will probably be very poor far from this interval. This allowance
+   * has been added to simplify implementation of search algorithms
+   * near the interval endpoints.</p>
+   * @param time time of the interpolated point
+   */
+  public void setInterpolatedTime(double time) {
+
+    try {
+      // initialize the search with the complete steps table
+      int iMin = 0;
+      StepInterpolator sMin = (StepInterpolator) steps.get(iMin);
+      double tMin = 0.5 * (sMin.getPreviousTime() + sMin.getCurrentTime());
+
+      int iMax = steps.size() - 1;
+      StepInterpolator sMax = (StepInterpolator) steps.get(iMax);
+      double tMax = 0.5 * (sMax.getPreviousTime() + sMax.getCurrentTime());
+
+      // handle points outside of the integration interval
+      // or in the first and last step
+      if (locatePoint(time, sMin) <= 0) {
+        index = iMin;
+        sMin.setInterpolatedTime(time);
+        return;
+      }
+      if (locatePoint(time, sMax) >= 0) {
+        index = iMax;
+        sMax.setInterpolatedTime(time);
+        return;
+      }
+
+      // reduction of the table slice size
+      while (iMax - iMin > 5) {
+
+        // use the last estimated index as the splitting index
+        StepInterpolator si = (StepInterpolator) steps.get(index);
+        int location = locatePoint(time, si);
+        if (location < 0) {
+          iMax = index;
+          tMax = 0.5 * (si.getPreviousTime() + si.getCurrentTime());
+        } else if (location > 0) {
+          iMin = index;
+          tMin = 0.5 * (si.getPreviousTime() + si.getCurrentTime());
+        } else {
+          // we have found the target step, no need to continue searching
+          si.setInterpolatedTime(time);
+          return;
+        }
+
+        // compute a new estimate of the index in the reduced table slice
+        int iMed = (iMin + iMax) / 2;
+        StepInterpolator sMed = (StepInterpolator) steps.get(iMed);
+        double tMed = 0.5 * (sMed.getPreviousTime() + sMed.getCurrentTime());
+
+        if ((Math.abs(tMed - tMin) < 1e-6) || (Math.abs(tMax - tMed) < 1e-6)) {
+          // too close to the bounds, we estimate using a simple dichotomy
+          index = iMed;
+        } else {
+          // estimate the index using a reverse quadratic polynom
+          // (reverse means we have i = P(t), thus allowing to simply
+          // compute index = P(time) rather than solving a quadratic equation)
+          double d12 = tMax - tMed;
+          double d23 = tMed - tMin;
+          double d13 = tMax - tMin;
+          double dt1 = time - tMax;
+          double dt2 = time - tMed;
+          double dt3 = time - tMin;
+          double iLagrange = (  (dt2 * dt3 * d23) * iMax
+                              - (dt1 * dt3 * d13) * iMed
+                              + (dt1 * dt2 * d12) * iMin)
+                           / (d12 * d23 * d13);
+          index = (int) Math.rint(iLagrange);
+        }
+
+        // force the next size reduction to be at least one tenth
+        int low  = Math.max(iMin + 1, (9 * iMin + iMax) / 10);
+        int high = Math.min(iMax - 1, (iMin + 9 * iMax) / 10);
+        if (index < low) {
+          index = low;
+        } else if (index > high) {
+          index = high;
+        }
+
+      }
+
+      // now the table slice is very small, we perform an iterative search
+      index = iMin;
+      while ((index <= iMax)
+             && (locatePoint(time, (StepInterpolator) steps.get(index)) > 0)) {
+        ++index;
+      }
+
+      StepInterpolator si = (StepInterpolator) steps.get(index);
+
+      si.setInterpolatedTime(time);
+
+    } catch (DerivativeException de) {
+      throw new RuntimeException("unexpected DerivativeException caught: "
+                                 + de.getMessage());
+    }
+
+  }
+
+  /**
+   * Get the state vector of the interpolated point.
+   * @return state vector at time {@link #getInterpolatedTime}
+   */
+  public double[] getInterpolatedState() {
+    return ((StepInterpolator) steps.get(index)).getInterpolatedState();
+  }
+
+  /** Compare a step interval and a double. 
+   * @param time point to locate
+   * @param interval step interval
+   * @return -1 if the double is before the interval, 0 if it is in
+   * the interval, and +1 if it is after the interval, according to
+   * the interval direction
+   */
+  private int locatePoint(double time, StepInterpolator interval) {
+    if (forward) {
+      if (time < interval.getPreviousTime()) {
+        return -1;
+      } else if (time > interval.getCurrentTime()) {
+        return +1;
+      } else {
+        return 0;
+      }
+    }
+    if (time > interval.getPreviousTime()) {
+      return -1;
+    } else if (time < interval.getCurrentTime()) {
+      return +1;
+    } else {
+      return 0;
+    }
+  }
+
+  /** Initial integration time. */
+  private double initialTime;
+
+  /** Final integration time. */
+  private double finalTime;
+
+  /** Integration direction indicator. */
+  private boolean forward;
+
+  /** Current interpolator index. */
+  private int index;
+
+  /** Steps table. */
+  private ArrayList steps;
+
+  private static final long serialVersionUID = 2259286184268533249L;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DerivativeException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DerivativeException.java?view=auto&rev=512066
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DerivativeException.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DerivativeException.java Mon Feb 26 15:12:40 2007
@@ -0,0 +1,50 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.ode;
+
+import org.apache.commons.math.MathException;
+
+/**
+ * This exception is made available to users to report
+ * the error conditions that are trigegred while computing
+ * the differential equations.
+ * @author Luc Maisonobe
+ * @version $Id: DerivativeException.java 1705 2006-09-17 19:57:39Z luc $
+ */
+public class DerivativeException
+  extends MathException {
+    
+  /** Simple constructor.
+   * Build an exception by translating and formating a message
+   * @param specifier format specifier (to be translated)
+   * @param parts to insert in the format (no translation)
+   */
+  public DerivativeException(String specifier, String[] parts) {
+    super(specifier, parts);
+  }
+
+  /** Build an instance from an underlying cause.
+   * @param cause cause for the exception
+   */
+  public DerivativeException(Throwable cause) {
+    super(cause);
+  }
+
+  private static final long serialVersionUID = -4100440615830558122L;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DerivativeException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54Integrator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54Integrator.java?view=auto&rev=512066
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54Integrator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54Integrator.java Mon Feb 26 15:12:40 2007
@@ -0,0 +1,153 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.ode;
+
+/**
+ * This class implements the 5(4) Dormand-Prince integrator for Ordinary
+ * Differential Equations.
+
+ * <p>This integrator is an embedded Runge-Kutta-Fehlberg integrator
+ * of order 5(4) used in local extrapolation mode (i.e. the solution
+ * is computed using the high order formula) with stepsize control
+ * (and automatic step initialization) and continuous output. This
+ * method uses 7 functions evaluations per step. However, since this
+ * is an <i>fsal</i>, the last evaluation of one step is the same as
+ * the first evaluation of the next step and hence can be avoided. So
+ * the cost is really 6 functions evaluations per step.</p>
+
+ * <p>This method has been published (whithout the continuous output
+ * that was added by Shampine in 1986) in the following article :
+ * <pre>
+ *  A family of embedded Runge-Kutta formulae
+ *  J. R. Dormand and P. J. Prince
+ *  Journal of Computational and Applied Mathematics
+ *  volume 6, no 1, 1980, pp. 19-26
+ * </pre></p>
+
+ * @version $Id: DormandPrince54Integrator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class DormandPrince54Integrator
+  extends RungeKuttaFehlbergIntegrator {
+
+  private static final String methodName = "Dormand-Prince 5(4)";
+
+  private static final double[] c = {
+    1.0/5.0, 3.0/10.0, 4.0/5.0, 8.0/9.0, 1.0, 1.0
+  };
+
+  private static final double[][] a = {
+    {1.0/5.0},
+    {3.0/40.0, 9.0/40.0},
+    {44.0/45.0, -56.0/15.0, 32.0/9.0},
+    {19372.0/6561.0, -25360.0/2187.0, 64448.0/6561.0,  -212.0/729.0},
+    {9017.0/3168.0, -355.0/33.0, 46732.0/5247.0, 49.0/176.0, -5103.0/18656.0},
+    {35.0/384.0, 0.0, 500.0/1113.0, 125.0/192.0, -2187.0/6784.0, 11.0/84.0}
+  };
+
+  private static final double[] b = {
+    35.0/384.0, 0.0, 500.0/1113.0, 125.0/192.0, -2187.0/6784.0, 11.0/84.0, 0.0
+  };
+
+  private static final double e1 =     71.0 / 57600.0;
+  private static final double e3 =    -71.0 / 16695.0;
+  private static final double e4 =     71.0 / 1920.0;
+  private static final double e5 = -17253.0 / 339200.0;
+  private static final double e6 =     22.0 / 525.0;
+  private static final double e7 =     -1.0 / 40.0;
+
+  /** Simple constructor.
+   * Build a fifth order Dormand-Prince integrator with the given step bounds
+   * @param minStep minimal step (must be positive even for backward
+   * integration), the last step can be smaller than this
+   * @param maxStep maximal step (must be positive even for backward
+   * integration)
+   * @param scalAbsoluteTolerance allowed absolute error
+   * @param scalRelativeTolerance allowed relative error
+   */
+  public DormandPrince54Integrator(double minStep, double maxStep,
+                                   double scalAbsoluteTolerance,
+                                   double scalRelativeTolerance) {
+    super(true, c, a, b, new DormandPrince54StepInterpolator(),
+          minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
+  }
+
+  /** Simple constructor.
+   * Build a fifth order Dormand-Prince integrator with the given step bounds
+   * @param minStep minimal step (must be positive even for backward
+   * integration), the last step can be smaller than this
+   * @param maxStep maximal step (must be positive even for backward
+   * integration)
+   * @param vecAbsoluteTolerance allowed absolute error
+   * @param vecRelativeTolerance allowed relative error
+   */
+  public DormandPrince54Integrator(double minStep, double maxStep,
+                                   double[] vecAbsoluteTolerance,
+                                   double[] vecRelativeTolerance) {
+    super(true, c, a, b, new DormandPrince54StepInterpolator(),
+          minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance);
+  }
+
+  /** Get the name of the method.
+   * @return name of the method
+   */
+  public String getName() {
+    return methodName;
+  }
+
+  /** Get the order of the method.
+   * @return order of the method
+   */
+  public int getOrder() {
+    return 5;
+  }
+
+  /** Compute the error ratio.
+   * @param yDotK derivatives computed during the first stages
+   * @param y0 estimate of the step at the start of the step
+   * @param y1 estimate of the step at the end of the step
+   * @param h  current step
+   * @return error ratio, greater than 1 if step should be rejected
+   */
+  protected double estimateError(double[][] yDotK,
+                                 double[] y0, double[] y1,
+                                 double h) {
+
+    double error = 0;
+
+    for (int j = 0; j < y0.length; ++j) {
+      double errSum = e1 * yDotK[0][j] +  e3 * yDotK[2][j]
+                    + e4 * yDotK[3][j] +  e5 * yDotK[4][j]
+                    + e6 * yDotK[5][j] +  e7 * yDotK[6][j];
+
+      double yScale = Math.max(Math.abs(y0[j]), Math.abs(y1[j]));
+      double tol = (vecAbsoluteTolerance == null)
+        ? (scalAbsoluteTolerance + scalRelativeTolerance * yScale)
+        : (vecAbsoluteTolerance[j] + vecRelativeTolerance[j] * yScale);
+      double ratio  = h * errSum / tol;
+      error += ratio * ratio;
+
+    }
+
+    return Math.sqrt(error / y0.length);
+
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54Integrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java?view=auto&rev=512066
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java Mon Feb 26 15:12:40 2007
@@ -0,0 +1,197 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math.ode;
+
+/**
+ * This class represents an interpolator over the last step during an
+ * ODE integration for the 5(4) Dormand-Prince integrator.
+ *
+ * @see DormandPrince54Integrator
+ *
+ * @version $Id: DormandPrince54StepInterpolator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+ *
+ */
+
+class DormandPrince54StepInterpolator
+  extends RungeKuttaStepInterpolator {
+
+  /** Simple constructor.
+   * This constructor builds an instance that is not usable yet, the
+   * {@link #reinitialize} method should be called before using the
+   * instance in order to initialize the internal arrays. This
+   * constructor is used only in order to delay the initialization in
+   * some cases. The {@link RungeKuttaFehlbergIntegrator} uses the
+   * prototyping design pattern to create the step interpolators by
+   * cloning an uninitialized model and latter initializing the copy.
+   */
+  public DormandPrince54StepInterpolator() {
+    super();
+    v1 = null;
+    v2 = null;
+    v3 = null;
+    v4 = null;
+    vectorsInitialized = false;
+  }
+
+  /** 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 DormandPrince54StepInterpolator(DormandPrince54StepInterpolator interpolator) {
+
+    super(interpolator);
+
+    if (interpolator.v1 == null) {
+
+      v1 = null;
+      v2 = null;
+      v3 = null;
+      v4 = null;
+      vectorsInitialized = false;
+
+    } else {
+
+      v1 = (double[]) interpolator.v1.clone();
+      v2 = (double[]) interpolator.v2.clone();
+      v3 = (double[]) interpolator.v3.clone();
+      v4 = (double[]) interpolator.v4.clone();
+      vectorsInitialized = interpolator.vectorsInitialized;
+
+    }
+
+  }
+
+  /**
+   * 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
+   */
+  public Object clone() {
+    return new DormandPrince54StepInterpolator(this);
+  }
+
+  /** Reinitialize the instance
+   * @param equations set of differential equations being integrated
+   * @param y reference to the integrator array holding the state at
+   * the end of the step
+   * @param yDotK reference to the integrator array holding all the
+   * intermediate slopes
+   * @param forward integration direction indicator
+   */
+  public void reinitialize(FirstOrderDifferentialEquations equations,
+                           double[] y, double[][] yDotK, boolean forward) {
+    super.reinitialize(equations, y, yDotK, forward);
+    v1 = null;
+    v2 = null;
+    v3 = null;
+    v4 = null;
+    vectorsInitialized = false;
+  }
+
+  /** Store the current step time.
+   * @param t current time
+   */
+  public void storeTime(double t) {
+    super.storeTime(t);
+    vectorsInitialized = false;
+  }
+
+  /** Compute the state at the interpolated time.
+   * @param theta normalized interpolation abscissa within the step
+   * (theta is zero at the previous time step and one at the current time step)
+   * @param oneMinusThetaH time gap between the interpolated time and
+   * the current time
+   * @throws DerivativeException this exception is propagated to the caller if the
+   * underlying user function triggers one
+   */
+  protected void computeInterpolatedState(double theta,
+                                          double oneMinusThetaH)
+    throws DerivativeException {
+
+    if (! vectorsInitialized) {
+
+      if (v1 == null) {
+        v1 = new double[interpolatedState.length];
+        v2 = new double[interpolatedState.length];
+        v3 = new double[interpolatedState.length];
+        v4 = new double[interpolatedState.length];
+      }
+
+      // no step finalization is needed for this interpolator
+
+      // we need to compute the interpolation vectors for this time step
+      for (int i = 0; i < interpolatedState.length; ++i) {
+        v1[i] = h * (a70 * yDotK[0][i] + a72 * yDotK[2][i] + a73 * yDotK[3][i]
+                     + a74 * yDotK[4][i] + a75 * yDotK[5][i]);
+        v2[i] = h * yDotK[0][i] - v1[i];
+        v3[i] = v1[i] - v2[i] - h * yDotK[6][i];
+        v4[i] = h * (d0 * yDotK[0][i] + d2 * yDotK[2][i] + d3 * yDotK[3][i]
+                     + d4 * yDotK[4][i] + d5 * yDotK[5][i] + d6 * yDotK[6][i]);
+      }
+
+      vectorsInitialized = true;
+
+    }
+
+    // interpolate
+    double eta = oneMinusThetaH / h;
+    for (int i = 0; i < interpolatedState.length; ++i) {
+      interpolatedState[i] = currentState[i]
+                           - eta * (v1[i]
+                                    - theta * (v2[i]
+                                               + theta * (v3[i]
+                                                          + eta * v4[i])));
+    }
+
+  }
+
+  /** First vector for interpolation. */
+  private double[] v1;
+
+  /** Second vector for interpolation. */
+  private double[] v2;
+
+  /** Third vector for interpolation. */
+  private double[] v3;
+
+  /** Fourth vector for interpolation. */
+  private double[] v4;
+
+  /** Initialization indicator for the interpolation vectors. */
+  private boolean vectorsInitialized;
+
+  // last row of the Butcher-array internal weights, note that a71 is null
+  private static final double a70 =    35.0 /  384.0;
+  private static final double a72 =   500.0 / 1113.0;
+  private static final double a73 =   125.0 /  192.0;
+  private static final double a74 = -2187.0 / 6784.0;
+  private static final double a75 =    11.0 /   84.0;
+
+  // dense output of Shampine (1986), note that d1 is null
+  private static final double d0 =  -12715105075.0 /  11282082432.0;
+  private static final double d2 =   87487479700.0 /  32700410799.0;
+  private static final double d3 =  -10690763975.0 /   1880347072.0;
+  private static final double d4 =  701980252875.0 / 199316789632.0;
+  private static final double d5 =   -1453857185.0 /    822651844.0;
+  private static final double d6 =      69997945.0 /     29380423.0;
+
+  private static final long serialVersionUID = 4104157279605906956L;
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/DormandPrince54StepInterpolator.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message