Package org.apache.commons.math3.ode

# Class AbstractIntegrator

java.lang.Object
org.apache.commons.math3.ode.AbstractIntegrator

All Implemented Interfaces:
  `FirstOrderIntegrator`, `ODEIntegrator`

Direct Known Subclasses:
  `AdaptiveStepsizeIntegrator`, `RungeKuttaIntegrator`

public abstract class AbstractIntegrator extends Object implements FirstOrderIntegrator
Base class managing common boilerplate for all integrators.

Since:
  2.0

## Field Summary

Fields
Modifier and Type
Field
Description
`protected boolean`
`isLastStep`
Indicator for last step.
`protected boolean`
`resetOccurred`
Indicator that a state or derivative reset was triggered by some event.
`protected Collection<StepHandler>`
`stepHandlers`
Step handler.
`protected double`
`stepSize`
Current stepsize.
`protected double`
`stepStart`
Current step start time.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`AbstractIntegrator()`
Build an instance with a null name.
``
`AbstractIntegrator(String name)`
Build an instance.

## Method Summary

Modifier and Type
Method
Description
`protected double`
`acceptStep(AbstractStepInterpolator interpolator, double[] y, double[] yDot, double tEnd)`
Accept a step, triggering events and step handlers.
`void`
`addEventHandler(EventHandler handler, double maxCheckInterval, double convergence, int maxIterationCount)`
Add an event handler to the integrator.
`void`
`addEventHandler(EventHandler handler, double maxCheckInterval, double convergence, int maxIterationCount, UnivariateSolver solver)`
Add an event handler to the integrator.
`void`
`addStepHandler(StepHandler handler)`
Add a step handler to this integrator.
`void`
`clearEventHandlers()`
Remove all the event handlers that have been added to the integrator.
`void`
`clearStepHandlers()`
Remove all the step handlers that have been added to the integrator.
`void`
`computeDerivatives(double t, double[] y, double[] yDot)`
Compute the derivatives and check the number of evaluations.
`protected IntegerSequence.Incrementor`
`getCounter()`
Get the evaluations counter.
`double`
`getCurrentSignedStepsize()`
Get the current signed value of the integration stepsize.
`double`
`getCurrentStepStart()`
Get the current value of the step start time ti.
`int`
`getEvaluations()`
Get the number of evaluations of the differential equations function.
`protected Incrementor`
`getEvaluationsCounter()`
Deprecated.
as of 3.6 replaced with `getCounter()`
`Collection<EventHandler>`
`getEventHandlers()`
Get all the event handlers that have been added to the integrator.
`protected ExpandableStatefulODE`
`getExpandable()`
Get the differential equations to integrate.
`int`
`getMaxEvaluations()`
Get the maximal number of functions evaluations.
`String`
`getName()`
Get the name of the method.
`Collection<StepHandler>`
`getStepHandlers()`
Get all the step handlers that have been added to the integrator.
`protected void`
`initIntegration(double t0, double[] y0, double t)`
Prepare the start of an integration.
`abstract void`
`integrate(ExpandableStatefulODE equations, double t)`
Integrate a set of differential equations up to the given time.
`double`
`integrate(FirstOrderDifferentialEquations equations, double t0, double[] y0, double t, double[] y)`
Integrate the differential equations up to the given time.
`protected void`
`sanityChecks(ExpandableStatefulODE equations, double t)`
Check the integration span.
`protected void`
`setEquations(ExpandableStatefulODE equations)`
Set the equations.
`void`
`setMaxEvaluations(int maxEvaluations)`
Set the maximal number of differential equations function evaluations.
`protected void`
`setStateInitialized(boolean stateInitialized)`
Set the stateInitialized flag.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### stepHandlers

protected Collection<StepHandler> stepHandlers
Step handler.

### stepStart

protected double stepStart
Current step start time.

### stepSize

protected double stepSize
Current stepsize.

### isLastStep

protected boolean isLastStep
Indicator for last step.

### resetOccurred

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

## Constructor Details

### AbstractIntegrator

public AbstractIntegrator(String name)
Build an instance.

Parameters:
  `name` - name of the method

### AbstractIntegrator

protected AbstractIntegrator()
Build an instance with a null name.

## Method Details

### getName

public String getName()
Get the name of the method.

Specified by:
  `getName` in interface `ODEIntegrator`
Returns:
  name of the method

### addStepHandler

public void addStepHandler(StepHandler handler)
Add a step handler to this integrator.

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

Specified by:
  `addStepHandler` in interface `ODEIntegrator`
Parameters:
  `handler` - handler for the accepted steps
See Also:
  - `ODEIntegrator.getStepHandlers()`
  - `ODEIntegrator.clearStepHandlers()`

### getStepHandlers

public Collection<StepHandler> getStepHandlers()
Get all the step handlers that have been added to the integrator.

Specified by:
  `getStepHandlers` in interface `ODEIntegrator`
Returns:
  an unmodifiable collection of the added events handlers
See Also:
  - `ODEIntegrator.addStepHandler(StepHandler)`
  - `ODEIntegrator.clearStepHandlers()`

### clearStepHandlers

public void clearStepHandlers()
Remove all the step handlers that have been added to the integrator.

Specified by:
  `clearStepHandlers` in interface `ODEIntegrator`
See Also:
  - `ODEIntegrator.addStepHandler(StepHandler)`
  - `ODEIntegrator.getStepHandlers()`

### addEventHandler

public void addEventHandler(EventHandler handler, double maxCheckInterval, double convergence, int maxIterationCount)
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.

Specified by:
  `addEventHandler` in interface `ODEIntegrator`
Parameters:
  `handler` - event handler
  `maxCheckInterval` - maximal time interval between switching function checks (this interval prevents missing sign changes in case the integration steps becomes very large)
  `convergence` - convergence threshold in the event time search
  `maxIterationCount` - upper limit of the iteration count in the event time search
See Also:
  - `ODEIntegrator.getEventHandlers()`
  - `ODEIntegrator.clearEventHandlers()`

### addEventHandler

public void addEventHandler(EventHandler handler, double maxCheckInterval, double convergence, int maxIterationCount, UnivariateSolver solver)
Add an event handler to the integrator.

Specified by:
  `addEventHandler` in interface `ODEIntegrator`
Parameters:
  `handler` - event handler
  `maxCheckInterval` - maximal time interval between switching function checks (this interval prevents missing sign changes in case the integration steps becomes very large)
  `convergence` - convergence threshold in the event time search
  `maxIterationCount` - upper limit of the iteration count in the event time search
  `solver` - The root-finding algorithm to use to detect the state events.
See Also:
  - `ODEIntegrator.getEventHandlers()`
  - `ODEIntegrator.clearEventHandlers()`

### getEventHandlers

public Collection<EventHandler> getEventHandlers()
Get all the event handlers that have been added to the integrator.

Specified by:
  `getEventHandlers` in interface `ODEIntegrator`
Returns:
  an unmodifiable collection of the added events handlers
See Also:
  - `ODEIntegrator.addEventHandler(EventHandler, double, double, int)`
  - `ODEIntegrator.clearEventHandlers()`

### clearEventHandlers

public void clearEventHandlers()
Remove all the event handlers that have been added to the integrator.

Specified by:
  `clearEventHandlers` in interface `ODEIntegrator`
See Also:
  - `ODEIntegrator.addEventHandler(EventHandler, double, double, int)`
  - `ODEIntegrator.getEventHandlers()`

### getCurrentStepStart

public double 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`.

Specified by:
  `getCurrentStepStart` in interface `ODEIntegrator`
Returns:
  current value of the step start time ti

### getCurrentSignedStepsize

public double 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`.

Specified by:
  `getCurrentSignedStepsize` in interface `ODEIntegrator`
Returns:
  current signed value of the stepsize

### setMaxEvaluations

public void setMaxEvaluations(int maxEvaluations)
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.

