https://mooseframework.inl.gov
GeochemistryFormattedOutputTest.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 
10 #include "gtest/gtest.h"
11 
13 
15 {
16  DenseMatrix<Real> stoi(1, 3);
17 
18  try
19  {
20  std::string s = GeochemistryFormattedOutput::reaction(stoi, 1, {"name"}, 1.0, 1);
21  FAIL() << "Missing expected exception.";
22  }
23  catch (const std::exception & e)
24  {
25  std::string msg(e.what());
26  ASSERT_TRUE(msg.find("GeochemistryFormattedOutput::reaction called with stoichiometric matrix "
27  "having 1 rows, but row = 1") != std::string::npos)
28  << "Failed with unexpected error message: " << msg;
29  }
30 
31  try
32  {
33  std::string s = GeochemistryFormattedOutput::reaction(stoi, 0, {"name", "name2"}, 1.0, 1);
34  FAIL() << "Missing expected exception.";
35  }
36  catch (const std::exception & e)
37  {
38  std::string msg(e.what());
39  ASSERT_TRUE(msg.find("GeochemistryFormattedOutput::reaction called with stoichiometric matrix "
40  "having 3 columns, but names has size 2") != std::string::npos)
41  << "Failed with unexpected error message: " << msg;
42  }
43 }
44 
46 {
47  DenseMatrix<Real> stoi(2, 3);
48  stoi(0, 0) = -1.0;
49  stoi(0, 1) = 1E-3;
50  stoi(0, 2) = -1.0 / 3.0;
51  stoi(1, 0) = -1E-3;
52  stoi(1, 1) = 2.0;
53  stoi(1, 2) = 456789.0;
54  EXPECT_EQ(GeochemistryFormattedOutput::reaction(stoi, 0, {"n0", "n1", "n2"}, 1.0E-2, 3),
55  "-1*n0 - 0.333*n2");
56  EXPECT_EQ(GeochemistryFormattedOutput::reaction(stoi, 1, {"n0", "n1", "n2"}, 1.0E-2, 3),
57  "2*n1 + 4.57e+05*n2");
58 }
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...
TEST(GeochemistryFormattedOutput, excepts)