https://mooseframework.inl.gov
GeochemistryTimeDependentReactor.C
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 
11 
13 
16 {
18  params.addParam<unsigned>(
19  "ramp_max_ionic_strength_subsequent",
20  0,
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");
24  params.addCoupledVar(
25  "mode",
26  0.0,
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).");
41  params.addCoupledVar(
42  "temperature",
43  25,
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");
52  params.addCoupledVar(
53  "cold_temperature",
54  25,
55  "This is only used if mode=4, where it is the cold temperature of the heat exchanger.");
56  params.addRangeCheckedParam<unsigned>(
57  "heating_increments",
58  1,
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 "
62  "problems converge");
63  params.addParam<Real>("initial_temperature",
64  25.0,
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",
68  0.0,
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",
74  {},
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",
80  {},
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",
85  {},
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.");
88  params.addCoupledVar("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",
94  {},
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.");
100  params.addCoupledVar("controlled_activity_value",
101  "Values of the activity or fugacity of the species in "
102  "controlled_activity_name list. These should always be positive");
103  params.addParam<bool>(
104  "evaluate_kinetic_rates_always",
105  true,
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",
112  {},
113  "Names of the kinetic species given initial values in kinetic_species_initial_value");
114  params.addParam<std::vector<Real>>(
115  "kinetic_species_initial_value",
116  {},
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");
121  params.addParam<MultiMooseEnum>(
122  "kinetic_species_unit",
123  kin_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");
126  return params;
127 }
128 
131 {
134  params.addClassDescription("UserObject that controls the time-dependent geochemistry reaction "
135  "processes. Spatial dependence is not possible using this class");
136  return params;
137 }
138 
140  const InputParameters & parameters)
141  : GeochemistryReactorBase(parameters),
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")),
147  _egs(_mgd,
148  _gac,
149  _is,
150  _swapper,
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"),
156  getParam<MultiMooseEnum>("constraint_unit"),
157  getParam<MultiMooseEnum>("constraint_meaning"),
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"),
163  getParam<MultiMooseEnum>("kinetic_species_unit")),
164  _solver(_mgd.basis_species_name.size(),
165  _mgd.kin_species_name.size(),
166  _is,
167  getParam<Real>("abs_tol"),
168  getParam<Real>("rel_tol"),
169  getParam<unsigned>("max_iter"),
170  getParam<Real>("max_initial_residual"),
171  _small_molality,
172  _max_swaps_allowed,
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")),
194  _minerals_dumped(),
195  _ramp_subsequent(getParam<unsigned>("ramp_max_ionic_strength_subsequent"))
196 {
197  // check sources and set the rates
198  if (coupledComponents("source_species_rates") != _num_source_species)
199  paramError("source_species_names", "must have the same size as source_species_rates");
200  for (unsigned i = 0; i < _num_source_species; ++i)
201  if (!(_mgd.basis_species_index.count(_source_species_names[i]) == 1 ||
204  paramError("source_species_names",
205  "The name " + _source_species_names[i] +
206  " does not appear in the basis, equilibrium or kinetic species list");
207 
208  // check and set activity controllers
209  for (unsigned i = 0; i < _num_removed_fixed; ++i)
210  {
212  paramError(
213  "remove_fixed_activity_name",
214  "The species ",
216  " is not in the basis, so cannot have its activity or fugacity constraint removed");
217  else
218  {
219  const unsigned basis_ind = _mgd.basis_species_index.at(_remove_fixed_activity_name[i]);
223  paramError("remove_fixed_activity_name",
224  "The species ",
226  " is does not have an activity or fugacity constraint so cannot have such a "
227  "constraint removed");
228  }
229  }
231  paramError("remove_fixed_activity_name",
232  "must be of the same size as remove_fixed_activity_time");
233  if (coupledComponents("controlled_activity_value") != _num_controlled_activity)
234  paramError("controlled_activity_name", "must have the same size as controlled_activity_value");
235 
236  // record coupled variables
237  const std::vector<MooseVariableFEBase *> & coupled_vars = getCoupledMooseVars();
238  for (unsigned int i = 0; i < coupled_vars.size(); i++)
239  addMooseVariableDependency(coupled_vars[i]);
240 
241  // setup minerals_dumped
242  for (unsigned i = 0; i < _mgd.basis_species_name.size(); ++i)
245  for (unsigned j = 0; j < _mgd.eqm_species_name.size(); ++j)
248  for (unsigned k = 0; k < _mgd.kin_species_name.size(); ++k)
251 }
252 
253 void
255 {
257 }
258 void
260 {
262 }
263 
264 void
266 {
267  // solve the geochemical system with its initial composition and with dt=0 so no kinetic additions
268  if (_num_my_nodes == 0)
269  return; // rather peculiar case where user has used many processors
270  _mole_additions.zero();
273  _solver_output[0],
274  _tot_iter[0],
275  _abs_residual[0],
276  0.0,
279 }
280 
281 void
283 {
284  if (_current_node->id() != 0)
285  return;
286 
288 
289  _mole_additions.zero();
291 
292  // remove appropriate constraints
294  {
295  _egs.closeSystem();
296  _closed_system = true;
297  }
298  for (unsigned i = 0; i < _num_removed_fixed; ++i)
299  {
301  {
304  _removed_fixed_activity[i] = true;
305  }
306  }
307 
308  // control activity
309  for (unsigned ca = 0; ca < _num_controlled_activity; ++ca)
310  {
311  const std::vector<GeochemicalSystem::ConstraintMeaningEnum> & cm = _egs.getConstraintMeaning();
313  {
314  const unsigned basis_ind =
319  }
320  }
321 
322  // compute moles added
323  for (unsigned i = 0; i < _num_source_species; ++i)
324  {
325  const Real this_rate = (*_source_species_rates[i])[0];
327  {
328  const unsigned basis_ind = _mgd.basis_species_index.at(_source_species_names[i]);
329  _mole_additions(basis_ind) += this_rate;
330  }
331  else if (_mgd.eqm_species_index.count(_source_species_names[i]))
332  {
333  const unsigned eqm_j = _mgd.eqm_species_index.at(_source_species_names[i]);
334  for (unsigned basis_ind = 0; basis_ind < _num_basis; ++basis_ind)
335  _mole_additions(basis_ind) += _mgd.eqm_stoichiometry(eqm_j, basis_ind) * this_rate;
336  }
337  else
338  {
339  const unsigned kin_ind = _mgd.kin_species_index.at(_source_species_names[i]);
340  _mole_additions(_num_basis + kin_ind) += this_rate;
341  }
342  }
343  for (unsigned i = 0; i < _num_basis + _num_kin; ++i)
344  _mole_additions(i) *= _dt;
345 
346  // activate special modes
347  if (_mode[0] == 1.0)
348  preSolveDump();
349  else if (_mode[0] == 3.0)
350  preSolveFlush();
351  else if (_mode[0] == 4.0)
352  {
355  }
356  else // nothing special: simply compute the desired temperature
358 
359  // set temperature, if necessary
361  {
364  }
366 
367  // solve the geochemical system
369  _solver_output[0],
370  _tot_iter[0],
371  _abs_residual[0],
372  _dt,
375 
376  // activate special modes
377  if (_mode[0] == 2.0)
379  else if (_mode[0] == 4.0)
381 }
382 
383 const GeochemicalSystem &
385 {
386  return _egs;
387 }
388 
389 const DenseVector<Real> &
391 {
392  return _mole_additions;
393 }
394 
395 const std::stringstream &
397 {
398  return _solver_output[0];
399 }
400 
402 {
403  return _tot_iter[0];
404 }
405 
407 {
408  return _abs_residual[0];
409 }
410 
411 Real
413  const std::string & species) const
414 {
415  if (_minerals_dumped.count(species) == 1)
416  return _minerals_dumped.at(species);
417  return 0.0;
418 }
419 
420 Real
421 GeochemistryTimeDependentReactor::newTemperature(const DenseVector<Real> & mole_additions) const
422 {
424  return _temperature[0];
425 
426  // if no reactants are being added, the system temperature will be _temperature[0]
427  bool any_additions = false;
428  for (unsigned i = 0; i < _num_basis + _num_kin; ++i)
429  if (mole_additions(i) > 0)
430  {
431  any_additions = true;
432  break;
433  }
434  if (!any_additions)
435  return _temperature[0];
436 
437  // assume heat capacities of inputs and outputs are the same, so final temperature is dictated
438  // by masses, also assume that the input happens first, then temperature equilibration, then
439  // the outputs occur
440  Real new_temperature = _temperature[0];
441  const std::vector<Real> & current_bulk = _egs.getBulkMolesOld();
442  Real current_kg = current_bulk[0] / GeochemistryConstants::MOLES_PER_KG_WATER;
443  Real input_kg = std::max(mole_additions(0), 0.0) / GeochemistryConstants::MOLES_PER_KG_WATER;
444  for (unsigned i = 1; i < _num_basis; ++i)
445  {
446  current_kg += current_bulk[i] * _mgd.basis_species_molecular_weight[i] / 1000.0;
447  input_kg += std::max(mole_additions(i), 0.0) * _mgd.basis_species_molecular_weight[i] / 1000.0;
448  }
449  for (unsigned k = 0; k < _num_kin; ++k)
450  input_kg += std::max(mole_additions(k + _num_basis), 0.0) *
452  new_temperature =
453  (_previous_temperature * current_kg + _temperature[0] * input_kg) / (current_kg + input_kg);
454  return new_temperature;
455 }
456 
457 void
459 {
460  // remove basis mineral moles
461  const std::vector<Real> & current_molal = _egs.getSolventMassAndFreeMolalityAndMineralMoles();
462  for (unsigned i = 1; i < _num_basis; ++i)
464  {
465  _mole_additions(i) = -current_molal[i]; // might overwrite the rates set above, which is good
466  _minerals_dumped[_mgd.basis_species_name[i]] += current_molal[i];
467  }
468 
470 
471  // add the chemicals immediately instead of during the solve (as occurs for other modes)
472  for (unsigned basis_ind = 0; basis_ind < _num_basis; ++basis_ind)
473  {
474  _egs.addToBulkMoles(basis_ind, _mole_additions(basis_ind));
475  _mole_additions(basis_ind) = 0.0;
476  }
477  // dump needs free mineral moles to be exactly zero and the above addToBulkMoles will have set
478  // this for standard minerals, but not things related to sorption or kinetic minerals, so:
480 
481  // Now need to swap all minerals out of the basis
482  const std::vector<Real> & eqm_molality = _egs.getEquilibriumMolality();
483  unsigned swap_into_basis = 0;
484  for (unsigned i = 0; i < _num_basis; ++i)
486  {
487  const bool legitimate_swap_found = _egs.getSwapper().findBestEqmSwap(
488  i, _mgd, eqm_molality, false, false, false, swap_into_basis);
489  if (legitimate_swap_found)
490  {
491  try
492  {
493  _egs.performSwap(i, swap_into_basis);
494  }
495  catch (const MooseException & e)
496  {
497  mooseError(e.what());
498  }
499  }
500  }
501 }
502 
503 void
505 {
507 
508  // Here we conserve mass, so compute the mass of the solution, without the free mineral moles.
509  // We don't include the free mineral moles because users of GeochemistWorkbench will want
510  // "flush" to operate like Bethke Eqn(13.14)
511  // I assume we also don't include kinetic-mineral moles
513  for (unsigned i = 1; i < _num_basis; ++i)
514  if (!_mgd.basis_species_mineral[i])
515  kg_in += _mole_additions(i) * _mgd.basis_species_molecular_weight[i] / 1000.0;
516  for (unsigned kin = 0; kin < _num_kin; ++kin)
517  if (!_mgd.kin_species_mineral[kin])
518  kg_in += _mole_additions(kin + _num_basis) * _mgd.kin_species_molecular_weight[kin] / 1000.0;
519 
520  const std::vector<Real> & current_bulk = _egs.getBulkMolesOld();
521  const std::vector<Real> & current_molal = _egs.getSolventMassAndFreeMolalityAndMineralMoles();
522  const std::vector<Real> & kin_moles = _egs.getKineticMoles();
523 
524  // compute the current mass, without moles from free minerals and without kinetic minerals
525  Real current_kg = current_bulk[0] / GeochemistryConstants::MOLES_PER_KG_WATER;
526  for (unsigned i = 1; i < _num_basis; ++i)
527  {
528  Real kinetic_contribution = 0.0;
529  for (unsigned k = 0; k < _num_kin; ++k)
531  kinetic_contribution += kin_moles[k] * _mgd.kin_stoichiometry(k, i);
533  current_kg += (current_bulk[i] - current_molal[i] - kinetic_contribution) *
535  else
536  current_kg += (current_bulk[i] - kinetic_contribution) *
538  }
539 
540  const Real fraction_to_remove = kg_in / current_kg;
541  for (unsigned i = 0; i < _num_basis; ++i)
542  {
543  Real all_kinetic_contribution = 0.0;
544  for (unsigned k = 0; k < _num_kin; ++k)
545  all_kinetic_contribution += kin_moles[k] * _mgd.kin_stoichiometry(k, i);
547  _mole_additions(i) -=
548  fraction_to_remove * (current_bulk[i] - current_molal[i] - all_kinetic_contribution);
549  else
550  _mole_additions(i) -= fraction_to_remove * (current_bulk[i] - all_kinetic_contribution);
551  }
552  for (unsigned k = 0; k < _num_kin; ++k)
553  if (!_mgd.kin_species_mineral[k])
554  _mole_additions(k + _num_basis) -= fraction_to_remove * kin_moles[k];
555 }
556 
557 void
559 {
560  // copy the current_molal values into a new vector
561  const std::vector<Real> current_molal = _egs.getSolventMassAndFreeMolalityAndMineralMoles();
562  // remove minerals
563  for (unsigned i = 1; i < _num_basis; ++i)
565  {
566  const Real to_remove = current_molal[i] - _small_molality * 10.0;
567  _egs.addToBulkMoles(i, -to_remove);
568  _minerals_dumped[_mgd.basis_species_name[i]] += to_remove;
569  }
570 
571  // copy the current kinetic moles into a new vector
572  const std::vector<Real> kin_moles = _egs.getKineticMoles();
573  // remove minerals
574  for (unsigned k = 0; k < _num_kin; ++k)
576  {
577  const Real to_remove = kin_moles[k] - _small_molality;
578  for (unsigned i = 0; i < _num_basis; ++i)
579  if (_mgd.kin_stoichiometry(k, i) != 0)
581  -_mgd.kin_stoichiometry(k, i) *
582  to_remove); // remember bulk moles contains kinetic contributions
584  _minerals_dumped[_mgd.kin_species_name[k]] += to_remove;
585  }
586 
588 }
589 
590 void
592 {
593  const std::vector<Real> & current_bulk = _egs.getBulkMolesOld();
594  for (unsigned i = 0; i < _num_basis; ++i)
595  _mole_additions(i) -= current_bulk[i];
596  const std::vector<Real> & kin_moles = _egs.getKineticMoles();
597  for (unsigned k = 0; k < _num_kin; ++k)
598  _mole_additions(k + _num_basis) -= kin_moles[k];
599 }
600 
601 void
603 {
604  // remove precipitates
606 
607  DenseVector<Real> zero_mole_additions(_num_basis + _num_kin);
608  DenseMatrix<Real> zero_dmole_additions(_num_basis + _num_kin, _num_basis + _num_kin);
609 
610  const Real del_temperature = (_temperature[0] - _previous_temperature) / _heating_increments;
611 
612  for (unsigned incr = 0; incr < _heating_increments; ++incr)
613  {
614  // set temperature
615  _new_temperature = _previous_temperature + del_temperature;
619 
620  zero_mole_additions.zero();
621  zero_dmole_additions.zero();
622 
623  // solve the geochemical system
625  _solver_output[0],
626  _tot_iter[0],
627  _abs_residual[0],
628  _dt,
629  zero_mole_additions,
630  zero_dmole_additions);
631 
632  // remove precipitates
634  }
635 }
const unsigned _num_basis
number of basis species
void computeConsistentConfiguration()
Compute a reasonably consistent configuration that can be used as an initial condition in a Newton pr...
virtual void finalize() override
virtual const std::stringstream & getSolverOutput(dof_id_type node_id) const override
constexpr Real MOLES_PER_KG_WATER
const unsigned _num_source_species
Number of source species.
static InputParameters validParams()
std::vector< bool > kin_species_mineral
kin_species_mineral[j] = true iff the j^th kinetic species is a mineral
virtual const char * what() const
std::vector< unsigned > _tot_iter
Number of iterations used by the solver at each node.
std::vector< bool > _removed_fixed_activity
Whether the activity or activity constraint has been removfed.
void changeConstraintToBulk(unsigned basis_ind)
Changes the constraint to MOLES_BULK_SPECIES (or MOLES_BULK_WATER if basis_ind = 0) for the basis ind...
bool _closed_system
Whether the system has been closed.
const std::vector< Real > & getBulkMolesOld() const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
ModelGeochemicalDatabase _mgd
my copy of the underlying ModelGeochemicalDatabase
virtual void zero() override final
void preSolveFlush()
Activate the special "flush" mode prior to solving the geochemical system:
std::unordered_map< std::string, unsigned > basis_species_index
basis_species_index[name] = index of the basis species, within all ModelGeochemicalDatabase internal ...
void preSolveDump()
Activate the special "dump" mode prior to solving the geochemical system:
const Node *const & _current_node
virtual const DenseVector< Real > & getMoleAdditions(dof_id_type node_id) const override
DenseMatrix< Real > kin_stoichiometry
kin_stoichiometry(i, j) = stoichiometric coefficient for kinetic species "i" in terms of the basis sp...
std::vector< Real > kin_species_molecular_weight
all quantities have a molecular weight (g/mol)
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 & _mode
Mode of the system (flush, flow-through, etc)
const unsigned _num_removed_fixed
Number of elements in the vector _remove_fixed_activity_name;.
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
Class that controls the time-dependent (but not space-dependent) geochemistry reactions.
GeochemistryTimeDependentReactor(const InputParameters &parameters)
void removeCurrentSpecies()
Alter _mole_additions so that it will represent the situation in which all current species are remove...
const VariableValue & _temperature
Temperature specified by user.
const std::vector< std::string > _remove_fixed_activity_name
Names of species to remove the fixed activity or fugacity constraint from.
const unsigned _num_kin
Number of kinetic species.
InputParameters emptyInputParameters()
std::unordered_map< std::string, unsigned > kin_species_index
kin_species_index[name] = index of the kinetic species, within all ModelGeochemicalDatabase internal ...
DenseMatrix< Real > eqm_stoichiometry
eqm_stoichiometry(i, j) = stoichiometric coefficient for equilibrium species "i" in terms of the basi...
ConstraintMeaningEnum
Each basis species has one of the following constraints.
Real _previous_temperature
Temperature at which the _egs was last made consistent.
const unsigned _num_my_nodes
Number of nodes handled by this processor (will need to be made un-const when mesh adaptivity is hand...
void setKineticMoles(unsigned kin, Real moles)
Sets the current AND old mole number for a kinetic species.
std::unordered_map< std::string, Real > _minerals_dumped
Moles of mineral removed by dump and flow-through.
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...
std::vector< std::stringstream > _solver_output
The solver output at each node.
const VariableValue & _cold_temperature
Cold temperature specified by user, which is used only when mode==4.
Real getKineticMoles(unsigned kin) const
void postSolveFlowThrough()
Activate the special "flow-through" mode after solving the geochemical system:
const std::vector< const VariableValue * > _source_species_rates
Rates of the source species.
const std::vector< std::string > _controlled_activity_species_names
Names of the species with controlled activity or fugacity.
const std::vector< std::string > _source_species_names
Names of the source species.
void paramError(const std::string &param, Args... args) const
virtual Real getSolverResidual(dof_id_type node_id) const override
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.
virtual Real getMolesDumped(dof_id_type node_id, const std::string &species) const override
GeochemicalSystem _egs
The equilibrium geochemical system that holds all the molalities, activities, etc.
registerMooseObject("GeochemistryApp", GeochemistryTimeDependentReactor)
virtual void initialize() override
void addCoupledVar(const std::string &name, const std::string &doc_string)
const std::vector< MooseVariableFieldBase *> & getCoupledMooseVars() const
std::vector< Real > basis_species_molecular_weight
all quantities have a molecular weight (g)
DenseVector< Real > _mole_additions
Moles of each basis species added at the current timestep, along with kinetic rates.
unsigned int coupledComponents(const std::string &var_name) const
const unsigned _num_controlled_activity
Number of species with controlled activity or fugacity.
Real _new_temperature
Temperature at which the solution is required.
void addMooseVariableDependency(MooseVariableFieldBase *var)
static InputParameters sharedParams()
params that are shared with AddTimeDependentReactionSolverAction
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< Real > _abs_residual
L1norm of the solver residual at each node.
virtual unsigned getSolverIterations(dof_id_type node_id) const override
Real getEquilibriumMolality(unsigned j) const
void setRampMaxIonicStrength(unsigned ramp_max_ionic_strength)
Sets the value of _ramp_max_ionic_strength.
void setTemperature(Real temperature)
Sets the temperature to the given quantity.
This class holds information about bulk composition, molalities, activities, activity coefficients...
virtual const GeochemicalSystem & getGeochemicalSystem(dof_id_type node_id) const override
Real newTemperature(const DenseVector< Real > &mole_additions) const
Based on _temperature[0], mole_additions, the current mass of the system and the current temperature ...
std::vector< bool > basis_species_mineral
basis_species_mineral[j] = true iff the j^th basis species is a mineral
const unsigned _ramp_subsequent
the ramp_max_ionic_strength to use during time-stepping
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
std::vector< std::string > kin_species_name
kin_species_name[j] = name of the j^th kinetic species
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
std::vector< bool > eqm_species_mineral
eqm_species_mineral[i] = true iff the i^th equilibrium species is a mineral
const std::vector< Real > & getSolventMassAndFreeMolalityAndMineralMoles() const
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const unsigned _heating_increments
If mode=4 then temperature is ramped from _cold_temperature to _temperature in heating_increments inc...
Base class that controls the spatio-temporal solution of geochemistry reactions.
const GeochemistrySpeciesSwapper & getSwapper() const
const std::vector< const VariableValue * > _controlled_activity_species_values
Activity or fugacity of the species with controlled activity or fugacity.
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 performSwap(unsigned swap_out_of_basis, unsigned swap_into_basis)
Perform the basis swap, and ensure that the resulting system is consistent.
void setConstraintValue(unsigned basis_ind, Real value)
Set the constraint value for the basis species.
void postSolveExchanger()
This is relevant for mode=4 simulations (heat-exchanger simulations).
void closeSystem()
Changes a KG_SOLVENT_WATER constraint to MOLES_BULK_WATER (if there is such a constraint) and all FRE...
const Real _small_molality
A small value of molality.
void setMineralRelatedFreeMoles(Real value)
Set the free mole number of mineral-related species to the value provided.
std::vector< std::string > eqm_species_name
eqm_species_name[i] = name of the i^th eqm species
static const std::string k
Definition: NS.h:130
std::vector< std::string > basis_species_name
basis_species_name[j] = name of the j^th basis species
const std::vector< GeochemicalSystem::ConstraintMeaningEnum > & getConstraintMeaning() const
const Real _close_system_at_time
Defines the time at which to close the system.
uint8_t dof_id_type
DenseMatrix< Real > _dmole_additions
Derivative of moles_added.