include/pops/coupling/schur/core/schur_source_kernels.hpp Source FileΒΆ

adc_cpp: include/pops/coupling/schur/core/schur_source_kernels.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
schur_source_kernels.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pops/core/foundation/types.hpp> // Real, POPS_HD
4#include <pops/mesh/storage/fab2d.hpp> // Array4, ConstArray4
5
6#include <stdexcept>
7#include <string>
8
25
26namespace pops {
27
28namespace detail {
29
36 POPS_HD void operator()(int i, int j) const {
37 f(i, j, 0) = f_n(i, j, 0) + inv_theta * (f(i, j, 0) - f_n(i, j, 0));
38 }
39};
40
49 POPS_HD void operator()(int i, int j) const {
50 const Real nx = vx_n(i, j, 0) + inv_theta * (vx(i, j, 0) - vx_n(i, j, 0));
51 const Real ny = vy_n(i, j, 0) + inv_theta * (vy(i, j, 0) - vy_n(i, j, 0));
52 vx(i, j, 0) = nx;
53 vy(i, j, 0) = ny;
54 const Real rho = st(i, j, c_rho);
55 st(i, j, c_mx) = rho * nx;
56 st(i, j, c_my) = rho * ny;
57 }
58};
59
66 int c_rho, c_E;
67 POPS_HD void operator()(int i, int j) const {
68 const Real rho = st(i, j, c_rho);
69 const Real ke_old =
70 Real(0.5) * rho * (vx_n(i, j, 0) * vx_n(i, j, 0) + vy_n(i, j, 0) * vy_n(i, j, 0));
71 const Real ke_new = Real(0.5) * rho * (vx(i, j, 0) * vx(i, j, 0) + vy(i, j, 0) * vy(i, j, 0));
72 st(i, j, c_E) += ke_new - ke_old;
73 }
74};
75
83 POPS_HD void operator()(int i, int j) const {
84 const Real rho = st(i, j, c_rho);
85 const Real inv = rho != Real(0) ? Real(1) / rho : Real(0);
86 vx(i, j, 0) = st(i, j, c_mx) * inv;
87 vy(i, j, 0) = st(i, j, c_my) * inv;
88 }
89};
90
96 int c_bz;
97 POPS_HD void operator()(int i, int j) const { bz_dst(i, j, 0) = bz_src(i, j, c_bz); }
98};
99
103inline void validate_krylov_params(Real tol, int max_iters, const char* who) {
104 if (!(tol > Real(0)) || max_iters < 1)
105 throw std::invalid_argument(std::string(who) + ": tol > 0, max_iters >= 1");
106}
107
108} // namespace detail
109
110} // namespace pops
Fab2D: single-grid data on a Box2D (in-house equivalent of AMReX's FArrayBox); Array4 / ConstArray4: ...
void validate_krylov_params(Real tol, int max_iters, const char *who)
Validates the Krylov tolerance / iteration budget shared by the Schur source steppers (historical con...
Definition schur_source_kernels.hpp:103
Definition amr_hierarchy.hpp:29
double Real
Definition types.hpp:30
WRITE POD handle (raw pointer + strides) over a Fab2D buffer, indexed by (i, j, c) IN GLOBAL INDICES ...
Definition fab2d.hpp:29
READ-only handle (const counterpart of Array4): same layout and same contract (POD device-copyable,...
Definition fab2d.hpp:44
Copies the B_z field (aux channel) into an internal scalar MultiFab (0 ghost is enough,...
Definition schur_source_kernels.hpp:93
POPS_HD void operator()(int i, int j) const
Definition schur_source_kernels.hpp:97
Array4 bz_dst
Definition schur_source_kernels.hpp:95
ConstArray4 bz_src
Definition schur_source_kernels.hpp:94
int c_bz
Definition schur_source_kernels.hpp:96
Extracts the velocity v = (mx, my) / rho from the state (Density / MomentumX / MomentumY roles) into ...
Definition schur_source_kernels.hpp:79
Array4 vy
Definition schur_source_kernels.hpp:81
int c_mx
Definition schur_source_kernels.hpp:82
POPS_HD void operator()(int i, int j) const
Definition schur_source_kernels.hpp:83
ConstArray4 st
Definition schur_source_kernels.hpp:80
int c_my
Definition schur_source_kernels.hpp:82
int c_rho
Definition schur_source_kernels.hpp:82
Array4 vx
Definition schur_source_kernels.hpp:81
Energy update: E^{n+1} = E^n + (1/2) rho^n (|v^{n+1}|^2 - |v^n|^2).
Definition schur_source_kernels.hpp:62
Array4 st
state (WRITE E; READ rho)
Definition schur_source_kernels.hpp:65
int c_E
Definition schur_source_kernels.hpp:66
ConstArray4 vy_n
v^n
Definition schur_source_kernels.hpp:63
ConstArray4 vx_n
Definition schur_source_kernels.hpp:63
int c_rho
Definition schur_source_kernels.hpp:66
ConstArray4 vx
Definition schur_source_kernels.hpp:64
POPS_HD void operator()(int i, int j) const
Definition schur_source_kernels.hpp:67
ConstArray4 vy
v^{n+1}
Definition schur_source_kernels.hpp:64
Linear extrapolation of a SCALAR field from the theta-stage to the full step: f^{n+1} = f^n + (1/thet...
Definition schur_source_kernels.hpp:32
ConstArray4 f_n
f^n
Definition schur_source_kernels.hpp:33
POPS_HD void operator()(int i, int j) const
Definition schur_source_kernels.hpp:36
Real inv_theta
1 / theta
Definition schur_source_kernels.hpp:35
Array4 f
IN: f^{n+theta}; OUT: f^{n+1}.
Definition schur_source_kernels.hpp:34
Linear extrapolation of the VELOCITY (vx, vy) from the theta-stage to the full step,...
Definition schur_source_kernels.hpp:43
int c_rho
Definition schur_source_kernels.hpp:48
POPS_HD void operator()(int i, int j) const
Definition schur_source_kernels.hpp:49
Array4 st
state (WRITE mx, my; READ rho)
Definition schur_source_kernels.hpp:46
Array4 vy
IN: v^{n+theta}; OUT: v^{n+1}.
Definition schur_source_kernels.hpp:45
int c_my
Definition schur_source_kernels.hpp:48
ConstArray4 vy_n
v^n
Definition schur_source_kernels.hpp:44
Array4 vx
Definition schur_source_kernels.hpp:45
Real inv_theta
1 / theta
Definition schur_source_kernels.hpp:47
ConstArray4 vx_n
Definition schur_source_kernels.hpp:44
int c_mx
Definition schur_source_kernels.hpp:48
Base scalar types and the POPS_HD macro (host+device portability).
#define POPS_HD
Definition types.hpp:25