|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Lattice with Halo ghost layers around the user-visible cells.
More...
#include <tpl_ca_ghost_lattice.H>
Public Types | |
| using | storage_type = Storage |
| using | boundary_type = Boundary |
| using | state_type = typename Storage::state_type |
| using | coord_type = typename Storage::coord_type |
| using | extents_type = typename Storage::extents_type |
Public Member Functions | |
| Ghost_Lattice ()=default | |
| Construct an empty ghost lattice (no cells allocated). | |
| Ghost_Lattice (const extents_type &user_extents, const state_type &init=state_type{}) | |
| Construct a ghost lattice with given user extents and init value. | |
| ca_size_t | size () const noexcept |
| ca_size_t | size (std::size_t d) const |
User-visible extent along axis d. | |
| const extents_type & | extents () const noexcept |
| const extents_type & | store_extents () const noexcept |
| state_type | at (const coord_type &c) const |
| Strict read through a user coordinate. | |
| void | set (const coord_type &c, const state_type &v) |
| Strict write through a user coordinate. | |
| state_type | at_safe (const coord_type &c) const |
| Boundary-aware read exploiting the halo as a fast path. | |
| void | refresh_halo () |
| Populate every ghost cell according to the boundary policy. | |
| const Storage & | storage () const noexcept |
| Direct access to the underlying storage (read-only). | |
| Storage & | storage () noexcept |
| Direct access to the underlying storage. | |
| void | fill (const state_type &value) |
Set every user-visible cell to value. | |
| void | swap (Ghost_Lattice &other) noexcept(noexcept(store_.swap(other.store_))) |
| O(1) swap with another ghost lattice of the same type. | |
Static Public Member Functions | |
| static constexpr std::size_t | dimension () noexcept |
| static constexpr std::size_t | halo_radius () noexcept |
Static Public Attributes | |
| static constexpr std::size_t | rank = Storage::rank |
| Number of axes (same as the underlying storage). | |
| static constexpr std::size_t | halo_v = Halo |
| Halo thickness (ghost cells per side per axis). | |
Private Member Functions | |
| coord_type | to_store (const coord_type &c) const noexcept |
| Convert a user coordinate into a store coordinate. | |
| state_type | out_of_range_value () const |
Value returned when at_safe sees a coordinate outside the halo. | |
| state_type | resolve_via_policy (coord_type c) const |
| Resolve a user coordinate through the boundary policy (slow path). | |
| template<typename F > | |
| void | for_each_halo_cell (F &&f) const |
Invoke f(user_coord) on every halo cell of the storage. | |
| void | store_set (const coord_type &user_c, const state_type &value) |
Write value directly into the store at the given user coord. | |
| state_type | store_get (const coord_type &user_c) const |
| Read directly from the store at the given user coord. | |
Private Attributes | |
| extents_type | user_ext_ {} |
| extents seen from the outside | |
| extents_type | store_ext_ {} |
extents of the backing storage (user + 2H) | |
| Storage | store_ {} |
| underlying storage (allocated once) | |
Lattice with Halo ghost layers around the user-visible cells.
| Storage | storage type satisfying CA::LatticeLike. The storage is constructed with extents user + 2*Halo so that the halo is plain backing memory. |
| Boundary | boundary tag (default OpenBoundary). See the file-level documentation for the accepted tags. |
| Halo | halo thickness in cells (default 1). The neighbourhood radius consumed by the engine must be <= Halo for the fast path to kick in. |
at, set, at_safe: O(rank) (a few additions per call).refresh_halo: O(boundary-surface cells), i.e. linear in the halo volume (which for 2D/3D is O(n^{rank-1})).Storage. Definition at line 152 of file tpl_ca_ghost_lattice.H.
| using Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::boundary_type = Boundary |
Definition at line 158 of file tpl_ca_ghost_lattice.H.
| using Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::coord_type = typename Storage::coord_type |
Definition at line 160 of file tpl_ca_ghost_lattice.H.
| using Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::extents_type = typename Storage::extents_type |
Definition at line 161 of file tpl_ca_ghost_lattice.H.
| using Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::state_type = typename Storage::state_type |
Definition at line 159 of file tpl_ca_ghost_lattice.H.
| using Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::storage_type = Storage |
Definition at line 157 of file tpl_ca_ghost_lattice.H.
|
default |
Construct an empty ghost lattice (no cells allocated).
|
inlineexplicit |
Construct a ghost lattice with given user extents and init value.
Allocates prod(user_ext + 2*Halo) cells and initialises every interior and halo cell with init. refresh_halo() is not called automatically, since the initial state of a CA is a pure user responsibility.
| [in] | user_extents | per-axis user-visible sizes. |
| [in] | init | initial value for every cell (default state_type{}). |
| std::bad_alloc | on allocation failure. |
Definition at line 325 of file tpl_ca_ghost_lattice.H.
|
inline |
Strict read through a user coordinate.
| [in] | c | user coordinate in [0, size(d)). |
| std::out_of_range | if any component of c is out of range. |
Definition at line 372 of file tpl_ca_ghost_lattice.H.
References ah_out_of_range_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_get(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
|
inline |
Boundary-aware read exploiting the halo as a fast path.
For a coordinate inside [-Halo, size(d) + Halo) on every axis this method performs a single direct read from the backing storage — no branch on the boundary policy, so interior steps are branch-free as long as the neighbourhood radius is <= Halo. For coordinates further out the slow path applies the policy on the fly so the function still honours the declared semantics.
| [in] | c | possibly out-of-range user coordinate. |
refresh_halo() has been called after the last set() that modified an interior cell whose boundary reflection falls into the halo). If the halo is stale, reads of halo coordinates return the previously cached (potentially out-of-date) value. Definition at line 418 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), h, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::out_of_range_value(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::resolve_via_policy(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_get(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
|
inlinestaticconstexprnoexcept |
Definition at line 337 of file tpl_ca_ghost_lattice.H.
References Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank.
|
inlinenoexcept |
Definition at line 360 of file tpl_ca_ghost_lattice.H.
References Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
|
inline |
Set every user-visible cell to value.
The halo is left untouched; call refresh_halo() afterwards if you need it synchronised with the new interior.
Definition at line 524 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_set(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_, and value.
|
inlineprivate |
Invoke f(user_coord) on every halo cell of the storage.
user_coord uses the same convention as at(c): axes are in the user frame, so values in [-Halo, 0) or [user_ext[d], user_ext[d] + Halo) mean "halo cell on that side".
Definition at line 237 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::enumerate(), h, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::refresh_halo().
|
inlinestaticconstexprnoexcept |
Definition at line 366 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching().
|
inlineprivate |
Value returned when at_safe sees a coordinate outside the halo.
Definition at line 183 of file tpl_ca_ghost_lattice.H.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::at_safe(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::resolve_via_policy().
|
inline |
Populate every ghost cell according to the boundary policy.
The engine calls this automatically before each step() so the rule loop can read neighbour values without any boundary branch. Calling it manually is harmless (idempotent under every policy implemented here).
at_safe() is now safe to call for any coordinate in [-Halo, size(d) + Halo).O(surface_area * Halo)). Definition at line 456 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::ca_ghost_detail::clamp_index(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::for_each_halo_cell(), Aleph::CA::ca_ghost_detail::positive_mod(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, Aleph::CA::ca_ghost_detail::reflect_index(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_get(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_set(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
|
inlineprivate |
Resolve a user coordinate through the boundary policy (slow path).
This is only used by at_safe when the coordinate steps outside the halo — i.e. when the neighbourhood radius exceeds Halo.
Definition at line 194 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::out_of_range_value(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::to_store(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::at_safe().
|
inline |
Strict write through a user coordinate.
| [in] | c | user coordinate in [0, size(d)). |
| [in] | v | value to write. |
| std::out_of_range | if any component of c is out of range. |
c must be a valid user coordinate (each component in [0, size(d))). c holds v. Halo cells that mirror interior cells (e.g. under ToroidalBoundary) are not updated automatically; call refresh_halo() before the next at_safe() call that may read the halo region. Definition at line 391 of file tpl_ca_ghost_lattice.H.
References ah_out_of_range_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_set(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
|
inlinenoexcept |
Definition at line 340 of file tpl_ca_ghost_lattice.H.
References Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
|
inline |
User-visible extent along axis d.
| [in] | d | axis index. |
| std::out_of_range | if d >= rank. |
Definition at line 352 of file tpl_ca_ghost_lattice.H.
References ah_out_of_range_error_if, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank, and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
|
inlinenoexcept |
Direct access to the underlying storage (read-only).
Definition at line 516 of file tpl_ca_ghost_lattice.H.
References Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_.
|
inlinenoexcept |
Direct access to the underlying storage.
Definition at line 519 of file tpl_ca_ghost_lattice.H.
References Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_.
|
inlinenoexcept |
2*Halo on every axis). Definition at line 363 of file tpl_ca_ghost_lattice.H.
References Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_ext_.
|
inlineprivate |
Read directly from the store at the given user coord.
Definition at line 305 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_, and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::to_store().
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::at(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::at_safe(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::refresh_halo().
|
inlineprivate |
Write value directly into the store at the given user coord.
No bounds-check (the caller is trusted).
Definition at line 299 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::to_store(), and value.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::fill(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::refresh_halo(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::set().
|
inlinenoexcept |
O(1) swap with another ghost lattice of the same type.
Definition at line 545 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_ext_, Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::swap(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::user_ext_.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::swap().
|
inlineprivatenoexcept |
Convert a user coordinate into a store coordinate.
Definition at line 174 of file tpl_ca_ghost_lattice.H.
References Aleph::blossom_maximum_cardinality_matching(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::rank.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::resolve_via_policy(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_get(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_set().
|
staticconstexpr |
Halo thickness (ghost cells per side per axis).
Definition at line 166 of file tpl_ca_ghost_lattice.H.
|
staticconstexpr |
Number of axes (same as the underlying storage).
Definition at line 164 of file tpl_ca_ghost_lattice.H.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::at(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::at_safe(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::dimension(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::fill(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::for_each_halo_cell(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::refresh_halo(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::resolve_via_policy(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::set(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::size(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::size(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::to_store().
|
private |
underlying storage (allocated once)
Definition at line 171 of file tpl_ca_ghost_lattice.H.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::resolve_via_policy(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::storage(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::storage(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_get(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_set(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::swap().
|
private |
extents of the backing storage (user + 2H)
Definition at line 170 of file tpl_ca_ghost_lattice.H.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::store_extents(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::swap().
|
private |
extents seen from the outside
Definition at line 169 of file tpl_ca_ghost_lattice.H.
Referenced by Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::at(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::at_safe(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::extents(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::fill(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::for_each_halo_cell(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::refresh_halo(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::resolve_via_policy(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::set(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::size(), Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::size(), and Aleph::CA::Ghost_Lattice< Storage, Boundary, Halo >::swap().