https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
GeochemicalModelInterrogator Class Reference

Queries and performs simple manipulations on a geochemical model. More...

#include <GeochemicalModelInterrogator.h>

Inheritance diagram for GeochemicalModelInterrogator:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 GeochemicalModelInterrogator (const InputParameters &parameters)
 
virtual Real time ()
 
virtual Real timeOld ()
 
virtual Real dt ()
 
virtual Real dtOld ()
 
virtual int timeStep ()
 
const unsigned intinterval () const
 
const MultiMooseEnumexecuteOn () const
 
bool isAdvanced ()
 
virtual const OutputOnWarehouseadvancedExecuteOn () const
 
void allowOutput (bool state)
 
virtual void outputStep (const ExecFlagType &type)
 
const std::set< Real > & getSyncTimes ()
 
virtual bool supportsMaterialPropertyOutput () const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
virtual void meshChanged ()
 
virtual void initialSetup ()
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnumgetExecuteOnEnum () const
 
const FunctiongetFunction (const std::string &name) const
 
const FunctiongetFunctionByName (const FunctionName &name) const
 
bool hasFunction (const std::string &param_name) const
 
bool hasFunctionByName (const FunctionName &name) const
 
bool isDefaultPostprocessorValue (const std::string &param_name, const unsigned int index=0) const
 
bool hasPostprocessor (const std::string &param_name, const unsigned int index=0) const
 
bool hasPostprocessorByName (const PostprocessorName &name) const
 
std::size_t coupledPostprocessors (const std::string &param_name) const
 
const PostprocessorName & getPostprocessorName (const std::string &param_name, const unsigned int index=0) const
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name) const
 
const VectorPostprocessorName & getVectorPostprocessorName (const std::string &param_name) const
 
PerfGraphperfGraph ()
 
const PostprocessorValuegetPostprocessorValue (const std::string &param_name, const unsigned int index=0) const
 
const PostprocessorValuegetPostprocessorValue (const std::string &param_name, const unsigned int index=0) const
 
const PostprocessorValuegetPostprocessorValueOld (const std::string &param_name, const unsigned int index=0) const
 
const PostprocessorValuegetPostprocessorValueOld (const std::string &param_name, const unsigned int index=0) const
 
const PostprocessorValuegetPostprocessorValueOlder (const std::string &param_name, const unsigned int index=0) const
 
const PostprocessorValuegetPostprocessorValueOlder (const std::string &param_name, const unsigned int index=0) const
 
virtual const PostprocessorValuegetPostprocessorValueByName (const PostprocessorName &name) const
 
virtual const PostprocessorValuegetPostprocessorValueByName (const PostprocessorName &name) const
 
const PostprocessorValuegetPostprocessorValueOldByName (const PostprocessorName &name) const
 
const PostprocessorValuegetPostprocessorValueOldByName (const PostprocessorName &name) const
 
const PostprocessorValuegetPostprocessorValueOlderByName (const PostprocessorName &name) const
 
const PostprocessorValuegetPostprocessorValueOlderByName (const PostprocessorName &name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
UserObjectName getUserObjectName (const std::string &param_name) const
 
const T & getUserObject (const std::string &param_name, bool is_dependency=true) const
 
const T & getUserObjectByName (const UserObjectName &object_name, bool is_dependency=true) const
 
const UserObjectgetUserObjectBase (const std::string &param_name, bool is_dependency=true) const
 
const UserObjectgetUserObjectBaseByName (const UserObjectName &object_name, bool is_dependency=true) const
 
bool hasUserObject (const std::string &param_name) const
 
bool hasUserObject (const std::string &param_name) const
 
bool hasUserObject (const std::string &param_name) const
 
bool hasUserObject (const std::string &param_name) const
 
bool hasUserObjectByName (const UserObjectName &object_name) const
 
bool hasUserObjectByName (const UserObjectName &object_name) const
 
bool hasUserObjectByName (const UserObjectName &object_name) const
 
bool hasUserObjectByName (const UserObjectName &object_name) const
 

Static Public Member Functions

static InputParameters sharedParams ()
 params that are shared with the AddGeochemicalModelInterrogatorAction More...
 
static InputParameters validParams ()
 
static ExecFlagEnum getDefaultExecFlagEnum ()
 
static void addDeprecatedInputParameters (InputParameters &params)
 

Public Attributes

const ConsoleStream _console
 

Protected Types

enum  InterrogationChoiceEnum { InterrogationChoiceEnum::REACTION, InterrogationChoiceEnum::ACTIVITY, InterrogationChoiceEnum::EQM_TEMPERATURE }
 

Protected Member Functions

virtual void output () override
 
virtual void solveSetup ()
 
virtual bool shouldOutput ()
 
virtual bool onInterval ()
 
void setWallTimeIntervalFromCommandLineParam ()
 
T & declareRestartableData (const std::string &data_name, Args &&... args)
 
ManagedValue< T > declareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
const T & getRestartableData (const std::string &data_name) const
 
T & declareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 
T & declareRecoverableData (const std::string &data_name, Args &&... args)
 
T & declareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 
T & declareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 
std::string restartableName (const std::string &data_name) const
 
virtual void addPostprocessorDependencyHelper (const PostprocessorName &) const
 
virtual void addVectorPostprocessorDependencyHelper (const VectorPostprocessorName &) const
 
const ReporterNamegetReporterName (const std::string &param_name) const
 
virtual void addReporterDependencyHelper (const ReporterName &)
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const T & getReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const T & getReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
virtual void addUserObjectDependencyHelper (const UserObject &) const
 

Protected Attributes

ModelGeochemicalDatabase _mgd
 
GeochemistrySpeciesSwapper _swapper
 
const std::vector< std::string > _swap_out
 
const std::vector< std::string > _swap_in
 
const unsigned _precision
 
enum GeochemicalModelInterrogator::InterrogationChoiceEnum _interrogation
 
const Real _temperature
 
const std::vector< std::string > _activity_species
 
const std::vector< Real_activity_values
 
const std::string _equilibrium_species
 
FEProblemBase_problem_ptr
 
bool _transient
 
bool _use_displaced
 
libMesh::EquationSystems_es_ptr
 
MooseMesh_mesh_ptr
 
bool _sequence
 
ExecFlagEnum _execute_on
 
ExecFlagType _current_execute_flag
 
Real_time
 
Real_time_old
 
int_t_step
 
Real_dt
 
Real_dt_old
 
unsigned int _num
 
const bool _time_step_interval_set_by_addparam
 
unsigned int _time_step_interval
 
const Real _min_simulation_time_interval
 
const Real _simulation_time_interval
 
Real _wall_time_interval
 
std::set< Real_sync_times
 
const Times *const _sync_times_object
 
Real _start_time
 
Real _end_time
 
int _start_step
 
int _end_step
 
Real _t_tol
 
bool _sync_only
 
bool _allow_output
 
bool _is_advanced
 
OutputOnWarehouse _advanced_execute_on
 
Real_last_output_simulation_time
 
std::chrono::time_point< std::chrono::steady_clock > _last_output_wall_time
 
Real _wall_time_since_last_output
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
MooseApp_restartable_app
 
const std::string _restartable_system_name
 
const THREAD_ID _restartable_tid
 
const bool _restartable_read_only
 
FEProblemBase_mci_feproblem
 
const ExecFlagEnum_execute_enum
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 

Private Member Functions

std::vector< std::string > eqmSpeciesOfInterest () const
 provide a list of the equilibrium species of interest to the Interrogator More...
 
void outputReaction (const std::string &eqm_species) const
 output nicely-formatted reaction info to console More...
 
void outputActivity (const std::string &eqm_species) const
 output activity info to console More...
 
void outputTemperature (const std::string &eqm_species) const
 output temperature info to console More...
 
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 activity) More...
 
Real getActivity (const std::string &species) const
 return the activity for the species. Note that knownActivity should be checked before calling getActivity. More...
 
Real solveForT (const DenseMatrix< Real > &reference_log10K, Real rhs) const
 

Detailed Description

Queries and performs simple manipulations on a geochemical model.

Definition at line 20 of file GeochemicalModelInterrogator.h.

Member Enumeration Documentation

◆ InterrogationChoiceEnum

Enumerator
REACTION 
ACTIVITY 
EQM_TEMPERATURE 

Definition at line 38 of file GeochemicalModelInterrogator.h.

38 { REACTION, ACTIVITY, EQM_TEMPERATURE } _interrogation;
enum GeochemicalModelInterrogator::InterrogationChoiceEnum _interrogation

Constructor & Destructor Documentation

◆ GeochemicalModelInterrogator()

GeochemicalModelInterrogator::GeochemicalModelInterrogator ( const InputParameters parameters)

Definition at line 91 of file GeochemicalModelInterrogator.C.

92  : Output(parameters),
93  UserObjectInterface(this),
94  _mgd(getUserObject<GeochemicalModelDefinition>("model_definition").getDatabase()),
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")),
99  _interrogation(getParam<MooseEnum>("interrogation").getEnum<InterrogationChoiceEnum>()),
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"))
104 {
105  if (_swap_out.size() != _swap_in.size())
106  paramError("swap_out_of_basis must have same length as swap_into_basis");
107  if (_activity_species.size() != _activity_values.size())
108  paramError("activity_species must have same length as activity_values");
109 }
const std::vector< std::string > _swap_in
const std::vector< std::string > _swap_out
std::unordered_map< std::string, unsigned > basis_species_index
basis_species_index[name] = index of the basis species, within all ModelGeochemicalDatabase internal ...
enum GeochemicalModelInterrogator::InterrogationChoiceEnum _interrogation
Output(const InputParameters &parameters)
const T & getParam(const std::string &name) const
void paramError(const std::string &param, Args... args) const
const std::vector< std::string > _activity_species
const InputParameters & parameters() const
const std::vector< Real > _activity_values
UserObjectInterface(const MooseObject *moose_object)

Member Function Documentation

◆ eqmSpeciesOfInterest()

std::vector< std::string > GeochemicalModelInterrogator::eqmSpeciesOfInterest ( ) const
private

provide a list of the equilibrium species of interest to the Interrogator

Definition at line 160 of file GeochemicalModelInterrogator.C.

Referenced by output().

161 {
162  if (_equilibrium_species == "")
163  return _mgd.eqm_species_name;
164  else if (_mgd.eqm_species_index.count(_equilibrium_species) == 1)
165  return {_equilibrium_species};
166  return {};
167 }
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
std::vector< std::string > eqm_species_name
eqm_species_name[i] = name of the i^th eqm species

◆ getActivity()

Real GeochemicalModelInterrogator::getActivity ( const std::string &  species) const
private

return the activity for the species. Note that knownActivity should be checked before calling getActivity.

Definition at line 207 of file GeochemicalModelInterrogator.C.

Referenced by outputActivity(), and outputTemperature().

208 {
209  unsigned ind = 0;
210  for (const auto & sp : _activity_species)
211  {
212  if (sp == species)
213  return _activity_values[ind];
214  ind += 1;
215  }
216  return 1.0; // must be a mineral
217 }
const std::vector< std::string > _activity_species
const std::vector< Real > _activity_values

◆ knownActivity()

bool GeochemicalModelInterrogator::knownActivity ( const std::string &  species) const
private

return true iff the activity is known for the species (it is a mineral or the user has set the activity)

Definition at line 194 of file GeochemicalModelInterrogator.C.

Referenced by outputActivity(), and outputTemperature().

195 {
196  for (const auto & sp : _activity_species)
197  if (sp == species)
198  return true;
199  if (_mgd.basis_species_index.count(species))
201  if (_mgd.eqm_species_index.count(species))
202  return _mgd.eqm_species_mineral[_mgd.eqm_species_index.at(species)];
203  return false;
204 }
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 > 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
const std::vector< std::string > _activity_species
std::vector< bool > basis_species_mineral
basis_species_mineral[j] = true iff the j^th basis species is a mineral
std::vector< bool > eqm_species_mineral
eqm_species_mineral[i] = true iff the i^th equilibrium species is a mineral

◆ output()

void GeochemicalModelInterrogator::output ( )
overrideprotectedvirtual

Implements Output.

Definition at line 112 of file GeochemicalModelInterrogator.C.

113 {
114  for (const auto & sp : eqmSpeciesOfInterest())
115  {
116  switch (_interrogation)
117  {
119  outputReaction(sp);
120  break;
122  outputActivity(sp);
123  break;
125  outputTemperature(sp);
126  break;
127  }
128  }
129 
130  for (unsigned i = 0; i < _swap_out.size(); ++i)
131  {
132  // any exception here is an error
133  try
134  {
136  }
137  catch (const MooseException & e)
138  {
139  mooseError(e.what());
140  }
141  for (const auto & sp : eqmSpeciesOfInterest())
142  {
143  switch (_interrogation)
144  {
146  outputReaction(sp);
147  break;
149  outputActivity(sp);
150  break;
152  outputTemperature(sp);
153  break;
154  }
155  }
156  }
157 }
std::vector< std::string > eqmSpeciesOfInterest() const
provide a list of the equilibrium species of interest to the Interrogator
const std::vector< std::string > _swap_in
virtual const char * what() const
const std::vector< std::string > _swap_out
void outputActivity(const std::string &eqm_species) const
output activity info to console
enum GeochemicalModelInterrogator::InterrogationChoiceEnum _interrogation
void outputReaction(const std::string &eqm_species) const
output nicely-formatted reaction info to console
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...
void mooseError(Args &&... args) const
void outputTemperature(const std::string &eqm_species) const
output temperature info to console

◆ outputActivity()

void GeochemicalModelInterrogator::outputActivity ( const std::string &  eqm_species) const
private

output activity info to console

Definition at line 220 of file GeochemicalModelInterrogator.C.

Referenced by output().

221 {
222  if (_mgd.eqm_species_index.count(eqm_species) == 0)
223  return;
224 
225  const unsigned row = _mgd.eqm_species_index.at(eqm_species);
226  const unsigned num_cols = _mgd.basis_species_index.size();
227  const Real cutoff = std::pow(10.0, -1.0 * _precision);
228  const std::vector<Real> temps = _mgd.original_database->getTemperatures();
229  const unsigned numT = temps.size();
230  const std::string model_type = _mgd.original_database->getLogKModel();
232  temps, _mgd.eqm_log10K.sub_matrix(row, 1, 0, numT).get_values(), model_type);
233  log10K.generate();
234  Real rhs = log10K.sample(_temperature);
235  std::stringstream lhs;
236 
237  lhs << std::setprecision(_precision);
238  if (knownActivity(eqm_species))
239  rhs += std::log10(getActivity(eqm_species));
240  else
241  lhs << "(A_" << eqm_species << ")^-1 ";
242 
243  for (unsigned i = 0; i < num_cols; ++i)
244  if (std::abs(_mgd.eqm_stoichiometry(row, i)) > cutoff)
245  {
246  const std::string sp = _mgd.basis_species_name[i];
247  if (knownActivity(sp))
248  rhs -= _mgd.eqm_stoichiometry(row, i) * std::log10(getActivity(sp));
249  else
250  lhs << "(A_" << sp << ")^" << _mgd.eqm_stoichiometry(row, i) << " ";
251  }
252 
253  lhs << "= 10^" << rhs << std::endl;
254  _console << lhs.str() << std::flush;
255 }
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...
std::string getLogKModel() const
Get the equilibrium constant model type.
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
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.
virtual void generate()
DenseMatrix< Real > eqm_log10K
eqm_log10K(i, j) = log10(equilibrium constant) for i^th equilibrium species at the j^th temperature p...
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...
const ConsoleStream _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)
std::vector< std::string > basis_species_name
basis_species_name[j] = name of the j^th basis species

◆ outputReaction()

void GeochemicalModelInterrogator::outputReaction ( const std::string &  eqm_species) const
private

output nicely-formatted reaction info to console

Definition at line 170 of file GeochemicalModelInterrogator.C.

Referenced by output(), and outputTemperature().

171 {
172  if (_mgd.eqm_species_index.count(eqm_species) == 0)
173  return;
174  std::stringstream ss;
175  const unsigned row = _mgd.eqm_species_index.at(eqm_species);
176  const Real cutoff = std::pow(10.0, -1.0 * _precision);
177  const std::vector<Real> temps = _mgd.original_database->getTemperatures();
178  const unsigned numT = temps.size();
179  const std::string model_type = _mgd.original_database->getLogKModel();
181  temps, _mgd.eqm_log10K.sub_matrix(row, 1, 0, numT).get_values(), model_type);
182  log10K.generate();
183  const Real log10_eqm_const = log10K.sample(_temperature);
184  ss << std::setprecision(_precision);
185  ss << eqm_species << " = ";
188  ss << " . log10(K) = " << log10_eqm_const;
189  ss << std::endl;
190  _console << ss.str() << std::flush;
191 }
std::string reaction(const DenseMatrix< Real > &stoi, unsigned row, const std::vector< std::string > &names, Real stoi_tol=1.0E-6, int precision=4)
Returns a nicely formatted string corresponding to the reaction defined by the given row of the stoic...
Fit the equilibrium constant values read from the thermodynamic databse at specified temperature valu...
std::string getLogKModel() const
Get the equilibrium constant model type.
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
DenseMatrix< Real > eqm_stoichiometry
eqm_stoichiometry(i, j) = stoichiometric coefficient for equilibrium species "i" in terms of the basi...
const std::vector< Real > & getTemperatures() const
Get the temperature points that the equilibrium constant is defined at.
virtual void generate()
DenseMatrix< Real > eqm_log10K
eqm_log10K(i, j) = log10(equilibrium constant) for i^th equilibrium species at the j^th temperature p...
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
const ConsoleStream _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)
std::vector< std::string > basis_species_name
basis_species_name[j] = name of the j^th basis species

◆ outputTemperature()

void GeochemicalModelInterrogator::outputTemperature ( const std::string &  eqm_species) const
private

output temperature info to console

Definition at line 258 of file GeochemicalModelInterrogator.C.

Referenced by output().

259 {
260  if (_mgd.eqm_species_index.count(eqm_species) == 0)
261  return;
262 
263  const unsigned row = _mgd.eqm_species_index.at(eqm_species);
264  const unsigned num_cols = _mgd.basis_species_index.size();
265  const Real cutoff = std::pow(10.0, -1.0 * _precision);
266  Real rhs = 1.0;
267 
268  // check that we know all the required activities, otherwise compute the RHS
269  if (knownActivity(eqm_species))
270  rhs = -std::log10(getActivity(eqm_species));
271  else
272  {
273  _console << "Not enough activites known to compute equilibrium temperature for reaction\n "
274  << std::flush;
275  outputReaction(eqm_species);
276  return;
277  }
278 
279  for (unsigned i = 0; i < num_cols; ++i)
280  if (std::abs(_mgd.eqm_stoichiometry(row, i)) > cutoff)
281  {
282  const std::string sp = _mgd.basis_species_name[i];
283  if (knownActivity(sp))
284  rhs += _mgd.eqm_stoichiometry(row, i) * std::log10(getActivity(sp));
285  else
286  {
287  _console << "Not enough activites known to compute equilibrium temperature for reaction\n "
288  << std::flush;
289  outputReaction(eqm_species);
290  return;
291  }
292  }
293 
294  const Real tsoln = solveForT(
295  _mgd.eqm_log10K.sub_matrix(row, 1, 0, _mgd.original_database->getTemperatures().size()), rhs);
296  _console << eqm_species << ". T = " << tsoln << "degC" << std::endl;
297 }
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 > 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
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.
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...
const ConsoleStream _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)
std::vector< std::string > basis_species_name
basis_species_name[j] = name of the j^th basis species

◆ sharedParams()

InputParameters GeochemicalModelInterrogator::sharedParams ( )
static

params that are shared with the AddGeochemicalModelInterrogatorAction

Definition at line 18 of file GeochemicalModelInterrogator.C.

Referenced by AddGeochemicalModelInterrogatorAction::validParams(), and validParams().

