Alamo
QUICK.H
Go to the documentation of this file.
1//
2// This header defines :code:`Numeric::Advect::QUICK`, a third-order upwind-biased
3// advection operator for collocated cell-centered fields.
4//
5// The operator is written as a GPU-safe functor:
6//
7// .. code-block:: c++
8//
9// rhs = quick(phi, velocity, i, j, k, comp, DX, options, stencil);
10//
11// It computes face velocities by averaging neighboring cell-centered velocity
12// values, reconstructs face values of :math:`\phi` with the QUICK stencil, and
13// returns either :math:`-\nabla\cdot(\phi\mathbf{u})` or
14// :math:`-\nabla\cdot(\phi\mathbf{u}) + \phi\nabla\cdot\mathbf{u}` depending on
15// :code:`Numeric::Advect::Options::form`.
16//
17// This implementation assumes collocated cell-centered data:
18// :code:`phi_location = Set::HC::Cell` and
19// :code:`velocity_location = Set::HC::Cell`. It requires two ghost cells in each
20// coordinate direction.
21//
22
23#ifndef NUMERIC_ADVECT_QUICK_H
24#define NUMERIC_ADVECT_QUICK_H
25
26#include "Advect.H"
27
28namespace Numeric
29{
30namespace Advect
31{
32class QUICK
33{
34public:
35 static constexpr const char* name = "quick";
38
39 static void Parse(QUICK&, IO::ParmParse&) {}
40
41 AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE
42 int NGhost() const
43 {
44 return 2;
45 }
46
47 AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE
49 Set::Scalar up1,
50 Set::Scalar down1) const
51 {
52 return (-up2 + 6.0 * up1 + 3.0 * down1) / 8.0;
53 }
54
55 template<class Phi, class Velocity>
56 AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE
57 Set::Scalar operator()( Phi const& phi,
58 Velocity const& velocity,
59 int i, int j, int k,
60 int comp,
61 const Set::Scalar* DX,
62 Options options = {},
63 std::array<Numeric::StencilType, AMREX_SPACEDIM> stencil = Numeric::DefaultType) const
64 {
65 (void)stencil;
66
67 const Set::Scalar phi_c = phi(i,j,k,comp);
68 Set::Scalar div_phi_u = 0.0;
69 Set::Scalar div_u = 0.0;
70
71 Set::Scalar ux_xlo = 0.5 * (velocity(i-1,j,k,0) + velocity(i,j,k,0));
72 Set::Scalar ux_xhi = 0.5 * (velocity(i,j,k,0) + velocity(i+1,j,k,0));
73 Set::Scalar flux_xlo = ux_xlo * (ux_xlo >= 0.0 ?
74 Reconstruct(phi(i-2,j,k,comp), phi(i-1,j,k,comp), phi_c) :
75 Reconstruct(phi(i+1,j,k,comp), phi_c, phi(i-1,j,k,comp)));
76 Set::Scalar flux_xhi = ux_xhi * (ux_xhi >= 0.0 ?
77 Reconstruct(phi(i-1,j,k,comp), phi_c, phi(i+1,j,k,comp)) :
78 Reconstruct(phi(i+2,j,k,comp), phi(i+1,j,k,comp), phi_c));
79 div_phi_u += (flux_xhi - flux_xlo) / DX[0];
80 div_u += (ux_xhi - ux_xlo) / DX[0];
81
82#if AMREX_SPACEDIM >= 2
83 Set::Scalar uy_ylo = 0.5 * (velocity(i,j-1,k,1) + velocity(i,j,k,1));
84 Set::Scalar uy_yhi = 0.5 * (velocity(i,j,k,1) + velocity(i,j+1,k,1));
85 Set::Scalar flux_ylo = uy_ylo * (uy_ylo >= 0.0 ?
86 Reconstruct(phi(i,j-2,k,comp), phi(i,j-1,k,comp), phi_c) :
87 Reconstruct(phi(i,j+1,k,comp), phi_c, phi(i,j-1,k,comp)));
88 Set::Scalar flux_yhi = uy_yhi * (uy_yhi >= 0.0 ?
89 Reconstruct(phi(i,j-1,k,comp), phi_c, phi(i,j+1,k,comp)) :
90 Reconstruct(phi(i,j+2,k,comp), phi(i,j+1,k,comp), phi_c));
91 div_phi_u += (flux_yhi - flux_ylo) / DX[1];
92 div_u += (uy_yhi - uy_ylo) / DX[1];
93#endif
94
95#if AMREX_SPACEDIM == 3
96 Set::Scalar uz_zlo = 0.5 * (velocity(i,j,k-1,2) + velocity(i,j,k,2));
97 Set::Scalar uz_zhi = 0.5 * (velocity(i,j,k,2) + velocity(i,j,k+1,2));
98 Set::Scalar flux_zlo = uz_zlo * (uz_zlo >= 0.0 ?
99 Reconstruct(phi(i,j,k-2,comp), phi(i,j,k-1,comp), phi_c) :
100 Reconstruct(phi(i,j,k+1,comp), phi_c, phi(i,j,k-1,comp)));
101 Set::Scalar flux_zhi = uz_zhi * (uz_zhi >= 0.0 ?
102 Reconstruct(phi(i,j,k-1,comp), phi_c, phi(i,j,k+1,comp)) :
103 Reconstruct(phi(i,j,k+2,comp), phi(i,j,k+1,comp), phi_c));
104 div_phi_u += (flux_zhi - flux_zlo) / DX[2];
105 div_u += (uz_zhi - uz_zlo) / DX[2];
106#endif
107
108 if (options.form == Form::Conservative) return -div_phi_u;
109 return -div_phi_u + phi_c * div_u;
110 }
111
112 template<class Phi, class Velocity>
113 AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE
114 Set::Scalar Scalar( Phi const& phi,
115 Velocity const& velocity,
116 int i, int j, int k,
117 int comp,
118 const Set::Scalar* DX,
119 Options options = {},
120 std::array<Numeric::StencilType, AMREX_SPACEDIM> stencil = Numeric::DefaultType) const
121 {
122 return (*this)(phi, velocity, i, j, k, comp, DX, options, stencil);
123 }
124};
125}
126}
127
128#endif
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Set::Scalar Scalar(Phi const &phi, Velocity const &velocity, int i, int j, int k, int comp, const Set::Scalar *DX, Options options={}, std::array< Numeric::StencilType, AMREX_SPACEDIM > stencil=Numeric::DefaultType) const
Definition QUICK.H:114
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Set::Scalar Reconstruct(Set::Scalar up2, Set::Scalar up1, Set::Scalar down1) const
Definition QUICK.H:48
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE int NGhost() const
Definition QUICK.H:42
static constexpr Set::HC phi_location
Definition QUICK.H:36
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE Set::Scalar operator()(Phi const &phi, Velocity const &velocity, int i, int j, int k, int comp, const Set::Scalar *DX, Options options={}, std::array< Numeric::StencilType, AMREX_SPACEDIM > stencil=Numeric::DefaultType) const
Definition QUICK.H:57
static void Parse(QUICK &, IO::ParmParse &)
Definition QUICK.H:39
static constexpr Set::HC velocity_location
Definition QUICK.H:37
static constexpr const char * name
Definition QUICK.H:35
This namespace contains some numerical tools.
Definition Advect.H:14
static std::array< StencilType, AMREX_SPACEDIM > DefaultType
Definition Stencil.H:23
amrex::Real Scalar
Definition Base.H:19
Hypercube
Definition Set.H:31
@ Cell
Definition Set.H:32