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

Functions

void ConvertForProjection (const MultiFab &den_div, const MultiFab &den_mlt, MultiFab &xmom, MultiFab &ymom, MultiFab &zmom, const Box &domain, const Vector< BCRec > &domain_bcs_type_h)
 
void compute_influx_outflux (Array< MultiFab *, AMREX_SPACEDIM > &vels_vec, Array< MultiFab *, AMREX_SPACEDIM > &area_vec, const Geometry &geom, Real &influx, Real &outflux)
 
void correct_outflow (const Geometry &geom_lev, Array< MultiFab *, AMREX_SPACEDIM > &vels_vec, const Box &domain, const Real alpha_fcf)
 
void enforceInOutSolvability (int, Array< MultiFab *, AMREX_SPACEDIM > &vels_vec, Array< MultiFab *, AMREX_SPACEDIM > &area_vec, const Geometry &geom)
 
void MakeProjectionWeights (const MultiFab &den_div, const MultiFab &den_mlt, const MultiFab &xmom, const MultiFab &ymom, const MultiFab &zmom, Array< MultiFab, AMREX_SPACEDIM > &beta, const Box &domain, const Vector< BCRec > &domain_bcs_type_h)
 
void MakeAdvectiveProjectionWeights (const MultiFab &den_div, const MultiFab &den_mlt, const MultiFab &xmom, const MultiFab &ymom, const MultiFab &zmom, Array< MultiFab, AMREX_SPACEDIM > &beta, const AdvType horiz_adv_type, const AdvType vert_adv_type, const Real horiz_upw_frac, const Real vert_upw_frac, const Periodicity &period)
 

Function Documentation

◆ compute_influx_outflux()

void compute_influx_outflux ( Array< MultiFab *, AMREX_SPACEDIM > &  vels_vec,
Array< MultiFab *, AMREX_SPACEDIM > &  area_vec,
const Geometry &  geom,
Real &  influx,
Real &  outflux 
)
184 {
185  influx = zero, outflux = zero;
186 
187  const Box domain = geom.Domain();
188  const auto& domlo = lbound(domain);
189  const auto& domhi = ubound(domain);
190 
191  // Normal face area (of undistorted mesh)
192  const Real* a_dx = geom.CellSize();
193  const Real ds_x = a_dx[1];
194  const Real ds_y = a_dx[0];
195 
196  IntVect ngrow = {0,0,0};
197 
198  // X-dir
199  auto const& vel_x = vels_vec[0]->const_arrays();
200  auto const& area_x = area_vec[0]->const_arrays();
201  influx += ds_x *
202  ParReduce(TypeList<ReduceOpSum>{},
203  TypeList<Real>{},
204  *vels_vec[0], ngrow,
205  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k)
206  noexcept -> GpuTuple<Real>
207  {
208  if ( (i == domlo.x && vel_x[box_no](i,j,k) > zero) ||
209  (i == domhi.x+1 && vel_x[box_no](i,j,k) < zero) ) {
210  return { std::abs(vel_x[box_no](i,j,k)) * area_x[box_no](i,j,k) };
211  } else {
212  return { zero };
213  }
214  });
215 
216  outflux += ds_x *
217  ParReduce(TypeList<ReduceOpSum>{},
218  TypeList<Real>{},
219  *vels_vec[0], ngrow,
220  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k)
221  noexcept -> GpuTuple<Real>
222  {
223  if ( (i == domlo.x && vel_x[box_no](i,j,k) < zero) ||
224  (i == domhi.x+1 && vel_x[box_no](i,j,k) > zero) ) {
225  return { std::abs(vel_x[box_no](i,j,k)) * area_x[box_no](i,j,k) };
226  } else {
227  return { zero };
228  }
229  });
230 
231  // Y-dir
232  auto const& vel_y= vels_vec[1]->const_arrays();
233  auto const& area_y = area_vec[1]->const_arrays();
234  influx += ds_y *
235  ParReduce(TypeList<ReduceOpSum>{},
236  TypeList<Real>{},
237  *vels_vec[1], ngrow,
238  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k)
239  noexcept -> GpuTuple<Real>
240  {
241  if ( (j == domlo.y && vel_y[box_no](i,j,k) > zero) ||
242  (j == domhi.y+1 && vel_y[box_no](i,j,k) < zero) ) {
243  return { std::abs(vel_y[box_no](i,j,k)) * area_y[box_no](i,j,k) };
244  } else {
245  return { zero };
246  }
247  });
248 
249  outflux += ds_y *
250  ParReduce(TypeList<ReduceOpSum>{},
251  TypeList<Real>{},
252  *vels_vec[1], ngrow,
253  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k)
254  noexcept -> GpuTuple<Real>
255  {
256  if ( (j == domlo.y && vel_y[box_no](i,j,k) < zero) ||
257  (j == domhi.y+1 && vel_y[box_no](i,j,k) > zero) ) {
258  return { std::abs(vel_y[box_no](i,j,k)) * area_y[box_no](i,j,k) };
259  } else {
260  return { zero };
261  }
262  });
263 
264  ParallelDescriptor::ReduceRealSum(influx);
265  ParallelDescriptor::ReduceRealSum(outflux);
266 }
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36

Referenced by enforceInOutSolvability().

Here is the caller graph for this function:

◆ ConvertForProjection()

void ConvertForProjection ( const MultiFab &  den_div,
const MultiFab &  den_mlt,
MultiFab &  xmom,
MultiFab &  ymom,
MultiFab &  zmom,
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
29 {
30  BL_PROFILE_VAR("ConvertForProjection()",onvertForProjection);
31 
32  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
33 
34 #ifdef _OPENMP
35 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
36 #endif
37  for ( MFIter mfi(den_div,TilingIfNotGPU()); mfi.isValid(); ++mfi)
38  {
39  // We need velocity in the interior ghost cells (init == real)
40  Box bx = mfi.tilebox();
41 
42  Box tbx = mfi.nodaltilebox(0);
43  Box tby = mfi.nodaltilebox(1);
44  Box tbz = mfi.nodaltilebox(2);
45 
46  if ( (bx.smallEnd(0) == domain.smallEnd(0)) &&
47  ( (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::ext_dir) ||
48  (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::ext_dir_upwind) ) )
49  {
50  tbx.growLo(0,-1);
51  }
52  if ( (bx.bigEnd(0) == domain.bigEnd(0)) &&
53  ( (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::ext_dir) ||
54  (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::ext_dir_upwind) ) )
55  {
56  tbx.growHi(0,-1);
57  }
58  if ( (bx.smallEnd(1) == domain.smallEnd(1)) &&
59  ( (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::ext_dir) ||
60  (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::ext_dir_upwind) ) )
61  {
62  tby.growLo(1,-1);
63  }
64  if ( (bx.bigEnd(1) == domain.bigEnd(1)) &&
65  ( (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::ext_dir) ||
66  (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::ext_dir_upwind) ) )
67  {
68  tby.growHi(1,-1);
69  }
70 
71  // Conserved variables on cell centers -- we use this for density
72  const Array4<const Real>& den_div_arr = den_div.const_array(mfi);
73  const Array4<const Real>& den_mlt_arr = den_mlt.const_array(mfi);
74 
75  // Momentum on faces
76  Array4<Real> const& momx = xmom.array(mfi);
77  Array4<Real> const& momy = ymom.array(mfi);
78  Array4<Real> const& momz = zmom.array(mfi);
79 
80  ParallelFor(tbx, tby, tbz,
81  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
82  momx(i,j,k) *= ( den_mlt_arr(i,j,k,Rho_comp) + den_mlt_arr(i-1,j,k,Rho_comp) )
83  / ( den_div_arr(i,j,k,Rho_comp) + den_div_arr(i-1,j,k,Rho_comp) );
84 
85  },
86  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
87  momy(i,j,k) *= ( den_mlt_arr(i,j,k,Rho_comp) + den_mlt_arr(i,j-1,k,Rho_comp) )
88  / ( den_div_arr(i,j,k,Rho_comp) + den_div_arr(i,j-1,k,Rho_comp) );
89  },
90  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
91  momz(i,j,k) *= ( den_mlt_arr(i,j,k,Rho_comp) + den_mlt_arr(i,j,k-1,Rho_comp) )
92  / ( den_div_arr(i,j,k,Rho_comp) + den_div_arr(i,j,k-1,Rho_comp) );
93  });
94 
95  if (bx.smallEnd(0) == domain.smallEnd(0)) {
96  if (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::ext_dir)
97  {
98  ParallelFor(makeSlab(tbx,0,domain.smallEnd(0)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
99  momx(i,j,k) *= den_mlt_arr(i-1,j,k,Rho_comp) / den_div_arr(i-1,j,k,Rho_comp) ;
100  });
101  }
102  else if (bc_ptr_h[BCVars::cons_bc].lo(0) == ERFBCType::ext_dir_upwind)
103  {
104  ParallelFor(makeSlab(tbx,0,domain.smallEnd(0)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
105  if (momx(i,j,k) >= zero) {
106  momx(i,j,k) *= den_mlt_arr(i-1,j,k,Rho_comp) / den_div_arr(i-1,j,k,Rho_comp) ;
107  } else {
108  momx(i,j,k) *= ( den_mlt_arr(i,j,k,Rho_comp) + den_mlt_arr(i-1,j,k,Rho_comp) )
109  / ( den_div_arr(i,j,k,Rho_comp) + den_div_arr(i-1,j,k,Rho_comp) );
110  }
111  });
112  }
113  }
114 
115  if (bx.bigEnd(0) == domain.bigEnd(0)) {
116  if (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::ext_dir)
117  {
118  ParallelFor(makeSlab(tbx,0,domain.bigEnd(0)+1), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
119  momx(i,j,k) *= den_mlt_arr(i,j,k,Rho_comp) / den_div_arr(i,j,k,Rho_comp) ;
120  });
121  }
122  else if (bc_ptr_h[BCVars::cons_bc].hi(0) == ERFBCType::ext_dir_upwind)
123  {
124  ParallelFor(makeSlab(tbx,0,domain.bigEnd(0)+1), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
125  if (momx(i,j,k) <= zero) {
126  momx(i,j,k) *= den_mlt_arr(i,j,k,Rho_comp) / den_div_arr(i,j,k,Rho_comp) ;
127  } else {
128  momx(i,j,k) *= ( den_mlt_arr(i,j,k,Rho_comp) + den_mlt_arr(i-1,j,k,Rho_comp) )
129  / ( den_div_arr(i,j,k,Rho_comp) + den_div_arr(i-1,j,k,Rho_comp) );
130  }
131  });
132  }
133  }
134 
135  if (bx.smallEnd(1) == domain.smallEnd(1)) {
136  if (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::ext_dir)
137  {
138  ParallelFor(makeSlab(tby,1,domain.smallEnd(1)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
139  momy(i,j,k) *= den_mlt_arr(i,j-1,k,Rho_comp) / den_div_arr(i,j-1,k,Rho_comp) ;
140  });
141  }
142  else if (bc_ptr_h[BCVars::cons_bc].lo(1) == ERFBCType::ext_dir_upwind)
143  {
144  ParallelFor(makeSlab(tby,1,domain.smallEnd(1)), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
145  if (momy(i,j,k) >= zero) {
146  momy(i,j,k) *= den_mlt_arr(i,j-1,k,Rho_comp) / den_div_arr(i,j-1,k,Rho_comp) ;
147  } else {
148  momy(i,j,k) *= ( den_mlt_arr(i,j,k,Rho_comp) + den_mlt_arr(i,j-1,k,Rho_comp) )
149  / ( den_div_arr(i,j,k,Rho_comp) + den_div_arr(i,j-1,k,Rho_comp) );
150  }
151  });
152  }
153  }
154 
155  if (bx.bigEnd(1) == domain.bigEnd(1)) {
156  if (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::ext_dir)
157  {
158  ParallelFor(makeSlab(tby,1,domain.bigEnd(1)+1), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
159  momy(i,j,k) *= den_mlt_arr(i,j,k,Rho_comp) / den_div_arr(i,j,k,Rho_comp) ;
160  });
161  }
162  else if (bc_ptr_h[BCVars::cons_bc].hi(1) == ERFBCType::ext_dir_upwind)
163  {
164  ParallelFor(makeSlab(tby,1,domain.bigEnd(1)+1), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
165  if (momy(i,j,k) <= zero) {
166  momy(i,j,k) *= den_mlt_arr(i,j,k,Rho_comp) / den_div_arr(i,j,k,Rho_comp) ;
167  } else {
168  momy(i,j,k) *= ( den_mlt_arr(i,j,k,Rho_comp) + den_mlt_arr(i,j-1,k,Rho_comp) )
169  / ( den_div_arr(i,j,k,Rho_comp) + den_div_arr(i,j-1,k,Rho_comp) );
170  }
171  });
172  }
173  }
174 
175 
176  } // end MFIter
177 }
#define Rho_comp
Definition: ERF_IndexDefines.H:61
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);})
@ cons_bc
Definition: ERF_IndexDefines.H:122
@ ext_dir
Definition: ERF_IndexDefines.H:317
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:325
@ ymom
Definition: ERF_IndexDefines.H:251
@ zmom
Definition: ERF_IndexDefines.H:252
@ xmom
Definition: ERF_IndexDefines.H:250

