Dampings< FP, D > Class Template Reference

CPP API: mio::Dampings< FP, D > Class Template Reference

collection of dampings at different time points. More...

#include <damping.h>

Public Types

using const_iterator = typename std::vector< value_type >::const_iterator
 
using const_reference = const value_type &
 
using iterator = typename std::vector< value_type >::iterator
 
using Matrix = typename Shape::Matrix
 
using reference = value_type &
 
using Shape = typename D::Shape
 
using value_type = D
 

Public Member Functions

void add (const value_type &damping)
 add a damping. More...
 
template<class... T>
void add (FP d, T... t)
 
template<class... T>
void add (T &&... t)
 
iterator begin ()
 STL iterators over matrices. More...
 
const_iterator begin () const
 
void clear ()
 remove all dampings. More...
 
 Dampings (std::initializer_list< value_type > il)
 create damping collection. More...
 
template<class... T>
requires std::is_constructible_v< Shape, T... > Dampings (T... shape_args)
 create damping collection. More...
 
iterator end ()
 
const_iterator end () const
 
auto get_matrix_at (SimulationTime< FP > t) const
 Computes the real contact frequency at a point in time. More...
 
size_t get_num_dampings () const
 get the number of matrices. More...
 
Shape get_shape () const
 dimensions of the damping matrix. More...
 
bool operator!= (const Dampings &other) const
 
bool operator== (const Dampings &other) const
 equality operators. More...
 
reference operator[] (size_t i)
 access one damping in this collection. More...
 
const_reference operator[] (size_t i) const
 
void remove (size_t i)
 remove the damping at index i. More...
 
template<class IOContext >
void serialize (IOContext &io) const
 serialize this. More...
 
void set_automatic_cache_update (bool b)
 Disable the internal cache to speed up multiple modifications in a row. More...
 

Static Public Member Functions

template<class IOContext >
static IOResult< Dampingsdeserialize (IOContext &io)
 deserialize an object of this class. More...
 

Private Member Functions

void add_ (const value_type &damping)
 internal add. More...
 
void automatic_cache_update ()
 updates the cache if automatic cache updates are enabled. More...
 
void update_cache ()
 compute the cache of accumulated dampings. More...
 

Static Private Member Functions

template<class Tuple >
static Matrix inclusive_exclusive_sum (const std::vector< Tuple > &v)
 
template<class Iter >
static void inclusive_exclusive_sum_rec (Iter b, Iter e, Matrix &sum)
 e.g. More...
 
static void update_active_dampings (const value_type &damping, std::vector< std::tuple< std::reference_wrapper< const Matrix >, DampingLevel, DampingType >> &active_by_type, std::vector< std::tuple< Matrix, DampingLevel >> &sum_by_level)
 replace matrices of the same type, sum up matrices on the same level. More...
 

Private Attributes

std::vector< std::tuple< Matrix, SimulationTime< FP > > > m_accumulated_dampings_cached
 
bool m_automatic_cache_update = true
 
std::vector< value_typem_dampings
 
Shape m_shape
 

Friends

void PrintTo (const Dampings &self, std::ostream *os)
 GTest printer. More...
 

Detailed Description

template<typename FP, class D>
class mio::Dampings< FP, D >

collection of dampings at different time points.

combination of dampings is computed in the way described at get_matrix_at.

See also
get_matrix_at
Template Parameters
FPFloating point type, e.g., double
Dan instance of Damping template or compatible type.

Member Typedef Documentation

◆ const_iterator

template<typename FP , class D >
using mio::Dampings< FP, D >::const_iterator = typename std::vector<value_type>::const_iterator

◆ const_reference

template<typename FP , class D >
using mio::Dampings< FP, D >::const_reference = const value_type&

◆ iterator

template<typename FP , class D >
using mio::Dampings< FP, D >::iterator = typename std::vector<value_type>::iterator

◆ Matrix

template<typename FP , class D >
using mio::Dampings< FP, D >::Matrix = typename Shape::Matrix

◆ reference

template<typename FP , class D >
using mio::Dampings< FP, D >::reference = value_type&

◆ Shape

template<typename FP , class D >
using mio::Dampings< FP, D >::Shape = typename D::Shape

◆ value_type

template<typename FP , class D >
using mio::Dampings< FP, D >::value_type = D

Constructor & Destructor Documentation

◆ Dampings() [1/2]

template<typename FP , class D >
template<class... T>
requires std::is_constructible_v<Shape, T...> mio::Dampings< FP, D >::Dampings ( T...  shape_args)
inlineexplicit

create damping collection.

Parameters
shape_argsshape constructor arguments.
num_dampingsnumber of initial elements in the collection
Template Parameters
TShape constructor arguments.

◆ Dampings() [2/2]

template<typename FP , class D >
mio::Dampings< FP, D >::Dampings ( std::initializer_list< value_type il)
inline

create damping collection.

Parameters
ilinitializer list of Dampings

Member Function Documentation

◆ add() [1/3]

template<typename FP , class D >
void mio::Dampings< FP, D >::add ( const value_type damping)
inline

add a damping.

Parameters
dampinga Damping

◆ add() [2/3]

template<typename FP , class D >
template<class... T>
void mio::Dampings< FP, D >::add ( FP  d,
T...  t 
)
inline

◆ add() [3/3]

template<typename FP , class D >
template<class... T>
void mio::Dampings< FP, D >::add ( T &&...  t)
inline

◆ add_()

template<typename FP , class D >
void mio::Dampings< FP, D >::add_ ( const value_type damping)
private

internal add.

◆ automatic_cache_update()

template<typename FP , class D >
void mio::Dampings< FP, D >::automatic_cache_update ( )
inlineprivate

updates the cache if automatic cache updates are enabled.

See also
update_cache(), set_automatic_cache_update()

◆ begin() [1/2]

template<typename FP , class D >
iterator mio::Dampings< FP, D >::begin ( )
inline

STL iterators over matrices.

◆ begin() [2/2]

template<typename FP , class D >
const_iterator mio::Dampings< FP, D >::begin ( ) const
inline

◆ clear()

template<typename FP , class D >
void mio::Dampings< FP, D >::clear ( )
inline

remove all dampings.

◆ deserialize()

template<typename FP , class D >
template<class IOContext >
static IOResult<Dampings> mio::Dampings< FP, D >::deserialize ( IOContext &  io)
inlinestatic

deserialize an object of this class.

See also
mio::deserialize

◆ end() [1/2]

template<typename FP , class D >
iterator mio::Dampings< FP, D >::end ( )
inline

◆ end() [2/2]

template<typename FP , class D >
const_iterator mio::Dampings< FP, D >::end ( ) const
inline

◆ get_matrix_at()

template<typename FP , class D >
auto mio::Dampings< FP, D >::get_matrix_at ( SimulationTime< FP >  t) const
inline

Computes the real contact frequency at a point in time.

Combines the dampings that are active at a point in time according to type and level rules. Dampings on different levels apply "multiplicatively". Dampings on the same level apply additively. e.g. Two dampings a and b on different levels combine to (1 - (1 - a)(1 - b)) or (a + b - ab). Two dampings a and b on the same level combine to (a + b).

Transitions between different contact frequencies are smoothed out over one day to avoid discontinuities. Uses lazy evaluation, coefficients are calculated on indexed access.

Parameters
ttime in the simulation
Returns
matrix expression

◆ get_num_dampings()

template<typename FP , class D >
size_t mio::Dampings< FP, D >::get_num_dampings ( ) const
inline

get the number of matrices.

◆ get_shape()

template<typename FP , class D >
Shape mio::Dampings< FP, D >::get_shape ( ) const
inline

dimensions of the damping matrix.

◆ inclusive_exclusive_sum()

template<typename FP , class D >
template<class Tuple >
static Matrix mio::Dampings< FP, D >::inclusive_exclusive_sum ( const std::vector< Tuple > &  v)
inlinestaticprivate

◆ inclusive_exclusive_sum_rec()

template<typename FP , class D >
template<class Iter >
static void mio::Dampings< FP, D >::inclusive_exclusive_sum_rec ( Iter  b,
Iter  e,
Matrix sum 
)
inlinestaticprivate

e.g.

inclusive_exclusive_sum({A, B, C}) = A + B + C - AB - BC - AC + ABC equal to but more efficient than 1 - (1 - A)(1 - B)(1 - C))

◆ operator!=()

template<typename FP , class D >
bool mio::Dampings< FP, D >::operator!= ( const Dampings< FP, D > &  other) const
inline

◆ operator==()

template<typename FP , class D >
bool mio::Dampings< FP, D >::operator== ( const Dampings< FP, D > &  other) const
inline

equality operators.

◆ operator[]() [1/2]

template<typename FP , class D >
reference mio::Dampings< FP, D >::operator[] ( size_t  i)
inline

access one damping in this collection.

◆ operator[]() [2/2]

template<typename FP , class D >
const_reference mio::Dampings< FP, D >::operator[] ( size_t  i) const
inline

◆ remove()

template<typename FP , class D >
void mio::Dampings< FP, D >::remove ( size_t  i)
inline

remove the damping at index i.

◆ serialize()

template<typename FP , class D >
template<class IOContext >
void mio::Dampings< FP, D >::serialize ( IOContext &  io) const
inline

serialize this.

See also
mio::serialize

◆ set_automatic_cache_update()

template<typename FP , class D >
void mio::Dampings< FP, D >::set_automatic_cache_update ( bool  b)
inline

Disable the internal cache to speed up multiple modifications in a row.

This class has an internal cache where all dampings are combined into a single time series of matrices for faster lookup. By default, the cache is automatically updated when dampings are added or removed, but this can be expensive. This function can be used to disable the cache so that add() or remove() can be called multiple times in a row more efficiently. Afterwards, the cache needs to be reenabled.

Parameters
bTrue if cache updates are enabled.

◆ update_active_dampings()

template<typename FP , class S >
void mio::Dampings< FP, S >::update_active_dampings ( const value_type damping,
std::vector< std::tuple< std::reference_wrapper< const Matrix >, DampingLevel, DampingType >> &  active_by_type,
std::vector< std::tuple< Matrix, DampingLevel >> &  sum_by_level 
)
staticprivate

replace matrices of the same type, sum up matrices on the same level.

add new types/levels if necessary.

◆ update_cache()

template<typename FP , class D >
void mio::Dampings< FP, D >::update_cache
private

compute the cache of accumulated dampings.

if this is used after adding dampings, all subsequent calls to get_matrix_at() are quick and threadsafe. Otherwise the cache is updated automatically on the first call.

Friends And Related Function Documentation

◆ PrintTo

template<typename FP , class D >
void PrintTo ( const Dampings< FP, D > &  self,
std::ostream *  os 
)
friend

GTest printer.

Member Data Documentation

◆ m_accumulated_dampings_cached

template<typename FP , class D >
std::vector<std::tuple<Matrix, SimulationTime<FP> > > mio::Dampings< FP, D >::m_accumulated_dampings_cached
private

◆ m_automatic_cache_update

template<typename FP , class D >
bool mio::Dampings< FP, D >::m_automatic_cache_update = true
private

◆ m_dampings

template<typename FP , class D >
std::vector<value_type> mio::Dampings< FP, D >::m_dampings
private

◆ m_shape

template<typename FP , class D >
Shape mio::Dampings< FP, D >::m_shape
private