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

Functions

void ApplySpongeZoneBCsForMom_ReadFromFile (const SpongeChoice &spongeChoice, const Geometry geom, const Box &tbx, const Box &tby, const Array4< const Real > &cell_data, const Array4< const Real > &z_phys_cc, const Array4< Real > &rho_u_rhs, const Array4< Real > &rho_v_rhs, const Array4< const Real > &rho_u, const Array4< const Real > &rho_v, const Vector< Real * > d_sponge_ptrs_at_lev)
 

Function Documentation

◆ ApplySpongeZoneBCsForMom_ReadFromFile()

void ApplySpongeZoneBCsForMom_ReadFromFile ( const SpongeChoice &  spongeChoice,
const Geometry  geom,
const Box &  tbx,
const Box &  tby,
const Array4< const Real > &  cell_data,
const Array4< const Real > &  z_phys_cc,
const Array4< Real > &  rho_u_rhs,
const Array4< Real > &  rho_v_rhs,
const Array4< const Real > &  rho_u,
const Array4< const Real > &  rho_v,
const Vector< Real * >  d_sponge_ptrs_at_lev 
)

Apply sponge zone damping to momentum RHS using target states read from a file.

Parameters
[in]spongeChoiceSponge zone configuration.
[in]geomGeometry for grid spacing and bounds.
[in]tbxBox for x-momentum update.
[in]tbyBox for y-momentum update.
[in]cell_dataCell-centered state data.
[in]z_phys_ccCell-centered physical height.
[in,out]rho_u_rhsRight-hand side for x-momentum.
[in,out]rho_v_rhsRight-hand side for y-momentum.
[in]rho_uCurrent x-momentum.
[in]rho_vCurrent y-momentum.
[in]d_sponge_ptrs_at_levPointers to target sponge velocities.
34 {
35  // Domain cell size and real bounds
36  auto dx = geom.CellSizeArray();
37  auto ProbHiArr = geom.ProbHiArray();
38  auto ProbLoArr = geom.ProbLoArray();
39 
40  const Real sponge_strength = spongeChoice.sponge_strength;
41  const int use_xlo_sponge_damping = spongeChoice.use_xlo_sponge_damping;
42  const int use_xhi_sponge_damping = spongeChoice.use_xhi_sponge_damping;
43  const int use_ylo_sponge_damping = spongeChoice.use_ylo_sponge_damping;
44  const int use_yhi_sponge_damping = spongeChoice.use_yhi_sponge_damping;
45  const int use_zlo_sponge_damping = spongeChoice.use_zlo_sponge_damping;
46  const int use_zhi_sponge_damping = spongeChoice.use_zhi_sponge_damping;
47 
48  const Real xlo_sponge_end = spongeChoice.xlo_sponge_end;
49  const Real xhi_sponge_start = spongeChoice.xhi_sponge_start;
50  const Real ylo_sponge_end = spongeChoice.ylo_sponge_end;
51  const Real yhi_sponge_start = spongeChoice.yhi_sponge_start;
52  const Real zlo_sponge_end = spongeChoice.zlo_sponge_end;
53  const Real zhi_sponge_start = spongeChoice.zhi_sponge_start;
54 
55  // Domain valid box
56  const Box& domain = geom.Domain();
57  int domlo_x = domain.smallEnd(0);
58  int domhi_x = domain.bigEnd(0) + 1;
59  int domlo_y = domain.smallEnd(1);
60  int domhi_y = domain.bigEnd(1) + 1;
61 
62  Real* ubar_sponge = d_sponge_ptrs_at_lev[Sponge::ubar_sponge];
63  Real* vbar_sponge = d_sponge_ptrs_at_lev[Sponge::vbar_sponge];
64 
65  if(use_xlo_sponge_damping)AMREX_ALWAYS_ASSERT(xlo_sponge_end > ProbLoArr[0]);
66  if(use_xhi_sponge_damping)AMREX_ALWAYS_ASSERT(xhi_sponge_start < ProbHiArr[0]);
67  if(use_ylo_sponge_damping)AMREX_ALWAYS_ASSERT(ylo_sponge_end > ProbLoArr[1]);
68  if(use_yhi_sponge_damping)AMREX_ALWAYS_ASSERT(yhi_sponge_start < ProbHiArr[1]);
69  if(use_zlo_sponge_damping)AMREX_ALWAYS_ASSERT(zlo_sponge_end > ProbLoArr[2]);
70  if(use_zhi_sponge_damping)AMREX_ALWAYS_ASSERT(zhi_sponge_start < ProbHiArr[2]);
71 
72  // Ramp lengths, computed here so that the kernels divide only by a valid length: the
73  // optimiser evaluates the guarded ramps of the sides that are switched off too, and the
74  // lengths of those sides (whose ends are never read from the inputs) can be zero
75  const Real L_xlo = use_xlo_sponge_damping ? (xlo_sponge_end - ProbLoArr[0]) : one;
76  const Real L_xhi = use_xhi_sponge_damping ? (ProbHiArr[0] - xhi_sponge_start) : one;
77  const Real L_ylo = use_ylo_sponge_damping ? (ylo_sponge_end - ProbLoArr[1]) : one;
78  const Real L_yhi = use_yhi_sponge_damping ? (ProbHiArr[1] - yhi_sponge_start) : one;
79  const Real L_zlo = use_zlo_sponge_damping ? (zlo_sponge_end - ProbLoArr[2]) : one;
80  const Real L_zhi = use_zhi_sponge_damping ? (ProbHiArr[2] - zhi_sponge_start) : one;
81 
82  ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
83  {
84  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
85  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
86 
87  Real x = ProbLoArr[0] + ii * dx[0];
88  Real y = ProbLoArr[1] + (jj+myhalf) * dx[1];
89  // Height and density on the x-face
90  Real z = myhalf * (z_phys_cc(i-1,j,k) + z_phys_cc(i,j,k));
91  Real rho_on_u_face = myhalf * (cell_data(i-1,j,k,0) + cell_data(i,j,k,0));
92 
93  // x lo sponge
94  if(use_xlo_sponge_damping){
95  if (x < xlo_sponge_end) {
96  Real xi = (xlo_sponge_end - x) / L_xlo;
97  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - rho_on_u_face*ubar_sponge[k]);
98  }
99  }
100  // x hi sponge
101  if(use_xhi_sponge_damping){
102  if (x > xhi_sponge_start) {
103  Real xi = (x - xhi_sponge_start) / L_xhi;
104  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - rho_on_u_face*ubar_sponge[k]);
105  }
106  }
107 
108  // y lo sponge
109  if(use_ylo_sponge_damping){
110  if (y < ylo_sponge_end) {
111  Real xi = (ylo_sponge_end - y) / L_ylo;
112  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - rho_on_u_face*ubar_sponge[k]);
113  }
114  }
115  // x right sponge
116  if(use_yhi_sponge_damping){
117  if (y > yhi_sponge_start) {
118  Real xi = (y - yhi_sponge_start) / L_yhi;
119  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - rho_on_u_face*ubar_sponge[k]);
120  }
121  }
122 
123  // z lo sponge
124  if(use_zlo_sponge_damping){
125  if (z < zlo_sponge_end) {
126  Real xi = (zlo_sponge_end - z) / L_zlo;
127  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - rho_on_u_face*ubar_sponge[k]);
128  }
129  }
130 
131 
132  // z hi sponge
133  if(use_zhi_sponge_damping){
134  if (z > zhi_sponge_start) {
135  Real xi = (z - zhi_sponge_start) / L_zhi;
136  rho_u_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_u(i, j, k) - rho_on_u_face*ubar_sponge[k]);
137  }
138  }
139  });
140 
141 
142  ParallelFor(tby, [=] AMREX_GPU_DEVICE(int i, int j, int k)
143  {
144  int ii = amrex::min(amrex::max(i, domlo_x), domhi_x);
145  int jj = amrex::min(amrex::max(j, domlo_y), domhi_y);
146 
147  Real x = ProbLoArr[0] + (ii+myhalf) * dx[0];
148  Real y = ProbLoArr[1] + jj * dx[1];
149  // Height and density on the y-face
150  Real z = myhalf * (z_phys_cc(i,j-1,k) + z_phys_cc(i,j,k));
151  Real rho_on_v_face = myhalf * (cell_data(i,j-1,k,0) + cell_data(i,j,k,0));
152 
153  // x lo sponge
154  if(use_xlo_sponge_damping){
155  if (x < xlo_sponge_end) {
156  Real xi = (xlo_sponge_end - x) / L_xlo;
157  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - rho_on_v_face*vbar_sponge[k]);
158  }
159  }
160  // x hi sponge
161  if(use_xhi_sponge_damping){
162  if (x > xhi_sponge_start) {
163  Real xi = (x - xhi_sponge_start) / L_xhi;
164  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - rho_on_v_face*vbar_sponge[k]);
165  }
166  }
167 
168  // y lo sponge
169  if(use_ylo_sponge_damping){
170  if (y < ylo_sponge_end) {
171  Real xi = (ylo_sponge_end - y) / L_ylo;
172  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - rho_on_v_face*vbar_sponge[k]);
173  }
174  }
175  // x right sponge
176  if(use_yhi_sponge_damping){
177  if (y > yhi_sponge_start) {
178  Real xi = (y - yhi_sponge_start) / L_yhi;
179  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - rho_on_v_face*vbar_sponge[k]);
180  }
181  }
182 
183  // z lo sponge
184  if(use_zlo_sponge_damping){
185  if (z < zlo_sponge_end) {
186  Real xi = (zlo_sponge_end - z) / L_zlo;
187  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - rho_on_v_face*vbar_sponge[k]);
188  }
189  }
190 
191 
192  // z hi sponge
193  if(use_zhi_sponge_damping){
194  if (z > zhi_sponge_start) {
195  Real xi = (z - zhi_sponge_start) / L_zhi;
196  rho_v_rhs(i, j, k) -= sponge_strength * xi * xi * (rho_v(i, j, k) - rho_on_v_face*vbar_sponge[k]);
197  }
198  }
199  });
200 }
@ vbar_sponge
Definition: ERF_DataStruct.H:215
@ ubar_sponge
Definition: ERF_DataStruct.H:215
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 myhalf
Definition: ERF_NumericalConstants.H:41
amrex::Real Real
Definition: ERF_ShocInterface.H:19
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 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
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
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_mom_sources().

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