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 diff --git a/unit_test/tstTemperature.hpp b/unit_test/tstTemperature.hpp index e00795ba..834fe749 100644 --- a/unit_test/tstTemperature.hpp +++ b/unit_test/tstTemperature.hpp @@ -328,7 +328,7 @@ void checkTemperatureResults(Inputs &inputs, Grid &grid, Temperature(grid.nx - coord_x); + loc_along_scan = static_cast((grid.nx - 1) - coord_x); else loc_along_scan = static_cast(coord_x); const double expected_tm = loc_along_scan + static_cast(coord_y) * inputs.temperature.temporal_offset; @@ -358,35 +358,27 @@ void checkTemperatureResults(Inputs &inputs, Grid &grid, Temperature; - - int id, np; - // Get number of processes - MPI_Comm_size(MPI_COMM_WORLD, &np); - // Get individual process ID - MPI_Comm_rank(MPI_COMM_WORLD, &id); - - // Default inputs struct - manually set temperature values for test - Inputs inputs; +// Initialize test input values for InitTemperatureFromFinch and InitTemperatureFromFile +void initTestInputs(const bool mirror_x, const int number_of_copies, Inputs &inputs) { inputs.temperature.x_offset = 0.0; inputs.temperature.y_offset = 1.0 * pow(10, -6); inputs.temperature.mirror_x = mirror_x; inputs.temperature.mirror_y = false; inputs.temperature.temporal_offset = 100.0; inputs.temperature.number_of_copies = number_of_copies; +} - // Default grid struct - manually set up domain for test - Grid grid; +// Initialize test grid for InitTemperatureFromFinch and InitTemperatureFromFile +void initTestGrid(const int id, const int np, Grid &grid) { grid.deltax = 1.0 * pow(10, -6); grid.x_min = -2.0 * pow(10, -6); grid.nx = 2; + grid.x_max = grid.x_min + grid.deltax * (grid.nx - 1); grid.y_min = 0.0; grid.ny_local = 3; + grid.ny = grid.ny_local * np; grid.y_offset = id * grid.ny_local; + grid.y_max = grid.y_min + grid.deltax * (grid.ny - 1); grid.z_min = 0.0; grid.z_min_layer[0] = grid.z_min; grid.nz = np; @@ -395,6 +387,26 @@ void testInitTemperatureFromFinch(const bool mirror_x, const int number_of_copie grid.number_of_layers = 1; grid.layer_height = 0; grid.layer_range = std::make_pair(0, grid.domain_size); +} + +// Test storing temperature data from Finch on the correct ExaCA ranks, optionally mirroring and translating the data +void testInitTemperatureFromFinch(const bool mirror_x, const int number_of_copies) { + + using memory_space = TEST_MEMSPACE; + using view_type_coupled = Kokkos::View; + + int id, np; + // Get number of processes + MPI_Comm_size(MPI_COMM_WORLD, &np); + // Get individual process ID + MPI_Comm_rank(MPI_COMM_WORLD, &id); + + // Default inputs struct - manually set temperature values for test + Inputs inputs; + // Default grid struct - manually set up domain for test + Grid grid; + initTestInputs(mirror_x, number_of_copies, inputs); + initTestGrid(id, np, grid); // Create dummy Finch temperature data stored on various ranks, to be mapped to ExaCA ranks view_type_coupled input_temperature_data(Kokkos::ViewAllocateWithoutInitializing("FinchData"), grid.nx * np, 6); @@ -435,29 +447,10 @@ void testInitTemperatureFromFile(const bool mirror_x, const int number_of_copies // Default inputs struct - manually set temperature values for test Inputs inputs; - inputs.temperature.x_offset = 0.0; - inputs.temperature.y_offset = 1.0 * pow(10, -6); - inputs.temperature.mirror_x = mirror_x; - inputs.temperature.mirror_y = false; - inputs.temperature.temporal_offset = 100.0; - inputs.temperature.number_of_copies = number_of_copies; - // Default grid struct - manually set up domain for test Grid grid; - grid.deltax = 1.0 * pow(10, -6); - grid.x_min = -2.0 * pow(10, -6); - grid.nx = 2; - grid.y_min = 0.0; - grid.ny_local = 3; - grid.y_offset = id * grid.ny_local; - grid.z_min = 0.0; - grid.z_min_layer[0] = grid.z_min; - grid.nz = np; - grid.domain_size = grid.nx * grid.ny_local * grid.nz; - grid.domain_size_all_layers = grid.domain_size; - grid.number_of_layers = 1; - grid.layer_height = 0; - grid.layer_range = std::make_pair(0, grid.domain_size); + initTestInputs(mirror_x, number_of_copies, inputs); + initTestGrid(id, np, grid); // Create dummy file temperature data on rank 0, including data to be mapped to other ExaCA ranks if (id == 0) {