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

#include <ERF_PhysBCFunct.H>

Collaboration diagram for ERFPhysBCFunct_base:

Public Member Functions

 ERFPhysBCFunct_base (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, std::unique_ptr< amrex::MultiFab > &z_phys_nd, bool moving_terrain, bool use_terrain, amrex::Real rdOcp, amrex::Real gravity)
 
 ~ERFPhysBCFunct_base ()
 
void operator() (amrex::MultiFab &mf, int icomp, int ncomp, amrex::IntVect const &nghost)
 
void impose_lateral_basestate_bcs (const amrex::Array4< amrex::Real > &dest_arr, const amrex::Array4< amrex::Real const > &z_nd, const amrex::Box &bx, const amrex::Box &domain, int ncomp, const amrex::IntVect &nghost)
 
void impose_vertical_basestate_bcs (const amrex::Array4< amrex::Real > &dest_arr, const amrex::Array4< amrex::Real const > &z_nd, const amrex::Box &bx, const amrex::Box &domain, int ncomp, const amrex::IntVect &nghost)
 

Private Attributes

int m_lev
 
amrex::Geometry m_geom
 
bool m_moving_terrain
 
bool m_use_terrain
 
amrex::Real m_rdOcp
 
amrex::Real m_gravity
 
amrex::Vector< amrex::BCRec > m_domain_bcs_type
 
amrex::Gpu::DeviceVector< amrex::BCRec > m_domain_bcs_type_d
 
amrex::MultiFab * m_z_phys_nd
 

Constructor & Destructor Documentation

◆ ERFPhysBCFunct_base()

ERFPhysBCFunct_base::ERFPhysBCFunct_base ( 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,
std::unique_ptr< amrex::MultiFab > &  z_phys_nd,
bool  moving_terrain,
bool  use_terrain,
amrex::Real  rdOcp,
amrex::Real  gravity 
)
inline

Construct the base-state 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]z_phys_ndnodal physical height MultiFab
[in]moving_terrainwhether moving terrain is active
[in]use_terrainwhether the mesh is terrain-fitted, so that the cell-centered height of a lateral ghost cell differs from that of the cell it copies from
[in]rdOcpratio of R_d to c_p, used to close the EOS in the ghost cells
[in]gravitymagnitude of gravity, used to transfer the base state in height
648  : m_lev(lev), m_geom(geom),
649  m_moving_terrain(moving_terrain),
651  m_rdOcp(rdOcp),
652  m_gravity(gravity),
653  m_domain_bcs_type(domain_bcs_type),
654  m_domain_bcs_type_d(domain_bcs_type_d),
655  m_z_phys_nd(z_phys_nd.get())
656  {}
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:128
const bool use_terrain
Definition: ERF_InitCustomPert_SLM.H:19
amrex::Gpu::DeviceVector< amrex::BCRec > m_domain_bcs_type_d
Definition: ERF_PhysBCFunct.H:711
amrex::Real m_rdOcp
Definition: ERF_PhysBCFunct.H:708
bool m_use_terrain
Definition: ERF_PhysBCFunct.H:707
int m_lev
Definition: ERF_PhysBCFunct.H:704
amrex::MultiFab * m_z_phys_nd
Definition: ERF_PhysBCFunct.H:712
amrex::Geometry m_geom
Definition: ERF_PhysBCFunct.H:705
bool m_moving_terrain
Definition: ERF_PhysBCFunct.H:706
amrex::Real m_gravity
Definition: ERF_PhysBCFunct.H:709
amrex::Vector< amrex::BCRec > m_domain_bcs_type
Definition: ERF_PhysBCFunct.H:710

◆ ~ERFPhysBCFunct_base()

ERFPhysBCFunct_base::~ERFPhysBCFunct_base ( )
inline

Destroy the base-state physical boundary-condition functor.

661 {}

Member Function Documentation

◆ impose_lateral_basestate_bcs()

void ERFPhysBCFunct_base::impose_lateral_basestate_bcs ( const amrex::Array4< amrex::Real > &  dest_arr,
const amrex::Array4< amrex::Real const > &  z_nd,
const amrex::Box &  bx,
const amrex::Box &  domain,
int  ncomp,
const amrex::IntVect &  nghost 
)

Impose lateral boundary conditions on base-state variables.

Parameters
[in,out]dest_arrbase-state data to be filled
[in]z_ndnodal physical height
[in]bxbox holding data to be filled
[in]domainsimulation domain
[in]ncompnumber of components
[in]nghostnumber of ghost cells to be filled

Impose lateral boundary conditions on the base state

Parameters
[in,out]dest_arrcell-centered data to be filled
[in]z_ndnodal physical height
[in]bxbox holding data to be filled
[in]domainsimulation domain
[in]ncompnumber of base-state components to fill
[in]nghostnumber of ghost cells in each coordinate direction
24 {
25  BL_PROFILE_VAR("impose_lateral_base_bcs()",impose_lateral_base_bcs);
26  //
27  // Note that the "bx" that comes in here has already been grown in the lateral directions
28  // but not in the vertical
29  //
30 
31  const int* bxlo = bx.loVect();
32  const int* bxhi = bx.hiVect();
33 
34  const int* dlo = domain.loVect();
35  const int* dhi = domain.hiVect();
36 
37  const auto& dom_lo = lbound(domain);
38  const auto& dom_hi = ubound(domain);
39 
40  // xlo: ori = 0
41  // ylo: ori = 1
42  // zlo: ori = 2
43  // xhi: ori = 3
44  // yhi: ori = 4
45  // zhi: ori = 5
46 
47  // Based on BCRec for the domain, we need to make BCRec for this Box
48  // 0 is used as starting index for bcrs
49  Vector<BCRec> bcrs(ncomp);
50 
51  int bc_comp = BaseBCVars::rho0_bc_comp;
52 
53  // The base state takes Rho's BC type, but a Dirichlet-type density (ext_dir,
54  // ext_dir_upwind, ext_dir_ingested or ext_dir_prim on an inflow face, or a wall's
55  // density value or gradient) means nothing for the hydrostatic column r0/p0/pi0/th0/qv0,
56  // and the passes below have no branch for those types. Extrapolate the column on every
57  // non-periodic lateral face that does not reflect it or extrapolate it to higher order.
58  auto base_bc_type = [] (int t) {
62  };
63 
64  for (int nc = 0; nc < ncomp; nc++)
65  {
66  for (int dir = 0; dir < AMREX_SPACEDIM; dir++)
67  {
68  int lo_t = m_domain_bcs_type[bc_comp].lo(dir);
69  int hi_t = m_domain_bcs_type[bc_comp].hi(dir);
70  if (dir < 2) { lo_t = base_bc_type(lo_t); hi_t = base_bc_type(hi_t); }
71  bcrs[nc].setLo(dir, ( bxlo[dir]<=dlo[dir] ? lo_t : BCType::int_dir ));
72  bcrs[nc].setHi(dir, ( bxhi[dir]>=dhi[dir] ? hi_t : BCType::int_dir ));
73  }
74  }
75 
76  Gpu::DeviceVector<BCRec> bcrs_d(ncomp);
77  Gpu::copyAsync(Gpu::hostToDevice, bcrs.begin(), bcrs.end(), bcrs_d.begin());
78  const BCRec* bc_ptr = bcrs_d.data();
79 
80  GeometryData const& geomdata = m_geom.data();
81  bool is_periodic_in_x = geomdata.isPeriodic(0);
82  bool is_periodic_in_y = geomdata.isPeriodic(1);
83 
84  // Do ghost cells in x-direction but not reaching out in y
85  // The corners we miss here will be covered in the y-loop below or by periodicity
86  if (!is_periodic_in_x)
87  {
88  // Populate ghost cells on lo-x and hi-x domain boundaries
89  Box bx_xlo(bx); bx_xlo.setBig (0,dom_lo.x-1);
90  Box bx_xhi(bx); bx_xhi.setSmall(0,dom_hi.x+1);
91 
93  bx_xlo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
94  {
95  int dest_comp = n;
96  int l_bc_type = bc_ptr[n].lo(0);
97  int iflip = 2*dom_lo.x - 1 - i;
98  if (l_bc_type == ERFBCType::foextrap) {
99  dest_arr(i,j,k,dest_comp) = dest_arr(dom_lo.x,j,k,dest_comp);
100  } else if (l_bc_type == ERFBCType::open) {
101  dest_arr(i,j,k,dest_comp) = dest_arr(dom_lo.x,j,k,dest_comp);
102  } else if (l_bc_type == ERFBCType::reflect_even) {
103  dest_arr(i,j,k,dest_comp) = dest_arr(iflip,j,k,dest_comp);
104  }
105  },
106  bx_xhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
107  {
108  int dest_comp = n;
109  int h_bc_type = bc_ptr[n].hi(0);
110  int iflip = 2*dom_hi.x + 1 - i;
111  if (h_bc_type == ERFBCType::foextrap) {
112  dest_arr(i,j,k,dest_comp) = dest_arr(dom_hi.x,j,k,dest_comp);
113  } else if (h_bc_type == ERFBCType::open) {
114  dest_arr(i,j,k,dest_comp) = dest_arr(dom_hi.x,j,k,dest_comp);
115  } else if (h_bc_type == ERFBCType::reflect_even) {
116  dest_arr(i,j,k,dest_comp) = dest_arr(iflip,j,k,dest_comp);
117  }
118  }
119  );
120  }
121 
122  if (!is_periodic_in_y)
123  {
124  // Populate ghost cells on lo-y and hi-y domain boundaries
125  Box bx_ylo(bx); bx_ylo.setBig (1,dom_lo.y-1);
126  Box bx_yhi(bx); bx_yhi.setSmall(1,dom_hi.y+1);
127  if (bx_ylo.smallEnd(2) != domain.smallEnd(2)) bx_ylo.growLo(2,nghost[2]);
128  if (bx_ylo.bigEnd(2) != domain.bigEnd(2)) bx_ylo.growHi(2,nghost[2]);
129  if (bx_yhi.smallEnd(2) != domain.smallEnd(2)) bx_yhi.growLo(2,nghost[2]);
130  if (bx_yhi.bigEnd(2) != domain.bigEnd(2)) bx_yhi.growHi(2,nghost[2]);
131  ParallelFor(
132  bx_ylo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
133  {
134  int dest_comp = n;
135  int l_bc_type = bc_ptr[n].lo(1);
136  int jflip = 2*dom_lo.y - 1 - j;
137  if (l_bc_type == ERFBCType::foextrap) {
138  dest_arr(i,j,k,dest_comp) = dest_arr(i,dom_lo.y,k,dest_comp);
139  } else if (l_bc_type == ERFBCType::open) {
140  dest_arr(i,j,k,dest_comp) = dest_arr(i,dom_lo.y,k,dest_comp);
141  } else if (l_bc_type == ERFBCType::reflect_even) {
142  dest_arr(i,j,k,dest_comp) = dest_arr(i,jflip,k,dest_comp);
143  }
144 
145  },
146  bx_yhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
147  {
148  int dest_comp = n;
149  int h_bc_type = bc_ptr[n].hi(1);
150  int jflip = 2*dom_hi.y + 1 - j;
151  if (h_bc_type == ERFBCType::foextrap) {
152  dest_arr(i,j,k,dest_comp) = dest_arr(i,dom_hi.y,k,dest_comp);
153  } else if (h_bc_type == ERFBCType::open) {
154  dest_arr(i,j,k,dest_comp) = dest_arr(i,dom_hi.y,k,dest_comp);
155  } else if (h_bc_type == ERFBCType::reflect_even) {
156  dest_arr(i,j,k,dest_comp) = dest_arr(i,jflip,k,dest_comp);
157  }
158  }
159  );
160  }
161 
162  // Next do ghost cells in x-direction but not reaching out in y
163  // The corners we miss here will be covered in the y-loop below or by periodicity
164  if (!is_periodic_in_x)
165  {
166  // Populate ghost cells on lo-x and hi-x domain boundaries
167  Box bx_xlo(bx); bx_xlo.setBig (0,dom_lo.x-1);
168  Box bx_xhi(bx); bx_xhi.setSmall(0,dom_hi.x+1);
169  if (bx_xlo.smallEnd(2) != domain.smallEnd(2)) bx_xlo.growLo(2,nghost[2]);
170  if (bx_xlo.bigEnd(2) != domain.bigEnd(2)) bx_xlo.growHi(2,nghost[2]);
171  if (bx_xhi.smallEnd(2) != domain.smallEnd(2)) bx_xhi.growLo(2,nghost[2]);
172  if (bx_xhi.bigEnd(2) != domain.bigEnd(2)) bx_xhi.growHi(2,nghost[2]);
173  ParallelFor(
174  bx_xlo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
175  {
176  int dest_comp = n;
177  int l_bc_type = bc_ptr[n].lo(0);
178  int iflip = 2*dom_lo.x - 1 - i;
179  if (l_bc_type == ERFBCType::foextrap) {
180  dest_arr(i,j,k,dest_comp) = dest_arr(dom_lo.x,j,k,dest_comp);
181  } else if (l_bc_type == ERFBCType::open) {
182  dest_arr(i,j,k,dest_comp) = dest_arr(dom_lo.x,j,k,dest_comp);
183  } else if (l_bc_type == ERFBCType::reflect_even) {
184  dest_arr(i,j,k,dest_comp) = dest_arr(iflip,j,k,dest_comp);
185  } else if (l_bc_type == ERFBCType::reflect_odd) {
186  dest_arr(i,j,k,dest_comp) = -dest_arr(iflip,j,k,dest_comp);
187  } else if (l_bc_type == ERFBCType::hoextrap) {
188  Real delta_i = static_cast<Real>(dom_lo.x - i);
189  dest_arr(i,j,k,dest_comp) = (one + delta_i)*dest_arr(dom_lo.x,j,k,dest_comp) - delta_i*dest_arr(dom_lo.x+1,j,k,dest_comp) ;
190  }
191  },
192  bx_xhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
193  {
194  int dest_comp = n;
195  int h_bc_type = bc_ptr[n].hi(0);
196  int iflip = 2*dom_hi.x + 1 - i;
197  if (h_bc_type == ERFBCType::foextrap) {
198  dest_arr(i,j,k,dest_comp) = dest_arr(dom_hi.x,j,k,dest_comp);
199  } else if (h_bc_type == ERFBCType::open) {
200  dest_arr(i,j,k,dest_comp) = dest_arr(dom_hi.x,j,k,dest_comp);
201  } else if (h_bc_type == ERFBCType::reflect_even) {
202  dest_arr(i,j,k,dest_comp) = dest_arr(iflip,j,k,dest_comp);
203  } else if (h_bc_type == ERFBCType::reflect_odd) {
204  dest_arr(i,j,k,dest_comp) = -dest_arr(iflip,j,k,dest_comp);
205  } else if (h_bc_type == ERFBCType::hoextrap) {
206  Real delta_i = static_cast<Real>(i - dom_hi.x);
207  dest_arr(i,j,k,dest_comp) = (one + delta_i)*dest_arr(dom_hi.x,j,k,dest_comp) - delta_i*dest_arr(dom_hi.x-1,j,k,dest_comp) ;
208  }
209  }
210  );
211  }
212 
213  if (!is_periodic_in_y)
214  {
215  // Populate ghost cells on lo-y and hi-y domain boundaries
216  Box bx_ylo(bx); bx_ylo.setBig (1,dom_lo.y-1);
217  Box bx_yhi(bx); bx_yhi.setSmall(1,dom_hi.y+1);
218  if (bx_ylo.smallEnd(2) != domain.smallEnd(2)) bx_ylo.growLo(2,nghost[2]);
219  if (bx_ylo.bigEnd(2) != domain.bigEnd(2)) bx_ylo.growHi(2,nghost[2]);
220  if (bx_yhi.smallEnd(2) != domain.smallEnd(2)) bx_yhi.growLo(2,nghost[2]);
221  if (bx_yhi.bigEnd(2) != domain.bigEnd(2)) bx_yhi.growHi(2,nghost[2]);
222  ParallelFor(
223  bx_ylo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
224  {
225  int dest_comp = n;
226  int l_bc_type = bc_ptr[n].lo(1);
227  int jflip = 2*dom_lo.y - 1 - j;
228  if (l_bc_type == ERFBCType::foextrap) {
229  dest_arr(i,j,k,dest_comp) = dest_arr(i,dom_lo.y,k,dest_comp);
230  } else if (l_bc_type == ERFBCType::open) {
231  dest_arr(i,j,k,dest_comp) = dest_arr(i,dom_lo.y,k,dest_comp);
232  } else if (l_bc_type == ERFBCType::reflect_even) {
233  dest_arr(i,j,k,dest_comp) = dest_arr(i,jflip,k,dest_comp);
234  } else if (l_bc_type == ERFBCType::reflect_odd) {
235  dest_arr(i,j,k,dest_comp) = -dest_arr(i,jflip,k,dest_comp);
236  } else if (l_bc_type == ERFBCType::hoextrap) {
237  Real delta_j = static_cast<Real>(dom_lo.y - j);
238  dest_arr(i,j,k,dest_comp) = (one + delta_j)*dest_arr(i,dom_lo.y,k,dest_comp) - delta_j*dest_arr(i,dom_lo.y+1,k,dest_comp) ;
239  }
240 
241  },
242  bx_yhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
243  {
244  int dest_comp = n;
245  int h_bc_type = bc_ptr[n].hi(1);
246  int jflip = 2*dom_hi.y + 1 - j;
247  if (h_bc_type == ERFBCType::foextrap) {
248  dest_arr(i,j,k,dest_comp) = dest_arr(i,dom_hi.y,k,dest_comp);
249  } else if (h_bc_type == ERFBCType::open) {
250  dest_arr(i,j,k,dest_comp) = dest_arr(i,dom_hi.y,k,dest_comp);
251  } else if (h_bc_type == ERFBCType::reflect_even) {
252  dest_arr(i,j,k,dest_comp) = dest_arr(i,jflip,k,dest_comp);
253  } else if (h_bc_type == ERFBCType::reflect_odd) {
254  dest_arr(i,j,k,dest_comp) = -dest_arr(i,jflip,k,dest_comp);
255  } else if (h_bc_type == ERFBCType::hoextrap) {
256  Real delta_j = static_cast<Real>(j - dom_hi.y);
257  dest_arr(i,j,k,dest_comp) = (one + delta_j)*dest_arr(i,dom_hi.y,k,dest_comp) - delta_j*dest_arr(i,dom_hi.y-1,k,dest_comp);
258  }
259  }
260  );
261  }
262 
263  //
264  // The copies above give a lateral ghost cell the base state of the cell it copies from,
265  // which on a terrain-fitted mesh sits at a different height: the nodal mesh is extrapolated
266  // past the domain, so z_cc of a ghost cell differs from z_cc of that cell whenever the
267  // terrain has a slope at the boundary. The base state left there is then neither the
268  // hydrostatic profile at the ghost cell's own height nor in hydrostatic balance along the
269  // ghost column, while detJ and the metric terms in that same column are height-consistent.
270  //
271  // Here we rebuild the base state of those cells at the height the mesh says the cell is at:
272  // p_0 is carried across the height offset by the hydrostatic relation, and rho_0 and pi_0
273  // follow from the equation of state so that it holds exactly in the ghost cell.
274  //
275  // This is done only where the boundary is foextrap or open: the reflecting and hoextrap
276  // conditions above are not copies of a single cell and are left alone. It reduces to the
277  // identity, bit for bit, wherever the two heights agree -- every constant-dz mesh, and any
278  // terrain that is flat at the boundary -- so it changes nothing there.
279  //
280  if (m_use_terrain && z_nd && ncomp == BaseState::num_comps)
281  {
282  auto is_ext_bc = [] (int bc_type) {
283  return (bc_type == ERFBCType::foextrap || bc_type == ERFBCType::open);
284  };
285 
286  const bool xlo_ext = !is_periodic_in_x && is_ext_bc(bcrs[0].lo(0));
287  const bool xhi_ext = !is_periodic_in_x && is_ext_bc(bcrs[0].hi(0));
288  const bool ylo_ext = !is_periodic_in_y && is_ext_bc(bcrs[0].lo(1));
289  const bool yhi_ext = !is_periodic_in_y && is_ext_bc(bcrs[0].hi(1));
290 
291  if (xlo_ext || xhi_ext || ylo_ext || yhi_ext)
292  {
293  //
294  // "bx" is grown laterally but not vertically, so we grow it in z the same way the
295  // loops above do, then trim it to the domain: the ghost cells above and below the
296  // domain are filled after us, by impose_vertical_basestate_bcs.
297  //
298  Box gbx(bx);
299  if (gbx.smallEnd(2) != domain.smallEnd(2)) gbx.growLo(2,nghost[2]);
300  if (gbx.bigEnd(2) != domain.bigEnd(2)) gbx.growHi(2,nghost[2]);
301  gbx.setSmall(2, amrex::max(gbx.smallEnd(2), dom_lo.z));
302  gbx.setBig (2, amrex::min(gbx.bigEnd(2) , dom_hi.z));
303 
304  const Real l_rdOcp = m_rdOcp;
305  const Real l_gravity = m_gravity;
306 
307  ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
308  {
309  //
310  // The cell this one was copied from: the nearest cell that is inside the domain
311  // laterally, which is just what the x-pass followed by the y-pass above leaves
312  // here, corners included.
313  //
314  const bool out_xlo = (i < dom_lo.x);
315  const bool out_xhi = (i > dom_hi.x);
316  const bool out_ylo = (j < dom_lo.y);
317  const bool out_yhi = (j > dom_hi.y);
318 
319  if (!(out_xlo || out_xhi || out_ylo || out_yhi)) { return; }
320 
321  // Leave the cell alone unless every boundary it lies outside of is foextrap/open
322  if (out_xlo && !xlo_ext) { return; }
323  if (out_xhi && !xhi_ext) { return; }
324  if (out_ylo && !ylo_ext) { return; }
325  if (out_yhi && !yhi_ext) { return; }
326 
327  const int ir = amrex::min(amrex::max(i,dom_lo.x),dom_hi.x);
328  const int jr = amrex::min(amrex::max(j,dom_lo.y),dom_hi.y);
329 
330  auto zcc = [=] (int ii, int jj, int kk) {
331  return Real(0.125) * ( z_nd(ii,jj ,kk ) + z_nd(ii+1,jj ,kk )
332  + z_nd(ii,jj+1,kk ) + z_nd(ii+1,jj+1,kk )
333  + z_nd(ii,jj ,kk+1) + z_nd(ii+1,jj ,kk+1)
334  + z_nd(ii,jj+1,kk+1) + z_nd(ii+1,jj+1,kk+1) );
335  };
336 
337  const Real dz_offset = zcc(i,j,k) - zcc(ir,jr,k);
338 
339  // Same height as the cell we copied from: the copy is already right
340  if (dz_offset == Real(0.0)) { return; }
341 
342  const Real r0_ref = dest_arr(ir,jr,k,BaseState::r0_comp );
343  const Real p0_ref = dest_arr(ir,jr,k,BaseState::p0_comp );
344  const Real th0_ref = dest_arr(ir,jr,k,BaseState::th0_comp);
345  const Real qv0_ref = dest_arr(ir,jr,k,BaseState::qv0_comp);
346 
347  //
348  // A base state that has not been built yet -- this is called on a MultiFab that
349  // was only just allocated and zeroed -- has nothing to transfer, and the scale
350  // height below would divide by zero. Leave the copy alone.
351  //
352  if (!(p0_ref > Real(0.0)) || !(r0_ref > Real(0.0)) || !(th0_ref > Real(0.0))) { return; }
353 
354  //
355  // p_0 across the height offset, using the scale height of the cell we copied
356  // from: p_0 * exp(-g dz / (R_d T_v)) with R_d T_v = p_0 / rho_0.
357  //
358  const Real p0_new = p0_ref * std::exp(-l_gravity * dz_offset * r0_ref / p0_ref);
359 
360  //
361  // theta_0 and qv_0 carry over unchanged. Reconstructing them at the height of
362  // this cell would need the profile of the column above and below k, and the
363  // cells we could read there are the ones this box happens to hold, so the
364  // stencil -- and with it the answer -- would depend on where the grids are
365  // split in z. Holding them fixed leaves an error of dtheta_0/dz * dz, which
366  // for the offsets a terrain-fitted mesh produces is a few thousandths of a
367  // kelvin, against the several pascals in p_0 that the transfer above removes.
368  //
369  dest_arr(i,j,k,BaseState::p0_comp ) = p0_new;
370  dest_arr(i,j,k,BaseState::th0_comp) = th0_ref;
371  dest_arr(i,j,k,BaseState::qv0_comp) = qv0_ref;
372  dest_arr(i,j,k,BaseState::pi0_comp) = getExnergivenP(p0_new, l_rdOcp);
373  dest_arr(i,j,k,BaseState::r0_comp ) = getRhogivenThetaPress(th0_ref, p0_new,
374  l_rdOcp, qv0_ref);
375  });
376  }
377  }
378 
379  Gpu::streamSynchronize();
380 }
GpuArray< int, AMREX_SPACEDIM > dhi
Definition: ERF_ActuatorSpreading.cpp:132
GpuArray< int, AMREX_SPACEDIM > dlo
Definition: ERF_ActuatorSpreading.cpp:132
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getRhogivenThetaPress(const amrex::Real th, const amrex::Real p, const amrex::Real rdOcp, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getExnergivenP(const amrex::Real P, const amrex::Real rdOcp)
Definition: ERF_EOS.H:141
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
@ rho0_bc_comp
Definition: ERF_IndexDefines.H:168
@ num_comps
Definition: ERF_IndexDefines.H:114
@ qv0_comp
Definition: ERF_IndexDefines.H:113
@ pi0_comp
Definition: ERF_IndexDefines.H:111
@ p0_comp
Definition: ERF_IndexDefines.H:110
@ th0_comp
Definition: ERF_IndexDefines.H:112
@ r0_comp
Definition: ERF_IndexDefines.H:109
@ 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
@ int_dir
Definition: ERF_IndexDefines.H:314
@ reflect_even
Definition: ERF_IndexDefines.H:315
@ nc
Definition: ERF_Morrison.H:47
@ t
Definition: ERF_WSM6.H:295
Here is the call graph for this function:

◆ impose_vertical_basestate_bcs()

void ERFPhysBCFunct_base::impose_vertical_basestate_bcs ( const amrex::Array4< amrex::Real > &  dest_arr,
const amrex::Array4< amrex::Real const > &  z_nd,
const amrex::Box &  bx,
const amrex::Box &  domain,
int  ncomp,
const amrex::IntVect &  nghost 
)

Impose vertical boundary conditions on base-state variables.

Parameters
[in,out]dest_arrbase-state data to be filled
[in]z_ndnodal physical height
[in]bxbox holding data to be filled
[in]domainsimulation domain
[in]ncompnumber of components
[in]nghostnumber of ghost cells to be filled

Impose vertical boundary conditions on the base state

Parameters
[in,out]dest_arrcell-centered base-state data to be filled
[in]z_phys_ndheight coordinate at nodes, unused for base-state fills
[in]bxbox holding data to be filled
[in]domainsimulation domain
[in]ncompnumber of base-state components to fill
[in]nghostnumber of ghost cells, unused for base-state fills
398 {
399  BL_PROFILE_VAR("impose_vertical_base_bcs()",impose_vertical_base_bcs);
400 
401  const auto& dom_lo = lbound(domain);
402  const auto& dom_hi = ubound(domain);
403 
404  Box bx_zlo(bx); bx_zlo.setBig(2,dom_lo.z-1);
405  Box bx_zhi(bx); bx_zhi.setSmall(2,dom_hi.z+1);
406  ParallelFor(
407  bx_zlo, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
408  {
409  dest_arr(i,j,k,n) = dest_arr(i,j,dom_lo.z,n);
410  },
411  bx_zhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n)
412  {
413  dest_arr(i,j,k,n) = dest_arr(i,j,dom_hi.z,n);
414  }
415  );
416 }
Here is the call graph for this function:

◆ operator()()

void ERFPhysBCFunct_base::operator() ( amrex::MultiFab &  mf,
int  icomp,
int  ncomp,
amrex::IntVect const &  nghost 
)

Impose physical boundary conditions at domain boundaries

Parameters
[in,out]mfbase-state MultiFab to be filled
[in]icompstarting component for base-state variables
[in]ncompnumber of components for base-state variables
[in]nghostnumber of ghost cells to be filled

Impose physical boundary conditions on the base state.

Parameters
[in,out]mfbase-state MultiFab to be filled
[in]icompstarting component, unused here
[in]ncompnumber of components
[in]nghostnumber of ghost cells to be filled
509 {
510  BL_PROFILE("ERFPhysBCFunct_base::()");
511 
512  if (m_geom.isAllPeriodic()) return;
513 
514  const auto& domain = m_geom.Domain();
515 
516  // Create a grown domain box containing valid + periodic cells
517  Box gdomain = domain;
518  for (int i = 0; i < AMREX_SPACEDIM; ++i) {
519  if (m_geom.isPeriodic(i)) {
520  gdomain.grow(i, nghost[i]);
521  }
522  }
523 
524  //
525  // We fill all of the interior and periodic ghost cells first, so we can fill
526  // those directly inside the lateral and vertical calls.
527  //
528  mf.FillBoundary(m_geom.periodicity());
529 
530 #ifdef AMREX_USE_OMP
531 #pragma omp parallel if (Gpu::notInLaunchRegion())
532 #endif
533  {
534  for (MFIter mfi(mf,false); mfi.isValid(); ++mfi)
535  {
536  //
537  // This is the box we pass to the different routines
538  // NOTE -- this is the full grid box NOT the tile box
539  //
540  Box bx = mfi.validbox();
541 
542  //
543  // These are the boxes we use to test on relative to the domain
544  //
545  Box cbx1 = bx; cbx1.grow(IntVect(nghost[0],nghost[1],0));
546  Box cbx2 = bx; cbx2.grow(nghost);
547 
548  Array4<const Real> z_nd_arr;
549 
550  if (m_z_phys_nd) {
551  z_nd_arr = m_z_phys_nd->const_array(mfi);
552  }
553 
554  if (!gdomain.contains(cbx2)) {
555  const Array4<Real> base_arr = mf.array(mfi);
556 
557  impose_lateral_basestate_bcs(base_arr,z_nd_arr,cbx1,domain,ncomp,nghost);
558  if (!m_moving_terrain) { // TODO: I don't know why the CI test fails if this is called
559  impose_vertical_basestate_bcs(base_arr,z_nd_arr,cbx2,domain,ncomp,nghost);
560  }
561  }
562 
563  } // MFIter
564  } // OpenMP
565 } // operator()
void impose_vertical_basestate_bcs(const amrex::Array4< amrex::Real > &dest_arr, const amrex::Array4< amrex::Real const > &z_nd, const amrex::Box &bx, const amrex::Box &domain, int ncomp, const amrex::IntVect &nghost)
Definition: ERF_BoundaryConditionsBaseState.cpp:392
void impose_lateral_basestate_bcs(const amrex::Array4< amrex::Real > &dest_arr, const amrex::Array4< amrex::Real const > &z_nd, const amrex::Box &bx, const amrex::Box &domain, int ncomp, const amrex::IntVect &nghost)
Definition: ERF_BoundaryConditionsBaseState.cpp:20

Member Data Documentation

◆ m_domain_bcs_type

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

◆ m_domain_bcs_type_d

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

◆ m_geom

amrex::Geometry ERFPhysBCFunct_base::m_geom
private

◆ m_gravity

amrex::Real ERFPhysBCFunct_base::m_gravity
private

◆ m_lev

int ERFPhysBCFunct_base::m_lev
private

◆ m_moving_terrain

bool ERFPhysBCFunct_base::m_moving_terrain
private

◆ m_rdOcp

amrex::Real ERFPhysBCFunct_base::m_rdOcp
private

◆ m_use_terrain

bool ERFPhysBCFunct_base::m_use_terrain
private

◆ m_z_phys_nd

amrex::MultiFab* ERFPhysBCFunct_base::m_z_phys_nd
private

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