From d66258f82f5dba58621f1c5ee662ae160438ed93 Mon Sep 17 00:00:00 2001 From: MattRolchigo <65y@ornl.gov> Date: Fri, 27 Sep 2024 16:38:59 -0400 Subject: [PATCH] Avoid potential float precision error in temperature translation --- src/CAtemperature.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CAtemperature.hpp b/src/CAtemperature.hpp index 141abd09..678c7561 100644 --- a/src/CAtemperature.hpp +++ b/src/CAtemperature.hpp @@ -141,9 +141,10 @@ struct Temperature { // Based on the X coordinate compared to the global domain bounds and the Y coordinate compared to the MPI rank Y // bounds (integers), return whether or not this translated coordinate is in bounds on this rank bool translatedXYInBounds(const double x_translated, const double y_translated, const Grid grid) { + const int coord_x = Kokkos::round((x_translated - grid.x_min) / grid.deltax); const int coord_y_global = Kokkos::round((y_translated - grid.y_min) / grid.deltax); bool xy_in_bounds; - if ((grid.x_min <= x_translated) && (grid.x_max >= x_translated) && (coord_y_global >= grid.y_offset) && + if ((coord_x >= 0) && (coord_x < grid.nx) && (coord_y_global >= grid.y_offset) && (coord_y_global < grid.y_offset + grid.ny_local)) xy_in_bounds = true; else