Drake
Drake C++ Documentation
ScalarInitialValueProblem< T > Class Template Reference

Detailed Description

template<typename T>
class drake::systems::ScalarInitialValueProblem< T >

A thin wrapper of the InitialValueProblem class to provide a simple interface when solving scalar initial value problems i.e.

when evaluating the x(t; 𝐀) solution function to the given ODE dx/dt = f(t, x; 𝐀), where f : t β¨― x β†’ ℝ , t ∈ ℝ, x ∈ ℝ, 𝐀 ∈ ℝᡐ, along with an initial condition x(tβ‚€; 𝐀) = xβ‚€. The parameter vector 𝐀 allows for generic IVP definitions, which can later be solved for any instance of said vector.

Note the distinction from general initial value problems where f : t β¨― 𝐱 β†’ ℝⁿ and 𝐱 ∈ ℝⁿ, addressed by the class being wrapped. While every scalar initial value problem could be written in vector form, this wrapper keeps both problem definition and solution in their scalar form with almost zero overhead, leading to clearer code if applicable. Moreover, this scalar form facilitates single-dimensional quadrature using methods for solving initial value problems.

See InitialValueProblem class documentation for information on caching support and dense output usage for improved efficiency in scalar IVP solving.

For further insight into its use, consider the following examples of scalar IVPs:

  • The population growth of an hypothetical bacteria colony is described by dN/dt = r * N. The colony has Nβ‚€ subjects at time tβ‚€. In this context, x β‰œ N, xβ‚€ β‰œ Nβ‚€, 𝐀 β‰œ [r], dx/dt = f(t, x; 𝐀) = 𝐀₁ * x.
  • The charge Q stored in the capacitor of a (potentially equivalent) series RC circuit driven by a time varying voltage source E(t) can be described by dQ/dt = (E(t) - Q / Cs) / Rs, where Rs refers to the resistor's resistance and Cs refers to the capacitor's capacitance. In this context, and assuming an initial stored charge Qβ‚€ at time tβ‚€, x β‰œ Q, 𝐀 β‰œ [Rs, Cs], xβ‚€ β‰œ Qβ‚€, dx/dt = f(t, x; 𝐀) = (E(t) - x / 𝐀₂) / 𝐀₁.
Template Parameters
TThe scalar type, which must be one of the default nonsymbolic scalars.

#include <drake/systems/analysis/scalar_initial_value_problem.h>

Public Types

using ScalarOdeFunction = std::function< T(const T &t, const T &x, const VectorX< T > &k)>
 Scalar ODE dx/dt = f(t, x; 𝐀) function type. More...
 

Public Member Functions

 ScalarInitialValueProblem (const ScalarOdeFunction &scalar_ode_function, const T &x0, const Eigen::Ref< const VectorX< T >> &k=Vector0< T >{})
 Constructs a scalar IVP described by the given scalar_ode_function, using given x0 as initial conditions, and parameterized with k. More...
 
Solve (const T &t0, const T &tf) const
 Solves the IVP from time t0 up to time tf, using the initial state 𝐱₀ and parameter vector 𝐀 provided in the constructor. More...
 
std::unique_ptr< ScalarDenseOutput< 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 initial time t0 and the final time tf, using initial state 𝐱₀ and parameter vector 𝐀 provided in the constructor. More...
 
template<typename Integrator , typename... Args>
Integratorreset_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
 ScalarInitialValueProblem (const ScalarInitialValueProblem &)=delete
 
ScalarInitialValueProblemoperator= (const ScalarInitialValueProblem &)=delete
 
 ScalarInitialValueProblem (ScalarInitialValueProblem &&)=delete
 
ScalarInitialValueProblemoperator= (ScalarInitialValueProblem &&)=delete
 

Member Typedef Documentation

◆ ScalarOdeFunction

using ScalarOdeFunction = std::function<T(const T& t, const T& x, const VectorX<T>& k)>

Scalar ODE dx/dt = f(t, x; 𝐀) function type.

Parameters
tThe independent variable t ∈ ℝ .
xThe dependent variable x ∈ ℝ .
kThe parameter vector 𝐀 ∈ ℝᡐ.
Returns
The derivative dx/dt ∈ ℝ.

Constructor & Destructor Documentation

◆ ScalarInitialValueProblem() [1/3]

◆ ScalarInitialValueProblem() [2/3]

◆ ScalarInitialValueProblem() [3/3]

ScalarInitialValueProblem ( const ScalarOdeFunction scalar_ode_function,
const T &  x0,
const Eigen::Ref< const VectorX< T >> &  k = Vector0< T >{} 
)

Constructs a scalar IVP described by the given scalar_ode_function, using given x0 as initial conditions, and parameterized with k.

Parameters
scalar_ode_functionThe ODE function f(t, 𝐱; 𝐀) that describes the state evolution over time.
x0The initial state 𝐱₀ ∈ ℝ.
kThe parameter vector 𝐀 ∈ ℝᡐ. By default m=0 (no parameters).

Member Function Documentation

◆ DenseSolve()

std::unique_ptr<ScalarDenseOutput<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 initial time t0 and the 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 𝐱₀ = 𝐱(t0) to tf and 𝐱(tf), creating a dense output over that [t0, tf] interval along the way.

Parameters
tfThe IVP will be solved up to this time, which must be β‰₯ t0. Usually, t0 < tf as an empty dense output would result if t0 = tf.
Returns
A dense approximation to 𝐱(t; 𝐀) with 𝐱(t0; 𝐀) = 𝐱₀, defined for t0 ≀ t ≀ tf.
Note
The larger the given 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.
Exceptions
std::exceptionif t0 > tf.

◆ get_integrator()

const IntegratorBase<T>& get_integrator ( ) const

Gets a reference to the internal integrator instance.

◆ get_mutable_integrator()

IntegratorBase<T>& get_mutable_integrator ( )

Gets a mutable reference to the internal integrator instance.

◆ operator=() [1/2]

ScalarInitialValueProblem& operator= ( const ScalarInitialValueProblem< T > &  )
delete

◆ operator=() [2/2]

ScalarInitialValueProblem& operator= ( ScalarInitialValueProblem< T > &&  )
delete

◆ reset_integrator()

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.

scalar_ivp.reset_integrator<RungeKutta2Integrator<T>>(max_step);
Parameters
argsThe integrator type-specific arguments.
Returns
The new integrator instance.
Template Parameters
IntegratorThe integrator type, which must be an IntegratorBase subclass.
ArgsThe integrator specific argument types.
Warning
This operation invalidates pointers returned by ScalarInitialValueProblem::get_integrator() and ScalarInitialValueProblem::get_mutable_integrator().

◆ Solve()

T Solve ( const T &  t0,
const T &  tf 
) const

Solves the IVP from time t0 up to time tf, using the initial state 𝐱₀ and parameter vector 𝐀 provided in the constructor.

Exceptions
std::exceptionif t0 > tf.

The documentation for this class was generated from the following file: