maliput
ScalarInitialValueProblem< T > Class Template Reference

Detailed Description

template<typename T>
class maliput::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 / ๐คโ‚‚) / ๐คโ‚.

@tparam_nonsymbolic_scalar

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

Classes

struct  ScalarOdeContext
 A collection of values i.e. More...
 

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

 DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN (ScalarInitialValueProblem)
 
 ScalarInitialValueProblem (const ScalarOdeFunction &scalar_ode_function, const ScalarOdeContext &default_values)
 Constructs an scalar IVP described by the given scalar_ode_function, using given default_values.t0 and default_values.x0 as initial conditions, and parameterized with default_values.k by default. More...
 
Solve (const T &tf, const ScalarOdeContext &values={}) const
 Solves the IVP for time tf, using the initial time tโ‚€, initial state xโ‚€ and parameter vector ๐ค present in values, falling back to the ones given on construction if not given. More...
 
std::unique_ptr< ScalarDenseOutput< T > > DenseSolve (const T &tf, const ScalarOdeContext &values={}) const
 Solves and yields an approximation of the IVP solution x(t; ๐ค) for the closed time interval between the initial time tโ‚€ and the given final time tf, using initial state xโ‚€ and parameter vector ๐ค present in values (falling back to the ones given on construction if not given). 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...
 

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()

ScalarInitialValueProblem ( const ScalarOdeFunction scalar_ode_function,
const ScalarOdeContext default_values 
)

Constructs an scalar IVP described by the given scalar_ode_function, using given default_values.t0 and default_values.x0 as initial conditions, and parameterized with default_values.k by default.

Parameters
scalar_ode_functionThe ODE function f(t, x; ๐ค) that describes the state evolution over time.
default_valuesThe values specified by default for this IVP, i.e. default initial time tโ‚€ โˆˆ โ„ and state xโ‚€ โˆˆ โ„, and default parameter vector ๐ค โˆˆ โ„แต.
Precondition
An initial time default_values.t0 is provided.
An initial state default_values.x0 is provided.
An parameter vector default_values.k is provided.
Exceptions
std::exceptionif preconditions are not met.

Member Function Documentation

◆ DenseSolve()

std::unique_ptr<ScalarDenseOutput<T> > DenseSolve ( const T &  tf,
const ScalarOdeContext values = {} 
) const

Solves and yields an approximation of the IVP solution x(t; ๐ค) for the closed time interval between the initial time tโ‚€ and the given final time tf, using initial state xโ‚€ and parameter vector ๐ค present in values (falling back to the ones given on construction if not given).

To this end, the wrapped IntegratorBase instance solves this scalar IVP, advancing time and state from tโ‚€ and xโ‚€ = x(tโ‚€) to tf and x(tf), creating a scalar dense output over that [tโ‚€, tf] interval along the way.

Parameters
tfThe IVP will be solved up to this time. Usually, tโ‚€ < tf as an empty dense output would result if tโ‚€ = tf.
valuesIVP initial conditions and parameters.
Returns
A dense approximation to x(t; ๐ค) with x(tโ‚€; ๐ค) = xโ‚€, defined for tโ‚€ โ‰ค 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.
Precondition
Given tf must be larger than or equal to the specified initial time tโ‚€ (either given or default).
If given, the dimension of the initial state vector values.x0 must match that of the default initial state vector in the default specified values given on construction.
If given, the dimension of the parameter vector values.k must match that of the parameter vector in the default specified values given on construction.
Exceptions
std::exceptionif any of the preconditions is not met.

◆ DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN()

DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN ( ScalarInitialValueProblem< T >  )

◆ 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.

◆ 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 &  tf,
const ScalarOdeContext values = {} 
) const

Solves the IVP for time tf, using the initial time tโ‚€, initial state xโ‚€ and parameter vector ๐ค present in values, falling back to the ones given on construction if not given.

Parameters
tfThe IVP will be solved for this time.
valuesIVP initial conditions and parameters.
Returns
The IVP solution x(tf; ๐ค) for x(tโ‚€; ๐ค) = xโ‚€.
Precondition
Given tf must be larger than or equal to the specified initial time tโ‚€ (either given or default).
If given, the dimension of the parameter vector values.k must match that of the parameter vector in the default specified values given on construction.
Exceptions
std::exceptionif any of the preconditions is not met.

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