Line data Source code
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 : 10 : #include "GeochemistryFormattedOutput.h" 11 : 12 : namespace GeochemistryFormattedOutput 13 : { 14 : std::string 15 3433 : reaction(const DenseMatrix<Real> & stoi, 16 : unsigned row, 17 : const std::vector<std::string> & names, 18 : Real stoi_tol, 19 : int precision) 20 : { 21 3433 : if (row >= stoi.m()) 22 1 : mooseError("GeochemistryFormattedOutput::reaction called with stoichiometric matrix having ", 23 1 : stoi.m(), 24 : " rows, but row = ", 25 : row); 26 3432 : const unsigned num_cols = stoi.n(); 27 3432 : if (num_cols != names.size()) 28 1 : mooseError("GeochemistryFormattedOutput::reaction called with stoichiometric matrix having ", 29 : num_cols, 30 : " columns, but names has size ", 31 1 : names.size()); 32 3431 : std::stringstream ss; 33 : ss << std::setprecision(precision); 34 : bool printed_something = false; 35 31603 : for (unsigned i = 0; i < num_cols; ++i) 36 28172 : if (stoi(row, i) > stoi_tol) 37 : { 38 7211 : if (!printed_something) 39 : { 40 2235 : ss << stoi(row, i) << "*" << names[i]; 41 : printed_something = true; 42 : } 43 : else 44 9952 : ss << " + " << stoi(row, i) << "*" << names[i]; 45 : } 46 20961 : else if (stoi(row, i) < -stoi_tol) 47 : { 48 3444 : if (!printed_something) 49 : { 50 1196 : ss << "-" << -stoi(row, i) << "*" << names[i]; 51 : printed_something = true; 52 : } 53 : else 54 2248 : ss << " - " << -stoi(row, i) << "*" << names[i]; 55 : } 56 3431 : return ss.str(); 57 3431 : } 58 : }