19 "ramp_max_ionic_strength_subsequent",
21 "The number of iterations over which to progressively increase the maximum ionic strength "
22 "(from zero to max_ionic_strength) during time-stepping. Unless a great deal occurs in each "
23 "time step, this parameter can be set quite small");
27 "This may vary temporally. If mode=1 then 'dump' mode is used, which means all non-kinetic "
28 "mineral masses are removed from the system before the equilibrium solution is sought (ie, "
29 "removal occurs at the beginning of the time step). If mode=2 then 'flow-through' mode is "
30 "used, which means all mineral masses are removed from the system after it the "
31 "equilbrium solution has been found (ie, at the end of a time step). If mode=3 then 'flush' "
32 "mode is used, then before the equilibrium solution is sought (ie, at the start of a time "
33 "step) water+species is removed from the system at the same rate as pure water + non-mineral "
34 "solutes are entering the system (specified in source_species_rates). If mode=4 then "
35 "'heat-exchanger' mode is used, which means the entire current aqueous solution is removed, "
36 "then the source_species are added, then the temperature is set to 'cold_temperature', the "
37 "system is solved and any precipitated minerals are removed, then the temperature is set to "
38 "'temperature', the system re-solved and any precipitated minerals are removed. If mode is "
39 "any other number, no special mode is active (the system simply responds to the "
40 "source_species_rates, controlled_activity_value, etc).");
44 "Temperature. This has two different meanings if mode!=4. (1) If no species are being "
45 "added to the solution (no source_species_rates are positive) then this is the temperature "
46 "of the aqueous solution. (2) If species are being added, this is the temperature of the "
47 "species being added. In case (2), the final aqueous-solution temperature is computed "
48 "assuming the species are added, temperature is equilibrated and then, if species are also "
49 "being removed, they are removed. If you wish to add species and simultaneously alter the "
50 "temperature, you will have to use a sequence of heat-add-heat-add, etc steps. In the case "
51 "that mode=4, temperature is the final temperature of the aqueous solution");
55 "This is only used if mode=4, where it is the cold temperature of the heat exchanger.");
59 "heating_increments > 0",
60 "This is only used if mode=4. Internal to this object, the temperature is ramped from "
61 "cold_temperature to temperature in heating_increments increments. This helps difficult "
63 params.
addParam<Real>(
"initial_temperature",
65 "The initial aqueous solution is equilibrated at this system before adding "
66 "reactants, changing temperature, etc.");
67 params.
addParam<Real>(
"close_system_at_time",
69 "Time at which to 'close' the system, that is, change a kg_solvent_water "
70 "constraint to moles_bulk_water, and all free_molality and "
71 "free_moles_mineral_species to moles_bulk_species");
72 params.
addParam<std::vector<std::string>>(
73 "remove_fixed_activity_name",
75 "The name of the species that should have their activity or fugacity constraint removed at "
76 "time given in remove_fixed_activity_time. There should be an equal number of these names "
77 "as times given in remove_fixed_activity_time. Each of these must be in the basis and have "
78 "an activity or fugacity constraint");
79 params.
addParam<std::vector<Real>>(
"remove_fixed_activity_time",
81 "The times at which the species in remove_fixed_activity_name "
82 "should have their activity or fugacity constraint removed.");
83 params.
addParam<std::vector<std::string>>(
84 "source_species_names",
86 "The name of the species that are added at rates given in source_species_rates. There must "
87 "be an equal number of these as source_species_rates.");
89 "Rates, in mols/time_unit, of addition of the species with names given in "
90 "source_species_names. A negative value corresponds to removing a species: "
91 "be careful that you don't cause negative mass problems!");
92 params.
addParam<std::vector<std::string>>(
93 "controlled_activity_name",
95 "The names of the species that have their activity or fugacity constrained. There should be "
96 "an equal number of these names as values given in controlled_activity_value. NOTE: if "
97 "these species are not in the basis, or they do not have an activity (or fugacity) "
98 "constraint then their activity cannot be controlled: in this case MOOSE will ignore the "
99 "value you prescribe in controlled_activity_value.");
101 "Values of the activity or fugacity of the species in "
102 "controlled_activity_name list. These should always be positive");
104 "evaluate_kinetic_rates_always",
106 "If true, then, evaluate the kinetic rates at every Newton step during the solve using the "
107 "current values of molality, activity, etc (ie, implement an implicit solve). If false, "
108 "then evaluate the kinetic rates using the values of molality, activity, etc, at the start "
109 "of the current time step (ie, implement an explicit solve)");
110 params.
addParam<std::vector<std::string>>(
111 "kinetic_species_name",
113 "Names of the kinetic species given initial values in kinetic_species_initial_value");
115 "kinetic_species_initial_value",
117 "Initial number of moles, mass or volume (depending on kinetic_species_unit) for each of the "
118 "species named in kinetic_species_name");
119 MultiMooseEnum kin_species_unit(
"dimensionless moles molal kg g mg ug kg_per_kg_solvent "
120 "g_per_kg_solvent mg_per_kg_solvent ug_per_kg_solvent cm3");
122 "kinetic_species_unit",
124 "Units of the numerical values given in kinetic_species_initial_value. Moles: mole number. "
125 "kg: kilograms. g: grams. mg: milligrams. ug: micrograms. cm3: cubic centimeters");
134 params.
addClassDescription(
"UserObject that controls the time-dependent geochemistry reaction "
135 "processes. Spatial dependence is not possible using this class");
142 _temperature(coupledValue(
"temperature")),
143 _cold_temperature(coupledValue(
"cold_temperature")),
144 _heating_increments(getParam<unsigned>(
"heating_increments")),
145 _new_temperature(getParam<Real>(
"initial_temperature")),
146 _previous_temperature(getParam<Real>(
"initial_temperature")),
151 getParam<
std::vector<
std::string>>(
"swap_out_of_basis"),
152 getParam<
std::vector<
std::string>>(
"swap_into_basis"),
153 getParam<
std::string>(
"charge_balance_species"),
154 getParam<
std::vector<
std::string>>(
"constraint_species"),
155 getParam<
std::vector<Real>>(
"constraint_value"),
158 _previous_temperature,
159 getParam<unsigned>(
"extra_iterations_to_make_consistent"),
160 getParam<Real>(
"min_initial_molality"),
161 getParam<
std::vector<
std::string>>(
"kinetic_species_name"),
162 getParam<
std::vector<Real>>(
"kinetic_species_initial_value"),
164 _solver(_mgd.basis_species_name.size(),
165 _mgd.kin_species_name.size(),
167 getParam<Real>(
"abs_tol"),
168 getParam<Real>(
"rel_tol"),
169 getParam<unsigned>(
"max_iter"),
170 getParam<Real>(
"max_initial_residual"),
173 getParam<
std::vector<
std::string>>(
"prevent_precipitation"),
174 getParam<Real>(
"max_ionic_strength"),
175 getParam<unsigned>(
"ramp_max_ionic_strength_initial"),
176 getParam<bool>(
"evaluate_kinetic_rates_always")),
177 _num_kin(_egs.getNumKinetic()),
178 _close_system_at_time(getParam<Real>(
"close_system_at_time")),
179 _closed_system(false),
180 _source_species_names(getParam<
std::vector<
std::string>>(
"source_species_names")),
181 _num_source_species(_source_species_names.size()),
182 _source_species_rates(coupledValues(
"source_species_rates")),
183 _remove_fixed_activity_name(getParam<
std::vector<
std::string>>(
"remove_fixed_activity_name")),
184 _remove_fixed_activity_time(getParam<
std::vector<Real>>(
"remove_fixed_activity_time")),
185 _num_removed_fixed(_remove_fixed_activity_name.size()),
186 _removed_fixed_activity(_num_removed_fixed, false),
187 _controlled_activity_species_names(
188 getParam<
std::vector<
std::string>>(
"controlled_activity_name")),
189 _num_controlled_activity(_controlled_activity_species_names.size()),
190 _controlled_activity_species_values(coupledValues(
"controlled_activity_value")),
191 _mole_additions(_num_basis + _num_kin),
192 _dmole_additions(_num_basis + _num_kin, _num_basis + _num_kin),
193 _mode(coupledValue(
"mode")),
195 _ramp_subsequent(getParam<unsigned>(
"ramp_max_ionic_strength_subsequent"))
199 paramError(
"source_species_names",
"must have the same size as source_species_rates");
206 " does not appear in the basis, equilibrium or kinetic species list");
213 "remove_fixed_activity_name",
216 " is not in the basis, so cannot have its activity or fugacity constraint removed");
226 " is does not have an activity or fugacity constraint so cannot have such a "
227 "constraint removed");
232 "must be of the same size as remove_fixed_activity_time");
234 paramError(
"controlled_activity_name",
"must have the same size as controlled_activity_value");
238 for (
unsigned int i = 0; i < coupled_vars.size(); i++)
314 const unsigned basis_ind =
334 for (
unsigned basis_ind = 0; basis_ind <
_num_basis; ++basis_ind)
349 else if (
_mode[0] == 3.0)
351 else if (
_mode[0] == 4.0)
379 else if (
_mode[0] == 4.0)
389const DenseVector<Real> &
395const std::stringstream &
415 const std::string & species)
const
429 bool any_additions =
false;
431 if (mole_additions(i) > 0)
433 any_additions =
true;
451 for (
unsigned k = 0; k <
_num_kin; ++k)
452 input_kg += std::max(mole_additions(k +
_num_basis), 0.0) *
456 return new_temperature;
474 for (
unsigned basis_ind = 0; basis_ind <
_num_basis; ++basis_ind)
485 unsigned swap_into_basis = 0;
490 i,
_mgd, eqm_molality,
false,
false,
false, swap_into_basis);
491 if (legitimate_swap_found)
518 for (
unsigned kin = 0; kin <
_num_kin; ++kin)
530 Real kinetic_contribution = 0.0;
531 for (
unsigned k = 0; k <
_num_kin; ++k)
535 current_kg += (current_bulk[i] - current_molal[i] - kinetic_contribution) *
538 current_kg += (current_bulk[i] - kinetic_contribution) *
542 const Real fraction_to_remove = kg_in / current_kg;
545 Real all_kinetic_contribution = 0.0;
546 for (
unsigned k = 0; k <
_num_kin; ++k)
550 fraction_to_remove * (current_bulk[i] - current_molal[i] - all_kinetic_contribution);
552 _mole_additions(i) -= fraction_to_remove * (current_bulk[i] - all_kinetic_contribution);
554 for (
unsigned k = 0; k <
_num_kin; ++k)
576 for (
unsigned k = 0; k <
_num_kin; ++k)
599 for (
unsigned k = 0; k <
_num_kin; ++k)
622 zero_mole_additions.zero();
623 zero_dmole_additions.zero();
632 zero_dmole_additions);
registerMooseObject("GeochemistryApp", GeochemistryTimeDependentReactor)
const std::vector< MooseVariableFieldBase * > & getCoupledMooseVars() const
unsigned int coupledComponents(const std::string &var_name) const
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.
void setRampMaxIonicStrength(unsigned ramp_max_ionic_strength)
Sets the value of _ramp_max_ionic_strength.
This class holds information about bulk composition, molalities, activities, activity coefficients,...
const std::vector< GeochemicalSystem::ConstraintMeaningEnum > & getConstraintMeaning() const
const GeochemistrySpeciesSwapper & getSwapper() const
void setMineralRelatedFreeMoles(Real value)
Set the free mole number of mineral-related species to the value provided.
void setKineticMoles(unsigned kin, Real moles)
Sets the current AND old mole number for a kinetic species.
void computeConsistentConfiguration()
Compute a reasonably consistent configuration that can be used as an initial condition in a Newton pr...
void changeConstraintToBulk(unsigned basis_ind)
Changes the constraint to MOLES_BULK_SPECIES (or MOLES_BULK_WATER if basis_ind = 0) for the basis ind...
void performSwap(unsigned swap_out_of_basis, unsigned swap_into_basis)
Perform the basis swap, and ensure that the resulting system is consistent.
Real getKineticMoles(unsigned kin) const
void addToBulkMoles(unsigned basis_ind, Real value)
Add to the MOLES_BULK_SPECIES (or MOLES_BULK_WATER if basis_ind = 0) for the basis species.
void setConstraintValue(unsigned basis_ind, Real value)
Set the constraint value for the basis species.
const std::vector< Real > & getBulkMolesOld() const
const std::vector< Real > & getSolventMassAndFreeMolalityAndMineralMoles() const
ConstraintMeaningEnum
Each basis species has one of the following constraints.
void closeSystem()
Changes a KG_SOLVENT_WATER constraint to MOLES_BULK_WATER (if there is such a constraint) and all FRE...
Real getEquilibriumMolality(unsigned j) const
void setTemperature(Real temperature)
Sets the temperature to the given quantity.
Base class that controls the spatio-temporal solution of geochemistry reactions.
virtual void finalize() override
std::vector< unsigned > _tot_iter
Number of iterations used by the solver at each node.
virtual void initialize() override
static InputParameters validParams()
const unsigned _num_my_nodes
Number of nodes handled by this processor (will need to be made un-const when mesh adaptivity is hand...
std::vector< Real > _abs_residual
L1norm of the solver residual at each node.
const unsigned _num_basis
number of basis species
ModelGeochemicalDatabase _mgd
my copy of the underlying ModelGeochemicalDatabase
std::vector< std::stringstream > _solver_output
The solver output at each node.
const Real _small_molality
A small value of molality.
bool findBestEqmSwap(unsigned basis_ind, const ModelGeochemicalDatabase &mgd, const std::vector< Real > &eqm_molality, bool minerals_allowed, bool gas_allowed, bool sorption_allowed, unsigned &best_eqm_species) const
For the the given basis index, find the equilibrium index that it should be swapped with.
Class that controls the time-dependent (but not space-dependent) geochemistry reactions.
const unsigned _ramp_subsequent
the ramp_max_ionic_strength to use during time-stepping
const VariableValue & _cold_temperature
Cold temperature specified by user, which is used only when mode==4.
const unsigned _heating_increments
If mode=4 then temperature is ramped from _cold_temperature to _temperature in heating_increments inc...
virtual const GeochemicalSystem & getGeochemicalSystem(dof_id_type node_id) const override
Real _previous_temperature
Temperature at which the _egs was last made consistent.
virtual void finalize() override
std::unordered_map< std::string, Real > _minerals_dumped
Moles of mineral removed by dump and flow-through.
static InputParameters validParams()
void postSolveExchanger()
This is relevant for mode=4 simulations (heat-exchanger simulations).
const unsigned _num_controlled_activity
Number of species with controlled activity or fugacity.
Real newTemperature(const DenseVector< Real > &mole_additions) const
Based on _temperature[0], mole_additions, the current mass of the system and the current temperature ...
virtual void initialSetup() override
const std::vector< const VariableValue * > _source_species_rates
Rates of the source species.
const unsigned _num_source_species
Number of source species.
DenseMatrix< Real > _dmole_additions
Derivative of moles_added.
void preSolveFlush()
Activate the special "flush" mode prior to solving the geochemical system:
GeochemicalSolver _solver
The solver.
const std::vector< Real > _remove_fixed_activity_time
Times at which to remove the fixed activity or fugacity from the species in _remove_fixed_activity_na...
const VariableValue & _temperature
Temperature specified by user.
void postSolveFlowThrough()
Activate the special "flow-through" mode after solving the geochemical system:
static InputParameters sharedParams()
params that are shared with AddTimeDependentReactionSolverAction
const std::vector< std::string > _controlled_activity_species_names
Names of the species with controlled activity or fugacity.
virtual const DenseVector< Real > & getMoleAdditions(dof_id_type node_id) const override
void removeCurrentSpecies()
Alter _mole_additions so that it will represent the situation in which all current species are remove...
const std::vector< std::string > _remove_fixed_activity_name
Names of species to remove the fixed activity or fugacity constraint from.
virtual void execute() override
virtual Real getMolesDumped(dof_id_type node_id, const std::string &species) const override
const unsigned _num_kin
Number of kinetic species.
const unsigned _num_removed_fixed
Number of elements in the vector _remove_fixed_activity_name;.
bool _closed_system
Whether the system has been closed.
GeochemistryTimeDependentReactor(const InputParameters ¶meters)
DenseVector< Real > _mole_additions
Moles of each basis species added at the current timestep, along with kinetic rates.
const Real _close_system_at_time
Defines the time at which to close the system.
virtual const std::stringstream & getSolverOutput(dof_id_type node_id) const override
virtual unsigned getSolverIterations(dof_id_type node_id) const override
const std::vector< std::string > _source_species_names
Names of the source species.
void preSolveDump()
Activate the special "dump" mode prior to solving the geochemical system:
std::vector< bool > _removed_fixed_activity
Whether the activity or activity constraint has been removfed.
const VariableValue & _mode
Mode of the system (flush, flow-through, etc)
const std::vector< const VariableValue * > _controlled_activity_species_values
Activity or fugacity of the species with controlled activity or fugacity.
Real _new_temperature
Temperature at which the solution is required.
virtual Real getSolverResidual(dof_id_type node_id) const override
virtual void initialize() override
GeochemicalSystem _egs
The equilibrium geochemical system that holds all the molalities, activities, etc.
void paramError(const std::string ¶m, Args... args) const
void mooseError(Args &&... args) const
virtual const char * what() const
void addMooseVariableDependency(MooseVariableFieldBase *var)
const Node *const & _current_node
virtual void zero() override final
constexpr Real MOLES_PER_KG_WATER
std::vector< bool > eqm_species_mineral
eqm_species_mineral[i] = true iff the i^th equilibrium species is a mineral
DenseMatrix< Real > eqm_stoichiometry
eqm_stoichiometry(i, j) = stoichiometric coefficient for equilibrium species "i" in terms of the basi...
std::vector< Real > basis_species_molecular_weight
all quantities have a molecular weight (g)
DenseMatrix< Real > kin_stoichiometry
kin_stoichiometry(i, j) = stoichiometric coefficient for kinetic species "i" in terms of the basis sp...
std::vector< bool > kin_species_mineral
kin_species_mineral[j] = true iff the j^th kinetic species is a mineral
std::vector< std::string > kin_species_name
kin_species_name[j] = name of the j^th kinetic species
std::vector< bool > basis_species_mineral
basis_species_mineral[j] = true iff the j^th basis species is a mineral
std::unordered_map< std::string, unsigned > eqm_species_index
eqm_species_index[name] = index of the equilibrium species (secondary aqueous species,...
std::vector< std::string > basis_species_name
basis_species_name[j] = name of the j^th basis species
std::unordered_map< std::string, unsigned > basis_species_index
basis_species_index[name] = index of the basis species, within all ModelGeochemicalDatabase internal ...
std::unordered_map< std::string, unsigned > kin_species_index
kin_species_index[name] = index of the kinetic species, within all ModelGeochemicalDatabase internal ...
std::vector< std::string > eqm_species_name
eqm_species_name[i] = name of the i^th eqm species
std::vector< Real > kin_species_molecular_weight
all quantities have a molecular weight (g/mol)