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

Functions

void ApplySpongeZoneBCsForCC (const SpongeChoice &spongeChoice, const Geometry geom, const Box &bx, const Array4< Real > &cell_rhs, const Array4< const Real > &cell_data, const Array4< const Real > &r0, const Array4< const Real > &th0, const Array4< const Real > &qv0, const Array4< const Real > &z_phys_cc, int n_qstate)
 Apply sponge zone damping to cell-centered state variables. More...
 
void ApplySpongeZoneBCsForMom (const SpongeChoice &spongeChoice, const Geometry geom, const Box &tbx, const Box &tby, const Box &tbz, const Array4< Real > &rho_u_rhs, const Array4< Real > &rho_v_rhs, const Array4< Real > &rho_w_rhs, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Array4< const Real > &rho_w, const Array4< const Real > &r0, const Array4< const Real > &z_phys_nd, const Array4< const Real > &z_phys_cc)
 Apply sponge zone damping to momentum variables. More...
 

Function Documentation

◆ ApplySpongeZoneBCsForCC()

void ApplySpongeZoneBCsForCC ( const SpongeChoice &  spongeChoice,
const Geometry  geom,
const Box &  bx,
const Array4< Real > &  cell_rhs,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  r0,
const Array4< const Real > &  th0,
const Array4< const Real > &  qv0,
const Array4< const Real > &  z_phys_cc,
int  n_qstate 
)

Apply sponge zone damping to cell-centered state variables.

Parameters
[in]spongeChoiceSponge configuration.
[in]geomDomain geometry.
[in]bxBox of indices to process.
[in,out]cell_rhsRight-hand side for state variables.
[in]cell_dataCurrent state data.
[in]r0Base state density.
[in]th0Base state potential temperature.
[in]qv0Base state moisture.
[in]z_phys_ccCell-centered physical height.
[in]n_qstateNumber of additional scalar state variables.
31 {
32  // Domain cell size and real bounds
33  auto dx = geom.CellSizeArray();
34  auto ProbHiArr = geom.ProbHiArray();
35  auto ProbLoArr = geom.ProbLoArray();
36 
37  const Real sponge_strength = spongeChoice.sponge_strength;
38  const int use_xlo_sponge_damping = spongeChoice.use_xlo_sponge_damping;
39  const int use_xhi_sponge_damping = spongeChoice.use_xhi_sponge_damping;
40  const int use_ylo_sponge_damping = spongeChoice.use_ylo_sponge_damping;
41  const int use_yhi_sponge_damping = spongeChoice.use_yhi_sponge_damping;
42  const int use_zlo_sponge_damping = spongeChoice.use_zlo_sponge_damping;
43  const int use_zhi_sponge_damping = spongeChoice.use_zhi_sponge_damping;
44  if (!use_xlo_sponge_damping &&
45  !use_xhi_sponge_damping &&
46  !use_ylo_sponge_damping &&
47  !use_yhi_sponge_damping &&
48  !use_zlo_sponge_damping &&
49  !use_zhi_sponge_damping)
50  return;
51 
52  const Real xlo_sponge_end = spongeChoice.xlo_sponge_end;
53  const Real xhi_sponge_start = spongeChoice.xhi_sponge_start;
54  const Real ylo_sponge_end = spongeChoice.ylo_sponge_end;
55  const Real yhi_sponge_start = spongeChoice.yhi_sponge_start;
56  const Real zlo_sponge_end = spongeChoice.zlo_sponge_end;
57  const Real zhi_sponge_start = spongeChoice.zhi_sponge_start;
58 
59  const Real sponge_density_tmp = spongeChoice.sponge_density;
60  const Real sponge_rhotheta_tmp = spongeChoice.sponge_rhotheta;
61  const Real sponge_rhomoist_tmp = spongeChoice.sponge_rhomoist;
62  const bool use_base_density = (sponge_density_tmp < zero);
63  const bool use_base_rhotheta = (sponge_rhotheta_tmp < zero);
64  const bool use_base_rhomoist = (sponge_rhomoist_tmp < zero);
65 
66  // Domain valid box
67  const Box& domain = geom.Domain();
68  int domlo_x = domain.smallEnd(0);
69  int domhi_x = domain.bigEnd(0) + 1;
70  int domlo_y = domain.smallEnd(1);
71  int domhi_y = domain.bigEnd(1) + 1;
72 
73  if(use_xlo_sponge_damping)AMREX_ALWAYS_ASSERT(xlo_sponge_end > ProbLoArr[0]);
74  if(use_xhi_sponge_damping)AMREX_ALWAYS_ASSERT(xhi_sponge_start < ProbHiArr[0]);
75  if(use_ylo_sponge_damping)AMREX_ALWAYS_ASSERT(ylo_sponge_end > ProbLoArr[1]);
76  if(use_yhi_sponge_damping)AMREX_ALWAYS_ASSERT(yhi_sponge_start < ProbHiArr[1]);
77  if(use_zlo_sponge_damping)AMREX_ALWAYS_ASSERT(zlo_sponge_end > ProbLoArr[2]);
78  if(use_zhi_sponge_damping)AMREX_ALWAYS_ASSERT(zhi_sponge_start < ProbHiArr[2]);
79 
80  // Ramp lengths, computed here so that the kernels divide only by a valid length: the
81  // optimiser evaluates the guarded ramps of the sides that are switched off too, and the
82  // lengths of those sides (whose ends are never read from the inputs) can be zero
83  const Real L_xlo = use_xlo_sponge_damping ? (xlo_sponge_end - ProbLoArr[0]) : one;
84  const Real L_xhi = use_xhi_sponge_damping ? (ProbHiArr[0] - xhi_sponge_start) : one;
85  const Real L_ylo = use_ylo_sponge_damping ? (ylo_sponge_end - ProbLoArr[1]) : one;
86  const Real L_yhi = use_yhi_sponge_damping ? (ProbHiArr[1] - yhi_sponge_start) : one;
87  const Real L_zlo = use_zlo_sponge_damping ? (zlo_sponge_end - ProbLoArr[2]) : one;
88  const Real L_zhi = use_zhi_sponge_damping ? (ProbHiArr[2] - zhi_sponge_start) : one;
89 
90  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
91  {
92  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
93  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
94 
95  Real x = ProbLoArr[0] + (ii+myhalf) * dx[0];
96  Real y = ProbLoArr[1] + (jj+myhalf) * dx[1];
97  Real z = z_phys_cc(i,j,k);
98 
99  Real sponge_density = (use_base_density) ? r0(i,j,k) : sponge_density_tmp;
100  Real sponge_rhotheta = (use_base_rhotheta) ? r0(i,j,k)*th0(i,j,k) : sponge_rhotheta_tmp;
101  Real sponge_rhomoist = (use_base_rhomoist) ? r0(i,j,k)*qv0(i,j,k) : sponge_rhomoist_tmp;
102 
103  // x left sponge
104  if(use_xlo_sponge_damping){
105  if (x < xlo_sponge_end) {
106  Real xi = (xlo_sponge_end - x) / L_xlo;
107  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
108  cell_rhs(i, j, k, 1) -= sponge_strength * xi * xi * (cell_data(i, j, k, 1) - sponge_rhotheta);
109  if (n_qstate > 0) {
110  cell_rhs(i, j, k, RhoQ1_comp) -= sponge_strength * xi * xi * (cell_data(i, j, k, RhoQ1_comp) - sponge_rhomoist);
111  for (int n = RhoQ2_comp; n < RhoQ1_comp+n_qstate; ++n) {
112  cell_rhs(i, j, k, n) -= sponge_strength * xi * xi * cell_data(i, j, k, n);
113  }
114  }
115  }
116  }
117  // x right sponge
118  if(use_xhi_sponge_damping){
119  if (x > xhi_sponge_start) {
120  Real xi = (x - xhi_sponge_start) / L_xhi;
121  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
122  cell_rhs(i, j, k, 1) -= sponge_strength * xi * xi * (cell_data(i, j, k, 1) - sponge_rhotheta);
123  if (n_qstate > 0) {
124  cell_rhs(i, j, k, RhoQ1_comp) -= sponge_strength * xi * xi * (cell_data(i, j, k, RhoQ1_comp) - sponge_rhomoist);
125  for (int n = RhoQ2_comp; n < RhoQ1_comp+n_qstate; ++n) {
126  cell_rhs(i, j, k, n) -= sponge_strength * xi * xi * cell_data(i, j, k, n);
127  }
128  }
129  }
130  }
131 
132  // y left sponge
133  if(use_ylo_sponge_damping){
134  if (y < ylo_sponge_end) {
135  Real xi = (ylo_sponge_end - y) / L_ylo;
136  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
137  cell_rhs(i, j, k, 1) -= sponge_strength * xi * xi * (cell_data(i, j, k, 1) - sponge_rhotheta);
138  if (n_qstate > 0) {
139  cell_rhs(i, j, k, RhoQ1_comp) -= sponge_strength * xi * xi * (cell_data(i, j, k, RhoQ1_comp) - sponge_rhomoist);
140  for (int n = RhoQ2_comp; n < RhoQ1_comp+n_qstate; ++n) {
141  cell_rhs(i, j, k, n) -= sponge_strength * xi * xi * cell_data(i, j, k, n);
142  }
143  }
144  }
145  }
146  // x right sponge
147  if(use_yhi_sponge_damping){
148  if (y > yhi_sponge_start) {
149  Real xi = (y - yhi_sponge_start) / L_yhi;
150  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
151  cell_rhs(i, j, k, 1) -= sponge_strength * xi * xi * (cell_data(i, j, k, 1) - sponge_rhotheta);
152  if (n_qstate > 0) {
153  cell_rhs(i, j, k, RhoQ1_comp) -= sponge_strength * xi * xi * (cell_data(i, j, k, RhoQ1_comp) - sponge_rhomoist);
154  for (int n = RhoQ2_comp; n < RhoQ1_comp+n_qstate; ++n) {
155  cell_rhs(i, j, k, n) -= sponge_strength * xi * xi * cell_data(i, j, k, n);
156  }
157  }
158  }
159  }
160 
161  // x left sponge
162  if(use_zlo_sponge_damping){
163  if (z < zlo_sponge_end) {
164  Real xi = (zlo_sponge_end - z) / L_zlo;
165  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
166  cell_rhs(i, j, k, 1) -= sponge_strength * xi * xi * (cell_data(i, j, k, 1) - sponge_rhotheta);
167  if (n_qstate > 0) {
168  cell_rhs(i, j, k, RhoQ1_comp) -= sponge_strength * xi * xi * (cell_data(i, j, k, RhoQ1_comp) - sponge_rhomoist);
169  for (int n = RhoQ2_comp; n < RhoQ1_comp+n_qstate; ++n) {
170  cell_rhs(i, j, k, n) -= sponge_strength * xi * xi * cell_data(i, j, k, n);
171  }
172  }
173  }
174  }
175  // x right sponge
176  if(use_zhi_sponge_damping){
177  if (z > zhi_sponge_start) {
178  Real xi = (z - zhi_sponge_start) / L_zhi;
179  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
180  cell_rhs(i, j, k, 1) -= sponge_strength * xi * xi * (cell_data(i, j, k, 1) - sponge_rhotheta);
181  if (n_qstate > 0) {
182  cell_rhs(i, j, k, RhoQ1_comp) -= sponge_strength * xi * xi * (cell_data(i, j, k, RhoQ1_comp) - sponge_rhomoist);
183  for (int n = RhoQ2_comp; n < RhoQ1_comp+n_qstate; ++n) {
184  cell_rhs(i, j, k, n) -= sponge_strength * xi * xi * cell_data(i, j, k, n);
185  }
186  }
187  }
188  }
189  });
190 }
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:67
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:66
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
amrex::Real Real
Definition: ERF_ShocInterface.H:19
real(kind=kind_phys), parameter, private r0
Definition: ERF_module_mp_wdm6.F90:75
amrex::Real zlo_sponge_end
Physical end location of the low-z sponge layer.
Definition: ERF_SpongeStruct.H:105
amrex::Real xlo_sponge_end
Physical end location of the low-x sponge layer.
Definition: ERF_SpongeStruct.H:103
bool use_zlo_sponge_damping
Whether sponge damping is applied at the low-z boundary.
Definition: ERF_SpongeStruct.H:94
amrex::Real ylo_sponge_end
Physical end location of the low-y sponge layer.
Definition: ERF_SpongeStruct.H:104
amrex::Real sponge_strength
Sponge damping strength.
Definition: ERF_SpongeStruct.H:97
amrex::Real sponge_rhotheta
Target rho-theta used by sponge damping.
Definition: ERF_SpongeStruct.H:107
amrex::Real yhi_sponge_start
Physical start location of the high-y sponge layer.
Definition: ERF_SpongeStruct.H:104
bool use_zhi_sponge_damping
Whether sponge damping is applied at the high-z boundary.
Definition: ERF_SpongeStruct.H:95
amrex::Real sponge_density
Target density used by sponge damping.
Definition: ERF_SpongeStruct.H:106
bool use_xlo_sponge_damping
Whether sponge damping is applied at the low-x boundary.
Definition: ERF_SpongeStruct.H:90
amrex::Real xhi_sponge_start
Physical start location of the high-x sponge layer.
Definition: ERF_SpongeStruct.H:103
bool use_xhi_sponge_damping
Whether sponge damping is applied at the high-x boundary.
Definition: ERF_SpongeStruct.H:91
amrex::Real sponge_rhomoist
Target moist density variable used by sponge damping.
Definition: ERF_SpongeStruct.H:108
bool use_yhi_sponge_damping
Whether sponge damping is applied at the high-y boundary.
Definition: ERF_SpongeStruct.H:93
bool use_ylo_sponge_damping
Whether sponge damping is applied at the low-y boundary.
Definition: ERF_SpongeStruct.H:92
amrex::Real zhi_sponge_start
Physical start location of the high-z sponge layer.
Definition: ERF_SpongeStruct.H:105

Referenced by make_sources().

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

◆ ApplySpongeZoneBCsForMom()

void ApplySpongeZoneBCsForMom ( const SpongeChoice &  spongeChoice,
const Geometry  geom,
const Box &  tbx,
const Box &  tby,
const Box &  tbz,
const Array4< Real > &  rho_u_rhs,
const Array4< Real > &  rho_v_rhs,
const Array4< Real > &  rho_w_rhs,
const Array4< const Real > &  rho_u,
const Array4< const Real > &  rho_v,
const Array4< const Real > &  rho_w,
const Array4< const Real > &  r0,
const Array4< const Real > &  z_phys_nd,
const Array4< const Real > &  z_phys_cc 
)

Apply sponge zone damping to momentum variables.

Parameters
[in]spongeChoiceSponge configuration.
[in]geomDomain geometry.
[in]tbxProcessing box for x-momentum.
[in]tbyProcessing box for y-momentum.
[in]tbzProcessing box for z-momentum.
[in,out]rho_u_rhsRight-hand side for x-momentum.
[in,out]rho_v_rhsRight-hand side for y-momentum.
[in,out]rho_w_rhsRight-hand side for z-momentum.
[in]rho_uCurrent x-momentum data.
[in]rho_vCurrent y-momentum data.
[in]rho_wCurrent z-momentum data.
[in]r0Base state density.
[in]z_phys_ndNode-centered physical height.
[in]z_phys_ccCell-centered physical height.
225 {
226  // Domain cell size and real bounds
227  auto dx = geom.CellSizeArray();
228  auto ProbHiArr = geom.ProbHiArray();
229  auto ProbLoArr = geom.ProbLoArray();
230 
231  const Real sponge_strength = spongeChoice.sponge_strength;
232  const int use_xlo_sponge_damping = spongeChoice.use_xlo_sponge_damping;
233  const int use_xhi_sponge_damping = spongeChoice.use_xhi_sponge_damping;
234  const int use_ylo_sponge_damping = spongeChoice.use_ylo_sponge_damping;
235  const int use_yhi_sponge_damping = spongeChoice.use_yhi_sponge_damping;
236  const int use_zlo_sponge_damping = spongeChoice.use_zlo_sponge_damping;
237  const int use_zhi_sponge_damping = spongeChoice.use_zhi_sponge_damping;
238  if (!use_xlo_sponge_damping &&
239  !use_xhi_sponge_damping &&
240  !use_ylo_sponge_damping &&
241  !use_yhi_sponge_damping &&
242  !use_zlo_sponge_damping &&
243  !use_zhi_sponge_damping)
244  return;
245 
246  const Real xlo_sponge_end = spongeChoice.xlo_sponge_end;
247  const Real xhi_sponge_start = spongeChoice.xhi_sponge_start;
248  const Real ylo_sponge_end = spongeChoice.ylo_sponge_end;
249  const Real yhi_sponge_start = spongeChoice.yhi_sponge_start;
250  const Real zlo_sponge_end = spongeChoice.zlo_sponge_end;
251  const Real zhi_sponge_start = spongeChoice.zhi_sponge_start;
252 
253  const Real sponge_x_velocity = spongeChoice.sponge_x_velocity;
254  const Real sponge_y_velocity = spongeChoice.sponge_y_velocity;
255  const Real sponge_z_velocity = spongeChoice.sponge_z_velocity;
256 
257  const Real sponge_density_tmp = spongeChoice.sponge_density;
258  const bool use_base = (sponge_density_tmp < zero);
259 
260  // Domain valid box
261  const Box& domain = geom.Domain();
262  int domlo_x = domain.smallEnd(0);
263  int domhi_x = domain.bigEnd(0) + 1;
264  int domlo_y = domain.smallEnd(1);
265  int domhi_y = domain.bigEnd(1) + 1;
266 
267  if(use_xlo_sponge_damping)AMREX_ALWAYS_ASSERT(xlo_sponge_end > ProbLoArr[0]);
268  if(use_xhi_sponge_damping)AMREX_ALWAYS_ASSERT(xhi_sponge_start < ProbHiArr[0]);
269  if(use_ylo_sponge_damping)AMREX_ALWAYS_ASSERT(ylo_sponge_end > ProbLoArr[1]);
270  if(use_yhi_sponge_damping)AMREX_ALWAYS_ASSERT(yhi_sponge_start < ProbHiArr[1]);
271  if(use_zlo_sponge_damping)AMREX_ALWAYS_ASSERT(zlo_sponge_end > ProbLoArr[2]);
272  if(use_zhi_sponge_damping)AMREX_ALWAYS_ASSERT(zhi_sponge_start < ProbHiArr[2]);
273 
274  // Ramp lengths, computed here so that the kernels divide only by a valid length: the
275  // optimiser evaluates the guarded ramps of the sides that are switched off too, and the
276  // lengths of those sides (whose ends are never read from the inputs) can be zero
277  const Real L_xlo = use_xlo_sponge_damping ? (xlo_sponge_end - ProbLoArr[0]) : one;
278  const Real L_xhi = use_xhi_sponge_damping ? (ProbHiArr[0] - xhi_sponge_start) : one;
279  const Real L_ylo = use_ylo_sponge_damping ? (ylo_sponge_end - ProbLoArr[1]) : one;
280  const Real L_yhi = use_yhi_sponge_damping ? (ProbHiArr[1] - yhi_sponge_start) : one;
281  const Real L_zlo = use_zlo_sponge_damping ? (zlo_sponge_end - ProbLoArr[2]) : one;
282  const Real L_zhi = use_zhi_sponge_damping ? (ProbHiArr[2] - zhi_sponge_start) : one;
283 
284  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
285  {
286  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
287  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
288 
289  Real x = ProbLoArr[0] + ii * dx[0];
290  Real y = ProbLoArr[1] + (jj+myhalf) * dx[1];
291  // Height of the x-face
292  Real z = myhalf * (z_phys_cc(i-1,j,k) + z_phys_cc(i,j,k));
293 
294  Real sponge_density = (use_base) ? myhalf * (r0(i,j,k) + r0(i-1,j,k)) : sponge_density_tmp;
295 
296  // x lo sponge
297  if(use_xlo_sponge_damping){
298  if (x < xlo_sponge_end) {
299  Real xi = (xlo_sponge_end - x) / L_xlo;
300  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
301  }
302  }
303  // x hi sponge
304  if(use_xhi_sponge_damping){
305  if (x > xhi_sponge_start) {
306  Real xi = (x - xhi_sponge_start) / L_xhi;
307  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
308  }
309  }
310 
311  // y lo sponge
312  if(use_ylo_sponge_damping){
313  if (y < ylo_sponge_end) {
314  Real xi = (ylo_sponge_end - y) / L_ylo;
315  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
316  }
317  }
318  // x right sponge
319  if(use_yhi_sponge_damping){
320  if (y > yhi_sponge_start) {
321  Real xi = (y - yhi_sponge_start) / L_yhi;
322  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
323  }
324  }
325 
326  // z lo sponge
327  if(use_zlo_sponge_damping){
328  if (z < zlo_sponge_end) {
329  Real xi = (zlo_sponge_end - z) / L_zlo;
330  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
331  }
332  }
333 
334 
335  // z hi sponge
336  if(use_zhi_sponge_damping){
337  if (z > zhi_sponge_start) {
338  Real xi = (z - zhi_sponge_start) / L_zhi;
339  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
340  }
341  }
342  });
343 
344 
345  ParallelFor(tby, [=] AMREX_GPU_DEVICE(int i, int j, int k)
346  {
347  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
348  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
349 
350  Real x = ProbLoArr[0] + (ii+myhalf) * dx[0];
351  Real y = ProbLoArr[1] + jj * dx[1];
352  // Height of the y-face
353  Real z = myhalf * (z_phys_cc(i,j-1,k) + z_phys_cc(i,j,k));
354 
355  Real sponge_density = (use_base) ? myhalf * (r0(i,j,k) + r0(i,j-1,k)) : sponge_density_tmp;
356 
357  // x lo sponge
358  if(use_xlo_sponge_damping){
359  if (x < xlo_sponge_end) {
360  Real xi = (xlo_sponge_end - x) / L_xlo;
361  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
362  }
363  }
364  // x hi sponge
365  if(use_xhi_sponge_damping){
366  if (x > xhi_sponge_start) {
367  Real xi = (x - xhi_sponge_start) / L_xhi;
368  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
369  }
370  }
371 
372  // y lo sponge
373  if(use_ylo_sponge_damping){
374  if (y < ylo_sponge_end) {
375  Real xi = (ylo_sponge_end - y) / L_ylo;
376  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
377  }
378  }
379  // x right sponge
380  if(use_yhi_sponge_damping){
381  if (y > yhi_sponge_start) {
382  Real xi = (y - yhi_sponge_start) / L_yhi;
383  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
384  }
385  }
386 
387  // z lo sponge
388  if(use_zlo_sponge_damping){
389  if (z < zlo_sponge_end) {
390  Real xi = (zlo_sponge_end - z) / L_zlo;
391  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
392  }
393  }
394 
395 
396  // z hi sponge
397  if(use_zhi_sponge_damping){
398  if (z > zhi_sponge_start) {
399  Real xi = (z - zhi_sponge_start) / L_zhi;
400  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
401  }
402  }
403  });
404 
405 
406  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k)
407  {
408  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
409  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
410 
411  Real x = ProbLoArr[0] + (ii+myhalf) * dx[0];
412  Real y = ProbLoArr[1] + (jj+myhalf) * dx[1];
413  // Height of the z-face centre: average of its four corner nodes, taken in pairs
414  // so that equal corner heights (no terrain) give back that height exactly
415  Real z = myhalf * ( myhalf * (z_phys_nd(i,j ,k) + z_phys_nd(i+1,j ,k))
416  + myhalf * (z_phys_nd(i,j+1,k) + z_phys_nd(i+1,j+1,k)) );
417 
418  Real sponge_density = (use_base) ? myhalf * (r0(i,j,k) + r0(i,j,k-1)) : sponge_density_tmp;
419 
420  // x left sponge
421  if(use_xlo_sponge_damping){
422  if (x < xlo_sponge_end) {
423  Real xi = (xlo_sponge_end - x) / L_xlo;
424  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
425  }
426  }
427  // x right sponge
428  if(use_xhi_sponge_damping){
429  if (x > xhi_sponge_start) {
430  Real xi = (x - xhi_sponge_start) / L_xhi;
431  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
432  }
433  }
434 
435  // y lo sponge
436  if(use_ylo_sponge_damping){
437  if (y < ylo_sponge_end) {
438  Real xi = (ylo_sponge_end - y) / L_ylo;
439  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
440  }
441  }
442  // x right sponge
443  if(use_yhi_sponge_damping){
444  if (y > yhi_sponge_start) {
445  Real xi = (y - yhi_sponge_start) / L_yhi;
446  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
447  }
448  }
449 
450  // z lo sponge
451  if(use_zlo_sponge_damping){
452  if (z < zlo_sponge_end) {
453  Real xi = (zlo_sponge_end - z) / L_zlo;
454  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
455  }
456  }
457 
458 
459  // z top sponge
460  if(use_zhi_sponge_damping){
461  if (z > zhi_sponge_start) {
462  Real xi = (z - zhi_sponge_start) / L_zhi;
463  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
464  }
465  }
466  });
467 }
amrex::Real sponge_y_velocity
Target y velocity used by sponge damping.
Definition: ERF_SpongeStruct.H:110
amrex::Real sponge_x_velocity
Target x velocity used by sponge damping.
Definition: ERF_SpongeStruct.H:109
amrex::Real sponge_z_velocity
Target vertical velocity used by sponge damping.
Definition: ERF_SpongeStruct.H:111

Referenced by make_mom_sources().

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