https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GeochemistryFormattedOutput.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{
14std::string
15reaction(const DenseMatrix<Real> & stoi,
16 unsigned row,
17 const std::vector<std::string> & names,
18 Real stoi_tol,
19 int precision)
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}
58}
void mooseError(Args &&... args)
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...