ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_UpdateWSubsidence_SineMassFlux.H
Go to the documentation of this file.
1  // Horizontally averaged density per level, summed over all boxes and ranks
2  Gpu::DeviceVector<Real> rho_d(khi+1, zero);
3  auto rho_arr = rho_d.data();
4  for (MFIter mfi(state, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
5  const auto &box = mfi.tilebox();
6  auto state_arr = state.const_array(mfi);
7  ParallelFor(box, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
8  Gpu::Atomic::AddNoRet(&rho_arr[k], state_arr(i, j, k, Rho_comp));
9  });
10  }
11 
12  Vector<Real> rho_h(khi+1, zero);
13  Gpu::copy(Gpu::deviceToHost, rho_d.begin(), rho_d.end(), rho_h.begin());
14  ParallelDescriptor::ReduceRealSum(rho_h.dataPtr(), khi+1);
15  {
16  const Box& dom = geom.Domain();
17  const Real inv_ncell_xy = one / static_cast<Real>(dom.length(0)*dom.length(1));
18  for (int k = 0; k <= khi; k++) { rho_h[k] *= inv_ncell_xy; }
19  }
20 
21  // Staggered rho via linear interpolation
22  Vector<Real> rho_stag(khi+2, zero);
23  rho_stag[0] = amrex::Real(1.5)*rho_h[0] - myhalf*rho_h[1];
24  rho_stag[khi+1] = amrex::Real(1.5)*rho_h[khi] - myhalf*rho_h[khi-1];
25  for (int k = 1; k <= khi; k++) {
26  rho_stag[k] = myhalf*(rho_h[k-1]+rho_h[k]);
27  }
28 
29  // Sinusoidal mass flux: w = 2*sin(pi*t/amrex::Real(600))/rho for t < 600
30  for (int k = 0; k <= khi+1; k++) {
31  if (time < amrex::Real(600)) {
32  Real real_time = static_cast<Real>(time) / amrex::Real(600);
33  wbar[k] = two*std::sin(PI*real_time) / rho_stag[k];
34  } else {
35  wbar[k] = zero;
36  }
37  }
38 
39  // Copy from host version to device version
40  amrex::Gpu::copy(amrex::Gpu::hostToDevice, wbar.begin(), wbar.end(), d_wbar.begin());
constexpr amrex::Real two
Definition: ERF_Constants.H:10
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
constexpr amrex::Real PI
Definition: ERF_Constants.H:42
@ wbar
Definition: ERF_DataStruct.H:152
#define Rho_comp
Definition: ERF_IndexDefines.H:36
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
auto rho_arr
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:3
Vector< Real > rho_h(khi+1, zero)
rho_stag[0]
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:23
Gpu::DeviceVector< Real > rho_d(khi+1, zero)
const Real inv_ncell_xy
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:17