From 60298c379cfa457e6e0f6173d5072215f21bc75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Fri, 20 Dec 2024 08:35:00 +0100 Subject: [PATCH] Revert "feat: make output of H(0) and O(0) optional" This reverts commit bdb5ce944fd001cb36c8369d8c792f2f4a54c7be. --- src/Init/DiffusionInit.cpp | 12 +++--- src/Init/GridInit.cpp | 75 ++++++++------------------------------ src/Init/InitialList.cpp | 11 ++---- src/Init/InitialList.hpp | 22 ++++------- src/initializer.cpp | 5 --- 5 files changed, 34 insertions(+), 91 deletions(-) diff --git a/src/Init/DiffusionInit.cpp b/src/Init/DiffusionInit.cpp index 7b5d9680b..7abd987ec 100644 --- a/src/Init/DiffusionInit.cpp +++ b/src/Init/DiffusionInit.cpp @@ -3,6 +3,7 @@ // Rcpp include #include +#include #include "DataStructures/Field.hpp" #include "InitialList.hpp" @@ -14,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -24,9 +26,9 @@ namespace poet { enum SEXP_TYPE { SEXP_IS_LIST, SEXP_IS_VEC }; const std::map tug_side_mapping = { - {tug::BC_SIDE_RIGHT, "E"}, - {tug::BC_SIDE_LEFT, "W"}, - {tug::BC_SIDE_TOP, "N"}, + {tug::BC_SIDE_RIGHT , "E"}, + {tug::BC_SIDE_LEFT , "W"}, + {tug::BC_SIDE_TOP , "N"}, {tug::BC_SIDE_BOTTOM, "S"}}; static std::vector colMajToRowMaj(const Rcpp::NumericVector &vec, @@ -164,8 +166,8 @@ InitialList::resolveBoundaries(const Rcpp::List &boundaries_list, if (boundaries_list.containsElementNamed(side.second.c_str())) { const Rcpp::List mapping = boundaries_list[side.second]; - const Rcpp::IntegerVector cells = mapping["cell"]; // MDL 2024-06-13 - const Rcpp::IntegerVector values = mapping["sol_id"]; // MDL + const Rcpp::IntegerVector cells = mapping["cell"]; // MDL 2024-06-13 + const Rcpp::IntegerVector values = mapping["sol_id"]; // MDL const Rcpp::CharacterVector type_str = mapping["type"]; if (cells.size() != values.size()) { diff --git a/src/Init/GridInit.cpp b/src/Init/GridInit.cpp index 63b33a628..d3ee24d5f 100644 --- a/src/Init/GridInit.cpp +++ b/src/Init/GridInit.cpp @@ -15,42 +15,6 @@ namespace poet { -// static Rcpp::NumericMatrix pqcMatToR(const PhreeqcMatrix &phreeqc, RInside -// &R) { - -// PhreeqcMatrix::STLExport phreeqc_mat = phreeqc.get(); - -// // PhreeqcInit::PhreeqcMat phreeqc_mat = phreeqc->getPhreeqcMat(); - -// // add "id" to the front of the column names - -// const std::size_t ncols = phreeqc_mat.names.size(); -// const std::size_t nrows = phreeqc_mat.values.size(); - -// phreeqc_mat.names.insert(phreeqc_mat.names.begin(), "ID"); - -// Rcpp::NumericMatrix mat(nrows, ncols + 1); - -// for (std::size_t i = 0; i < nrows; i++) { -// mat(i, 0) = phreeqc_mat.ids[i]; -// for (std::size_t j = 0; j < ncols; ++j) { -// mat(i, j + 1) = phreeqc_mat.values[i][j]; -// } -// } - -// Rcpp::colnames(mat) = Rcpp::wrap(phreeqc_mat.names); - -// return mat; -// } - -// static inline Rcpp::List matToGrid(RInside &R, const Rcpp::NumericMatrix -// &mat, -// const Rcpp::NumericMatrix &grid) { -// Rcpp::Function pqc_to_grid_R("pqc_to_grid"); - -// return pqc_to_grid_R(mat, grid); -// } - static inline std::map replaceRawKeywordIDs(std::map raws) { for (auto &raw : raws) { @@ -64,26 +28,6 @@ replaceRawKeywordIDs(std::map raws) { return raws; } -// static inline uint32_t getSolutionCount(std::unique_ptr -// &phreeqc, -// const Rcpp::List &initial_grid) { -// PhreeqcInit::ModulesArray mod_array; -// Rcpp::Function unique_R("unique"); - -// std::vector row_ids = -// Rcpp::as>(unique_R(initial_grid["ID"])); - -// // std::vector sizes_vec(sizes.begin(), sizes.end()); - -// // Rcpp::Function modify_sizes("modify_module_sizes"); -// // sizes_vec = Rcpp::as>( -// // modify_sizes(sizes_vec, phreeqc_mat, initial_grid)); - -// // std::copy(sizes_vec.begin(), sizes_vec.end(), sizes.begin()); - -// return phreeqc->getModuleSizes(row_ids)[POET_SOL]; -// } - static std::string readFile(const std::string &path) { std::string string_rpath(PATH_MAX, '\0'); @@ -121,8 +65,7 @@ static Rcpp::List expandGrid(const PhreeqcMatrix &pqc_mat, return Rcpp::Function("pqc_to_grid")(pqc_mat_R, grid_def); } -PhreeqcMatrix InitialList::prepareGrid(const Rcpp::List &grid_input, - bool include_h0_o0) { +PhreeqcMatrix InitialList::prepareGrid(const Rcpp::List &grid_input) { // parse input values std::string script; std::string database; @@ -186,11 +129,23 @@ PhreeqcMatrix InitialList::prepareGrid(const Rcpp::List &grid_input, grid_input[GRID_MEMBER_STR(GridMembers::PQC_WITH_REDOX)]) : false; - this->with_h0_o0 = include_h0_o0; + bool with_h0_o0 = + grid_input.containsElementNamed( + GRID_MEMBER_STR(GridMembers::PQC_WITH_H0_O0)) + ? Rcpp::as( + grid_input[GRID_MEMBER_STR(GridMembers::PQC_WITH_H0_O0)]) + : false; + + if (with_h0_o0 && !with_redox) { + throw std::runtime_error( + "Output of H(0) and O(0) can only be used with redox."); + } + + this->with_h0_o0 = with_h0_o0; this->with_redox = with_redox; PhreeqcMatrix pqc_mat = - PhreeqcMatrix(database, script, include_h0_o0, with_redox); + PhreeqcMatrix(database, script, with_h0_o0, with_redox); this->transport_names = pqc_mat.getSolutionNames(); diff --git a/src/Init/InitialList.cpp b/src/Init/InitialList.cpp index c6282977d..25203ebce 100644 --- a/src/Init/InitialList.cpp +++ b/src/Init/InitialList.cpp @@ -10,9 +10,8 @@ #include namespace poet { -void InitialList::initializeFromList(const Rcpp::List &setup, - bool include_h0_o0) { - PhreeqcMatrix phreeqc = prepareGrid(setup[grid_key], include_h0_o0); +void InitialList::initializeFromList(const Rcpp::List &setup) { + PhreeqcMatrix phreeqc = prepareGrid(setup[grid_key]); initDiffusion(setup[diffusion_key], phreeqc); initChemistry(setup[chemistry_key]); } @@ -89,8 +88,7 @@ void InitialList::importList(const Rcpp::List &setup, bool minimal) { this->chem_hooks = Rcpp::as(setup[static_cast(ExportList::CHEM_HOOKS)]); - this->ai_surrogate_input_script = Rcpp::as( - setup[static_cast(ExportList::AI_SURROGATE_INPUT_SCRIPT)]); + this->ai_surrogate_input_script = Rcpp::as(setup[static_cast(ExportList::AI_SURROGATE_INPUT_SCRIPT)]); } Rcpp::List InitialList::exportList() { @@ -142,8 +140,7 @@ Rcpp::List InitialList::exportList() { out[static_cast(ExportList::CHEM_INTERP_SPECIES)] = Rcpp::wrap(this->interp_species); out[static_cast(ExportList::CHEM_HOOKS)] = this->chem_hooks; - out[static_cast(ExportList::AI_SURROGATE_INPUT_SCRIPT)] = - this->ai_surrogate_input_script; + out[static_cast(ExportList::AI_SURROGATE_INPUT_SCRIPT)] = this->ai_surrogate_input_script; return out; } diff --git a/src/Init/InitialList.hpp b/src/Init/InitialList.hpp index 64c2fd08c..576828002 100644 --- a/src/Init/InitialList.hpp +++ b/src/Init/InitialList.hpp @@ -26,9 +26,9 @@ using TugType = double; class InitialList { public: - InitialList(RInside &R) : R(R) {}; + InitialList(RInside &R) : R(R){}; - void initializeFromList(const Rcpp::List &setup, bool include_h0_o0 = false); + void initializeFromList(const Rcpp::List &setup); void importList(const Rcpp::List &setup, bool minimal = false); Rcpp::List exportList(); @@ -56,14 +56,6 @@ private: CHEM_PQC_WITH_REDOX, CHEM_PQC_IDS, CHEM_FIELD_HEADER, - // CHEM_PQC_SCRIPTS, - // CHEM_PQC_SOLUTIONS, - // CHEM_PQC_SOLUTION_PRIMARY, - // CHEM_PQC_EXCHANGER, - // CHEM_PQC_KINETICS, - // CHEM_PQC_EQUILIBRIUM, - // CHEM_PQC_SURFACE_COMPS, - // CHEM_PQC_SURFACE_CHARGES, CHEM_DHT_SPECIES, CHEM_INTERP_SPECIES, CHEM_HOOKS, @@ -78,6 +70,7 @@ private: PQC_SCRIPT_STRING, PQC_SCRIPT_FILE, PQC_WITH_REDOX, + PQC_WITH_H0_O0, PQC_DB_STRING, PQC_DB_FILE, GRID_DEF, @@ -91,9 +84,10 @@ private: static_cast(InitialList::GridMembers::ENUM_SIZE); static constexpr std::array - GridMembersString = {"pqc_in_string", "pqc_in_file", "pqc_with_redox", - "pqc_db_string", "pqc_db_file", "grid_def", - "grid_size", "constant_cells", "porosity"}; + GridMembersString = {"pqc_in_string", "pqc_in_file", "pqc_with_redox", + "pqc_wth_h0_o0", "pqc_db_string", "pqc_db_file", + "grid_def", "grid_size", "constant_cells", + "porosity"}; constexpr const char *GRID_MEMBER_STR(GridMembers member) const { return GridMembersString[static_cast(member)]; @@ -101,7 +95,7 @@ private: // std::unique_ptr pqc_mat; - PhreeqcMatrix prepareGrid(const Rcpp::List &grid_input, bool include_h0_o0); + PhreeqcMatrix prepareGrid(const Rcpp::List &grid_input); std::uint8_t dim{0}; diff --git a/src/initializer.cpp b/src/initializer.cpp index dd99b4ce4..dd7e4ddd0 100644 --- a/src/initializer.cpp +++ b/src/initializer.cpp @@ -40,11 +40,6 @@ int main(int argc, char **argv) { bool asQS{false}; app.add_flag("-q, --qs", asQS, "Save output as .qs")->default_val(false); - bool includeH0O0{false}; - app.add_flag("--include-h0-o0", includeH0O0, - "Include H(0) and O(0) in the output") - ->default_val(false); - CLI11_PARSE(app, argc, argv); // source the input script