6#include <phreeqcpp/cxxKinetics.h>
42 auto path_to_database =
47 OGS_FATAL(
"Not found the specified thermodynamicdatabase: {:s}",
51 INFO(
"Found the specified thermodynamic database: {:s}", path_to_database);
53 return path_to_database;
60std::unique_ptr<ChemicalSolverInterface>
62 std::vector<std::unique_ptr<MeshLib::Mesh>>
const& meshes,
63 std::map<std::string, std::unique_ptr<GlobalLinearSolver>>
const&
65 BaseLib::ConfigTree
const& config, std::string
const& output_directory)
74 assert(mesh.getID() != 0);
75 DBUG(
"Found mesh '{:s}' with id {:d}.", mesh.getName(), mesh.getID());
81 linear_solvers, ls_name,
82 "A linear solver with the given name does not exist.");
87 auto chemical_system =
96 auto const& surface = chemical_system->surface;
99 auto const& exchangers = chemical_system->exchangers;
102 auto use_stream_for_data_exchange =
107 auto const project_file_name =
112 auto dump = surface.empty() && exchangers.empty()
114 : std::make_unique<PhreeqcIOData::Dump>(project_file_name);
127 auto const use_high_precision =
131 *chemical_system, user_punch, use_high_precision, project_file_name);
133 if (use_stream_for_data_exchange)
135 INFO(
"PhreeqcIO will use stringstream for data exchange.");
139 INFO(
"PhreeqcIO will use file for data exchange.");
142 return std::make_unique<PhreeqcIOData::PhreeqcIO>(
143 mesh, *linear_solver, std::move(project_file_name),
144 std::move(path_to_database), std::move(chemical_system),
145 std::move(reaction_rates), std::move(user_punch), std::move(output),
146 std::move(dump), std::move(knobs), use_stream_for_data_exchange);
150std::unique_ptr<ChemicalSolverInterface>
152 std::vector<std::unique_ptr<MeshLib::Mesh>>
const& meshes,
153 std::map<std::string, std::unique_ptr<GlobalLinearSolver>>
const&
155 BaseLib::ConfigTree
const& config, std::string
const& )
157 auto mesh = *meshes[0];
163 linear_solvers, ls_name,
164 "A linear solver with the given name does not exist.");
169 std::vector<std::pair<int, std::string>> process_id_to_component_name_map;
174 process_id_to_component_name_map);
191 return std::make_unique<PhreeqcKernelData::PhreeqcKernel>(
192 mesh, *linear_solver, mesh.computeNumberOfBaseNodes(),
193 process_id_to_component_name_map, std::move(path_to_database),
194 std::move(aqueous_solution), std::move(equilibrium_reactants),
195 std::move(kinetic_reactants), std::move(reaction_rates));
199std::unique_ptr<ChemicalSolverInterface>
201 std::vector<std::unique_ptr<MeshLib::Mesh>>
const& meshes,
202 std::map<std::string, std::unique_ptr<GlobalLinearSolver>>
const&
204 BaseLib::ConfigTree
const& config, std::string
const& )
213 assert(mesh.getID() != 0);
214 DBUG(
"Found mesh '{:s}' with id {:d}.", mesh.getName(), mesh.getID());
220 linear_solvers, ls_name,
221 "A linear solver with the given name does not exist.");
223 auto chemical_reaction_data =
229 std::vector<double> stoichiometric_matrix_vec;
230 for (
auto const& per_chemical_reaction_data : chemical_reaction_data)
232 stoichiometric_matrix_vec.insert(
233 stoichiometric_matrix_vec.end(),
234 per_chemical_reaction_data->stoichiometric_vector.begin(),
235 per_chemical_reaction_data->stoichiometric_vector.end());
238 auto const num_components =
243 stoichiometric_matrix_vec, num_components, num_components);
245 Eigen::SparseMatrix<double> sparse_stoichiometric_matrix;
246 sparse_stoichiometric_matrix = stoichiometric_matrix.sparseView();
248 return std::make_unique<SelfContainedSolverData::SelfContainedSolver>(
249 mesh, *linear_solver, sparse_stoichiometric_matrix,
250 std::move(chemical_reaction_data));
Definition of one reactive chemical system for PHREEQC coupling.
Chemical-solver interface used in OGS operator-split reactive transport.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
PHREEQC-backed ChemicalSolverInterface implementation.
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
std::filesystem::path projectDirectory() const
T getConfigParameter(std::string const ¶m) const
ConfigTree getConfigSubtree(std::string const &root) const
std::filesystem::path const & projectFilePath() const
Used to get the project file name.
bool IsFileExisting(const std::string &strFilename)
Returns true if given file exists.
std::string extractBaseNameWithoutExtension(std::string const &pathname)
std::string joinPaths(std::string const &pathA, std::string const &pathB)
OGS_NO_DANGLING Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
std::unique_ptr< UserPunch > createUserPunch(std::optional< BaseLib::ConfigTree > const &config, MeshLib::Mesh const &mesh)
std::unique_ptr< Output > createOutput(ChemicalSystem const &chemical_system, std::unique_ptr< UserPunch > const &user_punch, bool const use_high_precision, std::string const &project_file_name)
std::unique_ptr< ChemicalSystem > createChemicalSystem(BaseLib::ConfigTree const &config, MeshLib::Mesh &mesh)
Knobs createKnobs(BaseLib::ConfigTree const &config)
std::unique_ptr< EquilibriumReactants > createEquilibriumReactants(std::optional< BaseLib::ConfigTree > const &config, MeshLib::Mesh const &mesh)
std::unique_ptr< Kinetics > createKineticReactants(std::optional< BaseLib::ConfigTree > const &config, MeshLib::Mesh const &mesh)
AqueousSolution createAqueousSolution(BaseLib::ConfigTree const &config, std::vector< std::pair< int, std::string > > const &process_id_to_component_name_map)
std::vector< std::unique_ptr< ChemicalReaction > > createChemicalReactionData(BaseLib::ConfigTree const &config)
template std::vector< PhreeqcKernelData::ReactionRate > createReactionRates< PhreeqcKernelData::ReactionRate >(std::optional< BaseLib::ConfigTree > const &config)
std::unique_ptr< ChemicalSolverInterface > createChemicalSolverInterface< ChemicalSolver::SelfContained >(std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes, std::map< std::string, std::unique_ptr< GlobalLinearSolver > > const &linear_solvers, BaseLib::ConfigTree const &config, std::string const &)
std::unique_ptr< ChemicalSolverInterface > createChemicalSolverInterface< ChemicalSolver::PhreeqcKernel >(std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes, std::map< std::string, std::unique_ptr< GlobalLinearSolver > > const &linear_solvers, BaseLib::ConfigTree const &config, std::string const &)
std::unique_ptr< ChemicalSolverInterface > createChemicalSolverInterface< ChemicalSolver::Phreeqc >(std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes, std::map< std::string, std::unique_ptr< GlobalLinearSolver > > const &linear_solvers, BaseLib::ConfigTree const &config, std::string const &output_directory)
template std::vector< PhreeqcIOData::ReactionRate > createReactionRates< PhreeqcIOData::ReactionRate >(std::optional< BaseLib::ConfigTree > const &config)
Eigen::Map< const Matrix > toMatrix(std::vector< double > const &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
Mesh & findMeshByName(std::vector< std::unique_ptr< Mesh > > const &meshes, std::string_view const name)
std::string parseDatabasePath(BaseLib::ConfigTree const &config)