10 #include "gtest/gtest.h" 14 const double tol = 1.0e-6;
17 TEST(EquilibriumConstantInterpolatorTest, constructor_except)
20 std::vector<double> T = {0.0, 25.0};
21 std::vector<double> k_bad = {-6.5570};
22 std::vector<double> k_good = {-6.5570, 1.0};
27 FAIL() <<
"Missing expected exception.";
29 catch (
const std::exception & e)
31 std::string msg(e.what());
32 ASSERT_TRUE(msg.find(
"The temperature and logk data sets must be equal in length in " 33 "EquilibriumConstantInterpolator") != std::string::npos)
34 <<
"Failed with unexpected error message: " << msg;
40 FAIL() <<
"Missing expected exception.";
42 catch (
const std::exception & e)
44 std::string msg(e.what());
45 ASSERT_TRUE(msg.find(
"Type bad-type is not supported in EquilibriumConstantInterpolator") !=
47 <<
"Failed with unexpected error message: " << msg;
53 FAIL() <<
"Missing expected exception.";
55 catch (
const std::exception & e)
57 std::string msg(e.what());
59 msg.find(
"A Maier-Kelly fit cannot be used when the temperature points include 0. Use a " 60 "fourth-order fit instead") != std::string::npos)
61 <<
"Failed with unexpected error message: " << msg;
65 TEST(EquilibriumConstantInterpolatorTest, constructor)
68 std::vector<double> T = {0.0, 25.0, 60.0, 100.0, 150.0, 200.0, 250.0, 300.0};
69 std::vector<double>
k = {-6.5570, -6.3660, -6.3325, -6.4330, -6.7420, -7.1880, -7.7630, -8.4650};
75 T = {0.01, 25.0, 60.0, 100.0, 150.0, 200.0, 250.0, 300.0};
76 k = {-6.5570, -6.3660, -6.3325, -6.4330, -6.7420, -7.1880, -7.7630, -8.4650};
83 EXPECT_EQ(logk3.getSampleSize(), T.size());
86 TEST(EquilibriumConstantInterpolatorTest, linear)
88 const std::vector<double> T = {0.0, 25.0};
89 const std::vector<double>
k = {1.2, 2.4};
100 EXPECT_NEAR(logk.
sample(50.0), 3.6,
tol);
112 const std::vector<double> T2 = {0.01, 25.01};
118 EXPECT_NEAR(logk2.
sample(T2[0]), 1.2,
tol);
119 EXPECT_NEAR(logk2.
sample(T2[1]), 2.4,
tol);
120 EXPECT_NEAR(logk2.
sample(50.01), 3.6,
tol);
130 TEST(EquilibriumConstantInterpolatorTest, fourthOrder)
132 const std::vector<double> T = {0.0, 25.0, 60.0, 100.0, 150.0, 200.0, 250.0, 300.0};
133 const std::vector<double>
k = {
134 -6.5570, -6.3660, -6.3325, -6.4330, -6.7420, -7.1880, -7.7630, -8.4650};
159 EXPECT_NEAR(logk.
sample(T[1]), -6.38384537894225,
tol);
160 EXPECT_NEAR(logk.
sample(T[2]), -6.321712110081394,
tol);
161 EXPECT_NEAR(logk.
sample(T[3]), -6.429646151221264,
tol);
162 EXPECT_NEAR(logk.
sample(T[4]), -6.744733784802997,
tol);
163 EXPECT_NEAR(logk.
sample(T[5]), -7.193821631774174,
tol);
164 EXPECT_NEAR(logk.
sample(125.0), -6.567092778770316,
tol);
172 TEST(EquilibriumConstantInterpolatorTest, maierKelly)
174 const std::vector<double> T = {0.01, 25.0, 60.0, 100.0, 150.0, 200.0, 250.0, 300.0};
175 const std::vector<double>
k = {
176 0.2081, 0.0579, -0.2746, -0.7311, -1.3659, -2.0618, -2.8403, -3.7681};
201 EXPECT_NEAR(logk.
sample(T[1]), 0.061497433011205596,
tol);
202 EXPECT_NEAR(logk.
sample(T[2]), -0.30083706818706746,
tol);
203 EXPECT_NEAR(logk.
sample(T[3]), -0.7005921220757013,
tol);
204 EXPECT_NEAR(logk.
sample(T[4]), -1.3418011239865,
tol);
205 EXPECT_NEAR(logk.
sample(T[5]), -2.0827775371250423,
tol);
206 EXPECT_NEAR(logk.
sample(125.0), -1.0053697469019622,
tol);
214 TEST(EquilibriumConstantInterpolatorTest, linearNullValues)
216 const std::vector<double> T = {0.0, 25.0, 60.0, 100.0, 150.0, 200.0, 250.0, 300.0};
217 const std::vector<double>
k = {17.8660, 15.9746, 500.0, 500.0, 500.0, 500.0, 500.0, 500.0};
226 EXPECT_NEAR(logk.
sample(T[0]), 17.866,
tol);
227 EXPECT_NEAR(logk.
sample(T[1]), 15.9746,
tol);
228 EXPECT_NEAR(logk.
sample(60.0), 13.32664,
tol);
229 EXPECT_NEAR(logk.
sample(125.0), 8.409,
tol);
230 EXPECT_NEAR(logk.
sample(300.0), -4.8308,
tol);
233 TEST(EquilibriumConstantInterpolatorTest, fourthOrderNullValues)
235 const std::vector<double> T = {0.0, 25.0, 60.0, 100.0, 150.0, 200.0, 250.0, 300.0};
236 const std::vector<double>
k = {
237 -0.0162, -0.0264, -0.0340, -0.0459, -0.0618, -0.0803, 500.0, 500.0};
246 EXPECT_NEAR(logk.
sample(T[0]), -0.016418224486741174,
tol);
247 EXPECT_NEAR(logk.
sample(T[1]), -0.025715932916029558,
tol);
248 EXPECT_NEAR(logk.
sample(T[2]), -0.03492782535210691,
tol);
249 EXPECT_NEAR(logk.
sample(T[3]), -0.04524532642418216,
tol);
250 EXPECT_NEAR(logk.
sample(T[4]), -0.0620327728353172,
tol);
251 EXPECT_NEAR(logk.
sample(250.0), -0.08739490878982198,
tol);
252 EXPECT_NEAR(logk.
sample(300.0), -0.060966149023565674,
tol);
260 TEST(EquilibriumConstantInterpolatorTest, fourthOrderUserDefinedNullValues)
262 const std::vector<double> T = {0.0, 25.0, 60.0, 100.0, 150.0, 200.0, 250.0, 300.0};
263 const std::vector<double>
k = {
264 -0.0162, -0.0264, -0.0340, -0.0459, -0.0618, -0.0803, 999.999, 999.999};
273 EXPECT_NEAR(logk.
sample(T[0]), -0.016418224486741174,
tol);
274 EXPECT_NEAR(logk.
sample(T[1]), -0.025715932916029558,
tol);
275 EXPECT_NEAR(logk.
sample(T[2]), -0.03492782535210691,
tol);
276 EXPECT_NEAR(logk.
sample(T[3]), -0.04524532642418216,
tol);
277 EXPECT_NEAR(logk.
sample(T[4]), -0.0620327728353172,
tol);
278 EXPECT_NEAR(logk.
sample(250.0), -0.08739490878982198,
tol);
279 EXPECT_NEAR(logk.
sample(300.0), -0.060966149023565674,
tol);
288 TEST(EquilibriumConstantInterpolatorTest, piecewiselinear)
290 const std::vector<double> T = {0.0, 2.0, 6.0};
291 const std::vector<double>
k = {10.0, 0.0, 40.0};
296 for (
unsigned i = 0; i < 3; ++i)
299 EXPECT_NEAR(logk.
sample(3.0), 10.0,
tol);
300 EXPECT_NEAR(logk.
sample(-1.0), 10.0,
tol);
301 EXPECT_NEAR(logk.
sample(600), 40.0,
tol);
314 FAIL() <<
"Missing expected exception.";
316 catch (
const std::exception & e)
318 std::string msg(e.what());
320 msg.find(
"Dual cannot be used for specified fit type in EquilibriumConstantInterpolator") !=
322 <<
"Failed with unexpected error message: " << msg;
327 TEST(EquilibriumConstantInterpolatorTest, piecewiselinear_oneval)
329 const std::vector<double> T = {2.0};
330 const std::vector<double>
k = {10.0};
335 EXPECT_EQ(logk.
sample(1.0), 10.0);
336 EXPECT_EQ(logk.
sample(3.0), 10.0);
343 TEST(EquilibriumConstantInterpolatorTest, piecewiselinear_500)
345 const std::vector<double> T = {0.0, 2.0, 4.0, 6.0, 8.0};
346 const std::vector<double>
k = {10.0, 0.0, 500.0, 40.0, 500.0};
357 EXPECT_NEAR(logk.
sample(3.0), 10.0,
tol);
358 EXPECT_NEAR(logk.
sample(-1.0), 10.0,
tol);
359 EXPECT_NEAR(logk.
sample(600), 40.0,
tol);
368 TEST(EquilibriumConstantInterpolatorTest, piecewiselinear_except)
370 const std::vector<double> T = {2.0, 0.0, 6.0};
371 const std::vector<double>
k = {10.0, 0.0, 40.0};
377 FAIL() <<
"Missing expected exception.";
379 catch (
const std::exception & e)
381 std::string msg(e.what());
382 ASSERT_TRUE(msg.find(
"EquilibriumConstantInterpolation: x-values are not strictly increasing: " 383 "x[0]: 2 x[1]: 0") != std::string::npos)
384 <<
"Failed with unexpected error message: " << msg;
Fit the equilibrium constant values read from the thermodynamic databse at specified temperature valu...
unsigned int getSampleSize()
DualNumber< Real, DNDerivativeType, true > ADReal
virtual Real sample(Real T) override
Real sampleDerivative(Real T)
Sample derivative of function at temperature T.
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N >> &derivs, libMesh::dof_id_type index, Real value)
TEST(EquilibriumConstantInterpolatorTest, constructor_except)
exception tests for constructor
static const std::string k