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

Namespaces

 erf_detail_EnforceConstraintOnBdy
 

Functions

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. More...
 
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. More...
 
void compute_influx_outflux_bdy (FArrayBox &bdy_data_xlo, FArrayBox &bdy_data_xhi, FArrayBox &bdy_data_ylo, FArrayBox &bdy_data_yhi, Array< MultiFab *, AMREX_SPACEDIM > &area_vec, const iMultiFab &mask_x, const iMultiFab &mask_y, const Geometry &geom, Real &influx, Real &outflux, const int n)
 
void enforceInOutSolvability_bdy (const MultiFab &rho0, FArrayBox &bdy_data_xlo, FArrayBox &bdy_data_xhi, FArrayBox &bdy_data_ylo, FArrayBox &bdy_data_yhi, Array< MultiFab *, AMREX_SPACEDIM > &area_vec, const Geometry &geom, const Vector< BCRec > &domain_bcs_type_h)
 

Function Documentation

◆ compute_influx_outflux_bdy()

void compute_influx_outflux_bdy ( FArrayBox &  bdy_data_xlo,
FArrayBox &  bdy_data_xhi,
FArrayBox &  bdy_data_ylo,
FArrayBox &  bdy_data_yhi,
Array< MultiFab *, AMREX_SPACEDIM > &  area_vec,
const iMultiFab &  mask_x,
const iMultiFab &  mask_y,
const Geometry &  geom,
Real &  influx,
Real &  outflux,
const int  n 
)
164 {
165  BL_PROFILE_VAR("compute_influx_outflux_bdy()", computeInfluxOutfluxBdy);
166 
167  influx = zero, outflux = zero;
168 
169  const Box domain = geom.Domain();
170  const auto& domlo = lbound(domain);
171  const auto& domhi = ubound(domain);
172 
173  // Normal face area (of undistorted mesh)
174  const Real* a_dx = geom.CellSize();
175  const Real ds_x = a_dx[1];
176  const Real ds_y = a_dx[0];
177 
178  IntVect ngrow = {0,0,0};
179 
180  // X-dir
181  const auto& bdatxlo = bdy_data_xlo.const_array();
182  const auto& bdatxhi = bdy_data_xhi.const_array();
183  auto const& area_x = area_vec[0]->const_arrays();
184  auto const& mx = mask_x.const_arrays(); // owner mask: count shared faces once
185  influx += ds_x *
186  ParReduce(TypeList<ReduceOpSum>{},
187  TypeList<Real>{},
188  *area_vec[0], ngrow,
189  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k)
190  noexcept -> GpuTuple<Real>
191  {
192  if (mx[box_no](i,j,k) == 0) { return { zero }; }
193  if ( (i == domlo.x + n) && (j >= domlo.y+n && j<= domhi.y-n) && bdatxlo(i,j,k) > zero) {
194  return { std::abs(bdatxlo(i,j,k)) * area_x[box_no](i,j,k) };
195  } else if ( (i == domhi.x+1 - n) && (j >= domlo.y+n && j<= domhi.y-n) && bdatxhi(i,j,k) < zero) {
196  return { std::abs(bdatxhi(i,j,k)) * area_x[box_no](i,j,k) };
197  } else {
198  return { zero };
199  }
200  });
201 
202  outflux += ds_x *
203  ParReduce(TypeList<ReduceOpSum>{},
204  TypeList<Real>{},
205  *area_vec[0], ngrow,
206  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k)
207  noexcept -> GpuTuple<Real>
208  {
209  if (mx[box_no](i,j,k) == 0) { return { zero }; }
210  if (i == (domlo.x + n) && (j >= domlo.y+n && j<= domhi.y-n) && bdatxlo(i,j,k) < zero) {
211  return { std::abs(bdatxlo(i,j,k)) * area_x[box_no](i,j,k) };
212  } else if ( (i == domhi.x+1 - n) && (j >= domlo.y+n && j<= domhi.y-n) && bdatxhi(i,j,k) > zero) {
213  return { std::abs(bdatxhi(i,j,k)) * area_x[box_no](i,j,k) };
214  } else {
215  return { zero };
216  }
217  });
218 
219  // Y-dir
220  const auto& bdatylo = bdy_data_ylo.const_array();
221  const auto& bdatyhi = bdy_data_yhi.const_array();
222  auto const& area_y = area_vec[1]->const_arrays();
223  auto const& my = mask_y.const_arrays();
224  influx += ds_y *
225  ParReduce(TypeList<ReduceOpSum>{},
226  TypeList<Real>{},
227  *area_vec[1], ngrow,
228  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k)
229  noexcept -> GpuTuple<Real>
230  {
231  if (my[box_no](i,j,k) == 0) { return { zero }; }
232  if ( (j == domlo.y + n) && (i >= domlo.x+n && i<= domhi.x-n) && bdatylo(i,j,k) > zero) {
233  return { std::abs(bdatylo(i,j,k)) * area_y[box_no](i,j,k) };
234  } else if ( (j == domhi.y+1 - n) && (i >= domlo.x+n && i<= domhi.x-n) && bdatyhi(i,j,k) < zero) {
235  return { std::abs(bdatyhi(i,j,k)) * area_y[box_no](i,j,k) };
236  } else {
237  return { zero };
238  }
239  });
240 
241  outflux += ds_y *
242  ParReduce(TypeList<ReduceOpSum>{},
243  TypeList<Real>{},
244  *area_vec[1], ngrow,
245  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k)
246  noexcept -> GpuTuple<Real>
247  {
248  if (my[box_no](i,j,k) == 0) { return { zero }; }
249  if ( (j == domlo.y + n) && (i >= domlo.x+n && i<= domhi.x-n) && bdatylo(i,j,k) < zero) {
250  return { std::abs(bdatylo(i,j,k)) * area_y[box_no](i,j,k) };
251  } else if ( (j == domhi.y+1 - n) && (i >= domlo.x+n && i<= domhi.x-n) && bdatyhi(i,j,k) > zero) {
252  return { std::abs(bdatyhi(i,j,k)) * area_y[box_no](i,j,k) };
253  } else {
254  return { zero };
255  }
256  });
257 
258  ParallelDescriptor::ReduceRealSum(influx);
259  ParallelDescriptor::ReduceRealSum(outflux);
260 }
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36

Referenced by enforceInOutSolvability_bdy().

Here is the caller graph for this function:

◆ enforceInOutSolvability_bdy()

void enforceInOutSolvability_bdy ( const MultiFab &  rho0,
FArrayBox &  bdy_data_xlo,
FArrayBox &  bdy_data_xhi,
FArrayBox &  bdy_data_ylo,
FArrayBox &  bdy_data_yhi,
Array< MultiFab *, AMREX_SPACEDIM > &  area_vec,
const Geometry &  geom,
const Vector< BCRec > &  domain_bcs_type_h 
)
270 {
271  BL_PROFILE_VAR("enforceInOutSolvability_bdy()", enforceInOutSolvabilityBdy);
272 
273 #ifdef AMREX_USE_FLOAT
274  Real small_vel = Real(1.e-6);
275 #else
276  Real small_vel = Real(1.e-8);
277 #endif
278 
279  Box domain(geom.Domain());
280 
281  bool multiply_by_rho0 = true;
282  scale_bdy_normal_by_rho0(rho0, bdy_data_xlo, 0, domain, domain_bcs_type_h, multiply_by_rho0);
283  scale_bdy_normal_by_rho0(rho0, bdy_data_xhi, 0, domain, domain_bcs_type_h, multiply_by_rho0);
284  scale_bdy_normal_by_rho0(rho0, bdy_data_ylo, 1, domain, domain_bcs_type_h, multiply_by_rho0);
285  scale_bdy_normal_by_rho0(rho0, bdy_data_yhi, 1, domain, domain_bcs_type_h, multiply_by_rho0);
286 
287  int width =bdy_data_xlo.box().length(0);
288  AMREX_ASSERT(width == bdy_data_xhi.box().length(0));
289  AMREX_ASSERT(width == bdy_data_ylo.box().length(1));
290  AMREX_ASSERT(width == bdy_data_yhi.box().length(1));
291  // amrex::Print() << "width in enforce solvability " << width << std::endl;
292 
293  // Faces on a box boundary belong to both boxes; count each once
294  auto mask_x = OwnerMask(*area_vec[0], geom.periodicity());
295  auto mask_y = OwnerMask(*area_vec[1], geom.periodicity());
296 
297  for (int n = 0; n < width; n++)
298  {
299  Real influx = zero, outflux = zero;
300  compute_influx_outflux_bdy(bdy_data_xlo, bdy_data_xhi,
301  bdy_data_ylo, bdy_data_yhi,
302  area_vec, *mask_x, *mask_y, geom, influx, outflux, n);
303 
304  // amrex::Print() << " TOTAL BDY INFLUX / OUTFLOW AT WIDTH " << n << " " << influx << " " << outflux << "\n";
305 
306  if ((influx > small_vel) && (outflux < small_vel)) {
307  Abort("Cannot enforce solvability on bdy_data, no outflow from the direction dependent boundaries");
308  } else if ((influx < small_vel) && (outflux < small_vel)) {
309  // do nothing
310  } else {
311  const Real alpha_fcf = influx/outflux; // flux correction factor
312 
313  correct_bdy_outflow_on_face(bdy_data_xlo, 0, true , domain, alpha_fcf, n);
314  correct_bdy_outflow_on_face(bdy_data_xhi, 0, false, domain, alpha_fcf, n);
315  correct_bdy_outflow_on_face(bdy_data_ylo, 1, true , domain, alpha_fcf, n);
316  correct_bdy_outflow_on_face(bdy_data_yhi, 1, false, domain, alpha_fcf, n);
317 
318  // For diagnostic purposes.
319  // Real influx_dbg = zero, outflux_dbg = zero;
320  // compute_influx_outflux_bdy(bdy_data_xlo, bdy_data_xhi,
321  // bdy_data_ylo, bdy_data_yhi,
322  // area_vec, *mask_x, *mask_y, geom, influx_dbg, outflux_dbg, n);
323  // amrex::Print() << " TOTAL BDY INFLUX / OUTFLOW AT WIDTH " << n << " " << influx_dbg << " " << outflux_dbg << "\n";
324  }
325  }
326 
327  multiply_by_rho0 = false;
328  scale_bdy_normal_by_rho0(rho0, bdy_data_xlo, 0, domain, domain_bcs_type_h, multiply_by_rho0);
329  scale_bdy_normal_by_rho0(rho0, bdy_data_xhi, 0, domain, domain_bcs_type_h, multiply_by_rho0);
330  scale_bdy_normal_by_rho0(rho0, bdy_data_ylo, 1, domain, domain_bcs_type_h, multiply_by_rho0);
331  scale_bdy_normal_by_rho0(rho0, bdy_data_yhi, 1, domain, domain_bcs_type_h, multiply_by_rho0);
332 }
void compute_influx_outflux_bdy(FArrayBox &bdy_data_xlo, FArrayBox &bdy_data_xhi, FArrayBox &bdy_data_ylo, FArrayBox &bdy_data_yhi, Array< MultiFab *, AMREX_SPACEDIM > &area_vec, const iMultiFab &mask_x, const iMultiFab &mask_y, const Geometry &geom, Real &influx, Real &outflux, const int n)
Definition: ERF_EnforceConstraintOnBdy.cpp:157
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.
Definition: ERF_EnforceConstraintOnBdy.cpp:124
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.
Definition: ERF_EnforceConstraintOnBdy.cpp:23
Here is the call graph for this function: