improved sanity checks at integration start

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@574365 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2007-09-10 20:42:13 +00:00
parent 6261e6a91b
commit dfab77b143
4 changed files with 83 additions and 42 deletions

View File

@ -154,6 +154,58 @@ public abstract class AdaptiveStepsizeIntegrator
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

View File

@ -508,23 +508,7 @@ public class GraggBulirschStoerIntegrator
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

View File

@ -162,22 +162,7 @@ public abstract class RungeKuttaFehlbergIntegrator
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

View File

@ -114,27 +114,47 @@ public abstract class RungeKuttaIntegrator
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