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)
 
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)
 

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 
)
13 {
14  // Domain cell size and real bounds
15  auto dx = geom.CellSizeArray();
16  auto ProbHiArr = geom.ProbHiArray();
17  auto ProbLoArr = geom.ProbLoArray();
18 
19  const Real sponge_strength = spongeChoice.sponge_strength;
20  const int use_xlo_sponge_damping = spongeChoice.use_xlo_sponge_damping;
21  const int use_xhi_sponge_damping = spongeChoice.use_xhi_sponge_damping;
22  const int use_ylo_sponge_damping = spongeChoice.use_ylo_sponge_damping;
23  const int use_yhi_sponge_damping = spongeChoice.use_yhi_sponge_damping;
24  const int use_zlo_sponge_damping = spongeChoice.use_zlo_sponge_damping;
25  const int use_zhi_sponge_damping = spongeChoice.use_zhi_sponge_damping;
26  if (!use_xlo_sponge_damping &&
27  !use_xhi_sponge_damping &&
28  !use_ylo_sponge_damping &&
29  !use_yhi_sponge_damping &&
30  !use_zlo_sponge_damping &&
31  !use_zhi_sponge_damping)
32  return;
33 
34  const Real xlo_sponge_end = spongeChoice.xlo_sponge_end;
35  const Real xhi_sponge_start = spongeChoice.xhi_sponge_start;
36  const Real ylo_sponge_end = spongeChoice.ylo_sponge_end;
37  const Real yhi_sponge_start = spongeChoice.yhi_sponge_start;
38  const Real zlo_sponge_end = spongeChoice.zlo_sponge_end;
39  const Real zhi_sponge_start = spongeChoice.zhi_sponge_start;
40 
41  const Real sponge_density = spongeChoice.sponge_density;
42 
43  // Domain valid box
44  const Box& domain = geom.Domain();
45  int domlo_x = domain.smallEnd(0);
46  int domhi_x = domain.bigEnd(0) + 1;
47  int domlo_y = domain.smallEnd(1);
48  int domhi_y = domain.bigEnd(1) + 1;
49  int domlo_z = domain.smallEnd(2);
50  int domhi_z = domain.bigEnd(2) + 1;
51 
52  if(use_xlo_sponge_damping)AMREX_ALWAYS_ASSERT(xlo_sponge_end > ProbLoArr[0]);
53  if(use_xhi_sponge_damping)AMREX_ALWAYS_ASSERT(xhi_sponge_start < ProbHiArr[0]);
54  if(use_ylo_sponge_damping)AMREX_ALWAYS_ASSERT(ylo_sponge_end > ProbLoArr[1]);
55  if(use_yhi_sponge_damping)AMREX_ALWAYS_ASSERT(yhi_sponge_start < ProbHiArr[1]);
56  if(use_zlo_sponge_damping)AMREX_ALWAYS_ASSERT(zlo_sponge_end > ProbLoArr[2]);
57  if(use_zhi_sponge_damping)AMREX_ALWAYS_ASSERT(zhi_sponge_start < ProbHiArr[2]);
58 
59  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept
60  {
61  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
62  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
63  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
64 
65  Real x = ProbLoArr[0] + (ii+0.5) * dx[0];
66  Real y = ProbLoArr[1] + (jj+0.5) * dx[1];
67  Real z = ProbLoArr[2] + (kk+0.5) * dx[2];
68 
69  // x left sponge
70  if(use_xlo_sponge_damping){
71  if (x < xlo_sponge_end) {
72  Real xi = (xlo_sponge_end - x) / (xlo_sponge_end - ProbLoArr[0]);
73  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
74  }
75  }
76  // x right sponge
77  if(use_xhi_sponge_damping){
78  if (x > xhi_sponge_start) {
79  Real xi = (x - xhi_sponge_start) / (ProbHiArr[0] - xhi_sponge_start);
80  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
81  }
82  }
83 
84  // y left sponge
85  if(use_ylo_sponge_damping){
86  if (y < ylo_sponge_end) {
87  Real xi = (ylo_sponge_end - y) / (ylo_sponge_end - ProbLoArr[1]);
88  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
89  }
90  }
91  // x right sponge
92  if(use_yhi_sponge_damping){
93  if (y > yhi_sponge_start) {
94  Real xi = (y - yhi_sponge_start) / (ProbHiArr[1] - yhi_sponge_start);
95  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
96  }
97  }
98 
99  // x left sponge
100  if(use_zlo_sponge_damping){
101  if (z < zlo_sponge_end) {
102  Real xi = (zlo_sponge_end - z) / (zlo_sponge_end - ProbLoArr[2]);
103  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
104  }
105  }
106  // x right sponge
107  if(use_zhi_sponge_damping){
108  if (z > zhi_sponge_start) {
109  Real xi = (z - zhi_sponge_start) / (ProbHiArr[2] - zhi_sponge_start);
110  cell_rhs(i, j, k, 0) -= sponge_strength * xi * xi * (cell_data(i, j, k, 0) - sponge_density);
111  }
112  }
113  });
114 }
bool use_xlo_sponge_damping
Definition: ERF_SpongeStruct.H:53
amrex::Real xlo_sponge_end
Definition: ERF_SpongeStruct.H:63
amrex::Real zlo_sponge_end
Definition: ERF_SpongeStruct.H:65
bool use_zlo_sponge_damping
Definition: ERF_SpongeStruct.H:57
amrex::Real sponge_strength
Definition: ERF_SpongeStruct.H:60
bool use_ylo_sponge_damping
Definition: ERF_SpongeStruct.H:55
amrex::Real zhi_sponge_start
Definition: ERF_SpongeStruct.H:65
bool use_xhi_sponge_damping
Definition: ERF_SpongeStruct.H:54
bool use_zhi_sponge_damping
Definition: ERF_SpongeStruct.H:58
amrex::Real yhi_sponge_start
Definition: ERF_SpongeStruct.H:64
amrex::Real sponge_density
Definition: ERF_SpongeStruct.H:66
bool use_yhi_sponge_damping
Definition: ERF_SpongeStruct.H:56
amrex::Real xhi_sponge_start
Definition: ERF_SpongeStruct.H:63
amrex::Real ylo_sponge_end
Definition: ERF_SpongeStruct.H:64

Referenced by make_sources().

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 
)
129 {
130  // Domain cell size and real bounds
131  auto dx = geom.CellSizeArray();
132  auto ProbHiArr = geom.ProbHiArray();
133  auto ProbLoArr = geom.ProbLoArray();
134 
135  const Real sponge_strength = spongeChoice.sponge_strength;
136  const int use_xlo_sponge_damping = spongeChoice.use_xlo_sponge_damping;
137  const int use_xhi_sponge_damping = spongeChoice.use_xhi_sponge_damping;
138  const int use_ylo_sponge_damping = spongeChoice.use_ylo_sponge_damping;
139  const int use_yhi_sponge_damping = spongeChoice.use_yhi_sponge_damping;
140  const int use_zlo_sponge_damping = spongeChoice.use_zlo_sponge_damping;
141  const int use_zhi_sponge_damping = spongeChoice.use_zhi_sponge_damping;
142  if (!use_xlo_sponge_damping &&
143  !use_xhi_sponge_damping &&
144  !use_ylo_sponge_damping &&
145  !use_yhi_sponge_damping &&
146  !use_zlo_sponge_damping &&
147  !use_zhi_sponge_damping)
148  return;
149 
150  const Real xlo_sponge_end = spongeChoice.xlo_sponge_end;
151  const Real xhi_sponge_start = spongeChoice.xhi_sponge_start;
152  const Real ylo_sponge_end = spongeChoice.ylo_sponge_end;
153  const Real yhi_sponge_start = spongeChoice.yhi_sponge_start;
154  const Real zlo_sponge_end = spongeChoice.zlo_sponge_end;
155  const Real zhi_sponge_start = spongeChoice.zhi_sponge_start;
156 
157  const Real sponge_density = spongeChoice.sponge_density;
158  const Real sponge_x_velocity = spongeChoice.sponge_x_velocity;
159  const Real sponge_y_velocity = spongeChoice.sponge_y_velocity;
160  const Real sponge_z_velocity = spongeChoice.sponge_z_velocity;
161 
162  // Domain valid box
163  const Box& domain = geom.Domain();
164  int domlo_x = domain.smallEnd(0);
165  int domhi_x = domain.bigEnd(0) + 1;
166  int domlo_y = domain.smallEnd(1);
167  int domhi_y = domain.bigEnd(1) + 1;
168  int domlo_z = domain.smallEnd(2);
169  int domhi_z = domain.bigEnd(2) + 1;
170 
171  if(use_xlo_sponge_damping)AMREX_ALWAYS_ASSERT(xlo_sponge_end > ProbLoArr[0]);
172  if(use_xhi_sponge_damping)AMREX_ALWAYS_ASSERT(xhi_sponge_start < ProbHiArr[0]);
173  if(use_ylo_sponge_damping)AMREX_ALWAYS_ASSERT(ylo_sponge_end > ProbLoArr[1]);
174  if(use_yhi_sponge_damping)AMREX_ALWAYS_ASSERT(yhi_sponge_start < ProbHiArr[1]);
175  if(use_zlo_sponge_damping)AMREX_ALWAYS_ASSERT(zlo_sponge_end > ProbLoArr[2]);
176  if(use_zhi_sponge_damping)AMREX_ALWAYS_ASSERT(zhi_sponge_start < ProbHiArr[2]);
177 
178  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
179  {
180  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
181  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
182  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
183 
184  Real x = ProbLoArr[0] + ii * dx[0];
185  Real y = ProbLoArr[1] + (jj+0.5) * dx[1];
186  Real z = ProbLoArr[2] + (kk+0.5) * dx[2];
187 
188  // x lo sponge
189  if(use_xlo_sponge_damping){
190  if (x < xlo_sponge_end) {
191  Real xi = (xlo_sponge_end - x) / (xlo_sponge_end - ProbLoArr[0]);
192  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
193  }
194  }
195  // x hi sponge
196  if(use_xhi_sponge_damping){
197  if (x > xhi_sponge_start) {
198  Real xi = (x - xhi_sponge_start) / (ProbHiArr[0] - xhi_sponge_start);
199  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
200  }
201  }
202 
203  // y lo sponge
204  if(use_ylo_sponge_damping){
205  if (y < ylo_sponge_end) {
206  Real xi = (ylo_sponge_end - y) / (ylo_sponge_end - ProbLoArr[1]);
207  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
208  }
209  }
210  // x right sponge
211  if(use_yhi_sponge_damping){
212  if (y > yhi_sponge_start) {
213  Real xi = (y - yhi_sponge_start) / (ProbHiArr[1] - yhi_sponge_start);
214  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
215  }
216  }
217 
218  // z lo sponge
219  if(use_zlo_sponge_damping){
220  if (z < zlo_sponge_end) {
221  Real xi = (zlo_sponge_end - z) / (zlo_sponge_end - ProbLoArr[2]);
222  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
223  }
224  }
225 
226 
227  // z hi sponge
228  if(use_zhi_sponge_damping){
229  if (z > zhi_sponge_start) {
230  Real xi = (z - zhi_sponge_start) / (ProbHiArr[2] - zhi_sponge_start);
231  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - sponge_density*sponge_x_velocity);
232  }
233  }
234  });
235 
236 
237  ParallelFor(tby, [=] AMREX_GPU_DEVICE(int i, int j, int k)
238  {
239  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
240  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
241  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
242 
243  Real x = ProbLoArr[0] + (ii+0.5) * dx[0];
244  Real y = ProbLoArr[1] + jj * dx[1];
245  Real z = ProbLoArr[2] + (kk+0.5) * dx[2];
246 
247  // x lo sponge
248  if(use_xlo_sponge_damping){
249  if (x < xlo_sponge_end) {
250  Real xi = (xlo_sponge_end - x) / (xlo_sponge_end - ProbLoArr[0]);
251  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
252  }
253  }
254  // x hi sponge
255  if(use_xhi_sponge_damping){
256  if (x > xhi_sponge_start) {
257  Real xi = (x - xhi_sponge_start) / (ProbHiArr[0] - xhi_sponge_start);
258  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
259  }
260  }
261 
262  // y lo sponge
263  if(use_ylo_sponge_damping){
264  if (y < ylo_sponge_end) {
265  Real xi = (ylo_sponge_end - y) / (ylo_sponge_end - ProbLoArr[1]);
266  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
267  }
268  }
269  // x right sponge
270  if(use_yhi_sponge_damping){
271  if (y > yhi_sponge_start) {
272  Real xi = (y - yhi_sponge_start) / (ProbHiArr[1] - yhi_sponge_start);
273  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
274  }
275  }
276 
277  // z lo sponge
278  if(use_zlo_sponge_damping){
279  if (z < zlo_sponge_end) {
280  Real xi = (zlo_sponge_end - z) / (zlo_sponge_end - ProbLoArr[2]);
281  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
282  }
283  }
284 
285 
286  // z hi sponge
287  if(use_zhi_sponge_damping){
288  if (z > zhi_sponge_start) {
289  Real xi = (z - zhi_sponge_start) / (ProbHiArr[2] - zhi_sponge_start);
290  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - sponge_density*sponge_y_velocity);
291  }
292  }
293  });
294 
295 
296  ParallelFor(tbz, [=] AMREX_GPU_DEVICE(int i, int j, int k)
297  {
298  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
299  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
300  int kk = amrex::min(amrex::max(k, domlo_z), domhi_z);
301 
302  Real x = ProbLoArr[0] + (ii+0.5) * dx[0];
303  Real y = ProbLoArr[1] + (jj+0.5) * dx[1];
304  Real z = ProbLoArr[2] + kk * dx[2];
305 
306  // x left sponge
307  if(use_xlo_sponge_damping){
308  if (x < xlo_sponge_end) {
309  Real xi = (xlo_sponge_end - x) / (xlo_sponge_end - ProbLoArr[0]);
310  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
311  }
312  }
313  // x right sponge
314  if(use_xhi_sponge_damping){
315  if (x > xhi_sponge_start) {
316  Real xi = (x - xhi_sponge_start) / (ProbHiArr[0] - xhi_sponge_start);
317  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
318  }
319  }
320 
321  // y lo sponge
322  if(use_ylo_sponge_damping){
323  if (y < ylo_sponge_end) {
324  Real xi = (ylo_sponge_end - y) / (ylo_sponge_end - ProbLoArr[1]);
325  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
326  }
327  }
328  // x right sponge
329  if(use_yhi_sponge_damping){
330  if (y > yhi_sponge_start) {
331  Real xi = (y - yhi_sponge_start) / (ProbHiArr[1] - yhi_sponge_start);
332  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
333  }
334  }
335 
336  // z lo sponge
337  if(use_zlo_sponge_damping){
338  if (z < zlo_sponge_end) {
339  Real xi = (zlo_sponge_end - z) / (zlo_sponge_end - ProbLoArr[2]);
340  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
341  }
342  }
343 
344 
345  // z top sponge
346  if(use_zhi_sponge_damping){
347  if (z > zhi_sponge_start) {
348  Real xi = (z - zhi_sponge_start) / (ProbHiArr[2] - zhi_sponge_start);
349  rho_w_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_w(i, j, k) - sponge_density*sponge_z_velocity);
350  }
351  }
352  });
353 }
amrex::Real sponge_y_velocity
Definition: ERF_SpongeStruct.H:66
amrex::Real sponge_z_velocity
Definition: ERF_SpongeStruct.H:66
amrex::Real sponge_x_velocity
Definition: ERF_SpongeStruct.H:66

Referenced by make_mom_sources().

Here is the caller graph for this function: