10 #include "gtest/gtest.h" 19 {
"H2O",
"H+",
"HCO3-",
"O2(aq)",
"Ca++",
">(s)FeOH"},
32 TEST(GeochemistryIonicStrengthTest, sizeExceptions)
34 const std::vector<Real> basis_m_good(6);
35 const std::vector<Real> eqm_m_good(8);
36 const std::vector<Real> kin_m_good(3);
41 FAIL() <<
"Missing expected exception.";
43 catch (
const std::exception & e)
45 std::string msg(e.what());
48 "Ionic strength calculation: Number of basis species in mgd not equal to the size of " 49 "basis_species_molality") != std::string::npos)
50 <<
"Failed with unexpected error message: " << msg;
56 FAIL() <<
"Missing expected exception.";
58 catch (
const std::exception & e)
60 std::string msg(e.what());
61 ASSERT_TRUE(msg.find(
"Ionic strength calculation: Number of equilibrium species in mgd not " 62 "equal to the size of " 63 "eqm_species_molality") != std::string::npos)
64 <<
"Failed with unexpected error message: " << msg;
70 FAIL() <<
"Missing expected exception.";
72 catch (
const std::exception & e)
74 std::string msg(e.what());
75 ASSERT_TRUE(msg.find(
"Ionic strength calculation: Number of kinetic species in mgd not " 76 "equal to the size of " 77 "kin_species_molality") != std::string::npos)
78 <<
"Failed with unexpected error message: " << msg;
84 FAIL() <<
"Missing expected exception.";
86 catch (
const std::exception & e)
88 std::string msg(e.what());
89 ASSERT_TRUE(msg.find(
"Stoichiometric ionic strength calculation: Number of basis species in " 90 "mgd not equal to the size of " 91 "basis_species_molality") != std::string::npos)
92 <<
"Failed with unexpected error message: " << msg;
98 FAIL() <<
"Missing expected exception.";
100 catch (
const std::exception & e)
102 std::string msg(e.what());
105 "Stoichiometric ionic strength calculation: Number of equilibrium species in mgd not " 106 "equal to the size of " 107 "eqm_species_molality") != std::string::npos)
108 <<
"Failed with unexpected error message: " << msg;
114 FAIL() <<
"Missing expected exception.";
116 catch (
const std::exception & e)
118 std::string msg(e.what());
120 msg.find(
"Stoichiometric ionic strength calculation: Number of kinetic species in mgd not " 121 "equal to the size of " 122 "kin_species_molality") != std::string::npos)
123 <<
"Failed with unexpected error message: " << msg;
128 TEST(GeochemistryIonicStrengthTest, getsetMax)
131 EXPECT_EQ(
is.getMaxIonicStrength(), 1.0);
132 EXPECT_EQ(
is.getMaxStoichiometricIonicStrength(), 2.0);
134 is.setMaxIonicStrength(3.25);
135 is.setMaxStoichiometricIonicStrength(4.5);
137 EXPECT_EQ(
is.getMaxIonicStrength(), 3.25);
138 EXPECT_EQ(
is.getMaxStoichiometricIonicStrength(), 4.5);
142 TEST(GeochemistryIonicStrengthTest, getsetOnly)
152 EXPECT_FALSE(is_tmp.getUseOnlyBasisMolality());
153 EXPECT_FALSE(is_tmp.getUseOnlyClMolality());
154 is_tmp.setUseOnlyBasisMolality(
true);
155 EXPECT_TRUE(is_tmp.getUseOnlyBasisMolality());
156 EXPECT_FALSE(is_tmp.getUseOnlyClMolality());
157 is_tmp.setUseOnlyClMolality(
true);
158 EXPECT_TRUE(is_tmp.getUseOnlyBasisMolality());
159 EXPECT_TRUE(is_tmp.getUseOnlyClMolality());
160 is_tmp.setUseOnlyBasisMolality(
false);
161 EXPECT_FALSE(is_tmp.getUseOnlyBasisMolality());
162 EXPECT_TRUE(is_tmp.getUseOnlyClMolality());
166 TEST(GeochemistryIonicStrengthTest, ionicStrength)
168 Real gold_ionic_str = 0.0;
170 std::vector<Real> basis_m(6);
173 gold_ionic_str += 2.0;
175 gold_ionic_str += 3.0;
178 gold_ionic_str += 4 * 5.0;
181 const Real gold_basis_only = 0.5 * gold_ionic_str;
183 std::vector<Real> eqm_m(8);
186 gold_ionic_str += 4 * 2.2;
189 gold_ionic_str += 4.4;
191 gold_ionic_str += 5.5;
193 gold_ionic_str += 4 * 6.6;
195 gold_ionic_str += 7.7;
198 std::vector<Real> kin_m(3);
202 gold_ionic_str += -3.3;
204 gold_ionic_str *= 0.5;
209 EXPECT_NEAR(ionic_str, gold_ionic_str, 1E-9);
210 EXPECT_NEAR(ionic_str_basis_only, gold_basis_only, 1E-9);
217 TEST(GeochemistryIonicStrengthTest, stoichiometricIonicStrength)
219 Real gold_ionic_str = 0.0;
221 std::vector<Real> basis_m(6);
224 gold_ionic_str += 2.0;
226 gold_ionic_str += 3.0;
229 gold_ionic_str += 5.0 * 4;
232 const Real gold_basis_only = 0.5 * gold_ionic_str;
234 std::vector<Real> eqm_m(8);
236 gold_ionic_str += 1.1 * (1 + 1);
238 gold_ionic_str += 2.2 * 4;
240 gold_ionic_str += 3.3 * (4 + 1 - 1);
242 gold_ionic_str += 4.4 * (1);
244 gold_ionic_str += 5.5 * (1);
246 gold_ionic_str += 6.6 * (4);
248 gold_ionic_str += 7.7 * (1);
250 gold_ionic_str += 9.9 * (4 + 1 - 1);
252 std::vector<Real> kin_m(3);
254 gold_ionic_str += 0.0;
256 gold_ionic_str += 0.0;
258 gold_ionic_str += -3.3 * (1);
260 gold_ionic_str *= 0.5;
263 const Real ionic_str_basis_only =
266 EXPECT_NEAR(ionic_str, gold_ionic_str, 1E-9);
267 EXPECT_NEAR(ionic_str_basis_only, gold_basis_only, 1E-9);
274 TEST(GeochemistryIonicStrengthTest, stoichiometricIonicStrength_except)
276 std::vector<Real> basis_m(6);
277 std::vector<Real> eqm_m(8);
278 std::vector<Real> kin_m(3);
282 FAIL() <<
"Missing expected exception.";
284 catch (
const std::exception & e)
286 std::string msg(e.what());
289 "GeochemistryIonicStrength: attempting to compute stoichiometric ionic strength " 290 "using only the Cl- molality, but Cl- does not appear in the geochemical system") !=
292 <<
"Failed with unexpected error message: " << msg;
297 TEST(GeochemistryIonicStrengthTest, stoichiometricIonicStrengthOnlyCl)
303 db_cl, {
"H2O",
"H+",
"Cl-"}, {}, {}, {}, {}, {},
"O2(aq)",
"e-");
306 const std::vector<Real> basis_m{0.75, 2.5, 3.5};
307 const std::vector<Real> eqm_m{1.5, 0.25};
312 db_cl, {
"H2O",
"H+",
"Cl-"}, {}, {}, {}, {}, {},
"O2(aq)",
"e-");
317 const std::vector<Real> basis_m_eqm{0.75, 2.5, 3.5};
318 const std::vector<Real> eqm_m_eqm{1.5, 0.25};
319 const unsigned pos = mgd_cl_eqm.eqm_species_name[0] ==
"Cl-" ? 0 : 1;
325 "database/moose_testdb_cl_kinetic.json",
true,
true,
false);
327 db_cl_kin, {
"H2O"}, {}, {}, {}, {
"Cl-"}, {},
"O2(aq)",
"e-");
330 const std::vector<Real> basis_m_kin{0.75};
331 const std::vector<Real> kin_m_kin{7.75};
TEST(GeochemistryIonicStrengthTest, sizeExceptions)
Real getUseOnlyBasisMolality() const
Return the value of use_only_basis_molality.
Real getUseOnlyClMolality() const
Return the value of use_only_Cl_molality.
const GeochemistryIonicStrength is_calc(1E9, 1E9, false, false)
std::unordered_map< std::string, unsigned > basis_species_index
basis_species_index[name] = index of the basis species, within all ModelGeochemicalDatabase internal ...
std::unordered_map< std::string, unsigned > eqm_species_index
eqm_species_index[name] = index of the equilibrium species (secondary aqueous species, redox couples in equilibrium with the aqueous solution, minerals in equilibrium with the aqueous solution, gases in equilibrium with the aqueous solution) within all ModelGeochemicalDatabase internal datastrcutres, with given name
const GeochemicalDatabaseReader database("database/moose_testdb.json")
const PertinentGeochemicalSystem model(database, {"H2O", "H+", "HCO3-", "O2(aq)", "Ca++", ">(s)FeOH"}, {"Calcite"}, {}, {"Calcite_asdf"}, {"CH4(aq)"}, {">(s)FeOCa+"}, "O2(aq)", "e-")
Real ionicStrength(const ModelGeochemicalDatabase &mgd, const std::vector< Real > &basis_species_molality, const std::vector< Real > &eqm_species_molality, const std::vector< Real > &kin_species_molality) const
Compute ionic strength.
std::unordered_map< std::string, unsigned > kin_species_index
kin_species_index[name] = index of the kinetic species, within all ModelGeochemicalDatabase internal ...
Class to swap basis species with equilibrium species.
const ModelGeochemicalDatabase & modelGeochemicalDatabase() const
Return a reference to the ModelGeochemicalDatabase structure.
Constructs and stores a minimal amount of information that is pertinent to the user-defined geochemic...
Calculators to compute ionic strength and stoichiometric ionic strength.
PetscErrorCode PetscInt const PetscInt IS * is
const GeochemistryIonicStrength is_basis_only(1E9, 1E9, true, false)
const GeochemistryIonicStrength is_cl_only(1E9, 1E9, false, true)
const ModelGeochemicalDatabase mgd
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void performSwap(ModelGeochemicalDatabase &mgd, const std::string &replace_this, const std::string &with_this)
Check that replacing the named basis species with the named equilibrium species is valid...
Real stoichiometricIonicStrength(const ModelGeochemicalDatabase &mgd, const std::vector< Real > &basis_species_molality, const std::vector< Real > &eqm_species_molality, const std::vector< Real > &kin_species_molality) const
Compute stoichiometric ionic strength.
Data structure to hold all relevant information from the database file.
Class for reading geochemical reactions from a MOOSE geochemical database.