Reference documentation for deal.II version 9.4.1
|
#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 |
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\}\).
FiniteSizeHistory< T >::FiniteSizeHistory | ( | const std::size_t | max_elements = 0 | ) |
Constructor.
max_elements | maximum number of elements to be stored in the history. |
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.
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.
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.
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.
std::size_t FiniteSizeHistory< T >::size | ( | ) | const |
Return the current size of the history.
std::size_t FiniteSizeHistory< T >::max_size | ( | ) | const |
Return the maximum allowed size of the history.
void FiniteSizeHistory< T >::clear | ( | ) |
Clear the contents, including the cache.
|
private |
|
private |
|
private |