Skip to content

Commit d66258f

Browse files
MattRolchigostreeve
authored andcommitted
Avoid potential float precision error in temperature translation
1 parent 529f62b commit d66258f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/CAtemperature.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ struct Temperature {
141141
// Based on the X coordinate compared to the global domain bounds and the Y coordinate compared to the MPI rank Y
142142
// bounds (integers), return whether or not this translated coordinate is in bounds on this rank
143143
bool translatedXYInBounds(const double x_translated, const double y_translated, const Grid grid) {
144+
const int coord_x = Kokkos::round((x_translated - grid.x_min) / grid.deltax);
144145
const int coord_y_global = Kokkos::round((y_translated - grid.y_min) / grid.deltax);
145146
bool xy_in_bounds;
146-
if ((grid.x_min <= x_translated) && (grid.x_max >= x_translated) && (coord_y_global >= grid.y_offset) &&
147+
if ((coord_x >= 0) && (coord_x < grid.nx) && (coord_y_global >= grid.y_offset) &&
147148
(coord_y_global < grid.y_offset + grid.ny_local))
148149
xy_in_bounds = true;
149150
else

0 commit comments

Comments
 (0)