![]() |
OGS
|
|
Drives the chemistry step in the operator-split reactive transport loop.
Per timestep:
chemical_system_id, store the transported totals \(c_{T\alpha}\), the current porous-medium state (porosity, mineral fractions, reactive surface area), and the process variables (e.g. temperature \(T\), pressure \(p\), time \(t\), and timestep \(\Delta t\)) in the corresponding ChemicalSystem. Each chemical_system_id is treated as one local batch reactor.chemical_system_id, run PHREEQC via IPhreeqc, and obtain the reacted state after advancing chemistry over \(\Delta t\):Accessors:
Internal data:
chemical_system_id definition (aqueous solution, kinetic and equilibrium reactants, exchangers, surface sites).Definition at line 114 of file PhreeqcIO.h.
#include <PhreeqcIO.h>
Public Member Functions | |
| PhreeqcIO (MeshLib::Mesh const &mesh, GlobalLinearSolver &linear_solver, std::string const &project_file_name, std::string &&database, std::unique_ptr< ChemicalSystem > &&chemical_system, std::vector< ReactionRate > &&reaction_rates, std::unique_ptr< UserPunch > &&user_punch, std::unique_ptr< Output > &&output, std::unique_ptr< Dump > &&dump, Knobs &&knobs, bool use_stream_mode, int num_chemistry_threads, double concentration_warning_threshold) | |
| ~PhreeqcIO () | |
| void | initialize () override |
| void | initializeChemicalSystemConcrete (std::vector< double > const &concentrations, GlobalIndexType const &chemical_system_id, MaterialPropertyLib::Medium const &medium, ParameterLib::SpatialPosition const &pos, double const t) override |
| void | setChemicalSystemConcrete (std::vector< double > const &concentrations, GlobalIndexType const &chemical_system_id, MaterialPropertyLib::Medium const *medium, MaterialPropertyLib::VariableArray const &vars, ParameterLib::SpatialPosition const &pos, double const t, double const dt) override |
| void | setAqueousSolutionsPrevFromDumpFile () override |
| void | executeSpeciationCalculation (double const dt) override |
| double | getConcentration (int const component_id, GlobalIndexType const chemical_system_id) const override |
| void | updateVolumeFractionPostReaction (GlobalIndexType const &chemical_system_id, MaterialPropertyLib::Medium const &medium, ParameterLib::SpatialPosition const &pos, double const porosity, double const t, double const dt) override |
| void | updatePorosityPostReaction (GlobalIndexType const &chemical_system_id, MaterialPropertyLib::Medium const &medium, double &porosity) override |
| void | computeSecondaryVariable (std::size_t const ele_id, std::vector< GlobalIndexType > const &chemical_system_indices) override |
| std::vector< std::string > const | getComponentList () const override |
| Public Member Functions inherited from ChemistryLib::ChemicalSolverInterface | |
| ChemicalSolverInterface (MeshLib::Mesh const &mesh, GlobalLinearSolver &linear_solver_) | |
| std::vector< std::size_t > const & | activeElementIDs () const |
| virtual Eigen::SparseMatrix< double > const * | getStoichiometricMatrix () const |
| virtual double | getKineticPrefactor (std::size_t reaction_id) const |
| virtual | ~ChemicalSolverInterface ()=default |
Public Attributes | |
| std::string const | _phreeqc_input_file |
| Public Attributes inherited from ChemistryLib::ChemicalSolverInterface | |
| std::vector< GlobalIndexType > | chemical_system_index_map |
| MeshLib::Mesh const & | _mesh |
| GlobalLinearSolver & | linear_solver |
Private Member Functions | |
| void | writeInputsToFile (double const dt) |
| void | writeInputHeader (std::ostream &os) const |
| void | writeSystemBlock (std::ostream &os, std::size_t chemical_system_id, std::size_t solution_id, std::size_t prev_solution_id, double dt) const |
| void | updateSystemFromOutputLine (std::string_view line, std::size_t chemical_system_id) |
| void | setAqueousSolutionsPrevFromDumpString (std::string_view dump_content) |
| void | callPhreeqc () const |
| void | readOutputsFromFile () |
| void | executeSpeciationCalculationParallel (double const dt) |
| std::string | generateInputForSystem (std::size_t chemical_system_id, double const dt) const |
| void | parseOutputForSystem (std::string_view output_content, std::size_t chemical_system_id) |
| void | updateChemicalSystemFromOutput (std::vector< double > const &accepted_items, std::size_t chemical_system_id) |
| PhreeqcIO & | operator<< (double const dt) |
Private Attributes | |
| ClampingStats | _clamping_totals |
| std::string const | _database |
| Knobs const | _knobs |
| std::vector< ReactionRate > const | _reaction_rates |
| std::unique_ptr< ChemicalSystem > | _chemical_system |
| std::unique_ptr< UserPunch > | _user_punch |
| std::unique_ptr< Output > const | _output |
| std::unique_ptr< Dump > const | _dump |
| std::unique_ptr< PhreeqcInstancePool > | instance_pool_ |
| double | _dt = std::numeric_limits<double>::quiet_NaN() |
| std::size_t | _num_chemical_systems = 0 |
| double | _concentration_warning_threshold |
| int | phreeqc_instance_id = -1 |
| int | num_chemistry_threads_ |
| bool | _use_stream_mode |
Friends | |
| std::ostream & | operator<< (std::ostream &os, PhreeqcIO const &phreeqc_io) |
| std::istream & | operator>> (std::istream &in, PhreeqcIO &phreeqc_io) |
| ChemistryLib::PhreeqcIOData::PhreeqcIO::PhreeqcIO | ( | MeshLib::Mesh const & | mesh, |
| GlobalLinearSolver & | linear_solver, | ||
| std::string const & | project_file_name, | ||
| std::string && | database, | ||
| std::unique_ptr< ChemicalSystem > && | chemical_system, | ||
| std::vector< ReactionRate > && | reaction_rates, | ||
| std::unique_ptr< UserPunch > && | user_punch, | ||
| std::unique_ptr< Output > && | output, | ||
| std::unique_ptr< Dump > && | dump, | ||
| Knobs && | knobs, | ||
| bool | use_stream_mode, | ||
| int | num_chemistry_threads, | ||
| double | concentration_warning_threshold ) |
Definition at line 347 of file PhreeqcIO.cpp.
References ChemistryLib::ChemicalSolverInterface::ChemicalSolverInterface(), _chemical_system, _concentration_warning_threshold, _database, _dump, _knobs, _output, _phreeqc_input_file, _reaction_rates, _use_stream_mode, _user_punch, ChemistryLib::PhreeqcIOData::PhreeqcInstancePool::createInstance(), INFO(), instance_pool_, ChemistryLib::ChemicalSolverInterface::linear_solver, num_chemistry_threads_, OGS_FATAL, phreeqc_instance_id, and ChemistryLib::PhreeqcIOData::specifyFileName().
Referenced by operator<<(), operator<<, and operator>>.
| ChemistryLib::PhreeqcIOData::PhreeqcIO::~PhreeqcIO | ( | ) |
Definition at line 414 of file PhreeqcIO.cpp.
References phreeqc_instance_id.
|
private |
Definition at line 803 of file PhreeqcIO.cpp.
References _phreeqc_input_file, INFO(), OGS_FATAL, and phreeqc_instance_id.
Referenced by executeSpeciationCalculation().
|
overridevirtual |
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 1016 of file PhreeqcIO.cpp.
References _chemical_system.
|
overridevirtual |
Run PHREEQC for all local chemical systems for the current timestep.
Uses the state previously provided by initializeChemicalSystemConcrete() / setChemicalSystemConcrete() for each chemical_system_id. Each local system is advanced as an isolated batch reactor over \(\Delta t\): no mass is exchanged between different systems inside PHREEQC.
PHREEQC returns, for each system:
After this call completes, these reacted values are available for porosity update and for assembling the reaction/source term in the transport equation.
| dt | Timestep size \(\Delta t\) used for kinetic reactions. |
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 512 of file PhreeqcIO.cpp.
References _clamping_totals, _concentration_warning_threshold, _use_stream_mode, callPhreeqc(), DBUG(), executeSpeciationCalculationParallel(), readOutputsFromFile(), and writeInputsToFile().
|
private |
Definition at line 1092 of file PhreeqcIO.cpp.
References _dump, _num_chemical_systems, BaseLib::MPI::allRanksThrowOrNone(), generateInputForSystem(), INFO(), instance_pool_, num_chemistry_threads_, and parseOutputForSystem().
Referenced by executeSpeciationCalculation().
|
private |
Definition at line 1035 of file PhreeqcIO.cpp.
References _dump, _num_chemical_systems, writeInputHeader(), and writeSystemBlock().
Referenced by executeSpeciationCalculationParallel().
|
overridevirtual |
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 966 of file PhreeqcIO.cpp.
References _chemical_system.
|
overridevirtual |
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 535 of file PhreeqcIO.cpp.
References _chemical_system, and OGS_FATAL.
|
overridevirtual |
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 424 of file PhreeqcIO.cpp.
References _chemical_system, _num_chemical_systems, _user_punch, and ChemistryLib::ChemicalSolverInterface::chemical_system_index_map.
|
overridevirtual |
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 436 of file PhreeqcIO.cpp.
References _chemical_system, _concentration_warning_threshold, MaterialPropertyLib::AqueousLiquid, MaterialPropertyLib::Medium::phase(), ChemistryLib::PhreeqcIOData::setAqueousSolution(), and MaterialPropertyLib::Solid.
|
inlineprivate |
Definition at line 230 of file PhreeqcIO.h.
References PhreeqcIO(), and _dt.
|
private |
Definition at line 1063 of file PhreeqcIO.cpp.
References _chemical_system, OGS_FATAL, and updateSystemFromOutputLine().
Referenced by executeSpeciationCalculationParallel().
|
private |
Definition at line 816 of file PhreeqcIO.cpp.
References _output, DBUG(), and OGS_FATAL.
Referenced by executeSpeciationCalculation().
|
overridevirtual |
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 560 of file PhreeqcIO.cpp.
References _dump, _num_chemical_systems, and OGS_FATAL.
|
private |
Definition at line 586 of file PhreeqcIO.cpp.
References _dump, _num_chemical_systems, and DBUG().
|
overridevirtual |
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 481 of file PhreeqcIO.cpp.
References _chemical_system, _clamping_totals, _concentration_warning_threshold, MaterialPropertyLib::AqueousLiquid, MaterialPropertyLib::Medium::phase(), ChemistryLib::PhreeqcIOData::setAqueousSolution(), and MaterialPropertyLib::Solid.
|
private |
Definition at line 840 of file PhreeqcIO.cpp.
References _chemical_system, _output, _user_punch, ChemistryLib::PhreeqcIOData::Component, ChemistryLib::PhreeqcIOData::EquilibriumReactant, BaseLib::findElementOrError(), ChemistryLib::PhreeqcIOData::KineticReactant, OGS_FATAL, ChemistryLib::PhreeqcIOData::pe, ChemistryLib::PhreeqcIOData::pH, and ChemistryLib::PhreeqcIOData::SecondaryVariable.
Referenced by updateSystemFromOutputLine().
|
overridevirtual |
Update porosity after chemical reactions.
This applies porosity changes caused by precipitation / dissolution in the local chemical system. The updated porosity can then be used to update flow parameters (e.g. permeability) in the next timestep.
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 998 of file PhreeqcIO.cpp.
References _chemical_system.
|
private |
Parse one line of PHREEQC selected output and update the chemical system state. Used by both output-reading code paths (file-mode operator>> and stream-mode parseOutputForSystem()).
Definition at line 770 of file PhreeqcIO.cpp.
References _output, and updateChemicalSystemFromOutput().
Referenced by operator>>, and parseOutputForSystem().
|
overridevirtual |
Apply mineral precipitation / dissolution to the solid fraction in OGS.
Called after executeSpeciationCalculation(). For a given chemical_system_id, this function updates the solid / mineral inventory and related volume fractions based on the PHREEQC results for the last timestep.
Typical effect:
Reimplemented from ChemistryLib::ChemicalSolverInterface.
Definition at line 979 of file PhreeqcIO.cpp.
References _chemical_system.
|
private |
Write the global input header (PHASES, KNOBS, SELECTED_OUTPUT, USER_PUNCH, RATES) shared by both file and stream mode.
Definition at line 632 of file PhreeqcIO.cpp.
References _chemical_system, _knobs, _output, _reaction_rates, and _user_punch.
Referenced by generateInputForSystem(), and operator<<.
|
private |
Definition at line 607 of file PhreeqcIO.cpp.
References _phreeqc_input_file, DBUG(), and OGS_FATAL.
Referenced by executeSpeciationCalculation().
|
private |
Write the per-system input block (SOLUTION, EQUILIBRIUM_PHASES, KINETICS, SURFACE, EXCHANGE).
| os | Output stream to write the PHREEQC input to. |
| chemical_system_id | Zero-based index of the chemical system (mesh node/cell) being written. |
| solution_id | PHREEQC solution number for this system (1 in stream mode, chemical_system_id+1 in file mode). |
| prev_solution_id | Solution number of the previous-timestep aqueous solution used for SURFACE/EXCHANGE equilibration. |
| dt | Time step size in seconds. |
Definition at line 658 of file PhreeqcIO.cpp.
References _chemical_system, and _dump.
Referenced by generateInputForSystem(), and operator<<.
|
friend |
Definition at line 780 of file PhreeqcIO.cpp.
References PhreeqcIO(), _dt, _dump, _num_chemical_systems, writeInputHeader(), and writeSystemBlock().
|
friend |
Definition at line 930 of file PhreeqcIO.cpp.
References PhreeqcIO(), _chemical_system, _num_chemical_systems, OGS_FATAL, and updateSystemFromOutputLine().
|
private |
Definition at line 246 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), computeSecondaryVariable(), getComponentList(), getConcentration(), initialize(), initializeChemicalSystemConcrete(), operator>>, parseOutputForSystem(), setChemicalSystemConcrete(), updateChemicalSystemFromOutput(), updatePorosityPostReaction(), updateVolumeFractionPostReaction(), writeInputHeader(), and writeSystemBlock().
|
private |
Negative-concentration clamping accumulated over all chemical systems within one speciation step. Folded in setChemicalSystemConcrete() and flushed (reported + reset) in executeSpeciationCalculation() so that clamping is reported once per step rather than once per cell.
Definition at line 242 of file PhreeqcIO.h.
Referenced by executeSpeciationCalculation(), and setChemicalSystemConcrete().
|
private |
Negative (or zero) warning threshold for clamped concentrations. All negative concentrations are clamped to zero unconditionally (PHREEQC rejects negatives); this only sets the value below which a clamp is reported via an aggregated WARN. Concentrations in [threshold, 0) are treated as floating-point noise and clamped silently.
Definition at line 258 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), executeSpeciationCalculation(), initializeChemicalSystemConcrete(), and setChemicalSystemConcrete().
|
private |
Definition at line 243 of file PhreeqcIO.h.
Referenced by PhreeqcIO().
|
private |
Definition at line 251 of file PhreeqcIO.h.
Referenced by operator<<(), and operator<<.
|
private |
Definition at line 249 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), executeSpeciationCalculationParallel(), generateInputForSystem(), operator<<, setAqueousSolutionsPrevFromDumpFile(), setAqueousSolutionsPrevFromDumpString(), and writeSystemBlock().
|
private |
Definition at line 244 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), and writeInputHeader().
|
private |
Definition at line 252 of file PhreeqcIO.h.
Referenced by executeSpeciationCalculationParallel(), generateInputForSystem(), initialize(), operator<<, operator>>, setAqueousSolutionsPrevFromDumpFile(), and setAqueousSolutionsPrevFromDumpString().
|
private |
Definition at line 248 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), readOutputsFromFile(), updateChemicalSystemFromOutput(), updateSystemFromOutputLine(), and writeInputHeader().
| std::string const ChemistryLib::PhreeqcIOData::PhreeqcIO::_phreeqc_input_file |
Definition at line 179 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), callPhreeqc(), and writeInputsToFile().
|
private |
Definition at line 245 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), and writeInputHeader().
|
private |
Definition at line 268 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), and executeSpeciationCalculation().
|
private |
Definition at line 247 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), initialize(), updateChemicalSystemFromOutput(), and writeInputHeader().
|
private |
Definition at line 250 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), and executeSpeciationCalculationParallel().
|
private |
Definition at line 267 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), and executeSpeciationCalculationParallel().
|
private |
ID of the standalone file-mode PHREEQC instance (independent of the parallel pool). Created by PhreeqcInstancePool::createInstance() in the ctor only in file mode; in stream mode the pool is used instead and this stays -1. It must not be hard-coded to 0 because the IPhreeqc library hands out monotonically increasing IDs and another consumer (e.g. a unit test that constructed an IPhreeqc instance earlier) may have used 0 first.
Definition at line 266 of file PhreeqcIO.h.
Referenced by PhreeqcIO(), ~PhreeqcIO(), and callPhreeqc().