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 &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
758 {
759  BL_PROFILE_REGION("fine_compute_interior_ghost_RHS()");
760 
761  Real delta_t = static_cast<Real>(delta_t_d);
762 
763  // Relaxation constants
764  Real F1 = one/(Real(10.)*delta_t);
765  Real F2 = one/(Real(50.)*delta_t);
766 
767  // Vector of MFs to hold data (dm differs w/ fine patch)
768  Vector<MultiFab> fmf_p_v;
769 
770  // Loop over the variables
771  for (int ivar_idx = 0; ivar_idx < IntVars::NumTypes; ++ivar_idx)
772  {
773  // Fine mfs
774  MultiFab& fmf = S_data_f[ivar_idx];
775  MultiFab& rhs = S_rhs_f [ivar_idx];
776 
777  // NOTE: These temporary MFs and copy operations are horrible
778  // for memory usage and efficiency. However, we need to
779  // have access to ghost cells in the cons array to convert
780  // from primitive u/v/w to momentum. Furthermore, the BA
781  // for the fine patches in ERFFillPatcher don't match the
782  // BA for the data/RHS. For this reason, the data is copied
783  // to a vector of MFs (with ghost cells) so the BAs match
784  // the BA of data/RHS and we have access to rho to convert
785  // prim to conserved.
786 
787  // Temp MF on box (distribution map differs w/ fine patch)
788  int num_var = fmf.nComp();
789  fmf_p_v.emplace_back(fmf.boxArray(), fmf.DistributionMap(), num_var, fmf.nGrowVect());
790  MultiFab& fmf_p = fmf_p_v[ivar_idx];
791  MultiFab::Copy(fmf_p,fmf, 0, 0, num_var, fmf.nGrowVect());
792 
793  // Integer mask MF
794  int set_mask_val;
795  int relax_mask_val;
796  iMultiFab* mask;
797 
798  // Fill fine patch on interior halo region
799  //==========================================================
800  if (ivar_idx == IntVars::cons)
801  {
802  FPr_c->FillRelax(fmf_p, time, void_bc, domain_bcs_type);
803  mask = FPr_c->GetMask();
804  set_mask_val = FPr_c->GetSetMaskVal();
805  relax_mask_val = FPr_c->GetRelaxMaskVal();
806  }
807  else if (ivar_idx == IntVars::xmom)
808  {
809  FPr_u->FillRelax(fmf_p, time, void_bc, domain_bcs_type);
810  mask = FPr_u->GetMask();
811  set_mask_val = FPr_u->GetSetMaskVal();
812  relax_mask_val = FPr_u->GetRelaxMaskVal();
813 
814 #ifdef _OPENMP
815 #pragma omp parallel if (Gpu::notInLaunchRegion())
816 #endif
817  for ( MFIter mfi(fmf_p,TilingIfNotGPU()); mfi.isValid(); ++mfi)
818  {
819  Box tbx = mfi.tilebox();
820 
821  const Array4<Real>& prim_arr = fmf_p.array(mfi);
822  const Array4<const Real>& rho_arr = fmf_p_v[0].const_array(mfi);
823  const Array4<const int>& mask_arr = mask->const_array(mfi);
824 
825  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
826  {
827  if (mask_arr(i,j,k) == relax_mask_val) {
828  Real rho_interp = myhalf * ( rho_arr(i-1,j,k) + rho_arr(i,j,k) );
829  prim_arr(i,j,k) *= rho_interp;
830  }
831  });
832  } // mfi
833  }
834  else if (ivar_idx == IntVars::ymom)
835  {
836  FPr_v->FillRelax(fmf_p, time, void_bc, domain_bcs_type);
837  mask = FPr_v->GetMask();
838  set_mask_val = FPr_v->GetSetMaskVal();
839  relax_mask_val = FPr_v->GetRelaxMaskVal();
840 
841 #ifdef _OPENMP
842 #pragma omp parallel if (Gpu::notInLaunchRegion())
843 #endif
844  for ( MFIter mfi(fmf_p,TilingIfNotGPU()); mfi.isValid(); ++mfi)
845  {
846  Box tbx = mfi.tilebox();
847 
848  const Array4<Real>& prim_arr = fmf_p.array(mfi);
849  const Array4<const Real>& rho_arr = fmf_p_v[0].const_array(mfi);
850  const Array4<const int>& mask_arr = mask->const_array(mfi);
851 
852  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
853  {
854  if (mask_arr(i,j,k) == relax_mask_val) {
855  Real rho_interp = myhalf * ( rho_arr(i,j-1,k) + rho_arr(i,j,k) );
856  prim_arr(i,j,k) *= rho_interp;
857  }
858  });
859  } // mfi
860  }
861  else if (ivar_idx == IntVars::zmom)
862  {
863  FPr_w->FillRelax(fmf_p, time, void_bc, domain_bcs_type);
864  mask = FPr_w->GetMask();
865  set_mask_val = FPr_w->GetSetMaskVal();
866  relax_mask_val = FPr_w->GetRelaxMaskVal();
867 
868 #ifdef _OPENMP
869 #pragma omp parallel if (Gpu::notInLaunchRegion())
870 #endif
871  for ( MFIter mfi(fmf_p,TilingIfNotGPU()); mfi.isValid(); ++mfi)
872  {
873  Box tbx = mfi.tilebox();
874 
875  const Array4<Real>& prim_arr = fmf_p.array(mfi);
876  const Array4<const Real>& rho_arr = fmf_p_v[0].const_array(mfi);
877  const Array4<const int>& mask_arr = mask->const_array(mfi);
878 
879  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
880  {
881  if (mask_arr(i,j,k) == relax_mask_val) {
882  Real rho_interp = myhalf * ( rho_arr(i,j,k-1) + rho_arr(i,j,k) );
883  prim_arr(i,j,k) *= rho_interp;
884  }
885  });
886  } // mfi
887  } else {
888  Abort("Dont recognize this variable type in fine_compute_interior_ghost_RHS");
889  }
890 
891 
892  // Zero RHS in set region
893  //==========================================================
894 #ifdef _OPENMP
895 #pragma omp parallel if (Gpu::notInLaunchRegion())
896 #endif
897  for ( MFIter mfi(rhs,TilingIfNotGPU()); mfi.isValid(); ++mfi)
898  {
899  Box tbx = mfi.tilebox();
900  const Array4<Real>& rhs_arr = rhs.array(mfi);
901  const Array4<const int>& mask_arr = mask->const_array(mfi);
902 
903  ParallelFor(tbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
904  {
905  if (mask_arr(i,j,k) == set_mask_val) {
906  rhs_arr(i,j,k) = zero;
907  }
908  });
909  } // mfi
910 
911  // For Laplacian stencil
912  rhs.FillBoundary(geom.periodicity());
913 
914 
915  // Compute RHS in relaxation region
916  //==========================================================
917 #ifdef _OPENMP
918 #pragma omp parallel if (Gpu::notInLaunchRegion())
919 #endif
920  for ( MFIter mfi(fmf_p,TilingIfNotGPU()); mfi.isValid(); ++mfi)
921  {
922  Box tbx = mfi.tilebox();
923  const Array4<Real>& rhs_arr = rhs.array(mfi);
924  const Array4<const Real>& fine_arr = fmf_p.const_array(mfi);
925  const Array4<const Real>& data_arr = fmf.const_array(mfi);
926  const Array4<const int>& mask_arr = mask->const_array(mfi);
927 
928  Box vbx = mfi.validbox();
929  const auto& vbx_lo = lbound(vbx);
930  const auto& vbx_hi = ubound(vbx);
931 
932  int icomp = 0;
933 
934  int Spec_z = set_width;
935  int Relax_z = width - Spec_z;
936  Real num = Real(Spec_z + Relax_z);
937  Real denom = Real(Relax_z - 1);
938  ParallelFor(tbx, num_var, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
939  {
940  if (mask_arr(i,j,k) == relax_mask_val) {
941 
942  // Indices
943  Real n_ind(-1); // Set to -1 to quiet compiler warning
944  int ii(width-1); int jj(width-1);
945  bool near_x_lo_wall(false); bool near_x_hi_wall(false);
946  bool near_y_lo_wall(false); bool near_y_hi_wall(false);
947  bool mask_x_found(false); bool mask_y_found(false);
948 
949  // Near x-wall
950  if ((i-vbx_lo.x) < width) {
951  near_x_lo_wall = true;
952  ii = i-vbx_lo.x;
953  if (mask_arr(vbx_lo.x,j,k) == 2) mask_x_found = true;
954  } else if ((vbx_hi.x-i) < width) {
955  near_x_hi_wall = true;
956  ii = vbx_hi.x-i;
957  if (mask_arr(vbx_hi.x,j,k) == 2) mask_x_found = true;
958  }
959 
960  // Near y-wall
961  if ((j-vbx_lo.y) < width) {
962  near_y_lo_wall = true;
963  jj = j-vbx_lo.y;
964  if (mask_arr(i,vbx_lo.y,k) == 2) mask_y_found = true;
965  } else if ((vbx_hi.y-j) < width) {
966  near_y_hi_wall = true;
967  jj = vbx_hi.y-j;
968  if (mask_arr(i,vbx_hi.y,k) == 2) mask_y_found = true;
969  }
970 
971  // Found a nearby masked cell (valid n_ind)
972  if (mask_x_found && mask_y_found) {
973  n_ind = std::min(ii,jj) + one;
974  } else if (mask_x_found) {
975  n_ind = ii + one;
976  } else if (mask_y_found) {
977  n_ind = jj + one;
978  // Pesky corner cell
979  } else {
980  if (near_x_lo_wall || near_x_hi_wall) {
981  Real dj_min{width-one};
982  int j_lb = std::max(vbx_lo.y,j-width);
983  int j_ub = std::min(vbx_hi.y,j+width);
984  int li = (near_x_lo_wall) ? vbx_lo.x : vbx_hi.x;
985  for (int lj(j_lb); lj<=j_ub; ++lj) {
986  if (mask_arr(li,lj,k) == 2) {
987  mask_y_found = true;
988  dj_min = std::min(dj_min,(Real) std::abs(lj-j));
989  }
990  }
991  if (mask_y_found) {
992  Real mag = std::sqrt( Real(dj_min*dj_min + ii*ii) );
993  n_ind = std::min(mag,width-one) + one;
994  } else {
995  Abort("Mask not found near x wall!");
996  }
997  } else if (near_y_lo_wall || near_y_hi_wall) {
998  Real di_min{width-one};
999  int i_lb = std::max(vbx_lo.x,i-width);
1000  int i_ub = std::min(vbx_hi.x,i+width);
1001  int lj = (near_y_lo_wall) ? vbx_lo.y : vbx_hi.y;
1002  for (int li(i_lb); li<=i_ub; ++li) {
1003  if (mask_arr(li,lj,k) == 2) {
1004  mask_x_found = true;
1005  di_min = std::min(di_min,(Real) std::abs(li-i));
1006  }
1007  }
1008  if (mask_x_found) {
1009  Real mag = std::sqrt( Real(di_min*di_min + jj*jj) );
1010  n_ind = std::min(mag,width-one) + one;
1011  } else {
1012  Abort("Mask not found near y wall!");
1013  }
1014  } else {
1015  Abort("Relaxation cell must be near a wall!");
1016  }
1017  }
1018 
1019  Real Factor = (num - n_ind)/denom;
1020  Real d = data_arr(i ,j ,k ,n+icomp) + delta_t*rhs_arr(i , j , k ,n+icomp);
1021  Real d_ip1 = data_arr(i+1,j ,k ,n+icomp) + delta_t*rhs_arr(i+1, j , k ,n+icomp);
1022  Real d_im1 = data_arr(i-1,j ,k ,n+icomp) + delta_t*rhs_arr(i-1, j , k ,n+icomp);
1023  Real d_jp1 = data_arr(i ,j+1,k ,n+icomp) + delta_t*rhs_arr(i , j+1, k ,n+icomp);
1024  Real d_jm1 = data_arr(i ,j-1,k ,n+icomp) + delta_t*rhs_arr(i , j-1, k ,n+icomp);
1025  Real delta = fine_arr(i ,j ,k,n) - d;
1026  Real delta_xp = fine_arr(i+1,j ,k,n) - d_ip1;
1027  Real delta_xm = fine_arr(i-1,j ,k,n) - d_im1;
1028  Real delta_yp = fine_arr(i ,j+1,k,n) - d_jp1;
1029  Real delta_ym = fine_arr(i ,j-1,k,n) - d_jm1;
1030  Real Laplacian = delta_xp + delta_xm + delta_yp + delta_ym - Real(4.0)*delta;
1031  rhs_arr(i,j,k,n) += (F1*delta - F2*Laplacian) * Factor;
1032  }
1033  });
1034  } // mfi
1035  } // ivar_idx
1036 }
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
@ num
Definition: ERF_DataStruct.H:27
for(int i=0;i< m_num_species;i++)
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:48
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);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
auto rho_arr
Definition: ERF_UpdateWSubsidence_SineMassFlux.H:3
amrex::iMultiFab * GetMask()
Definition: ERF_FillPatcher.H:108
void FillRelax(amrex::MultiFab &mf, double time, BC &cbc, amrex::Vector< amrex::BCRec > const &bcs)
Definition: ERF_FillPatcher.H:195
int GetSetMaskVal()
Definition: ERF_FillPatcher.H:98
int GetRelaxMaskVal()
Definition: ERF_FillPatcher.H:103
@ NumTypes
Definition: ERF_IndexDefines.H:198
@ ymom
Definition: ERF_IndexDefines.H:196
@ cons
Definition: ERF_IndexDefines.H:194
@ zmom
Definition: ERF_IndexDefines.H:197
@ xmom
Definition: ERF_IndexDefines.H:195
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 &  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]timecurrent (total) time
[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
180 {
181  BL_PROFILE_REGION("realbdy_compute_interior_ghost_RHS()");
182 
183  Real delta_t = static_cast<Real>(delta_t_d);
184 
185  //
186  // Note that time (= start_time+old_stage_time) is measured as total time
187  // start_bdy_time and final_bdy_time are also measured as total time
188  //
189 
190  // Get bndry data if we have it
191  Vector<int> bnd_map = {BCVars::xvel_bc, BCVars::yvel_bc, BCVars::RhoTheta_bc_comp};
192  Array4<Real> bdatxlo, bdatxhi, bdatylo, bdatyhi;
193  Array4<Real> btenxlo, btenxhi, btenylo, btenyhi;
194  if (m_r2d) {
195  // Index is [plane orientation] and [level]
196  Vector<std::unique_ptr<PlaneVector>>& bndry_data = m_r2d->interp_in_time(time);
197  bdatxlo = (*bndry_data[0])[0].array();
198  bdatylo = (*bndry_data[1])[0].array();
199  bdatxhi = (*bndry_data[3])[0].array();
200  bdatyhi = (*bndry_data[4])[0].array();
201 
202  Vector<std::unique_ptr<PlaneVector>>& bndry_tend = m_r2d->get_tendency(time);
203  btenxlo = (*bndry_tend[0])[0].array();
204  btenylo = (*bndry_tend[1])[0].array();
205  btenxhi = (*bndry_tend[3])[0].array();
206  btenyhi = (*bndry_tend[4])[0].array();
207  }
208 
209  // Relaxation constants
210  Real F1 = one/(nudge_factor*delta_t);
211  Real F1_rho = one/((bdy_rho_nudge_factor > zero ? bdy_rho_nudge_factor : nudge_factor) * delta_t);
212 
213  // Time interpolation
214  double dT_d = bdy_time_interval;
215 
216  int n_time = static_cast<int>( (time-start_bdy_time) / dT_d);
217  int n_time_p1 = n_time + 1;
218  Real alpha = static_cast<Real>(((time-start_bdy_time) - n_time * dT_d) / dT_d);
219 
220  // Do not over run the last bdy file
221  if (time >= final_bdy_time) {
222  n_time = static_cast<int>( (final_bdy_time - start_bdy_time)/ dT_d);
223  n_time_p1 = n_time;
224  alpha = zero;
225  }
226 
228  Real oma = one - alpha;
229 
230  // Temporary FABs for storage (owned/filled on all ranks)
231  FArrayBox U_xlo, U_xhi, U_ylo, U_yhi;
232  FArrayBox V_xlo, V_xhi, V_ylo, V_yhi;
233  FArrayBox T_xlo, T_xhi, T_ylo, T_yhi;
234  FArrayBox R_xlo, R_xhi, R_ylo, R_yhi;
235  Array4<Real> r_xlo_arr, r_xhi_arr, r_ylo_arr, r_yhi_arr;
236 
237  // Variable index map (WRFBdyVars -> Vars)
238  Vector<int> var_map = {Vars::xvel, Vars::yvel, Vars::cons };
239  Vector<int> ivar_map = {IntVars::xmom, IntVars::ymom, IntVars::cons};
240 
241  // Variable icomp map
242  Vector<int> comp_map = {0, 0, RhoTheta_comp};
243 
244  // Indices
245  int ivarU = RealBdyVars::U;
246  int ivarV = RealBdyVars::V;
247  int ivarT = RealBdyVars::T;
248  int BdyEnd = RealBdyVars::NumTypes-2; // No loop over rho
249 
250  // NOTE: The sizing of the temporary BDY FABS is
251  // GLOBAL and occurs over the entire BDY region.
252 
253  // Size the FABs
254  //==========================================================
255  for (int ivar(ivarU); ivar < BdyEnd; ivar++) {
256  int ivar_idx = var_map[ivar];
257  Box domain = geom.Domain();
258  auto ixtype = S_cur_data[ivar_idx].boxArray().ixType();
259  domain.convert(ixtype);
260 
261  // NOTE: Ghost cells needed for idx type mismatch between mask and data (do_upwind)
262  IntVect ng_vect(0);
263  //IntVect ng_vect(1,1,0);
264  Box gdom(domain); gdom.grow(ng_vect);
265  Box bx_xlo, bx_xhi, bx_ylo, bx_yhi;
266  realbdy_interior_bxs_xy(gdom, domain, width,
267  bx_xlo, bx_xhi,
268  bx_ylo, bx_yhi,
269  ng_vect, true);
270 
271  // Size the FABs
272  if (ivar == ivarU) {
273  U_xlo.resize(bx_xlo,1,The_Async_Arena()); U_xhi.resize(bx_xhi,1,The_Async_Arena());
274  U_ylo.resize(bx_ylo,1,The_Async_Arena()); U_yhi.resize(bx_yhi,1,The_Async_Arena());
275  } else if (ivar == ivarV) {
276  V_xlo.resize(bx_xlo,1,The_Async_Arena()); V_xhi.resize(bx_xhi,1,The_Async_Arena());
277  V_ylo.resize(bx_ylo,1,The_Async_Arena()); V_yhi.resize(bx_yhi,1,The_Async_Arena());
278  } else if (ivar == ivarT){
279  T_xlo.resize(bx_xlo,1,The_Async_Arena()); T_xhi.resize(bx_xhi,1,The_Async_Arena());
280  T_ylo.resize(bx_ylo,1,The_Async_Arena()); T_yhi.resize(bx_yhi,1,The_Async_Arena());
281  } else {
282  continue;
283  }
284  } // ivar
285 
286  if (use_wrf_bdy_density) {
287  Box domain = geom.Domain();
288  const IntVect ng_vect(0);
289  Box bx_xlo, bx_xhi, bx_ylo, bx_yhi;
290  realbdy_interior_bxs_xy(domain, domain, width,
291  bx_xlo, bx_xhi, bx_ylo, bx_yhi, ng_vect, true);
292  R_xlo.resize(bx_xlo, 1, The_Async_Arena());
293  R_xhi.resize(bx_xhi, 1, The_Async_Arena());
294  R_ylo.resize(bx_ylo, 1, The_Async_Arena());
295  R_yhi.resize(bx_yhi, 1, The_Async_Arena());
296 
297  const auto& r_xlo_n = bdy_data_xlo[n_time][WRFBdyVars::R].const_array();
298  const auto& r_xlo_np1 = bdy_data_xlo[n_time_p1][WRFBdyVars::R].const_array();
299  const auto& r_xhi_n = bdy_data_xhi[n_time][WRFBdyVars::R].const_array();
300  const auto& r_xhi_np1 = bdy_data_xhi[n_time_p1][WRFBdyVars::R].const_array();
301  const auto& r_ylo_n = bdy_data_ylo[n_time][WRFBdyVars::R].const_array();
302  const auto& r_ylo_np1 = bdy_data_ylo[n_time_p1][WRFBdyVars::R].const_array();
303  const auto& r_yhi_n = bdy_data_yhi[n_time][WRFBdyVars::R].const_array();
304  const auto& r_yhi_np1 = bdy_data_yhi[n_time_p1][WRFBdyVars::R].const_array();
305  const auto& rbx = lbound(domain);
306  const auto& rhi = ubound(domain);
307  r_xlo_arr = R_xlo.array();
308  r_xhi_arr = R_xhi.array();
309  r_ylo_arr = R_ylo.array();
310  r_yhi_arr = R_yhi.array();
311 
312  ParallelFor(bx_xlo, bx_xhi,
313  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
314  int ii = amrex::max(i, rbx.x); ii = amrex::min(ii, rbx.x + width - 1);
315  int jj = amrex::max(j, rbx.y); jj = amrex::min(jj, rhi.y);
316  r_xlo_arr(i,j,k) = oma*r_xlo_n(ii,jj,k) + alpha*r_xlo_np1(ii,jj,k);
317  },
318  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
319  int ii = amrex::max(i, rhi.x - width + 1); ii = amrex::min(ii, rhi.x);
320  int jj = amrex::max(j, rbx.y); jj = amrex::min(jj, rhi.y);
321  r_xhi_arr(i,j,k) = oma*r_xhi_n(ii,jj,k) + alpha*r_xhi_np1(ii,jj,k);
322  });
323  ParallelFor(bx_ylo, bx_yhi,
324  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
325  int ii = amrex::max(i, rbx.x); ii = amrex::min(ii, rhi.x);
326  int jj = amrex::max(j, rbx.y); jj = amrex::min(jj, rbx.y + width - 1);
327  r_ylo_arr(i,j,k) = oma*r_ylo_n(ii,jj,k) + alpha*r_ylo_np1(ii,jj,k);
328  },
329  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
330  int ii = amrex::max(i, rbx.x); ii = amrex::min(ii, rhi.x);
331  int jj = amrex::max(j, rhi.y - width + 1); jj = amrex::min(jj, rhi.y);
332  r_yhi_arr(i,j,k) = oma*r_yhi_n(ii,jj,k) + alpha*r_yhi_np1(ii,jj,k);
333  });
334  }
335 
336 
337  // NOTE: These operations use the BDY FABS and RHO. The
338  // use of RHO to go from PRIM -> CONS requires that
339  // these operations be LOCAL. So we have allocated
340  // enough space to do global operations (1 rank) but
341  // will fill a subset of that data that the rank owns.
342 
343  // Populate FABs from bdy interpolation (primitive vars)
344  //==========================================================
345  for (int ivar(ivarU); ivar < BdyEnd; ivar++) {
346  int ivar_idx = var_map[ivar];
347  Box domain = geom.Domain();
348  auto ixtype = S_cur_data[ivar_idx].boxArray().ixType();
349  domain.convert(ixtype);
350  const auto& dom_lo = lbound(domain);
351  const auto& dom_hi = ubound(domain);
352 
353  // BndryReg idx and limiting
354  int bdy_comp = bnd_map[ivar];
355  const auto& dom_cc_lo = lbound(geom.Domain());
356  const auto& dom_cc_hi = ubound(geom.Domain());
357 
358 #ifdef _OPENMP
359 #pragma omp parallel if (Gpu::notInLaunchRegion())
360 #endif
361  for (MFIter mfi(S_cur_data[ivar_idx],TilingIfNotGPU()); mfi.isValid(); ++mfi) {
362  // NOTE: Ghost cells needed for idx type mismatch between mask and data (do_upwind)
363  IntVect ng_vect(0);
364  //IntVect ng_vect(1,1,0);
365  Box gtbx = grow(mfi.tilebox(ixtype.toIntVect()),ng_vect);
366  Box tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi;
367  realbdy_interior_bxs_xy(gtbx, domain, width,
368  tbx_xlo, tbx_xhi,
369  tbx_ylo, tbx_yhi,
370  ng_vect, true);
371 
372  Array4<Real> arr_xlo; Array4<Real> arr_xhi;
373  Array4<Real> arr_ylo; Array4<Real> arr_yhi;
374  if (ivar == ivarU) {
375  arr_xlo = U_xlo.array(); arr_xhi = U_xhi.array();
376  arr_ylo = U_ylo.array(); arr_yhi = U_yhi.array();
377  } else if (ivar == ivarV) {
378  arr_xlo = V_xlo.array(); arr_xhi = V_xhi.array();
379  arr_ylo = V_ylo.array(); arr_yhi = V_yhi.array();
380  } else if (ivar == ivarT){
381  arr_xlo = T_xlo.array(); arr_xhi = T_xhi.array();
382  arr_ylo = T_ylo.array(); arr_yhi = T_yhi.array();
383  } else {
384  continue;
385  }
386 
387  // Boundary data at fixed time intervals
388  const auto& bdatxlo_n = bdy_data_xlo[n_time ][ivar].const_array();
389  const auto& bdatxlo_np1 = bdy_data_xlo[n_time_p1][ivar].const_array();
390  const auto& bdatxhi_n = bdy_data_xhi[n_time ][ivar].const_array();
391  const auto& bdatxhi_np1 = bdy_data_xhi[n_time_p1][ivar].const_array();
392  const auto& bdatylo_n = bdy_data_ylo[n_time ][ivar].const_array();
393  const auto& bdatylo_np1 = bdy_data_ylo[n_time_p1][ivar].const_array();
394  const auto& bdatyhi_n = bdy_data_yhi[n_time ][ivar].const_array();
395  const auto& bdatyhi_np1 = bdy_data_yhi[n_time_p1][ivar].const_array();
396 
397  // Current density to convert to conserved vars
398  Array4<Real> r_arr = S_cur_data[IntVars::cons].array(mfi);
399 
400  // Limiting offset
401  int offset = width - 1;
402 
403  // Populate with interpolation (protect from ghost cells)
404  const auto rxlo = r_xlo_arr;
405  const auto rxhi = r_xhi_arr;
406  const auto rylo = r_ylo_arr;
407  const auto ryhi = r_yhi_arr;
408  ParallelFor(tbx_xlo, tbx_xhi,
409  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
410  {
411  int ii = std::max(i , dom_lo.x); ii = std::min(ii, dom_lo.x+offset);
412  int jj = std::max(j , dom_lo.y); jj = std::min(jj, dom_hi.y);
413 
414  Real rho_interp;
415  if (use_wrf_bdy_density && ivar==ivarU) {
416  int im = amrex::max(i-1, dom_lo.x);
417  rho_interp = myhalf * (rxlo(im,j,k) + rxlo(amrex::max(i, dom_lo.x),j,k));
418  } else if (use_wrf_bdy_density && ivar==ivarV) {
419  int jm = amrex::max(j-1, dom_lo.y);
420  rho_interp = myhalf * (rxlo(i,jm,k) + rxlo(i,amrex::max(j, dom_lo.y),k));
421  } else if (use_wrf_bdy_density) {
422  rho_interp = rxlo(i,j,k);
423  } else if (ivar==ivarU) {
424  rho_interp = myhalf * ( r_arr(i-1,j ,k) + r_arr(i,j,k) );
425  } else if (ivar==ivarV) {
426  rho_interp = myhalf * ( r_arr(i ,j-1,k) + r_arr(i,j,k) );
427  } else {
428  rho_interp = r_arr(i,j,k);
429  }
430 
431  if (bdatxlo) {
432  int ii2 = std::min(std::max(i , dom_cc_lo.x), dom_cc_hi.x);
433  int jj2 = std::min(std::max(j , dom_cc_lo.y), dom_cc_hi.y);
434  arr_xlo(i,j,k) = rho_interp * bdatxlo(ii2,jj2,k,bdy_comp);
435  } else {
436  arr_xlo(i,j,k) = rho_interp * ( oma * bdatxlo_n (ii,jj,k,0)
437  + alpha * bdatxlo_np1(ii,jj,k,0) );
438  }
439  },
440  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
441  {
442  int ii = std::max(i , dom_hi.x-offset); ii = std::min(ii, dom_hi.x);
443  int jj = std::max(j , dom_lo.y); jj = std::min(jj, dom_hi.y);
444 
445  Real rho_interp;
446  if (use_wrf_bdy_density && ivar==ivarU) {
447  int im = amrex::max(i-1, dom_lo.x);
448  rho_interp = myhalf * (rxhi(im,j,k) + rxhi(amrex::max(i, dom_lo.x),j,k));
449  } else if (use_wrf_bdy_density && ivar==ivarV) {
450  int jm = amrex::max(j-1, dom_lo.y);
451  rho_interp = myhalf * (rxhi(i,jm,k) + rxhi(i,amrex::max(j, dom_lo.y),k));
452  } else if (use_wrf_bdy_density) {
453  rho_interp = rxhi(i,j,k);
454  } else if (ivar==ivarU) {
455  rho_interp = myhalf * ( r_arr(i-1,j ,k) + r_arr(i,j,k) );
456  } else if (ivar==ivarV) {
457  rho_interp = myhalf * ( r_arr(i ,j-1,k) + r_arr(i,j,k) );
458  } else {
459  rho_interp = r_arr(i,j,k);
460  }
461 
462  if (bdatxhi) {
463  int ii2 = std::min(std::max(i , dom_cc_lo.x), dom_cc_hi.x);
464  int jj2 = std::min(std::max(j , dom_cc_lo.y), dom_cc_hi.y);
465  arr_xhi(i,j,k) = rho_interp * bdatxhi(ii2,jj2,k,bdy_comp);
466  } else {
467  arr_xhi(i,j,k) = rho_interp * ( oma * bdatxhi_n (ii,jj,k,0)
468  + alpha * bdatxhi_np1(ii,jj,k,0) );
469  }
470  });
471 
472  ParallelFor(tbx_ylo, tbx_yhi,
473  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
474  {
475  int ii = std::max(i , dom_lo.x); ii = std::min(ii, dom_hi.x);
476  int jj = std::max(j , dom_lo.y); jj = std::min(jj, dom_lo.y+offset);
477 
478  Real rho_interp;
479  if (use_wrf_bdy_density && ivar==ivarU) {
480  int im = amrex::max(i-1, dom_lo.x);
481  rho_interp = myhalf * (rylo(im,j,k) + rylo(amrex::max(i, dom_lo.x),j,k));
482  } else if (use_wrf_bdy_density && ivar==ivarV) {
483  int jm = amrex::max(j-1, dom_lo.y);
484  rho_interp = myhalf * (rylo(i,jm,k) + rylo(i,amrex::max(j, dom_lo.y),k));
485  } else if (use_wrf_bdy_density) {
486  rho_interp = rylo(i,j,k);
487  } else if (ivar==ivarU) {
488  rho_interp = myhalf * ( r_arr(i-1,j ,k) + r_arr(i,j,k) );
489  } else if (ivar==ivarV) {
490  rho_interp = myhalf * ( r_arr(i ,j-1,k) + r_arr(i,j,k) );
491  } else {
492  rho_interp = r_arr(i,j,k);
493  }
494 
495  if (bdatylo) {
496  int ii2 = std::min(std::max(i , dom_cc_lo.x), dom_cc_hi.x);
497  int jj2 = std::min(std::max(j , dom_cc_lo.y), dom_cc_hi.y);
498  arr_ylo(i,j,k) = rho_interp * bdatylo(ii2,jj2,k,bdy_comp);
499  } else {
500  arr_ylo(i,j,k) = rho_interp * ( oma * bdatylo_n (ii,jj,k,0)
501  + alpha * bdatylo_np1(ii,jj,k,0) );
502  }
503  },
504  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
505  {
506  int ii = std::max(i , dom_lo.x); ii = std::min(ii, dom_hi.x);
507  int jj = std::max(j , dom_hi.y-offset); jj = std::min(jj, dom_hi.y);
508 
509  Real rho_interp;
510  if (use_wrf_bdy_density && ivar==ivarU) {
511  int im = amrex::max(i-1, dom_lo.x);
512  rho_interp = myhalf * (ryhi(im,j,k) + ryhi(amrex::max(i, dom_lo.x),j,k));
513  } else if (use_wrf_bdy_density && ivar==ivarV) {
514  int jm = amrex::max(j-1, dom_lo.y);
515  rho_interp = myhalf * (ryhi(i,jm,k) + ryhi(i,amrex::max(j, dom_lo.y),k));
516  } else if (use_wrf_bdy_density) {
517  rho_interp = ryhi(i,j,k);
518  } else if (ivar==ivarU) {
519  rho_interp = myhalf * ( r_arr(i-1,j ,k) + r_arr(i,j,k) );
520  } else if (ivar==ivarV) {
521  rho_interp = myhalf * ( r_arr(i ,j-1,k) + r_arr(i,j,k) );
522  } else {
523  rho_interp = r_arr(i,j,k);
524  }
525 
526  if (bdatyhi) {
527  int ii2 = std::min(std::max(i , dom_cc_lo.x), dom_cc_hi.x);
528  int jj2 = std::min(std::max(j , dom_cc_lo.y), dom_cc_hi.y);
529  arr_yhi(i,j,k) = rho_interp * bdatyhi(ii2,jj2,k,bdy_comp);
530  } else {
531  arr_yhi(i,j,k) = rho_interp * ( oma * bdatyhi_n (ii,jj,k,0)
532  + alpha * bdatyhi_np1(ii,jj,k,0) );
533  }
534  });
535  } // mfi
536  } // ivar
537 
538 
539  // Compute RHS in relaxation region
540  //==========================================================
541  auto dx = geom.CellSizeArray();
542  auto ProbLo = geom.ProbLoArray();
543  auto ProbHi = geom.ProbHiArray();
544 
545  for (int ivar(ivarU); ivar < BdyEnd; ivar++) {
546  int ivar_idx = ivar_map[ivar];
547  int icomp = comp_map[ivar];
548 
549  Box domain = geom.Domain();
550  domain.convert(S_cur_data[ivar_idx].boxArray().ixType());
551  IntVect ng_vect(0);
552 
553 #ifdef _OPENMP
554 #pragma omp parallel if (Gpu::notInLaunchRegion())
555 #endif
556  for (MFIter mfi(S_cur_data[ivar_idx],TilingIfNotGPU()); mfi.isValid(); ++mfi)
557  {
558  Box tbx = mfi.tilebox();
559  Box tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi;
560  realbdy_interior_bxs_xy(tbx, domain, width,
561  tbx_xlo, tbx_xhi,
562  tbx_ylo, tbx_yhi,
563  ng_vect);
564 
565  Array4<Real> rhs_arr; Array4<Real> data_arr;
566  Array4<Real> arr_xlo; Array4<Real> arr_xhi;
567  Array4<Real> arr_ylo; Array4<Real> arr_yhi;
568  if (ivar == ivarU) {
569  arr_xlo = U_xlo.array(); arr_xhi = U_xhi.array();
570  arr_ylo = U_ylo.array(); arr_yhi = U_yhi.array();
571  rhs_arr = S_rhs[IntVars::xmom].array(mfi);
572  data_arr = S_cur_data[IntVars::xmom].array(mfi);
573  } else if (ivar == ivarV) {
574  arr_xlo = V_xlo.array(); arr_xhi = V_xhi.array();
575  arr_ylo = V_ylo.array(); arr_yhi = V_yhi.array();
576  rhs_arr = S_rhs[IntVars::ymom].array(mfi);
577  data_arr = S_cur_data[IntVars::ymom].array(mfi);
578  } else if (ivar == ivarT){
579  arr_xlo = T_xlo.array(); arr_xhi = T_xhi.array();
580  arr_ylo = T_ylo.array(); arr_yhi = T_yhi.array();
581  rhs_arr = S_rhs[IntVars::cons].array(mfi);
582  data_arr = S_cur_data[IntVars::cons].array(mfi);
583  } else {
584  continue;
585  }
586 
588  width, dx, ProbLo, ProbHi, F1,
589  tbx_xlo , tbx_xhi , tbx_ylo , tbx_yhi ,
590  arr_xlo , arr_xhi , arr_ylo , arr_yhi ,
591  data_arr, rhs_arr , c_p, rdOcp);
592  } // mfi
593  } // ivar
594 
595  if (use_wrf_bdy_density) {
596  for (MFIter mfi(S_cur_data[IntVars::cons], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
597  Box domain = geom.Domain();
598  Box tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi;
599  realbdy_interior_bxs_xy(mfi.tilebox(), domain, width,
600  tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi);
601  realbdy_compute_relaxation(Rho_comp, 1, width, dx, ProbLo, ProbHi, F1_rho,
602  tbx_xlo, tbx_xhi, tbx_ylo, tbx_yhi,
603  r_xlo_arr, r_xhi_arr, r_ylo_arr, r_yhi_arr,
604  S_cur_data[IntVars::cons].const_array(mfi),
605  S_rhs[IntVars::cons].array(mfi), c_p, rdOcp);
606  }
607  }
608 
609  // Set normal velocity RHS at the boundary
610  //==========================================================
611  Box domain = geom.Domain();
612  Box domainx = convert(domain, IntVect(1,0,0));
613  Box domainy = convert(domain, IntVect(0,1,0));
614 
615  int ilo = domainx.smallEnd(0);
616  int ihi = domainx.bigEnd(0);
617  int jlo = domainy.smallEnd(1);
618  int jhi = domainy.bigEnd(1);
619 
620 #ifdef _OPENMP
621 #pragma omp parallel if (Gpu::notInLaunchRegion())
622 #endif
623  for (MFIter mfi(S_cur_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
624  {
625  Box tbx = mfi.nodaltilebox(0);
626  Box tbx_lo, tbx_hi;
627  if (tbx.smallEnd(0) == ilo) {
628  tbx_lo = makeSlab(tbx,0,ilo);
629  }
630  if (tbx.bigEnd(0) == ihi) {
631  tbx_hi = makeSlab(tbx,0,ihi);
632  }
633 
634  Box tby = mfi.nodaltilebox(1);
635  Box tby_lo, tby_hi;
636  if (tby.smallEnd(1) == jlo) {
637  tby_lo = makeSlab(tby,1,jlo);
638  }
639  if (tby.bigEnd(1) == jhi) {
640  tby_hi = makeSlab(tby,1,jhi);
641  }
642 
643  Array4<Real> rhs_xmom = S_rhs[IntVars::xmom].array(mfi);
644  Array4<Real> rhs_ymom = S_rhs[IntVars::ymom].array(mfi);
645 
646  Array4<const Real> rhs_cons = S_rhs[IntVars::cons].const_array(mfi);
647  Array4<const Real> cons_arr = S_cur_data[IntVars::cons].const_array(mfi);
648 
649  const auto& bdatxlo_n = bdy_data_xlo[n_time ][ivarU].const_array();
650  const auto& bdatxlo_np1 = bdy_data_xlo[n_time_p1][ivarU].const_array();
651  const auto& bdatxhi_n = bdy_data_xhi[n_time ][ivarU].const_array();
652  const auto& bdatxhi_np1 = bdy_data_xhi[n_time_p1][ivarU].const_array();
653 
654  const auto& bdatylo_n = bdy_data_ylo[n_time ][ivarV].const_array();
655  const auto& bdatylo_np1 = bdy_data_ylo[n_time_p1][ivarV].const_array();
656  const auto& bdatyhi_n = bdy_data_yhi[n_time ][ivarV].const_array();
657  const auto& bdatyhi_np1 = bdy_data_yhi[n_time_p1][ivarV].const_array();
658 
659  Real dT = static_cast<Real>(bdy_time_interval);
660 
661  ParallelFor(tbx_lo, tbx_hi,
662  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
663  {
664  Real rho_tend = rhs_cons(i,j,k);
665  Real rho_val = Real(0.5) * (cons_arr(i,j,k) + cons_arr(i-1,j,k));
666  Real u_tend, u_val;
667  if (btenxlo) {
668  u_tend = btenxlo(i,j,k,BCVars::xvel_bc);
669  u_val = bdatxlo(i,j,k,BCVars::xvel_bc);
670  } else {
671  u_tend = (bdatxlo_np1(i,j,k) - bdatxlo_n(i,j,k)) / dT;
672  u_val = oma * bdatxlo_n(i,j,k) + alpha * bdatxlo_np1(i,j,k);
673  }
674  rhs_xmom(i,j,k) = rho_val * u_tend + u_val * rho_tend;
675  },
676  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
677  {
678  // NOTE: (i,j,k) is the hi face of the domain, so the cell (i,j,k) is
679  // an exterior ghost cell for which the cons RHS is never filled;
680  // use the adjacent interior cell, mirroring the lo side.
681  Real rho_tend = rhs_cons(i-1,j,k);
682  Real rho_val = Real(0.5) * (cons_arr(i,j,k) + cons_arr(i-1,j,k));
683  Real u_tend, u_val;
684  if (btenxhi) {
685  u_tend = btenxhi(i,j,k,BCVars::xvel_bc);
686  u_val = bdatxhi(i,j,k,BCVars::xvel_bc);
687  } else {
688  u_tend = (bdatxhi_np1(i,j,k) - bdatxhi_n(i,j,k)) / dT;
689  u_val = oma * bdatxhi_n(i,j,k) + alpha * bdatxhi_np1(i,j,k);
690  }
691  rhs_xmom(i,j,k) = rho_val * u_tend + u_val * rho_tend;
692  });
693 
694  ParallelFor(tby_lo, tby_hi,
695  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
696  {
697  Real rho_tend = rhs_cons(i,j,k);
698  Real rho_val = Real(0.5) * (cons_arr(i,j,k) + cons_arr(i,j-1,k));
699  Real v_tend, v_val;
700  if (btenylo) {
701  v_tend = btenylo(i,j,k,BCVars::yvel_bc);
702  v_val = bdatylo(i,j,k,BCVars::yvel_bc);
703  } else {
704  v_tend = (bdatylo_np1(i,j,k) - bdatylo_n(i,j,k)) / dT;
705  v_val = oma * bdatylo_n(i,j,k) + alpha * bdatylo_np1(i,j,k);
706  }
707  rhs_ymom(i,j,k) = rho_val * v_tend + v_val * rho_tend;
708  },
709  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
710  {
711  // NOTE: (i,j,k) is the hi face of the domain, so the cell (i,j,k) is
712  // an exterior ghost cell for which the cons RHS is never filled;
713  // use the adjacent interior cell, mirroring the lo side.
714  Real rho_tend = rhs_cons(i,j-1,k);
715  Real rho_val = Real(0.5) * (cons_arr(i,j,k) + cons_arr(i,j-1,k));
716  Real v_tend, v_val;
717  if (btenyhi) {
718  v_tend = btenyhi(i,j,k,BCVars::yvel_bc);
719  v_val = bdatyhi(i,j,k,BCVars::yvel_bc);
720  } else {
721  v_tend = (bdatyhi_np1(i,j,k) - bdatyhi_n(i,j,k)) / dT;
722  v_val = oma * bdatyhi_n(i,j,k) + alpha * bdatyhi_np1(i,j,k);
723  }
724  rhs_ymom(i,j,k) = rho_val * v_tend + v_val * rho_tend;
725  });
726  } // mfi
727 }
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
const Real dx
Definition: ERF_InitCustomPert_ABL.H:23
const Real rdOcp
Definition: ERF_InitCustomPert_Bomex.H:16
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:31
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:242
@ RhoTheta_bc_comp
Definition: ERF_IndexDefines.H:88
@ yvel_bc
Definition: ERF_IndexDefines.H:103
@ xvel_bc
Definition: ERF_IndexDefines.H:102
@ U
Definition: ERF_IndexDefines.H:123
@ NumTypes
Definition: ERF_IndexDefines.H:128
@ T
Definition: ERF_IndexDefines.H:125
@ V
Definition: ERF_IndexDefines.H:124
@ xvel
Definition: ERF_IndexDefines.H:177
@ cons
Definition: ERF_IndexDefines.H:176
@ yvel
Definition: ERF_IndexDefines.H:178
@ R
Definition: ERF_IndexDefines.H:138
@ rhi
Definition: ERF_WSM6.H:250
real(kind=kind_phys), parameter, public alpha
Definition: ERF_module_mp_wsm6.F90:44
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