https://mooseframework.inl.gov
Functions
GeochemistryFormattedOutput Namespace Reference

Functions

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 stoichiometric matrix. More...
 

Function Documentation

◆ reaction()

std::string GeochemistryFormattedOutput::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 stoichiometric matrix.

For instance, if stoi(row, :) = (1, 2, 1E-5, -0.333333333333) and names = ["H2O", "H+", "HCO3-", "O2(aq)"] then this function will return "H2O + 2*H+ - 0.333*O2(aq)" if stoi_tol=1E-4 and precision = 3

Parameters
stoimatrix stoichiometric coefficients
rowrow of stoi which defines the reaction of interest
namesnames of the basis species
stoi_tolAny stoichiometric coefficients of magnitude less than this value will not appear in the returned string
precisionMaximum number of digits written for each stoichiometric coefficient in the returned string

Definition at line 15 of file GeochemistryFormattedOutput.C.

Referenced by GeochemistryConsoleOutput::output(), GeochemistryConsoleOutput::outputNernstInfo(), GeochemicalModelInterrogator::outputReaction(), GeochemicalDatabaseReader::printReactions(), and TEST().

20 {
21  if (row >= stoi.m())
22  mooseError("GeochemistryFormattedOutput::reaction called with stoichiometric matrix having ",
23  stoi.m(),
24  " rows, but row = ",
25  row);
26  const unsigned num_cols = stoi.n();
27  if (num_cols != names.size())
28  mooseError("GeochemistryFormattedOutput::reaction called with stoichiometric matrix having ",
29  num_cols,
30  " columns, but names has size ",
31  names.size());
32  std::stringstream ss;
33  ss << std::setprecision(precision);
34  bool printed_something = false;
35  for (unsigned i = 0; i < num_cols; ++i)
36  if (stoi(row, i) > stoi_tol)
37  {
38  if (!printed_something)
39  {
40  ss << stoi(row, i) << "*" << names[i];
41  printed_something = true;
42  }
43  else
44  ss << " + " << stoi(row, i) << "*" << names[i];
45  }
46  else if (stoi(row, i) < -stoi_tol)
47  {
48  if (!printed_something)
49  {
50  ss << "-" << -stoi(row, i) << "*" << names[i];
51  printed_something = true;
52  }
53  else
54  ss << " - " << -stoi(row, i) << "*" << names[i];
55  }
56  return ss.str();
57 }
void mooseError(Args &&... args)
unsigned int m() const
unsigned int n() const