You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2007/09/10 22:42:14 UTC

svn commit: r574365 - in /commons/proper/math/trunk/src/java/org/apache/commons/math/ode: AdaptiveStepsizeIntegrator.java GraggBulirschStoerIntegrator.java RungeKuttaFehlbergIntegrator.java RungeKuttaIntegrator.java

Author: luc
Date: Mon Sep 10 13:42:13 2007
New Revision: 574365

URL: http://svn.apache.org/viewvc?rev=574365&view=rev
Log:
improved sanity checks at integration start

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java?rev=574365&r1=574364&r2=574365&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/AdaptiveStepsizeIntegrator.java Mon Sep 10 13:42:13 2007
@@ -154,6 +154,58 @@
     switchesHandler.add(function, maxCheckInterval, convergence);
   }
 
+  /** Perform some sanity checks on the integration parameters.
+   * @param equations differential equations set
+   * @param t0 start time
+   * @param y0 state vector at t0
+   * @param t target time for the integration
+   * @param y placeholder where to put the state vector
+   * @exception IntegratorException if some inconsistency is detected
+   */
+  protected void sanityChecks(FirstOrderDifferentialEquations equations,
+                              double t0, double[] y0, double t, double[] y)
+    throws IntegratorException {
+      if (equations.getDimension() != y0.length) {
+          throw new IntegratorException("dimensions mismatch: ODE problem has dimension {0},"
+                                        + " initial state vector has dimension {1}",
+                                        new String[] {
+                                          Integer.toString(equations.getDimension()),
+                                          Integer.toString(y0.length)
+                                        });
+      }
+      if (equations.getDimension() != y.length) {
+          throw new IntegratorException("dimensions mismatch: ODE problem has dimension {0},"
+                                        + " final state vector has dimension {1}",
+                                        new String[] {
+                                          Integer.toString(equations.getDimension()),
+                                          Integer.toString(y.length)
+                                        });
+      }
+      if ((vecAbsoluteTolerance != null) && (vecAbsoluteTolerance.length != y0.length)) {
+          throw new IntegratorException("dimensions mismatch: state vector has dimension {0},"
+                                        + " absolute tolerance vector has dimension {1}",
+                                        new String[] {
+                                          Integer.toString(y0.length),
+                                          Integer.toString(vecAbsoluteTolerance.length)
+                                        });
+      }
+      if ((vecRelativeTolerance != null) && (vecRelativeTolerance.length != y0.length)) {
+          throw new IntegratorException("dimensions mismatch: state vector has dimension {0},"
+                                        + " relative tolerance vector has dimension {1}",
+                                        new String[] {
+                                          Integer.toString(y0.length),
+                                          Integer.toString(vecRelativeTolerance.length)
+                                        });
+      }
+      if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) {
+        throw new IntegratorException("too small integration interval: length = {0}",
+                                      new String[] {
+                                        Double.toString(Math.abs(t - t0))
+                                      });
+      }
+      
+  }
+
   /** Initialize the integration step.
    * @param equations differential equations set
    * @param forward forward integration indicator

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerIntegrator.java?rev=574365&r1=574364&r2=574365&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/GraggBulirschStoerIntegrator.java Mon Sep 10 13:42:13 2007
@@ -508,23 +508,7 @@
                         double t0, double[] y0, double t, double[] y)
   throws DerivativeException, IntegratorException {
 
-    // sanity check
-    if (equations.getDimension() != y0.length) {
-      throw new IntegratorException("dimensions mismatch: "
-                                    + "ODE problem has dimension {0}"
-                                    + ", state vector has dimension {1}",
-                                    new String[] {
-                                      Integer.toString(equations.getDimension()),
-                                      Integer.toString(y0.length)
-                                    });
-    }
-    if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) {
-      throw new IntegratorException("too small integration interval: length = {0}",
-                                    new String[] {
-                                      Double.toString(Math.abs(t - t0))
-                                    });
-    }
-
+    sanityChecks(equations, t0, y0, t, y);
     boolean forward = (t > t0);
 
     // create some internal working arrays

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java?rev=574365&r1=574364&r2=574365&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaFehlbergIntegrator.java Mon Sep 10 13:42:13 2007
@@ -162,22 +162,7 @@
                         double t, double[] y)
   throws DerivativeException, IntegratorException {
 
-    // sanity check
-    if (equations.getDimension() != y0.length) {
-      throw new IntegratorException("dimensions mismatch: ODE problem has dimension {0},"
-                                    + " state vector has dimension {1}",
-                                    new String[] {
-                                      Integer.toString(equations.getDimension()),
-                                      Integer.toString(y0.length)
-                                    });
-    }
-    if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) {
-      throw new IntegratorException("too small integration interval: length = {0}",
-                                    new String[] {
-                                      Double.toString(Math.abs(t - t0))
-                                    });
-    }
-    
+    sanityChecks(equations, t0, y0, t, y);
     boolean forward = (t > t0);
 
     // create some internal working arrays

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java?rev=574365&r1=574364&r2=574365&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/RungeKuttaIntegrator.java Mon Sep 10 13:42:13 2007
@@ -114,27 +114,47 @@
     switchesHandler.add(function, maxCheckInterval, convergence);
   }
 
-  public void integrate(FirstOrderDifferentialEquations equations,
-                        double t0, double[] y0,
-                        double t, double[] y)
-  throws DerivativeException, IntegratorException {
-
-    // sanity check
+  /** Perform some sanity checks on the integration parameters.
+   * @param equations differential equations set
+   * @param t0 start time
+   * @param y0 state vector at t0
+   * @param t target time for the integration
+   * @param y placeholder where to put the state vector
+   * @exception IntegratorException if some inconsistency is detected
+   */
+  private void sanityChecks(FirstOrderDifferentialEquations equations,
+                            double t0, double[] y0, double t, double[] y)
+    throws IntegratorException {
     if (equations.getDimension() != y0.length) {
       throw new IntegratorException("dimensions mismatch: ODE problem has dimension {0},"
-                                    + " state vector has dimension {1}",
+                                    + " initial state vector has dimension {1}",
                                     new String[] {
                                       Integer.toString(equations.getDimension()),
                                       Integer.toString(y0.length)
                                     });
     }
+    if (equations.getDimension() != y.length) {
+        throw new IntegratorException("dimensions mismatch: ODE problem has dimension {0},"
+                                      + " final state vector has dimension {1}",
+                                      new String[] {
+                                        Integer.toString(equations.getDimension()),
+                                        Integer.toString(y.length)
+                                      });
+      }
     if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) {
       throw new IntegratorException("too small integration interval: length = {0}",
                                     new String[] {
                                       Double.toString(Math.abs(t - t0))
                                     });
-    }
-    
+    }      
+  }
+
+  public void integrate(FirstOrderDifferentialEquations equations,
+                        double t0, double[] y0,
+                        double t, double[] y)
+  throws DerivativeException, IntegratorException {
+
+    sanityChecks(equations, t0, y0, t, y);
     boolean forward = (t > t0);
 
     // create some internal working arrays