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, 0.0);
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, 0.0);
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, 0.0);
17  rho_stag[0] = 1.5*rho_h[0] - 0.5*rho_h[1];
18  rho_stag[khi+1] = 1.5*rho_h[khi] - 0.5*rho_h[khi-1];
19  for (int k = 1; k <= khi; k++) {
20  rho_stag[k] = 0.5*(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] = 0.0;
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 PI
Definition: ERF_Constants.H:6
@ 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 auto prob_lo=geomdata.ProbLo();const auto dx=geomdata.CellSize();const Real x=(prob_lo[0]+(i+0.5) *dx[0])/mf_m(i, j, 0);const Real z=z_cc(i, j, k);Real L=std::sqrt(std::pow((x - x_c)/x_r, 2)+std::pow((z - z_c)/z_r, 2));if(L<=1.0) { Real dT=T_pert *(std::cos(PI *L)+1.0)/2.0;Real Tbar_hse=p_hse(i, j, k)/(R_d *r_hse(i, j, k));Real theta_perturbed=(Tbar_hse+dT) *std::pow(p_0/p_hse(i, j, k), rdOcp);Real theta_0=(Tbar_hse) *std::pow(p_0/p_hse(i, j, k), rdOcp);if(const_rho) { state_pert(i, j, k, RhoTheta_comp)=r_hse(i, j, k) *(theta_perturbed - theta_0);} else { state_pert(i, j, k, Rho_comp)=getRhoThetagivenP(p_hse(i, j, k))/theta_perturbed - r_hse(i, j, k);} } })
auto rho_arr
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:3
Gpu::DeviceVector< Real > rho_d(khi+1, 0.0)
rho_stag[0]
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:17
Vector< Real > rho_h(khi+1, 0.0)