ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERFPhysBCFunct_w Class Reference

#include <ERF_PhysBCFunct.H>

Collaboration diagram for ERFPhysBCFunct_w:

Public Member Functions

 ERFPhysBCFunct_w (const int lev, const amrex::Geometry &geom, const amrex::Vector< amrex::BCRec > &domain_bcs_type, const amrex::Gpu::DeviceVector< amrex::BCRec > &domain_bcs_type_d, amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > bc_extdir_vals, amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > bc_neumann_vals, const TerrainType &terrain_type, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &mapfac_lev, std::unique_ptr< amrex::MultiFab > &z_phys_nd, const bool use_real_bcs, amrex::Real *w_bc_data)
 
 ~ERFPhysBCFunct_w ()
 
void operator() (amrex::MultiFab &mf, amrex::MultiFab &xvel, amrex::MultiFab &yvel, amrex::IntVect const &nghost, const double time, int bccomp, bool do_fb)
 
void impose_lateral_zvel_bcs (const amrex::Array4< amrex::Real > &dest_arr, const amrex::Array4< amrex::Real const > &xvel_arr, const amrex::Array4< amrex::Real const > &yvel_arr, const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< amrex::Real const > &mf_u, const amrex::Array4< amrex::Real const > &mf_v, const amrex::Array4< amrex::Real const > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > dxInv, TerrainType terrain_type, int bccomp, const double time)
 
void impose_vertical_zvel_bcs (const amrex::Array4< amrex::Real > &dest_arr, const amrex::Array4< amrex::Real const > &xvel_arr, const amrex::Array4< amrex::Real const > &yvel_arr, const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< amrex::Real const > &mf_u, const amrex::Array4< amrex::Real const > &mf_v, const amrex::Array4< amrex::Real const > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > dxInv, int bccomp_u, int bccomp_v, int bccomp_w, TerrainType terrain_type, const double time)
 

Private Attributes

int m_lev
 
amrex::Geometry m_geom
 
amrex::Vector< amrex::BCRec > m_domain_bcs_type
 
amrex::Gpu::DeviceVector< amrex::BCRec > m_domain_bcs_type_d
 
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_extdir_vals
 
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_neumann_vals
 
TerrainType m_terrain_type
 
amrex::MultiFab * m_mapfac_u
 
amrex::MultiFab * m_mapfac_v
 
amrex::MultiFab * m_z_phys_nd
 
bool m_use_real_bcs
 
amrex::Real * m_w_bc_data
 

Constructor & Destructor Documentation

◆ ERFPhysBCFunct_w()

ERFPhysBCFunct_w::ERFPhysBCFunct_w ( const int  lev,
const amrex::Geometry &  geom,
const amrex::Vector< amrex::BCRec > &  domain_bcs_type,
const amrex::Gpu::DeviceVector< amrex::BCRec > &  domain_bcs_type_d,
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max >  bc_extdir_vals,
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max >  bc_neumann_vals,
const TerrainType &  terrain_type,
amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  mapfac_lev,
std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
const bool  use_real_bcs,
amrex::Real *  w_bc_data 
)
inline

Construct the z-velocity physical boundary-condition functor.

Parameters
[in]levlevel index
[in]geomgeometry for the level
[in]domain_bcs_typehost boundary-condition records
[in]domain_bcs_type_ddevice boundary-condition records
[in]bc_extdir_valsexternal Dirichlet values for boundary faces
[in]bc_neumann_valsNeumann values for boundary faces
[in]terrain_typeterrain type for the level
[in]mapfac_levmap-factor MultiFabs for the level
[in]z_phys_ndnodal physical height MultiFab
[in]use_real_bcswhether real-data boundary conditions are active
[in]w_bc_dataoptional z-velocity boundary data
517  : m_lev(lev),
518  m_geom(geom), m_domain_bcs_type(domain_bcs_type),
519  m_domain_bcs_type_d(domain_bcs_type_d),
520  m_bc_extdir_vals(bc_extdir_vals),
521  m_bc_neumann_vals(bc_neumann_vals),
522  m_terrain_type(terrain_type),
523  m_z_phys_nd(z_phys_nd.get()),
524  m_use_real_bcs(use_real_bcs),
525  m_w_bc_data(w_bc_data)
526  {
527  m_mapfac_u = mapfac_lev[MapFacType::u_x].get();
528  m_mapfac_v = mapfac_lev[MapFacType::v_y].get();
529  }
@ v_y
Definition: ERF_DataStruct.H:41
@ u_x
Definition: ERF_DataStruct.H:40
amrex::Vector< amrex::BCRec > m_domain_bcs_type
Definition: ERF_PhysBCFunct.H:611
amrex::Geometry m_geom
Definition: ERF_PhysBCFunct.H:610
int m_lev
Definition: ERF_PhysBCFunct.H:609
amrex::Real * m_w_bc_data
Definition: ERF_PhysBCFunct.H:620
bool m_use_real_bcs
Definition: ERF_PhysBCFunct.H:619
amrex::Gpu::DeviceVector< amrex::BCRec > m_domain_bcs_type_d
Definition: ERF_PhysBCFunct.H:612
amrex::MultiFab * m_mapfac_v
Definition: ERF_PhysBCFunct.H:617
TerrainType m_terrain_type
Definition: ERF_PhysBCFunct.H:615
amrex::MultiFab * m_z_phys_nd
Definition: ERF_PhysBCFunct.H:618
amrex::MultiFab * m_mapfac_u
Definition: ERF_PhysBCFunct.H:616
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_neumann_vals
Definition: ERF_PhysBCFunct.H:614
amrex::Array< amrex::Array< amrex::Real, AMREX_SPACEDIM *2 >, AMREX_SPACEDIM+NBCVAR_max > m_bc_extdir_vals
Definition: ERF_PhysBCFunct.H:613

◆ ~ERFPhysBCFunct_w()

ERFPhysBCFunct_w::~ERFPhysBCFunct_w ( )
inline

Destroy the z-velocity physical boundary-condition functor.

534 {}

Member Function Documentation

◆ impose_lateral_zvel_bcs()

void ERFPhysBCFunct_w::impose_lateral_zvel_bcs ( const amrex::Array4< amrex::Real > &  dest_arr,
const amrex::Array4< amrex::Real const > &  xvel_arr,
const amrex::Array4< amrex::Real const > &  yvel_arr,
const amrex::Box &  bx,
const amrex::Box &  domain,
const amrex::Array4< amrex::Real const > &  mf_u,
const amrex::Array4< amrex::Real const > &  mf_v,
const amrex::Array4< amrex::Real const > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM >  dxInv,
TerrainType  terrain_type,
int  bccomp,
const double  time 
)

Impose lateral boundary conditions on z velocity.

Parameters
[in,out]dest_arrz-velocity data to be filled
[in]xvel_arrx-velocity used to determine upwind inflow
[in]yvel_arry-velocity used to determine upwind inflow
[in]bxbox holding data to be filled
[in]domainsimulation domain
[in]mf_ux map-factor field
[in]mf_vy map-factor field
[in]z_ndnodal physical height
[in]dxInvinverse cell size
[in]terrain_typeterrain representation
[in]bccompboundary-condition component
[in]timetime at which data should be filled

Impose lateral boundary conditions on z-component of velocity

Parameters
[in,out]dest_arrArray4 of the quantity to be filled
[in]xvel_arrx-velocity used to determine upwind Dirichlet inflow
[in]yvel_arry-velocity used to determine upwind Dirichlet inflow
[in]bxbox associated with this data
[in]domaincomputational domain
[in]mf_umetric-aware x-velocity used to convert omega to w
[in]mf_vmetric-aware y-velocity used to convert omega to w
[in]z_phys_ndheight coordinate at nodes
[in]dxInvinverse cell size array
[in]terrain_typeterrain type used to decide whether omega conversion is needed
[in]bccompindex into m_domain_bcs_type
[in]timetime at which the data should be filled
67 {
68  BL_PROFILE_VAR("impose_lateral_zvel_bcs()",impose_lateral_zvel_bcs);
69  const auto& dom_lo = lbound(domain);
70  const auto& dom_hi = ubound(domain);
71 
72  //
73  // An ext_dir_upwind face decides inflow against the face velocity, but the box we
74  // loop over does not always have a face velocity at every one of its cells: the
75  // state carries one more lateral ghost than the velocities do (ngrow_state =
76  // ComputeGhostCells()+1 against ngrow_vels = ComputeGhostCells()), and a velocity
77  // box is nodal in its own direction where the array being read is cell centered.
78  // Either way the outermost ghost cells have no velocity of their own, so sample
79  // the nearest one that exists. Cells already inside the velocity array are
80  // unaffected; only that outermost layer changes, and it previously read out of
81  // bounds.
82  //
83  const auto& xvel_lo = lbound(xvel_arr);
84  const auto& xvel_hi = ubound(xvel_arr);
85  const auto& yvel_lo = lbound(yvel_arr);
86  const auto& yvel_hi = ubound(yvel_arr);
87  const WFromOmegaRange wr = wfromomega_range(xvel_arr, yvel_arr, mf_u, mf_v, z_phys_nd);
88 
89  // Based on BCRec for the domain, we need to make BCRec for this Box
90  // bccomp is used as starting index for m_domain_bcs_type
91  // 0 is used as starting index for bcrs
92  Vector<BCRec> bcrs_w(1);
93  setBC(enclosedCells(bx), domain, bccomp, 0, 1, m_domain_bcs_type, bcrs_w);
94 
95  bool l_use_terrain_fitted_coords = ( (terrain_type == TerrainType::StaticFittedMesh) ||
96  (terrain_type == TerrainType::MovingFittedMesh) );
97 
98  // xlo: ori = 0
99  // ylo: ori = 1
100  // zlo: ori = 2
101  // xhi: ori = 3
102  // yhi: ori = 4
103  // zhi: ori = 5
104 
105  Gpu::DeviceVector<BCRec> bcrs_w_d(1);
106  Gpu::copyAsync(Gpu::hostToDevice, bcrs_w.begin(), bcrs_w.end(), bcrs_w_d.begin());
107  const BCRec* bc_ptr_w = bcrs_w_d.data();
108 
109  GpuArray<GpuArray<Real, AMREX_SPACEDIM*2>,1> l_bc_extdir_vals_d;
110 
111  for (int ori = 0; ori < 2*AMREX_SPACEDIM; ori++) {
112  l_bc_extdir_vals_d[0][ori] = m_bc_extdir_vals[bccomp][ori];
113  }
114 
115  GeometryData const& geomdata = m_geom.data();
116  bool is_periodic_in_x = geomdata.isPeriodic(0);
117  bool is_periodic_in_y = geomdata.isPeriodic(1);
118 
119  FArrayBox dhdtfab;
120 
121  // First do all ext_dir bcs
122  if (!is_periodic_in_x)
123  {
124  Real* zvel_bc_ptr = m_w_bc_data;
125  Box bx_xlo(bx); bx_xlo.setBig (0,dom_lo.x-1);
126  Box bx_xhi(bx); bx_xhi.setSmall(0,dom_hi.x+1);
127  ParallelFor(bx_xlo, bx_xhi,
128  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
129  int iflip = 2*dom_lo.x - 1 - i;
130  if ( (bc_ptr_w[0].lo(0) == ERFBCType::ext_dir) ||
131  (bc_ptr_w[0].lo(0) == ERFBCType::ext_dir_upwind && xvel_arr(dom_lo.x,Clamp(j,xvel_lo.y,xvel_hi.y),Clamp(k,xvel_lo.z,xvel_hi.z)) >= zero) )
132  {
133  dest_arr(i,j,k) = (zvel_bc_ptr) ? zvel_bc_ptr[k] : l_bc_extdir_vals_d[0][0];
134  if (l_use_terrain_fitted_coords) {
135  int wi = Clamp(i,wr.ilo,wr.ihi), wj = Clamp(j,wr.jlo,wr.jhi), wk = Clamp(k,wr.klo,wr.khi);
136  dest_arr(i,j,k) = WFromOmega(wi,wj,wk,dest_arr(i,j,k),
137  xvel_arr,yvel_arr,
138  mf_u,mf_v,z_phys_nd,dxInv);
139  }
140  } else if (bc_ptr_w[0].lo(0) == ERFBCType::foextrap ||
141  bc_ptr_w[0].lo(0) == ERFBCType::ext_dir_upwind) { // outflow part of an inflow_outflow face
142  dest_arr(i,j,k) = dest_arr(dom_lo.x,j,k);
143  } else if (bc_ptr_w[0].lo(0) == ERFBCType::open) {
144  dest_arr(i,j,k) = dest_arr(dom_lo.x,j,k);
145  } else if (bc_ptr_w[0].lo(0) == ERFBCType::reflect_even) {
146  dest_arr(i,j,k) = dest_arr(iflip,j,k);
147  } else if (bc_ptr_w[0].lo(0) == ERFBCType::reflect_odd) {
148  dest_arr(i,j,k) = -dest_arr(iflip,j,k);
149  } else if (bc_ptr_w[0].lo(0) == ERFBCType::hoextrap) {
150  Real d = static_cast<Real>(dom_lo.x - i);
151  dest_arr(i,j,k) = (one + d)*dest_arr(dom_lo.x,j,k) - d*dest_arr(dom_lo.x+1,j,k);
152  }
153  },
154  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
155  int iflip = 2*dom_hi.x + 1 - i;
156  if ( (bc_ptr_w[0].hi(0) == ERFBCType::ext_dir) ||
157  (bc_ptr_w[0].hi(0) == ERFBCType::ext_dir_upwind && xvel_arr(dom_hi.x+1,Clamp(j,xvel_lo.y,xvel_hi.y),Clamp(k,xvel_lo.z,xvel_hi.z)) <= zero) )
158  {
159  dest_arr(i,j,k) = (zvel_bc_ptr) ? zvel_bc_ptr[k] : l_bc_extdir_vals_d[0][3];
160  if (l_use_terrain_fitted_coords) {
161  int wi = Clamp(i,wr.ilo,wr.ihi), wj = Clamp(j,wr.jlo,wr.jhi), wk = Clamp(k,wr.klo,wr.khi);
162  dest_arr(i,j,k) = WFromOmega(wi,wj,wk,dest_arr(i,j,k),
163  xvel_arr,yvel_arr,
164  mf_u,mf_v,z_phys_nd,dxInv);
165  }
166  } else if (bc_ptr_w[0].hi(0) == ERFBCType::foextrap ||
167  bc_ptr_w[0].hi(0) == ERFBCType::ext_dir_upwind) { // outflow part of an inflow_outflow face
168  dest_arr(i,j,k) = dest_arr(dom_hi.x,j,k);
169  } else if (bc_ptr_w[0].hi(0) == ERFBCType::open) {
170  dest_arr(i,j,k) = dest_arr(dom_hi.x,j,k);
171  } else if (bc_ptr_w[0].hi(0) == ERFBCType::reflect_even) {
172  dest_arr(i,j,k) = dest_arr(iflip,j,k);
173  } else if (bc_ptr_w[0].hi(0) == ERFBCType::reflect_odd) {
174  dest_arr(i,j,k) = -dest_arr(iflip,j,k);
175  } else if (bc_ptr_w[0].hi(0) == ERFBCType::hoextrap) {
176  Real d = static_cast<Real>(i - dom_hi.x);
177  dest_arr(i,j,k) = (one + d)*dest_arr(dom_hi.x,j,k) - d*dest_arr(dom_hi.x-1,j,k);
178  }
179  }
180  );
181  }
182 
183  // First do all ext_dir bcs
184  if (!is_periodic_in_y)
185  {
186  Real* zvel_bc_ptr = m_w_bc_data;
187  Box bx_ylo(bx); bx_ylo.setBig (1,dom_lo.y-1);
188  Box bx_yhi(bx); bx_yhi.setSmall(1,dom_hi.y+1);
189  ParallelFor(bx_ylo, bx_yhi,
190  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
191  int jflip = 2*dom_lo.y - 1 - j;
192  if ( (bc_ptr_w[0].lo(1) == ERFBCType::ext_dir) ||
193  (bc_ptr_w[0].lo(1) == ERFBCType::ext_dir_upwind && yvel_arr(Clamp(i,yvel_lo.x,yvel_hi.x),dom_lo.y,Clamp(k,yvel_lo.z,yvel_hi.z)) >= zero) )
194  {
195  dest_arr(i,j,k) = (zvel_bc_ptr) ? zvel_bc_ptr[k] : l_bc_extdir_vals_d[0][1];
196  if (l_use_terrain_fitted_coords) {
197  int wi = Clamp(i,wr.ilo,wr.ihi), wj = Clamp(j,wr.jlo,wr.jhi), wk = Clamp(k,wr.klo,wr.khi);
198  dest_arr(i,j,k) = WFromOmega(wi,wj,wk,dest_arr(i,j,k),
199  xvel_arr,yvel_arr,
200  mf_u,mf_v,z_phys_nd,dxInv);
201  }
202  } else if (bc_ptr_w[0].lo(1) == ERFBCType::foextrap ||
203  bc_ptr_w[0].lo(1) == ERFBCType::ext_dir_upwind) { // outflow part of an inflow_outflow face
204  dest_arr(i,j,k) = dest_arr(i,dom_lo.y,k);
205  } else if (bc_ptr_w[0].lo(1) == ERFBCType::open) {
206  dest_arr(i,j,k) = dest_arr(i,dom_lo.y,k);
207  } else if (bc_ptr_w[0].lo(1) == ERFBCType::reflect_even) {
208  dest_arr(i,j,k) = dest_arr(i,jflip,k);
209  } else if (bc_ptr_w[0].lo(1) == ERFBCType::reflect_odd) {
210  dest_arr(i,j,k) = -dest_arr(i,jflip,k);
211  } else if (bc_ptr_w[0].lo(1) == ERFBCType::hoextrap) {
212  Real d = static_cast<Real>(dom_lo.y - j);
213  dest_arr(i,j,k) = (one + d)*dest_arr(i,dom_lo.y,k) - d*dest_arr(i,dom_lo.y+1,k);
214  }
215  },
216  [=] AMREX_GPU_DEVICE (int i, int j, int k) {
217  int jflip = 2*dom_hi.y + 1 - j;
218  if ( (bc_ptr_w[0].hi(1) == ERFBCType::ext_dir) ||
219  (bc_ptr_w[0].hi(1) == ERFBCType::ext_dir_upwind && yvel_arr(Clamp(i,yvel_lo.x,yvel_hi.x),dom_hi.y+1,Clamp(k,yvel_lo.z,yvel_hi.z)) <= zero) )
220  {
221  dest_arr(i,j,k) = (zvel_bc_ptr) ? zvel_bc_ptr[k] : l_bc_extdir_vals_d[0][4];
222  if (l_use_terrain_fitted_coords) {
223  int wi = Clamp(i,wr.ilo,wr.ihi), wj = Clamp(j,wr.jlo,wr.jhi), wk = Clamp(k,wr.klo,wr.khi);
224  dest_arr(i,j,k) = WFromOmega(wi,wj,wk,dest_arr(i,j,k),
225  xvel_arr,yvel_arr,
226  mf_u,mf_v,z_phys_nd,dxInv);
227  }
228  } else if (bc_ptr_w[0].hi(1) == ERFBCType::foextrap ||
229  bc_ptr_w[0].hi(1) == ERFBCType::ext_dir_upwind) { // outflow part of an inflow_outflow face
230  dest_arr(i,j,k) = dest_arr(i,dom_hi.y,k);
231  } else if (bc_ptr_w[0].hi(1) == ERFBCType::open) {
232  dest_arr(i,j,k) = dest_arr(i,dom_hi.y,k);
233  } else if (bc_ptr_w[0].hi(1) == ERFBCType::reflect_even) {
234  dest_arr(i,j,k) = dest_arr(i,jflip,k);
235  } else if (bc_ptr_w[0].hi(1) == ERFBCType::reflect_odd) {
236  dest_arr(i,j,k) = -dest_arr(i,jflip,k);
237  } else if (bc_ptr_w[0].hi(1) == ERFBCType::hoextrap) {
238  Real d = static_cast<Real>(j - dom_hi.y);
239  dest_arr(i,j,k) = (one + d)*dest_arr(i,dom_hi.y,k) - d*dest_arr(i,dom_hi.y-1,k);
240  }
241  });
242  }
243  Gpu::streamSynchronize();
244 }
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
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
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real WFromOmega(int &i, int &j, int &k, amrex::Real omega, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv)
Definition: ERF_TerrainMetrics.H:867
void impose_lateral_zvel_bcs(const amrex::Array4< amrex::Real > &dest_arr, const amrex::Array4< amrex::Real const > &xvel_arr, const amrex::Array4< amrex::Real const > &yvel_arr, const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< amrex::Real const > &mf_u, const amrex::Array4< amrex::Real const > &mf_v, const amrex::Array4< amrex::Real const > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > dxInv, TerrainType terrain_type, int bccomp, const double time)
Definition: ERF_BoundaryConditionsZvel.cpp:57
@ open
Definition: ERF_IndexDefines.H:324
@ reflect_odd
Definition: ERF_IndexDefines.H:313
@ hoextrap
Definition: ERF_IndexDefines.H:318
@ foextrap
Definition: ERF_IndexDefines.H:316
@ ext_dir
Definition: ERF_IndexDefines.H:317
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:325
@ reflect_even
Definition: ERF_IndexDefines.H:315
@ wi
Definition: ERF_AdvanceWDM6.cpp:277
Here is the call graph for this function:

◆ impose_vertical_zvel_bcs()

void ERFPhysBCFunct_w::impose_vertical_zvel_bcs ( const amrex::Array4< amrex::Real > &  dest_arr,
const amrex::Array4< amrex::Real const > &  xvel_arr,
const amrex::Array4< amrex::Real const > &  yvel_arr,
const amrex::Box &  bx,
const amrex::Box &  domain,
const amrex::Array4< amrex::Real const > &  mf_u,
const amrex::Array4< amrex::Real const > &  mf_v,
const amrex::Array4< amrex::Real const > &  z_nd,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM >  dxInv,
int  bccomp_u,
int  bccomp_v,
int  bccomp_w,
TerrainType  terrain_type,
const double  time 
)

Impose vertical boundary conditions on z velocity.

Parameters
[in,out]dest_arrz-velocity data to be filled
[in]xvel_arrx-velocity used by terrain-aware vertical BCs
[in]yvel_arry-velocity used by terrain-aware vertical BCs
[in]bxbox holding data to be filled
[in]domainsimulation domain
[in]mf_ux map-factor field
[in]mf_vy map-factor field
[in]z_ndnodal physical height
[in]dxInvinverse cell size
[in]bccomp_ux-velocity boundary-condition component
[in]bccomp_vy-velocity boundary-condition component
[in]bccomp_wz-velocity boundary-condition component
[in]terrain_typeterrain representation
[in]timetime at which data should be filled

Impose vertical boundary conditions on z-component of velocity

Parameters
[in,out]dest_arrArray4 of the quantity to be filled
[in]xvel_arrx-velocity used to convert omega to w
[in]yvel_arry-velocity used to convert omega to w
[in]bxbox associated with this data
[in]domaincomputational domain
[in]mf_umetric-aware x-velocity used to convert omega to w
[in]mf_vmetric-aware y-velocity used to convert omega to w
[in]z_phys_ndheight coordinate at nodes
[in]dxInvinverse cell size array
[in]bccomp_uindex into m_domain_bcs_type corresponding to u
[in]bccomp_vindex into m_domain_bcs_type corresponding to v
[in]bccomp_windex into m_domain_bcs_type corresponding to w
[in]terrain_typeif MovingFittedMesh then the terrain is moving; otherwise fixed
[in]timetime at which the data should be filled
276 {
277  BL_PROFILE_VAR("impose_vertical_zvel_bcs()",impose_vertical_zvel_bcs);
278  const auto& dom_lo = lbound(domain);
279  const auto& dom_hi = ubound(domain);
280  const WFromOmegaRange wr = wfromomega_range(xvel_arr, yvel_arr, mf_u, mf_v, z_phys_nd);
281 
282  // xlo: ori = 0
283  // ylo: ori = 1
284  // zlo: ori = 2
285  // xhi: ori = 3
286  // yhi: ori = 4
287  // zhi: ori = 5
288 
289  // Based on BCRec for the domain, we need to make BCRec for this Box
290  // bccomp is used as starting index for m_domain_bcs_type
291  // 0 is used as starting index for bcrs
292  Vector<BCRec> bcrs_u(1), bcrs_v(1), bcrs_w(1);
293  setBC(enclosedCells(bx), domain, bccomp_u, 0, 1, m_domain_bcs_type, bcrs_u);
294  setBC(enclosedCells(bx), domain, bccomp_v, 0, 1, m_domain_bcs_type, bcrs_v);
295  setBC(enclosedCells(bx), domain, bccomp_w, 0, 1, m_domain_bcs_type, bcrs_w);
296 
297  // We use these for the asserts below
298  const BCRec* bc_ptr_u_h = bcrs_u.data();
299  const BCRec* bc_ptr_v_h = bcrs_v.data();
300  const BCRec* bc_ptr_w_h = bcrs_w.data();
301 
302  bool l_use_terrain_fitted_coords = ( (terrain_type == TerrainType::StaticFittedMesh) ||
303  (terrain_type == TerrainType::MovingFittedMesh) );
304  bool l_moving_terrain = (terrain_type == TerrainType::MovingFittedMesh);
305 
306  GpuArray<GpuArray<Real, AMREX_SPACEDIM*2>,1> l_bc_extdir_vals_d;
307 
308  for (int ori = 0; ori < 2*AMREX_SPACEDIM; ori++) {
309  l_bc_extdir_vals_d[0][ori] = m_bc_extdir_vals[bccomp_w][ori];
310  }
311 
312  // *******************************************************
313  // Bottom boundary
314  // *******************************************************
315 
316  // *******************************************************
317  // Moving terrain
318  // *******************************************************
319  if (l_moving_terrain)
320  {
321  //************************************************************
322  // NOTE: z_t depends on the time interval in which it is
323  // evaluated so we can't arbitrarily define it at a
324  // given time, we must specify an interval
325  //************************************************************
326 
327  // Static terrain
328  } else if (l_use_terrain_fitted_coords) {
329 
330  if (m_lev == 0) {
331  AMREX_ALWAYS_ASSERT( (bc_ptr_u_h[0].lo(2) == ERFBCType::ext_dir && bc_ptr_v_h[0].lo(2) == ERFBCType::ext_dir) ||
332  (bc_ptr_u_h[0].lo(2) != ERFBCType::ext_dir && bc_ptr_v_h[0].lo(2) != ERFBCType::ext_dir) );
333  } else {
334  // If we do not reach to the top or bottom boundary then the z-vel should be
335  // filled by interpolation from the coarser grid using ERF_FillPatcher.
336  }
337  if (bx.smallEnd(2) == dom_lo.z) {
338  ParallelFor(makeSlab(bx,2,dom_lo.z), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
339  int wi = Clamp(i,wr.ilo,wr.ihi), wj = Clamp(j,wr.jlo,wr.jhi), wk = Clamp(k,wr.klo,wr.khi);
340  dest_arr(i,j,k) = WFromOmega(wi,wj,wk,l_bc_extdir_vals_d[0][2],
341  xvel_arr,yvel_arr,
342  mf_u,mf_v,z_phys_nd,dxInv);
343  });
344  }
345 
346  // No terrain
347  } else {
348  if (bx.smallEnd(2) == dom_lo.z) {
349  ParallelFor(makeSlab(bx,2,dom_lo.z), [=] AMREX_GPU_DEVICE (int i, int j, int k) {
350  dest_arr(i,j,k) = l_bc_extdir_vals_d[0][2];
351  });
352  }
353  }
354 
355  // *******************************************************
356  // Top boundary
357  // *******************************************************
358 
359  // NOTE: if we set SlipWall at top, that generates ERFBCType::ext_dir which sets w=0 here
360  // NOTE: if we set Outflow at top, that generates ERFBCType::foextrap which doesn't touch w here
361  if (bx.bigEnd(2) == dom_hi.z+1) {
362  if (bc_ptr_w_h[0].hi(2) == ERFBCType::ext_dir) {
363  ParallelFor(makeSlab(bx,2,dom_hi.z+1), [=] AMREX_GPU_DEVICE (int i, int j, int k)
364  {
365  if (l_use_terrain_fitted_coords) {
366  int wi = Clamp(i,wr.ilo,wr.ihi), wj = Clamp(j,wr.jlo,wr.jhi), wk = Clamp(k,wr.klo,wr.khi);
367  dest_arr(i,j,k) = WFromOmega(wi,wj,wk,l_bc_extdir_vals_d[0][5],
368  xvel_arr,yvel_arr,
369  mf_u,mf_v,z_phys_nd,dxInv);
370  } else {
371  dest_arr(i,j,k) = l_bc_extdir_vals_d[0][5];
372  }
373  });
374  } else if (bc_ptr_w_h[0].hi(2) == ERFBCType::neumann_int) {
375  ParallelFor(makeSlab(bx,2,dom_hi.z+1), [=] AMREX_GPU_DEVICE (int i, int j, int k)
376  {
377  dest_arr(i,j,k) = (Real(4.0)*dest_arr(i,j,dom_hi.z) - dest_arr(i,j,dom_hi.z-1))/three;
378  });
379  }
380  }
381  Gpu::streamSynchronize();
382 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
void impose_vertical_zvel_bcs(const amrex::Array4< amrex::Real > &dest_arr, const amrex::Array4< amrex::Real const > &xvel_arr, const amrex::Array4< amrex::Real const > &yvel_arr, const amrex::Box &bx, const amrex::Box &domain, const amrex::Array4< amrex::Real const > &mf_u, const amrex::Array4< amrex::Real const > &mf_v, const amrex::Array4< amrex::Real const > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > dxInv, int bccomp_u, int bccomp_v, int bccomp_w, TerrainType terrain_type, const double time)
Definition: ERF_BoundaryConditionsZvel.cpp:265
@ neumann_int
Definition: ERF_IndexDefines.H:323
Here is the call graph for this function:

◆ operator()()

void ERFPhysBCFunct_w::operator() ( amrex::MultiFab &  mf,
amrex::MultiFab &  xvel,
amrex::MultiFab &  yvel,
amrex::IntVect const &  nghost,
const double  time,
int  bccomp,
bool  do_fb 
)

Impose physical boundary conditions at domain boundaries

Parameters
[in,out]mfz-velocity MultiFab to be filled
[in]xvelx-velocity MultiFab used by upwind boundary conditions
[in]yvely-velocity MultiFab used by upwind boundary conditions
[in]nghostnumber of ghost cells to be filled for velocity components
[in]timetime at which the data should be filled
[in]bccompindex into m_domain_bcs_type for z velocity
[in]do_fbwhether to fill periodic/interior ghost cells first

Impose physical boundary conditions on z velocity.

Parameters
[in,out]mfz-velocity MultiFab to be filled
[in]xvelx-velocity MultiFab used by upwind boundary conditions
[in]yvely-velocity MultiFab used by upwind boundary conditions
[in]nghostnumber of ghost cells to be filled
[in]timetime at which data should be filled
[in]bccomp_windex into m_domain_bcs_type for z velocity
[in]do_fbwhether to fill periodic/interior ghost cells first
381 {
382  BL_PROFILE("ERFPhysBCFunct_w::()");
383 
384  //
385  // We fill all of the interior and periodic ghost cells first, so we can fill
386  // those directly inside the lateral and vertical calls.
387  // If triply periodic this is all we do
388  //
389  if (do_fb) {
390  mf.FillBoundary(m_geom.periodicity());
391  }
392 
393  if (m_geom.isAllPeriodic()) return;
394 
395  int bccomp_u = BCVars::xvel_bc;
396  int bccomp_v = BCVars::yvel_bc;
397 
398  const auto& domain = m_geom.Domain();
399  const auto dxInv = m_geom.InvCellSizeArray();
400 
401  Box gdomainz = surroundingNodes(domain,2);
402  for (int i = 0; i < AMREX_SPACEDIM; ++i) {
403  if (m_geom.isPeriodic(i)) {
404  gdomainz.grow(i, nghost[i]);
405  }
406  }
407  //
408  // We want to make sure we impose the z-vels at k=0 if the box includes k=0
409  //
410  if (gdomainz.smallEnd(2) == 0) gdomainz.setSmall(2,1);
411 
412  // With terrain, w is converted from omega (WFromOmega), which reads the map factors
414  "ERFPhysBCFunct_w: terrain needs the u and v map factors");
415 
416 #ifdef AMREX_USE_OMP
417 #pragma omp parallel if (Gpu::notInLaunchRegion())
418 #endif
419  {
420  for (MFIter mfi(mf,false); mfi.isValid(); ++mfi)
421  {
422  //
423  // This is the box we pass to the different routines
424  // NOTE -- this is the full grid NOT the tile box
425  //
426  Box bx = mfi.validbox();
427 
428  //
429  // These are the boxes we use to test on relative to the domain
430  //
431  Box zbx = surroundingNodes(bx,2); zbx.grow(nghost);
432  if (zbx.smallEnd(2) < domain.smallEnd(2)) zbx.setSmall(2,domain.smallEnd(2));
433  if (zbx.bigEnd(2) > domain.bigEnd(2)) {
434  zbx.setBig(2,domain.bigEnd(2)+1);
435  } else if (zbx.bigEnd(2) > xvel[mfi].box().bigEnd(2)) {
436  // We do this so if a box at level > 0 doesn't reach the top boundary, we don't go out of bounds
437  // (Note xvel is chosen arbitrarily; we could have used yvel instead)
438  zbx.setBig(2,xvel[mfi].box().bigEnd(2));
439  }
440 
441  Array4<const Real> z_nd_arr;
442  Array4<const Real> mf_u_arr;
443  Array4<const Real> mf_v_arr;
444  if (m_z_phys_nd) {
445  z_nd_arr = m_z_phys_nd->const_array(mfi);
446  }
447  if (m_mapfac_u) {
448  mf_u_arr = m_mapfac_u->const_array(mfi);
449  }
450  if (m_mapfac_v) {
451  mf_v_arr = m_mapfac_v->const_array(mfi);
452  }
453 
454  //
455  // Recall that gdomainz.smallEnd(2) = 1 not 0!
456  //
457  if (!gdomainz.contains(zbx)) {
458  Array4<const Real> const& velx_arr = xvel.const_array(mfi);
459  Array4<const Real> const& vely_arr = yvel.const_array(mfi);
460  Array4< Real> const& velz_arr = mf.array(mfi);
461 
462  if (!gdomainz.contains(zbx) && !m_use_real_bcs) {
463  impose_lateral_zvel_bcs(velz_arr,velx_arr,vely_arr,zbx,domain,
464  mf_u_arr,mf_v_arr,z_nd_arr,dxInv,m_terrain_type,bccomp_w,time);
465  }
466 
467  impose_vertical_zvel_bcs(velz_arr,velx_arr,vely_arr,zbx,domain,mf_u_arr,mf_v_arr,
468  z_nd_arr,dxInv,bccomp_u, bccomp_v, bccomp_w, m_terrain_type, time);
469  }
470 
471  //
472  // The faces beyond the bottom and top boundary faces are not set above, so
473  // give them the value on the boundary face. Nothing else fills them: on
474  // a level > 0 FillPatchTwoLevels does not fill outside the domain, and
475  // ERF::Advance has set them to bogus_large_value. The EB wall slopes
476  // read w at k = -1 where the EB meets the bottom boundary (issue #4876).
477  //
478  if (!m_geom.isPeriodic(2)) {
479  Array4<Real> const& velz_arr = mf.array(mfi);
480  Box gbx = mfi.fabbox() & surroundingNodes(bx,2).grow(nghost);
481  const int klo = domain.smallEnd(2);
482  const int khi = domain.bigEnd(2)+1;
483  if (gbx.smallEnd(2) < klo) {
484  Box bx_zlo(gbx); bx_zlo.setBig(2,klo-1);
485  ParallelFor(bx_zlo, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
486  velz_arr(i,j,k) = velz_arr(i,j,klo);
487  });
488  }
489  if (gbx.bigEnd(2) > khi) {
490  Box bx_zhi(gbx); bx_zhi.setSmall(2,khi+1);
491  ParallelFor(bx_zhi, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
492  velz_arr(i,j,k) = velz_arr(i,j,khi);
493  });
494  }
495  }
496  } // MFIter
497  } // OpenMP
498 } // operator()
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
@ yvel_bc
Definition: ERF_IndexDefines.H:139
@ xvel_bc
Definition: ERF_IndexDefines.H:138
@ xvel
Definition: ERF_IndexDefines.H:232
@ yvel
Definition: ERF_IndexDefines.H:233
Here is the call graph for this function:

Member Data Documentation

◆ m_bc_extdir_vals

amrex::Array<amrex::Array<amrex::Real, AMREX_SPACEDIM*2>,AMREX_SPACEDIM+NBCVAR_max> ERFPhysBCFunct_w::m_bc_extdir_vals
private

◆ m_bc_neumann_vals

amrex::Array<amrex::Array<amrex::Real, AMREX_SPACEDIM*2>,AMREX_SPACEDIM+NBCVAR_max> ERFPhysBCFunct_w::m_bc_neumann_vals
private

◆ m_domain_bcs_type

amrex::Vector<amrex::BCRec> ERFPhysBCFunct_w::m_domain_bcs_type
private

◆ m_domain_bcs_type_d

amrex::Gpu::DeviceVector<amrex::BCRec> ERFPhysBCFunct_w::m_domain_bcs_type_d
private

◆ m_geom

amrex::Geometry ERFPhysBCFunct_w::m_geom
private

◆ m_lev

int ERFPhysBCFunct_w::m_lev
private

◆ m_mapfac_u

amrex::MultiFab* ERFPhysBCFunct_w::m_mapfac_u
private

Referenced by ERFPhysBCFunct_w().

◆ m_mapfac_v

amrex::MultiFab* ERFPhysBCFunct_w::m_mapfac_v
private

Referenced by ERFPhysBCFunct_w().

◆ m_terrain_type

TerrainType ERFPhysBCFunct_w::m_terrain_type
private

◆ m_use_real_bcs

bool ERFPhysBCFunct_w::m_use_real_bcs
private

◆ m_w_bc_data

amrex::Real* ERFPhysBCFunct_w::m_w_bc_data
private

◆ m_z_phys_nd

amrex::MultiFab* ERFPhysBCFunct_w::m_z_phys_nd
private

The documentation for this class was generated from the following files: