ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_UpdateWSubsidence_SineMassFlux.H
Go to the documentation of this file.
1  // Compute density from state on device, copy to host
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  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 
15  // Staggered rho via linear interpolation
16  Vector<Real> rho_stag(khi+2, zero);
17  rho_stag[0] = amrex::Real(1.5)*rho_h[0] - myhalf*rho_h[1];
18  rho_stag[khi+1] = amrex::Real(1.5)*rho_h[khi] - myhalf*rho_h[khi-1];
19  for (int k = 1; k <= khi; k++) {
20  rho_stag[k] = myhalf*(rho_h[k-1]+rho_h[k]);
21  }
22 
23  // Sinusoidal mass flux: w = 2*sin(pi*t/600)/rho for t < 600
24  for (int k = 0; k <= khi+1; k++) {
25  if (time < 600) {
26  wbar[k] = 2*sin(PI*time/600)/rho_stag[k];
27  } else {
28  wbar[k] = zero;
29  }
30  }
31 
32  // Copy from host version to device version
33  amrex::Gpu::copy(amrex::Gpu::hostToDevice, wbar.begin(), wbar.end(), d_wbar.begin());
constexpr amrex::Real zero
Definition: ERF_Constants.H:6
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:11
constexpr amrex::Real PI
Definition: ERF_Constants.H:16
@ wbar
Definition: ERF_DataStruct.H:98
#define Rho_comp
Definition: ERF_IndexDefines.H:36
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { const Real *dx=geomdata.CellSize();const Real x=(i+0.5) *dx[0];const Real y=(j+0.5) *dx[1];const Real Omg=erf_vortex_Gaussian(x, y, xc, yc, R, beta, sigma);const Real deltaT=-(gamma - 1.0)/(2.0 *sigma *sigma) *Omg *Omg;const Real rho_norm=std::pow(1.0+deltaT, inv_gm1);const Real T=(1.0+deltaT) *T_inf;const Real p=std::pow(rho_norm, Gamma)/Gamma *rho_0 *a_inf *a_inf;const Real rho_theta=rho_0 *rho_norm *(T *std::pow(p_0/p, rdOcp));state_pert(i, j, k, RhoTheta_comp)=rho_theta - getRhoThetagivenP(p_hse(i, j, k));const Real r2d_xy=std::sqrt((x-xc) *(x-xc)+(y-yc) *(y-yc));state_pert(i, j, k, RhoScalar_comp)=0.25 *(1.0+std::cos(PI *std::min(r2d_xy, R)/R));})
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:17
Gpu::DeviceVector< Real > rho_d(khi+1, zero)