Specified by:
  `setMaxEvaluations` in interface `ODEIntegrator`
Parameters:
  `maxEvaluations` - maximal number of function evaluations (negative values are silently converted to maximal integer value, thus representing almost unlimited evaluations)

### getMaxEvaluations

public int getMaxEvaluations()
Get the maximal number of functions evaluations.

Specified by:
  `getMaxEvaluations` in interface `ODEIntegrator`
Returns:
  maximal number of functions evaluations

### getEvaluations

public int 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.

Specified by:
  `getEvaluations` in interface `ODEIntegrator`
Returns:
  number of evaluations of the differential equations function

### initIntegration

protected void initIntegration(double t0, double[] y0, double t)
Prepare the start of an integration.

Parameters:
  `t0` - start value of the independent time variable
  `y0` - array containing the start value of the state vector
  `t` - target time for the integration

### setEquations

protected void setEquations(ExpandableStatefulODE equations)
Set the equations.

Parameters:
  `equations` - equations to set

### getExpandable

protected ExpandableStatefulODE getExpandable()
Get the differential equations to integrate.

Returns:
  differential equations to integrate
Since:
  3.2

### getEvaluationsCounter

@Deprecated protected Incrementor getEvaluationsCounter()
Deprecated.
as of 3.6 replaced with `getCounter()`
Get the evaluations counter.

Returns:
  evaluations counter
Since:
  3.2

### getCounter

protected IntegerSequence.Incrementor getCounter()
Get the evaluations counter.

Returns:
  evaluations counter
Since:
  3.6

### integrate

public double integrate(FirstOrderDifferentialEquations equations, double t0, double[] y0, double t, double[] y) throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException
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 (`ODEIntegrator.getCurrentSignedStepsize()`), it is not thread-safe.

Specified by:
  `integrate` in interface `FirstOrderIntegrator`
Parameters:
  `equations` - differential equations to integrate
  `t0` - initial time
  `y0` - initial value of the state vector at t0
  `t` - target time for the integration (can be set to a value smaller than `t0` for backward integration)
  `y` - 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:
  stop time, will be the same as target time if integration reached its target, but may be different if some `EventHandler` stops it at some point.
Throws:
  `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

### integrate

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` - complete set of differential equations to integrate
  `t` - target time for the integration (can be set to a value smaller than `t0` for backward integration)
Throws:
  `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

### computeDerivatives

public void computeDerivatives(double t, double[] y, double[] yDot) throws MaxCountExceededException, DimensionMismatchException, NullPointerException
Compute the derivatives and check the number of evaluations.

Parameters:
  `t` - current value of the independent time variable
  `y` - array containing the current value of the state vector
  `yDot` - placeholder array where to put the time derivative of the state vector
Throws:
  `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[])`)

### setStateInitialized

protected void setStateInitialized(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` - new value for the flag
Since:
  2.2

### acceptStep

protected double acceptStep(AbstractStepInterpolator interpolator, double[] y, double[] yDot, double tEnd) throws MaxCountExceededException, DimensionMismatchException, NoBracketingException
Accept a step, triggering events and step handlers.

Parameters:
  `interpolator` - step interpolator
  `y` - 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` - placeholder array where to put the time derivative of the state vector
  `tEnd` - final integration time
Returns:
  time at end of step
Throws:
  `MaxCountExceededException` - if the interpolator throws one because the number of functions evaluations is exceeded
  `NoBracketingException` - if the location of an event cannot be bracketed
  `DimensionMismatchException` - if arrays dimensions do not match equations settings
Since:
  2.2

### sanityChecks

protected void sanityChecks(ExpandableStatefulODE equations, double t) throws NumberIsTooSmallException, DimensionMismatchException
Check the integration span.

Parameters:
  `equations` - set of differential equations
  `t` - target time for the integration
Throws:
  `NumberIsTooSmallException` - if integration span is too small
  `DimensionMismatchException` - if adaptive step size integrators tolerance arrays dimensions are not compatible with equations settings