Skip to content

Commit

Permalink
Update euler_grid.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-bournes authored Feb 23, 2024
1 parent 58eb159 commit 3616771
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/core/diffusion/euler_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ void EulerGrid::DiffuseWithNeumann(real_t dt) {
b = c - nx * ny;
t = c + nx * ny;

real_t left = c1_[c - 1];
real_t right = c1_[c + 1];
real_t bottom = c1_[b];
real_t top = c1_[t];
real_t north = c1_[n];
real_t south = c1_[s];
// Clamp to avoid out of bounds access. Clamped values are initialized
// to a wrong value but will be overwritten by the boundary condition
// evaluation. All other values are correct.
real_t left{c1_[std::clamp(l, size_t{0}, num_boxes - 1)]};
real_t right{c1_[std::clamp(r, size_t{0}, num_boxes - 1)]};
real_t bottom{c1_[std::clamp(b, size_t{0}, num_boxes - 1)]};
real_t top{c1_[std::clamp(t, size_t{0}, num_boxes - 1)]};
real_t north{c1_[std::clamp(n, size_t{0}, num_boxes - 1)]};
real_t south{c1_[std::clamp(s, size_t{0}, num_boxes - 1)]};
real_t center_factor{6.0};

if (x == 0 || x == (nx - 1) || y == 0 || y == (ny - 1) || z == 0 ||
Expand Down Expand Up @@ -335,12 +338,15 @@ void EulerGrid::DiffuseWithPeriodic(real_t dt) {
b = c - nx * ny;
t = c + nx * ny;

real_t left = c1_[l];
real_t right = c1_[r];
real_t bottom = c1_[b];
real_t top = c1_[t];
real_t north = c1_[n];
real_t south = c1_[s];
// Clamp to avoid out of bounds access. Clamped values are initialized
// to a wrong value but will be overwritten by the boundary condition
// evaluation. All other values are correct.
real_t left{c1_[std::clamp(l, size_t{0}, num_boxes - 1)]};
real_t right{c1_[std::clamp(r, size_t{0}, num_boxes - 1)]};
real_t bottom{c1_[std::clamp(b, size_t{0}, num_boxes - 1)]};
real_t top{c1_[std::clamp(t, size_t{0}, num_boxes - 1)]};
real_t north{c1_[std::clamp(n, size_t{0}, num_boxes - 1)]};
real_t south{c1_[std::clamp(s, size_t{0}, num_boxes - 1)]};

if (x == 0 || x == (nx - 1) || y == 0 || y == (ny - 1) || z == 0 ||
z == (nz - 1)) {
Expand Down

0 comments on commit 3616771

Please sign in to comment.