ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ERF_MomentumToVelocity.cpp File Reference
#include <AMReX.H>
#include <AMReX_MultiFab.H>
#include <ERF_Utils.H>
Include dependency graph for ERF_MomentumToVelocity.cpp:

Functions

void MomentumToVelocity (MultiFab &xvel, MultiFab &yvel, MultiFab &zvel, const MultiFab &density, const MultiFab &xmom_in, const MultiFab &ymom_in, const MultiFab &zmom_in, const Box &domain, const Vector< BCRec > &domain_bcs_type_h)
 

Function Documentation

◆ MomentumToVelocity()

void MomentumToVelocity ( MultiFab &  xvel,
MultiFab &  yvel,
MultiFab &  zvel,
const MultiFab &  density,
const MultiFab &  xmom_in,
const MultiFab &  ymom_in,
const MultiFab &  zmom_in,
const Box &  domain,
const Vector< BCRec > &  domain_bcs_type_h 
)

Convert momentum to velocity by dividing by density averaged onto faces

Parameters
[out]xvelx-component of velocity
[out]yvely-component of velocity
[out]zvelz-component of velocity
[in]densitydensity at cell centers
[in]xmom_inx-component of momentum
[in]ymom_iny-component of momentum
[in]zmom_inz-component of momentum
[in]domainDomain at this level
[in]domain_bcs_type_hhost vector for domain boundary conditions
30 {
31  BL_PROFILE_VAR("MomentumToVelocity()",MomentumToVelocity);
32 
33  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
34 
35 #ifdef _OPENMP
36 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
37 #endif
38  for ( MFIter mfi(density,TilingIfNotGPU()); mfi.isValid(); ++mfi)
39  {
40  // We need velocity in the interior ghost cells (init == real)
41  Box bx = mfi.tilebox();
42 
43  const Box& tbx = surroundingNodes(bx,0);
44  const Box& tby = surroundingNodes(bx,1);
45  const Box& tbz = surroundingNodes(bx,2);
46 
47  // Conserved variables on cell centers -- we use this for density
48  const Array4<const Real>& dens_arr = density.array(mfi);
49 
50  // Momentum on faces
51  Array4<Real const> const& momx = xmom_in.const_array(mfi);
52  Array4<Real const> const& momy = ymom_in.const_array(mfi);
53  Array4<Real const> const& momz = zmom_in.const_array(mfi);
54 
55  // Velocity on faces
56  const Array4<Real>& velx = xvel.array(mfi);
57  const Array4<Real>& vely = yvel.array(mfi);
58  const Array4<Real>& velz = zvel.array(mfi);
59 
60  ParallelFor(tbx, tby, tbz,
61  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
62  velx(i,j,k) = momx(i,j,k) * 2.0 / (dens_arr(i,j,k,Rho_comp) + dens_arr(i-1,j,k,Rho_comp));
63  },
64  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
65  vely(i,j,k) = momy(i,j,k) * 2.0 / (dens_arr(i,j,k,Rho_comp) + dens_arr(i,j-1,k,Rho_comp));
66  },
67  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
68  velz(i,j,k) = momz(i,j,k) * 2.0 / (dens_arr(i,j,k,Rho_comp) + dens_arr(i,j,k-1,Rho_comp));
69  });
70 
71  if (bx.smallEnd(0) == domain.smallEnd(0)) {
72  if (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::ext_dir)
73  {
74  ParallelFor(makeSlab(tbx,0,domain.smallEnd(0)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
75  velx(i,j,k) = momx(i,j,k) / dens_arr(i-1,j,k,Rho_comp);
76  });
77  }
78  else if (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::ext_dir_upwind)
79  {
80  ParallelFor(makeSlab(tbx,0,domain.smallEnd(0)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
81  if (momx(i,j,k) >= 0.) {
82  velx(i,j,k) = momx(i,j,k) / dens_arr(i-1,j,k,Rho_comp);
83  }
84  });
85  }
86  }
87 
88  if (bx.bigEnd(0) == domain.bigEnd(0)) {
89  if (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::ext_dir)
90  {
91  ParallelFor(makeSlab(tbx,0,domain.bigEnd(0)+1), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
92  velx(i,j,k) = momx(i,j,k) / dens_arr(i,j,k,Rho_comp);
93  });
94  }
95  else if (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::ext_dir_upwind)
96  {
97  ParallelFor(makeSlab(tbx,0,domain.smallEnd(0)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
98  if (momx(i,j,k) <= 0.) {
99  velx(i,j,k) = momx(i,j,k) / dens_arr(i,j,k,Rho_comp);
100  }
101  });
102  }
103  }
104 
105  if (bx.smallEnd(1) == domain.smallEnd(1)) {
106  if (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::ext_dir)
107  {
108  ParallelFor(makeSlab(tby,1,domain.smallEnd(1)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
109  vely(i,j,k) = momy(i,j,k) / dens_arr(i,j-1,k,Rho_comp);
110  });
111  }
112  else if (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::ext_dir_upwind)
113  {
114  ParallelFor(makeSlab(tby,1,domain.smallEnd(1)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
115  if (momy(i,j,k) >= 0.) {
116  vely(i,j,k) = momy(i,j,k) / dens_arr(i,j-1,k,Rho_comp);
117  }
118  });
119  }
120  }
121 
122  if (bx.bigEnd(1) == domain.bigEnd(1)) {
123  if (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::ext_dir)
124  {
125  ParallelFor(makeSlab(tby,1,domain.bigEnd(1)+1), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
126  vely(i,j,k) = momy(i,j,k) / dens_arr(i,j,k,Rho_comp);
127  });
128  }
129  else if (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::ext_dir_upwind)
130  {
131  ParallelFor(makeSlab(tby,1,domain.smallEnd(1)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
132  if (momy(i,j,k) <= 0.) {
133  vely(i,j,k) = momy(i,j,k) / dens_arr(i,j,k,Rho_comp);
134  }
135  });
136  }
137  }
138  } // end MFIter
139 }
#define Rho_comp
Definition: ERF_IndexDefines.H:36
void MomentumToVelocity(MultiFab &xvel, MultiFab &yvel, MultiFab &zvel, const MultiFab &density, const MultiFab &xmom_in, const MultiFab &ymom_in, const MultiFab &zmom_in, const Box &domain, const Vector< BCRec > &domain_bcs_type_h)
Definition: ERF_MomentumToVelocity.cpp:25
@ cons_bc
Definition: ERF_IndexDefines.H:76
@ ext_dir
Definition: ERF_IndexDefines.H:191
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:199
@ xvel
Definition: ERF_IndexDefines.H:141
@ zvel
Definition: ERF_IndexDefines.H:143
@ yvel
Definition: ERF_IndexDefines.H:142

Referenced by ERF::AverageDownTo(), ERF::FillCoarsePatch(), and ERF::FillIntermediatePatch().

Here is the caller graph for this function: