From 1f586f1748569a8bf3639c33ca5f79c9ac34f7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Tue, 10 Sep 2024 09:10:33 +0200 Subject: [PATCH] feat: remove header dependency to c++20 features --- poet/include/PhreeqcEngine.hpp | 76 ++----- poet/src/Engine.cpp | 200 ++++++++---------- poet/src/InitGetSet.cpp | 10 +- .../{ => Wrapper}/EquilibriumCompWrapper.cpp | 0 poet/src/{ => Wrapper}/EquilibriumWrapper.cpp | 0 .../Wrapper}/EquilibriumWrapper.hpp | 0 .../src/{ => Wrapper}/ExchangeCompWrapper.cpp | 0 poet/src/{ => Wrapper}/ExchangeWrapper.cpp | 0 .../Wrapper}/ExchangeWrapper.hpp | 0 poet/src/{ => Wrapper}/KineticCompWrapper.cpp | 0 poet/src/{ => Wrapper}/KineticWrapper.cpp | 0 .../Wrapper}/KineticWrapper.hpp | 0 poet/src/{ => Wrapper}/SolutionWrapper.cpp | 0 .../Wrapper}/SolutionWrapper.hpp | 0 .../{ => Wrapper}/SurfaceChargeWrapper.cpp | 0 poet/src/{ => Wrapper}/SurfaceCompWrapper.cpp | 0 poet/src/{ => Wrapper}/SurfaceWrapper.cpp | 0 .../Wrapper}/SurfaceWrapper.hpp | 0 poet/{include => src/Wrapper}/WrapperBase.hpp | 0 19 files changed, 103 insertions(+), 183 deletions(-) rename poet/src/{ => Wrapper}/EquilibriumCompWrapper.cpp (100%) rename poet/src/{ => Wrapper}/EquilibriumWrapper.cpp (100%) rename poet/{include => src/Wrapper}/EquilibriumWrapper.hpp (100%) rename poet/src/{ => Wrapper}/ExchangeCompWrapper.cpp (100%) rename poet/src/{ => Wrapper}/ExchangeWrapper.cpp (100%) rename poet/{include => src/Wrapper}/ExchangeWrapper.hpp (100%) rename poet/src/{ => Wrapper}/KineticCompWrapper.cpp (100%) rename poet/src/{ => Wrapper}/KineticWrapper.cpp (100%) rename poet/{include => src/Wrapper}/KineticWrapper.hpp (100%) rename poet/src/{ => Wrapper}/SolutionWrapper.cpp (100%) rename poet/{include => src/Wrapper}/SolutionWrapper.hpp (100%) rename poet/src/{ => Wrapper}/SurfaceChargeWrapper.cpp (100%) rename poet/src/{ => Wrapper}/SurfaceCompWrapper.cpp (100%) rename poet/src/{ => Wrapper}/SurfaceWrapper.cpp (100%) rename poet/{include => src/Wrapper}/SurfaceWrapper.hpp (100%) rename poet/{include => src/Wrapper}/WrapperBase.hpp (100%) diff --git a/poet/include/PhreeqcEngine.hpp b/poet/include/PhreeqcEngine.hpp index fd455d90..91ae9a2c 100644 --- a/poet/include/PhreeqcEngine.hpp +++ b/poet/include/PhreeqcEngine.hpp @@ -1,49 +1,35 @@ - #pragma once -#include "EquilibriumWrapper.hpp" -#include "ExchangeWrapper.hpp" -#include "KineticWrapper.hpp" #include "POETInit.hpp" -#include "SolutionWrapper.hpp" -#include "SurfaceWrapper.hpp" -#include - -#include -#include -#include -#include -#include -#include -#include #include -#include -#include #include /** * @brief Class for running Phreeqc wrappped in POET * - * Direct interface to Phreeqc, without utilizing *_MODIFY keywords/scripts to + * Direct interface to Phreeqc, without utilizing *_MODIFY keywords/scripts + to * set new values. Use with already initialized Phreeqc config. * */ -class PhreeqcEngine : public IPhreeqc { +class PhreeqcEngine { public: /** * @brief Construct a new Phreeqc Engine object * - * Construct a new Phreeqc Engine object by previously initialized POETConfig. + * Construct a new Phreeqc Engine object by previously initialized + POETConfig. * * @param config Holds the configuration for the Phreeqc engine. */ - PhreeqcEngine(const POETConfig &config) : IPhreeqc() { - this->LoadDatabaseString(config.database.c_str()); - this->RunString(config.input_script.c_str()); + PhreeqcEngine(const POETConfig &config); - this->init_wrappers(config.cell); - } + /** + * @brief Destroy the Phreeqc Engine object + * + */ + ~PhreeqcEngine(); /** * @brief Siimulate a cell for a given time step @@ -56,42 +42,6 @@ public: void runCell(std::vector &cell_values, double time_step); private: - void init_wrappers(const POETInitCell &cell); - void run(double time_step); - - cxxSolution *Get_solution(std::size_t n) { - return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_solution_map(), n); - } - - cxxExchange *Get_exchange(std::size_t n) { - return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_exchange_map(), n); - } - - cxxKinetics *Get_kinetic(std::size_t n) { - return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_kinetics_map(), n); - } - - cxxPPassemblage *Get_equilibrium(std::size_t n) { - return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_pp_assemblage_map(), - n); - } - - cxxSurface *Get_surface(std::size_t n) { - return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_surface_map(), n); - } - - void get_essential_values(std::span &data); - - void set_essential_values(const std::span &data); - - std::unique_ptr solutionWrapperPtr; - std::unique_ptr exchangeWrapperPtr; - std::unique_ptr kineticsWrapperPtr; - std::unique_ptr equilibriumWrapperPtr; - std::unique_ptr surfaceWrapperPtr; - - bool has_exchange = false; - bool has_kinetics = false; - bool has_equilibrium = false; - bool has_surface = false; + class Impl; + std::unique_ptr impl; }; \ No newline at end of file diff --git a/poet/src/Engine.cpp b/poet/src/Engine.cpp index f3af6f1d..c74b73da 100644 --- a/poet/src/Engine.cpp +++ b/poet/src/Engine.cpp @@ -4,7 +4,89 @@ #include #include -void PhreeqcEngine::init_wrappers(const POETInitCell &cell) { +#include +#include + +#include "Wrapper/EquilibriumWrapper.hpp" +#include "Wrapper/ExchangeWrapper.hpp" +#include "Wrapper/KineticWrapper.hpp" +#include "Wrapper/SolutionWrapper.hpp" +#include "Wrapper/SurfaceWrapper.hpp" +class PhreeqcEngine::Impl : public IPhreeqc { +public: + Impl(const POETConfig &config); + void init_wrappers(const POETInitCell &cell); + void run(double time_step); + + cxxSolution *Get_solution(std::size_t n) { + return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_solution_map(), n); + } + + cxxExchange *Get_exchange(std::size_t n) { + return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_exchange_map(), n); + } + + cxxKinetics *Get_kinetic(std::size_t n) { + return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_kinetics_map(), n); + } + + cxxPPassemblage *Get_equilibrium(std::size_t n) { + return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_pp_assemblage_map(), + n); + } + + cxxSurface *Get_surface(std::size_t n) { + return Utilities::Rxn_find(this->PhreeqcPtr->Get_Rxn_surface_map(), n); + } + + void get_essential_values(std::span &data); + + void set_essential_values(const std::span &data); + + std::unique_ptr solutionWrapperPtr; + std::unique_ptr exchangeWrapperPtr; + std::unique_ptr kineticsWrapperPtr; + std::unique_ptr equilibriumWrapperPtr; + std::unique_ptr surfaceWrapperPtr; + + bool has_exchange = false; + bool has_kinetics = false; + bool has_equilibrium = false; + bool has_surface = false; +}; + +PhreeqcEngine::PhreeqcEngine(const POETConfig &config) + : impl(std::make_unique(config)) {} + +PhreeqcEngine::Impl::Impl(const POETConfig &config) { + this->LoadDatabaseString(config.database.c_str()); + this->RunString(config.input_script.c_str()); + + this->init_wrappers(config.cell); +} + +PhreeqcEngine::~PhreeqcEngine() = default; + +void PhreeqcEngine::runCell(std::vector &cell_values, + double time_step) { + // skip ID + std::span cell_data{cell_values.begin() + 1, cell_values.end()}; + + this->impl->set_essential_values(cell_data); + this->impl->run(time_step); + this->impl->get_essential_values(cell_data); +} + +void PhreeqcEngine::Impl::run(double time_step) { + std::stringstream time_ss; + time_ss << std::fixed << std::setprecision(20) << time_step; + + const std::string runs_string = + "RUN_CELLS\n -cells 1\n -time_step " + time_ss.str() + "\nEND\n"; + this->RunString(runs_string.c_str()); +} + +void PhreeqcEngine::Impl::init_wrappers(const POETInitCell &cell) { // Solutions this->solutionWrapperPtr = @@ -41,7 +123,7 @@ void PhreeqcEngine::init_wrappers(const POETInitCell &cell) { } } -void PhreeqcEngine::get_essential_values(std::span &data) { +void PhreeqcEngine::Impl::get_essential_values(std::span &data) { this->solutionWrapperPtr->get(data); @@ -76,54 +158,9 @@ void PhreeqcEngine::get_essential_values(std::span &data) { data.subspan(offset, this->surfaceWrapperPtr->size())}; this->surfaceWrapperPtr->get(surf_span); } - - // // Exchange - // if (this->Get_exchange(cell_number) != NULL) { - // std::vector exch_values(this->exchangeWrapperPtr->size()); - - // std::span exch_span{exch_values}; - - // this->exchangeWrapperPtr->get(exch_span); - - // // this->Get_exchange(cell_number)->get_essential_values(exch_values); - // essentials.insert(essentials.end(), exch_values.begin(), - // exch_values.end()); - // } - - // // Kinetics - // if (this->Get_kinetic(cell_number) != NULL) { - // std::vector kin_values; - - // this->Get_kinetic(cell_number)->get_essential_values(kin_values); - // essentials.insert(essentials.end(), kin_values.begin(), - // kin_values.end()); - // } - - // // PPassemblage - // if (this->Get_equilibrium(cell_number) != NULL) { - // std::vector equ_values; - - // this->Get_equilibrium(cell_number)->get_essential_values(equ_values); - // essentials.insert(essentials.end(), equ_values.begin(), - // equ_values.end()); - // } - - // // Surface - // if (this->Get_surface(cell_number) != NULL) { - // std::vector surf_values(this->surfaceWrapperPtr->size()); - // std::span surf_span{surf_values}; - - // this->surfaceWrapperPtr->get(surf_span); - - // // this->Get_surface(cell_number)->get_essential_values(surf_values); - // essentials.insert(essentials.end(), surf_values.begin(), - // surf_values.end()); - // } - - // return essentials; } -void PhreeqcEngine::set_essential_values(const std::span &data) { +void PhreeqcEngine::Impl::set_essential_values(const std::span &data) { this->solutionWrapperPtr->set(data); this->PhreeqcPtr->initial_solutions_poet(1); @@ -159,71 +196,4 @@ void PhreeqcEngine::set_essential_values(const std::span &data) { data.subspan(offset, this->surfaceWrapperPtr->size())}; this->surfaceWrapperPtr->set(surf_span); } - - // // Solutions - // if (this->Get_solution(cell_number) != NULL) { - // this->Get_solution(cell_number)->set_essential_values(dump_it, order); - // this->PhreeqcPtr->initial_solutions_poet(cell_number); - // } - - // // Exchange - // if (this->Get_exchange(cell_number) != NULL) { - // auto &exch_pointer = this->exchangeWrapperPtr; - // std::span exch_span{dump_it, exch_pointer->size()}; - // exch_pointer->set(exch_span); - - // dump_it += exch_pointer->size(); - - // // this->Get_exchange(cell_number)->set_essential_values(dump_it); - // // this->PhreeqcPtr->Rxn_new_exchange.insert(cell_number); - // // this->Get_exchange(cell_number)->Set_new_def(true); - // // this->Get_exchange(cell_number)->Set_solution_equilibria(true); - // // this->Get_exchange(cell_number)->Set_n_solution(cell_number); - // // this->PhreeqcPtr->initial_exchangers(FALSE); - // } - - // // Kinetics - // if (this->Get_kinetic(cell_number) != NULL) { - // this->Get_kinetic(cell_number)->set_essential_values(dump_it); - // } - - // // PPassemblage - // if (this->Get_equilibrium(cell_number) != NULL) { - // this->Get_equilibrium(cell_number)->set_essential_values(dump_it); - // } - - // // Surface - // if (this->Get_surface(cell_number) != NULL) { - // auto *tmp = this->Get_surface(cell_number); - // auto &surf_pointer = this->surfaceWrapperPtr; - // std::span surf_span{dump_it, surf_pointer->size()}; - // surf_pointer->set(surf_span); - - // dump_it += surf_pointer->size(); - - // // this->PhreeqcPtr->Rxn_new_surface.insert(cell_number); - - // // this->Get_surface(cell_number)->set_essential_values(dump_it); - // // this->PhreeqcPtr->Rxn_new_surface.insert(cell_number); - // // this->PhreeqcPtr->initial_surfaces(TRUE); - // } -} - -void PhreeqcEngine::runCell(std::vector &cell_values, - double time_step) { - // skip ID - std::span cell_data{cell_values.begin() + 1, cell_values.end()}; - - this->set_essential_values(cell_data); - this->run(time_step); - this->get_essential_values(cell_data); -} - -void PhreeqcEngine::run(double time_step) { - std::stringstream time_ss; - time_ss << std::fixed << std::setprecision(20) << time_step; - - const std::string runs_string = - "RUN_CELLS\n -cells 1\n -time_step " + time_ss.str() + "\nEND\n"; - this->RunString(runs_string.c_str()); } \ No newline at end of file diff --git a/poet/src/InitGetSet.cpp b/poet/src/InitGetSet.cpp index 04bb03f3..1f5a813a 100644 --- a/poet/src/InitGetSet.cpp +++ b/poet/src/InitGetSet.cpp @@ -1,9 +1,9 @@ -#include "EquilibriumWrapper.hpp" -#include "ExchangeWrapper.hpp" -#include "KineticWrapper.hpp" #include "PhreeqcInit.hpp" -#include "SolutionWrapper.hpp" -#include "SurfaceWrapper.hpp" +#include "Wrapper/EquilibriumWrapper.hpp" +#include "Wrapper/ExchangeWrapper.hpp" +#include "Wrapper/KineticWrapper.hpp" +#include "Wrapper/SolutionWrapper.hpp" +#include "Wrapper/SurfaceWrapper.hpp" #include "global_structures.h" #include diff --git a/poet/src/EquilibriumCompWrapper.cpp b/poet/src/Wrapper/EquilibriumCompWrapper.cpp similarity index 100% rename from poet/src/EquilibriumCompWrapper.cpp rename to poet/src/Wrapper/EquilibriumCompWrapper.cpp diff --git a/poet/src/EquilibriumWrapper.cpp b/poet/src/Wrapper/EquilibriumWrapper.cpp similarity index 100% rename from poet/src/EquilibriumWrapper.cpp rename to poet/src/Wrapper/EquilibriumWrapper.cpp diff --git a/poet/include/EquilibriumWrapper.hpp b/poet/src/Wrapper/EquilibriumWrapper.hpp similarity index 100% rename from poet/include/EquilibriumWrapper.hpp rename to poet/src/Wrapper/EquilibriumWrapper.hpp diff --git a/poet/src/ExchangeCompWrapper.cpp b/poet/src/Wrapper/ExchangeCompWrapper.cpp similarity index 100% rename from poet/src/ExchangeCompWrapper.cpp rename to poet/src/Wrapper/ExchangeCompWrapper.cpp diff --git a/poet/src/ExchangeWrapper.cpp b/poet/src/Wrapper/ExchangeWrapper.cpp similarity index 100% rename from poet/src/ExchangeWrapper.cpp rename to poet/src/Wrapper/ExchangeWrapper.cpp diff --git a/poet/include/ExchangeWrapper.hpp b/poet/src/Wrapper/ExchangeWrapper.hpp similarity index 100% rename from poet/include/ExchangeWrapper.hpp rename to poet/src/Wrapper/ExchangeWrapper.hpp diff --git a/poet/src/KineticCompWrapper.cpp b/poet/src/Wrapper/KineticCompWrapper.cpp similarity index 100% rename from poet/src/KineticCompWrapper.cpp rename to poet/src/Wrapper/KineticCompWrapper.cpp diff --git a/poet/src/KineticWrapper.cpp b/poet/src/Wrapper/KineticWrapper.cpp similarity index 100% rename from poet/src/KineticWrapper.cpp rename to poet/src/Wrapper/KineticWrapper.cpp diff --git a/poet/include/KineticWrapper.hpp b/poet/src/Wrapper/KineticWrapper.hpp similarity index 100% rename from poet/include/KineticWrapper.hpp rename to poet/src/Wrapper/KineticWrapper.hpp diff --git a/poet/src/SolutionWrapper.cpp b/poet/src/Wrapper/SolutionWrapper.cpp similarity index 100% rename from poet/src/SolutionWrapper.cpp rename to poet/src/Wrapper/SolutionWrapper.cpp diff --git a/poet/include/SolutionWrapper.hpp b/poet/src/Wrapper/SolutionWrapper.hpp similarity index 100% rename from poet/include/SolutionWrapper.hpp rename to poet/src/Wrapper/SolutionWrapper.hpp diff --git a/poet/src/SurfaceChargeWrapper.cpp b/poet/src/Wrapper/SurfaceChargeWrapper.cpp similarity index 100% rename from poet/src/SurfaceChargeWrapper.cpp rename to poet/src/Wrapper/SurfaceChargeWrapper.cpp diff --git a/poet/src/SurfaceCompWrapper.cpp b/poet/src/Wrapper/SurfaceCompWrapper.cpp similarity index 100% rename from poet/src/SurfaceCompWrapper.cpp rename to poet/src/Wrapper/SurfaceCompWrapper.cpp diff --git a/poet/src/SurfaceWrapper.cpp b/poet/src/Wrapper/SurfaceWrapper.cpp similarity index 100% rename from poet/src/SurfaceWrapper.cpp rename to poet/src/Wrapper/SurfaceWrapper.cpp diff --git a/poet/include/SurfaceWrapper.hpp b/poet/src/Wrapper/SurfaceWrapper.hpp similarity index 100% rename from poet/include/SurfaceWrapper.hpp rename to poet/src/Wrapper/SurfaceWrapper.hpp diff --git a/poet/include/WrapperBase.hpp b/poet/src/Wrapper/WrapperBase.hpp similarity index 100% rename from poet/include/WrapperBase.hpp rename to poet/src/Wrapper/WrapperBase.hpp