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

public abstract Class MultistepIntegrator

extends AdaptiveStepsizeIntegrator
Class Inheritance
Known Direct Subclasses
org.apache.commons.math3.ode.nonstiff.AdamsIntegrator
Imports
org.apache.commons.math3.exception.DimensionMismatchException, .MathIllegalStateException, .MaxCountExceededException, .NoBracketingException, .NumberIsTooSmallException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.linear.Array2DRowRealMatrix, org.apache.commons.math3.ode.nonstiff.AdaptiveStepsizeIntegrator, .DormandPrince853Integrator, org.apache.commons.math3.ode.sampling.StepHandler, .StepInterpolator, org.apache.commons.math3.util.FastMath

This class is the base class for multistep integrators for Ordinary Differential Equations.

We define scaled derivatives si(n) at step n as:

s1(n) = h y'n for first derivative
s2(n) = h2/2 y''n for second derivative
s3(n) = h3/6 y'''n for third derivative
...
sk(n) = hk/k! y(k)n for kth derivative

Rather than storing several previous steps separately, this implementation uses the Nordsieck vector with higher degrees scaled derivatives all taken at the same step (yn, s1(n) and rn) where rn is defined as:

rn = [ s2(n), s3(n) ... sk(n) ]T
(we omit the k index in the notation for clarity)

Multistep integrators with Nordsieck representation are highly sensitive to large step changes because when the step is multiplied by factor a, the kth component of the Nordsieck vector is multiplied by ak and the last components are the least accurate ones. The default max growth factor is therefore set to a quite low value: 21/order.

Since
2.0
See Also
org.apache.commons.math3.ode.nonstiff.AdamsBashforthIntegrator, org.apache.commons.math3.ode.nonstiff.AdamsMoultonIntegrator

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MultistepIntegrator.InitializationCompletedMarkerException

Marker exception used ONLY to stop the starter integrator after first step.

private class
MultistepIntegrator.NordsieckInitializer

Specialized step handler storing the first step.

public static interface
MultistepIntegrator.NordsieckTransformer

Deprecated as of 3.6 this unused interface is deprecated
Transformer used to convert the first step to Nordsieck representation.

Field Summary

Modifier and TypeField and Description
private double
exp

Stepsize control exponent.

private double
maxGrowth

Maximal growth factor for stepsize control.

private double
minReduction

Minimal reduction factor for stepsize control.

protected Array2DRowRealMatrix
nordsieck

Nordsieck matrix of the higher scaled derivatives.

private final int
nSteps

Number of steps of the multistep method (excluding the one being computed).

private double
safety

Safety factor for stepsize control.

protected double[]
scaled

First scaled derivative (h y').

private FirstOrderIntegrator
starter

Starter integrator.

Inherited from org.apache.commons.math3.ode.nonstiff.AdaptiveStepsizeIntegrator:
mainSetDimensionscalAbsoluteTolerancescalRelativeTolerancevecAbsoluteTolerancevecRelativeTolerance

Constructor Summary

AccessConstructor and Description
protected
MultistepIntegrator(final String
name of the method
name
,
final int
number of steps of the multistep method (excluding the one being computed)
nSteps
,
final int
order of the method
order
,
final double
minimal step (must be positive even for backward integration), the last step can be smaller than this
minStep
,
final double
maximal step (must be positive even for backward integration)
maxStep
,
final double
allowed absolute error
scalAbsoluteTolerance
,
final double
allowed relative error
scalRelativeTolerance
)

Build a multistep integrator with the given stepsize bounds.

protected
MultistepIntegrator(final String
name of the method
name
,
final int
number of steps of the multistep method (excluding the one being computed)
nSteps
,
final int
order of the method
order
,
final double
minimal step (must be positive even for backward integration), the last step can be smaller than this
minStep
,
final double
maximal step (must be positive even for backward integration)
maxStep
,
final double[]
allowed absolute error
vecAbsoluteTolerance
,
final double[]
allowed relative error
vecRelativeTolerance
)

Build a multistep integrator with the given stepsize bounds.

Method Summary

Modifier and TypeMethod and Description
protected double

Returns:

grow/shrink factor for next step
computeStepGrowShrinkFactor
(final double
normalized error of the current step
error
)

Compute step grow/shrink factor according to normalized error.

public double

Returns:

maximal growth factor
getMaxGrowth
()

Get the maximal growth factor for stepsize control.

public double

Returns:

minimal reduction factor
getMinReduction
()

Get the minimal reduction factor for stepsize control.

public int

Returns:

number of steps of the multistep method (excluding the one being computed)
getNSteps
()

Get the number of steps of the multistep method (excluding the one being computed).

public double

Returns:

safety factor
getSafety
()

Get the safety factor for stepsize control.

public ODEIntegrator

Returns:

starter integrator
getStarterIntegrator
()

Get the starter integrator.

protected abstract Array2DRowRealMatrix

Returns:

Nordieck vector at first step (h2/2 y''n, h3/6 y'''n ... hk/k! y(k)n)
initializeHighOrderDerivatives
(final double
step size to use for scaling
h
,
final double[]
first steps times
t
,
final double[][]
first steps states
y
,
final double[][]
first steps derivatives
yDot
)

Initialize the high order scaled derivatives at step start.

public void
setMaxGrowth(final double
maximal growth factor
maxGrowth
)

Set the maximal growth factor for stepsize control.

public void
setMinReduction(final double
minimal reduction factor
minReduction
)

Set the minimal reduction factor for stepsize control.

public void
setSafety(final double
safety factor
safety
)

Set the safety factor for stepsize control.

public void
setStarterIntegrator(FirstOrderIntegrator
starter integrator
starterIntegrator
)

Set the starter integrator.

protected void
start(final double
initial time
t0
,
final double[]
initial value of the state vector at t0
y0
,
final double
target time for the integration (can be set to a value smaller than t0 for backward integration)
t
)

Start the integration.

Inherited from org.apache.commons.math3.ode.nonstiff.AdaptiveStepsizeIntegrator:
filterStepgetCurrentStepStartgetMaxStepgetMinStepinitializeStepintegrateresetInternalStatesanityCheckssetInitialStepSizesetStepSizeControlsetStepSizeControl

Field Detail

expback to summary
private double exp

Stepsize control exponent.

maxGrowthback to summary
private double maxGrowth

Maximal growth factor for stepsize control.

minReductionback to summary
private double minReduction

Minimal reduction factor for stepsize control.

nordsieckback to summary
protected Array2DRowRealMatrix nordsieck

Nordsieck matrix of the higher scaled derivatives.

(h2/2 y'', h3/6 y''' ..., hk/k! y(k))

nStepsback to summary
private final int nSteps

Number of steps of the multistep method (excluding the one being computed).

safetyback to summary
private double safety

Safety factor for stepsize control.

scaledback to summary
protected double[] scaled

First scaled derivative (h y').

starterback to summary
private FirstOrderIntegrator starter

Starter integrator.

Constructor Detail

MultistepIntegratorback to summary
protected MultistepIntegrator(final String name, final int nSteps, final int order, final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) throws NumberIsTooSmallException

Build a multistep integrator with the given stepsize bounds.

The default starter integrator is set to the Dormand-Prince 8(5,3) integrator with some defaults settings.

The default max growth factor is set to a quite low value: 21/order.

Parameters
name:String

name of the method

nSteps:int

number of steps of the multistep method (excluding the one being computed)

order:int

order of the method

minStep:double

minimal step (must be positive even for backward integration), the last step can be smaller than this

maxStep:double

maximal step (must be positive even for backward integration)

scalAbsoluteTolerance:double

allowed absolute error

scalRelativeTolerance:double

allowed relative error

Exceptions
NumberIsTooSmallException:
if number of steps is smaller than 2
MultistepIntegratorback to summary
protected MultistepIntegrator(final String name, final int nSteps, final int order, final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance)

Build a multistep integrator with the given stepsize bounds.

The default starter integrator is set to the Dormand-Prince 8(5,3) integrator with some defaults settings.

The default max growth factor is set to a quite low value: 21/order.

Parameters
name:String

name of the method

nSteps:int

number of steps of the multistep method (excluding the one being computed)

order:int

order of the method

minStep:double

minimal step (must be positive even for backward integration), the last step can be smaller than this

maxStep:double

maximal step (must be positive even for backward integration)

vecAbsoluteTolerance:double[]

allowed absolute error

vecRelativeTolerance:double[]

allowed relative error

Method Detail

computeStepGrowShrinkFactorback to summary
protected double computeStepGrowShrinkFactor(final double error)

Compute step grow/shrink factor according to normalized error.

Parameters
error:double

normalized error of the current step

Returns:double

grow/shrink factor for next step

getMaxGrowthback to summary
public double getMaxGrowth()

Get the maximal growth factor for stepsize control.

Returns:double

maximal growth factor

getMinReductionback to summary
public double getMinReduction()

Get the minimal reduction factor for stepsize control.

Returns:double

minimal reduction factor

getNStepsback to summary
public int getNSteps()

Get the number of steps of the multistep method (excluding the one being computed).

Returns:int

number of steps of the multistep method (excluding the one being computed)

getSafetyback to summary
public double getSafety()

Get the safety factor for stepsize control.

Returns:double

safety factor

getStarterIntegratorback to summary
public ODEIntegrator getStarterIntegrator()

Get the starter integrator.

Returns:ODEIntegrator

starter integrator

initializeHighOrderDerivativesback to summary
protected abstract Array2DRowRealMatrix initializeHighOrderDerivatives(final double h, final double[] t, final double[][] y, final double[][] yDot)

Initialize the high order scaled derivatives at step start.

Parameters
h:double

step size to use for scaling

t:double[]

first steps times

y:double[][]

first steps states

yDot:double[][]

first steps derivatives

Returns:Array2DRowRealMatrix

Nordieck vector at first step (h2/2 y''n, h3/6 y'''n ... hk/k! y(k)n)

