|
| 1 | +//======================================================================================== |
| 2 | +// AthenaXXX astrophysical plasma code |
| 3 | +// Copyright(C) 2020 James M. Stone <jmstone@ias.edu> and the Athena code team |
| 4 | +// Licensed under the 3-clause BSD License (the "LICENSE") |
| 5 | +//======================================================================================== |
| 6 | +#ifndef RECON_MIXED_PPM_PLM_HPP_ |
| 7 | +#define RECON_MIXED_PPM_PLM_HPP_ |
| 8 | +//! \file reconstruct_mixed_ppm_plm.hpp |
| 9 | +// \brief Mixed reconstruction: PPM for hydro variables (mass, mom1-3, energy), |
| 10 | +// PLM for magnetic fields (B1,B2,B3). Requires that PPM() and PLM() are |
| 11 | +// already defined elsewhere in the same compilation unit. |
| 12 | +// This version only works with uniform mesh spacing |
| 13 | + |
| 14 | +#include <parthenon/parthenon.hpp> |
| 15 | + |
| 16 | +#include "plm_simple.hpp" |
| 17 | +#include "ppm_simple.hpp" |
| 18 | + |
| 19 | +using parthenon::ScratchPad2D; |
| 20 | + |
| 21 | +//---------------------------------------------------------------------------------------- |
| 22 | +//! \fn Reconstruct<Reconstruction::mixed_ppm_plm, int DIR>() |
| 23 | +// \brief Wrapper for mixed PPM/PLM reconstruction. Uses PPM for variable indices |
| 24 | +// 0-4 (density, momenta, energy) and PLM for indices 5-7 (Bcc1..Bcc3). |
| 25 | +// Matches the style and structure of PLM and PPM reconstruction files. |
| 26 | + |
| 27 | +template <Reconstruction recon, int XNDIR> |
| 28 | +KOKKOS_INLINE_FUNCTION |
| 29 | + typename std::enable_if<recon == Reconstruction::mixed_ppm_plm, void>::type |
| 30 | + Reconstruct(parthenon::team_mbr_t const &member, const int k, const int j, |
| 31 | + const int il, const int iu, const parthenon::VariablePack<Real> &q, |
| 32 | + ScratchPad2D<Real> &ql, ScratchPad2D<Real> &qr) { |
| 33 | + const auto nvar = q.GetDim(4); |
| 34 | + |
| 35 | + // Variable index mapping |
| 36 | + constexpr int ppm_lo = 0; // density |
| 37 | + constexpr int ppm_hi = 4; // energy |
| 38 | + constexpr int plm_lo = 5; // Bcc1 |
| 39 | + constexpr int plm_hi = 7; // Bcc3 |
| 40 | + |
| 41 | + for (auto n = 0; n < nvar; ++n) { |
| 42 | + parthenon::par_for_inner(member, il, iu, [&](const int i) { |
| 43 | + //------------------------------------------------------------------------ |
| 44 | + // PPM branch: density, momentum1-3, energy |
| 45 | + //------------------------------------------------------------------------ |
| 46 | + if (n >= ppm_lo && n <= ppm_hi) { |
| 47 | + if constexpr (XNDIR == parthenon::X1DIR) { |
| 48 | + PPM(q(n, k, j, i - 2), q(n, k, j, i - 1), q(n, k, j, i), q(n, k, j, i + 1), |
| 49 | + q(n, k, j, i + 2), ql(n, i + 1), qr(n, i)); |
| 50 | + } else if constexpr (XNDIR == parthenon::X2DIR) { |
| 51 | + PPM(q(n, k, j - 2, i), q(n, k, j - 1, i), q(n, k, j, i), q(n, k, j + 1, i), |
| 52 | + q(n, k, j + 2, i), ql(n, i), qr(n, i)); |
| 53 | + } else if constexpr (XNDIR == parthenon::X3DIR) { |
| 54 | + PPM(q(n, k - 2, j, i), q(n, k - 1, j, i), q(n, k, j, i), q(n, k + 1, j, i), |
| 55 | + q(n, k + 2, j, i), ql(n, i), qr(n, i)); |
| 56 | + } else { |
| 57 | + PARTHENON_FAIL("Unknown direction for mixed PPM branch."); |
| 58 | + } |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + //------------------------------------------------------------------------ |
| 63 | + // PLM branch: magnetic fields B1,B2,B3 |
| 64 | + //------------------------------------------------------------------------ |
| 65 | + if (n >= plm_lo && n <= plm_hi) { |
| 66 | + if constexpr (XNDIR == parthenon::X1DIR) { |
| 67 | + PLM(q(n, k, j, i - 1), q(n, k, j, i), q(n, k, j, i + 1), ql(n, i + 1), |
| 68 | + qr(n, i)); |
| 69 | + } else if constexpr (XNDIR == parthenon::X2DIR) { |
| 70 | + PLM(q(n, k, j - 1, i), q(n, k, j, i), q(n, k, j + 1, i), ql(n, i), qr(n, i)); |
| 71 | + } else if constexpr (XNDIR == parthenon::X3DIR) { |
| 72 | + PLM(q(n, k - 1, j, i), q(n, k, j, i), q(n, k + 1, j, i), ql(n, i), qr(n, i)); |
| 73 | + } else { |
| 74 | + PARTHENON_FAIL("Unknown direction for mixed PLM branch."); |
| 75 | + } |
| 76 | + return; |
| 77 | + } |
| 78 | + |
| 79 | + //------------------------------------------------------------------------ |
| 80 | + // Default fallback: PPM |
| 81 | + //------------------------------------------------------------------------ |
| 82 | + if constexpr (XNDIR == parthenon::X1DIR) { |
| 83 | + PPM(q(n, k, j, i - 2), q(n, k, j, i - 1), q(n, k, j, i), q(n, k, j, i + 1), |
| 84 | + q(n, k, j, i + 2), ql(n, i + 1), qr(n, i)); |
| 85 | + } else if constexpr (XNDIR == parthenon::X2DIR) { |
| 86 | + PPM(q(n, k, j - 2, i), q(n, k, j - 1, i), q(n, k, j, i), q(n, k, j + 1, i), |
| 87 | + q(n, k, j + 2, i), ql(n, i), qr(n, i)); |
| 88 | + } else if constexpr (XNDIR == parthenon::X3DIR) { |
| 89 | + PPM(q(n, k - 2, j, i), q(n, k - 1, j, i), q(n, k, j, i), q(n, k + 1, j, i), |
| 90 | + q(n, k + 2, j, i), ql(n, i), qr(n, i)); |
| 91 | + } |
| 92 | + }); // par_for_inner |
| 93 | + } // for n |
| 94 | +} |
| 95 | + |
| 96 | +#endif // RECON_MIXED_PPM_PLM_HPP_ |
0 commit comments