ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_AdvectionSrcForScalars.H
Go to the documentation of this file.
1 #include <ERF_IndexDefines.H>
2 #include <ERF_Interpolation.H>
3 
4 /**
5  * Wrapper function for computing the advective tendency w/ spatial order > 2.
6  */
7 template<typename InterpType_H, typename InterpType_V>
8 void
9 AdvectionSrcForScalarsWrapper (const amrex::Box& bx,
10  const int& ncomp, const int& icomp,
11  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM> flx_arr,
12  const amrex::Array4<const amrex::Real>& cell_prim,
13  const amrex::Array4<const amrex::Real>& avg_xmom,
14  const amrex::Array4<const amrex::Real>& avg_ymom,
15  const amrex::Array4<const amrex::Real>& avg_zmom,
16  const amrex::Real horiz_upw_frac,
17  const amrex::Real vert_upw_frac)
18 {
19  // Instantiate structs for vert/horiz interp
20  InterpType_H interp_prim_h(cell_prim);
21  InterpType_V interp_prim_v(cell_prim);
22 
23  const amrex::Box xbx = amrex::surroundingNodes(bx,0);
24  const amrex::Box ybx = amrex::surroundingNodes(bx,1);
25  const amrex::Box zbx = amrex::surroundingNodes(bx,2);
26 
27  amrex::ParallelFor(xbx, ncomp,[=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
28  {
29  const int cons_index = icomp + n;
30  const int prim_index = cons_index - 1;
31 
32  amrex::Real interpx(0.);
33 
34  interp_prim_h.InterpolateInX(i,j,k,prim_index,interpx,avg_xmom(i ,j ,k ),horiz_upw_frac);
35  (flx_arr[0])(i,j,k,cons_index) = avg_xmom(i,j,k) * interpx;
36  });
37  amrex::ParallelFor(ybx, ncomp,[=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
38  {
39  const int cons_index = icomp + n;
40  const int prim_index = cons_index - 1;
41 
42  amrex::Real interpy(0.);
43  interp_prim_h.InterpolateInY(i,j,k,prim_index,interpy,avg_ymom(i ,j ,k ),horiz_upw_frac);
44 
45  (flx_arr[1])(i,j,k,cons_index) = avg_ymom(i,j,k) * interpy;
46  });
47  amrex::ParallelFor(zbx, ncomp,[=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
48  {
49  const int cons_index = icomp + n;
50  const int prim_index = cons_index - 1;
51 
52  amrex::Real interpz(0.);
53 
54  interp_prim_v.InterpolateInZ(i,j,k,prim_index,interpz,avg_zmom(i ,j ,k ),vert_upw_frac);
55 
56  (flx_arr[2])(i,j,k,cons_index) = avg_zmom(i,j,k) * interpz;
57  });
58 }
59 
60 /**
61  * Wrapper function for templating the vertical advective tendency w/ spatial order > 2.
62  */
63 template<typename InterpType_H>
64 void
65 AdvectionSrcForScalarsVert (const amrex::Box& bx,
66  const int& ncomp, const int& icomp,
67  const amrex::GpuArray<const amrex::Array4<amrex::Real>, AMREX_SPACEDIM> flx_arr,
68  const amrex::Array4<const amrex::Real>& cell_prim,
69  const amrex::Array4<const amrex::Real>& avg_xmom,
70  const amrex::Array4<const amrex::Real>& avg_ymom,
71  const amrex::Array4<const amrex::Real>& avg_zmom,
72  const amrex::Real horiz_upw_frac,
73  const amrex::Real vert_upw_frac,
74  const AdvType vert_adv_type)
75 {
76  switch(vert_adv_type) {
78  AdvectionSrcForScalarsWrapper<InterpType_H,CENTERED2>(bx, ncomp, icomp,
79  flx_arr, cell_prim,
80  avg_xmom, avg_ymom, avg_zmom,
81  horiz_upw_frac, vert_upw_frac);
82  break;
84  AdvectionSrcForScalarsWrapper<InterpType_H,UPWIND3>(bx, ncomp, icomp,
85  flx_arr, cell_prim,
86  avg_xmom, avg_ymom, avg_zmom,
87  horiz_upw_frac, vert_upw_frac);
88  break;
90  AdvectionSrcForScalarsWrapper<InterpType_H,CENTERED4>(bx, ncomp, icomp,
91  flx_arr, cell_prim,
92  avg_xmom, avg_ymom, avg_zmom,
93  horiz_upw_frac, vert_upw_frac);
94  break;
96  AdvectionSrcForScalarsWrapper<InterpType_H,UPWIND5>(bx, ncomp, icomp,
97  flx_arr, cell_prim,
98  avg_xmom, avg_ymom, avg_zmom,
99  horiz_upw_frac, vert_upw_frac);
100  break;
102  AdvectionSrcForScalarsWrapper<InterpType_H,CENTERED6>(bx, ncomp, icomp,
103  flx_arr, cell_prim,
104  avg_xmom, avg_ymom, avg_zmom,
105  horiz_upw_frac, vert_upw_frac);
106  break;
107  default:
108  AMREX_ASSERT_WITH_MESSAGE(false, "Unknown vertical advection scheme!");
109  }
110 }
void AdvectionSrcForScalarsWrapper(const amrex::Box &bx, const int &ncomp, const int &icomp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > flx_arr, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac)
Definition: ERF_AdvectionSrcForScalars.H:9
void AdvectionSrcForScalarsVert(const amrex::Box &bx, const int &ncomp, const int &icomp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > flx_arr, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, const AdvType vert_adv_type)
Definition: ERF_AdvectionSrcForScalars.H:65
AdvType
Definition: ERF_IndexDefines.H:191
@ Centered_4th
@ Centered_6th
@ Centered_2nd