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 2015/12/09 17:16:49 UTC
[09/50] [abbrv] [math] Fixed wrong state reset in field ode.
Fixed wrong state reset in field ode.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/8180c9e5
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/8180c9e5
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/8180c9e5
Branch: refs/heads/MATH_3_X
Commit: 8180c9e5e444c661ec99a41444590f95bafcb6b9
Parents: a40d822
Author: Luc Maisonobe <lu...@apache.org>
Authored: Tue Dec 1 12:19:24 2015 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Tue Dec 1 12:19:24 2015 +0100
----------------------------------------------------------------------
.../math3/ode/AbstractFieldIntegrator.java | 20 ++++++++++----------
.../math3/ode/events/FieldEventState.java | 18 ++++++++++++------
2 files changed, 22 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/8180c9e5/src/main/java/org/apache/commons/math3/ode/AbstractFieldIntegrator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/ode/AbstractFieldIntegrator.java b/src/main/java/org/apache/commons/math3/ode/AbstractFieldIntegrator.java
index c15b827..b39ed3b 100644
--- a/src/main/java/org/apache/commons/math3/ode/AbstractFieldIntegrator.java
+++ b/src/main/java/org/apache/commons/math3/ode/AbstractFieldIntegrator.java
@@ -340,17 +340,17 @@ public abstract class AbstractFieldIntegrator<T extends RealFieldElement<T>> imp
return eventState;
}
- boolean needReset = false;
+ FieldODEState<T> newState = null;
for (final FieldEventState<T> state : eventsStates) {
- needReset = needReset || state.reset(eventState);
- }
- if (needReset) {
- // some event handler has triggered changes that
- // invalidate the derivatives, we need to recompute them
- final T[] y = equations.getMapper().mapState(eventState);
- final T[] yDot = computeDerivatives(eventState.getTime(), y);
- resetOccurred = true;
- return equations.getMapper().mapStateAndDerivative(eventState.getTime(), y, yDot);
+ newState = state.reset(eventState);
+ if (newState != null) {
+ // some event handler has triggered changes that
+ // invalidate the derivatives, we need to recompute them
+ final T[] y = equations.getMapper().mapState(newState);
+ final T[] yDot = computeDerivatives(newState.getTime(), y);
+ resetOccurred = true;
+ return equations.getMapper().mapStateAndDerivative(newState.getTime(), y, yDot);
+ }
}
// prepare handling of the remaining part of the step
http://git-wip-us.apache.org/repos/asf/commons-math/blob/8180c9e5/src/main/java/org/apache/commons/math3/ode/events/FieldEventState.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/ode/events/FieldEventState.java b/src/main/java/org/apache/commons/math3/ode/events/FieldEventState.java
index 2210b4c..044b889 100644
--- a/src/main/java/org/apache/commons/math3/ode/events/FieldEventState.java
+++ b/src/main/java/org/apache/commons/math3/ode/events/FieldEventState.java
@@ -23,6 +23,7 @@ import org.apache.commons.math3.analysis.solvers.AllowedSolution;
import org.apache.commons.math3.analysis.solvers.BracketedRealFieldUnivariateSolver;
import org.apache.commons.math3.exception.MaxCountExceededException;
import org.apache.commons.math3.exception.NoBracketingException;
+import org.apache.commons.math3.ode.FieldODEState;
import org.apache.commons.math3.ode.FieldODEStateAndDerivative;
import org.apache.commons.math3.ode.sampling.FieldStepInterpolator;
import org.apache.commons.math3.util.FastMath;
@@ -325,22 +326,27 @@ public class FieldEventState<T extends RealFieldElement<T>> {
/** Let the event handler reset the state if it wants.
* @param state state at the beginning of the next step
- * @return true if the integrator should reset the derivatives too
+ * @return reset state (may by the same as initial state if only
+ * derivatives should be reset), or null if nothing is reset
*/
- public boolean reset(final FieldODEStateAndDerivative<T> state) {
+ public FieldODEState<T> reset(final FieldODEStateAndDerivative<T> state) {
if (!(pendingEvent && pendingEventTime.subtract(state.getTime()).abs().subtract(convergence).getReal() <= 0)) {
- return false;
+ return null;
}
+ final FieldODEState<T> newState;
if (nextAction == Action.RESET_STATE) {
- handler.resetState(state);
+ newState = handler.resetState(state);
+ } else if (nextAction == Action.RESET_DERIVATIVES) {
+ newState = state;
+ } else {
+ newState = null;
}
pendingEvent = false;
pendingEventTime = null;
- return (nextAction == Action.RESET_STATE) ||
- (nextAction == Action.RESET_DERIVATIVES);
+ return newState;
}