setMaxGrowthback to summary
public void setMaxGrowth(final double maxGrowth)

Set the maximal growth factor for stepsize control.

Parameters
maxGrowth:double

maximal growth factor

setMinReductionback to summary
public void setMinReduction(final double minReduction)

Set the minimal reduction factor for stepsize control.

Parameters
minReduction:double

minimal reduction factor

setSafetyback to summary
public void setSafety(final double safety)

Set the safety factor for stepsize control.

Parameters
safety:double

safety factor

setStarterIntegratorback to summary
public void setStarterIntegrator(FirstOrderIntegrator starterIntegrator)

Set the starter integrator.

The various step and event handlers for this starter integrator will be managed automatically by the multi-step integrator. Any user configuration for these elements will be cleared before use.

Parameters
starterIntegrator:FirstOrderIntegrator

starter integrator

startback to summary
protected void start(final double t0, final double[] y0, final double t) throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException

Start the integration.

This method computes one step using the underlying starter integrator, and initializes the Nordsieck vector at step start. The starter integrator purpose is only to establish initial conditions, it does not really change time by itself. The top level multistep integrator remains in charge of handling time propagation and events handling as it will starts its own computation right from the beginning. In a sense, the starter integrator can be seen as a dummy one and so it will never trigger any user event nor call any user step handler.

Parameters
t0:double

initial time

y0:double[]

initial value of the state vector at t0

t:double

target time for the integration (can be set to a value smaller than t0 for backward integration)

Exceptions
DimensionMismatchException:
if arrays dimension do not match equations settings
NumberIsTooSmallException:
if integration step is too small
MaxCountExceededException:
if the number of functions evaluations is exceeded
NoBracketingException:
if the location of an event cannot be bracketed
org.apache.commons.math3.ode back to summary

private Class MultistepIntegrator.InitializationCompletedMarkerException

extends RuntimeException
Class Inheritance

Marker exception used ONLY to stop the starter integrator after first step.

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

Serializable version identifier.

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

Serializable version identifier.

Constructor Detail

InitializationCompletedMarkerExceptionback to summary
pack-priv InitializationCompletedMarkerException()

Simple constructor.

org.apache.commons.math3.ode back to summary

private Class MultistepIntegrator.NordsieckInitializer

extends Object
implements StepHandler
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.ode.MultistepIntegrator.NordsieckInitializer
All Implemented Interfaces
org.apache.commons.math3.ode.sampling.StepHandler

Specialized step handler storing the first step.

Field Summary

Modifier and TypeField and Description
private int
count

Steps counter.

private final double[]
t

First steps times.

private final double[][]
y

First steps states.

private final double[][]
yDot