Referenced by ERF::project_momenta().

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

◆ correct_outflow()

void correct_outflow ( const Geometry &  geom_lev,
Array< MultiFab *, AMREX_SPACEDIM > &  vels_vec,
const Box &  domain,
const Real  alpha_fcf 
)
273 {
274  for (OrientationIter oit; oit != nullptr; ++oit) {
275  const auto ori = oit();
276  const int dir = ori.coordDir();
277  const auto oriIsLow = ori.isLow();
278  const auto oriIsHigh = ori.isHigh();
279 
280  if (dir < 2) {
281 
282  // MultiFab for normal velocity
283  const auto& vel_mf = vels_vec[dir];
284 
285  // Domain extent indices for the velocities
286  int dlo = domain.smallEnd(dir);
287  int dhi = domain.bigEnd(dir)+1;
288 
289  // get BCs for the normal velocity and set the boundary index
290  int bndry;
291  if (oriIsLow) {
292  bndry = dlo;
293  } else {
294  bndry = dhi;
295  }
296 
297  // Assume here that all domain boundaries are viewed as direction_dependent!
298  if (!geom_lev.isPeriodic(dir))
299  {
300  for (MFIter mfi(*vel_mf, false); mfi.isValid(); ++mfi) {
301 
302  Box box = mfi.validbox();
303 
304  // Enter further only if the box boundary is at the domain boundary
305  if ((oriIsLow && (box.smallEnd(dir) == dlo))
306  || (oriIsHigh && (box.bigEnd(dir) == dhi))) {
307 
308  // create a 2D box normal to dir at the low/high boundary
309  Box box2d(box); box2d.setRange(dir, bndry);
310 
311  auto vel_arr = vel_mf->array(mfi);
312 
313  ParallelFor(box2d, [=] AMREX_GPU_DEVICE (int i, int j, int k)
314  {
315  if ((oriIsLow && vel_arr(i,j,k) < 0)
316  || (oriIsHigh && vel_arr(i,j,k) > 0)) {
317  vel_arr(i,j,k) *= alpha_fcf;
318  }
319  });
320  }
321  } // mfi
322  } // geom
323  } // dir < 2
324  } // ori
325 }
GpuArray< int, AMREX_SPACEDIM > dhi
Definition: ERF_ActuatorSpreading.cpp:132
GpuArray< int, AMREX_SPACEDIM > dlo
Definition: ERF_ActuatorSpreading.cpp:132

Referenced by enforceInOutSolvability().

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

◆ enforceInOutSolvability()

void enforceInOutSolvability ( int  ,
Array< MultiFab *, AMREX_SPACEDIM > &  vels_vec,
Array< MultiFab *, AMREX_SPACEDIM > &  area_vec,
const Geometry &  geom 
)
331 {
332  Real small_vel = Real(1.e-8);
333 
334  Real influx = zero, outflux = zero;
335 
336  const Box domain = geom.Domain();
337 
338  Real influx_lev = zero, outflux_lev = zero;
339  compute_influx_outflux(vels_vec, area_vec, geom, influx_lev, outflux_lev);
340  influx += influx_lev;
341  outflux += outflux_lev;
342  amrex::Print() <<" TOTAL INFLUX / OUTFLOW " << influx << " " << outflux << std::endl;
343 
344  if ((influx > small_vel) && (outflux < small_vel)) {
345  Abort("Cannot enforce solvability, no outflow from the direction dependent boundaries");
346  } else if ((influx < small_vel) && (outflux < small_vel)) {
347  return; // do nothing
348  } else {
349  const Real alpha_fcf = influx/outflux; // flux correction factor
350  correct_outflow(geom, vels_vec, domain, alpha_fcf);
351 
352  // Just for diagnostic purposes!
353  // Real influx_lev = zero, outflux_lev = zero;
354  // compute_influx_outflux(vels_vec, area_vec, geom, influx_lev, outflux_lev);
355  // amrex::Print() <<" TOTAL INFLUX / OUTFLOW " << influx_lev << " " << outflux_lev << std::endl;
356  }
357 }
void correct_outflow(const Geometry &geom_lev, Array< MultiFab *, AMREX_SPACEDIM > &vels_vec, const Box &domain, const Real alpha_fcf)
Definition: ERF_ConvertForProjection.cpp:268
void compute_influx_outflux(Array< MultiFab *, AMREX_SPACEDIM > &vels_vec, Array< MultiFab *, AMREX_SPACEDIM > &area_vec, const Geometry &geom, Real &influx, Real &outflux)
Definition: ERF_ConvertForProjection.cpp:179

Referenced by ERF::project_momenta().

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

◆ MakeAdvectiveProjectionWeights()

void MakeAdvectiveProjectionWeights ( const MultiFab &  den_div,
const MultiFab &  den_mlt,
const MultiFab &  xmom,
const MultiFab &  ymom,
const MultiFab &  zmom,
Array< MultiFab, AMREX_SPACEDIM > &  beta,
const AdvType  horiz_adv_type,
const AdvType  vert_adv_type,
const Real  horiz_upw_frac,
const Real  vert_upw_frac,
const Periodicity &  period 
)

Face weights beta = den_mlt / den_div mapped onto the faces the way the advection scheme maps a scalar onto them: the cell-centered ratio den_mlt / den_div (on the valid and ghost cells) is reconstructed on each face by BuildScalarAdvectionFaceValues with the given schemes and upwind fractions, the upwind side picked from the sign of the momenta passed in. On a pseudo-incompressible level, with den_mlt = rho0 theta0 and den_div = rho, this is the face value of theta with which (rho theta) is advected when rho theta = rho0 theta0, so the projected flux beta (rho u) is the advective flux of (rho theta).

Parameters
[in]den_divdensity divided out, at cell centers (component Rho_comp), with ghost cells
[in]den_mltdensity multiplied in, at cell centers (component Rho_comp), with ghost cells
[in]xmomx-face momentum (its sign picks the upwind side)
[in]ymomy-face momentum (its sign picks the upwind side)
[in]zmomz-face vertical mass flux, Omega on a terrain-fitted mesh (its sign picks the upwind side)
[out]betaface weights on the valid faces of xmom, ymom and zmom (defined here)
[in]horiz_adv_typehorizontal advection scheme
[in]vert_adv_typevertical advection scheme
[in]horiz_upw_frachorizontal upwind fraction
[in]vert_upw_fracvertical upwind fraction
[in]periodperiodicity of the level, to fill the ratio's ghost cells between boxes

The ratio is computed on the valid and ghost cells and then its ghost cells inside the domain (between boxes and across periodic boundaries) are filled from the neighboring valid cells, so that they hold the same values as the valid cells there: the reconstruction reads two or three cells past the face, and the base state's ghost cells beyond the first are not filled between boxes. Outside the domain the ratio comes from the ghost cells of den_div and den_mlt; a cell with no density (covered by an embedded boundary, or a corner the boundary conditions leave unfilled) gets the ratio one.

