Top Description Fields Constructors Methods
org.apache.commons.math3.ode.sampling

public abstract Class AbstractStepInterpolator

extends Object
implements StepInterpolator
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.ode.sampling.StepInterpolator, java.io.Externalizable, java.io.Serializable
Known Direct Subclasses
org.apache.commons.math3.ode.sampling.NordsieckStepInterpolator, org.apache.commons.math3.ode.nonstiff.GraggBulirschStoerStepInterpolator, org.apache.commons.math3.ode.nonstiff.RungeKuttaStepInterpolator
Imports
java.io.IOException, .ObjectInput, .ObjectOutput, org.apache.commons.math3.exception.MaxCountExceededException, org.apache.commons.math3.ode.EquationsMapper

This abstract class represents an interpolator over the last step during an ODE integration.

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
org.apache.commons.math3.ode.FirstOrderIntegrator, org.apache.commons.math3.ode.SecondOrderIntegrator, StepHandler

Field Summary

Modifier and TypeField and Description
protected double[]
currentState

current state

private boolean
dirtyState

indicator for dirty state.

private boolean
finalized

indicate if the step has been finalized or not.

private boolean
forward

integration direction.

private double
globalCurrentTime

global current time

private double
globalPreviousTime

global previous time

protected double
h

current time step

protected double[]
interpolatedDerivatives

interpolated derivatives

protected double[]
interpolatedPrimaryDerivatives

interpolated primary derivatives

protected double[]
interpolatedPrimaryState

interpolated primary state

protected double[][]
interpolatedSecondaryDerivatives

interpolated secondary derivatives

protected double[][]
interpolatedSecondaryState

interpolated secondary state

protected double[]
interpolatedState

interpolated state

protected double
interpolatedTime

interpolated time

private EquationsMapper
primaryMapper

Equations mapper for the primary equations set.

private EquationsMapper[]
secondaryMappers

Equations mappers for the secondary equations sets.

private double
softCurrentTime

soft current time

private double
softPreviousTime

soft previous time

Constructor Summary

AccessConstructor and Description
protected
AbstractStepInterpolator()

Simple constructor.

protected
AbstractStepInterpolator(final double[]
reference to the integrator array holding the state at the end of the step
y
,
final boolean
integration direction indicator
forward
,
final EquationsMapper
equations mapper for the primary equations set
primaryMapper
,
final EquationsMapper[]
equations mappers for the secondary equations sets
secondaryMappers
)

Simple constructor.

protected
AbstractStepInterpolator(final AbstractStepInterpolator
interpolator to copy from.
interpolator
)

Copy constructor.

Method Summary

Modifier and TypeMethod and Description
private void
allocateInterpolatedArrays(final int
total dimension (negative if arrays should be set to null)
dimension
)

Allocate the various interpolated states arrays.

protected abstract void
computeInterpolatedStateAndDerivatives(double
normalized interpolation abscissa within the step (theta is zero at the previous time step and one at the current time step)
theta
,
double
time gap between the interpolated time and the current time
oneMinusThetaH
)

Compute the state and derivatives at the interpolated time.

public StepInterpolator
protected abstract StepInterpolator

Returns:

a copy of the finalized instance
doCopy
()

Really copy the finalized instance.

protected void
doFinalize()

Really finalize the step.

private void
evaluateCompleteInterpolatedState()

Lazy evaluation of complete interpolated state.

public final void
finalizeStep()

Finalize the step.

public double

Returns:

current soft grid point time
getCurrentTime
()

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getCurrentTime.

Get the current soft grid point time.

public double

Returns:

current global grid point time
getGlobalCurrentTime
()

Get the current global grid point time.

public double

Returns:

previous global grid point time
getGlobalPreviousTime
()

Get the previous global grid point time.

public double[]
getInterpolatedDerivatives()

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedDerivatives.

Get the derivatives of the state vector of the interpolated point.

public double[]
getInterpolatedSecondaryDerivatives(final int
index of the secondary set, as returned by ExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)
index
)

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedSecondaryDerivatives.

Get the interpolated secondary derivatives corresponding to the secondary equations.

public double[]
getInterpolatedSecondaryState(final int
index of the secondary set, as returned by ExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)
index
)

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedSecondaryState.

Get the interpolated secondary state corresponding to the secondary equations.

public double[]
public double
public double

Returns:

previous soft grid point time
getPreviousTime
()

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getPreviousTime.

Get the previous soft grid point time.

public boolean
isForward()

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.isForward.

Check if the natural integration direction is forward.

protected double

Returns:

interpolated time to be set later by the caller
readBaseExternal
(final ObjectInput
stream where to read the state from
in
)

Read the base state of the instance.

public abstract void
readExternal(ObjectInput
the stream to read data from in order to restore the object
in
)

Redeclares java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

protected void
reinitialize(final double[]
reference to the integrator array holding the state at the end of the step
y
,
final boolean
integration direction indicator
isForward
,
final EquationsMapper
equations mapper for the primary equations set
primary
,
final EquationsMapper[]
equations mappers for the secondary equations sets
secondary
)

Reinitialize the instance

public void
setInterpolatedTime(final double
time of the interpolated point
time
)

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.setInterpolatedTime.

Set the time of the interpolated point.

public void
setSoftCurrentTime(final double
end of the restricted step
softCurrentTime
)

Restrict step range to a limited part of the global step.

public void
setSoftPreviousTime(final double
start of the restricted step
softPreviousTime
)

Restrict step range to a limited part of the global step.

public void
shift()

Shift one step forward.

public void
storeTime(final double
current time
t
)

Store the current step time.

protected void
writeBaseExternal(final ObjectOutput
stream where to save the state
out
)

Save the base state of the instance.

public abstract void
writeExternal(ObjectOutput
the stream to write the object to
out
)

Redeclares java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentStateback to summary
protected double[] currentState

current state

dirtyStateback to summary
private boolean dirtyState

indicator for dirty state.

finalizedback to summary
private boolean finalized

indicate if the step has been finalized or not.

forwardback to summary
private boolean forward

integration direction.

globalCurrentTimeback to summary
private double globalCurrentTime

global current time

globalPreviousTimeback to summary
private double globalPreviousTime

global previous time

hback to summary
protected double h

current time step

interpolatedDerivativesback to summary
protected double[] interpolatedDerivatives

interpolated derivatives

interpolatedPrimaryDerivativesback to summary
protected double[] interpolatedPrimaryDerivatives

interpolated primary derivatives

interpolatedPrimaryStateback to summary
protected double[] interpolatedPrimaryState

interpolated primary state

interpolatedSecondaryDerivativesback to summary
protected double[][] interpolatedSecondaryDerivatives

interpolated secondary derivatives

interpolatedSecondaryStateback to summary
protected double[][] interpolatedSecondaryState

interpolated secondary state

interpolatedStateback to summary
protected double[] interpolatedState

interpolated state

interpolatedTimeback to summary
protected double interpolatedTime

interpolated time

primaryMapperback to summary
private EquationsMapper primaryMapper

Equations mapper for the primary equations set.

secondaryMappersback to summary
private EquationsMapper[] secondaryMappers

Equations mappers for the secondary equations sets.

softCurrentTimeback to summary
private double softCurrentTime

soft current time

softPreviousTimeback to summary
private double softPreviousTime

soft previous time

Constructor Detail

AbstractStepInterpolatorback to summary
protected AbstractStepInterpolator()

Simple constructor. This constructor builds an instance that is not usable yet, the reinitialize 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, the org.apache.commons.math3.ode.nonstiff.EmbeddedRungeKuttaIntegrator class uses the prototyping design pattern to create the step interpolators by cloning an uninitialized model and latter initializing the copy.

AbstractStepInterpolatorback to summary
protected AbstractStepInterpolator(final double[] y, final boolean forward, final EquationsMapper primaryMapper, final EquationsMapper[] secondaryMappers)

Simple constructor.

Parameters
y:double[]

reference to the integrator array holding the state at the end of the step

forward:boolean

integration direction indicator

primaryMapper:EquationsMapper

equations mapper for the primary equations set

secondaryMappers:EquationsMapper[]

equations mappers for the secondary equations sets

AbstractStepInterpolatorback to summary
protected AbstractStepInterpolator(final AbstractStepInterpolator interpolator)

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 NullPointerException later. 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:AbstractStepInterpolator

interpolator to copy from.

Method Detail

allocateInterpolatedArraysback to summary
private void allocateInterpolatedArrays(final int dimension)

Allocate the various interpolated states arrays.

Parameters
dimension:int

total dimension (negative if arrays should be set to null)

computeInterpolatedStateAndDerivativesback to summary
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:double

normalized interpolation abscissa within the step (theta is zero at the previous time step and one at the current time step)

oneMinusThetaH:double

time gap between the interpolated time and the current time

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
copyback to summary
public StepInterpolator copy() throws MaxCountExceededException

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.copy.

Doc from org.apache.commons.math3.ode.sampling.StepInterpolator.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.

Returns:StepInterpolator

a deep copy of the instance, which can be used independently.

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded during step finalization
doCopyback to summary
protected abstract StepInterpolator 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:StepInterpolator

a copy of the finalized instance

doFinalizeback to summary
protected void doFinalize() throws MaxCountExceededException

Really finalize the step. The default implementation of this method does nothing.

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
evaluateCompleteInterpolatedStateback to summary
private void evaluateCompleteInterpolatedState() throws MaxCountExceededException

Lazy evaluation of complete interpolated state.

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
finalizeStepback to summary
public final void finalizeStep() throws MaxCountExceededException

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 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 handleStep is valid only for the duration of the handleStep call, 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 doFinalize method if it has never been called during this step and set a flag indicating that it has been called once. It is the doFinalize method which should perform the evaluations. This wrapping prevents from calling doFinalize several times and hence evaluating the differential equations too often. Therefore, subclasses are not allowed not reimplement it, they should rather reimplement doFinalize.

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
getCurrentTimeback to summary
public double getCurrentTime()

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getCurrentTime.

Get the current soft grid point time.

Returns:double

current soft grid point time

See Also
setSoftCurrentTime(double)
getGlobalCurrentTimeback to summary
public double getGlobalCurrentTime()