19 {
21  params.addRequiredParam<UserObjectName>("model_definition",
22  "The name of the GeochemicalModelDefinition user object");
23  params.addParam<std::vector<std::string>>(
24  "swap_out_of_basis",
25  {},
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>>(
32  "swap_into_basis",
33  {},
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>>(
37  "activity_species",
38  {},
39  "Species that are provided numerical values of activity (or fugacity for gases) in the "
40  "activity_value input");
41  params.addParam<std::vector<Real>>(
42  "activity_values",
43  {},
44  "Numerical values for the activity (or fugacity) for the "
45  "species in the activity_species list. These are activity values, not log10(activity).");
46  params.addParam<unsigned int>(
47  "precision",
48  4,
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",
53  "",
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");
57  params.addParam<MooseEnum>(
58  "interrogation",
59  interrogation_choice,
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");
63  params.addParam<Real>(
64  "temperature",
65  25,
66  "Equilibrium constants will be computed at this temperature [degC]. This is "
67  "ignored if interrogation=eqm_temperature.");
68  params.addRangeCheckedParam<Real>(
69  "stoichiometry_tolerance",
70  1E-6,
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.");
76  return params;
77 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
InputParameters emptyInputParameters()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)

◆ solveForT()

Real GeochemicalModelInterrogator::solveForT ( const DenseMatrix< Real > &  reference_log10K,
Real  rhs 
) const
private
Returns
The value of temperature for which log10K = rhs. If no solution is possible, NaN is returned
Parameters
reference_log10kvalues of log10K at the values of temperature in _mgd.tmperatures. Only reference_log10K(0, *) will be used. rhs The right-hand side

Definition at line 300 of file GeochemicalModelInterrogator.C.

Referenced by outputTemperature().

301 {
302  const std::vector<Real> temps = _mgd.original_database->getTemperatures();
303  const unsigned numT = temps.size();
304  const std::string model_type = _mgd.original_database->getLogKModel();
305 
306  // find the bracket that contains the rhs
307  unsigned bracket = 0;
308  for (bracket = 0; bracket < numT - 1; ++bracket)
309  {
310  if (reference_log10K(0, bracket) <= rhs && reference_log10K(0, bracket + 1) > rhs)
311  break;
312  else if (reference_log10K(0, bracket) >= rhs && reference_log10K(0, bracket + 1) < rhs)
313  break;
314  }
315 
316  if (bracket == numT - 1)
317  return std::numeric_limits<double>::quiet_NaN();
318 
319  EquilibriumConstantInterpolator log10K(temps, reference_log10K.get_values(), model_type);
320  log10K.generate();
321  // now do a Newton-Raphson to find T for which log10K.sample(T) = rhs
323  const Real small_delT =
325  Real del_temp = small_delT;
326  unsigned iter = 0;
327  while (std::abs(del_temp) >= small_delT && iter++ < 100)
328  {
329  Real residual = log10K.sample(temp) - rhs;
330  del_temp = -residual / log10K.sampleDerivative(temp);
331  temp += del_temp;
332  }
333  return temp;
334 }
constexpr Real CELSIUS_TO_KELVIN
Fit the equilibrium constant values read from the thermodynamic databse at specified temperature valu...
std::string getLogKModel() const
Get the equilibrium constant model type.
const std::vector< Real > & getTemperatures() const
Get the temperature points that the equilibrium constant is defined at.
virtual void generate()
std::vector< Real > & get_values()
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
MooseUnits pow(const MooseUnits &, int)
void bracket(std::function< Real(Real)> const &f, Real &x1, Real &x2)
Function to bracket a root of a given function.
Definition: BrentsMethod.C:17

◆ validParams()

InputParameters GeochemicalModelInterrogator::validParams ( )
static

Definition at line 80 of file GeochemicalModelInterrogator.C.

81 {
84  params.addClassDescription("Performing simple manipulations of and querying a "
85  "geochemical model");
86 
87  params.set<ExecFlagEnum>("execute_on") = {EXEC_FINAL};
88  return params;
89 }
static InputParameters sharedParams()
params that are shared with the AddGeochemicalModelInterrogatorAction
T & set(const std::string &name, bool quiet_mode=false)
void addClassDescription(const std::string &doc_string)
const ExecFlagType EXEC_FINAL
static InputParameters validParams()

Member Data Documentation

◆ _activity_species

const std::vector<std::string> GeochemicalModelInterrogator::_activity_species
protected

◆ _activity_values

const std::vector<Real> GeochemicalModelInterrogator::_activity_values
protected

Definition at line 41 of file GeochemicalModelInterrogator.h.

Referenced by GeochemicalModelInterrogator(), and getActivity().

◆ _equilibrium_species

const std::string GeochemicalModelInterrogator::_equilibrium_species
protected

Definition at line 42 of file GeochemicalModelInterrogator.h.

Referenced by eqmSpeciesOfInterest().

◆ _interrogation

enum GeochemicalModelInterrogator::InterrogationChoiceEnum GeochemicalModelInterrogator::_interrogation
protected

Referenced by output().

◆ _mgd

ModelGeochemicalDatabase GeochemicalModelInterrogator::_mgd
protected

◆ _precision

const unsigned GeochemicalModelInterrogator::_precision
protected

◆ _swap_in

const std::vector<std::string> GeochemicalModelInterrogator::_swap_in
protected

Definition at line 36 of file GeochemicalModelInterrogator.h.

Referenced by GeochemicalModelInterrogator(), and output().

◆ _swap_out

const std::vector<std::string> GeochemicalModelInterrogator::_swap_out
protected

Definition at line 35 of file GeochemicalModelInterrogator.h.

Referenced by GeochemicalModelInterrogator(), and output().

◆ _swapper

GeochemistrySpeciesSwapper GeochemicalModelInterrogator::_swapper
protected

Definition at line 34 of file GeochemicalModelInterrogator.h.

Referenced by output().

◆ _temperature

const Real GeochemicalModelInterrogator::_temperature
protected

Definition at line 39 of file GeochemicalModelInterrogator.h.

Referenced by outputActivity(), and outputReaction().


The documentation for this class was generated from the following files: