Alamo
Centered.H
Go to the documentation of this file.
1//
2// This header defines :code:`Numeric::Advect::Centered`, a second-order centered
3// finite-volume 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 = centered(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` by arithmetic averaging, 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 one ghost cell in each
20// coordinate direction.
21//
22
23#ifndef NUMERIC_ADVECT_CENTERED_H
24#define NUMERIC_ADVECT_CENTERED_H
25
26#include "Advect.H"
27
28namespace Numeric
29{
30namespace Advect
31{
33{
34public:
35 static constexpr const char* name = "centered";
38
39 static void Parse(Centered&, IO::ParmParse&) {}
40
41 AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE
42 int NGhost() const
43 {
44 return 1;
45 }
46
47 template<class Phi, class Velocity>
48 AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE
49 Set::Scalar operator()( Phi const& phi,
50 Velocity const& velocity,
51 int i, int j, int k,
52 int comp,
53 const Set::Scalar* DX,
54 Options options = {},
55 std::array<Numeric::StencilType, AMREX_SPACEDIM> stencil = Numeric::DefaultType) const
56 {
57 (void)stencil;
58
59 const Set::Scalar phi_c = phi(i,j,k,comp);
60 Set::Scalar div_phi_u = 0.0;
61 Set::Scalar div_u = 0.0;
62
63 Set::Scalar ux_xlo = 0.5 * (velocity(i-1,j,k,0) + velocity(i,j,k,0));
64 Set::Scalar ux_xhi = 0.5 * (velocity(i,j,k,0) + velocity(i+1,j,k,0));
65 Set::Scalar flux_xlo = ux_xlo * 0.5 * (phi(i-1,j,k,comp) + phi_c);
66 Set::Scalar flux_xhi = ux_xhi * 0.5 * (phi_c + phi(i+1,j,k,comp));
67 div_phi_u += (flux_xhi - flux_xlo) / DX[0];
68 div_u += (ux_xhi - ux_xlo) / DX[0];
69
70#if AMREX_SPACEDIM >= 2
71 Set::Scalar uy_ylo = 0.5 * (velocity(i,j-1,k,1) + velocity(i,j,k,1));
72 Set::Scalar uy_yhi = 0.5 * (velocity(i,j,k,1) + velocity(i,j+1,k,1));
73 Set::Scalar flux_ylo = uy_ylo * 0.5 * (phi(i,j-1,k,comp) + phi_c);
74 Set::Scalar flux_yhi = uy_yhi * 0.5 * (phi_c + phi(i,j+1,k,comp));
75 div_phi_u += (flux_yhi - flux_ylo) / DX[1];
76 div_u += (uy_yhi - uy_ylo) / DX[1];
77#endif
78
79#if AMREX_SPACEDIM == 3
80 Set::Scalar uz_zlo = 0.5 * (velocity(i,j,k-1,2) + velocity(i,j,k,2));
81 Set::Scalar uz_zhi = 0.5 * (velocity(i,j,k,2) + velocity(i,j,k+1,2));
82 Set::Scalar flux_zlo = uz_zlo * 0.5 * (phi(i,j,k-1,comp) + phi_c);
83 Set::Scalar flux_zhi = uz_zhi * 0.5 * (phi_c + phi(i,j,k+1,comp));
84 div_phi_u += (flux_zhi - flux_zlo) / DX[2];
85 div_u += (uz_zhi - uz_zlo) / DX[2];
86#endif
87
88 if (options.form == Form::Conservative) return -div_phi_u;
89 return -div_phi_u + phi_c * div_u;
90 }
91
92 template<class Phi, class Velocity>
93 AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE
94 Set::Scalar Scalar( Phi const& phi,
95 Velocity const& velocity,
96 int i, int j, int k,
97 int comp,
98 const Set::Scalar* DX,
99 Options options = {},
100 std::array<Numeric::StencilType, AMREX_SPACEDIM> stencil = Numeric::DefaultType) const
101 {
102 return (*this)(phi, velocity, i, j, k, comp, DX, options, stencil);
103 }
104};
105}
106}
107
108#endif
static constexpr Set::HC phi_location
Definition Centered.H:36
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE int NGhost() const
Definition Centered.H:42
static constexpr const char * name
Definition Centered.H:35
static constexpr Set::HC velocity_location
Definition Centered.H:37
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 Centered.H:49
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 Centered.H:94
static void Parse(Centered &, IO::ParmParse &)
Definition Centered.H:39
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