include/pops/core/model/coupled_system.hpp Source FileΒΆ

adc_cpp: include/pops/core/model/coupled_system.hpp Source File
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
coupled_system.hpp
Go to the documentation of this file.
1
15
16#pragma once
17
19
20#include <cstddef>
21#include <tuple>
22#include <type_traits>
23#include <utility>
24
25namespace pops {
26
36template <EquationBlockLike... Blocks>
38 static constexpr std::size_t n_blocks = sizeof...(Blocks);
39
40 std::tuple<Blocks...> blocks;
41
42 explicit CoupledSystem(Blocks... bs) : blocks(std::move(bs)...) {}
43
44 template <std::size_t I>
45 decltype(auto) block() {
46 return std::get<I>(blocks);
47 }
48
49 template <std::size_t I>
50 decltype(auto) block() const {
51 return std::get<I>(blocks);
52 }
53
54 template <class F>
55 void for_each_block(F&& f) {
56 std::apply([&](auto&... bs) { (std::forward<F>(f)(bs), ...); }, blocks);
57 }
58
59 template <class F>
60 void for_each_block(F&& f) const {
61 std::apply([&](const auto&... bs) { (std::forward<F>(f)(bs), ...); }, blocks);
62 }
63};
64
65namespace detail {
67// requires-clause (s.for_each_block([](auto&){})) trips the nvcc/EDG frontend: an
68// extended lambda in an UNEVALUATED context is not instantiable on the device side -> the
69// AmrSystemCoupler<CoupledSystemLike System> facade does not instantiate under Cuda (the B_z-AMR
70// device path then went through advance_amr directly). A NAMED FUNCTOR works around this (same recipe
71// as the named functors in block_builder.hpp, #64) without changing the host-side semantics.
73 template <class B>
74 void operator()(B&) const {}
75};
76} // namespace detail
77
83template <class S>
84concept CoupledSystemLike = requires(S s) {
85 { S::n_blocks } -> std::convertible_to<std::size_t>;
86 s.for_each_block(detail::ForEachBlockProbe{});
87};
88
89template <EquationBlockLike... Blocks>
90CoupledSystem(Blocks...) -> CoupledSystem<Blocks...>;
91
92} // namespace pops
Minimal concept for coupled systems: n_blocks and for_each_block with a named functor.
Definition coupled_system.hpp:84
Minimal concept for equation blocks: Model, Spatial, Time, name, state, U().
Definition equation_block.hpp:68
EquationBlock: association (model, field U, spatial scheme, time policy, BC).
Definition amr_hierarchy.hpp:29
Heterogeneous collection of equation blocks, parameterized by their exact types.
Definition coupled_system.hpp:37
static constexpr std::size_t n_blocks
Definition coupled_system.hpp:38
decltype(auto) block() const
Definition coupled_system.hpp:50
std::tuple< Blocks... > blocks
Definition coupled_system.hpp:40
CoupledSystem(Blocks... bs)
Definition coupled_system.hpp:42
decltype(auto) block()
Definition coupled_system.hpp:45
void for_each_block(F &&f) const
Definition coupled_system.hpp:60
void for_each_block(F &&f)
Definition coupled_system.hpp:55
NAMED no-op probe for the CoupledSystemLike concept. A generic lambda in the.
Definition coupled_system.hpp:72
void operator()(B &) const
Definition coupled_system.hpp:74