15#ifndef HYDRO_PLIC_NORMALS_K_H
16#define HYDRO_PLIC_NORMALS_K_H
37#if AMREX_SPACEDIM == 3
50 amrex::Real mm1 = F(i - 1, j - 1, k - 1) + F(i - 1, j - 1, k + 1) + F(i - 1, j + 1, k - 1) +
51 F(i - 1, j + 1, k + 1) +
52 2.0_rt * (F(i - 1, j - 1, k) + F(i - 1, j + 1, k) + F(i - 1, j, k - 1) +
54 4.0_rt * F(i - 1, j, k);
55 amrex::Real mm2 = F(i + 1, j - 1, k - 1) + F(i + 1, j - 1, k + 1) + F(i + 1, j + 1, k - 1) +
56 F(i + 1, j + 1, k + 1) +
57 2.0_rt * (F(i + 1, j - 1, k) + F(i + 1, j + 1, k) + F(i + 1, j, k - 1) +
59 4.0_rt * F(i + 1, j, k);
62 mm1 = F(i - 1, j - 1, k - 1) + F(i - 1, j - 1, k + 1) + F(i + 1, j - 1, k - 1) +
63 F(i + 1, j - 1, k + 1) +
65 (F(i - 1, j - 1, k) + F(i + 1, j - 1, k) + F(i, j - 1, k - 1) + F(i, j - 1, k + 1)) +
66 4.0_rt * F(i, j - 1, k);
67 mm2 = F(i - 1, j + 1, k - 1) + F(i - 1, j + 1, k + 1) + F(i + 1, j + 1, k - 1) +
68 F(i + 1, j + 1, k + 1) +
70 (F(i - 1, j + 1, k) + F(i + 1, j + 1, k) + F(i, j + 1, k - 1) + F(i, j + 1, k + 1)) +
71 4.0_rt * F(i, j + 1, k);
74 mm1 = F(i - 1, j - 1, k - 1) + F(i - 1, j + 1, k - 1) + F(i + 1, j - 1, k - 1) +
75 F(i + 1, j + 1, k - 1) +
77 (F(i - 1, j, k - 1) + F(i + 1, j, k - 1) + F(i, j - 1, k - 1) + F(i, j + 1, k - 1)) +
78 4.0_rt * F(i, j, k - 1);
79 mm2 = F(i - 1, j - 1, k + 1) + F(i - 1, j + 1, k + 1) + F(i + 1, j - 1, k + 1) +
80 F(i + 1, j + 1, k + 1) +
82 (F(i - 1, j, k + 1) + F(i + 1, j, k + 1) + F(i, j - 1, k + 1) + F(i, j + 1, k + 1)) +
83 4.0_rt * F(i, j, k + 1);
104 amrex::Real m1 = F(i - 1, j, k - 1) + F(i - 1, j, k + 1) + F(i - 1, j - 1, k) +
105 F(i - 1, j + 1, k) + F(i - 1, j, k);
106 amrex::Real m2 = F(i + 1, j, k - 1) + F(i + 1, j, k + 1) + F(i + 1, j - 1, k) +
107 F(i + 1, j + 1, k) + F(i + 1, j, k);
108 m[0][0] = (m1 > m2) ? 1.0_rt : -1.0_rt;
109 m1 = F(i - 1, j - 1, k) + F(i + 1, j - 1, k) + F(i, j - 1, k);
110 m2 = F(i - 1, j + 1, k) + F(i + 1, j + 1, k) + F(i, j + 1, k);
111 m[0][1] = 0.5_rt * (m1 - m2);
112 m1 = F(i - 1, j, k - 1) + F(i + 1, j, k - 1) + F(i, j, k - 1);
113 m2 = F(i - 1, j, k + 1) + F(i + 1, j, k + 1) + F(i, j, k + 1);
114 m[0][2] = 0.5_rt * (m1 - m2);
117 m1 = F(i - 1, j - 1, k) + F(i - 1, j + 1, k) + F(i - 1, j, k);
118 m2 = F(i + 1, j - 1, k) + F(i + 1, j + 1, k) + F(i + 1, j, k);
119 m[1][0] = 0.5_rt * (m1 - m2);
120 m1 = F(i, j - 1, k - 1) + F(i, j - 1, k + 1) + F(i + 1, j - 1, k) + F(i - 1, j - 1, k) +
122 m2 = F(i, j + 1, k - 1) + F(i, j + 1, k + 1) + F(i + 1, j + 1, k) + F(i - 1, j + 1, k) +
124 m[1][1] = (m1 > m2) ? 1.0_rt : -1.0_rt;
125 m1 = F(i, j - 1, k - 1) + F(i, j, k - 1) + F(i, j + 1, k - 1);
126 m2 = F(i, j - 1, k + 1) + F(i, j, k + 1) + F(i, j + 1, k + 1);
127 m[1][2] = 0.5_rt * (m1 - m2);
130 m1 = F(i - 1, j, k - 1) + F(i - 1, j, k + 1) + F(i - 1, j, k);
131 m2 = F(i + 1, j, k - 1) + F(i + 1, j, k + 1) + F(i + 1, j, k);
132 m[2][0] = 0.5_rt * (m1 - m2);
133 m1 = F(i, j - 1, k - 1) + F(i, j - 1, k + 1) + F(i, j - 1, k);
134 m2 = F(i, j + 1, k - 1) + F(i, j + 1, k + 1) + F(i, j + 1, k);
135 m[2][1] = 0.5_rt * (m1 - m2);
136 m1 = F(i - 1, j, k - 1) + F(i + 1, j, k - 1) + F(i, j - 1, k - 1) + F(i, j + 1, k - 1) +
138 m2 = F(i - 1, j, k + 1) + F(i + 1, j, k + 1) + F(i, j - 1, k + 1) + F(i, j + 1, k + 1) +
140 m[2][2] = (m1 > m2) ? 1.0_rt : -1.0_rt;
144 for (
int c = 0; c < 3; ++c) {
145 const amrex::Real t = std::abs(m[c][0]) + std::abs(m[c][1]) + std::abs(m[c][2]);
146 for (
int d = 0; d < 3; ++d) {
152 if (std::abs(m[1][1]) > t0) {
153 t0 = std::abs(m[1][1]);
156 if (std::abs(m[2][2]) > t0) {
161 constexpr amrex::Real tiny = std::numeric_limits<amrex::Real>::epsilon();
163 amrex::Real t = std::abs(m[3][0]) + std::abs(m[3][1]) + std::abs(m[3][2]) + tiny;
164 for (
int d = 0; d < 3; ++d) {
170 t =
amrex::max(std::abs(m[3][0]), std::abs(m[3][1]), std::abs(m[3][2]));
171 if (std::abs(m[cn][cn]) > t && t > 0.0_rt) {
192 mx = (F(i - 1, j - 1, k) + 2.0_rt * F(i - 1, j, k) + F(i - 1, j + 1, k)) -
193 (F(i + 1, j - 1, k) + 2.0_rt * F(i + 1, j, k) + F(i + 1, j + 1, k));
194 my = (F(i - 1, j - 1, k) + 2.0_rt * F(i, j - 1, k) + F(i + 1, j - 1, k)) -
195 (F(i - 1, j + 1, k) + 2.0_rt * F(i, j + 1, k) + F(i + 1, j + 1, k));
215 const amrex::Real cL = F(i - 1, j - 1, k) + F(i - 1, j, k) + F(i - 1, j + 1, k);
216 const amrex::Real cR = F(i + 1, j - 1, k) + F(i + 1, j, k) + F(i + 1, j + 1, k);
217 const amrex::Real rB = F(i - 1, j - 1, k) + F(i, j - 1, k) + F(i + 1, j - 1, k);
218 const amrex::Real rT = F(i - 1, j + 1, k) + F(i, j + 1, k) + F(i + 1, j + 1, k);
221 m[0][0] = (cL > cR) ? 1.0_rt : -1.0_rt;
222 m[0][1] = 0.5_rt * (rB - rT);
224 m[1][0] = 0.5_rt * (cL - cR);
225 m[1][1] = (rB > rT) ? 1.0_rt : -1.0_rt;
227 for (
int c = 0; c < 2; ++c) {
228 const amrex::Real t = std::abs(m[c][0]) + std::abs(m[c][1]);
232 int cn = (std::abs(m[1][1]) > std::abs(m[0][0])) ? 1 : 0;
234 constexpr amrex::Real tiny = std::numeric_limits<amrex::Real>::epsilon();
237 amrex::Real t = std::abs(m[2][0]) + std::abs(m[2][1]) + tiny;
241 t =
amrex::max(std::abs(m[2][0]), std::abs(m[2][1]));
242 if (std::abs(m[cn][cn]) > t && t > 0.0_rt) {
278 const auto liquid = [&](
const int s) {
280 return (sigma > 0.0_rt) ? f : 1.0_rt - f;
298 if (!column(iv, Hc)) {
302 for (
int t = 0; t < AMREX_SPACEDIM; ++t) {
309 if (!column(iv - et, Hm) || !column(iv + et, Hp)) {
313 mt[t] = 0.5_rt * (Hm - Hp);
316 for (
int a = 0; a < 3; ++a) {
386 const amrex::Real am[3] = {std::abs(mx), std::abs(my), std::abs(mz)};
387 int d = (am[1] > am[0]) ? 1 : 0;
388 if (AMREX_SPACEDIM == 3 && am[2] > am[d]) {
407template <
typename Normal>
416 Normal::normal(i, j, k, F, mx, my, mz);
419 amrex::Real norm = std::abs(mx) + std::abs(my) + std::abs(mz);
420 if (norm <= std::numeric_limits<amrex::Real>::epsilon()) {
430 alpha =
volume_intercept(std::abs(mx), std::abs(my), std::abs(mz), F(i, j, k));
437 amrex::Abort(
"Unknown reconstruction: " + reconstruction +
438 " (expected youngs, myc or myc_height)");
447template <
typename Fn>
449 if (reconstruction ==
"youngs") {
450 return std::forward<Fn>(fn)(
Youngs{});
452 if (reconstruction ==
"myc") {
455 if (reconstruction !=
"myc_height") {
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
#define AMREX_D_DECL(a, b, c)
__host__ static __device__ constexpr IntVectND< dim > TheDimensionVector(int d) noexcept
ArrayND< T, 4, true > Array4
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition hydro_plic.cpp:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void myc_normal(const int i, const int j, const int k, amrex::Array4< amrex::Real const > const &F, amrex::Real &mx, amrex::Real &my, amrex::Real &mz)
Mixed Youngs-Centered normal (2D). Returns an L1-normalized normal pointing out of the liquid.
Definition hydro_plic_normals_K.H:203
void unknown_reconstruction(std::string const &reconstruction)
Definition hydro_plic_normals_K.H:436
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void fit_plane(const int i, const int j, const int k, amrex::Array4< amrex::Real const > const &F, amrex::Real &mx, amrex::Real &my, amrex::Real &mz, amrex::Real &alpha)
Reconstruct the PLIC plane m.x = alpha in cell (i,j,k), in unit-cube cell coordinates with sum|m| = 1...
Definition hydro_plic_normals_K.H:408
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void youngs_normal(const int i, const int j, const int k, amrex::Array4< amrex::Real const > const &F, amrex::Real &mx, amrex::Real &my, amrex::Real &mz)
Youngs' finite-difference normal on the 9-point stencil, scaled by -8 (i.e. m = -8 grad F).
Definition hydro_plic_normals_K.H:185
decltype(auto) dispatch_normal(std::string const &reconstruction, Fn &&fn)
Call fn with the normal scheme of a reconstruction name, as fn(Normal{}), and return what it returns....
Definition hydro_plic_normals_K.H:448
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool height_normal(const int i, const int j, const int k, const int d, amrex::Array4< amrex::Real const > const &F, amrex::Real m[3])
Height-function normal with height direction d: the liquid heights of the 7-cell columns through (i,...
Definition hydro_plic_normals_K.H:265
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real volume_intercept(const amrex::Real b1, const amrex::Real b2, const amrex::Real b3, const amrex::Real volF)
Analytic plane constant alpha such that the region m1*x1 + m2*x2 + m3*x3 <= alpha of the unit cube ha...
Definition hydro_plic_K.H:84
static constexpr int hf_half
Definition hydro_plic_normals_K.H:29
static constexpr amrex::Real hf_pure_tol
Definition hydro_plic_normals_K.H:34
__host__ __device__ void ignore_unused(const Ts &...)
void Abort(const std::string &msg)
The height-function normal along the dominant direction of the Mixed Youngs-Centered normal,...
Definition hydro_plic_normals_K.H:374
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE void normal(const int i, const int j, const int k, amrex::Array4< amrex::Real const > const &F, amrex::Real &mx, amrex::Real &my, amrex::Real &mz) noexcept
Definition hydro_plic_normals_K.H:378
static constexpr int stencil
Definition hydro_plic_normals_K.H:375
Mixed Youngs-Centered normal (Aulisa et al., JCP 225, 2007).
Definition hydro_plic_normals_K.H:354
static constexpr int stencil
Definition hydro_plic_normals_K.H:355
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE void normal(const int i, const int j, const int k, amrex::Array4< amrex::Real const > const &F, amrex::Real &mx, amrex::Real &my, amrex::Real &mz) noexcept
Definition hydro_plic_normals_K.H:358
Youngs' finite-difference normal.
Definition hydro_plic_normals_K.H:338
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE void normal(const int i, const int j, const int k, amrex::Array4< amrex::Real const > const &F, amrex::Real &mx, amrex::Real &my, amrex::Real &mz) noexcept
Definition hydro_plic_normals_K.H:342
static constexpr int stencil
Definition hydro_plic_normals_K.H:339