include/pops/numerics/elliptic/eb/cut_fraction.hpp Source FileΒΆ

adc_cpp: include/pops/numerics/elliptic/eb/cut_fraction.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
cut_fraction.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pops/core/foundation/types.hpp> // Real, POPS_HD
4
20
21namespace pops {
22namespace detail {
23
34 if (ln < Real(0))
35 return h; // interior neighbor: no cut (full face)
36 Real th = lc / (lc - ln); // ls changes sign: linear cut fraction
37 if (th < Real(1e-3))
38 th = Real(1e-3); // anti division-by-zero guard (theta -> 0)
39 if (th > Real(1))
40 th = Real(1);
41 return th * h;
42}
43
63
75template <class LevelSet>
76POPS_HD inline CutFraction cut_fraction(const LevelSet& ls, Real xc, Real yc, Real dx, Real dy) {
77 const Real lc = ls(xc, yc);
78 const Real axm = cut_distance(lc, ls(xc - dx, yc), dx);
79 const Real axp = cut_distance(lc, ls(xc + dx, yc), dx);
80 const Real aym = cut_distance(lc, ls(xc, yc - dy), dy);
81 const Real ayp = cut_distance(lc, ls(xc, yc + dy), dy);
82 const Real alpha_xm = axm / dx;
83 const Real alpha_xp = axp / dx;
84 const Real alpha_ym = aym / dy;
85 const Real alpha_yp = ayp / dy;
86 // Volume fraction: average of the half-faces per axis (mean extent of the cell along each
87 // direction, normalized), product of the two axes. Far from the boundary -> 1; cut cell -> < 1.
88 const Real kappa = Real(0.5) * (alpha_xm + alpha_xp) * Real(0.5) * (alpha_ym + alpha_yp);
89 return CutFraction{axm, axp, aym, ayp, alpha_xm, alpha_xp, alpha_ym, alpha_yp, kappa};
90}
91
101
103 const Real sx = cf.axm + cf.axp;
104 const Real sy = cf.aym + cf.ayp;
106 Real(2) / (cf.axm * sx), // w_xm on p(i-1)
107 Real(2) / (cf.axp * sx), // w_xp on p(i+1)
108 Real(2) / (cf.aym * sy), // w_ym on p(i,j-1)
109 Real(2) / (cf.ayp * sy), // w_yp on p(i,j+1)
110 Real(2) / (cf.axm * cf.axp) + Real(2) / (cf.aym * cf.ayp)}; // w_diag
111}
112
113} // namespace detail
114} // namespace pops
POPS_HD CutFraction cut_fraction(const LevelSet &ls, Real xc, Real yc, Real dx, Real dy)
Computes the cut geometry of an ACTIVE cell (center (xc, yc) with ls < 0) from a level-set ls evaluat...
Definition cut_fraction.hpp:76
POPS_HD ShortleyWellerWeights shortley_weller(const CutFraction &cf)
Definition cut_fraction.hpp:102
POPS_HD Real cut_distance(Real lc, Real ln, Real h)
Cut distance of ONE face along a direction, starting from the active center (ls < 0).
Definition cut_fraction.hpp:33
Definition amr_hierarchy.hpp:29
double Real
Definition types.hpp:30
Geometric result of crossing a cut cell: 4 cut distances per face, the 4 apertures alpha_f normalized...
Definition cut_fraction.hpp:52
Real axm
cut distance of face x- (toward i-1), in [1e-3*dx, dx]
Definition cut_fraction.hpp:53
Real aym
cut distance of face y- (toward j-1)
Definition cut_fraction.hpp:55
Real alpha_yp
aperture of face y+ = ayp / dy
Definition cut_fraction.hpp:60
Real kappa
volume fraction of the cell (share in the active domain), in (0, 1]
Definition cut_fraction.hpp:61
Real ayp
cut distance of face y+ (toward j+1)
Definition cut_fraction.hpp:56
Real alpha_xm
aperture of face x- = axm / dx, in [1e-3, 1]
Definition cut_fraction.hpp:57
Real alpha_xp
aperture of face x+ = axp / dx
Definition cut_fraction.hpp:58
Real alpha_ym
aperture of face y- = aym / dy
Definition cut_fraction.hpp:59
Real axp
cut distance of face x+ (toward i+1)
Definition cut_fraction.hpp:54
Shortley-Weller weights (5-point cut-cell stencil) from the 4 cut distances.
Definition cut_fraction.hpp:98
Real w_yp
Definition cut_fraction.hpp:99
Real w_xp
Definition cut_fraction.hpp:99
Real w_diag
Definition cut_fraction.hpp:99
Real w_ym
Definition cut_fraction.hpp:99
Real w_xm
Definition cut_fraction.hpp:99
Base scalar types and the POPS_HD macro (host+device portability).
#define POPS_HD
Definition types.hpp:25