Class AbstractStepInterpolator
- All Implemented Interfaces:
Externalizable,Serializable,StepInterpolator
- Direct Known Subclasses:
NordsieckStepInterpolator
The various ODE integrators provide objects extending this class to the step handlers. The handlers can use these objects to retrieve the state vector at intermediate times between the previous and the current grid points (dense output).
- Since:
- 1.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double[]current stateprotected doublecurrent time stepprotected double[]interpolated derivativesprotected double[]interpolated primary derivativesprotected double[]interpolated primary stateprotected double[][]interpolated secondary derivativesprotected double[][]interpolated secondary stateprotected double[]interpolated stateprotected doubleinterpolated time -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSimple constructor.protectedAbstractStepInterpolator(double[] y, boolean forward, EquationsMapper primaryMapper, EquationsMapper[] secondaryMappers) Simple constructor.protectedAbstractStepInterpolator(AbstractStepInterpolator interpolator) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidcomputeInterpolatedStateAndDerivatives(double theta, double oneMinusThetaH) Compute the state and derivatives at the interpolated time.copy()Copy the instance.protected abstract StepInterpolatordoCopy()Really copy the finalized instance.protected voidReally finalize the step.final voidFinalize the step.doubleGet the current soft grid point time.doubleGet the current global grid point time.doubleGet the previous global grid point time.double[]Get the derivatives of the state vector of the interpolated point.double[]getInterpolatedSecondaryDerivatives(int index) Get the interpolated secondary derivatives corresponding to the secondary equations.double[]getInterpolatedSecondaryState(int index) Get the interpolated secondary state corresponding to the secondary equations.double[]Get the state vector of the interpolated point.doubleGet the time of the interpolated point.doubleGet the previous soft grid point time.booleanCheck if the natural integration direction is forward.protected doubleRead the base state of the instance.abstract voidprotected voidreinitialize(double[] y, boolean isForward, EquationsMapper primary, EquationsMapper[] secondary) Reinitialize the instancevoidsetInterpolatedTime(double time) Set the time of the interpolated point.voidsetSoftCurrentTime(double softCurrentTime) Restrict step range to a limited part of the global step.voidsetSoftPreviousTime(double softPreviousTime) Restrict step range to a limited part of the global step.voidshift()Shift one step forward.voidstoreTime(double t) Store the current step time.protected voidSave the base state of the instance.abstract void
-
Field Details
-
h
protected double hcurrent time step -
currentState
protected double[] currentStatecurrent state -
interpolatedTime
protected double interpolatedTimeinterpolated time -
interpolatedState
protected double[] interpolatedStateinterpolated state -
interpolatedDerivatives
protected double[] interpolatedDerivativesinterpolated derivatives -
interpolatedPrimaryState
protected double[] interpolatedPrimaryStateinterpolated primary state -
interpolatedPrimaryDerivatives
protected double[] interpolatedPrimaryDerivativesinterpolated primary derivatives -
interpolatedSecondaryState
protected double[][] interpolatedSecondaryStateinterpolated secondary state -
interpolatedSecondaryDerivatives
protected double[][] interpolatedSecondaryDerivativesinterpolated secondary derivatives
-
-
Constructor Details
-
AbstractStepInterpolator
protected AbstractStepInterpolator()Simple constructor. This constructor builds an instance that is not usable yet, thereinitialize(double[], boolean, org.apache.commons.math3.ode.EquationsMapper, org.apache.commons.math3.ode.EquationsMapper[])method should be called before using the instance in order to initialize the internal arrays. This constructor is used only in order to delay the initialization in some cases. As an example, theEmbeddedRungeKuttaIntegratorclass uses the prototyping design pattern to create the step interpolators by cloning an uninitialized model and latter initializing the copy. -
AbstractStepInterpolator
protected AbstractStepInterpolator(double[] y, boolean forward, EquationsMapper primaryMapper, EquationsMapper[] secondaryMappers) Simple constructor.- Parameters:
y- reference to the integrator array holding the state at the end of the stepforward- integration direction indicatorprimaryMapper- equations mapper for the primary equations setsecondaryMappers- equations mappers for the secondary equations sets
-
AbstractStepInterpolator
Copy constructor.The copied interpolator should have been finalized before the copy, otherwise the copy will not be able to perform correctly any derivative computation and will throw a
NullPointerExceptionlater. Since we don't want this constructor to throw the exceptions finalization may involve and since we don't want this method to modify the state of the copied interpolator, finalization is not done automatically, it remains under user control.The copy is a deep copy: its arrays are separated from the original arrays of the instance.
- Parameters:
interpolator- interpolator to copy from.
-
-
Method Details
-
reinitialize
protected void reinitialize(double[] y, boolean isForward, EquationsMapper primary, EquationsMapper[] secondary) Reinitialize the instance- Parameters:
y- reference to the integrator array holding the state at the end of the stepisForward- integration direction indicatorprimary- equations mapper for the primary equations setsecondary- equations mappers for the secondary equations sets
-
copy
Copy the instance.The copied instance is guaranteed to be independent from the original one. Both can be used with different settings for interpolated time without any side effect.
- Specified by:
copyin interfaceStepInterpolator- Returns:
- a deep copy of the instance, which can be used independently.
- Throws:
MaxCountExceededException- if the number of functions evaluations is exceeded during step finalization- See Also:
-
doCopy
Really copy the finalized instance.This method is called by
copy()after the step has been finalized. It must perform a deep copy to have an new instance completely independent for the original instance.- Returns:
- a copy of the finalized instance
-
shift
public void shift()Shift one step forward. Copy the current time into the previous time, hence preparing the interpolator for future calls tostoreTime -
storeTime
public void storeTime(double t) Store the current step time.- Parameters:
t- current time
-
setSoftPreviousTime
public void setSoftPreviousTime(double softPreviousTime) Restrict step range to a limited part of the global step.This method can be used to restrict a step and make it appear as if the original step was smaller. Calling this method only changes the value returned by
getPreviousTime(), it does not change any other property- Parameters:
softPreviousTime- start of the restricted step- Since:
- 2.2
-
setSoftCurrentTime
public void setSoftCurrentTime(double softCurrentTime) Restrict step range to a limited part of the global step.This method can be used to restrict a step and make it appear as if the original step was smaller. Calling this method only changes the value returned by
getCurrentTime(), it does not change any other property- Parameters:
softCurrentTime- end of the restricted step- Since:
- 2.2
-
getGlobalPreviousTime
public double getGlobalPreviousTime()Get the previous global grid point time.- Returns:
- previous global grid point time
-
getGlobalCurrentTime
public double getGlobalCurrentTime()Get the current global grid point time.- Returns:
- current global grid point time
-
getPreviousTime
public double getPreviousTime()Get the previous soft grid point time.- Specified by:
getPreviousTimein interfaceStepInterpolator- Returns:
- previous soft grid point time
- See Also:
-
getCurrentTime
public double getCurrentTime()Get the current soft grid point time.- Specified by:
getCurrentTimein interfaceStepInterpolator- Returns:
- current soft grid point time
- See Also:
-
getInterpolatedTime
public double getInterpolatedTime()Get the time of the interpolated point. IfStepInterpolator.setInterpolatedTime(double)has not been called, it returns the current grid point time.- Specified by:
getInterpolatedTimein interfaceStepInterpolator- Returns:
- interpolation point time
-
setInterpolatedTime
public void setInterpolatedTime(double time) Set the time of the interpolated point.Setting the time outside of the current step is now allowed, but should be used with care since the accuracy of the interpolator will 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. This includes the internal arrays returned in
StepInterpolator.getInterpolatedState(),StepInterpolator.getInterpolatedDerivatives(),StepInterpolator.getInterpolatedSecondaryState(int)andStepInterpolator.getInterpolatedSecondaryDerivatives(int). So if their content must be preserved across several calls, user must copy them.- Specified by:
setInterpolatedTimein interfaceStepInterpolator- Parameters:
time- time of the interpolated point- See Also:
-
isForward
public boolean isForward()Check if the natural integration direction is forward.This method provides the integration direction as specified by the integrator itself, it avoid some nasty problems in degenerated cases like null steps due to cancellation at step initialization, step control or discrete events triggering.
- Specified by:
isForwardin interfaceStepInterpolator- Returns:
- true if the integration variable (time) increases during integration
-
computeInterpolatedStateAndDerivatives
protected abstract void computeInterpolatedStateAndDerivatives(double theta, double oneMinusThetaH) throws MaxCountExceededException Compute the state and derivatives at the interpolated time. This is the main processing method that should be implemented by the derived classes to perform the interpolation.- Parameters:
theta- normalized interpolation abscissa within the step (theta is zero at the previous time step and one at the current time step)oneMinusThetaH- time gap between the interpolated time and the current time- Throws:
MaxCountExceededException- if the number of functions evaluations is exceeded
-
getInterpolatedState
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
StepInterpolator.setInterpolatedTime(double)method.- Specified by:
getInterpolatedStatein interfaceStepInterpolator- Returns:
- state vector at time
StepInterpolator.getInterpolatedTime() - Throws:
MaxCountExceededException- if the number of functions evaluations is exceeded- See Also:
-
getInterpolatedDerivatives
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
StepInterpolator.setInterpolatedTime(double)method.- Specified by:
getInterpolatedDerivativesin interfaceStepInterpolator- Returns:
- derivatives of the state vector at time
StepInterpolator.getInterpolatedTime() - Throws:
MaxCountExceededException- if the number of functions evaluations is exceeded- See Also:
-
getInterpolatedSecondaryState
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
StepInterpolator.setInterpolatedTime(double)method.- Specified by:
getInterpolatedSecondaryStatein interfaceStepInterpolator- Parameters:
index- index of the secondary set, as returned byExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)- Returns:
- interpolated secondary state at the current interpolation date
- Throws:
MaxCountExceededException- if the number of functions evaluations is exceeded- See Also:
-
getInterpolatedSecondaryDerivatives
Get the interpolated secondary derivatives 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.
- Specified by:
getInterpolatedSecondaryDerivativesin interfaceStepInterpolator- Parameters:
index- index of the secondary set, as returned byExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)- Returns:
- interpolated secondary derivatives at the current interpolation date
- Throws:
MaxCountExceededException- if the number of functions evaluations is exceeded- See Also:
-
finalizeStep
Finalize the step.Some embedded Runge-Kutta integrators need fewer functions evaluations than their counterpart step interpolators. These interpolators should perform the last evaluations they need by themselves only if they need them. This method triggers these extra evaluations. It can be called directly by the user step handler and it is called automatically if
setInterpolatedTime(double)is called.Once this method has been called, no other evaluation will be performed on this step. If there is a need to have some side effects between the step handler and the differential equations (for example update some data in the equations once the step has been done), it is advised to call this method explicitly from the step handler before these side effects are set up. If the step handler induces no side effect, then this method can safely be ignored, it will be called transparently as needed.
Warning: since the step interpolator provided to the step handler as a parameter of the
handleStepis valid only for the duration of thehandleStepcall, one cannot simply store a reference and reuse it later. One should first finalize the instance, then copy this finalized instance into a new object that can be kept.This method calls the protected
doFinalizemethod if it has never been called during this step and set a flag indicating that it has been called once. It is thedoFinalizemethod which should perform the evaluations. This wrapping prevents from callingdoFinalizeseveral times and hence evaluating the differential equations too often. Therefore, subclasses are not allowed not reimplement it, they should rather reimplementdoFinalize.- Throws:
MaxCountExceededException- if the number of functions evaluations is exceeded
-
doFinalize
Really finalize the step. The default implementation of this method does nothing.- Throws:
MaxCountExceededException- if the number of functions evaluations is exceeded
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeBaseExternal
Save the base state of the instance. This method performs step finalization if it has not been done before.- Parameters:
out- stream where to save the state- Throws:
IOException- in case of write error
-
readBaseExternal
Read the base state of the instance. This method does neither set the interpolated time nor state. It is up to the derived class to reset it properly calling thesetInterpolatedTime(double)method later, once all rest of the object state has been set up properly.- Parameters:
in- stream where to read the state from- Returns:
- interpolated time to be set later by the caller
- Throws:
IOException- in case of read errorClassNotFoundException- if an equation mapper class cannot be found
-