https://mooseframework.inl.gov
Loading...
Searching...
No Matches
GeochemistryUnitConverterTest.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
14const GeochemicalDatabaseReader db("database/moose_testdb.json", true, true, false);
17 {"H2O", "Ca++", "HCO3-", "H+", ">(s)FeOH", "Fe++", "CH4(aq)", "O2(aq)", ">(w)FeOH"},
18 {"Calcite", "Fe(OH)3(ppd)"},
19 {"CH4(g)"},
20 {"Something"},
21 {"(O-phth)--"},
22 {">(s)FeO-"},
23 "O2(aq)",
24 "e-");
26
27// Test exceptions
28TEST(GeochemistryUnitConverterTest, exceptions)
29{
30 try
31 {
34 FAIL() << "Missing expected exception.";
35 }
36 catch (const std::exception & e)
37 {
38 std::string msg(e.what());
39 ASSERT_TRUE(
40 msg.find(
41 "GeochemistryUnitConverter: bad_name is not a basis, equilibrium or kinetic species") !=
42 std::string::npos)
43 << "Failed with unexpected error message: " << msg;
44 }
45
46 try
47 {
50 FAIL() << "Missing expected exception.";
51 }
52 catch (const std::exception & e)
53 {
54 std::string msg(e.what());
55 ASSERT_TRUE(msg.find("GeochemistryUnitConverter: Cannot use CM3 units for species Ca++ because "
56 "it is not a mineral") != std::string::npos)
57 << "Failed with unexpected error message: " << msg;
58 }
59
60 try
61 {
64 FAIL() << "Missing expected exception.";
65 }
66 catch (const std::exception & e)
67 {
68 std::string msg(e.what());
69 ASSERT_TRUE(
70 msg.find("GeochemistryUnitConverter: Cannot use CM3 units for species CO3-- because "
71 "it is not a mineral") != std::string::npos)
72 << "Failed with unexpected error message: " << msg;
73 }
74
75 try
76 {
79 FAIL() << "Missing expected exception.";
80 }
81 catch (const std::exception & e)
82 {
83 std::string msg(e.what());
84 ASSERT_TRUE(
85 msg.find("GeochemistryUnitConverter: Cannot use CM3 units for species CH4(g) because "
86 "it is not a mineral") != std::string::npos)
87 << "Failed with unexpected error message: " << msg;
88 }
89
90 try
91 {
94 FAIL() << "Missing expected exception.";
95 }
96 catch (const std::exception & e)
97 {
98 std::string msg(e.what());
99 ASSERT_TRUE(
100 msg.find("GeochemistryUnitConverter: Cannot use CM3 units for species (O-phth)-- because "
101 "it is not a mineral") != std::string::npos)
102 << "Failed with unexpected error message: " << msg;
103 }
104
105 try
106 {
109 FAIL() << "Missing expected exception.";
110 }
111 catch (const std::exception & e)
112 {
113 std::string msg(e.what());
114 ASSERT_TRUE(
115 msg.find("GeochemistryUnitConverter: Cannot use CM3 units for species >(s)FeO- because "
116 "it is not a mineral") != std::string::npos)
117 << "Failed with unexpected error message: " << msg;
118 }
119}
120
121// Test fromMoles
122TEST(GeochemistryUnitConverterTest, fromMoles)
123{
126 11.0);
129 11.0);
132 11.0);
135 11.0 * 40.08,
136 1.0E-8);
139 11.0 * 40.08 / 1.0E3,
140 1.0E-8);
143 11.0 * 61.0171 * 1.0E3,
144 1.0E-8);
147 11.0 * 1.0079 * 1.0E6,
148 1.0E-3);
149 EXPECT_NEAR(
152 11.0 * 72.8543 * 1E-3,
153 1.0E-8);
154 EXPECT_NEAR(
157 11.0 * 1234.567,
158 1.0E-8);
159 EXPECT_NEAR(
162 11.0 * 44.0098 * 1E3,
163 1.0E-8);
164 EXPECT_NEAR(
167 11.0 * 100.0892 * 1E6,
168 1.0E-3);
170 11.0,
172 "Fe(OH)3(ppd)",
173 mgd),
174 11.0 * 106.8689 * 1E6,
175 1.0E-3);
176 EXPECT_NEAR(
179 11.0 * 16.0426,
180 1.0E-8);
181 EXPECT_NEAR(
184 11.0 * 88.8537 * 1E3,
185 1.0E-8);
188 11.0 * 164.1172 * 1E6,
189 1.0E-3);
192 11.0 * 71.8464 * 1E6,
193 1.0E-3);
196 11.0 * 36.9340,
197 1.0E-8);
200 11.0 * 34.3200,
201 1.0E-8);
204 11.0 * 20.8200,
205 1.0E-8);
206}
207
208// Test toMoles
209TEST(GeochemistryUnitConverterTest, toMoles)
210{
213 11.0);
216 11.0);
219 11.0);
222 11.0,
223 1.0E-8);
224 EXPECT_NEAR(
226 11.0 * 40.08 / 1.0E3, GeochemistryUnitConverter::GeochemistryUnit::KG, "Ca++", mgd),
227 11.0,
228 1.0E-8);
229 EXPECT_NEAR(
231 11.0 * 61.0171 * 1.0E3, GeochemistryUnitConverter::GeochemistryUnit::MG, "HCO3-", mgd),
232 11.0,
233 1.0E-8);
234 EXPECT_NEAR(
236 11.0 * 1.0079 * 1.0E6, GeochemistryUnitConverter::GeochemistryUnit::UG, "H+", mgd),
237 11.0,
238 1.0E-3);
240 11.0 * 72.8543 * 1E-3,
242 ">(s)FeOH",
243 mgd),
244 11.0,
245 1.0E-8);
247 11.0 * 1234.567,
249 ">(w)FeOH",
250 mgd),
251 11.0,
252 1.0E-8);
254 11.0 * 44.0098 * 1E3,
256 "CO2(aq)",
257 mgd),
258 11.0,
259 1.0E-8);
261 11.0 * 100.0892 * 1E6,
263 "Calcite",
264 mgd),
265 11.0,
266 1.0E-3);
268 11.0 * 106.8689 * 1E6,
270 "Fe(OH)3(ppd)",
271 mgd),
272 11.0,
273 1.0E-3);
275 11.0 * 16.0426,
277 "CH4(g)",
278 mgd),
279 11.0,
280 1.0E-8);
282 11.0 * 88.8537 * 1E3,
284 "Something",
285 mgd),
286 11.0,
287 1.0E-8);
288 EXPECT_NEAR(GeochemistryUnitConverter::toMoles(11.0 * 164.1172 * 1E6,
290 "(O-phth)--",
291 mgd),
292 11.0,
293 1.0E-3);
294 EXPECT_NEAR(
296 11.0 * 71.8464 * 1E6, GeochemistryUnitConverter::GeochemistryUnit::UG, ">(s)FeO-", mgd),
297 11.0,
298 1.0E-3);
300 11.0 * 36.9340, GeochemistryUnitConverter::GeochemistryUnit::CM3, "Calcite", mgd),
301 11.0,
302 1.0E-8);
303 EXPECT_NEAR(
305 11.0 * 34.3200, GeochemistryUnitConverter::GeochemistryUnit::CM3, "Fe(OH)3(ppd)", mgd),
306 11.0,
307 1.0E-8);
308 EXPECT_NEAR(
310 11.0 * 20.8200, GeochemistryUnitConverter::GeochemistryUnit::CM3, "Something", mgd),
311 11.0,
312 1.0E-8);
313}
TEST(GeochemistryUnitConverterTest, exceptions)
const PertinentGeochemicalSystem model(db, {"H2O", "Ca++", "HCO3-", "H+", ">(s)FeOH", "Fe++", "CH4(aq)", "O2(aq)", ">(w)FeOH"}, {"Calcite", "Fe(OH)3(ppd)"}, {"CH4(g)"}, {"Something"}, {"(O-phth)--"}, {">(s)FeO-"}, "O2(aq)", "e-")
const GeochemicalDatabaseReader db("database/moose_testdb.json", true, true, false)
const ModelGeochemicalDatabase mgd
Class for reading geochemical reactions from a MOOSE geochemical database.
Constructs and stores a minimal amount of information that is pertinent to the user-defined geochemic...
const ModelGeochemicalDatabase & modelGeochemicalDatabase() const
Return a reference to the ModelGeochemicalDatabase structure.
Real fromMoles(Real moles, const GeochemistryUnit unit, const std::string &species_name, const ModelGeochemicalDatabase &mgd)
Calculates the amount of "unit"s of species_name in 1 mole, OR in 1 molal, whichever is appropriate.
Real toMoles(Real quantity, const GeochemistryUnit unit, const std::string &species_name, const ModelGeochemicalDatabase &mgd)
Calculates the amount of moles corresponding to "quantity" "unit"s of species name,...
Data structure to hold all relevant information from the database file.