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 2008/07/10 14:42:31 UTC
svn commit: r675552 -
/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AbstractIntegrator.java
Author: luc
Date: Thu Jul 10 05:42:30 2008
New Revision: 675552
URL: http://svn.apache.org/viewvc?rev=675552&view=rev
Log:
Replaced size adjustment of all steps of fixed steps Runge-Kutta integrators by a truncation of the last step only.
JIRA: MATH-214
Modified:
commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AbstractIntegrator.java
Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AbstractIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AbstractIntegrator.java?rev=675552&r1=675551&r2=675552&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AbstractIntegrator.java (original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/ode/AbstractIntegrator.java Thu Jul 10 05:42:30 2008
@@ -23,6 +23,7 @@
import org.apache.commons.math.ode.events.CombinedEventsManager;
import org.apache.commons.math.ode.events.EventHandler;
+import org.apache.commons.math.ode.events.EventState;
import org.apache.commons.math.ode.sampling.StepHandler;
/**
@@ -159,4 +160,59 @@
}
+ /** Add an event handler for end time checking.
+ * <p>This method can be used to simplify handling of integration end time.
+ * It leverages the nominal stop condition with the exceptional stop
+ * conditions.</p>
+ * @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,
+ final CombinedEventsManager manager) {
+ CombinedEventsManager newManager = new CombinedEventsManager();
+ for (final EventState state : manager.getEventsStates()) {
+ newManager.addEventHandler(state.getEventHandler(),
+ state.getMaxCheckInterval(),
+ state.getConvergence(),
+ state.getMaxIterationCount());
+ }
+ newManager.addEventHandler(new EndTimeChecker(endTime),
+ Double.POSITIVE_INFINITY, Math.ulp(endTime), 10);
+ return newManager;
+ }
+
+ /** Specialized event handler to stop integration. */
+ private static class EndTimeChecker implements EventHandler {
+
+ /** Serializable version identifier. */
+ private static final long serialVersionUID = -5211782540446301964L;
+
+ /** DEsiredt end time. */
+ private final double endTime;
+
+ /** Build an instance.
+ * @param endTime desired time
+ */
+ public EndTimeChecker(final double endTime) {
+ this.endTime = endTime;
+ }
+
+ /** {@inheritDoc} */
+ public int eventOccurred(double t, double[] y) {
+ return STOP;
+ }
+
+ /** {@inheritDoc} */
+ public double g(double t, double[] y) {
+ return t - endTime;
+ }
+
+ /** {@inheritDoc} */
+ public void resetState(double t, double[] y) {
+ }
+
+ }
+
}
\ No newline at end of file