https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GeochemicalSolver.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "GeochemicalSystem.h"
14
19{
20public:
50 GeochemicalSolver(unsigned num_basis,
51 unsigned num_kin,
53 Real abs_tol,
54 Real rel_tol,
55 unsigned max_iter,
56 Real max_initial_residual,
57 Real swap_threshold,
58 unsigned max_swaps_allowed,
59 const std::vector<std::string> & prevent_precipitation,
60 Real max_ionic_strength,
61 unsigned ramp_max_ionic_strength,
62 bool evaluate_kin_always);
63
85 std::stringstream & ss,
86 unsigned & tot_iter,
87 Real & abs_residual,
88 Real dt,
89 DenseVector<Real> & mole_additions,
90 DenseMatrix<Real> & dmole_additions);
91
93 void setMaxInitialResidual(Real max_initial_residual);
94
96 Real getMaxInitialResidual() const;
97
99 void setRampMaxIonicStrength(unsigned ramp_max_ionic_strength);
100
102 unsigned getRampMaxIonicStrength() const;
103
104private:
108 const unsigned _num_basis;
110 const unsigned _num_kin;
116 DenseVector<Real> _residual;
120 DenseMatrix<Real> _jacobian;
122 DenseVector<Real> _new_mol;
124 const Real _abs_tol;
126 const Real _rel_tol;
130 const unsigned _max_iter;
134 const Real _swap_threshold;
136 const unsigned _max_swaps_allowed;
138 const std::vector<std::string> _prevent_precipitation;
149 DenseVector<Real> _input_mole_additions;
151 DenseMatrix<Real> _input_dmole_additions;
152
161 Real computeResidual(const GeochemicalSystem & egs,
162 DenseVector<Real> & residual,
163 const DenseVector<Real> & mole_additions) const;
164
173 void solveAndUnderrelax(const GeochemicalSystem & egs,
174 DenseMatrix<Real> & jacobian,
175 DenseVector<Real> & new_mol) const;
176
189 bool swapNeeded(const GeochemicalSystem & egs,
190 unsigned & swap_out_of_basis,
191 unsigned & swap_into_basis,
192 std::stringstream & ss) const;
193
205 Real dt,
206 DenseVector<Real> & mole_additions,
207 DenseMatrix<Real> & dmole_additions);
208};
This class contains methods to solve the algebraic system in GeochemicalSystem.
unsigned _ramp_max_ionic_strength
Number of iterations over which to increase the maximum ionic strength to _max_ionic_strength.
DenseVector< Real > _new_mol
the new molality after finding the solution of _jacobian * neg_change_mol = _residual
Real getMaxInitialResidual() const
Get value for max_initial_residual.
DenseMatrix< Real > _input_dmole_additions
d(mole_additions)/d(species) as specified in the argument of solveSystem
Real _max_initial_residual
maximum desired initial residual
const unsigned _max_iter
maximum number of iterations allowed during an inner solve
bool _evaluate_kin_always
When to compute the kinetic rates: if true then evaluate before every residual calculation,...
const unsigned _num_basis
Number of species in the basis.
void solveSystem(GeochemicalSystem &egs, std::stringstream &ss, unsigned &tot_iter, Real &abs_residual, Real dt, DenseVector< Real > &mole_additions, DenseMatrix< Real > &dmole_additions)
Solve the system.
bool swapNeeded(const GeochemicalSystem &egs, unsigned &swap_out_of_basis, unsigned &swap_into_basis, std::stringstream &ss) const
Check if a basis swap is needed.
Real computeResidual(const GeochemicalSystem &egs, DenseVector< Real > &residual, const DenseVector< Real > &mole_additions) const
Builds the residual of the algebraic system.
const std::vector< std::string > _prevent_precipitation
The minerals named in this list can have positive saturation indices and will not precipitate.
void setRampMaxIonicStrength(unsigned ramp_max_ionic_strength)
Sets the value of _ramp_max_ionic_strength.
unsigned getRampMaxIonicStrength() const
Gets the value of _ramp_max_ionic_strength.
DenseVector< Real > _input_mole_additions
the mole_additions for the basis and kinetic species as specified in the argument of solveSystem
DenseVector< Real > _residual
residual of the algebraic system we wish to solve
DenseMatrix< Real > _jacobian
jacobian of the algebraic system
const Real _rel_tol
If the residual of the algebraic system falls below this value times the initial residual,...
const Real _max_ionic_strength
Maximum ionic strength allowed.
const Real _swap_threshold
If a basis molality < swap_threshold, we attempt to swap it out of the basis.
Real _abs_residual
L1 norm of residual.
Real _res0_times_rel
_res0_times_rel = _rel_tol * initial residual
bool reduceInitialResidual(GeochemicalSystem &egs, Real dt, DenseVector< Real > &mole_additions, DenseMatrix< Real > &dmole_additions)
Progressively alter the initial-guess molalities for the algebraic system to attempt to reduce the re...
void solveAndUnderrelax(const GeochemicalSystem &egs, DenseMatrix< Real > &jacobian, DenseVector< Real > &new_mol) const
Solves _jacobian * neg_change_mol = _residual for neg_change_mol, then performs an underrelaxation to...
void setMaxInitialResidual(Real max_initial_residual)
Set value for max_initial_residual.
unsigned _num_basis_in_algebraic_system
Number of basis molalities (and potentially solvent water mass) in the algebraic system.
const Real _abs_tol
If the residual of the algebraic system falls below this value, the Newton process has converged.
const unsigned _num_kin
Number of kinetic species.
GeochemistryIonicStrength & _is
The ionic-strength calculator.
const unsigned _max_swaps_allowed
Maximum number of swaps allowed before the solve aborts.
unsigned _num_in_algebraic_system
Number of unknowns (molalities and surface potentials) in the algebraic system.
This class holds information about bulk composition, molalities, activities, activity coefficients,...
Calculators to compute ionic strength and stoichiometric ionic strength.