First steps derivatives.

Constructor Summary

AccessConstructor and Description
pack-priv
NordsieckInitializer(final int
number of start points (including the initial point)
nbStartPoints
,
final int
problem dimension
n
)

Simple constructor.

Method Summary

Modifier and TypeMethod and Description
public void
handleStep(StepInterpolator
interpolator for the last accepted step. For efficiency purposes, the various integrators reuse the same object on each call, so if the instance wants to keep it across all calls (for example to provide at the end of the integration a continuous model valid throughout the integration range, as the ContinuousOutputModel class does), it should build a local copy using the clone method of the interpolator and store this copy. Keeping only a reference to the interpolator and reusing it will result in unpredictable behavior (potentially crashing the application).
interpolator
,
boolean
true if the step is the last one
isLast
)

Implements org.apache.commons.math3.ode.sampling.StepHandler.handleStep.

Handle the last accepted step

public void
init(double
start value of the independent time variable
t0
,
double[]
array containing the start value of the state vector
y0
,
double
target time for the integration
time
)

Implements org.apache.commons.math3.ode.sampling.StepHandler.init.

Initialize step handler at the start of an ODE integration.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private int count

Steps counter.

tback to summary
private final double[] t

First steps times.

yback to summary
private final double[][] y

First steps states.

yDotback to summary
private final double[][] yDot

First steps derivatives.

Constructor Detail

NordsieckInitializerback to summary
pack-priv NordsieckInitializer(final int nbStartPoints, final int n)

Simple constructor.

Parameters
nbStartPoints:int

number of start points (including the initial point)

n:int

problem dimension

Method Detail

handleStepback to summary
public void handleStep(StepInterpolator interpolator, boolean isLast) throws MaxCountExceededException

Implements org.apache.commons.math3.ode.sampling.StepHandler.handleStep.

Doc from org.apache.commons.math3.ode.sampling.StepHandler.handleStep.

Handle the last accepted step

Parameters
interpolator:StepInterpolator

interpolator for the last accepted step. For efficiency purposes, the various integrators reuse the same object on each call, so if the instance wants to keep it across all calls (for example to provide at the end of the integration a continuous model valid throughout the integration range, as the ContinuousOutputModel class does), it should build a local copy using the clone method of the interpolator and store this copy. Keeping only a reference to the interpolator and reusing it will result in unpredictable behavior (potentially crashing the application).

isLast:boolean

true if the step is the last one

Exceptions
MaxCountExceededException:
if the interpolator throws one because the number of functions evaluations is exceeded
initback to summary
public void init(double t0, double[] y0, double time)

Implements org.apache.commons.math3.ode.sampling.StepHandler.init.

Doc from org.apache.commons.math3.ode.sampling.StepHandler.init.

Initialize step handler at the start of an ODE integration.

This method is called once at the start of the integration. It may be used by the step handler to initialize some internal data if needed.

Parameters
t0:double

start value of the independent time variable

y0:double[]

array containing the start value of the state vector

time:double

target time for the integration

org.apache.commons.math3.ode back to summary

public Interface MultistepIntegrator.NordsieckTransformer

Annotations
@Deprecated

Deprecated

as of 3.6 this unused interface is deprecated

Transformer used to convert the first step to Nordsieck representation.

Method Summary

Modifier and TypeMethod and Description
public Array2DRowRealMatrix

Returns:

Nordieck vector at first step (h2/2 y''n, h3/6 y'''n ... hk/k! y(k)n)
initializeHighOrderDerivatives
(final double
step size to use for scaling
h
,
final double[]
first steps times
t
,
final double[][]
first steps states
y
,
final double[][]
first steps derivatives
yDot
)

Initialize the high order scaled derivatives at step start.

Method Detail

initializeHighOrderDerivativesback to summary
public Array2DRowRealMatrix initializeHighOrderDerivatives(final double h, final double[] t, final double[][] y, final double[][] yDot)

Initialize the high order scaled derivatives at step start.

Parameters
h:double

step size to use for scaling

t:double[]

first steps times

y:double[][]

first steps states

yDot:double[][]

first steps derivatives

Returns:Array2DRowRealMatrix

Nordieck vector at first step (h2/2 y''n, h3/6 y'''n ... hk/k! y(k)n)