A general initial value problem (or IVP) representation class, that allows evaluating the π±(t; π€) solution function to the given ODE dπ±/dt = f(t, π±; π€), where f : t β¨― π± β ββΏ, t β β, π± β ββΏ, π€ β βα΅, provided an initial condition π±(tβ; π€) = π±β.
The parameter vector π€ allows for generic IVP definitions, which can later be solved for any instance of said vector.
By default, an explicit 3rd order RungeKutta integration scheme is used.
The implementation of this class performs basic computation caching, optimizing away repeated integration whenever the IVP is solved for increasing values of time t while both initial conditions and parameters are kept constant, e.g. if solved for tβ > tβ first, solving for tβ > tβ will only require integrating from tβ onward.
Additionally, IntegratorBase's dense output support can be leveraged to efficiently approximate the IVP solution within closed intervals of t. This is convenient when there's a need for a more dense sampling of the IVP solution than what would be available through either fixed or error-controlled step integration (for a given accuracy), or when the IVP is to be solved repeatedly for arbitrarily many t values within a given interval. See documentation of the internally held IntegratorBase subclass instance (either the default or a user-defined one, set via reset_integrator()) for further reference on the specific dense output technique in use.
For further insight into its use, consider the following examples:
T | The scalar type, which must be one of the default nonsymbolic scalars. |
#include <drake/systems/analysis/initial_value_problem.h>
Public Types | |
using | OdeFunction = std::function< VectorX< T >(const T &t, const VectorX< T > &x, const VectorX< T > &k)> |
General ODE system dπ±/dt = f(t, π±; π€) function type. More... | |
Public Member Functions | |
InitialValueProblem (const OdeFunction &ode_function, const Eigen::Ref< const VectorX< T >> &x0, const Eigen::Ref< const VectorX< T >> &k=Vector0< T >{}) | |
Constructs an IVP described by the given ode_function , using x0 as initial conditions, and parameterized with k . More... | |
VectorX< T > | Solve (const T &t0, const T &tf) const |
Solves the IVP from the initial time t0 up to time tf , using the initial state vector π±β and parameter vector π€ provided in the constructor. More... | |
std::unique_ptr< DenseOutput< T > > | DenseSolve (const T &t0, const T &tf) const |
Solves and yields an approximation of the IVP solution x(t; π€) for the closed time interval between the given initial time t0 and the given final time tf , using initial state π±β and parameter vector π€ provided in the constructor. More... | |
template<typename Integrator , typename... Args> | |
Integrator * | reset_integrator (Args &&... args) |
Resets the internal integrator instance by in-place construction of the given integrator type. More... | |
const IntegratorBase< T > & | get_integrator () const |
Gets a reference to the internal integrator instance. More... | |
IntegratorBase< T > & | get_mutable_integrator () |
Gets a mutable reference to the internal integrator instance. More... | |
Does not allow copy, move, or assignment | |
InitialValueProblem (const InitialValueProblem &)=delete | |
InitialValueProblem & | operator= (const InitialValueProblem &)=delete |
InitialValueProblem (InitialValueProblem &&)=delete | |
InitialValueProblem & | operator= (InitialValueProblem &&)=delete |
Static Public Attributes | |
static const double | kDefaultAccuracy |
Default integration accuracy in the relative tolerance sense. More... | |
static const double | kInitialStepSize |
Default initial integration step size. More... | |
static const double | kMaxStepSize |
Default maximum integration step size. More... | |
using OdeFunction = std::function<VectorX<T>(const T& t, const VectorX<T>& x, const VectorX<T>& k)> |
General ODE system dπ±/dt = f(t, π±; π€) function type.
t | The independent scalar variable t β β. |
x | The dependent vector variable π± β ββΏ. |
k | The vector of parameters π€ β βα΅. |
|
delete |
|
delete |
InitialValueProblem | ( | const OdeFunction & | ode_function, |
const Eigen::Ref< const VectorX< T >> & | x0, | ||
const Eigen::Ref< const VectorX< T >> & | k = Vector0< T >{} |
||
) |
Constructs an IVP described by the given ode_function
, using x0
as initial conditions, and parameterized with k
.
ode_function | The ODE function f(t, π±; π€) that describes the state evolution over time. |
x0 | The initial state vector π±β β ββΏ. |
k | The parameter vector π€ β βα΅. By default m=0 (no parameters). |
std::unique_ptr<DenseOutput<T> > DenseSolve | ( | const T & | t0, |
const T & | tf | ||
) | const |
Solves and yields an approximation of the IVP solution x(t; π€) for the closed time interval between the given initial time t0
and the given final time tf
, using initial state π±β and parameter vector π€ provided in the constructor.
To this end, the wrapped IntegratorBase instance solves this IVP, advancing time and state from tβ and π±β = π±(tβ) to tf
and π±(tf
), creating a dense output over that [tβ, tf
] interval along the way.
tf | The IVP will be solved up to this time, which must be β₯ tβ. Usually, tβ < tf as an empty dense output would result if tβ = tf . |
tf
value is, the larger the approximated interval will be. See documentation of the specific dense output technique in use for reference on performance impact as this interval grows. std::exception | if t0 > tf. |
const IntegratorBase<T>& get_integrator | ( | ) | const |
Gets a reference to the internal integrator instance.
IntegratorBase<T>& get_mutable_integrator | ( | ) |
Gets a mutable reference to the internal integrator instance.
|
delete |
|
delete |
Integrator* reset_integrator | ( | Args &&... | args | ) |
Resets the internal integrator instance by in-place construction of the given integrator type.
A usage example is shown below.
args | The integrator type-specific arguments. |
Integrator | The integrator type, which must be an IntegratorBase subclass. |
Args | The integrator specific argument types. |
VectorX<T> Solve | ( | const T & | t0, |
const T & | tf | ||
) | const |
Solves the IVP from the initial time t0
up to time tf
, using the initial state vector π±β and parameter vector π€ provided in the constructor.
std::exception | if t0 > tf. |
|
static |
Default integration accuracy in the relative tolerance sense.
|
static |
Default initial integration step size.
|
static |
Default maximum integration step size.