6#include <phreeqcpp/cxxKinetics.h>
44 auto path_to_database =
49 OGS_FATAL(
"Not found the specified thermodynamicdatabase: {:s}",
53 INFO(
"Found the specified thermodynamic database: {:s}", path_to_database);
55 return path_to_database;
62std::unique_ptr<ChemicalSolverInterface>
64 std::vector<std::unique_ptr<MeshLib::Mesh>>
const& meshes,
65 std::map<std::string, std::unique_ptr<GlobalLinearSolver>>
const&
67 BaseLib::ConfigTree
const& config, std::string
const& output_directory)
76 assert(mesh.getID() != 0);
77 DBUG(
"Found mesh '{:s}' with id {:d}.", mesh.getName(), mesh.getID());
83 linear_solvers, ls_name,
84 "A linear solver with the given name does not exist.");
89 auto chemical_system =
98 auto const& surface = chemical_system->surface;
101 auto const& exchangers = chemical_system->exchangers;
104 auto use_stream_for_data_exchange =
109 auto const num_chemistry_threads_opt =
112 if (num_chemistry_threads_opt && *num_chemistry_threads_opt <= 0)
115 "<chemistry_threads> must be a positive integer, but got {:d}.",
116 *num_chemistry_threads_opt);
118 int const num_chemistry_threads =
119 num_chemistry_threads_opt ? *num_chemistry_threads_opt
126 auto const concentration_warning_threshold =
130 if (concentration_warning_threshold > 0.0)
133 "<concentration_warning_threshold> must not be positive (it is a "
134 "threshold for negative concentrations), but got {:g}.",
135 concentration_warning_threshold);
139 auto const project_file_name =
144 auto dump = surface.empty() && exchangers.empty()
146 : std::make_unique<PhreeqcIOData::Dump>(project_file_name);
159 auto const use_high_precision =
163 *chemical_system, user_punch, use_high_precision, project_file_name);
165 if (use_stream_for_data_exchange)
167 INFO(
"PhreeqcIO will use stringstream for data exchange.");
171 INFO(
"PhreeqcIO will use file for data exchange.");
174 return std::make_unique<PhreeqcIOData::PhreeqcIO>(
175 mesh, *linear_solver, std::move(project_file_name),
176 std::move(path_to_database), std::move(chemical_system),
177 std::move(reaction_rates), std::move(user_punch), std::move(output),
178 std::move(dump), std::move(knobs), use_stream_for_data_exchange,
179 num_chemistry_threads, concentration_warning_threshold);
183std::unique_ptr<ChemicalSolverInterface>
185 std::vector<std::unique_ptr<MeshLib::Mesh>>
const& meshes,
186 std::map<std::string, std::unique_ptr<GlobalLinearSolver>>
const&
188 BaseLib::ConfigTree
const& config, std::string
const& )
190 auto mesh = *meshes[0];
196 linear_solvers, ls_name,
197 "A linear solver with the given name does not exist.");
202 std::vector<std::pair<int, std::string>> process_id_to_component_name_map;
207 process_id_to_component_name_map);
224 return std::make_unique<PhreeqcKernelData::PhreeqcKernel>(
225 mesh, *linear_solver, mesh.computeNumberOfBaseNodes(),
226 process_id_to_component_name_map, std::move(path_to_database),
227 std::move(aqueous_solution), std::move(equilibrium_reactants),
228 std::move(kinetic_reactants), std::move(reaction_rates));
232std::unique_ptr<ChemicalSolverInterface>
234 std::vector<std::unique_ptr<MeshLib::Mesh>>
const& meshes,
235 std::map<std::string, std::unique_ptr<GlobalLinearSolver>>
const&
237 BaseLib::ConfigTree
const& config, std::string
const& )
246 assert(mesh.getID() != 0);
247 DBUG(
"Found mesh '{:s}' with id {:d}.", mesh.getName(), mesh.getID());
253 linear_solvers, ls_name,
254 "A linear solver with the given name does not exist.");
256 auto chemical_reaction_data =
262 std::vector<double> stoichiometric_matrix_vec;
263 for (
auto const& per_chemical_reaction_data : chemical_reaction_data)
265 stoichiometric_matrix_vec.insert(
266 stoichiometric_matrix_vec.end(),
267 per_chemical_reaction_data->stoichiometric_vector.begin(),
268 per_chemical_reaction_data->stoichiometric_vector.end());
271 auto const num_components =
276 stoichiometric_matrix_vec, num_components, num_components);
278 Eigen::SparseMatrix<double> sparse_stoichiometric_matrix;
279 sparse_stoichiometric_matrix = stoichiometric_matrix.sparseView();
281 return std::make_unique<SelfContainedSolverData::SelfContainedSolver>(
282 mesh, *linear_solver, sparse_stoichiometric_matrix,
283 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
std::optional< T > getConfigParameterOptional(std::string const ¶m) 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)
int getNumberOfChemistryThreads()
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)