org.apache.commons.math4.ode.nonstiff

• Type Parameters:
T - the type of the field elements
All Implemented Interfaces:
FirstOrderFieldIntegrator<T>
Direct Known Subclasses:
EmbeddedRungeKuttaFieldIntegrator, MultistepFieldIntegrator

public abstract class AdaptiveStepsizeFieldIntegrator<T extends RealFieldElement<T>>
extends AbstractFieldIntegrator<T>
This abstract class holds the common part of all adaptive stepsize integrators for Ordinary Differential Equations.

These algorithms perform integration with stepsize control, which means the user does not specify the integration step but rather a tolerance on error. The error threshold is computed as

 threshold_i = absTol_i + relTol_i * max (abs (ym), abs (ym+1))

where absTol_i is the absolute tolerance for component i of the state vector and relTol_i is the relative tolerance for the same component. The user can also use only two scalar values absTol and relTol which will be used for all components.

Note that only the main part of the state vector is used for stepsize control. The secondary parts of the state vector are explicitly ignored for stepsize control.

If the estimated error for ym+1 is such that

 sqrt((sum (errEst_i / threshold_i)^2 ) / n) < 1

(where n is the main set dimension) then the step is accepted, otherwise the step is rejected and a new attempt is made with a new stepsize.

Since:
3.6
• ### Field Summary

Fields
Modifier and Type Field and Description
protected int mainSetDimension
Main set dimension.
protected double scalAbsoluteTolerance
Allowed absolute scalar error.
protected double scalRelativeTolerance
Allowed relative scalar error.
protected double[] vecAbsoluteTolerance
Allowed absolute vectorial error.
protected double[] vecRelativeTolerance
Allowed relative vectorial error.
• ### Constructor Summary

Constructors
Constructor and Description
AdaptiveStepsizeFieldIntegrator(Field<T> field, String name, double minStep, double maxStep, double[] vecAbsoluteTolerance, double[] vecRelativeTolerance)
Build an integrator with the given stepsize bounds.
AdaptiveStepsizeFieldIntegrator(Field<T> field, String name, double minStep, double maxStep, double scalAbsoluteTolerance, double scalRelativeTolerance)
Build an integrator with the given stepsize bounds.
• ### Method Summary

All Methods
Modifier and Type Method and Description
protected T filterStep(T h, boolean forward, boolean acceptSmall)
Filter the integration step.
T getMaxStep()
Get the maximal step.
T getMinStep()
Get the minimal step.
T initializeStep(boolean forward, int order, T[] scale, FieldODEStateAndDerivative<T> state0, FieldEquationsMapper<T> mapper)
Initialize the integration step.
protected void resetInternalState()
Reset internal state to dummy values.
protected void sanityChecks(FieldODEState<T> eqn, T t)
Check the integration span.
void setInitialStepSize(T initialStepSize)
Set the initial step size.
void setStepSizeControl(double minimalStep, double maximalStep, double[] absoluteTolerance, double[] relativeTolerance)
Set the adaptive step size control parameters.
void setStepSizeControl(double minimalStep, double maximalStep, double absoluteTolerance, double relativeTolerance)
Set the adaptive step size control parameters.
• ### Methods inherited from class org.apache.commons.math4.ode.AbstractFieldIntegrator

acceptStep, addEventHandler, addEventHandler, addStepHandler, clearEventHandlers, clearStepHandlers, computeDerivatives, getCurrentSignedStepsize, getCurrentStepStart, getEquations, getEvaluations, getEvaluationsCounter, getEventHandlers, getField, getMaxEvaluations, getName, getStepHandlers, getStepSize, getStepStart, initIntegration, isLastStep, resetOccurred, setIsLastStep, setMaxEvaluations, setStateInitialized, setStepSize, setStepStart
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Methods inherited from interface org.apache.commons.math4.ode.FirstOrderFieldIntegrator

integrate
• ### Field Detail

• #### scalAbsoluteTolerance

protected double scalAbsoluteTolerance
Allowed absolute scalar error.
• #### scalRelativeTolerance

protected double scalRelativeTolerance
Allowed relative scalar error.
• #### vecAbsoluteTolerance

protected double[] vecAbsoluteTolerance
Allowed absolute vectorial error.
• #### vecRelativeTolerance

protected double[] vecRelativeTolerance
Allowed relative vectorial error.
• #### mainSetDimension

protected int mainSetDimension
Main set dimension.
• ### Constructor Detail

public AdaptiveStepsizeFieldIntegrator(Field<T> field,
String name,
double minStep,
double maxStep,
double scalAbsoluteTolerance,
double scalRelativeTolerance)
Build an integrator with the given stepsize bounds. The default step handler does nothing.
Parameters:
field - field to which the time and state vector elements belong
name - name of the method
minStep - minimal step (sign is irrelevant, regardless of integration direction, forward or backward), the last step can be smaller than this
maxStep - maximal step (sign is irrelevant, regardless of integration direction, forward or backward), the last step can be smaller than this
scalAbsoluteTolerance - allowed absolute error
scalRelativeTolerance - allowed relative error

public AdaptiveStepsizeFieldIntegrator(Field<T> field,
String name,
double minStep,
double maxStep,
double[] vecAbsoluteTolerance,
double[] vecRelativeTolerance)
Build an integrator with the given stepsize bounds. The default step handler does nothing.
Parameters:
field - field to which the time and state vector elements belong
name - name of the method
minStep - minimal step (sign is irrelevant, regardless of integration direction, forward or backward), the last step can be smaller than this
maxStep - maximal step (sign is irrelevant, regardless of integration direction, forward or backward), the last step can be smaller than this
vecAbsoluteTolerance - allowed absolute error
vecRelativeTolerance - allowed relative error
• ### Method Detail

• #### setStepSizeControl

public void setStepSizeControl(double minimalStep,
double maximalStep,
double absoluteTolerance,
double relativeTolerance)
Set the adaptive step size control parameters.

A side effect of this method is to also reset the initial step so it will be automatically computed by the integrator if setInitialStepSize is not called by the user.

Parameters:
minimalStep - minimal step (must be positive even for backward integration), the last step can be smaller than this
maximalStep - maximal step (must be positive even for backward integration)
absoluteTolerance - allowed absolute error
relativeTolerance - allowed relative error
• #### setStepSizeControl

public void setStepSizeControl(double minimalStep,
double maximalStep,
double[] absoluteTolerance,
double[] relativeTolerance)
Set the adaptive step size control parameters.

A side effect of this method is to also reset the initial step so it will be automatically computed by the integrator if setInitialStepSize is not called by the user.

Parameters:
minimalStep - minimal step (must be positive even for backward integration), the last step can be smaller than this
maximalStep - maximal step (must be positive even for backward integration)
absoluteTolerance - allowed absolute error
relativeTolerance - allowed relative error
• #### setInitialStepSize

public void setInitialStepSize(T initialStepSize)
Set the initial step size.

This method allows the user to specify an initial positive step size instead of letting the integrator guess it by itself. If this method is not called before integration is started, the initial step size will be estimated by the integrator.

Parameters:
initialStepSize - initial step size to use (must be positive even for backward integration ; providing a negative value or a value outside of the min/max step interval will lead the integrator to ignore the value and compute the initial step size by itself)
• #### sanityChecks

protected void sanityChecks(FieldODEState<T> eqn,
T t)
throws DimensionMismatchException,
NumberIsTooSmallException
Check the integration span.
Overrides:
sanityChecks in class AbstractFieldIntegrator<T extends RealFieldElement<T>>
Parameters:
eqn - set of differential equations
t - target time for the integration
Throws:
DimensionMismatchException - if adaptive step size integrators tolerance arrays dimensions are not compatible with equations settings
NumberIsTooSmallException - if integration span is too small
• #### initializeStep

public T initializeStep(boolean forward,
int order,
T[] scale,
FieldODEStateAndDerivative<T> state0,
FieldEquationsMapper<T> mapper)
throws MaxCountExceededException,
DimensionMismatchException
Initialize the integration step.
Parameters:
forward - forward integration indicator
order - order of the method
scale - scaling vector for the state vector (can be shorter than state vector)
state0 - state at integration start time
mapper - mapper for all the equations
Returns:
first integration step
Throws:
MaxCountExceededException - if the number of functions evaluations is exceeded
DimensionMismatchException - if arrays dimensions do not match equations settings
• #### filterStep

protected T filterStep(T h,
boolean forward,
boolean acceptSmall)
throws NumberIsTooSmallException
Filter the integration step.
Parameters:
h - signed step
forward - forward integration indicator
acceptSmall - if true, steps smaller than the minimal value are silently increased up to this value, if false such small steps generate an exception
Returns:
a bounded integration step (h if no bound is reach, or a bounded value)
Throws:
NumberIsTooSmallException - if the step is too small and acceptSmall is false
• #### resetInternalState

protected void resetInternalState()
Reset internal state to dummy values.
• #### getMinStep

public T getMinStep()
Get the minimal step.
Returns:
minimal step
• #### getMaxStep

public T getMaxStep()
Get the maximal step.
Returns:
maximal step