Reference documentation for deal.II version 9.6.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
FiniteSizeHistory< T > Class Template Reference

#include <deal.II/numerics/history.h>

Public Member Functions

 FiniteSizeHistory (const std::size_t max_elements=0)
 
void add (const T &element)
 
void remove (const std::size_t index)
 
T & operator[] (const std::size_t index)
 
const T & operator[] (const std::size_t index) const
 
std::size_t size () const
 
std::size_t max_size () const
 
void clear ()
 

Private Attributes

std::size_t max_n_elements
 
std::deque< std::unique_ptr< T > > data
 
std::deque< std::unique_ptr< T > > cache
 

Detailed Description

template<typename T>
class FiniteSizeHistory< T >

A helper class to store a finite-size collection of objects of type T. If the number of elements exceeds the specified maximum size of the container, the oldest element is removed. Additionally, random access and removal of elements is implemented. Indexing is done relative to the last added element.

In order to optimize the container for usage with memory-demanding objects (i.e. linear algebra vectors), the removal of an element does not free the memory. Instead the element is being kept in a separate cache so that subsequent addition does not require re-allocation of memory.

The primary usage of this class is in solvers to store a history of vectors. That is, if at the iteration \(k\) we store \(m\) vectors from previous iterations \(\{k-1,k-2,...,k-m\}\), then addition of the new element will make the object contain elements from iterations \(\{k,k-1,k-2,...,k-m+1\}\).

Definition at line 48 of file history.h.

Constructor & Destructor Documentation

◆ FiniteSizeHistory()

template<typename T >
FiniteSizeHistory< T >::FiniteSizeHistory ( const std::size_t max_elements = 0)

Constructor.

Parameters
max_elementsmaximum number of elements to be stored in the history.

Member Function Documentation

◆ add()

template<typename T >
void FiniteSizeHistory< T >::add ( const T & element)

Add new object by copying. If the maximum number of elements is reached, the oldest element is removed.

◆ remove()

template<typename T >
void FiniteSizeHistory< T >::remove ( const std::size_t index)

Remove an element with index index, counting from the last added element. index==0 therefore corresponds to removing the newset element.

◆ operator[]() [1/2]

template<typename T >
T & FiniteSizeHistory< T >::operator[] ( const std::size_t index)

Read/write access to an element with index index, counting from the last added element. index==0 therefore corresponds to the newset element.

◆ operator[]() [2/2]

template<typename T >
const T & FiniteSizeHistory< T >::operator[] ( const std::size_t index) const

Read access to an element with index index, counting from the last added element. index==0 therefore corresponds to the newset element.

◆ size()

template<typename T >
std::size_t FiniteSizeHistory< T >::size ( ) const

Return the current size of the history.

◆ max_size()

template<typename T >
std::size_t FiniteSizeHistory< T >::max_size ( ) const

Return the maximum allowed size of the history.

◆ clear()

template<typename T >
void FiniteSizeHistory< T >::clear ( )

Clear the contents, including the cache.

Member Data Documentation

◆ max_n_elements

template<typename T >
std::size_t FiniteSizeHistory< T >::max_n_elements
private

Maximum number of elements to be stored.

Definition at line 118 of file history.h.

◆ data

template<typename T >
std::deque<std::unique_ptr<T> > FiniteSizeHistory< T >::data
private

A deque which stores the data.

Definition at line 123 of file history.h.

◆ cache

template<typename T >
std::deque<std::unique_ptr<T> > FiniteSizeHistory< T >::cache
private

A deque to cache data, in particular for the case when removal is followed by addition.

Definition at line 129 of file history.h.


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