Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood > Class Template Reference

Synchronous double-buffered engine for multi-field lattices. More...

#include <tpl_ca_multi_field_engine.H>

Collaboration diagram for Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >:
[legend]

Public Types

using lattice_type = Lattice
 
using rule_type = Rule
 
using neighborhood_type = Neighborhood
 
using coord_type = typename Lattice::coord_type
 
using extents_type = typename Lattice::extents_type
 
using fields_tuple = typename Lattice::field_types
 
using hook_type = std::function< void(std::size_t, const Lattice &)>
 Hook signature: (step_index_just_completed, frame).
 

Public Member Functions

 Multi_Field_Engine (Lattice initial, Rule r, Neighborhood n)
 Build a multi-field engine.
 
 Multi_Field_Engine (Lattice initial, Rule r)
 Build with a default-constructed neighbourhood.
 
 Multi_Field_Engine (const Multi_Field_Engine &other)=default
 Copy another engine: its lattices, its rule, its neighborhood, its hooks and its count of steps.
 
 Multi_Field_Engine (Multi_Field_Engine &&other) noexcept(std::is_nothrow_move_constructible_v< Lattice > and std::is_nothrow_move_constructible_v< Rule > and std::is_nothrow_move_constructible_v< Neighborhood >)
 Take the simulation of another engine, which is left with empty lattices, no hooks and no steps run.
 
Multi_Field_Engine & operator= (const Multi_Field_Engine &other)=default
 Copy another engine into this one: its lattices, its rule, its neighborhood, its hooks and its count of steps.
 
Multi_Field_Engine & operator= (Multi_Field_Engine &&other) noexcept(noexcept(swap(other)))
 Exchange this engine with another, which is left with the previous simulation of this one.
 
void swap (Multi_Field_Engine &other) noexcept(noexcept(cur_.swap(other.cur_)) and std::is_nothrow_swappable_v< Rule > and std::is_nothrow_swappable_v< Neighborhood >)
 Exchange in O(1) the simulation of this engine and another.
 
const Lattice & frame () const noexcept
 
std::size_t steps_run () const noexcept
 
const extents_type & extents () const noexcept
 
template<typename F >
void on_pre_step (F &&f)
 Register a hook fired before every step().
 
template<typename F >
void on_post_step (F &&f)
 Register a hook fired after every step().
 
void step ()
 Apply the multi-field rule to every cell once and swap buffers.
 
void run (const std::size_t steps)
 Run several steps.
 

Static Public Attributes

static constexpr std::size_t rank = Lattice::rank
 
static constexpr std::size_t field_count = Lattice::field_count
 
static constexpr std::size_t neighbour_count = Neighborhood::size_v
 

Private Member Functions

template<std::size_t... I>
void write_cell (const coord_type &c, const fields_tuple &v, std::index_sequence< I... >)
 
void swap_all_or_none (Multi_Field_Engine &other)
 
template<typename F >
void iterate_lattice (F &&f)
 

Static Private Member Functions

template<std::size_t... I>
static auto make_buffers (std::index_sequence< I... >)
 

Private Attributes

Lattice cur_
 
Lattice nxt_
 
Rule rule_
 
Neighborhood nh_
 
hook_type pre_hook_
 
hook_type post_hook_
 
std::size_t step_count_ = 0
 

Detailed Description

template<typename Lattice, typename Rule, typename Neighborhood>
class Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >

Synchronous double-buffered engine for multi-field lattices.

Template Parameters
LatticeMulti_Field_Lattice<...> instance.
Rulemulti-field rule (MultiFieldRuleLike).
Neighborhoodmono-field neighbourhood applied uniformly to every field (NeighborhoodLike).
Complexity
step() is O(N * S * F) where N is the cell count, S the neighbour count and F the number of fields.

Definition at line 122 of file tpl_ca_multi_field_engine.H.

Member Typedef Documentation

◆ coord_type

template<typename Lattice , typename Rule , typename Neighborhood >
using Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::coord_type = typename Lattice::coord_type

Definition at line 134 of file tpl_ca_multi_field_engine.H.

◆ extents_type

template<typename Lattice , typename Rule , typename Neighborhood >
using Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::extents_type = typename Lattice::extents_type

Definition at line 135 of file tpl_ca_multi_field_engine.H.

◆ fields_tuple

template<typename Lattice , typename Rule , typename Neighborhood >
using Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::fields_tuple = typename Lattice::field_types

Definition at line 136 of file tpl_ca_multi_field_engine.H.

◆ hook_type

template<typename Lattice , typename Rule , typename Neighborhood >
using Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::hook_type = std::function<void(std::size_t, const Lattice &)>

Hook signature: (step_index_just_completed, frame).

Definition at line 143 of file tpl_ca_multi_field_engine.H.

◆ lattice_type

template<typename Lattice , typename Rule , typename Neighborhood >
using Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::lattice_type = Lattice

Definition at line 131 of file tpl_ca_multi_field_engine.H.

◆ neighborhood_type

template<typename Lattice , typename Rule , typename Neighborhood >
using Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::neighborhood_type = Neighborhood

Definition at line 133 of file tpl_ca_multi_field_engine.H.

◆ rule_type

template<typename Lattice , typename Rule , typename Neighborhood >
using Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::rule_type = Rule

Definition at line 132 of file tpl_ca_multi_field_engine.H.

Constructor & Destructor Documentation

◆ Multi_Field_Engine() [1/4]

template<typename Lattice , typename Rule , typename Neighborhood >
Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::Multi_Field_Engine ( Lattice  initial,
Rule  r,
Neighborhood  n 
)
inline

Build a multi-field engine.

Allocates a next-step lattice with the same extents as the initial lattice. Both buffers share the boundary policy and layout.

Parameters
[in]initialinitial lattice (consumed by move).
[in]rrule instance (consumed by move).
[in]nneighbourhood instance (consumed by move).
Exceptions
std::bad_allocon next-buffer allocation failure.

Definition at line 178 of file tpl_ca_multi_field_engine.H.

◆ Multi_Field_Engine() [2/4]

template<typename Lattice , typename Rule , typename Neighborhood >
Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::Multi_Field_Engine ( Lattice  initial,
Rule  r 
)
inline

Build with a default-constructed neighbourhood.

Definition at line 183 of file tpl_ca_multi_field_engine.H.

◆ Multi_Field_Engine() [3/4]

template<typename Lattice , typename Rule , typename Neighborhood >
Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::Multi_Field_Engine ( const Multi_Field_Engine< Lattice, Rule, Neighborhood > &  other)
default

Copy another engine: its lattices, its rule, its neighborhood, its hooks and its count of steps.

Parameters
[in]otherengine to copy.

◆ Multi_Field_Engine() [4/4]

template<typename Lattice , typename Rule , typename Neighborhood >
Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::Multi_Field_Engine ( Multi_Field_Engine< Lattice, Rule, Neighborhood > &&  other)
inlinenoexcept

Take the simulation of another engine, which is left with empty lattices, no hooks and no steps run.

The implicit move took the lattices but copied the step counter: the moved-from engine reported the steps of a simulation that it no longer had.

Parameters
[in,out]otherengine to move from.

Definition at line 203 of file tpl_ca_multi_field_engine.H.

Member Function Documentation

◆ extents()

template<typename Lattice , typename Rule , typename Neighborhood >
const extents_type & Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::extents ( ) const
inlinenoexcept

◆ frame()

template<typename Lattice , typename Rule , typename Neighborhood >
const Lattice & Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::frame ( ) const
inlinenoexcept
Returns
the current frame.

Definition at line 307 of file tpl_ca_multi_field_engine.H.

References Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::cur_.

◆ iterate_lattice()

template<typename Lattice , typename Rule , typename Neighborhood >
template<typename F >
void Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::iterate_lattice ( F &&  f)
inlineprivate

◆ make_buffers()

template<typename Lattice , typename Rule , typename Neighborhood >
template<std::size_t... I>
static auto Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::make_buffers ( std::index_sequence< I... >  )
inlinestaticprivate

◆ on_post_step()

template<typename Lattice , typename Rule , typename Neighborhood >
template<typename F >
void Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::on_post_step ( F &&  f)
inline

Register a hook fired after every step().

Definition at line 333 of file tpl_ca_multi_field_engine.H.

References Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::post_hook_.

◆ on_pre_step()

template<typename Lattice , typename Rule , typename Neighborhood >
template<typename F >
void Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::on_pre_step ( F &&  f)
inline

Register a hook fired before every step().

Definition at line 326 of file tpl_ca_multi_field_engine.H.

References Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::pre_hook_.

◆ operator=() [1/2]

template<typename Lattice , typename Rule , typename Neighborhood >
Multi_Field_Engine & Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::operator= ( const Multi_Field_Engine< Lattice, Rule, Neighborhood > &  other)
default

Copy another engine into this one: its lattices, its rule, its neighborhood, its hooks and its count of steps.

Parameters
[in]otherengine to copy.
Returns
this engine.

◆ operator=() [2/2]

template<typename Lattice , typename Rule , typename Neighborhood >
Multi_Field_Engine & Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::operator= ( Multi_Field_Engine< Lattice, Rule, Neighborhood > &&  other)
inlinenoexcept

Exchange this engine with another, which is left with the previous simulation of this one.

Parameters
[in,out]otherengine to move from.
Returns
this engine.

Definition at line 224 of file tpl_ca_multi_field_engine.H.

References Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::swap().

◆ run()

template<typename Lattice , typename Rule , typename Neighborhood >
void Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::run ( const std::size_t  steps)
inline

Run several steps.

Parameters
[in]stepsnumber of consecutive step() calls.
Exceptions
Anyexception propagated by step().

Definition at line 381 of file tpl_ca_multi_field_engine.H.

References Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::step(), and steps.

Referenced by main().

◆ step()

◆ steps_run()

template<typename Lattice , typename Rule , typename Neighborhood >
std::size_t Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::steps_run ( ) const
inlinenoexcept
Returns
the number of completed steps.

Definition at line 313 of file tpl_ca_multi_field_engine.H.

References Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::step_count_.

◆ swap()

template<typename Lattice , typename Rule , typename Neighborhood >
void Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::swap ( Multi_Field_Engine< Lattice, Rule, Neighborhood > &  other)
inlinenoexcept

Exchange in O(1) the simulation of this engine and another.

Parameters
[in,out]otherengine to exchange with.
Exceptions
whatswapping the rules, the neighborhoods or the lattices throws. When one of those swaps may throw, the rules and the neighborhoods are exchanged before the lattices, all or none: if a swap throws, those before it are exchanged back, and both engines are left as they were, if the swap that threw left its arguments as they were. If a swap that puts one back throws too, both engines can only be destroyed or assigned. std::swap(), for a rule without a swap of its own, may leave it moved from.

Definition at line 243 of file tpl_ca_multi_field_engine.H.

References Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::cur_, Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::nh_, Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::nxt_, Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::post_hook_, Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::pre_hook_, Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::rule_, Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::step_count_, Aleph::CA::Lattice< Storage, Boundary >::swap(), Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::swap(), and Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::swap_all_or_none().

Referenced by Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::operator=(), Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::swap(), and Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::swap_all_or_none().

◆ swap_all_or_none()

◆ write_cell()

template<typename Lattice , typename Rule , typename Neighborhood >
template<std::size_t... I>
void Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::write_cell ( const coord_type &  c,
const fields_tuple &  v,
std::index_sequence< I... >   
)
inlineprivate

Member Data Documentation

◆ cur_

◆ field_count

template<typename Lattice , typename Rule , typename Neighborhood >
constexpr std::size_t Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::field_count = Lattice::field_count
staticconstexpr

Definition at line 139 of file tpl_ca_multi_field_engine.H.

◆ neighbour_count

template<typename Lattice , typename Rule , typename Neighborhood >
constexpr std::size_t Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::neighbour_count = Neighborhood::size_v
staticconstexpr

◆ nh_

◆ nxt_

◆ post_hook_

◆ pre_hook_

◆ rank

template<typename Lattice , typename Rule , typename Neighborhood >
constexpr std::size_t Aleph::CA::Multi_Field_Engine< Lattice, Rule, Neighborhood >::rank = Lattice::rank
staticconstexpr

◆ rule_

◆ step_count_


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