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

public abstract Class AbstractIntegrator

extends Object
implements FirstOrderIntegrator
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.ode.FirstOrderIntegrator, org.apache.commons.math3.ode.ODEIntegrator
Known Direct Subclasses
org.apache.commons.math3.ode.nonstiff.AdaptiveStepsizeIntegrator, org.apache.commons.math3.ode.nonstiff.RungeKuttaIntegrator
Imports
java.util.ArrayList, .Collection, .Collections, .Comparator, .Iterator, .List, .SortedSet, .TreeSet, org.apache.commons.math3.analysis.solvers.BracketingNthOrderBrentSolver, .UnivariateSolver, org.apache.commons.math3.exception.DimensionMismatchException, .MaxCountExceededException, .NoBracketingException, .NumberIsTooSmallException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.ode.events.EventHandler, .EventState, org.apache.commons.math3.ode.sampling.AbstractStepInterpolator, .StepHandler, org.apache.commons.math3.util.FastMath, .IntegerSequence, .Precision

Base class managing common boilerplate for all integrators.
Since
2.0

Field Summary

Modifier and TypeField and Description
private IntegerSequence.Incrementor
evaluations

Counter for number of evaluations.

private Collection<EventState>
eventsStates

Events states.

private transient ExpandableStatefulODE
expandable

Differential equations to integrate.

protected boolean
isLastStep

Indicator for last step.

private final String
name

Name of the method.

protected boolean
resetOccurred

Indicator that a state or derivative reset was triggered by some event.

private boolean
statesInitialized

Initialization indicator of events states.

protected Collection<StepHandler>
stepHandlers

Step handler.

protected double
stepSize

Current stepsize.

protected double
stepStart

Current step start time.

Constructor Summary

AccessConstructor and Description
public
AbstractIntegrator(final String
name of the method
name
)

Build an instance.

protected
AbstractIntegrator()

Build an instance with a null name.

Method Summary

Modifier and TypeMethod and Description
protected double

Returns:

time at end of step
acceptStep
(final AbstractStepInterpolator
step interpolator
interpolator
,
final double[]
state vector at step end time, must be reset if an event asks for resetting or if an events stops integration during the step
y
,
final double[]
placeholder array where to put the time derivative of the state vector
yDot
,
final double
final integration time
tEnd
)

Accept a step, triggering events and step handlers.

public void
addEventHandler(final EventHandler
event handler
handler
,
final double
maximal time interval between switching function checks (this interval prevents missing sign changes in case the integration steps becomes very large)
maxCheckInterval
,
final double
convergence threshold in the event time search
convergence
,
final int
upper limit of the iteration count in the event time search
maxIterationCount
)

Implements org.apache.commons.math3.ode.ODEIntegrator.addEventHandler.

Add an event handler to the integrator.

public void
addEventHandler(final EventHandler
event handler
handler
,
final double
maximal time interval between switching function checks (this interval prevents missing sign changes in case the integration steps becomes very large)
maxCheckInterval
,
final double
convergence threshold in the event time search
convergence
,
final int
upper limit of the iteration count in the event time search
maxIterationCount
,
final UnivariateSolver
The root-finding algorithm to use to detect the state events.
solver
)

Implements org.apache.commons.math3.ode.ODEIntegrator.addEventHandler.

Add an event handler to the integrator.

public void
addStepHandler(final StepHandler
handler for the accepted steps
handler
)

Implements org.apache.commons.math3.ode.ODEIntegrator.addStepHandler.

Add a step handler to this integrator.

public void
clearEventHandlers()

Implements org.apache.commons.math3.ode.ODEIntegrator.clearEventHandlers.

Remove all the event handlers that have been added to the integrator.

public void
clearStepHandlers()

Implements org.apache.commons.math3.ode.ODEIntegrator.clearStepHandlers.

Remove all the step handlers that have been added to the integrator.

public void
computeDerivatives(final double
current value of the independent time variable
t
,
final double[]
array containing the current value of the state vector
y
,
final double[]
placeholder array where to put the time derivative of the state vector
yDot
)

Compute the derivatives and check the number of evaluations.

protected IntegerSequence.Incrementor

Returns:

evaluations counter
getCounter
()

Get the evaluations counter.

public double
getCurrentSignedStepsize()

Implements org.apache.commons.math3.ode.ODEIntegrator.getCurrentSignedStepsize.

Get the current signed value of the integration stepsize.

public double
getCurrentStepStart()

Implements org.apache.commons.math3.ode.ODEIntegrator.getCurrentStepStart.

Get the current value of the step start time ti.

public int
getEvaluations()

Implements org.apache.commons.math3.ode.ODEIntegrator.getEvaluations.

Get the number of evaluations of the differential equations function.

protected Incrementor

Returns:

evaluations counter
getEvaluationsCounter
()
Deprecated as of 3.6 replaced with getCounter()

