ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InteriorGhostCells.cpp File Reference
#include "ERF_Utils.H"
Include dependency graph for ERF_InteriorGhostCells.cpp:

Functions

void realbdy_interior_bxs_xy (const Box &bx, const Box &domain, const int &width, Box &bx_xlo, Box &bx_xhi, Box &bx_ylo, Box &bx_yhi, const IntVect &ng_vect, const bool get_int_ng)
 
void realbdy_bc_bxs_xy (const Box &bx, const Box &domain, const int &set_width, Box &bx_xlo, Box &bx_xhi, Box &bx_ylo, Box &bx_yhi, const IntVect &ng_vect)
 
void realbdy_compute_interior_ghost_rhs (const double &elapsed_time, const double &start_time, const double &delta_t_d, const double &start_bdy_time, const double &final_bdy_time, const double &bdy_time_interval, const Real &nudge_factor, int width, const Geometry &geom, Vector< MultiFab > &S_rhs, Vector< MultiFab > &S_cur_data, Vector< Vector< FArrayBox >> &bdy_data_xlo, Vector< Vector< FArrayBox >> &bdy_data_xhi, Vector< Vector< FArrayBox >> &bdy_data_ylo, Vector< Vector< FArrayBox >> &bdy_data_yhi, std::unique_ptr< ReadBndryPlanes > &m_r2d, const Real &c_p, const Real &rdOcp, const bool use_wrf_bdy_density, const Real &bdy_rho_nudge_factor)
 
void fine_compute_interior_ghost_rhs (const double &time, const double &delta_t_d, const int &width, const int &set_width, const Geometry &geom, ERFFillPatcher *FPr_c, ERFFillPatcher *FPr_u, ERFFillPatcher *FPr_v, ERFFillPatcher *FPr_w, Vector< BCRec > &domain_bcs_type, Vector< MultiFab > &S_rhs_f, Vector< MultiFab > &S_data_f)
 

Variables

PhysBCFunctNoOp void_bc
 

Function Documentation

◆ fine_compute_interior_ghost_rhs()

void fine_compute_interior_ghost_rhs ( const double &  time,
const double &  delta_t_d,
const int &  width,
const int &  set_width,
const Geometry &  geom,
ERFFillPatcher *  FPr_c,
ERFFillPatcher *  FPr_u,
ERFFillPatcher *  FPr_v,
ERFFillPatcher *  FPr_w,
Vector< BCRec > &  domain_bcs_type,
Vector< MultiFab > &  S_rhs_f,
Vector< MultiFab > &  S_data_f 
)

Compute the RHS in the fine relaxation zone

Parameters
[in]timecurrent (elapsed) time
[in]delta_ttimestep
[in]widthnumber of cells in (relaxation+specified) zone
[in]set_widthnumber of cells in (specified) zone
[in]FPr_ccons fine patch container
[in]FPr_uuvel fine patch container
[in]FPr_vvvel fine patch container
[in]FPr_wwvel fine patch container
[in]boxes_at_levelboxes at current level
[in]domain_bcs_typeboundary condition types
[out]S_rhsRHS to be computed here
[in]S_datacurrent value of the solution
757 {
758  BL_PROFILE_REGION("fine_compute_interior_ghost_RHS()");
759 
760  Real delta_t = static_cast<Real>(delta_t_d);
761 
762  // Relaxation constants
763  Real F1 = one/(Real(10.)*delta_t);
764  Real F2 = one/(Real(50.)*delta_t);
765 
766  // Vector of MFs to hold data (dm differs w/ fine patch)
767  Vector<MultiFab> fmf_p_v;
768 
769  // Loop over the variables
770  for (int ivar_idx = 0; ivar_idx < IntVars::NumTypes; ++ivar_idx)
771  {
772  // Fine mfs
773  MultiFab& fmf = S_data_f[ivar_idx];
774  MultiFab& rhs = S_rhs_f [ivar_idx];
775 
776  // NOTE: These temporary MFs and copy operations are horrible
777  // for memory usage and efficiency. However, we need to
778  // have access to ghost cells in the cons array to convert
779  // from primitive u/v/w to momentum. Furthermore, the BA
780  // for the fine patches in ERFFillPatcher don't match the
781  // BA for the data/RHS. For this reason, the data is copied
782  // to a vector of MFs (with ghost cells) so the BAs match
783  // the BA of data/RHS and we have access to rho to convert
784  // prim to conserved.
785 
786  // Temp MF on box (distribution map differs w/ fine patch)
787  int num_var = fmf.nComp();
788  fmf_p_v.emplace_back(fmf.boxArray(), fmf.DistributionMap(), num_var, fmf.nGrowVect());
789  MultiFab& fmf_p = fmf_p_v[ivar_idx];
790  MultiFab::Copy(fmf_p,fmf, 0, 0, num_var, fmf.nGrowVect());
791 
792  // Integer mask MF
793  int set_mask_val;
794  int relax_mask_val;
795  iMultiFab* mask;
796 
797  // Fill fine patch on interior halo region
798  //==========================================================
799  if (ivar_idx == IntVars::cons)
800  {
801  FPr_c->FillRelax(fmf_p, time, void_bc, domain_bcs_type);
802  mask = FPr_c->GetMask();
803  set_mask_val = FPr_c->GetSetMaskVal();
804  relax_mask_val = FPr_c->GetRelaxMaskVal();
805  }
806  else if (ivar_idx == IntVars::xmom)
807  {
808  FPr_u->FillRelax(fmf_p, time, void_bc, domain_bcs_type);
809  mask = FPr_u->GetMask();
810  set_mask_val = FPr_u->GetSetMaskVal();
811  relax_mask_val = FPr_u->GetRelaxMaskVal();
812 
813 #ifdef _OPENMP
814 #pragma omp parallel if (Gpu::notInLaunchRegion())
815 #endif
816  for ( MFIter mfi(fmf_p,TilingIfNotGPU()); mfi.isValid(); ++mfi)
817  {
818  Box tbx = mfi.tilebox();
819 
820  const Array4<Real>& prim_arr = fmf_p.array(mfi);
821  const Array4<const Real>& rho_arr = fmf_p_v[0].const_array(mfi);
822  const Array4<const int>& mask_arr = mask->const_array(mfi);
823 
824  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
825  {
826  if (mask_arr(i,j,k) == relax_mask_val) {
827  Real rho_interp = myhalf * ( rho_arr(i-1,j,k) + rho_arr(i,j,k) );
828  prim_arr(i,j,k) *= rho_interp;
829  }
830  });
831  } // mfi
832  }
833  else if (ivar_idx == IntVars::ymom)
834  {
835  FPr_v->FillRelax(fmf_p, time, void_bc, domain_bcs_type);
836  mask = FPr_v->GetMask();
837  set_mask_val = FPr_v->GetSetMaskVal();
838  relax_mask_val = FPr_v->GetRelaxMaskVal();
839 
840 #ifdef _OPENMP
841 #pragma omp parallel if (Gpu::notInLaunchRegion())
842 #endif
843  for ( MFIter mfi(fmf_p,TilingIfNotGPU()); mfi.isValid(); ++mfi)
844  {
845  Box tbx = mfi.tilebox();
846 
847  const Array4<Real>& prim_arr = fmf_p.array(mfi);
848  const Array4<const Real>& rho_arr = fmf_p_v[0].const_array(mfi);
849  const Array4<const int>& mask_arr = mask->const_array(mfi);
850 
851  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
852  {
853  if (mask_arr(i,j,k) == relax_mask_val) {
854  Real rho_interp = myhalf * ( rho_arr(i,j-1,k) + rho_arr(i,j,k) );
855  prim_arr(i,j,k) *= rho_interp;
856  }
857  });
858  } // mfi
859  }
860  else if (ivar_idx == IntVars::zmom)
861  {
862  FPr_w->FillRelax(fmf_p, time, void_bc, domain_bcs_type);
863  mask = FPr_w->GetMask();
864  set_mask_val = FPr_w->GetSetMaskVal();
865  relax_mask_val = FPr_w->GetRelaxMaskVal();
866 
867 #ifdef _OPENMP
868 #pragma omp parallel if (Gpu::notInLaunchRegion())
869 #endif
870  for ( MFIter mfi(fmf_p,TilingIfNotGPU()); mfi.isValid(); ++mfi)
871  {
872  Box tbx = mfi.tilebox();
873 
874  const Array4<Real>& prim_arr = fmf_p.array(mfi);
875  const Array4<const Real>& rho_arr = fmf_p_v[0].const_array(mfi);
876  const Array4<const int>& mask_arr = mask->const_array(mfi);
877 
878  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
879  {
880  if (mask_arr(i,j,k) == relax_mask_val) {
881  Real rho_interp = myhalf * ( rho_arr(i,j,k-1) + rho_arr(i,j,k) );
882  prim_arr(i,j,k) *= rho_interp;
883  }
884  });
885  } // mfi
886  } else {
887  Abort("Dont recognize this variable type in fine_compute_interior_ghost_RHS");
888  }
889 
890 
891  // Zero RHS in set region
892  //==========================================================
893 #ifdef _OPENMP
894 #pragma omp parallel if (Gpu::notInLaunchRegion())
895 #endif
896  for ( MFIter mfi(rhs,TilingIfNotGPU()); mfi.isValid(); ++mfi)
897  {
898  Box tbx = mfi.tilebox();
899  const Array4<Real>& rhs_arr = rhs.array(mfi);
900  const Array4<const int>& mask_arr = mask->const_array(mfi);
901 
902  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
903  {
904  if (mask_arr(i,j,k) == set_mask_val) {
905  rhs_arr(i,j,k) = zero;
906  }
907  });
908  } // mfi
909 
910  // For Laplacian stencil
911  rhs.FillBoundary(geom.periodicity());
912 
913 
914  // Compute RHS in relaxation region
915  //==========================================================
916 #ifdef _OPENMP
917 #pragma omp parallel if (Gpu::notInLaunchRegion())
918 #endif
919  for ( MFIter mfi(fmf_p,TilingIfNotGPU()); mfi.isValid(); ++mfi)
920  {
921  Box tbx = mfi.tilebox();
922  const Array4<Real>& rhs_arr = rhs.array(mfi);
923  const Array4<const Real>& fine_arr = fmf_p.const_array(mfi);
924  const Array4<const Real>& data_arr = fmf.const_array(mfi);
925  const Array4<const int>& mask_arr = mask->const_array(mfi);
926 
927  Box vbx = mfi.validbox();
928  const auto& vbx_lo = lbound(vbx);
929  const auto& vbx_hi = ubound(vbx);
930 
931  int icomp = 0;
932 
933  int Spec_z = set_width;
934  int Relax_z = width - Spec_z;
935  Real num = Real(Spec_z + Relax_z);
936  Real denom = Real(Relax_z - 1);
937  ParallelFor(tbx, num_var, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
938  {
939  if (mask_arr(i,j,k) == relax_mask_val) {
940 
941  // Indices
942  Real n_ind(-1); // Set to -1 to quiet compiler warning
943  int ii(width-1); int jj(width-1);
944  bool near_x_lo_wall(false); bool near_x_hi_wall(false);
945  bool near_y_lo_wall(false); bool near_y_hi_wall(false);
946  bool mask_x_found(false); bool mask_y_found(false);
947 
948  // Near x-wall
949  if ((i-vbx_lo.x) < width) {
950  near_x_lo_wall = true;
951  ii = i-vbx_lo.x;
952  if (mask_arr(vbx_lo.x,j,k) == 2) mask_x_found = true;
953  } else if ((vbx_hi.x-i) < width) {
954  near_x_hi_wall = true;
955  ii = vbx_hi.x-i;
956  if (mask_arr(vbx_hi.x,j,k) == 2) mask_x_found = true;
957  }
958 
959  // Near y-wall
960  if ((j-vbx_lo.y) < width) {
961  near_y_lo_wall = true;
962  jj = j-vbx_lo.y;
963  if (mask_arr(i,vbx_lo.y,k) == 2) mask_y_found = true;
964  } else if ((vbx_hi.y-j) < width) {
965  near_y_hi_wall = true;
966  jj = vbx_hi.y-j;
967  if (mask_arr(i,vbx_hi.y,k) == 2) mask_y_found = true;
968  }
969 
970  // Found a nearby masked cell (valid n_ind)
971  if (mask_x_found && mask_y_found) {
972  n_ind = std::min(ii,jj) + one;
973  } else if (mask_x_found) {
974  n_ind = ii + one;
975  } else if (mask_y_found) {
976  n_ind = jj + one;
977  // Pesky corner cell
978  } else {
979  if (near_x_lo_wall || near_x_hi_wall) {
980  Real dj_min{width-one};
981  int j_lb = std::max(vbx_lo.y,j-width);
982  int j_ub = std::min(vbx_hi.y,j+width);
983  int li = (near_x_lo_wall) ? vbx_lo.x : vbx_hi.x;
984  for (int lj(j_lb); lj<=j_ub; ++lj) {
985  if (mask_arr(li,lj,k) == 2) {
986  mask_y_found = true;
987  dj_min = std::min(dj_min,(Real) std::abs(lj-j));
988  }
989  }
990  if (mask_y_found) {
991  Real mag = std::sqrt( Real(dj_min*dj_min + ii*ii) );
992  n_ind = std::min(mag,width-one) + one;
993  } else {
994  Abort("Mask not found near x wall!");
995  }
996  } else if (near_y_lo_wall || near_y_hi_wall) {
997  Real di_min{width-one};
998  int i_lb = std::max(vbx_lo.x,i-width);
999  int i_ub = std::min(vbx_hi.x,i+width);
1000  int lj = (near_y_lo_wall) ? vbx_lo.y : vbx_hi.y;
1001  for (int li(i_lb); li<=i_ub; ++li) {
1002  if (mask_arr(li,lj,k) == 2) {
1003  mask_x_found = true;
1004  di_min = std::min(di_min,(Real) std::abs(li-i));
1005  }
1006  }
1007  if (mask_x_found) {
1008  Real mag = std::sqrt( Real(di_min*di_min + jj*jj) );
1009  n_ind = std::min(mag,width-one) + one;
1010  } else {
1011  Abort("Mask not found near y wall!");
1012  }
1013  } else {
1014  Abort("Relaxation cell must be near a wall!");
1015  }
1016  }
1017 
1018  Real Factor = (num - n_ind)/denom;
1019  Real d = data_arr(i ,j ,k ,n+icomp) + delta_t*rhs_arr(i , j , k ,n+icomp);
1020  Real d_ip1 = data_arr(i+1,j ,k ,n+icomp) + delta_t*rhs_arr(i+1, j , k ,n+icomp);
1021  Real d_im1 = data_arr(i-1,j ,k ,n+icomp) + delta_t*rhs_arr(i-1, j , k ,n+icomp);
1022  Real d_jp1 = data_arr(i ,j+1,k ,n+icomp) + delta_t*rhs_arr(i , j+1, k ,n+icomp);
1023  Real d_jm1 = data_arr(i ,j-1,k ,n+icomp) + delta_t*rhs_arr(i , j-1, k ,n+icomp);
1024  Real delta = fine_arr(i ,j ,k,n) - d;
1025  Real delta_xp = fine_arr(i+1,j ,k,n) - d_ip1;
1026  Real delta_xm = fine_arr(i-1,j ,k,n) - d_im1;
1027  Real delta_yp = fine_arr(i ,j+1,k,n) - d_jp1;
1028  Real delta_ym = fine_arr(i ,j-1,k,n) - d_jm1;
1029  Real Laplacian = delta_xp + delta_xm + delta_yp + delta_ym - Real(4.0)*delta;
1030  rhs_arr(i,j,k,n) += (F1*delta - F2*Laplacian) * Factor;
1031  }
1032  });
1033  } // mfi
1034  } // ivar_idx
1035 }
@ num
Definition: ERF_DataStruct.H:40
for(int i=0;i< m_num_species;i++)
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:52
PhysBCFunctNoOp void_bc
Definition: ERF_InteriorGhostCells.cpp:5
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 one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
auto rho_arr
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:3
amrex::iMultiFab * GetMask()
Definition: ERF_FillPatcher.H:124
void FillRelax(amrex::MultiFab &mf, double time, BC &cbc, amrex::Vector< amrex::BCRec > const &bcs)
Definition: ERF_FillPatcher.H:220
int GetSetMaskVal()
Definition: ERF_FillPatcher.H:98
int GetRelaxMaskVal()
Definition: ERF_FillPatcher.H:119
@ NumTypes
Definition: ERF_IndexDefines.H:253
@ ymom
Definition: ERF_IndexDefines.H:251
@ cons
Definition: ERF_IndexDefines.H:249
@ zmom
Definition: ERF_IndexDefines.H:252
@ xmom
Definition: ERF_IndexDefines.H:250
Here is the call graph for this function:

◆ realbdy_bc_bxs_xy()

void realbdy_bc_bxs_xy ( const Box &  bx,
const Box &  domain,
const int &  set_width,
Box &  bx_xlo,
Box &  bx_xhi,
Box &  bx_ylo,
Box &  bx_yhi,
const IntVect &  ng_vect 
)

Get the boxes for looping over interior/exterior ghost cells for use by fillpatch, erf_slow_rhs_pre, and erf_slow_rhs_post.

Parameters
[in]bxbox to intersect with 4 halo regions
[in]domainbox of the whole domain
[in]widthnumber of cells in (relaxation+specified) zone
[in]set_widthnumber of cells in (specified) zone
[out]bx_xlohalo box at x_lo boundary
[out]bx_xhihalo box at x_hi boundary
[out]bx_ylohalo box at y_lo boundary
[out]bx_yhihalo box at y_hi boundary
[in]ng_vectnumber of ghost cells in each direction
[in]get_int_ngflag to get ghost cells inside the domain
101 {
102  AMREX_ALWAYS_ASSERT(bx.ixType() == domain.ixType());
103 
104  // Domain bounds without ghost cells
105  const auto& dom_lo = lbound(domain);
106  const auto& dom_hi = ubound(domain);
107 
108  // Four boxes matching the domain
109  Box gdom_xlo(domain); Box gdom_xhi(domain);
110  Box gdom_ylo(domain); Box gdom_yhi(domain);
111 
112  // Get offsets from box index type
113  IntVect iv_type = bx.ixType().toIntVect();
114  int offx = (iv_type[0]==1) ? 0 : -1;
115  int offy = (iv_type[1]==1) ? 0 : -1;
116 
117  // Stagger the boxes based upon index type
118  gdom_xlo += IntVect(offx,0,0); gdom_xhi += IntVect(-offx,0,0);
119  gdom_ylo += IntVect(0,offy,0); gdom_yhi += IntVect(0,-offy,0);
120 
121  // Trim the boxes to only include internal ghost cells
122  gdom_xlo.setBig(0,dom_lo.x+set_width+offx-1); gdom_xhi.setSmall(0,dom_hi.x-set_width-offx+1);
123  gdom_ylo.setBig(1,dom_lo.y+set_width+offy-1); gdom_yhi.setSmall(1,dom_hi.y-set_width-offy+1);
124 
125  // Remove overlapping corners from y-face boxes
126  gdom_ylo.setSmall(0,gdom_xlo.bigEnd(0)+1); gdom_ylo.setBig(0,gdom_xhi.smallEnd(0)-1);
127  gdom_yhi.setSmall(0,gdom_xlo.bigEnd(0)+1); gdom_yhi.setBig(0,gdom_xhi.smallEnd(0)-1);
128 
129  // Grow boxes to get external ghost cells only
130  gdom_xlo.growLo(0,ng_vect[0]+offx); gdom_xhi.growHi(0,ng_vect[0]+offx);
131  gdom_xlo.grow (1,ng_vect[1] ); gdom_xhi.grow (1,ng_vect[1] );
132  gdom_ylo.growLo(1,ng_vect[1]+offy); gdom_yhi.growHi(1,ng_vect[1]+offy);
133 
134  // Populate everything
135  bx_xlo = (bx & gdom_xlo);
136  bx_xhi = (bx & gdom_xhi);
137  bx_ylo = (bx & gdom_ylo);
138  bx_yhi = (bx & gdom_yhi);
139 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
Here is the call graph for this function:

◆ realbdy_compute_interior_ghost_rhs()

void realbdy_compute_interior_ghost_rhs ( const double &  elapsed_time,
const double &  start_time,
const double &  delta_t_d,
const double &  start_bdy_time,
const double &  final_bdy_time,
const double &  bdy_time_interval,
const Real &  nudge_factor,
int  width,
const Geometry &  geom,
Vector< MultiFab > &  S_rhs,
Vector< MultiFab > &  S_cur_data,
Vector< Vector< FArrayBox >> &  bdy_data_xlo,
Vector< Vector< FArrayBox >> &  bdy_data_xhi,
Vector< Vector< FArrayBox >> &  bdy_data_ylo,
Vector< Vector< FArrayBox >> &  bdy_data_yhi,
std::unique_ptr< ReadBndryPlanes > &  m_r2d,
const Real &  c_p,
const Real &  rdOcp,
const bool  use_wrf_bdy_density,
const Real &  bdy_rho_nudge_factor 
)

Compute the RHS in the relaxation zone

Parameters
[in]elapsed_timecurrent time, measured from the start of the run
[in]start_timeepoch time of the start of the run
[in]delta_ttimestep
[in]start_bdy_timefull time of the first time slice of boundary data
[in]final_bdy_timefull time of the last time slice of boundary data
[in]bdy_time_intervaltime interval between boundary condition time stamps
[in]widthnumber of cells in (relaxation+specified) zone
[in]set_widthnumber of cells in (specified) zone
[in]geomcontainer for geometric information
[out]S_rhsRHS to be computed here
[in]S_datacurrent value of the solution
[in]bdy_data_xloboundary data on interior of low x-face
[in]bdy_data_xhiboundary data on interior of high x-face
[in]bdy_data_yloboundary data on interior of low y-face
[in]bdy_data_yhiboundary data on interior of high y-face
182 {
183  BL_PROFILE_REGION("realbdy_compute_interior_ghost_RHS()");
184 
185  Real delta_t = static_cast<Real>(delta_t_d);
186 
187  //
188  // start_bdy_time and final_bdy_time are measured as total (epoch) time
189  //
190  const double time = start_time + elapsed_time; // total time, for the boundary planes
191 
192  // Get bndry data if we have it
193  Vector<int> bnd_map = {BCVars::xvel_bc, BCVars::yvel_bc, BCVars::RhoTheta_bc_comp};
194  Array4<Real> bdatxlo, bdatxhi, bdatylo, bdatyhi;
195  Array4<Real> btenxlo, btenxhi, btenylo, btenyhi;
196  if (m_r2d) {
197  // Index is [plane orientation] and [level]
198  Vector<std::unique_ptr<PlaneVector>>& bndry_data = m_r2d->interp_in_time(time);
199  bdatxlo = (*bndry_data[0])[0].array();
200  bdatylo = (*bndry_data[1])[0].array();
201  bdatxhi = (*bndry_data[3])[0].array();
202  bdatyhi = (*bndry_data[4])[0].array();
203 
204  Vector<std::unique_ptr<PlaneVector>>& bndry_tend = m_r2d->get_tendency(time);
205  btenxlo = (*bndry_tend[0])[0].array();
206  btenylo = (*bndry_tend[1])[0].array();
207  btenxhi = (*bndry_tend[3])[0].array();
208  btenyhi = (*bndry_tend[4])[0].array();
209  }
210 
211  // Relaxation constants
212  Real F1 = one/(nudge_factor*delta_t);
213  Real F1_rho = one/((bdy_rho_nudge_factor > zero ? bdy_rho_nudge_factor : nudge_factor) * delta_t);
214 
215  // Time interpolation (see bdy_time_weights for why the offset is formed first)
216  const BdyTimeWeights tw = bdy_time_weights(elapsed_time + (start_time - start_bdy_time),
217  final_bdy_time - start_bdy_time,
218  bdy_time_interval);
219  const int n_time = tw.n_lo;
220  const int n_time_p1 = tw.n_hi;
221  const Real alpha = tw.alpha;
222  Real oma = one - alpha;
223 
224  // Temporary FABs for storage (owned/filled on all ranks)
225  FArrayBox U_xlo, U_xhi, U_ylo, U_yhi;
226  FArrayBox V_xlo, V_xhi, V_ylo, V_yhi;
227  FArrayBox T_xlo, T_xhi, T_ylo, T_yhi;
228  FArrayBox R_xlo, R_xhi, R_ylo, R_yhi;
229  Array4<Real> r_xlo_arr, r_xhi_arr, r_ylo_arr, r_yhi_arr;
230 
231  // Variable index map (WRFBdyVars -> Vars)
232  Vector<int> var_map = {Vars::xvel, Vars::yvel, Vars::cons };
233  Vector<int> ivar_map = {IntVars::xmom, IntVars::ymom, IntVars::cons};
234 
235  // Variable icomp map
236  Vector<int> comp_map = {0, 0, RhoTheta_comp};
237 
238  // Indices
239  int ivarU = RealBdyVars::U;
240  int ivarV = RealBdyVars::V;
241  int ivarT = RealBdyVars::T;
242  // This helper applies the velocity/theta boundary relaxation only;
243  // density (R) and moisture (QV) are handled by fill_from_realbdy.
244  int BdyEnd = RealBdyVars::T + 1;
245 
246  // NOTE: The sizing of the temporary BDY FABS is
247  // GLOBAL and occurs over the entire BDY region.
248 
249  // Size the FABs
250  //==========================================================
251  for (int ivar(ivarU); ivar < BdyEnd; ivar++) {
252  int ivar_idx = var_map[ivar];
253  Box domain = geom.Domain();
254  auto ixtype = S_cur_data[ivar_idx].boxArray().ixType();
255  domain.convert(ixtype);
256 
257  // NOTE: Ghost cells needed for idx type mismatch between mask and data (do_upwind)
258  IntVect ng_vect(0);
259  //IntVect ng_vect(1,1,0);
260  Box gdom(domain); gdom.grow(ng_vect);
261  Box bx_xlo, bx_xhi, bx_ylo, bx_yhi;
262  realbdy_interior_bxs_xy(gdom, domain, width,
263  bx_xlo, bx_xhi,
264  bx_ylo, bx_yhi,
265  ng_vect, true);
266 
267  // Size the FABs
268  if (ivar == ivarU) {
269  U_xlo.resize(bx_xlo,1,The_Async_Arena()); U_xhi.resize(bx_xhi,1,The_Async_Arena());
270  U_ylo.resize(bx_ylo,1,The_Async_Arena()); U_yhi.resize(bx_yhi,1,The_Async_Arena());
271  } else if (ivar == ivarV) {
272  V_xlo.resize(bx_xlo,1,The_Async_Arena()); V_xhi.resize(bx_xhi,1,The_Async_Arena());
273  V_ylo.resize(bx_ylo,1,The_Async_Arena()); V_yhi.resize(bx_yhi,1,The_Async_Arena());
274  } else if (ivar == ivarT){
275  T_xlo.resize(bx_xlo,1,The_Async_Arena()); T_xhi.resize(bx_xhi,1,The_Async_Arena());
276  T_ylo.resize(bx_ylo,1,The_Async_Arena()); T_yhi.resize(bx_yhi,1,The_Async_Arena());
277  } else {
278  continue;
279  }
280  } // ivar
281 
282  if (use_wrf_bdy_density) {
283  const IntVect ng_vect(1,1,0);
284  Box domain = geom.Domain();
285  Box gdom(domain); gdom.grow(ng_vect);
286  Box bx_xlo, bx_xhi, bx_ylo, bx_yhi;
287  realbdy_interior_bxs_xy(gdom, domain, width,
288  bx_xlo, bx_xhi, bx_ylo, bx_yhi,
289  ng_vect, true);
290 
291  R_xlo.resize(bx_xlo, 1, The_Async_Arena());
292  R_xhi.resize(bx_xhi, 1, The_Async_Arena());
293  R_ylo.resize(bx_ylo, 1, The_Async_Arena());
294  R_yhi.resize(bx_yhi, 1, The_Async_Arena());
295 
296  const auto& r_xlo_n = bdy_data_xlo[n_time ][WRFBdyVars::R].const_array();
297  const auto& r_xlo_np1 = bdy_data_xlo[n_time_p1][WRFBdyVars::R].const_array();
298  const auto& r_xhi_n = bdy_data_xhi[n_time ][WRFBdyVars::R].const_array();
299  const auto& r_xhi_np1 = bdy_data_xhi[n_time_p1][WRFBdyVars::R].const_array();
300  const auto& r_ylo_n = bdy_data_ylo[n_time ][WRFBdyVars::R].const_array();
301  const auto& r_ylo_np1 = bdy_data_ylo[n_time_p1][WRFBdyVars::R].const_array();
302  const auto& r_yhi_n = bdy_data_yhi[n_time ][WRFBdyVars::R].const_array();
303  const auto& r_yhi_np1 = bdy_data_yhi[n_time_p1][WRFBdyVars::R].const_array();
304  const auto& rbx = lbound(domain);
305  const auto& rhi = ubound(domain);
306  r_xlo_arr = R_xlo.array();
307  r_xhi_arr = R_xhi.array();
308  r_ylo_arr = R_ylo.array();
309  r_yhi_arr = R_yhi.array();
310 
311  ParallelFor(bx_xlo, bx_xhi,
312  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
313  int ii = amrex::max(i, rbx.x); ii = amrex::min(ii, rbx.x + width - 1);
314  int jj = amrex::max(j, rbx.y); jj = amrex::min(jj, rhi.y);
315  r_xlo_arr(i,j,k) = oma*r_xlo_n(ii,jj,k) + alpha*r_xlo_np1(ii,jj,k);
316  },
317  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
318  int ii = amrex::max(i, rhi.x - width + 1); ii = amrex::min(ii, rhi.x);
319  int jj = amrex::max(j, rbx.y); jj = amrex::min(jj, rhi.y);
320  r_xhi_arr(i,j,k) = oma*r_xhi_n(ii,jj,k) + alpha*r_xhi_np1(ii,jj,k);
321  });
322  ParallelFor(bx_ylo, bx_yhi,
323  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
324  int ii = amrex::max(i, rbx.x); ii = amrex::min(ii, rhi.x);
325  int jj = amrex::max(j, rbx.y); jj = amrex::min(jj, rbx.y + width - 1);
326  r_ylo_arr(i,j,k) = oma*r_ylo_n(ii,jj,k) + alpha*r_ylo_np1(ii,jj,k);
327  },
328  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
329  int ii = amrex::max(i, rbx.x); ii = amrex::min(ii, rhi.x);
330  int jj = amrex::max(j, rhi.y - width + 1); jj = amrex::min(jj, rhi.y);
331  r_yhi_arr(i,j,k) = oma*r_yhi_n(ii,jj,k) + alpha*r_yhi_np1(ii,jj,k);
332  });
333  }
334 
335 
336  // NOTE: These operations use the BDY FABS and RHO. The
337  // use of RHO to go from PRIM -> CONS requires that
338  // these operations be LOCAL. So we have allocated
339  // enough space to do global operations (1 rank) but
340  // will fill a subset of that data that the rank owns.
341 
342  // Populate FABs from bdy interpolation (primitive vars)
343  //==========================================================
344  for (int ivar(ivarU); ivar < BdyEnd; ivar++) {
345  int ivar_idx = var_map[ivar];
346  Box domain = geom.Domain();
347  auto ixtype = S_cur_data[ivar_idx].boxArray().ixType();
348  domain.convert(ixtype);
349  const auto& dom_lo = lbound(domain);
350  const auto& dom_hi = ubound(domain);
351 
352  // BndryReg idx and limiting
353  int bdy_comp = bnd_map[ivar];
354  const auto& dom_cc_lo = lbound(geom.Domain());
355  const auto& dom_cc_hi = ubound(geom.Domain());
356 
357 #ifdef _OPENMP
358 #pragma omp parallel if (Gpu::notInLaunchRegion())
359 #endif
360  for (MFIter mfi(S_cur_data[ivar_idx],TilingIfNotGPU()); mfi.isValid(); ++mfi) {
361  // NOTE: Ghost cells needed for idx type mismatch between mask and data (do_upwind)
362  IntVect ng_vect(0);
363  //IntVect ng_vect(1,1,0);
364  Box gtbx = grow(mfi.tilebox(ixtype.toIntVect()),ng_vect);
365  Box tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi;
366  realbdy_interior_bxs_xy(gtbx, domain, width,
367  tbx_xlo, tbx_xhi,
368  tbx_ylo, tbx_yhi,
369  ng_vect, true);
370 
371  Array4<Real> arr_xlo; Array4<Real> arr_xhi;
372  Array4<Real> arr_ylo; Array4<Real> arr_yhi;
373  if (ivar == ivarU) {
374  arr_xlo = U_xlo.array(); arr_xhi = U_xhi.array();
375  arr_ylo = U_ylo.array(); arr_yhi = U_yhi.array();
376  } else if (ivar == ivarV) {
377  arr_xlo = V_xlo.array(); arr_xhi = V_xhi.array();
378  arr_ylo = V_ylo.array(); arr_yhi = V_yhi.array();
379  } else if (ivar == ivarT){
380  arr_xlo = T_xlo.array(); arr_xhi = T_xhi.array();
381  arr_ylo = T_ylo.array(); arr_yhi = T_yhi.array();
382  } else {
383  continue;
384  }
385 
386  // Boundary data at fixed time intervals
387  const auto& bdatxlo_n = bdy_data_xlo[n_time ][ivar].const_array();
388  const auto& bdatxlo_np1 = bdy_data_xlo[n_time_p1][ivar].const_array();
389  const auto& bdatxhi_n = bdy_data_xhi[n_time ][ivar].const_array();
390  const auto& bdatxhi_np1 = bdy_data_xhi[n_time_p1][ivar].const_array();
391  const auto& bdatylo_n = bdy_data_ylo[n_time ][ivar].const_array();
392  const auto& bdatylo_np1 = bdy_data_ylo[n_time_p1][ivar].const_array();
393  const auto& bdatyhi_n = bdy_data_yhi[n_time ][ivar].const_array();
394  const auto& bdatyhi_np1 = bdy_data_yhi[n_time_p1][ivar].const_array();
395 
396  // Current density to convert to conserved vars
397  Array4<Real> r_arr = S_cur_data[IntVars::cons].array(mfi);
398 
399  // Limiting offset
400  int offset = width - 1;
401 
402  // Populate with interpolation (protect from ghost cells)
403  const auto rxlo = r_xlo_arr;
404  const auto rxhi = r_xhi_arr;
405  const auto rylo = r_ylo_arr;
406  const auto ryhi = r_yhi_arr;
407  ParallelFor(tbx_xlo, tbx_xhi,
408  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
409  {
410  int ii = std::max(i , dom_lo.x); ii = std::min(ii, dom_lo.x+offset);
411  int jj = std::max(j , dom_lo.y); jj = std::min(jj, dom_hi.y);
412 
413  Real rho_interp;
414  if (use_wrf_bdy_density && ivar==ivarU) {
415  int im = amrex::max(i-1, dom_lo.x);
416  rho_interp = myhalf * (rxlo(im,j,k) + rxlo(amrex::max(i, dom_lo.x),j,k));
417  } else if (use_wrf_bdy_density && ivar==ivarV) {
418  int jm = amrex::max(j-1, dom_lo.y);
419  rho_interp = myhalf * (rxlo(i,jm,k) + rxlo(i,amrex::max(j, dom_lo.y),k));
420  } else if (use_wrf_bdy_density) {
421  rho_interp = rxlo(i,j,k);
422  } else if (ivar==ivarU) {
423  rho_interp = myhalf * ( r_arr(i-1,j ,k) + r_arr(i,j,k) );
424  } else if (ivar==ivarV) {
425  rho_interp = myhalf * ( r_arr(i ,j-1,k) + r_arr(i,j,k) );
426  } else {
427  rho_interp = r_arr(i,j,k);
428  }
429 
430  if (bdatxlo) {
431  int ii2 = std::min(std::max(i , dom_cc_lo.x), dom_cc_hi.x);
432  int jj2 = std::min(std::max(j , dom_cc_lo.y), dom_cc_hi.y);
433  arr_xlo(i,j,k) = rho_interp * bdatxlo(ii2,jj2,k,bdy_comp);
434  } else {
435  arr_xlo(i,j,k) = rho_interp * ( oma * bdatxlo_n (ii,jj,k,0)
436  + alpha * bdatxlo_np1(ii,jj,k,0) );
437  }
438  },
439  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
440  {
441  int ii = std::max(i , dom_hi.x-offset); ii = std::min(ii, dom_hi.x);
442  int jj = std::max(j , dom_lo.y); jj = std::min(jj, dom_hi.y);
443 
444  Real rho_interp;
445  if (use_wrf_bdy_density && ivar==ivarU) {
446  int im = amrex::max(i-1, dom_lo.x);
447  rho_interp = myhalf * (rxhi(im,j,k) + rxhi(amrex::max(i, dom_lo.x),j,k));
448  } else if (use_wrf_bdy_density && ivar==ivarV) {
449  int jm = amrex::max(j-1, dom_lo.y);
450  rho_interp = myhalf * (rxhi(i,jm,k) + rxhi(i,amrex::max(j, dom_lo.y),k));
451  } else if (use_wrf_bdy_density) {
452  rho_interp = rxhi(i,j,k);
453  } else if (ivar==ivarU) {
454  rho_interp = myhalf * ( r_arr(i-1,j ,k) + r_arr(i,j,k) );
455  } else if (ivar==ivarV) {
456  rho_interp = myhalf * ( r_arr(i ,j-1,k) + r_arr(i,j,k) );
457  } else {
458  rho_interp = r_arr(i,j,k);
459  }
460 
461  if (bdatxhi) {
462  int ii2 = std::min(std::max(i , dom_cc_lo.x), dom_cc_hi.x);
463  int jj2 = std::min(std::max(j , dom_cc_lo.y), dom_cc_hi.y);
464  arr_xhi(i,j,k) = rho_interp * bdatxhi(ii2,jj2,k,bdy_comp);
465  } else {
466  arr_xhi(i,j,k) = rho_interp * ( oma * bdatxhi_n (ii,jj,k,0)
467  + alpha * bdatxhi_np1(ii,jj,k,0) );
468  }
469  });
470 
471  ParallelFor(tbx_ylo, tbx_yhi,
472  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
473  {
474  int ii = std::max(i , dom_lo.x); ii = std::min(ii, dom_hi.x);
475  int jj = std::max(j , dom_lo.y); jj = std::min(jj, dom_lo.y+offset);
476 
477  Real rho_interp;
478  if (use_wrf_bdy_density && ivar==ivarU) {
479  int im = amrex::max(i-1, dom_lo.x);
480  rho_interp = myhalf * (rylo(im,j,k) + rylo(amrex::max(i, dom_lo.x),j,k));
481  } else if (use_wrf_bdy_density && ivar==ivarV) {
482  int jm = amrex::max(j-1, dom_lo.y);
483  rho_interp = myhalf * (rylo(i,jm,k) + rylo(i,amrex::max(j, dom_lo.y),k));
484  } else if (use_wrf_bdy_density) {
485  rho_interp = rylo(i,j,k);
486  } else if (ivar==ivarU) {
487  rho_interp = myhalf * ( r_arr(i-1,j ,k) + r_arr(i,j,k) );
488  } else if (ivar==ivarV) {
489  rho_interp = myhalf * ( r_arr(i ,j-1,k) + r_arr(i,j,k) );
490  } else {
491  rho_interp = r_arr(i,j,k);
492  }
493 
494  if (bdatylo) {
495  int ii2 = std::min(std::max(i , dom_cc_lo.x), dom_cc_hi.x);
496  int jj2 = std::min(std::max(j , dom_cc_lo.y), dom_cc_hi.y);
497  arr_ylo(i,j,k) = rho_interp * bdatylo(ii2,jj2,k,bdy_comp);
498  } else {
499  arr_ylo(i,j,k) = rho_interp * ( oma * bdatylo_n (ii,jj,k,0)
500  + alpha * bdatylo_np1(ii,jj,k,0) );
501  }
502  },
503  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
504  {
505  int ii = std::max(i , dom_lo.x); ii = std::min(ii, dom_hi.x);
506  int jj = std::max(j , dom_hi.y-offset); jj = std::min(jj, dom_hi.y);
507 
508  Real rho_interp;
509  if (use_wrf_bdy_density && ivar==ivarU) {
510  int im = amrex::max(i-1, dom_lo.x);
511  rho_interp = myhalf * (ryhi(im,j,k) + ryhi(amrex::max(i, dom_lo.x),j,k));
512  } else if (use_wrf_bdy_density && ivar==ivarV) {
513  int jm = amrex::max(j-1, dom_lo.y);
514  rho_interp = myhalf * (ryhi(i,jm,k) + ryhi(i,amrex::max(j, dom_lo.y),k));
515  } else if (use_wrf_bdy_density) {
516  rho_interp = ryhi(i,j,k);
517  } else if (ivar==ivarU) {
518  rho_interp = myhalf * ( r_arr(i-1,j ,k) + r_arr(i,j,k) );
519  } else if (ivar==ivarV) {
520  rho_interp = myhalf * ( r_arr(i ,j-1,k) + r_arr(i,j,k) );
521  } else {
522  rho_interp = r_arr(i,j,k);
523  }
524 
525  if (bdatyhi) {
526  int ii2 = std::min(std::max(i , dom_cc_lo.x), dom_cc_hi.x);
527  int jj2 = std::min(std::max(j , dom_cc_lo.y), dom_cc_hi.y);
528  arr_yhi(i,j,k) = rho_interp * bdatyhi(ii2,jj2,k,bdy_comp);
529  } else {
530  arr_yhi(i,j,k) = rho_interp * ( oma * bdatyhi_n (ii,jj,k,0)
531  + alpha * bdatyhi_np1(ii,jj,k,0) );
532  }
533  });
534  } // mfi
535  } // ivar
536 
537 
538  // Compute RHS in relaxation region
539  //==========================================================
540  auto dx = geom.CellSizeArray();
541  auto ProbLo = geom.ProbLoArray();
542  auto ProbHi = geom.ProbHiArray();
543 
544  for (int ivar(ivarU); ivar < BdyEnd; ivar++) {
545  int ivar_idx = ivar_map[ivar];
546  int icomp = comp_map[ivar];
547 
548  Box domain = geom.Domain();
549  domain.convert(S_cur_data[ivar_idx].boxArray().ixType());
550  IntVect ng_vect(0);
551 
552 #ifdef _OPENMP
553 #pragma omp parallel if (Gpu::notInLaunchRegion())
554 #endif
555  for (MFIter mfi(S_cur_data[ivar_idx],TilingIfNotGPU()); mfi.isValid(); ++mfi)
556  {
557  Box tbx = mfi.tilebox();
558  Box tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi;
559  realbdy_interior_bxs_xy(tbx, domain, width,
560  tbx_xlo, tbx_xhi,
561  tbx_ylo, tbx_yhi,
562  ng_vect);
563 
564  Array4<Real> rhs_arr; Array4<Real> data_arr;
565  Array4<Real> arr_xlo; Array4<Real> arr_xhi;
566  Array4<Real> arr_ylo; Array4<Real> arr_yhi;
567  if (ivar == ivarU) {
568  arr_xlo = U_xlo.array(); arr_xhi = U_xhi.array();
569  arr_ylo = U_ylo.array(); arr_yhi = U_yhi.array();
570  rhs_arr = S_rhs[IntVars::xmom].array(mfi);
571  data_arr = S_cur_data[IntVars::xmom].array(mfi);
572  } else if (ivar == ivarV) {
573  arr_xlo = V_xlo.array(); arr_xhi = V_xhi.array();
574  arr_ylo = V_ylo.array(); arr_yhi = V_yhi.array();
575  rhs_arr = S_rhs[IntVars::ymom].array(mfi);
576  data_arr = S_cur_data[IntVars::ymom].array(mfi);
577  } else if (ivar == ivarT){
578  arr_xlo = T_xlo.array(); arr_xhi = T_xhi.array();
579  arr_ylo = T_ylo.array(); arr_yhi = T_yhi.array();
580  rhs_arr = S_rhs[IntVars::cons].array(mfi);
581  data_arr = S_cur_data[IntVars::cons].array(mfi);
582  } else {
583  continue;
584  }
585 
587  width, dx, ProbLo, ProbHi, F1,
588  tbx_xlo , tbx_xhi , tbx_ylo , tbx_yhi ,
589  arr_xlo , arr_xhi , arr_ylo , arr_yhi ,
590  data_arr, rhs_arr , c_p, rdOcp);
591  } // mfi
592  } // ivar
593 
594  if (use_wrf_bdy_density) {
595  for (MFIter mfi(S_cur_data[IntVars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
596  Box domain = geom.Domain();
597  Box tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi;
598  realbdy_interior_bxs_xy(mfi.tilebox(), domain, width,
599  tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi);
600  realbdy_compute_relaxation(Rho_comp, 1, width, dx, ProbLo, ProbHi, F1_rho,
601  tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi,
602  r_xlo_arr, r_xhi_arr, r_ylo_arr, r_yhi_arr,
603  S_cur_data[IntVars::cons].const_array(mfi),
604  S_rhs[IntVars::cons].array(mfi), c_p, rdOcp);
605  }
606  }
607 
608  // Set normal velocity RHS at the boundary
609  //==========================================================
610  Box domain = geom.Domain();
611  Box domainx = convert(domain, IntVect(1,0,0));
612  Box domainy = convert(domain, IntVect(0,1,0));
613 
614  int ilo = domainx.smallEnd(0);
615  int ihi = domainx.bigEnd(0);
616  int jlo = domainy.smallEnd(1);
617  int jhi = domainy.bigEnd(1);
618 
619 #ifdef _OPENMP
620 #pragma omp parallel if (Gpu::notInLaunchRegion())
621 #endif
622  for (MFIter mfi(S_cur_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
623  {
624  Box tbx = mfi.nodaltilebox(0);
625  Box tbx_lo, tbx_hi;
626  if (tbx.smallEnd(0) == ilo) {
627  tbx_lo = makeSlab(tbx,0,ilo);
628  }
629  if (tbx.bigEnd(0) == ihi) {
630  tbx_hi = makeSlab(tbx,0,ihi);
631  }
632 
633  Box tby = mfi.nodaltilebox(1);
634  Box tby_lo, tby_hi;
635  if (tby.smallEnd(1) == jlo) {
636  tby_lo = makeSlab(tby,1,jlo);
637  }
638  if (tby.bigEnd(1) == jhi) {
639  tby_hi = makeSlab(tby,1,jhi);
640  }
641 
642  Array4<Real> rhs_xmom = S_rhs[IntVars::xmom].array(mfi);
643  Array4<Real> rhs_ymom = S_rhs[IntVars::ymom].array(mfi);
644 
645  Array4<const Real> rhs_cons = S_rhs[IntVars::cons].const_array(mfi);
646  Array4<const Real> cons_arr = S_cur_data[IntVars::cons].const_array(mfi);
647 
648  const auto& bdatxlo_n = bdy_data_xlo[n_time ][ivarU].const_array();
649  const auto& bdatxlo_np1 = bdy_data_xlo[n_time_p1][ivarU].const_array();
650  const auto& bdatxhi_n = bdy_data_xhi[n_time ][ivarU].const_array();
651  const auto& bdatxhi_np1 = bdy_data_xhi[n_time_p1][ivarU].const_array();
652 
653  const auto& bdatylo_n = bdy_data_ylo[n_time ][ivarV].const_array();
654  const auto& bdatylo_np1 = bdy_data_ylo[n_time_p1][ivarV].const_array();
655  const auto& bdatyhi_n = bdy_data_yhi[n_time ][ivarV].const_array();
656  const auto& bdatyhi_np1 = bdy_data_yhi[n_time_p1][ivarV].const_array();
657 
658  Real dT = static_cast<Real>(bdy_time_interval);
659 
660  ParallelFor(tbx_lo, tbx_hi,
661  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
662  {
663  Real rho_tend = rhs_cons(i,j,k);
664  Real rho_val = Real(0.5) * (cons_arr(i,j,k) + cons_arr(i-1,j,k));
665  Real u_tend, u_val;
666  if (btenxlo) {
667  u_tend = btenxlo(i,j,k,BCVars::xvel_bc);
668  u_val = bdatxlo(i,j,k,BCVars::xvel_bc);
669  } else {
670  u_tend = (bdatxlo_np1(i,j,k) - bdatxlo_n(i,j,k)) / dT;
671  u_val = oma * bdatxlo_n(i,j,k) + alpha * bdatxlo_np1(i,j,k);
672  }
673  rhs_xmom(i,j,k) = rho_val * u_tend + u_val * rho_tend;
674  },
675  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
676  {
677  // NOTE: (i,j,k) is the hi face of the domain, so the cell (i,j,k) is
678  // an exterior ghost cell for which the cons RHS is never filled;
679  // use the adjacent interior cell, mirroring the lo side.
680  Real rho_tend = rhs_cons(i-1,j,k);
681  Real rho_val = Real(0.5) * (cons_arr(i,j,k) + cons_arr(i-1,j,k));
682  Real u_tend, u_val;
683  if (btenxhi) {
684  u_tend = btenxhi(i,j,k,BCVars::xvel_bc);
685  u_val = bdatxhi(i,j,k,BCVars::xvel_bc);
686  } else {
687  u_tend = (bdatxhi_np1(i,j,k) - bdatxhi_n(i,j,k)) / dT;
688  u_val = oma * bdatxhi_n(i,j,k) + alpha * bdatxhi_np1(i,j,k);
689  }
690  rhs_xmom(i,j,k) = rho_val * u_tend + u_val * rho_tend;
691  });
692 
693  ParallelFor(tby_lo, tby_hi,
694  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
695  {
696  Real rho_tend = rhs_cons(i,j,k);
697  Real rho_val = Real(0.5) * (cons_arr(i,j,k) + cons_arr(i,j-1,k));
698  Real v_tend, v_val;
699  if (btenylo) {
700  v_tend = btenylo(i,j,k,BCVars::yvel_bc);
701  v_val = bdatylo(i,j,k,BCVars::yvel_bc);
702  } else {
703  v_tend = (bdatylo_np1(i,j,k) - bdatylo_n(i,j,k)) / dT;
704  v_val = oma * bdatylo_n(i,j,k) + alpha * bdatylo_np1(i,j,k);
705  }
706  rhs_ymom(i,j,k) = rho_val * v_tend + v_val * rho_tend;
707  },
708  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
709  {
710  // NOTE: (i,j,k) is the hi face of the domain, so the cell (i,j,k) is
711  // an exterior ghost cell for which the cons RHS is never filled;
712  // use the adjacent interior cell, mirroring the lo side.
713  Real rho_tend = rhs_cons(i,j-1,k);
714  Real rho_val = Real(0.5) * (cons_arr(i,j,k) + cons_arr(i,j-1,k));
715  Real v_tend, v_val;
716  if (btenyhi) {
717  v_tend = btenyhi(i,j,k,BCVars::yvel_bc);
718  v_val = bdatyhi(i,j,k,BCVars::yvel_bc);
719  } else {
720  v_tend = (bdatyhi_np1(i,j,k) - bdatyhi_n(i,j,k)) / dT;
721  v_val = oma * bdatyhi_n(i,j,k) + alpha * bdatyhi_np1(i,j,k);
722  }
723  rhs_ymom(i,j,k) = rho_val * v_tend + v_val * rho_tend;
724  });
725  } // mfi
726 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:128
void realbdy_interior_bxs_xy(const Box &bx, const Box &domain, const int &width, Box &bx_xlo, Box &bx_xhi, Box &bx_ylo, Box &bx_yhi, const IntVect &ng_vect, const bool get_int_ng)
Definition: ERF_InteriorGhostCells.cpp:23
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:36
AMREX_FORCE_INLINE BdyTimeWeights bdy_time_weights(const double time_since_start, const double data_span, const double dT)
Definition: ERF_Utils.H:428
AMREX_GPU_HOST AMREX_FORCE_INLINE void realbdy_compute_relaxation(const int &icomp, const int &num_var, const int &width, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dx, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &ProbLo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &ProbHi, const amrex::Real &F1, const amrex::Box &bx_xlo, const amrex::Box &bx_xhi, const amrex::Box &bx_ylo, const amrex::Box &bx_yhi, const amrex::Array4< const amrex::Real > &arr_xlo, const amrex::Array4< const amrex::Real > &arr_xhi, const amrex::Array4< const amrex::Real > &arr_ylo, const amrex::Array4< const amrex::Real > &arr_yhi, const amrex::Array4< const amrex::Real > &data_arr, const amrex::Array4< amrex::Real > &rhs_arr, const amrex::Real &c_p, const amrex::Real &rdOcp, const int bdy_moist_nudge_type=0)
Definition: ERF_Utils.H:540
@ RhoTheta_bc_comp
Definition: ERF_IndexDefines.H:124
@ yvel_bc
Definition: ERF_IndexDefines.H:139
@ xvel_bc
Definition: ERF_IndexDefines.H:138
@ U
Definition: ERF_IndexDefines.H:178
@ T
Definition: ERF_IndexDefines.H:180
@ V
Definition: ERF_IndexDefines.H:179
@ alpha
Definition: ERF_SLM.H:153
@ xvel
Definition: ERF_IndexDefines.H:232
@ cons
Definition: ERF_IndexDefines.H:231
@ yvel
Definition: ERF_IndexDefines.H:233
@ R
Definition: ERF_IndexDefines.H:193
@ rhi
Definition: ERF_WSM6.H:362
Definition: ERF_Utils.H:407
int n_hi
Definition: ERF_Utils.H:409
amrex::Real alpha
Definition: ERF_Utils.H:410
int n_lo
Definition: ERF_Utils.H:408
Here is the call graph for this function:

◆ realbdy_interior_bxs_xy()

void realbdy_interior_bxs_xy ( const Box &  bx,
const Box &  domain,
const int &  width,
Box &  bx_xlo,
Box &  bx_xhi,
Box &  bx_ylo,
Box &  bx_yhi,
const IntVect &  ng_vect,
const bool  get_int_ng 
)

Get the boxes for looping over interior/exterior ghost cells for use by fillpatch, erf_slow_rhs_pre, and erf_slow_rhs_post.

Parameters
[in]bxbox to intersect with 4 halo regions
[in]domainbox of the whole domain
[in]widthnumber of cells in (relaxation+specified) zone
[in]set_widthnumber of cells in (specified) zone
[out]bx_xlohalo box at x_lo boundary
[out]bx_xhihalo box at x_hi boundary
[out]bx_ylohalo box at y_lo boundary
[out]bx_yhihalo box at y_hi boundary
[in]ng_vectnumber of ghost cells in each direction
[in]get_int_ngflag to get ghost cells inside the domain
32 {
33  AMREX_ALWAYS_ASSERT(bx.ixType() == domain.ixType());
34 
35  //==================================================================
36  // NOTE: X-face boxes take ownership of the overlapping region.
37  // With exterior ghost cells (ng_vect != 0), the x-face
38  // boxes will have exterior ghost cells in both x & y.
39  //==================================================================
40 
41  // Domain bounds without ghost cells
42  const auto& dom_lo = lbound(domain);
43  const auto& dom_hi = ubound(domain);
44 
45  // Four boxes matching the domain
46  Box gdom_xlo(domain); Box gdom_xhi(domain);
47  Box gdom_ylo(domain); Box gdom_yhi(domain);
48 
49  // Trim the boxes to only include internal ghost cells
50  gdom_xlo.setBig(0,dom_lo.x+width-1); gdom_xhi.setSmall(0,dom_hi.x-width+1);
51  gdom_ylo.setBig(1,dom_lo.y+width-1); gdom_yhi.setSmall(1,dom_hi.y-width+1);
52 
53  // Remove overlapping corners from y-face boxes
54  gdom_ylo.setSmall(0,gdom_xlo.bigEnd(0)+1); gdom_ylo.setBig(0,gdom_xhi.smallEnd(0)-1);
55  gdom_yhi.setSmall(0,gdom_xlo.bigEnd(0)+1); gdom_yhi.setBig(0,gdom_xhi.smallEnd(0)-1);
56 
57  // Grow boxes to get external ghost cells only
58  gdom_xlo.growLo(0,ng_vect[0]); gdom_xhi.growHi(0,ng_vect[0]);
59  gdom_xlo.grow (1,ng_vect[1]); gdom_xhi.grow (1,ng_vect[1]);
60  gdom_ylo.growLo(1,ng_vect[1]); gdom_yhi.growHi(1,ng_vect[1]);
61 
62  // Grow boxes to get internal ghost cells
63  if (get_int_ng) {
64  gdom_xlo.growHi(0,ng_vect[0]); gdom_xhi.growLo(0,ng_vect[0]);
65  gdom_ylo.grow (0,ng_vect[0]); gdom_yhi.grow (0,ng_vect[0]);
66  gdom_ylo.growHi(1,ng_vect[1]); gdom_yhi.growLo(1,ng_vect[1]);
67  }
68 
69  // Populate everything
70  bx_xlo = (bx & gdom_xlo);
71  bx_xhi = (bx & gdom_xhi);
72  bx_ylo = (bx & gdom_ylo);
73  bx_yhi = (bx & gdom_yhi);
74 }

Referenced by realbdy_compute_interior_ghost_rhs().

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

Variable Documentation

◆ void_bc

PhysBCFunctNoOp void_bc