ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_VelocityToMomentum.cpp File Reference
#include <AMReX.H>
#include <AMReX_MultiFab.H>
#include <ERF_Utils.H>
#include <AMReX_MultiFabUtil.H>
Include dependency graph for ERF_VelocityToMomentum.cpp:

Functions

void VelocityToMomentum (const MultiFab &xvel_in, const IntVect &xvel_ngrow, const MultiFab &yvel_in, const IntVect &yvel_ngrow, const MultiFab &zvel_in, const IntVect &zvel_ngrow, const MultiFab &density, MultiFab &xmom, MultiFab &ymom, MultiFab &zmom, const Box &domain, const Vector< BCRec > &domain_bcs_type_h)
 

Function Documentation

◆ VelocityToMomentum()

void VelocityToMomentum ( const MultiFab &  xvel_in,
const IntVect &  xvel_ngrow,
const MultiFab &  yvel_in,
const IntVect &  yvel_ngrow,
const MultiFab &  zvel_in,
const IntVect &  zvel_ngrow,
const MultiFab &  density,
MultiFab &  xmom,
MultiFab &  ymom,
MultiFab &  zmom,
const Box &  domain,
const Vector< BCRec > &  domain_bcs_type_h 
)

Convert velocity to momentum by multiplying by density averaged onto faces.

Parameters
[in]xvel_inx-component of velocity
[in]xvel_ngrowhow many cells to grow the tilebox for the x-momentum
[in]yvel_iny-component of velocity
[in]yvel_ngrowhow many cells to grow the tilebox for the y-momentum
[in]zvel_inz-component of velocity
[in]zvel_ngrowhow many cells to grow the tilebox for the z-momentum
[in]densitydensity at cell centers
[out]xmomx-component of momentum
[out]ymomy-component of momentum
[out]zmomz-component of momentum
[in]domainDomain at this level
[in]domain_bcs_type_hhost vector for domain boundary conditions
[in]l_use_ndiffflag describing whether we will later add explicit numerical diffusion
38 {
39  BL_PROFILE_VAR("VelocityToMomentum()",VelocityToMomentum);
40 
41  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
42 
43  // Loop over boxes = valid boxes grown by ngrow
44 #ifdef _OPENMP
45 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
46 #endif
47  for ( MFIter mfi(density,TilingIfNotGPU()); mfi.isValid(); ++mfi)
48  {
49  // We need momentum in the interior ghost cells (init == real)
50  const Box& bx = mfi.tilebox();
51  Box tbx, tby, tbz;
52 
53  tbx = mfi.tilebox(IntVect(1,0,0),xvel_ngrow);
54  tby = mfi.tilebox(IntVect(0,1,0),yvel_ngrow);
55  tbz = mfi.tilebox(IntVect(0,0,1),zvel_ngrow);
56 
57  // Don't actually try to fill w above or below the domain
58  if (tbz.smallEnd(2) < domain.smallEnd(2)) tbz.setSmall(2,domain.smallEnd(2));
59  if (tbz.bigEnd(2) > domain.bigEnd(2)+1) tbz.setBig(2,domain.bigEnd(2)+1);
60 
61  // Conserved/state variables on cell centers -- we use this for density
62  const Array4<const Real>& dens_arr = density.array(mfi);
63 
64  // Momentum on faces, to be computed
65  Array4<Real> const& momx = xmom.array(mfi);
66  Array4<Real> const& momy = ymom.array(mfi);
67  Array4<Real> const& momz = zmom.array(mfi);
68 
69  // Velocity on faces, used in computation
70  const Array4<Real const>& velx = xvel_in.const_array(mfi);
71  const Array4<Real const>& vely = yvel_in.const_array(mfi);
72  const Array4<Real const>& velz = zvel_in.const_array(mfi);
73 
74  // ********************************************************************************************
75 
76  ParallelFor(tbx, tby, tbz,
77  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
78  momx(i,j,k) = velx(i,j,k) * 0.5 * (dens_arr(i,j,k,Rho_comp) + dens_arr(i-1,j,k,Rho_comp));
79  },
80  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
81  momy(i,j,k) = vely(i,j,k) * 0.5 * (dens_arr(i,j,k,Rho_comp) + dens_arr(i,j-1,k,Rho_comp));
82  },
83  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
84  momz(i,j,k) = velz(i,j,k) * 0.5 * (dens_arr(i,j,k,Rho_comp) + dens_arr(i,j,k-1,Rho_comp));
85  });
86 
87  // ********************************************************************************************
88 
89  if ( (bx.smallEnd(0) == domain.smallEnd(0)) &&
90  (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::ext_dir) ) {
91  ParallelFor(makeSlab(tbx,0,domain.smallEnd(0)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
92  momx(i,j,k) = velx(i,j,k) * dens_arr(i-1,j,k,Rho_comp);
93  });
94  }
95  if ( (bx.bigEnd(0) == domain.bigEnd(0)) &&
96  (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::ext_dir) ) {
97  ParallelFor(makeSlab(tbx,0,domain.bigEnd(0)+1), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
98  momx(i,j,k) = velx(i,j,k) * dens_arr(i,j,k,Rho_comp);
99  });
100  }
101  if ( (bx.smallEnd(1) == domain.smallEnd(1)) &&
102  (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::ext_dir) ) {
103  ParallelFor(makeSlab(tby,1,domain.smallEnd(1)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
104  momy(i,j,k) = vely(i,j,k) * dens_arr(i,j-1,k,Rho_comp);
105  });
106  }
107  if ( (bx.bigEnd(1) == domain.bigEnd(1)) &&
108  (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::ext_dir) ) {
109  ParallelFor(makeSlab(tby,1,domain.bigEnd(1)+1), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
110  momy(i,j,k) = vely(i,j,k) * dens_arr(i,j,k,Rho_comp);
111  });
112  }
113  } // end MFIter
114 }
#define Rho_comp
Definition: ERF_IndexDefines.H:36
void VelocityToMomentum(const MultiFab &xvel_in, const IntVect &xvel_ngrow, const MultiFab &yvel_in, const IntVect &yvel_ngrow, const MultiFab &zvel_in, const IntVect &zvel_ngrow, const MultiFab &density, MultiFab &xmom, MultiFab &ymom, MultiFab &zmom, const Box &domain, const Vector< BCRec > &domain_bcs_type_h)
Definition: ERF_VelocityToMomentum.cpp:28
@ cons_bc
Definition: ERF_IndexDefines.H:76
@ ext_dir
Definition: ERF_IndexDefines.H:180
@ ymom
Definition: ERF_IndexDefines.H:141
@ zmom
Definition: ERF_IndexDefines.H:142
@ xmom
Definition: ERF_IndexDefines.H:140