From 25aa4bd3665d8b265f03fa2b3e7ab6ee68256367 Mon Sep 17 00:00:00 2001
From: Luc Maisonobe
Setting the time outside of the integration interval is now - * allowed (it was not allowed up to version 5.9 of Mantissa), but - * should be used with care since the accuracy of the interpolator - * will probably be very poor far from this interval. This allowance - * has been added to simplify implementation of search algorithms - * near the interval endpoints.
+ * allowed, but should be used with care since the accuracy of the + * interpolator will probably be very poor far from this interval. + * This allowance has been added to simplify implementation of search + * algorithms near the interval endpoints. + *Note that each time this method is called, the internal arrays + * returned in {@link #getInterpolatedState()}, {@link + * #getInterpolatedDerivatives()} and {@link #getInterpolatedSecondaryState(int)} + * will be overwritten. So if their content must be preserved + * across several calls, user must copy them.
* @param time time of the interpolated point + * @see #getInterpolatedState() + * @see #getInterpolatedDerivatives() + * @see #getInterpolatedSecondaryState(int) */ public void setInterpolatedTime(final double time) { @@ -330,8 +337,13 @@ public class ContinuousOutputModel /** * Get the state vector of the interpolated point. + *The returned vector is a reference to a reused array, so + * it should not be modified and it should be copied if it needs + * to be preserved across several calls to the associated + * {@link #setInterpolatedTime(double)} method.
* @return state vector at time {@link #getInterpolatedTime} * @exception MaxCountExceededException if the number of functions evaluations is exceeded + * @see #setInterpolatedTime(double) * @see #getInterpolatedDerivatives() * @see #getInterpolatedSecondaryState(int) */ @@ -341,8 +353,13 @@ public class ContinuousOutputModel /** * Get the derivatives of the state vector of the interpolated point. + *The returned vector is a reference to a reused array, so + * it should not be modified and it should be copied if it needs + * to be preserved across several calls to the associated + * {@link #setInterpolatedTime(double)} method.
* @return derivatives of the state vector at time {@link #getInterpolatedTime} * @exception MaxCountExceededException if the number of functions evaluations is exceeded + * @see #setInterpolatedTime(double) * @see #getInterpolatedState() * @see #getInterpolatedSecondaryState(int) * @since 3.4 @@ -352,11 +369,16 @@ public class ContinuousOutputModel } /** Get the interpolated secondary state corresponding to the secondary equations. + *The returned vector is a reference to a reused array, so + * it should not be modified and it should be copied if it needs + * to be preserved across several calls to the associated + * {@link #setInterpolatedTime(double)} method.
* @param secondaryStateIndex index of the secondary set, as returned by {@link * org.apache.commons.math3.ode.ExpandableStatefulODE#addSecondaryEquations( * org.apache.commons.math3.ode.SecondaryEquations) * ExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)} * @return interpolated secondary state at the current interpolation date + * @see #setInterpolatedTime(double) * @see #getInterpolatedState() * @see #getInterpolatedDerivatives() * @since 3.2 diff --git a/src/main/java/org/apache/commons/math3/ode/sampling/StepInterpolator.java b/src/main/java/org/apache/commons/math3/ode/sampling/StepInterpolator.java index 44e77ebeb..5d27bf2c3 100644 --- a/src/main/java/org/apache/commons/math3/ode/sampling/StepInterpolator.java +++ b/src/main/java/org/apache/commons/math3/ode/sampling/StepInterpolator.java @@ -74,10 +74,17 @@ public interface StepInterpolator extends Externalizable { * probably be very poor far from this step. This allowance has been * added to simplify implementation of search algorithms near the * step endpoints. - *Setting the time changes the instance internal state. If a - * specific state must be preserved, a copy of the instance must be - * created using {@link #copy()}.
+ *Setting the time changes the instance internal state. This includes + * the internal arrays returned in {@link #getInterpolatedState()}, + * {@link #getInterpolatedDerivatives()}, {@link + * #getInterpolatedSecondaryState(int)} and {@link + * #getInterpolatedSecondaryDerivatives(int)}. So if their content must be preserved + * across several calls, user must copy them.
* @param time time of the interpolated point + * @see #getInterpolatedState() + * @see #getInterpolatedDerivatives() + * @see #getInterpolatedSecondaryState(int) + * @see #getInterpolatedSecondaryDerivatives(int) */ void setInterpolatedTime(double time); @@ -85,9 +92,13 @@ public interface StepInterpolator extends Externalizable { * Get the state vector of the interpolated point. *The returned vector is a reference to a reused array, so * it should not be modified and it should be copied if it needs - * to be preserved across several calls.
+ * to be preserved across several calls to the associated + * {@link #setInterpolatedTime(double)} method. * @return state vector at time {@link #getInterpolatedTime} * @see #getInterpolatedDerivatives() + * @see #getInterpolatedSecondaryState(int) + * @see #getInterpolatedSecondaryDerivatives(int) + * @see #setInterpolatedTime(double) * @exception MaxCountExceededException if the number of functions evaluations is exceeded */ double[] getInterpolatedState() throws MaxCountExceededException; @@ -96,9 +107,13 @@ public interface StepInterpolator extends Externalizable { * Get the derivatives of the state vector of the interpolated point. *The returned vector is a reference to a reused array, so * it should not be modified and it should be copied if it needs - * to be preserved across several calls.
+ * to be preserved across several calls to the associated + * {@link #setInterpolatedTime(double)} method. * @return derivatives of the state vector at time {@link #getInterpolatedTime} * @see #getInterpolatedState() + * @see #getInterpolatedSecondaryState(int) + * @see #getInterpolatedSecondaryDerivatives(int) + * @see #setInterpolatedTime(double) * @since 2.0 * @exception MaxCountExceededException if the number of functions evaluations is exceeded */ @@ -107,7 +122,8 @@ public interface StepInterpolator extends Externalizable { /** Get the interpolated secondary state corresponding to the secondary equations. *The returned vector is a reference to a reused array, so * it should not be modified and it should be copied if it needs - * to be preserved across several calls.
+ * to be preserved across several calls to the associated + * {@link #setInterpolatedTime(double)} method. * @param index index of the secondary set, as returned by {@link * org.apache.commons.math3.ode.ExpandableStatefulODE#addSecondaryEquations( * org.apache.commons.math3.ode.SecondaryEquations) From 45ae5c7e42b07ff24e2385de57f70e9484a46ae3 Mon Sep 17 00:00:00 2001 From: Luc MaisonobeThe returned vector is a reference to a reused array, so + * it should not be modified and it should be copied if it needs + * to be preserved across several calls to the associated + * {@link #setInterpolatedTime(double)} method.
+ * @param secondaryStateIndex index of the secondary set, as returned by {@link + * org.apache.commons.math3.ode.ExpandableStatefulODE#addSecondaryEquations( + * org.apache.commons.math3.ode.SecondaryEquations) + * ExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)} + * @return interpolated secondary derivatives at the current interpolation date + * @see #setInterpolatedTime(double) + * @see #getInterpolatedState() + * @see #getInterpolatedDerivatives() + * @see #getInterpolatedSecondaryState(int) + * @since 3.4 + * @exception MaxCountExceededException if the number of functions evaluations is exceeded + */ + public double[] getInterpolatedSecondaryDerivatives(final int secondaryStateIndex) + throws MaxCountExceededException { + return steps.get(index).getInterpolatedSecondaryDerivatives(secondaryStateIndex); + } + /** Compare a step interval and a double. * @param time point to locate * @param interval step interval