Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Reproductions::BTW_Sandpile Class Reference

Deterministic open-boundary Bak-Tang-Wiesenfeld sandpile. More...

#include <ca_reproduction_support.H>

Collaboration diagram for Aleph::CA::Reproductions::BTW_Sandpile:
[legend]

Public Types

using Grid = Lattice< Dense_Cell_Storage< int, 2 >, OpenBoundary >
 
using update_scheme = Sequential_Update< RowMajor >
 

Public Member Functions

 BTW_Sandpile (const ca_size_t side, const std::uint64_t seed=0)
 Construct an empty square sandpile.
 
Avalanche drop_random ()
 Drop one grain at a uniformly selected cell and stabilise.
 
Avalanche drop_at (const ca_size_t row, const ca_size_t column)
 Drop one grain at (row, column) and stabilise.
 
const Grid & frame () const noexcept
 Return the current stable grid.
 
bool stable () const
 Test whether every cell is below the toppling threshold.
 

Private Member Functions

void add_if_inside (const ca_index_t row, const ca_index_t column)
 Add one grain when (row, column) lies inside the open grid.
 

Private Attributes

Grid grid_
 
std::mt19937_64 rng_
 

Detailed Description

Deterministic open-boundary Bak-Tang-Wiesenfeld sandpile.

The implementation performs in-place row-major toppling sweeps. It names Sequential_Update<RowMajor> as its update scheme because direct BTW toppling writes both the selected cell and its neighbours; a pull-only local rule cannot preserve grains while expressing that operation.

Definition at line 312 of file ca_reproduction_support.H.

Member Typedef Documentation

◆ Grid

◆ update_scheme

Constructor & Destructor Documentation

◆ BTW_Sandpile()

Aleph::CA::Reproductions::BTW_Sandpile::BTW_Sandpile ( const ca_size_t  side,
const std::uint64_t  seed = 0 
)
inlineexplicit

Construct an empty square sandpile.

Parameters
sidegrid side length.
seedseed used for uniformly distributed grain drops.
Exceptions
std::domain_errorif side == 0.

Definition at line 323 of file ca_reproduction_support.H.

References Aleph::blossom_maximum_cardinality_matching().

Member Function Documentation

◆ add_if_inside()

void Aleph::CA::Reproductions::BTW_Sandpile::add_if_inside ( const ca_index_t  row,
const ca_index_t  column 
)
inlineprivate

Add one grain when (row, column) lies inside the open grid.

Parameters
rowcandidate row.
columncandidate column.

Definition at line 406 of file ca_reproduction_support.H.

References Aleph::CA::Lattice< Storage, Boundary >::at(), Aleph::blossom_maximum_cardinality_matching(), grid_, row, Aleph::CA::Lattice< Storage, Boundary >::set(), and Aleph::CA::Lattice< Storage, Boundary >::size().

Referenced by drop_at().

◆ drop_at()

Avalanche Aleph::CA::Reproductions::BTW_Sandpile::drop_at ( const ca_size_t  row,
const ca_size_t  column 
)
inline

Drop one grain at (row, column) and stabilise.

Parameters
rowzero-based row.
columnzero-based column.
Returns
avalanche size and duration.
Exceptions
std::domain_errorif the coordinate is out of range.

Definition at line 344 of file ca_reproduction_support.H.

References add_if_inside(), ah_domain_error_if, Aleph::CA::Lattice< Storage, Boundary >::at(), Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Reproductions::Avalanche::duration, grid_, r, row, Aleph::CA::Lattice< Storage, Boundary >::set(), Aleph::CA::Reproductions::Avalanche::size, and Aleph::CA::Lattice< Storage, Boundary >::size().

Referenced by drop_random().

◆ drop_random()

Avalanche Aleph::CA::Reproductions::BTW_Sandpile::drop_random ( )
inline

Drop one grain at a uniformly selected cell and stabilise.

Returns
avalanche size and duration.

Definition at line 332 of file ca_reproduction_support.H.

References drop_at(), grid_, rng_, and Aleph::CA::Lattice< Storage, Boundary >::size().

◆ frame()

const Grid & Aleph::CA::Reproductions::BTW_Sandpile::frame ( ) const
inlinenoexcept

Return the current stable grid.

Returns
const lattice reference.

Definition at line 381 of file ca_reproduction_support.H.

References grid_.

◆ stable()

bool Aleph::CA::Reproductions::BTW_Sandpile::stable ( ) const
inline

Test whether every cell is below the toppling threshold.

Returns
true when the frame is stable.

Definition at line 389 of file ca_reproduction_support.H.

References Aleph::CA::Lattice< Storage, Boundary >::at(), grid_, r, and Aleph::CA::Lattice< Storage, Boundary >::size().

Member Data Documentation

◆ grid_

Grid Aleph::CA::Reproductions::BTW_Sandpile::grid_
private

Definition at line 399 of file ca_reproduction_support.H.

Referenced by add_if_inside(), drop_at(), drop_random(), frame(), and stable().

◆ rng_

std::mt19937_64 Aleph::CA::Reproductions::BTW_Sandpile::rng_
private

Definition at line 400 of file ca_reproduction_support.H.

Referenced by drop_random().


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