fixed too long first step in fixed Runge-Kutta integrators.
This change is similar to the one done two years ago for adaptive step sizes integrator. JIRA: MATH-727
This commit is contained in:
parent
86b92b4e56
commit
69273dca61
|
@ -119,7 +119,19 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator {
|
|||
|
||||
// set up integration control objects
|
||||
stepStart = equations.getTime();
|
||||
stepSize = forward ? step : -step;
|
||||
if (forward) {
|
||||
if (stepStart + step >= t) {
|
||||
stepSize = t - stepStart;
|
||||
} else {
|
||||
stepSize = step;
|
||||
}
|
||||
} else {
|
||||
if (stepStart - step <= t) {
|
||||
stepSize = t - stepStart;
|
||||
} else {
|
||||
stepSize = -step;
|
||||
}
|
||||
}
|
||||
initIntegration(equations.getTime(), y0, t);
|
||||
|
||||
// main integration loop
|
||||
|
|
|
@ -310,4 +310,28 @@ public class ClassicalRungeKuttaIntegratorTest {
|
|||
}, 0.0, new double[] { 0.0 }, 5.0, new double[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTooLargeFirstStep() {
|
||||
|
||||
RungeKuttaIntegrator integ = new ClassicalRungeKuttaIntegrator(0.5);
|
||||
final double start = 0.0;
|
||||
final double end = 0.001;
|
||||
FirstOrderDifferentialEquations equations = new FirstOrderDifferentialEquations() {
|
||||
|
||||
public int getDimension() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void computeDerivatives(double t, double[] y, double[] yDot) {
|
||||
Assert.assertTrue(t >= FastMath.nextAfter(start, Double.NEGATIVE_INFINITY));
|
||||
Assert.assertTrue(t <= FastMath.nextAfter(end, Double.POSITIVE_INFINITY));
|
||||
yDot[0] = -100.0 * y[0];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
integ.integrate(equations, start, new double[] { 1.0 }, end, new double[1]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue