From 0c125f71ed4126f4bd9095598ca00adf53932116 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Mon, 14 Jul 2008 15:12:36 +0000 Subject: [PATCH] fixed a problem preventing integration stop when end time was exactly 0 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@676618 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/math/ode/AbstractIntegrator.java | 8 ++++++-- .../math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java | 2 +- .../commons/math/ode/nonstiff/RungeKuttaIntegrator.java | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/commons/math/ode/AbstractIntegrator.java b/src/java/org/apache/commons/math/ode/AbstractIntegrator.java index dad909f25..24d7c4f84 100644 --- a/src/java/org/apache/commons/math/ode/AbstractIntegrator.java +++ b/src/java/org/apache/commons/math/ode/AbstractIntegrator.java @@ -164,12 +164,14 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { *

This method can be used to simplify handling of integration end time. * It leverages the nominal stop condition with the exceptional stop * conditions.

+ * @param startTime integration start time * @param endTime desired end time * @param manager manager containing the user-defined handlers * @return a new manager containing all the user-defined handlers plus a * dedicated manager triggering a stop event at entTime */ - protected CombinedEventsManager addEndTimeChecker(final double endTime, + protected CombinedEventsManager addEndTimeChecker(final double startTime, + final double endTime, final CombinedEventsManager manager) { CombinedEventsManager newManager = new CombinedEventsManager(); for (final EventState state : manager.getEventsStates()) { @@ -179,7 +181,9 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { state.getMaxIterationCount()); } newManager.addEventHandler(new EndTimeChecker(endTime), - Double.POSITIVE_INFINITY, Math.ulp(endTime), 10); + Double.POSITIVE_INFINITY, + Math.ulp(Math.max(Math.abs(startTime), Math.abs(endTime))), + 100); return newManager; } diff --git a/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java b/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java index 8e9686edc..77bdc7b25 100644 --- a/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java +++ b/src/java/org/apache/commons/math/ode/nonstiff/EmbeddedRungeKuttaIntegrator.java @@ -198,7 +198,7 @@ public abstract class EmbeddedRungeKuttaIntegrator for (StepHandler handler : stepHandlers) { handler.reset(); } - CombinedEventsManager manager = addEndTimeChecker(t, eventsHandlersManager); + CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop diff --git a/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java b/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java index 96893e06a..3460147f2 100644 --- a/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java +++ b/src/java/org/apache/commons/math/ode/nonstiff/RungeKuttaIntegrator.java @@ -113,7 +113,7 @@ public abstract class RungeKuttaIntegrator extends AbstractIntegrator { for (StepHandler handler : stepHandlers) { handler.reset(); } - CombinedEventsManager manager = addEndTimeChecker(t, eventsHandlersManager); + CombinedEventsManager manager = addEndTimeChecker(t0, t, eventsHandlersManager); boolean lastStep = false; // main integration loop