include/pops/numerics/linalg/lorentz_eliminator.hpp Source FileΒΆ

adc_cpp: include/pops/numerics/linalg/lorentz_eliminator.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
lorentz_eliminator.hpp
Go to the documentation of this file.
1
9
10#pragma once
11
13
14namespace pops {
15
56 Real w; // w = theta * dt * B_z
57 Real det; // det(B) = 1 + w^2
58
59 // theta: implicitness of the scheme (0 = explicit, 1 = implicit, 0.5 = Crank-Nicolson).
60 // dt: time step.
61 // B_z: z component of the magnetic field.
64 : w(theta * dt * B_z), det(Real(1) + (theta * dt * B_z) * (theta * dt * B_z)) {}
65
67 POPS_HD void apply_B(Real vx, Real vy, Real& Bx, Real& By) const {
68 Bx = vx - w * vy;
69 By = vy + w * vx;
70 }
71
73 POPS_HD void apply_Binv(Real vx, Real vy, Real& vxp, Real& vyp) const {
74 const Real inv = Real(1) / det;
75 vxp = inv * (vx + w * vy);
76 vyp = inv * (vy - w * vx);
77 }
78
81 POPS_HD Real binv_11() const { return Real(1) / det; }
82 POPS_HD Real binv_12() const { return w / det; }
83 POPS_HD Real binv_21() const { return -w / det; }
84 POPS_HD Real binv_22() const { return Real(1) / det; }
86};
87
88// Static check: LorentzEliminator is trivially copyable (POD-like),
89// guaranteeing it can be captured by value in a Kokkos/CUDA kernel
90// without hidden allocation.
91static_assert(__is_trivially_copyable(LorentzEliminator),
92 "LorentzEliminator must be trivially copyable (zero allocation, device-safe)");
93
94} // namespace pops
Definition amr_hierarchy.hpp:29
double Real
Definition types.hpp:30
LorentzEliminator: operator B = [[1,-w],[w,1]] and its analytic inverse.
Definition lorentz_eliminator.hpp:55
POPS_HD void apply_B(Real vx, Real vy, Real &Bx, Real &By) const
apply_B: applies B = [[1,-w],[w,1]] to (vx, vy), writes (Bx, By). POPS_HD.
Definition lorentz_eliminator.hpp:67
POPS_HD Real binv_11() const
Definition lorentz_eliminator.hpp:81
POPS_HD Real binv_21() const
Definition lorentz_eliminator.hpp:83
POPS_HD Real binv_12() const
Definition lorentz_eliminator.hpp:82
POPS_HD void apply_Binv(Real vx, Real vy, Real &vxp, Real &vyp) const
apply_Binv: applies B^{-1} = (1/det)*[[1,w],[-w,1]] to (vx, vy), writes (vxp, vyp)....
Definition lorentz_eliminator.hpp:73
POPS_HD LorentzEliminator(Real theta, Real dt, Real B_z)
Builds from (theta, dt, B_z): w = theta*dt*B_z, det = 1 + w^2. POPS_HD.
Definition lorentz_eliminator.hpp:63
Real w
Definition lorentz_eliminator.hpp:56
POPS_HD Real binv_22() const
Definition lorentz_eliminator.hpp:84
Real det
Definition lorentz_eliminator.hpp:57
Base scalar types and the POPS_HD macro (host+device portability).
#define POPS_HD
Definition types.hpp:25