504 {
505  BL_PROFILE("MakeAdvectiveProjectionWeights()");
506 
507  beta[0].define(xmom.boxArray(), xmom.DistributionMap(), 1, 0, MFInfo(), xmom.Factory());
508  beta[1].define(ymom.boxArray(), ymom.DistributionMap(), 1, 0, MFInfo(), ymom.Factory());
509  beta[2].define(zmom.boxArray(), zmom.DistributionMap(), 1, 0, MFInfo(), zmom.Factory());
510 
511  const IntVect ng = amrex::min(den_div.nGrowVect(), den_mlt.nGrowVect());
512  MultiFab ratio(den_div.boxArray(), den_div.DistributionMap(), 1, ng);
513 
514 #ifdef _OPENMP
515 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
516 #endif
517  for ( MFIter mfi(ratio,TilingIfNotGPU()); mfi.isValid(); ++mfi)
518  {
519  const Box& gbx = mfi.growntilebox(ng);
520  const Array4<const Real>& dd = den_div.const_array(mfi);
521  const Array4<const Real>& dm = den_mlt.const_array(mfi);
522  const Array4< Real>& q = ratio.array(mfi);
523  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
524  {
525  q(i,j,k) = proj_weight(dm(i,j,k,Rho_comp), dd(i,j,k,Rho_comp));
526  });
527  }
528 
529  ratio.FillBoundary(period);
530 
531  // Each box writes the faces of its own valid cells (faces shared by two boxes get the same
532  // value from both, as the advection fluxes do)
533  for ( MFIter mfi(ratio); mfi.isValid(); ++mfi)
534  {
535  const Box& bx = mfi.validbox();
536  const GpuArray<const Array4<Real>, AMREX_SPACEDIM> b_arr{beta[0].array(mfi),
537  beta[1].array(mfi),
538  beta[2].array(mfi)};
539  BuildScalarAdvectionFaceValues(bx, ratio.const_array(mfi), 0, b_arr, 0,
540  xmom.const_array(mfi), ymom.const_array(mfi), zmom.const_array(mfi),
541  horiz_adv_type, vert_adv_type, horiz_upw_frac, vert_upw_frac);
542  }
543 }
GpuArray< Real, AMREX_SPACEDIM > period
Definition: ERF_ActuatorSpreading.cpp:131
void BuildScalarAdvectionFaceValues(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &scalar, const int scalar_comp, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &face_arr, const int face_comp, const amrex::Array4< const amrex::Real > &xflux, const amrex::Array4< const amrex::Real > &yflux, const amrex::Array4< const amrex::Real > &zflux, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac)
Definition: ERF_AdvectionSrcForScalars.H:431
@ ng
Definition: ERF_Morrison.H:51
@ beta
Definition: ERF_SLM.H:154
@ q
Definition: ERF_WSM6.H:296

Referenced by ERF::project_momenta().

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

◆ MakeProjectionWeights()

void MakeProjectionWeights ( const MultiFab &  den_div,
const MultiFab &  den_mlt,
const MultiFab &  xmom,
const MultiFab &  ymom,
const MultiFab &  zmom,
Array< MultiFab, AMREX_SPACEDIM > &  beta,
const Box &  domain,
const Vector< BCRec > &  domain_bcs_type_h 
)

Face weights beta = den_mlt / den_div with which ConvertForProjection converts (den_div u) to (den_mlt u), on the valid faces of xmom, ymom and zmom: the same face averages and the same one-sided values on the ext_dir and ext_dir_upwind faces of the lateral domain boundaries (the upwind side chosen from the sign of the momentum passed in). Multiplying the momenta by beta is then what ConvertForProjection does, and dividing by the same beta undoes it.

Parameters
[in]den_divdensity divided out, at cell centers (component Rho_comp)
[in]den_mltdensity multiplied in, at cell centers (component Rho_comp)
[in]xmomx-face momentum (its sign picks the upwind side)
[in]ymomy-face momentum (its sign picks the upwind side)
[in]zmomz-face momentum (its layout only)
[out]betaface weights on the valid faces of xmom, ymom and zmom (defined here)
[in]domainDomain at this level
[in]domain_bcs_type_hhost vector for domain boundary conditions

A face with no density on either side (covered by an embedded boundary) gets beta = 1.

392 {
393  BL_PROFILE("MakeProjectionWeights()");
394 
395  beta[0].define(xmom.boxArray(), xmom.DistributionMap(), 1, 0, MFInfo(), xmom.Factory());
396  beta[1].define(ymom.boxArray(), ymom.DistributionMap(), 1, 0, MFInfo(), ymom.Factory());
397  beta[2].define(zmom.boxArray(), zmom.DistributionMap(), 1, 0, MFInfo(), zmom.Factory());
398 
399  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
400  const int xlo = bc_ptr_h[BCVars::cons_bc].lo(0);
401  const int xhi = bc_ptr_h[BCVars::cons_bc].hi(0);
402  const int ylo = bc_ptr_h[BCVars::cons_bc].lo(1);
403  const int yhi = bc_ptr_h[BCVars::cons_bc].hi(1);
404  const int dlo_x = domain.smallEnd(0);
405  const int dhi_x = domain.bigEnd(0) + 1;
406  const int dlo_y = domain.smallEnd(1);
407  const int dhi_y = domain.bigEnd(1) + 1;
408 
409 #ifdef _OPENMP
410 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
411 #endif
412  for ( MFIter mfi(den_div,TilingIfNotGPU()); mfi.isValid(); ++mfi)
413  {
414  Box tbx = mfi.nodaltilebox(0);
415  Box tby = mfi.nodaltilebox(1);
416  Box tbz = mfi.nodaltilebox(2);
417 
418  const Array4<const Real>& dd = den_div.const_array(mfi);
419  const Array4<const Real>& dm = den_mlt.const_array(mfi);
420 
421  const Array4<const Real>& momx = xmom.const_array(mfi);
422  const Array4<const Real>& momy = ymom.const_array(mfi);
423 
424  const Array4<Real>& bx = beta[0].array(mfi);
425  const Array4<Real>& by = beta[1].array(mfi);
426  const Array4<Real>& bz = beta[2].array(mfi);
427 
428  ParallelFor(tbx, tby, tbz,
429  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
430  Real b = proj_weight(dm(i,j,k,Rho_comp) + dm(i-1,j,k,Rho_comp),
431  dd(i,j,k,Rho_comp) + dd(i-1,j,k,Rho_comp));
432  if (i == dlo_x) {
433  if (xlo == ERFBCType::ext_dir ||
434  (xlo == ERFBCType::ext_dir_upwind && momx(i,j,k) >= zero)) {
435  b = proj_weight(dm(i-1,j,k,Rho_comp), dd(i-1,j,k,Rho_comp));
436  }
437  } else if (i == dhi_x) {
438  if (xhi == ERFBCType::ext_dir ||
439  (xhi == ERFBCType::ext_dir_upwind && momx(i,j,k) <= zero)) {
440  b = proj_weight(dm(i,j,k,Rho_comp), dd(i,j,k,Rho_comp));
441  }
442  }
443  bx(i,j,k) = b;
444  },
445  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
446  Real b = proj_weight(dm(i,j,k,Rho_comp) + dm(i,j-1,k,Rho_comp),
447  dd(i,j,k,Rho_comp) + dd(i,j-1,k,Rho_comp));
448  if (j == dlo_y) {
449  if (ylo == ERFBCType::ext_dir ||
450  (ylo == ERFBCType::ext_dir_upwind && momy(i,j,k) >= zero)) {
451  b = proj_weight(dm(i,j-1,k,Rho_comp), dd(i,j-1,k,Rho_comp));
452  }
453  } else if (j == dhi_y) {
454  if (yhi == ERFBCType::ext_dir ||
455  (yhi == ERFBCType::ext_dir_upwind && momy(i,j,k) <= zero)) {
456  b = proj_weight(dm(i,j,k,Rho_comp), dd(i,j,k,Rho_comp));
457  }
458  }
459  by(i,j,k) = b;
460  },
461  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
462  bz(i,j,k) = proj_weight(dm(i,j,k,Rho_comp) + dm(i,j,k-1,Rho_comp),
463  dd(i,j,k,Rho_comp) + dd(i,j,k-1,Rho_comp));
464  });
465  } // end MFIter
466 }

Referenced by ERF::project_momenta().

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