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:
parent
6261e6a91b
commit
dfab77b143
|
@ -154,6 +154,58 @@ public abstract class AdaptiveStepsizeIntegrator
|
||||||
switchesHandler.add(function, maxCheckInterval, convergence);
|
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.
|
/** Initialize the integration step.
|
||||||
* @param equations differential equations set
|
* @param equations differential equations set
|
||||||
* @param forward forward integration indicator
|
* @param forward forward integration indicator
|
||||||
|
|
|
@ -508,23 +508,7 @@ public class GraggBulirschStoerIntegrator
|
||||||
double t0, double[] y0, double t, double[] y)
|
double t0, double[] y0, double t, double[] y)
|
||||||
throws DerivativeException, IntegratorException {
|
throws DerivativeException, IntegratorException {
|
||||||
|
|
||||||
// sanity check
|
sanityChecks(equations, t0, y0, t, y);
|
||||||
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))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean forward = (t > t0);
|
boolean forward = (t > t0);
|
||||||
|
|
||||||
// create some internal working arrays
|
// create some internal working arrays
|
||||||
|
|
|
@ -162,22 +162,7 @@ public abstract class RungeKuttaFehlbergIntegrator
|
||||||
double t, double[] y)
|
double t, double[] y)
|
||||||
throws DerivativeException, IntegratorException {
|
throws DerivativeException, IntegratorException {
|
||||||
|
|
||||||
// sanity check
|
sanityChecks(equations, t0, y0, t, y);
|
||||||
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))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean forward = (t > t0);
|
boolean forward = (t > t0);
|
||||||
|
|
||||||
// create some internal working arrays
|
// create some internal working arrays
|
||||||
|
|
|
@ -114,27 +114,47 @@ public abstract class RungeKuttaIntegrator
|
||||||
switchesHandler.add(function, maxCheckInterval, convergence);
|
switchesHandler.add(function, maxCheckInterval, convergence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void integrate(FirstOrderDifferentialEquations equations,
|
/** Perform some sanity checks on the integration parameters.
|
||||||
double t0, double[] y0,
|
* @param equations differential equations set
|
||||||
double t, double[] y)
|
* @param t0 start time
|
||||||
throws DerivativeException, IntegratorException {
|
* @param y0 state vector at t0
|
||||||
|
* @param t target time for the integration
|
||||||
// sanity check
|
* @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) {
|
if (equations.getDimension() != y0.length) {
|
||||||
throw new IntegratorException("dimensions mismatch: ODE problem has dimension {0},"
|
throw new IntegratorException("dimensions mismatch: ODE problem has dimension {0},"
|
||||||
+ " state vector has dimension {1}",
|
+ " initial state vector has dimension {1}",
|
||||||
new String[] {
|
new String[] {
|
||||||
Integer.toString(equations.getDimension()),
|
Integer.toString(equations.getDimension()),
|
||||||
Integer.toString(y0.length)
|
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))) {
|
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}",
|
throw new IntegratorException("too small integration interval: length = {0}",
|
||||||
new String[] {
|
new String[] {
|
||||||
Double.toString(Math.abs(t - t0))
|
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);
|
boolean forward = (t > t0);
|
||||||
|
|
||||||
// create some internal working arrays
|
// create some internal working arrays
|
||||||
|
|
Loading…
Reference in New Issue