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

Snapshots the lattice every period steps. More...

#include <ca-observer.H>

Collaboration diagram for Aleph::CA::Sampling_Observer< Lattice >:
[legend]

Public Member Functions

 Sampling_Observer ()=default
 Construct an observer that snapshots every step.
 
 Sampling_Observer (const std::size_t period)
 Construct an observer with an explicit sampling period.
 
const Array< Lattice > & snapshots () const noexcept
 Return collected snapshots.
 
const Array< std::size_t > & step_indices () const noexcept
 Return step indices for collected snapshots.
 
std::size_t size () const noexcept
 Return the number of stored snapshots.
 
void reset () noexcept
 Clear all snapshots and step indices.
 
void on_step_begin (const std::size_t step, const Lattice &frame)
 Capture the initial frame when sampling is enabled.
 
void on_step_end (const std::size_t step, const Lattice &frame)
 Capture the completed frame at period boundaries.
 

Private Attributes

std::size_t period_ = 1
 
Array< Lattice > snapshots_
 
Array< std::size_t > step_indices_
 

Detailed Description

template<typename Lattice>
class Aleph::CA::Sampling_Observer< Lattice >

Snapshots the lattice every period steps.

Stores in-memory copies into a Array<Lattice> accessible via snapshots(). The initial frame is captured (under on_step_begin for step 0) and every step whose index is a multiple of period thereafter. Pass period == 0 to disable sampling entirely.

Template Parameters
Latticelattice type to copy.
Complexity
Sampling a frame costs O(N) time and space. Non-sampling callbacks are O(1).
Thread-safety
Thread-safe for concurrent readers after simulation stops; not thread-safe for concurrent callbacks.
Exception-safety
Strong guarantee unless copying the lattice or appending to the arrays throws.

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

Constructor & Destructor Documentation

◆ Sampling_Observer() [1/2]

template<typename Lattice >
Aleph::CA::Sampling_Observer< Lattice >::Sampling_Observer ( )
default

Construct an observer that snapshots every step.

Exceptions
Thisfunction does not throw.

◆ Sampling_Observer() [2/2]

template<typename Lattice >
Aleph::CA::Sampling_Observer< Lattice >::Sampling_Observer ( const std::size_t  period)
inlineexplicit

Construct an observer with an explicit sampling period.

Parameters
[in]periodsnapshot period; zero disables sampling.
Exceptions
Thisfunction does not throw.

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

Member Function Documentation

◆ on_step_begin()

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

Capture the initial frame when sampling is enabled.

Parameters
[in]stepstep index about to run.
[in]frameframe before the step.
Exceptions
Anyexception thrown while copying frame or appending.

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

References Aleph::and, Aleph::Array< T >::append(), Aleph::CA::Sampling_Observer< Lattice >::period_, Aleph::CA::Sampling_Observer< Lattice >::snapshots_, and Aleph::CA::Sampling_Observer< Lattice >::step_indices_.

◆ on_step_end()

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

Capture the completed frame at period boundaries.

Parameters
[in]stepcompleted step index.
[in]frameframe after the step.
Exceptions
Anyexception thrown while copying frame or appending.

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

References Aleph::Array< T >::append(), Aleph::CA::Sampling_Observer< Lattice >::period_, Aleph::CA::Sampling_Observer< Lattice >::snapshots_, and Aleph::CA::Sampling_Observer< Lattice >::step_indices_.

◆ reset()

template<typename Lattice >
void Aleph::CA::Sampling_Observer< Lattice >::reset ( )
inlinenoexcept

Clear all snapshots and step indices.

Exceptions
Thisfunction does not throw.
Complexity
O(size()) plus snapshot destruction cost.

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

References Aleph::Array< T >::clear(), Aleph::CA::Sampling_Observer< Lattice >::snapshots_, and Aleph::CA::Sampling_Observer< Lattice >::step_indices_.

◆ size()

template<typename Lattice >
std::size_t Aleph::CA::Sampling_Observer< Lattice >::size ( ) const
inlinenoexcept

Return the number of stored snapshots.

Returns
snapshot count.
Exceptions
Thisfunction does not throw.

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

References Aleph::CA::Sampling_Observer< Lattice >::snapshots_.

◆ snapshots()

template<typename Lattice >
const Array< Lattice > & Aleph::CA::Sampling_Observer< Lattice >::snapshots ( ) const
inlinenoexcept

Return collected snapshots.

Returns
snapshots in chronological order.
Exceptions
Thisfunction does not throw.

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

References Aleph::CA::Sampling_Observer< Lattice >::snapshots_.

◆ step_indices()

template<typename Lattice >
const Array< std::size_t > & Aleph::CA::Sampling_Observer< Lattice >::step_indices ( ) const
inlinenoexcept

Return step indices for collected snapshots.

Returns
step indices aligned with snapshots().
Exceptions
Thisfunction does not throw.

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

References Aleph::CA::Sampling_Observer< Lattice >::step_indices_.

Member Data Documentation

◆ period_

◆ snapshots_

◆ step_indices_


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