ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_detail_EnforceConstraintOnBdy Namespace Reference

Functions

void scale_bdy_normal_by_rho0 (const MultiFab &rho0, FArrayBox &bdy_fab, const int dir, const Box &domain, const Vector< BCRec > &domain_bcs_type_h, const bool multiply_by_rho0)
 Scale the normal boundary velocity by the base state density. More...
 
void correct_bdy_outflow_on_face (FArrayBox &bdy_fab, const int dir, const bool is_low, const Box &domain, const Real alpha_fcf, const int n)
 Correct outflow values on a boundary face. More...
 

Function Documentation

◆ correct_bdy_outflow_on_face()

void erf_detail_EnforceConstraintOnBdy::correct_bdy_outflow_on_face ( FArrayBox &  bdy_fab,
const int  dir,
const bool  is_low,
const Box &  domain,
const Real  alpha_fcf,
const int  n 
)

Correct outflow values on a boundary face.

Parameters
[in,out]bdy_fabBoundary data FAB.
[in]dirCoordinate direction.
[in]is_lowTrue if operating on the low side of the domain.
[in]domainComputational domain.
[in]alpha_fcfFlux correction factor.
[in]nWidth index for the correction.
130 {
131  const int bndry = is_low ? domain.smallEnd(dir) + n : domain.bigEnd(dir)+1 - n;
132  Box bx = bdy_fab.box();
133 
134  if (bx.smallEnd(dir) > bndry || bx.bigEnd(dir) < bndry) {
135  return;
136  }
137  // amrex::Print() << "CORRECTING OUTFLOW VALS BY MULTIPLIER " << alpha_fcf << std::endl;
138 
139  bx.setRange(dir, bndry);
140  bx.grow(1-dir, -n);
141 
142  const Array4<Real>& bdy_arr = bdy_fab.array();
143 
144  // amrex::Print() << "OPERATING ON BX " << bx << std::endl;
145 
146  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
147  {
148  if ((is_low && bdy_arr(i,j,k) < zero) ||
149  (!is_low && bdy_arr(i,j,k) > zero)) {
150  bdy_arr(i,j,k) *= alpha_fcf;
151  }
152  });
153 }
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);})
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36

Referenced by enforceInOutSolvability_bdy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scale_bdy_normal_by_rho0()

void erf_detail_EnforceConstraintOnBdy::scale_bdy_normal_by_rho0 ( const MultiFab &  rho0,
FArrayBox &  bdy_fab,
const int  dir,
const Box &  domain,
const Vector< BCRec > &  domain_bcs_type_h,
const bool  multiply_by_rho0 
)

Scale the normal boundary velocity by the base state density.

Parameters
[in]rho0Base state density.
[in,out]bdy_fabBoundary data FAB to be scaled.
[in]dirCoordinate direction.
[in]domainComputational domain.
[in]domain_bcs_type_hBoundary condition types for the domain.
[in]multiply_by_rho0Whether to multiply (true) or divide (false) by rho0.
29 {
30  AMREX_ALWAYS_ASSERT(bdy_fab.nComp() == 1);
31 
32  FArrayBox bdy_tmp(bdy_fab.box(), 1, The_Managed_Arena());
33  bdy_tmp.template setVal<RunOn::Device>(zero);
34 
35  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
36  const int domlo = domain.smallEnd(dir);
37  const int domhi = domain.bigEnd(dir) + 1;
38  const int bc_lo = bc_ptr_h[BCVars::cons_bc].lo(dir);
39  const int bc_hi = bc_ptr_h[BCVars::cons_bc].hi(dir);
40 
41 #ifdef _OPENMP
42 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
43 #endif
44  for (MFIter mfi(rho0,TilingIfNotGPU()); mfi.isValid(); ++mfi)
45  {
46  // Give every face one owner, the tile holding the cell above it (plus the
47  // domain-high face): the per-rank results are summed below, so a face shared
48  // by two boxes on different ranks would otherwise be counted twice
49  Box bx = amrex::surroundingNodes(mfi.tilebox(), dir);
50  if (bx.bigEnd(dir) != domhi) { bx.growHi(dir, -1); }
51  bx &= bdy_fab.box();
52  if (!bx.ok()) { continue; }
53 
54  const Array4<const Real>& rho0_arr = rho0.const_array(mfi);
55  const Array4<const Real>& bdy_arr = bdy_fab.const_array();
56  const Array4<Real>& tmp_arr = bdy_tmp.array();
57 
58  // amrex::Print() << "MULTIPLYING BY RHO0 ON BX " << dir << " " << bx << std::endl;
59 
60  if (dir == 0) {
61  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
62  {
63  const Real normal_vel = bdy_arr(i,j,k);
64  const bool use_xlo =
65  (i == domlo) &&
66  ((bc_lo == ERFBCType::ext_dir) ||
67  (bc_lo == ERFBCType::ext_dir_upwind && normal_vel >= zero));
68  const bool use_xhi =
69  (i == domhi) &&
70  ((bc_hi == ERFBCType::ext_dir) ||
71  (bc_hi == ERFBCType::ext_dir_upwind && normal_vel <= zero));
72 
73  Real fac;
74  if (use_xlo) {
75  fac = rho0_arr(i-1,j,k,Rho_comp);
76  } else if (use_xhi) {
77  fac = rho0_arr(i,j,k,Rho_comp);
78  } else {
79  fac = Real(0.5) * (rho0_arr(i,j,k,Rho_comp) + rho0_arr(i-1,j,k,Rho_comp));
80  }
81  tmp_arr(i,j,k) = multiply_by_rho0 ? normal_vel * fac : normal_vel / fac;
82  });
83  } else {
84  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
85  {
86  const Real normal_vel = bdy_arr(i,j,k);
87  const bool use_ylo =
88  (j == domlo) &&
89  ((bc_lo == ERFBCType::ext_dir) ||
90  (bc_lo == ERFBCType::ext_dir_upwind && normal_vel >= zero));
91  const bool use_yhi =
92  (j == domhi) &&
93  ((bc_hi == ERFBCType::ext_dir) ||
94  (bc_hi == ERFBCType::ext_dir_upwind && normal_vel <= zero));
95 
96  Real fac;
97  if (use_ylo) {
98  fac = rho0_arr(i,j-1,k,Rho_comp);
99  } else if (use_yhi) {
100  fac = rho0_arr(i,j,k,Rho_comp);
101  } else {
102  fac = Real(0.5) * (rho0_arr(i,j,k,Rho_comp) + rho0_arr(i,j-1,k,Rho_comp));
103  }
104  tmp_arr(i,j,k) = multiply_by_rho0 ? normal_vel * fac : normal_vel / fac;
105  });
106  }
107  }
108 
109  ParallelAllReduce::Sum(bdy_tmp.dataPtr(), bdy_tmp.size(), ParallelContext::CommunicatorAll());
110  bdy_fab.template copy<RunOn::Device>(bdy_tmp, 0, 0, 1);
111 }
#define Rho_comp
Definition: ERF_IndexDefines.H:61
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
@ cons_bc
Definition: ERF_IndexDefines.H:122
@ ext_dir
Definition: ERF_IndexDefines.H:317
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:325

Referenced by enforceInOutSolvability_bdy().

Here is the call graph for this function:
Here is the caller graph for this function: