22 "The name of the GeochemicalModelDefinition user object");
23 params.
addParam<std::vector<std::string>>(
26 "Species that should be removed from the model_definition's basis and be replaced with the " 27 "swap_into_basis species. There must be the same number of species in swap_out_of_basis and " 28 "swap_into_basis. If this list contains more than one species, the swapping is performed " 29 "one-by-one, starting with the first pair (swap_out_of_basis[0] and swap_into_basis[0]), " 30 "then the next pair, etc");
31 params.
addParam<std::vector<std::string>>(
34 "Species that should be removed from the model_definition's " 35 "equilibrium species list and added to the basis");
36 params.
addParam<std::vector<std::string>>(
39 "Species that are provided numerical values of activity (or fugacity for gases) in the " 40 "activity_value input");
44 "Numerical values for the activity (or fugacity) for the " 45 "species in the activity_species list. These are activity values, not log10(activity).");
49 "Precision for printing values. Also, if the absolute value of a stoichiometric coefficient " 50 "is less than 10^(-precision) then it is set to zero. Also, if equilibrium temperatures are " 51 "desired, they will be computed to a relative error of 10^(-precision)");
52 params.
addParam<std::string>(
"equilibrium_species",
54 "Only output results for this equilibrium species. If not " 55 "provided, results for all equilibrium species will be outputted");
56 MooseEnum interrogation_choice(
"reaction activity eqm_temperature",
"reaction");
60 "Type of interrogation to perform. reaction: Output equilibrium species reactions and " 61 "log10K. activity: determine activity products at equilibrium. eqm_temperature: determine " 62 "temperature to ensure equilibrium");
66 "Equilibrium constants will be computed at this temperature [degC]. This is " 67 "ignored if interrogation=eqm_temperature.");
69 "stoichiometry_tolerance",
71 "stoichiometry_tolerance >= 0.0",
72 "Swapping involves inverting matrices via a singular value decomposition. During this " 73 "process: (1) if abs(singular value) < stoi_tol * L1norm(singular values), then the " 74 "matrix is deemed singular (so the basis swap is deemed invalid); (2) if abs(any " 75 "stoichiometric coefficient) < stoi_tol then it is set to zero.");
95 _swapper(_mgd.basis_species_index.size(), getParam<
Real>(
"stoichiometry_tolerance")),
96 _swap_out(getParam<
std::vector<
std::string>>(
"swap_out_of_basis")),
97 _swap_in(getParam<
std::vector<
std::string>>(
"swap_into_basis")),
98 _precision(getParam<unsigned
int>(
"precision")),
100 _temperature(getParam<
Real>(
"temperature")),
101 _activity_species(getParam<
std::vector<
std::string>>(
"activity_species")),
102 _activity_values(getParam<
std::vector<
Real>>(
"activity_values")),
103 _equilibrium_species(getParam<
std::string>(
"equilibrium_species"))
106 paramError(
"swap_out_of_basis must have same length as swap_into_basis");
108 paramError(
"activity_species must have same length as activity_values");
130 for (
unsigned i = 0; i <
_swap_out.size(); ++i)
159 std::vector<std::string>
174 std::stringstream ss;
178 const unsigned numT = temps.size();
185 ss << eqm_species <<
" = ";
188 ss <<
" . log10(K) = " << log10_eqm_const;
229 const unsigned numT = temps.size();
235 std::stringstream lhs;
241 lhs <<
"(A_" << eqm_species <<
")^-1 ";
243 for (
unsigned i = 0; i < num_cols; ++i)
253 lhs <<
"= 10^" << rhs << std::endl;
254 _console << lhs.str() << std::flush;
273 _console <<
"Not enough activites known to compute equilibrium temperature for reaction\n " 279 for (
unsigned i = 0; i < num_cols; ++i)
287 _console <<
"Not enough activites known to compute equilibrium temperature for reaction\n " 296 _console << eqm_species <<
". T = " << tsoln <<
"degC" << std::endl;
303 const unsigned numT = temps.size();
310 if (reference_log10K(0,
bracket) <= rhs && reference_log10K(0,
bracket + 1) > rhs)
312 else if (reference_log10K(0,
bracket) >= rhs && reference_log10K(0,
bracket + 1) < rhs)
317 return std::numeric_limits<double>::quiet_NaN();
323 const Real small_delT =
325 Real del_temp = small_delT;
327 while (std::abs(del_temp) >= small_delT && iter++ < 100)
329 Real residual = log10K.sample(temp) - rhs;
330 del_temp = -residual / log10K.sampleDerivative(temp);
ModelGeochemicalDatabase _mgd
static InputParameters validParams()
std::vector< std::string > eqmSpeciesOfInterest() const
provide a list of the equilibrium species of interest to the Interrogator
Queries and performs simple manipulations on a geochemical model.
const std::vector< std::string > _swap_in
virtual const char * what() const
constexpr Real CELSIUS_TO_KELVIN
const std::vector< std::string > _swap_out
static InputParameters sharedParams()
params that are shared with the AddGeochemicalModelInterrogatorAction
const unsigned _precision
std::unordered_map< std::string, unsigned > basis_species_index
basis_species_index[name] = index of the basis species, within all ModelGeochemicalDatabase internal ...
Fit the equilibrium constant values read from the thermodynamic databse at specified temperature valu...
void outputActivity(const std::string &eqm_species) const
output activity info to console
enum GeochemicalModelInterrogator::InterrogationChoiceEnum _interrogation
virtual void output() override
std::string getLogKModel() const
Get the equilibrium constant model type.
GeochemicalModelInterrogator(const InputParameters ¶meters)
std::unordered_map< std::string, unsigned > eqm_species_index
eqm_species_index[name] = index of the equilibrium species (secondary aqueous species, redox couples in equilibrium with the aqueous solution, minerals in equilibrium with the aqueous solution, gases in equilibrium with the aqueous solution) within all ModelGeochemicalDatabase internal datastrcutres, with given name
Real solveForT(const DenseMatrix< Real > &reference_log10K, Real rhs) const
User object that parses a geochemical database file, and only retains information relevant to the cur...
DenseMatrix< Real > eqm_stoichiometry
eqm_stoichiometry(i, j) = stoichiometric coefficient for equilibrium species "i" in terms of the basi...
bool knownActivity(const std::string &species) const
return true iff the activity is known for the species (it is a mineral or the user has set the activi...
const std::vector< Real > & getTemperatures() const
Get the temperature points that the equilibrium constant is defined at.
void paramError(const std::string ¶m, Args... args) const
std::vector< T > & get_values()
const std::vector< std::string > _activity_species
DenseMatrix< Real > eqm_log10K
eqm_log10K(i, j) = log10(equilibrium constant) for i^th equilibrium species at the j^th temperature p...
void outputReaction(const std::string &eqm_species) const
output nicely-formatted reaction info to console
const GeochemicalDatabaseReader * original_database
a pointer to the original database used to build this ModelGeochemicalDatabase
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real getActivity(const std::string &species) const
return the activity for the species. Note that knownActivity should be checked before calling getActi...
void performSwap(ModelGeochemicalDatabase &mgd, const std::string &replace_this, const std::string &with_this)
Check that replacing the named basis species with the named equilibrium species is valid...
const std::string _equilibrium_species
std::vector< bool > basis_species_mineral
basis_species_mineral[j] = true iff the j^th basis species is a mineral
void mooseError(Args &&... args) const
std::vector< bool > eqm_species_mineral
eqm_species_mineral[i] = true iff the i^th equilibrium species is a mineral
const std::vector< Real > _activity_values
const ConsoleStream _console
void outputTemperature(const std::string &eqm_species) const
output temperature info to console
DenseMatrix sub_matrix(unsigned int row_id, unsigned int row_size, unsigned int col_id, unsigned int col_size) const
MooseUnits pow(const MooseUnits &, int)
const ExecFlagType EXEC_FINAL
static InputParameters validParams()
std::vector< std::string > eqm_species_name
eqm_species_name[i] = name of the i^th eqm species
void ErrorVector unsigned int
std::vector< std::string > basis_species_name
basis_species_name[j] = name of the j^th basis species
registerMooseObject("GeochemistryApp", GeochemicalModelInterrogator)
GeochemistrySpeciesSwapper _swapper
void bracket(std::function< Real(Real)> const &f, Real &x1, Real &x2)
Function to bracket a root of a given function.