Drake
ScalarInitialValueProblem< T > Class Template Reference

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

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

## Classes

struct  SpecifiedValues
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

ScalarInitialValueProblem (const ScalarODEFunction &scalar_ode_function, const SpecifiedValues &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 SpecifiedValues &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 SpecifiedValues &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>
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 pointer to the internal integrator instance. More...

IntegratorBase< T > * get_mutable_integrator ()
Gets a pointer to the internal mutable integrator instance. More...

Does not allow copy, move, or assignment
ScalarInitialValueProblem (const ScalarInitialValueProblem &)=delete

ScalarInitialValueProblemoperator= (const ScalarInitialValueProblem &)=delete

ScalarInitialValueProblem (ScalarInitialValueProblem &&)=delete

ScalarInitialValueProblemoperator= (ScalarInitialValueProblem &&)=delete

## 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
 T The ℝ domain scalar type, which must be a valid Eigen scalar.
Note
Instantiated templates for the following scalar types T are provided:
• double

## Member Typedef Documentation

 using ScalarODEFunction = std::function& k)>

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

Parameters
 t The independent variable t ∈ ℝ . x The dependent variable x ∈ ℝ . k The parameter vector 𝐤 ∈ ℝᵐ.
Returns
The derivative dx/dt ∈ ℝ.

## Constructor & Destructor Documentation

 ScalarInitialValueProblem ( const ScalarInitialValueProblem< T > & )
delete
 ScalarInitialValueProblem ( ScalarInitialValueProblem< T > && )
delete
 ScalarInitialValueProblem ( const ScalarODEFunction & scalar_ode_function, const SpecifiedValues & default_values )
inline

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_function The ODE function f(t, x; 𝐤) that describes the state evolution over time. default_values The 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::logic_error if preconditions are not met.

## Member Function Documentation

 std::unique_ptr > DenseSolve ( const T & tf, const SpecifiedValues & values = {} ) const
inline

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
 tf The IVP will be solved up to this time. Usually, t₀ < tf as an empty dense output would result if t₀ = tf. values IVP 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::logic_error if any of the preconditions is not met.
 const IntegratorBase* get_integrator ( ) const
inline

Gets a pointer to the internal integrator instance.

 IntegratorBase* get_mutable_integrator ( )
inline

Gets a pointer to the internal mutable integrator instance.

 ScalarInitialValueProblem& operator= ( const ScalarInitialValueProblem< T > & )
delete
 ScalarInitialValueProblem& operator= ( ScalarInitialValueProblem< T > && )
delete
 Integrator* reset_integrator ( Args &&... args )
inline

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
 args The integrator type-specific arguments.
Returns
The new integrator instance.
Template Parameters
 Integrator The integrator type, which must be an IntegratorBase subclass. Args The integrator specific argument types.
Warning
This operation invalidates pointers returned by ScalarInitialValueProblem::get_integrator() and ScalarInitialValueProblem::get_mutable_integrator().
 T Solve ( const T & tf, const SpecifiedValues & values = {} ) const
inline

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
 tf The IVP will be solved for this time. values IVP 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::logic_error if any of the preconditions is not met.

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