ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 > &z_phys_cc)
 
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)
 

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

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

Referenced by make_mom_sources().

Here is the caller graph for this function: