53 const int* bxlo,
const int* bxhi,
const int* domlo,
56 const int nx = q_hi[0] - q_lo[0] + 1;
57 const int ny = q_hi[1] - q_lo[1] + 1;
58 auto idx = [&](
int i,
int j,
int k) ->
int& {
59 return q[(i - q_lo[0]) + (j - q_lo[1]) * nx + (k - q_lo[2]) * nx * ny];
62 for (
int k = bxlo[2]; k <= bxhi[2]; ++k) {
63 for (
int j = bxlo[1]; j <= bxhi[1]; ++j) {
64 for (
int i = bxlo[0]; i <= bxhi[0]; ++i) {
65 const int center = idx(i, j, k);
76 bool connected =
false;
77 for (
int n = 0; n < 6; ++n) {
78 if (center == nbr[n]) {
85 idx(i, j, k) = (center == 0) ? 1 : 0;
109 const amrex::Array4<amrex::Real>& fy,
110 const amrex::Array4<amrex::Real>& fz,
111 const amrex::Array4<const amrex::Real>& sol,
112 const amrex::Real* dxinv) {
113 const auto lo = bx.loVect3d();
114 const auto hi = bx.hiVect3d();
115 const amrex::Real dhx = dxinv[0];
116 const amrex::Real dhy = dxinv[1];
117 const amrex::Real dhz = dxinv[2];
119 constexpr int comp_phi = 0;
120 constexpr int comp_ct = 1;
125 xbx.surroundingNodes(0);
126 amrex::ParallelFor(xbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
noexcept {
131 fx(i, j, k) = dhx * (sol(i, j, k, comp_phi) - sol(i - 1, j, k, comp_phi));
139 ybx.surroundingNodes(1);
140 amrex::ParallelFor(ybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
noexcept {
145 fy(i, j, k) = dhy * (sol(i, j, k, comp_phi) - sol(i, j - 1, k, comp_phi));
153 zbx.surroundingNodes(2);
154 amrex::ParallelFor(zbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
noexcept {
159 fz(i, j, k) = dhz * (sol(i, j, k, comp_phi) - sol(i, j, k - 1, comp_phi));
183 const amrex::Array4<amrex::Real>& n_arr,
184 const amrex::Array4<const amrex::Real>& fx,
185 const amrex::Array4<const amrex::Real>& fy,
186 const amrex::Array4<const amrex::Real>& fz,
const amrex::Real* dxinv,
188 const amrex::Real dtdx = dt * dxinv[0];
189 const amrex::Real dtdy = dt * dxinv[1];
190 const amrex::Real dtdz = dt * dxinv[2];
192 constexpr int comp_phi = 0;
194 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
noexcept {
195 n_arr(i, j, k, comp_phi) =
196 p_arr(i, j, k, comp_phi) + dtdx * (fx(i + 1, j, k) - fx(i, j, k)) +
197 dtdy * (fy(i, j + 1, k) - fy(i, j, k)) + dtdz * (fz(i, j, k + 1) - fz(i, j, k));
219 const amrex::Array4<const amrex::Real>& fx,
220 const amrex::Array4<const amrex::Real>& fy,
221 const amrex::Array4<const amrex::Real>& fz,
222 const amrex::Box& fxbox,
const amrex::Box& fybox,
223 const amrex::Box& fzbox,
int dir, amrex::Real& flux_in,
224 amrex::Real& flux_out) {
225 const auto lo = cell_bx.loVect3d();
226 const auto hi = cell_bx.hiVect3d();
233 if (fxbox.smallEnd(0) <= lo[0]) {
234 for (
int k = lo[2]; k <= hi[2]; ++k)
235 for (
int j = lo[1]; j <= hi[1]; ++j)
236 flux_in += fx(lo[0], j, k);
238 if (fxbox.bigEnd(0) >= hi[0] + 1) {
239 for (
int k = lo[2]; k <= hi[2]; ++k)
240 for (
int j = lo[1]; j <= hi[1]; ++j)
241 flux_out += fx(hi[0] + 1, j, k);
243 }
else if (dir == 1) {
245 if (fybox.smallEnd(1) <= lo[1]) {
246 for (
int k = lo[2]; k <= hi[2]; ++k)
247 for (
int i = lo[0]; i <= hi[0]; ++i)
248 flux_in += fy(i, lo[1], k);
250 if (fybox.bigEnd(1) >= hi[1] + 1) {
251 for (
int k = lo[2]; k <= hi[2]; ++k)
252 for (
int i = lo[0]; i <= hi[0]; ++i)
253 flux_out += fy(i, hi[1] + 1, k);
257 if (fzbox.smallEnd(2) <= lo[2]) {
258 for (
int j = lo[1]; j <= hi[1]; ++j)
259 for (
int i = lo[0]; i <= hi[0]; ++i)
260 flux_in += fz(i, j, lo[2]);
262 if (fzbox.bigEnd(2) >= hi[2] + 1) {
263 for (
int j = lo[1]; j <= hi[1]; ++j)
264 for (
int i = lo[0]; i <= hi[0]; ++i)
265 flux_out += fz(i, j, hi[2] + 1);
void integrateBoundaryFluxes(const amrex::Box &cell_bx, const amrex::Array4< const amrex::Real > &fx, const amrex::Array4< const amrex::Real > &fy, const amrex::Array4< const amrex::Real > &fz, const amrex::Box &fxbox, const amrex::Box &fybox, const amrex::Box &fzbox, int dir, amrex::Real &flux_in, amrex::Real &flux_out)
Sum fluxes on the inlet (low) and outlet (high) domain faces.
Definition TortuosityKernels.H:218
void removeIsolatedCells(int *q, const int *q_lo, const int *q_hi, int, const int *bxlo, const int *bxhi, const int *domlo, const int *domhi)
Remove isolated single cells by checking 6-connectivity.
Definition TortuosityKernels.H:52
void forwardEulerUpdate(const amrex::Box &bx, const amrex::Array4< const amrex::Real > &p_arr, const amrex::Array4< amrex::Real > &n_arr, const amrex::Array4< const amrex::Real > &fx, const amrex::Array4< const amrex::Real > &fy, const amrex::Array4< const amrex::Real > &fz, const amrex::Real *dxinv, amrex::Real dt)
Forward Euler update: phi_new = phi_old + dt * div(flux).
Definition TortuosityKernels.H:182
void computeFaceFluxes(const amrex::Box &bx, const amrex::Array4< amrex::Real > &fx, const amrex::Array4< amrex::Real > &fy, const amrex::Array4< amrex::Real > &fz, const amrex::Array4< const amrex::Real > &sol, const amrex::Real *dxinv)
Compute face fluxes using finite differences on a cell-centred solution.
Definition TortuosityKernels.H:108