include/pops/numerics/time/schemes/scheduler.hpp Source FileΒΆ

adc_cpp: include/pops/numerics/time/schemes/scheduler.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
scheduler.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <type_traits>
7#include <utility>
8
25
26namespace pops {
27
28template <class Block>
30
31template <class Block>
34
35// Block cadence (tutor return): it advances only 1 macro-step out of `stride`.
36template <class Block>
38
39// Variant with a macro-step counter: a block of cadence `stride` advances only at macro-steps
40// that are multiples of stride, and then by an EFFECTIVE step stride*dt (it catches up on
41// time). Total after M macro-steps = M*dt like the others, but computed M/stride times (the
42// "gas not resolved every step"). substeps stays orthogonal (splits the effective step).
43// stride=1 -> every macro-step, effective step dt: strictly the historical behavior.
44template <CoupledSystemLike System, class AdvanceBlock>
45void advance_subcycled(System& system, Real dt, int macro_step, AdvanceBlock&& advance_block) {
46 system.for_each_block([&](auto& block) {
47 using Block = std::decay_t<decltype(block)>;
48 if constexpr (block_time_treatment_v<Block> != TimeTreatment::Prescribed) {
49 constexpr int stride = block_stride_v<Block>;
50 if (macro_step % stride != 0)
51 return; // slow block: skip this macro-step
52 constexpr int n = block_substeps_v<Block>;
53 const Real h = (dt * static_cast<Real>(stride)) / static_cast<Real>(n);
54 for (int s = 0; s < n; ++s)
55 advance_block(block, h, s, n);
56 }
57 });
58}
59
60// Historical overload (no cadence): macro_step = 0 -> all blocks advance every step (stride
61// ignored). Bit-identical to the old advance_subcycled.
62template <CoupledSystemLike System, class AdvanceBlock>
63void advance_subcycled(System& system, Real dt, AdvanceBlock&& advance_block) {
64 advance_subcycled(system, dt, 0, std::forward<AdvanceBlock>(advance_block));
65}
66
67} // namespace pops
Coupled multi-species system, composed at runtime from generic bricks.
Definition system.hpp:89
CoupledSystem: heterogeneous collection of equation blocks (multi-species, multi-scheme).
Definition amr_hierarchy.hpp:29
constexpr int block_substeps_v
Definition scheduler.hpp:29
void advance_subcycled(System &system, Real dt, int macro_step, AdvanceBlock &&advance_block)
Definition scheduler.hpp:45
double Real
Definition types.hpp:30
TimeTreatment
Definition time_integrator.hpp:29
constexpr int block_stride_v
Definition scheduler.hpp:37
constexpr TimeTreatment block_time_treatment_v
Definition scheduler.hpp:32
Definition time_integrator.hpp:46
Base scalar types and the POPS_HD macro (host+device portability).