PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
|
BDF (Backward Differentiation Formula) time integration scheme for a system of ODEs for an initial value problem (IVP) More...
#include <Bdf.h>
Public Types | |
using | ScalarType = TScalar |
Floating point scalar type. | |
using | IndexType = TIndex |
Integer index type. | |
Public Member Functions | |
Bdf (int step=1, int order=2) | |
Construct a step -step BDF (backward differentiation formula) time integration scheme for a system of ODEs (ordinary differential equation) of order order . | |
auto | Order () const |
Order of the ODE. | |
auto | Step () const |
Step s of the s -step BDF scheme. | |
auto | Dimensions () const |
Number of ODEs. | |
auto | TimeStep () const |
Time step size. | |
auto | Inertia (int o) const |
Inertia of the BDF scheme for the \( o^\text{th} \) state derivative. | |
auto | State (int k, int o=0) const -> decltype(xt.col(0)) |
\( o^\text{th} \) state derivative | |
auto | State (int k, int o=0) -> decltype(xt.col(0)) |
\( o^\text{th} \) state derivative | |
auto | CurrentState (int o=0) const -> decltype(xt.col(0)) |
Current state derivative. | |
auto | CurrentState (int o=0) -> decltype(xt.col(0)) |
Current state derivative. | |
auto | Alpha () const |
Interpolation coefficients \( \alpha_k \) except \( \alpha_s \). | |
auto | Beta () const |
Forcing term coefficient \( \beta \) s.t. \( \tilde{\beta} = h \beta \). | |
auto | BetaTilde () const |
Time-step scaled forcing term coefficient \( \tilde{\beta} = h \beta \). | |
void | SetOrder (int order) |
Set the order of the ODE system. | |
void | SetStep (int step) |
Set the step of the BDF scheme. | |
void | SetTimeStep (ScalarType dt) |
Set the time step size. | |
void | ConstructEquations () |
Construct the BDF equations, i.e. compute \( \tilde{x^{(o)}} = \sum_{k=0}^{s-1}
\alpha_k x^{(o)}_{t_i - s + k} \) for all \( o = 0, ..., \text{order}-1 \). | |
template<class TDerivedX> | |
void | SetInitialConditions (Eigen::DenseBase< TDerivedX > const &x0) |
Set the initial conditions for the initial value problem. | |
template<class... TDerivedX> | |
void | SetInitialConditions (Eigen::DenseBase< TDerivedX > const &... x0) |
Set the initial conditions for the initial value problem. | |
template<class TDerivedX> | |
void | Step (Eigen::DenseBase< TDerivedX > const &x) |
Advance the BDF scheme by one time step. | |
template<class... TDerivedX> | |
void | Step (Eigen::DenseBase< TDerivedX > const &... xs) |
Advance the BDF scheme by one time step. | |
void | Tick () |
Advance the BDF scheme by one time step. | |
void | Serialize (io::Archive &archive) const |
Serialize to HDF5 group. | |
void | Deserialize (io::Archive const &archive) |
Deserialize from HDF5 group. | |
Public Attributes | |
Eigen::Matrix< ScalarType, Eigen::Dynamic, Eigen::Dynamic > | xt |
Eigen::Matrix< ScalarType, Eigen::Dynamic, Eigen::Dynamic > | xtilde |
IndexType | ti |
Current time index s.t. \(t = t_0 + h t_i\). | |
ScalarType | h |
Time step size \( h \). | |
BDF (Backward Differentiation Formula) time integration scheme for a system of ODEs for an initial value problem (IVP)
Refer to background here.
An order \( p \) system of ODEs \( x^{(p)} = f(t, \frac{d^{p-1}}{dt^{p-1}} x, \dots, x) \) can be transformed into a system of \( p \) first-order ODEs using slack variables \( x^{(o)} = \frac{d^o}{dt^o} x \) for \( o = 0, \dots, p-1 \), such that the IVP can be rewritten as
\[ \begin{align*} \frac{d}{dt} x_{p-1} &= f(t, x^{(p-1)}, \dots, x^{(o)}) \\ \frac{d}{dt} x^{(p-j)} &= x^{(p-j+1)}, \quad j = 2, \dots, p \end{align*} . \]
Since BDF discretizes each equation as \( \sum_{k=0}^s \alpha_k x_{n-s+k} = h \beta f(t, x_n^{(p-1)}, \dots, x_n) \), we have that
\[ \begin{align*} x^{(p-1)}_n + \tilde{x}^{(p-1)}_\text{BDFS} - \tilde{\beta}_\text{BDFS} f(t, x_n^{(p-1)}, \dots, x_n) &= 0 \\ x^{(o)}_n + \tilde{x}^{(o)}_\text{BDFS} - \tilde{\beta}_\text{BDFS} x^{(o+1)}_n &= 0 \end{align*} \]
for \( o=0,\dots,p-2 \), where \( \tilde{\beta} = h \beta \) and \( n \) is the next time step index.
One performs time integration by solving for the states and their derivatives \( x_n^{(o)} \) for \( o=0,\dots,p-1 \) at each time step using root-finding of the above equations. Alternatively, the root-finding equations can be treated as stationarity conditions \( \nabla f = 0 \) for some objective function \( f \), and solved via numerical optimization of \( f \).
This class encapsulates the storage of the past states and their lower order derivatives \( x_{n-s+k}^{(o)} \), the construction of so-called inertias \( \tilde{x}^{(o)}_\text{BDFS} \), the interpolation coefficients \( \alpha_k \), forcing term coefficient \( \beta \) and generalize the BDF scheme to various ODE systems of different orders. Specific ODEs are then entirely defined by the forcing function \( f(t, \frac{d^{p-1}}{dt^{p-1}} x, \dots, x) \), and it is up to the user to derive their specific equations to solve.
pbat::sim::integration::Bdf< TScalar, TIndex >::Bdf | ( | int | step = 1, |
int | order = 2 ) |
Construct a step
-step BDF (backward differentiation formula) time integration scheme for a system of ODEs (ordinary differential equation) of order order
.
step | 0 < s < 7 backward differentiation scheme |
order | order > 0 order of the ODE |
0 < step < 7
order > 0
|
inline |
Interpolation coefficients \( \alpha_k \) except \( \alpha_s \).
s x 1
vector of interpolation coefficients \( \alpha_k \)
|
inline |
Forcing term coefficient \( \beta \) s.t. \( \tilde{\beta} = h \beta \).
|
inline |
Time-step scaled forcing term coefficient \( \tilde{\beta} = h \beta \).
auto pbat::sim::integration::Bdf< TScalar, TIndex >::CurrentState | ( | int | o = 0 | ) | -> decltype(xt.col(0)) |
Current state derivative.
o | Order of the state derivative \( o = 0, ..., \text{order}-1 \) |
n x 1
current state derivative vector \( x^{(o)}_{t_i} \) auto pbat::sim::integration::Bdf< TScalar, TIndex >::CurrentState | ( | int | o = 0 | ) | const -> decltype(xt.col(0)) |
Current state derivative.
o | Order of the state derivative \( o = 0, ..., \text{order}-1 \) |
n x 1
current state derivative vector \( x^{(o)}_{t_i} \) void pbat::sim::integration::Bdf< TScalar, TIndex >::Deserialize | ( | io::Archive const & | archive | ) |
Deserialize from HDF5 group.
archive | Archive to deserialize from |
|
inline |
Number of ODEs.
|
inline |
Inertia of the BDF scheme for the \( o^\text{th} \) state derivative.
o | Order of the state derivative \( o = 0, ..., \text{order}-1 \) |
n x 1
inertia vector for the \( o^\text{th} \) state derivative
|
inline |
Order of the ODE.
void pbat::sim::integration::Bdf< TScalar, TIndex >::Serialize | ( | io::Archive & | archive | ) | const |
Serialize to HDF5 group.
archive | Archive to serialize to |
|
inline |
Set the initial conditions for the initial value problem.
x0 | order vectors of n x 1 initial conditions \( x^{(o)}_{t_0} \) |
sizeof...(TDerivedX) == order
ti == 0
|
inline |
Set the initial conditions for the initial value problem.
x0 | n x order matrix of initial conditions s.t. x0.col(o) = \f$ x^{(o)}_{t_0} \f$ for \( o = 0, ..., \text{order}-1 \) |
x0.cols() == order
ti == 0
void pbat::sim::integration::Bdf< TScalar, TIndex >::SetOrder | ( | int | order | ) |
Set the order of the ODE system.
order | Order of the ODE system \( \text{order} > 0 \) |
order > 0
void pbat::sim::integration::Bdf< TScalar, TIndex >::SetStep | ( | int | step | ) |
Set the step of the BDF scheme.
step | Step of the BDF scheme \( 0 < s < 7 \) |
0 < step < 7
void pbat::sim::integration::Bdf< TScalar, TIndex >::SetTimeStep | ( | ScalarType | dt | ) |
Set the time step size.
dt | Time step size \( dt > 0 \) |
dt > 0
auto pbat::sim::integration::Bdf< TScalar, TIndex >::State | ( | int | k, |
int | o = 0 ) -> decltype(xt.col(0)) |
\( o^\text{th} \) state derivative
k | State index \( k = 0, ..., s \) for the vector \( x^{(o)}_{t_i - s + k} \) |
o | Order of the state derivative \( o = 0, ..., \text{order}-1 \) |
n x 1
state derivative vector \( x^{(o)}_{t_i - s + k} \) auto pbat::sim::integration::Bdf< TScalar, TIndex >::State | ( | int | k, |
int | o = 0 ) const -> decltype(xt.col(0)) |
\( o^\text{th} \) state derivative
k | State index \( k = 0, ..., s \) for the vector \( x^{(o)}_{t_i - s + k} \) |
o | Order of the state derivative \( o = 0, ..., \text{order}-1 \) |
n x 1
state derivative vector \( x^{(o)}_{t_i - s + k} \)
|
inline |
Step s
of the s
-step BDF scheme.
s
of the s
-step BDF scheme
|
inline |
Advance the BDF scheme by one time step.
TDerivedX | Derived type of the input matrix |
xs | order vectors of n x 1 current state derivatives \( x_{t_i}^{(o)} \) |
sizeof...(TDerivedX) == order
|
inline |
Advance the BDF scheme by one time step.
TDerivedX | Derived type of the input matrix |
x | n x order matrix of the current state derivatives \( x_{t_i}^{(o)} \) |
|
inline |
Time step size.
Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic> pbat::sim::integration::Bdf< TScalar, TIndex >::xt |
n x |s*order|
matrix of n
-dimensional states and their time derivatives s.t. \( xt.col(o*s + k) = x^(k)(t - k*dt) \) for \( k = 0, ..., s \) and \( o = 0, ..., \text{order}-1 \)
Eigen::Matrix<ScalarType, Eigen::Dynamic, Eigen::Dynamic> pbat::sim::integration::Bdf< TScalar, TIndex >::xtilde |
n x order
matrix of n
-dimensional aggregated past states and time derivatives s.t. xtilde.col(o) = \( \frac{1}{\alpha_s} \sum_{k=t_i-s}^{s-1}
< \alpha_k x_k \) for \( o = 0, ..., \text{order}-1 \)