Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Density_Observer< State > Class Template Reference

Records the count of cells in tracked_state per step. More...

#include <ca-observer.H>

Collaboration diagram for Aleph::CA::Density_Observer< State >:
[legend]

Public Member Functions

 Density_Observer ()=default
 Construct an observer that tracks State{}.
 
 Density_Observer (State s)
 Construct an observer tracking a specific state.
 
 Density_Observer (const Density_Observer &other)=default
 Copy another observer: the state that it counts, the counts of each step, their totals, and whether it has seen a frame.
 
 Density_Observer (Density_Observer &&other) noexcept(std::is_nothrow_copy_constructible_v< State >)
 Take the samples of another observer, which is left with none, tracking the same state.
 
Density_Observer & operator= (const Density_Observer &other)=default
 Copy another observer into this one: the state that it counts, the counts of each step, their totals, and whether it has seen a frame.
 
Density_Observer & operator= (Density_Observer &&other) noexcept(std::is_nothrow_swappable_v< State >)
 Exchange this observer with another, which is left with the previous samples of this one.
 
void swap (Density_Observer &other) noexcept(std::is_nothrow_swappable_v< State >)
 Exchange in O(1) the tracked state and the samples of this observer and another.
 
const Array< ca_size_t > & counts () const noexcept
 Return the count time series.
 
const Array< ca_size_t > & totals () const noexcept
 Return the total-cell time series.
 
double density_at (const std::size_t i) const
 Return density at a recorded sample.
 
std::size_t size () const noexcept
 Return the number of recorded samples.
 
void reset () noexcept
 Clear all recorded samples.
 
template<typename Lattice >
void on_step_begin (const std::size_t step, const Lattice &frame)
 Record the initial frame before step zero.
 
template<typename Lattice >
void on_step_end (const std::size_t step, const Lattice &frame)
 Record the frame after a completed step.
 

Private Attributes

State tracked_state_ {}
 
Array< ca_size_t > counts_
 
Array< ca_size_t > totals_
 
bool seeded_ = false
 

Detailed Description

template<typename State>
class Aleph::CA::Density_Observer< State >

Records the count of cells in tracked_state per step.

At the end of every step the observer pushes one entry into its history. The very first sample is recorded inside on_step_begin for step == 0, so the time series includes the initial frame.

Template Parameters
Statecell state type to track.
Complexity
Callbacks are O(N) per sampled frame and O(1) extra space per sample, where N is the number of cells.
Thread-safety
Thread-safe for concurrent readers after simulation stops; not thread-safe for concurrent writers/callbacks.
Exception-safety
Strong guarantee unless array allocation throws during sampling.

Definition at line 328 of file ca-observer.H.

Constructor & Destructor Documentation

◆ Density_Observer() [1/4]

template<typename State >
Aleph::CA::Density_Observer< State >::Density_Observer ( )
default

Construct an observer that tracks State{}.

Exceptions
Anyexception thrown by State default construction.

◆ Density_Observer() [2/4]

template<typename State >
Aleph::CA::Density_Observer< State >::Density_Observer ( State  s)
inlineexplicit

Construct an observer tracking a specific state.

Parameters
[in]sstate value counted at every sample.
Exceptions
Anyexception thrown while moving/copying s.

Definition at line 345 of file ca-observer.H.

◆ Density_Observer() [3/4]

template<typename State >
Aleph::CA::Density_Observer< State >::Density_Observer ( const Density_Observer< State > &  other)
default

Copy another observer: the state that it counts, the counts of each step, their totals, and whether it has seen a frame.

Parameters
[in]otherobserver to copy.

◆ Density_Observer() [4/4]

template<typename State >
Aleph::CA::Density_Observer< State >::Density_Observer ( Density_Observer< State > &&  other)
inlinenoexcept

Take the samples of another observer, which is left with none, tracking the same state.

The implicit move took the samples but copied the flag of the initial sample: the moved-from observer, reused, skipped the initial frame of its next run.

Parameters
[in,out]otherobserver to move from.

Definition at line 362 of file ca-observer.H.

Member Function Documentation

◆ counts()

template<typename State >
const Array< ca_size_t > & Aleph::CA::Density_Observer< State >::counts ( ) const
inlinenoexcept

Return the count time series.

Returns
counts, one per recorded step including the initial frame.
Exceptions
Thisfunction does not throw.

Definition at line 404 of file ca-observer.H.

References Aleph::CA::Density_Observer< State >::counts_.

◆ density_at()

template<typename State >
double Aleph::CA::Density_Observer< State >::density_at ( const std::size_t  i) const
inline

Return density at a recorded sample.

Parameters
[in]isample index.
Returns
counts()[i] / totals()[i], or 0 for empty lattices.
Exceptions
std::out_of_rangeif i >= size().

Definition at line 423 of file ca-observer.H.

References ah_out_of_range_error_if, Aleph::CA::Density_Observer< State >::counts_, Aleph::Array< T >::size(), and Aleph::CA::Density_Observer< State >::totals_.

Referenced by main().

◆ on_step_begin()

template<typename State >
template<typename Lattice >
void Aleph::CA::Density_Observer< State >::on_step_begin ( const std::size_t  step,
const Lattice &  frame 
)
inline

Record the initial frame before step zero.

Template Parameters
Latticelattice type.
Parameters
[in]stepstep index about to run.
[in]frameframe before the step.
Exceptions
std::bad_allocif appending the sample allocates.

Definition at line 459 of file ca-observer.H.

References Aleph::and, Aleph::Array< T >::append(), Aleph::CA::count_state(), Aleph::CA::Density_Observer< State >::counts_, Aleph::CA::Density_Observer< State >::seeded_, Aleph::CA::total_cells(), Aleph::CA::Density_Observer< State >::totals_, and Aleph::CA::Density_Observer< State >::tracked_state_.

◆ on_step_end()

template<typename State >
template<typename Lattice >
void Aleph::CA::Density_Observer< State >::on_step_end ( const std::size_t  step,
const Lattice &  frame 
)
inline

Record the frame after a completed step.

Template Parameters
Latticelattice type.
Parameters
[in]stepcompleted step index, ignored.
[in]frameframe after the step.
Exceptions
std::bad_allocif appending the sample allocates.

Definition at line 476 of file ca-observer.H.

References Aleph::Array< T >::append(), Aleph::CA::count_state(), Aleph::CA::Density_Observer< State >::counts_, Aleph::CA::total_cells(), Aleph::CA::Density_Observer< State >::totals_, and Aleph::CA::Density_Observer< State >::tracked_state_.

◆ operator=() [1/2]

template<typename State >
Density_Observer & Aleph::CA::Density_Observer< State >::operator= ( const Density_Observer< State > &  other)
default

Copy another observer into this one: the state that it counts, the counts of each step, their totals, and whether it has seen a frame.

Parameters
[in]otherobserver to copy.
Returns
this observer.

◆ operator=() [2/2]

template<typename State >
Density_Observer & Aleph::CA::Density_Observer< State >::operator= ( Density_Observer< State > &&  other)
inlinenoexcept

Exchange this observer with another, which is left with the previous samples of this one.

Parameters
[in,out]otherobserver to move from.
Returns
this observer.

Definition at line 380 of file ca-observer.H.

References Aleph::CA::Density_Observer< State >::swap().

◆ reset()

template<typename State >
void Aleph::CA::Density_Observer< State >::reset ( )
inlinenoexcept

Clear all recorded samples.

Exceptions
Thisfunction does not throw.
Complexity
O(size()).

Definition at line 445 of file ca-observer.H.

References Aleph::Array< T >::clear(), Aleph::CA::Density_Observer< State >::counts_, Aleph::CA::Density_Observer< State >::seeded_, and Aleph::CA::Density_Observer< State >::totals_.

◆ size()

template<typename State >
std::size_t Aleph::CA::Density_Observer< State >::size ( ) const
inlinenoexcept

Return the number of recorded samples.

Returns
sample count.
Exceptions
Thisfunction does not throw.

Definition at line 434 of file ca-observer.H.

References Aleph::CA::Density_Observer< State >::counts_, and Aleph::Array< T >::size().

Referenced by main().

◆ swap()

template<typename State >
void Aleph::CA::Density_Observer< State >::swap ( Density_Observer< State > &  other)
inlinenoexcept

◆ totals()

template<typename State >
const Array< ca_size_t > & Aleph::CA::Density_Observer< State >::totals ( ) const
inlinenoexcept

Return the total-cell time series.

Returns
total cell counts, aligned with counts().
Exceptions
Thisfunction does not throw.

Definition at line 413 of file ca-observer.H.

References Aleph::CA::Density_Observer< State >::totals_.

Member Data Documentation

◆ counts_

◆ seeded_

◆ totals_

◆ tracked_state_


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