From 9f1d69982d3b6ac6bfd6f5ca6d80593cff4a47d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Thu, 25 Sep 2025 15:08:13 +0200 Subject: [PATCH] feat(grid): enable cell_ID integration in chemistry data flow --- R_lib/init_r_lib.R | 3 +++ src/Chemistry/WorkerFunctions.cpp | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/R_lib/init_r_lib.R b/R_lib/init_r_lib.R index f3f1adeed..aa82998bd 100644 --- a/R_lib/init_r_lib.R +++ b/R_lib/init_r_lib.R @@ -60,6 +60,9 @@ pqc_to_grid <- function(pqc_mat, grid) { # Convert the result matrix to a data frame res_df <- as.data.frame(result_mat) + # Add cell_ID column to beginning of res_df + res_df <- cbind(cell_ID = seq(0, nrow(res_df) - 1), res_df) + # Remove all columns which only contain NaN # res_df <- res_df[, colSums(is.na(res_df)) != nrow(res_df)] diff --git a/src/Chemistry/WorkerFunctions.cpp b/src/Chemistry/WorkerFunctions.cpp index 11c70d7cc..b354f986d 100644 --- a/src/Chemistry/WorkerFunctions.cpp +++ b/src/Chemistry/WorkerFunctions.cpp @@ -428,14 +428,23 @@ namespace poet { to_ignore.push_back(wp_id); } - } + + // HACK: remove the first element (cell_id) before sending to phreeqc + inout_chem[wp_id].erase( + inout_chem[wp_id].begin(), inout_chem[wp_id].begin() + 1); + } + this->pqc_runner->run(inout_chem, dTimestep, to_ignore); for (std::size_t wp_id = 0; wp_id < work_package.size; wp_id++) { if (work_package.mapping[wp_id] == CHEM_PQC) { - work_package.output[wp_id] = inout_chem[wp_id]; + // HACK: as we removed the first element (cell_id) before sending to phreeqc, + // copy back with an offset of 1 + work_package.output[wp_id] = work_package.input[wp_id]; + std::copy(inout_chem[wp_id].begin(), inout_chem[wp_id].end(), + work_package.output[wp_id].begin() + 1); } } }