From 71253dacae98f79ef7f0666c00e587fec8458e11 Mon Sep 17 00:00:00 2001 From: "clara.bayley" Date: Fri, 20 Sep 2024 23:26:51 +0200 Subject: [PATCH] refactor: alternative attempt to fix calculation of source index for winds using yac edges fields --- libs/coupldyn_yac/yac_cartesian_dynamics.cpp | 14 +++++++++----- libs/coupldyn_yac/yac_cartesian_dynamics.hpp | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/coupldyn_yac/yac_cartesian_dynamics.cpp b/libs/coupldyn_yac/yac_cartesian_dynamics.cpp index 465e21e9..6857fe6f 100644 --- a/libs/coupldyn_yac/yac_cartesian_dynamics.cpp +++ b/libs/coupldyn_yac/yac_cartesian_dynamics.cpp @@ -9,7 +9,7 @@ * Author: Wilton Loch (WL) * Additional Contributors: Clara Bayley (CB) * ----- - * Last Modified: Monday 9th September 2024 + * Last Modified: Friday 20th September 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -170,8 +170,8 @@ void CartesianDynamics::receive_yac_field(const unsigned int grid_points, for (size_t i = 0; i < ndims_east; i++) { for (size_t k = 0; k < vertical_levels; k++) { auto vertical_idx = k; - auto edges_ndims_east = ndims_east * 2 - 1; - auto source_idx = edges_ndims_east * j + ndims_east - 1 + i; + auto source_idx = (ndims_east - 1) * j + ndims_east * j; + source_idx += std::min(2 * i + 1, 2 * ndims_east - 2); auto ii = (ndims_east * j + i) * vertical_levels + k; target_array[ii] = yac_raw_data[vertical_idx][source_idx] / conversion_factor; } @@ -187,8 +187,12 @@ void CartesianDynamics::receive_yac_field(const unsigned int grid_points, for (size_t i = 0; i < ndims_east; i++) { for (size_t k = 0; k < vertical_levels; k++) { auto vertical_idx = k; - auto edges_ndims_east = ndims_east * 2 + 1; - auto source_idx = edges_ndims_east * j + i; + auto source_idx = ndims_east * j + (ndims_east + 1) * j; + if (j < ndims_north - 1) { + source_idx += 2 * i; + } else { + source_idx += i; + } auto ii = (ndims_east * j + i) * vertical_levels + k; target_array[ii] = yac_raw_data[vertical_idx][source_idx] / conversion_factor; } diff --git a/libs/coupldyn_yac/yac_cartesian_dynamics.hpp b/libs/coupldyn_yac/yac_cartesian_dynamics.hpp index 2b457bd9..f61bb306 100644 --- a/libs/coupldyn_yac/yac_cartesian_dynamics.hpp +++ b/libs/coupldyn_yac/yac_cartesian_dynamics.hpp @@ -9,7 +9,7 @@ * Author: Clara Bayley (CB) * Additional Contributors: * ----- - * Last Modified: Wednesday 4th September 2024 + * Last Modified: Friday 20th September 2024 * Modified By: CB * ----- * License: BSD 3-Clause "New" or "Revised" License @@ -23,6 +23,7 @@ #ifndef LIBS_COUPLDYN_YAC_YAC_CARTESIAN_DYNAMICS_HPP_ #define LIBS_COUPLDYN_YAC_YAC_CARTESIAN_DYNAMICS_HPP_ +#include #include #include #include