58#ifndef TPL_CA_MULTI_FIELD_ENGINE_H
59#define TPL_CA_MULTI_FIELD_ENGINE_H
78namespace ca_mf_engine_detail {
86 std::index_sequence<I...>)
90 if (
neigh_sz > std::tuple_size_v<std::tuple_element_t<0, Buffers>>)
91 neigh_sz = std::tuple_size_v<std::tuple_element_t<0, Buffers>>;
94 nh.for_each_offset(center, [&](
const auto &
off)
121template <
typename Lattice,
typename Rule,
typename Neighborhood>
125 "Multi_Field_Engine requires a MultiFieldLatticeLike lattice");
127 "Multi_Field_Engine requires a NeighborhoodLike neighbourhood");
128 static_assert(Neighborhood::rank_v ==
Lattice::rank,
"Neighbourhood rank must match lattice rank");
154 template <std::size_t...
I>
157 return std::tuple{std::array<typename Lattice::template field_type<I>,
161 template <std::size_t...
I>
164 ((
nxt_.template
set<I>(c, std::get<I>(v))), ...);
184 requires std::default_initializable<Neighborhood>
207 template <
typename F>
214 template <
typename F>
242 std::make_index_sequence<field_count>{});
265 for (std::size_t i = 0; i <
steps; ++i)
270 template <
typename F>
274 if constexpr (
rank == 1)
283 else if constexpr (
rank == 2)
295 else if constexpr (
rank == 3)
311 static_assert(
rank <= 3,
"Multi_Field_Engine currently supports rank <= 3");
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
typename Storage::extents_type extents_type
const extents_type & extents() const noexcept
void swap(Lattice &other) noexcept(noexcept(store_.swap(other.store_)))
O(1) swap.
typename Storage::coord_type coord_type
static constexpr std::size_t rank
ca_size_t size() const noexcept
Synchronous double-buffered engine for multi-field lattices.
void run(const std::size_t steps)
Run several steps.
typename Lattice::coord_type coord_type
Multi_Field_Engine(Lattice initial, Rule r)
Build with a default-constructed neighbourhood.
Multi_Field_Engine(Lattice initial, Rule r, Neighborhood n)
Build a multi-field engine.
void step()
Apply the multi-field rule to every cell once and swap buffers.
void on_pre_step(F &&f)
Register a hook fired before every step().
void iterate_lattice(F &&f)
static constexpr std::size_t rank
void write_cell(const coord_type &c, const fields_tuple &v, std::index_sequence< I... >)
static constexpr std::size_t neighbour_count
const extents_type & extents() const noexcept
static constexpr std::size_t field_count
void on_post_step(F &&f)
Register a hook fired after every step().
typename Lattice::extents_type extents_type
const Lattice & frame() const noexcept
static auto make_buffers(std::index_sequence< I... >)
std::size_t steps_run() const noexcept
std::function< void(std::size_t, const Lattice &)> hook_type
Hook signature: (step_index_just_completed, frame).
typename Lattice::field_types fields_tuple
Neighborhood neighborhood_type
Shape (per-axis sizes) of an mdspan, mixing compile-time and run-time extents.
A coordinate type with N integral components.
Concept: a lattice that exposes the multi-field interface.
Connectivity pattern around a coordinate.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
auto build_views(const Lattice &lat, const Neighborhood &nh, const typename Lattice::coord_type ¢er, Buffers &bufs, std::index_sequence< I... >)
Recurse over the Field_Indices and gather one Neighbor_View per field.
@ I
Infected (and infectious).
std::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
Main namespace for Aleph-w library functions.
Per-cell context handed to rules that need to know "where" and "when" they are firing.
C++20 concepts for the Cellular Automata module.
Phase 14 multi-field cellular automata lattice (AoS / SoA).
Phase 14 multi-field local rules for Aleph::CA.
Neighborhoods catalogue for Aleph::CA.