40 size_t r = coeffs.rows(),
c = coeffs.cols();
41 if (
strict && (r != 3 ||
c != 1)) {
42 throw ValueError(
format(
"%s (%d): You have to provide a 3,1 matrix of coefficients, not (%d,%d).", __FILE__, __LINE__, r,
c));
46 auto fnc = [&](
double x) {
return exp((
double)(coeffs[0] / (x)-coeffs[2])); };
47 double x_den = (y - ybase) + coeffs[1];
50 if (x_den < x_lo || x_den > x_hi) {
57 const double f_lo = fnc(x_lo);
58 const double f_hi = fnc(x_hi);
60 return (f_hi - f_lo) / (x_hi - x_lo) * (x_den - x_lo) + f_lo;
66 size_t r = coeffs.rows(),
c = coeffs.cols();
67 if (
strict && (r != 3 ||
c != 1)) {
68 throw ValueError(
format(
"%s (%d): You have to provide a 3,1 matrix of coefficients, not (%d,%d).", __FILE__, __LINE__, r,
c));
72 auto fnc = [&](
double x) {
return exp((
double)(log((
double)(1.0 / (x) + 1.0 / (x) / (x))) * coeffs[1] + coeffs[2])); };
73 double x_den = (y - ybase) + coeffs[0];
76 if (x_den < x_lo || x_den > x_hi) {
83 const double f_lo = fnc(x_lo);
84 const double f_hi = fnc(x_hi);
86 return (f_hi - f_lo) / (x_hi - x_lo) * (x_den - x_lo) + f_lo;
93 Eigen::MatrixXd coeffs;
95 offset = data.
coeffs(0, 0);
96 if (r == 1 &&
c > 1) {
97 coeffs = Eigen::MatrixXd(data.
coeffs.block(0, 1, r,
c - 1));
99 }
else if (r > 1 &&
c == 1) {
100 coeffs = Eigen::MatrixXd(data.
coeffs.block(1, 0, r - 1,
c));
103 throw ValueError(
format(
"%s (%d): You have to provide a vector (1D matrix) of coefficients, not (%d,%d).", __FILE__, __LINE__, r,
c));
107 throw ValueError(
format(
"%s (%d): You have to provide a vector (1D matrix) of coefficients, not (%d,%d).", __FILE__, __LINE__, r,
c));
124 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
138 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
141 throw ValueError(
format(
"%s (%d): There is no predefined way to use this function type \"[%d]\" for specific heat.", __FILE__, __LINE__,
160 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
180 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
195 throw ValueError(
format(
"Saturation pressure is not available below TminPsat=%g K (T=%g K)", this->TminPsat,
T));
209 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
229 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
246 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
250 format(
"%s (%d): There is no predefined way to use this function type \"[%d]\" for density.", __FILE__, __LINE__,
density.
type));
261 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
265 format(
"%s (%d): There is no predefined way to use this function type \"[%d]\" for entropy.", __FILE__, __LINE__,
specific_heat.
type));
276 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
280 format(
"%s (%d): There is no predefined way to use this function type \"[%d]\" for entropy.", __FILE__, __LINE__,
specific_heat.
type));
404 double d_raw = Dmass;
409 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
412 throw ValueError(
format(
"%s (%d): There is no predefined way to use this function type \"[%d]\" for inverse density.", __FILE__, __LINE__,
418 double c_raw = Cmass;
423 throw ValueError(
format(
"%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?", __FILE__,
426 throw ValueError(
format(
"%s (%d): There is no predefined way to use this function type \"[%d]\" for inverse specific heat.", __FILE__,
442 if (
Tmin <= 0.)
throw ValueError(
"Please specify the minimum temperature.");
443 if (
Tmax <= 0.)
throw ValueError(
"Please specify the maximum temperature.");
447 if (
T < TF)
throw ValueError(
format(
"Your temperature %f is below the freezing point of %f.",
T, TF));
474 if (p < 0.0)
throw ValueError(
format(
"You cannot use negative pressures: %f < %f. ", p, 0.0));
475 if (ps > 0.0 && p < ps)
throw ValueError(
format(
"Equations are valid for liquid phase only: %f < %f (psat). ", p, ps));
484 if (xmin < 0.0 || xmin > 1.0)
throw ValueError(
"Please specify the minimum concentration between 0 and 1.");
485 if (xmax < 0.0 || xmax > 1.0)
throw ValueError(
"Please specify the maximum concentration between 0 and 1.");
502# include <catch2/catch_all.hpp>
505Eigen::MatrixXd makeMatrix(
const std::vector<double>& coefficients) {
507 std::vector<std::vector<double>> matrix;
508 std::vector<double> tmpVector;
511 tmpVector.push_back(coefficients[0]);
512 tmpVector.push_back(coefficients[6]);
513 tmpVector.push_back(coefficients[11]);
514 tmpVector.push_back(coefficients[15]);
515 matrix.push_back(tmpVector);
518 tmpVector.push_back(coefficients[1] * 100.0);
519 tmpVector.push_back(coefficients[7] * 100.0);
520 tmpVector.push_back(coefficients[12] * 100.0);
521 tmpVector.push_back(coefficients[16] * 100.0);
522 matrix.push_back(tmpVector);
525 tmpVector.push_back(coefficients[2] * 100.0 * 100.0);
526 tmpVector.push_back(coefficients[8] * 100.0 * 100.0);
527 tmpVector.push_back(coefficients[13] * 100.0 * 100.0);
528 tmpVector.push_back(coefficients[17] * 100.0 * 100.0);
529 matrix.push_back(tmpVector);
532 tmpVector.push_back(coefficients[3] * 100.0 * 100.0 * 100.0);
533 tmpVector.push_back(coefficients[9] * 100.0 * 100.0 * 100.0);
534 tmpVector.push_back(coefficients[14] * 100.0 * 100.0 * 100.0);
535 tmpVector.push_back(0.0);
536 matrix.push_back(tmpVector);
539 tmpVector.push_back(coefficients[4] * 100.0 * 100.0 * 100.0 * 100.0);
540 tmpVector.push_back(coefficients[10] * 100.0 * 100.0 * 100.0 * 100.0);
541 tmpVector.push_back(0.0);
542 tmpVector.push_back(0.0);
543 matrix.push_back(tmpVector);
546 tmpVector.push_back(coefficients[5] * 100.0 * 100.0 * 100.0 * 100.0 * 100.0);
547 tmpVector.push_back(0.0);
548 tmpVector.push_back(0.0);
549 tmpVector.push_back(0.0);
550 matrix.push_back(tmpVector);
556TEST_CASE(
"Internal consistency checks and example use cases for the incompressible fluids",
"[IncompressibleFluids]") {
557 SECTION(
"Test case for \"SylthermXLT\" by Dow Chemicals") {
559 std::vector<double> cRho;
560 cRho.push_back(+1.1563685145E+03);
561 cRho.push_back(-1.0269048032E+00);
562 cRho.push_back(-9.3506079577E-07);
563 cRho.push_back(+1.0368116627E-09);
568 std::vector<double> cHeat;
569 cHeat.push_back(+1.1562261074E+03);
570 cHeat.push_back(+2.0994549103E+00);
571 cHeat.push_back(+7.7175381057E-07);
572 cHeat.push_back(-3.7008444051E-20);
577 std::vector<double> cCond;
578 cCond.push_back(+1.6121957379E-01);
579 cCond.push_back(-1.3023781944E-04);
580 cCond.push_back(-1.4395238766E-07);
585 std::vector<double> cVisc;
586 cVisc.push_back(+1.0337654989E+03);
587 cVisc.push_back(-4.3322764383E+01);
588 cVisc.push_back(+1.0715062356E+01);
623 double T = 273.15 + 50;
628 val = 824.4615702148608;
629 res = XLT.
rho(
T, p, x);
638 val = 1834.7455527670554;
639 res = XLT.
c(
T, p, x);
648 CHECK_THROWS(XLT.
s(
T, p, x));
649 CHECK_THROWS(XLT.
h(
T, p, x));
650 CHECK_THROWS(XLT.
u(
T, p, x));
653 val = 0.0008931435169681835;
654 res = XLT.
visc(
T, p, x);
663 val = 0.10410086156049088;
664 res = XLT.
cond(
T, p, x);
673 SECTION(
"Test case for Methanol from SecCool") {
679 double T = 273.15 + 10;
686 expected = 963.2886528091547;
687 actual = CH3OH.
rho(
T, p, x);
698 expected = 3993.9748117022423;
699 actual = CH3OH.
c(
T, p, x);
710 CHECK_THROWS(CH3OH.
s(
T, p, x));
711 CHECK_THROWS(CH3OH.
h(
T, p, x));
712 CHECK_THROWS(CH3OH.
u(
T, p, x));
715 expected = 0.0023970245009602097;
716 actual = CH3OH.
visc(
T, p, x);
729 expected = 0.44791148414693727;
730 actual = CH3OH.
cond(
T, p, x);
743 expected = -20.02 + 273.15;