Get the evaluations counter.

public Collection<EventHandler>
getEventHandlers()

Implements org.apache.commons.math3.ode.ODEIntegrator.getEventHandlers.

Get all the event handlers that have been added to the integrator.

protected ExpandableStatefulODE

Returns:

differential equations to integrate
getExpandable
()

Get the differential equations to integrate.

public int
getMaxEvaluations()

Implements org.apache.commons.math3.ode.ODEIntegrator.getMaxEvaluations.

Get the maximal number of functions evaluations.

public String
getName()

Implements org.apache.commons.math3.ode.ODEIntegrator.getName.

Get the name of the method.

public Collection<StepHandler>
getStepHandlers()

Implements org.apache.commons.math3.ode.ODEIntegrator.getStepHandlers.

Get all the step handlers that have been added to the integrator.

protected void
initIntegration(final double
start value of the independent time variable
t0
,
final double[]
array containing the start value of the state vector
y0
,
final double
target time for the integration
t
)

Prepare the start of an integration.

public double
integrate(final FirstOrderDifferentialEquations
differential equations to integrate
equations
,
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
,
final double[]
placeholder where to put the state vector at each successful step (and hence at the end of integration), can be the same object as y0
y
)

Implements org.apache.commons.math3.ode.FirstOrderIntegrator.integrate.

Integrate the differential equations up to the given time.

public abstract void
integrate(ExpandableStatefulODE
complete set of differential equations to integrate
equations
,
double
target time for the integration (can be set to a value smaller than t0 for backward integration)
t
)

Integrate a set of differential equations up to the given time.

protected void
sanityChecks(final ExpandableStatefulODE
set of differential equations
equations
,
final double
target time for the integration
t
)

Check the integration span.

protected void
setEquations(final ExpandableStatefulODE
equations to set
equations
)

Set the equations.

public void
setMaxEvaluations(int
maximal number of function evaluations (negative values are silently converted to maximal integer value, thus representing almost unlimited evaluations)
maxEvaluations
)

Implements org.apache.commons.math3.ode.ODEIntegrator.setMaxEvaluations.

Set the maximal number of differential equations function evaluations.

protected void
setStateInitialized(final boolean
new value for the flag
stateInitialized
)

Set the stateInitialized flag.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

evaluationsback to summary
private IntegerSequence.Incrementor evaluations

Counter for number of evaluations.

eventsStatesback to summary
private Collection<EventState> eventsStates

Events states.

expandableback to summary
private transient ExpandableStatefulODE expandable

Differential equations to integrate.

isLastStepback to summary
protected boolean isLastStep

Indicator for last step.

nameback to summary
private final String name

Name of the method.

resetOccurredback to summary
protected boolean resetOccurred

Indicator that a state or derivative reset was triggered by some event.

statesInitializedback to summary
private boolean statesInitialized

Initialization indicator of events states.

stepHandlersback to summary
protected Collection<StepHandler> stepHandlers

Step handler.

stepSizeback to summary
protected double stepSize

Current stepsize.

stepStartback to summary
protected double stepStart

Current step start time.

Constructor Detail

AbstractIntegratorback to summary
public AbstractIntegrator(final String name)

Build an instance.

Parameters
name:String

name of the method

AbstractIntegratorback to summary
protected AbstractIntegrator()

Build an instance with a null name.

Method Detail

acceptStepback to summary
protected double acceptStep(final AbstractStepInterpolator interpolator, final double[] y, final double[] yDot, final double tEnd) throws MaxCountExceededException, DimensionMismatchException, NoBracketingException

Accept a step, triggering events and step handlers.

Parameters
interpolator:AbstractStepInterpolator

step interpolator

y:double[]

state vector at step end time, must be reset if an event asks for resetting or if an events stops integration during the step

yDot:double[]

placeholder array where to put the time derivative of the state vector

tEnd:double

final integration time

Returns:double

time at end of step

Exceptions
MaxCountExceededException:
if the interpolator throws one because the number of functions evaluations is exceeded
DimensionMismatchException:
if arrays dimensions do not match equations settings
NoBracketingException:
if the location of an event cannot be bracketed
Since
2.2
addEventHandlerback to summary
public void addEventHandler(final EventHandler handler, final double maxCheckInterval, final double convergence, final int maxIterationCount)

Implements org.apache.commons.math3.ode.ODEIntegrator.addEventHandler.

Doc from org.apache.commons.math3.ode.ODEIntegrator.addEventHandler.

Add an event handler to the integrator. Uses a default UnivariateSolver with an absolute accuracy equal to the given convergence threshold, as root-finding algorithm to detect the state events.

Parameters
handler:EventHandler

event handler

maxCheckInterval:double

maximal time interval between switching function checks (this interval prevents missing sign changes in case the integration steps becomes very large)

convergence:double

convergence threshold in the event time search

maxIterationCount:int

upper limit of the iteration count in the event time search

addEventHandlerback to summary
public void addEventHandler(final EventHandler handler, final double maxCheckInterval, final double convergence, final int maxIterationCount, final UnivariateSolver solver)

Implements org.apache.commons.math3.ode.ODEIntegrator.addEventHandler.

Doc from org.apache.commons.math3.ode.ODEIntegrator.addEventHandler.

Add an event handler to the integrator.

Parameters
handler:EventHandler

event handler

maxCheckInterval:double

maximal time interval between switching function checks (this interval prevents missing sign changes in case the integration steps becomes very large)

convergence:double

convergence threshold in the event time search

maxIterationCount:int

upper limit of the iteration count in the event time search

solver:UnivariateSolver

The root-finding algorithm to use to detect the state events.

addStepHandlerback to summary
public void addStepHandler(final StepHandler handler)

Implements org.apache.commons.math3.ode.ODEIntegrator.addStepHandler.

Doc from org.apache.commons.math3.ode.ODEIntegrator.addStepHandler.

Add a step handler to this integrator.

The handler will be called by the integrator for each accepted step.

Parameters
handler:StepHandler

handler for the accepted steps

clearEventHandlersback to summary
public void clearEventHandlers()

Implements org.apache.commons.math3.ode.ODEIntegrator.clearEventHandlers.

Doc from org.apache.commons.math3.ode.ODEIntegrator.clearEventHandlers.

Remove all the event handlers that have been added to the integrator.

clearStepHandlersback to summary
public void clearStepHandlers()

Implements org.apache.commons.math3.ode.ODEIntegrator.clearStepHandlers.

Doc from org.apache.commons.math3.ode.ODEIntegrator.clearStepHandlers.

Remove all the step handlers that have been added to the integrator.

computeDerivativesback to summary
public void computeDerivatives(final double t, final double[] y, final double[] yDot) throws MaxCountExceededException, DimensionMismatchException, NullPointerException

Compute the derivatives and check the number of evaluations.

Parameters
t:double

current value of the independent time variable

y:double[]

array containing the current value of the state vector

yDot:double[]

placeholder array where to put the time derivative of the state vector

Exceptions
MaxCountExceededException:
if the number of functions evaluations is exceeded
DimensionMismatchException:
if arrays dimensions do not match equations settings
NullPointerException:
if the ODE equations have not been set (i.e. if this method is called outside of a call to integrate(ExpandableStatefulODE, double) or integrate(FirstOrderDifferentialEquations, double, double[], double, double[]))
getCounterback to summary
protected IntegerSequence.Incrementor getCounter()

Get the evaluations counter.

Returns:IntegerSequence.Incrementor

evaluations counter

Since
3.6
getCurrentSignedStepsizeback to summary
public double getCurrentSignedStepsize()

Implements org.apache.commons.math3.ode.ODEIntegrator.getCurrentSignedStepsize.

Doc from org.apache.commons.math3.ode.ODEIntegrator.getCurrentSignedStepsize.

Get the current signed value of the integration stepsize.

This method can be called during integration (typically by the object implementing the differential equations problem) if the signed value of the current stepsize that is tried is needed.

The result is undefined if the method is called outside of calls to integrate.

Returns:double

current signed value of the stepsize

getCurrentStepStartback to summary
public double getCurrentStepStart()

Implements org.apache.commons.math3.ode.ODEIntegrator.getCurrentStepStart.

Doc from org.apache.commons.math3.ode.ODEIntegrator.getCurrentStepStart.

Get the current value of the step start time ti.

This method can be called during integration (typically by the object implementing the differential equations problem) if the value of the current step that is attempted is needed.

The result is undefined if the method is called outside of calls to integrate.

Returns:double

current value of the step start time ti

getEvaluationsback to summary
public int getEvaluations()

Implements org.apache.commons.math3.ode.ODEIntegrator.getEvaluations.

Doc from org.apache.commons.math3.ode.ODEIntegrator.getEvaluations.

Get the number of evaluations of the differential equations function.

The number of evaluations corresponds to the last call to the integrate method. It is 0 if the method has not been called yet.

Returns:int

number of evaluations of the differential equations function

getEvaluationsCounterback to summary
protected Incrementor getEvaluationsCounter()

Deprecated

as of 3.6 replaced with getCounter()

Get the evaluations counter.

Returns:Incrementor

evaluations counter

Annotations
@Deprecated
Since
3.2
getEventHandlersback to summary
public Collection<EventHandler> getEventHandlers()

Implements org.apache.commons.math3.ode.ODEIntegrator.getEventHandlers.

Doc from org.apache.commons.math3.ode.ODEIntegrator.getEventHandlers.

Get all the event handlers that have been added to the integrator.

Returns:Collection<EventHandler>

