Author: luc
Date: Mon Apr 25 09:45:49 2011
New Revision: 1096443

URL: http://svn.apache.org/viewvc?rev=1096443&view=rev
Log:
Added setters allowing to change the step size control parameters of adaptive 
step size ODE integrators

Jira: MATH-563

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java?rev=1096443&r1=1096442&r2=1096443&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java
 Mon Apr 25 09:45:49 2011
@@ -66,16 +66,16 @@ public abstract class AdaptiveStepsizeIn
   extends AbstractIntegrator {
 
     /** Allowed absolute scalar error. */
-    protected final double scalAbsoluteTolerance;
+    protected double scalAbsoluteTolerance;
 
     /** Allowed relative scalar error. */
-    protected final double scalRelativeTolerance;
+    protected double scalRelativeTolerance;
 
     /** Allowed absolute vectorial error. */
-    protected final double[] vecAbsoluteTolerance;
+    protected double[] vecAbsoluteTolerance;
 
     /** Allowed relative vectorial error. */
-    protected final double[] vecRelativeTolerance;
+    protected double[] vecRelativeTolerance;
 
     /** Main set dimension. */
     protected int mainSetDimension;
@@ -84,10 +84,10 @@ public abstract class AdaptiveStepsizeIn
     private double initialStep;
 
     /** Minimal step. */
-    private final double minStep;
+    private double minStep;
 
     /** Maximal step. */
-    private final double maxStep;
+    private double maxStep;
 
   /** Build an integrator with the given stepsize bounds.
    * The default step handler does nothing.
@@ -107,16 +107,7 @@ public abstract class AdaptiveStepsizeIn
                                     final double scalRelativeTolerance) {
 
     super(name);
-
-    this.minStep     = FastMath.abs(minStep);
-    this.maxStep     = FastMath.abs(maxStep);
-    this.initialStep = -1.0;
-
-    this.scalAbsoluteTolerance = scalAbsoluteTolerance;
-    this.scalRelativeTolerance = scalRelativeTolerance;
-    this.vecAbsoluteTolerance  = null;
-    this.vecRelativeTolerance  = null;
-
+    setStepSizeControl(minStep, maxStep, scalAbsoluteTolerance, 
scalRelativeTolerance);
     resetInternalState();
 
   }
@@ -139,17 +130,66 @@ public abstract class AdaptiveStepsizeIn
                                     final double[] vecRelativeTolerance) {
 
     super(name);
+    setStepSizeControl(minStep, maxStep, vecAbsoluteTolerance, 
vecRelativeTolerance);
+    resetInternalState();
 
-    this.minStep     = minStep;
-    this.maxStep     = maxStep;
-    this.initialStep = -1.0;
-
-    this.scalAbsoluteTolerance = 0;
-    this.scalRelativeTolerance = 0;
-    this.vecAbsoluteTolerance  = vecAbsoluteTolerance.clone();
-    this.vecRelativeTolerance  = vecRelativeTolerance.clone();
+  }
 
-    resetInternalState();
+  /** Set the adaptive step size control parameters.
+   * <p>
+   * A side effect of this method is to also reset the initial
+   * step so it will be automatically computed by the integrator
+   * if {@link #setInitialStepSize(double) setInitialStepSize}
+   * is not called by the user.
+   * </p>
+   * @param minimalStep minimal step (must be positive even for backward
+   * integration), the last step can be smaller than this
+   * @param maximalStep maximal step (must be positive even for backward
+   * integration)
+   * @param absoluteTolerance allowed absolute error
+   * @param relativeTolerance allowed relative error
+   */
+  public void setStepSizeControl(final double minimalStep, final double 
maximalStep,
+                                 final double absoluteTolerance,
+                                 final double relativeTolerance) {
+
+      minStep     = FastMath.abs(minimalStep);
+      maxStep     = FastMath.abs(maximalStep);
+      initialStep = -1;
+
+      scalAbsoluteTolerance = absoluteTolerance;
+      scalRelativeTolerance = relativeTolerance;
+      vecAbsoluteTolerance  = null;
+      vecRelativeTolerance  = null;
+
+  }
+
+  /** Set the adaptive step size control parameters.
+   * <p>
+   * A side effect of this method is to also reset the initial
+   * step so it will be automatically computed by the integrator
+   * if {@link #setInitialStepSize(double) setInitialStepSize}
+   * is not called by the user.
+   * </p>
+   * @param minimalStep minimal step (must be positive even for backward
+   * integration), the last step can be smaller than this
+   * @param maximalStep maximal step (must be positive even for backward
+   * integration)
+   * @param absoluteTolerance allowed absolute error
+   * @param relativeTolerance allowed relative error
+   */
+  public void setStepSizeControl(final double minimalStep, final double 
maximalStep,
+                                 final double[] absoluteTolerance,
+                                 final double[] relativeTolerance) {
+
+      minStep     = FastMath.abs(minimalStep);
+      maxStep     = FastMath.abs(maximalStep);
+      initialStep = -1;
+
+      scalAbsoluteTolerance = 0;
+      scalRelativeTolerance = 0;
+      vecAbsoluteTolerance  = absoluteTolerance.clone();
+      vecRelativeTolerance  = relativeTolerance.clone();
 
   }
 

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1096443&r1=1096442&r2=1096443&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Apr 25 09:45:49 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="luc" type="add" issue="MATH-563" >
+        Added setters allowing to change the step size control parameters of 
adaptive
+        step size ODE integrators
+      </action>
       <action dev="luc" type="add" issue="MATH-557" >
         Added a compareTo method to MathUtils that uses a number of ulps as a
         tolerance error, and works well on all numbers, including normals, 
subnormals,

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java?rev=1096443&r1=1096442&r2=1096443&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/nonstiff/DormandPrince853IntegratorTest.java
 Mon Apr 25 09:45:49 2011
@@ -158,16 +158,17 @@ public class DormandPrince853IntegratorT
     throws MathUserException, IntegratorException {
 
     int previousCalls = Integer.MAX_VALUE;
+    AdaptiveStepsizeIntegrator integ =
+        new DormandPrince853Integrator(0, Double.POSITIVE_INFINITY,
+                                       Double.NaN, Double.NaN);
     for (int i = -12; i < -2; ++i) {
       TestProblem1 pb = new TestProblem1();
       double minStep = 0;
       double maxStep = pb.getFinalTime() - pb.getInitialTime();
       double scalAbsoluteTolerance = FastMath.pow(10.0, i);
       double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
+      integ.setStepSizeControl(minStep, maxStep, scalAbsoluteTolerance, 
scalRelativeTolerance);
 
-      FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, 
maxStep,
-                                                                  
scalAbsoluteTolerance,
-                                                                  
scalRelativeTolerance);
       TestProblemHandler handler = new TestProblemHandler(pb, integ);
       integ.addStepHandler(handler);
       integ.integrate(pb,


Reply via email to