Get the current global grid point time.

Returns:double

current global grid point time

getGlobalPreviousTimeback to summary
public double getGlobalPreviousTime()

Get the previous global grid point time.

Returns:double

previous global grid point time

getInterpolatedDerivativesback to summary
public double[] getInterpolatedDerivatives() throws MaxCountExceededException

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedDerivatives.

Doc from org.apache.commons.math3.ode.sampling.StepInterpolator.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 setInterpolatedTime(double) method.

Returns:double[]

derivatives of the state vector at time getInterpolatedTime

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
getInterpolatedSecondaryDerivativesback to summary
public double[] getInterpolatedSecondaryDerivatives(final int index) throws MaxCountExceededException

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedSecondaryDerivatives.

Doc from org.apache.commons.math3.ode.sampling.StepInterpolator.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.

Parameters
index:int

index of the secondary set, as returned by ExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)

Returns:double[]

interpolated secondary derivatives at the current interpolation date

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
getInterpolatedSecondaryStateback to summary
public double[] getInterpolatedSecondaryState(final int index) throws MaxCountExceededException

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedSecondaryState.

Doc from org.apache.commons.math3.ode.sampling.StepInterpolator.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 setInterpolatedTime(double) method.

Parameters
index:int

index of the secondary set, as returned by ExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)

Returns:double[]

interpolated secondary state at the current interpolation date

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
getInterpolatedStateback to summary
public double[] getInterpolatedState() throws MaxCountExceededException

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedState.

Doc from org.apache.commons.math3.ode.sampling.StepInterpolator.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 setInterpolatedTime(double) method.

Returns:double[]

state vector at time getInterpolatedTime

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
getInterpolatedTimeback to summary
public double getInterpolatedTime()

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedTime.

Doc from org.apache.commons.math3.ode.sampling.StepInterpolator.getInterpolatedTime.

Get the time of the interpolated point. If setInterpolatedTime has not been called, it returns the current grid point time.

Returns:double

interpolation point time

getPreviousTimeback to summary
public double getPreviousTime()

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.getPreviousTime.

Get the previous soft grid point time.

Returns:double

previous soft grid point time

See Also
setSoftPreviousTime(double)
isForwardback to summary
public boolean isForward()

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.isForward.

Doc from org.apache.commons.math3.ode.sampling.StepInterpolator.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.

Returns:boolean

true if the integration variable (time) increases during integration

readBaseExternalback to summary
protected double readBaseExternal(final ObjectInput in) throws IOException, ClassNotFoundException

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 the setInterpolatedTime method later, once all rest of the object state has been set up properly.

Parameters
in:ObjectInput

stream where to read the state from

Returns:double

interpolated time to be set later by the caller

Exceptions
IOException:
in case of read error
ClassNotFoundException:
if an equation mapper class cannot be found
readExternalback to summary
public abstract void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

Redeclares java.io.Externalizable.readExternal.

Doc from java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Parameters
in:ObjectInput

the stream to read data from in order to restore the object

Exceptions
IOException:
if I/O errors occur
ClassNotFoundException:
If the class for an object being restored cannot be found.
reinitializeback to summary
protected void reinitialize(final double[] y, final boolean isForward, final EquationsMapper primary, final EquationsMapper[] secondary)

Reinitialize the instance

Parameters
y:double[]

reference to the integrator array holding the state at the end of the step

isForward:boolean

integration direction indicator

primary:EquationsMapper

equations mapper for the primary equations set

secondary:EquationsMapper[]

equations mappers for the secondary equations sets

setInterpolatedTimeback to summary
public void setInterpolatedTime(final double time)

Implements org.apache.commons.math3.ode.sampling.StepInterpolator.setInterpolatedTime.

Doc from org.apache.commons.math3.ode.sampling.StepInterpolator.setInterpolatedTime.

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 getInterpolatedState(), getInterpolatedDerivatives(), getInterpolatedSecondaryState(int) and getInterpolatedSecondaryDerivatives(int). So if their content must be preserved across several calls, user must copy them.

Parameters
time:double

time of the interpolated point

setSoftCurrentTimeback to summary
public void setSoftCurrentTime(final 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:double

end of the restricted step

Since
2.2
setSoftPreviousTimeback to summary
public void setSoftPreviousTime(final 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:double

start of the restricted step

Since
2.2
shiftback to summary
public void shift()

Shift one step forward. Copy the current time into the previous time, hence preparing the interpolator for future calls to storeTime

storeTimeback to summary
public void storeTime(final double t)

Store the current step time.

Parameters
t:double

current time

writeBaseExternalback to summary
protected void writeBaseExternal(final ObjectOutput out) throws IOException

Save the base state of the instance. This method performs step finalization if it has not been done before.

Parameters
out:ObjectOutput

stream where to save the state

Exceptions
IOException:
in case of write error
writeExternalback to summary
public abstract void writeExternal(ObjectOutput out) throws IOException

Redeclares java.io.Externalizable.writeExternal.

Doc from java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Parameters
out:ObjectOutput

the stream to write the object to

Exceptions
IOException:
Includes any I/O exceptions that may occur