an unmodifiable collection of the added events handlers

getExpandableback to summary
protected ExpandableStatefulODE getExpandable()

Get the differential equations to integrate.

Returns:ExpandableStatefulODE

differential equations to integrate

Since
3.2
getMaxEvaluationsback to summary
public int getMaxEvaluations()

Implements org.apache.commons.math3.ode.ODEIntegrator.getMaxEvaluations.

Doc from org.apache.commons.math3.ode.ODEIntegrator.getMaxEvaluations.

Get the maximal number of functions evaluations.

Returns:int

maximal number of functions evaluations

getNameback to summary
public String getName()

Implements org.apache.commons.math3.ode.ODEIntegrator.getName.

Doc from org.apache.commons.math3.ode.ODEIntegrator.getName.

Get the name of the method.

Returns:String

name of the method

getStepHandlersback to summary
public Collection<StepHandler> getStepHandlers()

Implements org.apache.commons.math3.ode.ODEIntegrator.getStepHandlers.

Doc from org.apache.commons.math3.ode.ODEIntegrator.getStepHandlers.

Get all the step handlers that have been added to the integrator.

Returns:Collection<StepHandler>

an unmodifiable collection of the added events handlers

initIntegrationback to summary
protected void initIntegration(final double t0, final double[] y0, final double t)

Prepare the start of an integration.

Parameters
t0:double

start value of the independent time variable

y0:double[]

array containing the start value of the state vector

t:double

target time for the integration

integrateback to summary
public double integrate(final FirstOrderDifferentialEquations equations, final double t0, final double[] y0, final double t, final double[] y) throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException

Implements org.apache.commons.math3.ode.FirstOrderIntegrator.integrate.

Doc from org.apache.commons.math3.ode.FirstOrderIntegrator.integrate.

Integrate the differential equations up to the given time.

This method solves an Initial Value Problem (IVP).

Since this method stores some internal state variables made available in its public interface during integration (getCurrentSignedStepsize()), it is not thread-safe.

Parameters
equations:FirstOrderDifferentialEquations

differential equations to integrate

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)

y:double[]

placeholder where to put the state vector at each successful step (and hence at the end of integration), can be the same object as y0

Returns:double

stop time, will be the same as target time if integration reached its target, but may be different if some org.apache.commons.math3.ode.events.EventHandler stops it at some point.

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
integrateback to summary
public abstract void integrate(ExpandableStatefulODE equations, double t) throws NumberIsTooSmallException, DimensionMismatchException, MaxCountExceededException, NoBracketingException

Integrate a set of differential equations up to the given time.

This method solves an Initial Value Problem (IVP).

The set of differential equations is composed of a main set, which can be extended by some sets of secondary equations. The set of equations must be already set up with initial time and partial states. At integration completion, the final time and partial states will be available in the same object.

Since this method stores some internal state variables made available in its public interface during integration (getCurrentSignedStepsize()), it is not thread-safe.

Parameters
equations:ExpandableStatefulODE

complete set of differential equations to integrate

t:double

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

Exceptions
NumberIsTooSmallException:
if integration step is too small
DimensionMismatchException:
if the dimension of the complete state does not match the complete equations sets dimension
MaxCountExceededException:
if the number of functions evaluations is exceeded
NoBracketingException:
if the location of an event cannot be bracketed
sanityChecksback to summary
protected void sanityChecks(final ExpandableStatefulODE equations, final double t) throws NumberIsTooSmallException, DimensionMismatchException

Check the integration span.

Parameters
equations:ExpandableStatefulODE

set of differential equations

t:double

target time for the integration

Exceptions
NumberIsTooSmallException:
if integration span is too small
DimensionMismatchException:
if adaptive step size integrators tolerance arrays dimensions are not compatible with equations settings
setEquationsback to summary
protected void setEquations(final ExpandableStatefulODE equations)

Set the equations.

Parameters
equations:ExpandableStatefulODE

equations to set

setMaxEvaluationsback to summary
public void setMaxEvaluations(int maxEvaluations)

Implements org.apache.commons.math3.ode.ODEIntegrator.setMaxEvaluations.

Doc from org.apache.commons.math3.ode.ODEIntegrator.setMaxEvaluations.

Set the maximal number of differential equations function evaluations.

The purpose of this method is to avoid infinite loops which can occur for example when stringent error constraints are set or when lots of discrete events are triggered, thus leading to many rejected steps.

Parameters
maxEvaluations:int

maximal number of function evaluations (negative values are silently converted to maximal integer value, thus representing almost unlimited evaluations)

setStateInitializedback to summary
protected void setStateInitialized(final boolean stateInitialized)

Set the stateInitialized flag.

This method must be called by integrators with the value false before they start integration, so a proper lazy initialization is done automatically on the first step.

Parameters
stateInitialized:boolean

new value for the flag

Since
2.2