include/pops/physics/bricks/source.hpp Source FileΒΆ

adc_cpp: include/pops/physics/bricks/source.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
source.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pops/core/model/physical_model.hpp> // aux_comps<>: propagates the aux channel of a composite source
6
14
15namespace pops {
16
17// OPTIONAL CONTRACT frequency(U, aux) -> Real (audit 2026-06, step_cfl work): a source brick
18// may declare its local FREQUENCY mu [1/s] (relaxation/collision/reaction rate). When the brick
19// exposes it, CompositeModel forwards it (source_frequency) and System::step_cfl enforces the
20// bound dt <= cfl * substeps / (stride * max_cells(mu)) -- the meeting's "second CFL" (source),
21// distinct from the transport CFL (no h: a source is bounded in 1/time). A brick WITHOUT
22// frequency (all of those in this file today) does not constrain the step (historical). Must be
23// POPS_HD (evaluated inside a reduction kernel).
24
27struct NoSource {
28 template <class State>
29 POPS_HD State apply(const State&, const Aux&) const {
30 return State{};
31 }
32};
33
48 Real qom = 1; // q/m (sign included)
49 int c_rho = 0, c_mx = 1, c_my = 2, c_E = 3; // defaults = canonical fluid layout (bit-identical)
50 template <class State>
51 POPS_HD State apply(const State& u, const Aux& a) const {
52 const Real Ex = -a.grad_x, Ey = -a.grad_y;
53 State s{};
54 s[c_mx] = qom * u[c_rho] * Ex;
55 s[c_my] = qom * u[c_rho] * Ey;
56 if constexpr (State::size() == 4)
57 s[c_E] = qom * (u[c_mx] * Ex + u[c_my] * Ey);
58 return s;
59 }
60};
61
74 int c_rho = 0, c_mx = 1, c_my = 2, c_E = 3; // defaults = canonical fluid layout (bit-identical)
75 template <class State>
76 POPS_HD State apply(const State& u, const Aux& a) const {
77 const Real gx = -a.grad_x, gy = -a.grad_y;
78 State s{};
79 s[c_mx] = u[c_rho] * gx;
80 s[c_my] = u[c_rho] * gy;
81 if constexpr (State::size() == 4)
82 s[c_E] = u[c_mx] * gx + u[c_my] * gy;
83 return s;
84 }
85};
86
105 Real qom = 1; // q/m (sign included)
106 static constexpr int n_aux = 4; // reads B_z (extra aux channel, canonical index 3)
107 // ROLE-AWARE (audit section 5): only the MOMENTUM components are read/written (the magnetic
108 // force touches neither density nor energy -- zero work). c_mx/c_my are members, defaults =
109 // canonical layout (m_x=1, m_y=2), resolved by model_factory via the transport roles. Canonical
110 // == defaults -> bit-identical. POD integers -> device-clean.
111 int c_mx = 1, c_my = 2;
112 template <class State>
113 POPS_HD State apply(const State& u, const Aux& a) const {
114 static_assert(
115 State::size() >= 3,
116 "MagneticLorentzForce : requires a fluid transport >= 3 variables (momentum on 2 axes)");
117 const Real c = qom * a.B_z;
118 State s{};
119 s[c_mx] = c * u[c_my]; // +qom B_z m_(y/theta)
120 s[c_my] = -c * u[c_mx]; // -qom B_z m_(x/r)
121 // energy stays 0: v x B is perpendicular to v, zero work.
122 return s;
123 }
124};
125
135template <class A, class B>
137 A a{};
138 B b{};
139 static constexpr int n_aux = aux_comps<A>() > aux_comps<B>() ? aux_comps<A>() : aux_comps<B>();
140 template <class State>
141 POPS_HD State apply(const State& u, const Aux& ax) const {
142 return a.apply(u, ax) + b.apply(u, ax);
143 }
144};
145
146} // namespace pops
Definition amr_hierarchy.hpp:29
double Real
Definition types.hpp:30
POPS_HD constexpr int aux_comps()
Width of the aux channel a model CONSUMES.
Definition physical_model.hpp:67
C++20 concepts defining the contract of the physics layer.
Pointwise types of the physics layer: StateVec<N> (conserved state) and Aux (auxiliary fields from th...
POINTWISE auxiliary fields shared with the physics: single coupling channel.
Definition state.hpp:123
Real grad_y
Definition state.hpp:126
Real grad_x
Definition state.hpp:125
SUM of two source bricks: S(U, aux) = A.apply(U, aux) + B.apply(U, aux).
Definition source.hpp:136
POPS_HD State apply(const State &u, const Aux &ax) const
Definition source.hpp:141
A a
Definition source.hpp:137
static constexpr int n_aux
Definition source.hpp:139
B b
Definition source.hpp:138
Gravitational force rho g (+ work if 4 variables).
Definition source.hpp:73
int c_my
Definition source.hpp:74
int c_E
Definition source.hpp:74
POPS_HD State apply(const State &u, const Aux &a) const
Definition source.hpp:76
int c_rho
Definition source.hpp:74
int c_mx
Definition source.hpp:74
MAGNETIC Lorentz force q (v x B) on momentum, field B = B_z z_hat out of plane.
Definition source.hpp:104
POPS_HD State apply(const State &u, const Aux &a) const
Definition source.hpp:113
int c_my
Definition source.hpp:111
Real qom
Definition source.hpp:105
int c_mx
Definition source.hpp:111
static constexpr int n_aux
Definition source.hpp:106
No source: S(U, aux) = 0.
Definition source.hpp:27
POPS_HD State apply(const State &, const Aux &) const
Definition source.hpp:29
Electrostatic potential force (q/m) rho E on momentum (+ work on energy if 4 variables).
Definition source.hpp:47
int c_E
Definition source.hpp:49
int c_rho
Definition source.hpp:49
int c_mx
Definition source.hpp:49
int c_my
Definition source.hpp:49
Real qom
Definition source.hpp:48
POPS_HD State apply(const State &u, const Aux &a) const
Definition source.hpp:51
Base scalar types and the POPS_HD macro (host+device portability).
#define POPS_HD
Definition types.hpp:25