Step interpolator only needs the mapper, not the full equations.

This commit is contained in:
Luc Maisonobe 2016-01-06 12:23:54 +01:00
parent 7644b5a2bd
commit 02641ff729
1 changed files with 17 additions and 17 deletions

View File

@ -19,7 +19,7 @@ package org.apache.commons.math4.ode.sampling;
import org.apache.commons.math4.RealFieldElement; import org.apache.commons.math4.RealFieldElement;
import org.apache.commons.math4.exception.MaxCountExceededException; import org.apache.commons.math4.exception.MaxCountExceededException;
import org.apache.commons.math4.ode.FieldExpandableODE; import org.apache.commons.math4.ode.FieldEquationsMapper;
import org.apache.commons.math4.ode.FieldODEStateAndDerivative; import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
/** This abstract class represents an interpolator over the last step /** This abstract class represents an interpolator over the last step
@ -64,8 +64,8 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
/** integration direction. */ /** integration direction. */
private boolean forward; private boolean forward;
/** ODE equations with primary and secondary components. */ /** Mapper for ODE equations primary and secondary components. */
private FieldExpandableODE<T> equations; private FieldEquationsMapper<T> mapper;
/** Simple constructor. /** Simple constructor.
* This constructor builds an instance that is not usable yet, the * This constructor builds an instance that is not usable yet, the
@ -87,17 +87,17 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
currentState = null; currentState = null;
finalized = false; finalized = false;
forward = true; forward = true;
equations = null; mapper = null;
} }
/** Simple constructor. /** Simple constructor.
* @param y reference to the integrator array holding the state at * @param y reference to the integrator array holding the state at
* the end of the step * the end of the step
* @param forward integration direction indicator * @param forward integration direction indicator
* @param equations primary and secondary equations set * @param mapper mapper for ODE equations primary and secondary components
*/ */
protected AbstractFieldStepInterpolator(final T[] y, final boolean forward, protected AbstractFieldStepInterpolator(final T[] y, final boolean forward,
final FieldExpandableODE<T> equations) { final FieldEquationsMapper<T> mapper) {
globalPreviousState = null; globalPreviousState = null;
globalCurrentState = null; globalCurrentState = null;
@ -107,7 +107,7 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
currentState = y; currentState = y;
finalized = false; finalized = false;
this.forward = forward; this.forward = forward;
this.equations = equations; this.mapper = mapper;
} }
@ -138,23 +138,23 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
if (interpolator.currentState == null) { if (interpolator.currentState == null) {
currentState = null; currentState = null;
equations = null; mapper = null;
} else { } else {
currentState = interpolator.currentState.clone(); currentState = interpolator.currentState.clone();
} }
finalized = interpolator.finalized; finalized = interpolator.finalized;
forward = interpolator.forward; forward = interpolator.forward;
equations = interpolator.equations; mapper = interpolator.mapper;
} }
/** Reinitialize the instance /** Reinitialize the instance
* @param y reference to the integrator array holding the state at the end of the step * @param y reference to the integrator array holding the state at the end of the step
* @param isForward integration direction indicator * @param isForward integration direction indicator
* @param eqn primary and secondary equations set * @param equationsMapper mapper for ODE equations primary and secondary components
*/ */
protected void reinitialize(final T[] y, final boolean isForward, final FieldExpandableODE<T> eqn) { protected void reinitialize(final T[] y, final boolean isForward, final FieldEquationsMapper<T> equationsMapper) {
globalPreviousState = null; globalPreviousState = null;
globalCurrentState = null; globalCurrentState = null;
@ -164,7 +164,7 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
currentState = y.clone(); currentState = y.clone();
finalized = false; finalized = false;
this.forward = isForward; this.forward = isForward;
this.equations = eqn; this.mapper = equationsMapper;
} }
@ -272,7 +272,7 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
public FieldODEStateAndDerivative<T> getInterpolatedState(final T time) { public FieldODEStateAndDerivative<T> getInterpolatedState(final T time) {
final T oneMinusThetaH = globalCurrentState.getTime().subtract(time); final T oneMinusThetaH = globalCurrentState.getTime().subtract(time);
final T theta = (h.getReal() == 0) ? h.getField().getZero() : h.subtract(oneMinusThetaH).divide(h); final T theta = (h.getReal() == 0) ? h.getField().getZero() : h.subtract(oneMinusThetaH).divide(h);
return computeInterpolatedStateAndDerivatives(equations, theta, oneMinusThetaH); return computeInterpolatedStateAndDerivatives(mapper, time, theta, oneMinusThetaH);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -283,7 +283,8 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
/** Compute the state and derivatives at the interpolated time. /** Compute the state and derivatives at the interpolated time.
* This is the main processing method that should be implemented by * This is the main processing method that should be implemented by
* the derived classes to perform the interpolation. * the derived classes to perform the interpolation.
* @param eqn ODE equations with primary and secondary components * @param equationsMapper mapper for ODE equations primary and secondary components
* @param time interpolation time
* @param theta normalized interpolation abscissa within the step * @param theta normalized interpolation abscissa within the step
* (theta is zero at the previous time step and one at the current time step) * (theta is zero at the previous time step and one at the current time step)
* @param oneMinusThetaH time gap between the interpolated time and * @param oneMinusThetaH time gap between the interpolated time and
@ -291,9 +292,8 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
* @return interpolated state and derivatives * @return interpolated state and derivatives
* @exception MaxCountExceededException if the number of functions evaluations is exceeded * @exception MaxCountExceededException if the number of functions evaluations is exceeded
*/ */
protected abstract FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(FieldExpandableODE<T> eqn, protected abstract FieldODEStateAndDerivative<T> computeInterpolatedStateAndDerivatives(FieldEquationsMapper<T> equationsMapper,
T theta, T time, T theta, T oneMinusThetaH)
T oneMinusThetaH)
throws MaxCountExceededException; throws MaxCountExceededException;
/** /**