19 template<
typename TType,
typename RhoType>
20 auto alphaig(
const TType& ,
const RhoType& )
const {
21 using otype = std::common_type_t <TType, RhoType>;
40 template<
typename TType,
typename RhoType>
41 auto alphaig(
const TType& T,
const RhoType& )
const {
42 using otype = std::common_type_t <TType, RhoType>;
43 return forceeval(
static_cast<otype
>(
a * log(T)));
63 template<
typename TType,
typename RhoType>
64 auto alphaig(
const TType& T,
const RhoType& rho)
const {
65 using otype = std::common_type_t <TType, RhoType>;
75 const std::valarray<double>
n,
t;
79 template<
typename TType,
typename RhoType>
80 auto alphaig(
const TType& T,
const RhoType& )
const {
81 std::common_type_t <TType, RhoType> summer = 0.0;
82 for (
auto i = 0U; i <
n.size(); ++i) {
83 summer +=
n[i] *
pow(T,
t[i]);
94 const std::valarray<double>
n,
theta;
98 template<
typename TType,
typename RhoType>
99 auto alphaig(
const TType& T,
const RhoType& )
const {
100 std::common_type_t <TType, RhoType> summer = 0.0;
101 for (
auto i = 0U; i <
n.size(); ++i) {
102 summer +=
n[i] * log(1.0 - exp(-
theta[i] / T));
116 const std::valarray<double>&
n,
117 const std::valarray<double>&
c,
118 const std::valarray<double>&
d,
119 const std::valarray<double>&
theta,
123 template<
typename TType,
typename RhoType>
124 auto alphaig(
const TType& T,
const RhoType& )
const {
125 std::common_type_t <TType, RhoType> summer = 0.0;
126 for (
auto i = 0U; i <
n.size(); ++i) {
127 summer +=
n[i] * log(
c[i] +
d[i]*exp(
theta[i] / T));
144 template<
typename TType,
typename RhoType>
145 auto alphaig(
const TType& T,
const RhoType& )
const {
146 std::common_type_t <TType, RhoType> summer = 0.0;
147 for (
auto i = 0U; i <
n.size(); ++i) {
149 TType cosh_theta_over_T = cosh(
theta[i] / T);
150 summer +=
n[i] * log(abs(cosh_theta_over_T));
167 template<
typename TType,
typename RhoType>
168 auto alphaig(
const TType& T,
const RhoType& )
const {
169 std::common_type_t <TType, RhoType> summer = 0.0;
170 for (
auto i = 0U; i <
n.size(); ++i) {
172 TType sinh_theta_over_T = sinh(
theta[i] / T);
173 summer +=
n[i] * log(abs(sinh_theta_over_T));
191 const double c,
const double T_0,
const double R
194 template<
typename TType,
typename RhoType>
195 auto alphaig(
const TType& T,
const RhoType& )
const {
196 using otype = std::common_type_t <TType, RhoType>;
215 const double c,
const double t,
const double T_0,
const double R
218 template<
typename TType,
typename RhoType>
219 auto alphaig(
const TType& T,
const RhoType& )
const {
220 using otype = std::common_type_t <TType, RhoType>;
246 if (jpure.is_array()) {
247 throw teqp::InvalidArgument(
"JSON data passed to PureIdealHelmholtz must be an object and contain the fields \"R\" and \"terms\"");
249 double R = jpure.at(
"R");
250 for (
auto& term : jpure.at(
"terms")) {
251 if (!term.is_object()) {
255 if (term.at(
"type") ==
"Constant") {
258 else if (term.at(
"type") ==
"Lead") {
261 else if (term.at(
"type") ==
"LogT") {
264 else if (term.at(
"type") ==
"PowerT") {
267 else if (term.at(
"type") ==
"PlanckEinstein") {
270 else if (term.at(
"type") ==
"PlanckEinsteinGeneralized") {
273 else if (term.at(
"type") ==
"GERG2004Cosh") {
276 else if (term.at(
"type") ==
"GERG2004Sinh") {
279 else if (term.at(
"type") ==
"Cp0Constant") {
282 else if (term.at(
"type") ==
"Cp0PowerT") {
286 throw InvalidArgument(
"Don't understand this type: " + term.at(
"type").get<std::string>());
291 template<
typename TType,
typename RhoType>
292 auto alphaig(
const TType& T,
const RhoType &rho)
const{
293 std::common_type_t <TType, RhoType> ig = 0.0;
295 auto contrib = std::visit([&](
auto& t) {
return t.alphaig(T, rho); }, term);
314 std::vector<PureIdealHelmholtz>
pures;
317 if (!jpures.is_array()) {
320 for (
auto &jpure : jpures){
321 pures.emplace_back(jpure);
325 template<
typename TType,
typename RhoType,
typename MoleFrac>
326 auto alphaig(
const TType& T,
const RhoType &rho,
const MoleFrac &molefrac)
const {
327 std::common_type_t <TType, RhoType,
decltype(molefrac[0])> ig = 0.0;
328 if (
static_cast<std::size_t
>(molefrac.size()) !=
pures.size()){
332 for (
auto &pure :
pures){
334 ig += molefrac[i]*(pure.alphaig(T, rho) + log(molefrac[i]));
346 template<
typename TType,
typename RhoType,
typename MoleFrac>
347 auto alphar(
const TType& T,
const RhoType &rho,
const MoleFrac &molefrac)
const {
348 return alphaig(T, rho, molefrac);
352 template<
typename MoleFrac>
353 auto R(
const MoleFrac &)
const{
354 return 8.31446261815324;
362 if (term.at(
"type") ==
"IdealGasHelmholtzLead") {
366 return {{{
"type",
"Lead"}, {
"a_1", term.at(
"a1").get<
double>() - log(rhori)}, {
"a_2", term.at(
"a2").get<
double>() * Tri}, {
"R", R}}};
368 else if (term.at(
"type") ==
"IdealGasHelmholtzEnthalpyEntropyOffset") {
370 std::valarray<double> n = {term.at(
"a1").get<
double>(), term.at(
"a2").get<
double>()*Tri};
371 std::valarray<double> t = {0, -1};
372 return {{{
"type",
"PowerT"}, {
"n", n}, {
"t", t}, {
"R", R}}};
374 else if (term.at(
"type") ==
"IdealGasHelmholtzLogTau") {
377 double a = term.at(
"a").get<
double>();
378 nlohmann::json term1 = {{
"type",
"Constant"}, {
"a", a*log(Tri)}, {
"R", R}};
379 nlohmann::json term2 = {{
"type",
"LogT"}, {
"a", -a}, {
"R", R}};
380 return {term1, term2};
382 else if (term.at(
"type") ==
"IdealGasHelmholtzPlanckEinstein") {
384 std::valarray<double> n = term.at(
"n");
385 std::valarray<double> theta = term.at(
"t").get<std::valarray<double>>()*Tri;
386 return {{{
"type",
"PlanckEinstein"}, {
"n", n}, {
"theta", theta}, {
"R", R}}};
388 else if (term.at(
"type") ==
"IdealGasHelmholtzPlanckEinsteinFunctionT") {
390 std::valarray<double> n = term.at(
"n");
391 std::valarray<double> theta = term.at(
"v");
392 return {{{
"type",
"PlanckEinstein"}, {
"n", n}, {
"theta", theta}, {
"R", R}}};
394 else if (term.at(
"type") ==
"IdealGasHelmholtzPlanckEinsteinGeneralized") {
396 std::valarray<double> n = term.at(
"n");
397 std::valarray<double> c = term.at(
"c");
398 std::valarray<double> d = term.at(
"d");
399 std::valarray<double> theta = term.at(
"t").get<std::valarray<double>>()*Tri;
401 return {{{
"type",
"PlanckEinsteinGeneralized"}, {
"n", n}, {
"c", c}, {
"d", d}, {
"theta", theta}, {
"R", R}}};
403 else if (term.at(
"type") ==
"IdealGasHelmholtzPower") {
405 std::valarray<double> n = term.at(
"n").get<std::valarray<double>>();
406 std::valarray<double> t = term.at(
"t").get<std::valarray<double>>();
407 for (
auto i = 0U; i < n.size(); ++i){
408 n[i] *=
pow(Tri, t[i]);
411 return {{{
"type",
"PowerT"}, {
"n", n}, {
"t", t}, {
"R", R}}};
413 else if (term.at(
"type") ==
"IdealGasHelmholtzCP0PolyT") {
415 nlohmann::json newterms = nlohmann::json::array();
417 std::valarray<double> t = term.at(
"t"), c = term.at(
"c");
418 double T_0 = term.at(
"T0");
419 for (
auto i = 0U; i < t.size(); ++i){
421 newterms.push_back({{
"type",
"Cp0Constant"}, {
"c", c[i]}, {
"T_0", T_0}, {
"R", R}});
424 newterms.push_back({{
"type",
"Cp0PowerT"}, {
"c", c[i]}, {
"t", t[i]}, {
"T_0", T_0}, {
"R", R}});
429 else if (term.at(
"type") ==
"IdealGasHelmholtzCP0Constant") {
431 double T_0 = term.at(
"T0");
432 return {{{
"type",
"Cp0Constant"}, {
"c", term.at(
"cp_over_R")}, {
"T_0", T_0}, {
"R", R}}};
434 else if (term.at(
"type") ==
"IdealGasHelmholtzCP0AlyLee") {
436 nlohmann::json newterms = nlohmann::json::array();
438 std::valarray<double> constants = term.at(
"c");
439 double T_0 = term.at(
"T0");
442 if (std::abs(constants[0]) > 1e-14) {
443 newterms.push_back({{
"type",
"Cp0Constant"}, {
"c", constants[0]}, {
"T_0", T_0}, {
"R", R}});
446 std::vector<double> n, c, d, t;
447 if (std::abs(constants[1]) > 1e-14) {
449 n.push_back(constants[1]);
450 t.push_back(-2 * constants[2]);
454 if (std::abs(constants[3]) > 1e-14) {
456 n.push_back(-constants[3]);
457 t.push_back(-2 * constants[4]);
462 {{
"type",
"PlanckEinsteinGeneralized"}, {
"n", n}, {
"c", c}, {
"d", d}, {
"theta", t}, {
"R", R}}
473 throw InvalidArgument(
"Don't understand this type of CoolProp ideal-gas Helmholtz energy term: " + term.at(
"type").get<std::string>());
496 std::filesystem::path p = s;
499 catch(std::exception &){
500 j = nlohmann::json::parse(s);
504 auto jEOS = j.at(
"EOS")[index];
505 auto jCP = jEOS.at(
"alpha0");
506 double Tri = jEOS.at(
"STATES").at(
"reducing").at(
"T");
507 double rhori = jEOS.at(
"STATES").at(
"reducing").at(
"rhomolar");
508 double R = jEOS.at(
"gas_constant");
511 nlohmann::json newterms = nlohmann::json::array();
512 for (
const auto& term : jCP){
516 for (
auto newterm : converted){
517 newterms.push_back(newterm);
518 if (!newterms.back().is_object()){
519 std::cout << newterm.dump() << std::endl;
525 return {{
"terms", newterms}, {
"R", R}};
IdealHelmholtzConstant(double a, double R)
auto alphaig(const TType &, const RhoType &) const
auto alphaig(const TType &T, const RhoType &) const
IdealHelmholtzCp0Constant(const double c, const double T_0, const double R)
IdealHelmholtzCp0PowerT(const double c, const double t, const double T_0, const double R)
auto alphaig(const TType &T, const RhoType &) const
auto alphaig(const TType &T, const RhoType &) const
const std::valarray< double > n
IdealHelmholtzGERG2004Cosh(const std::valarray< double > &n, const std::valarray< double > &theta, double R)
const std::valarray< double > theta
const std::valarray< double > theta
const std::valarray< double > n
auto alphaig(const TType &T, const RhoType &) const
IdealHelmholtzGERG2004Sinh(const std::valarray< double > &n, const std::valarray< double > &theta, double R)
auto alphaig(const TType &T, const RhoType &rho) const
IdealHelmholtzLead(double a_1, double a_2, double R)
auto alphaig(const TType &T, const RhoType &) const
IdealHelmholtzLogT(double a, double R)
const std::valarray< double > c
auto alphaig(const TType &T, const RhoType &) const
const std::valarray< double > n
const std::valarray< double > d
const std::valarray< double > theta
IdealHelmholtzPlanckEinsteinGeneralized(const std::valarray< double > &n, const std::valarray< double > &c, const std::valarray< double > &d, const std::valarray< double > &theta, double R)
IdealHelmholtzPlanckEinstein(const std::valarray< double > &n, const std::valarray< double > &theta, double R)
auto alphaig(const TType &T, const RhoType &) const
const std::valarray< double > theta
const std::valarray< double > n
auto alphaig(const TType &T, const RhoType &) const
const std::valarray< double > t
IdealHelmholtzPowerT(const std::valarray< double > &n, const std::valarray< double > &t, double R)
const std::valarray< double > n
Ideal-gas Helmholtz energy container.
auto alphaig(const TType &T, const RhoType &rho, const MoleFrac &molefrac) const
auto alphar(const TType &T, const RhoType &rho, const MoleFrac &molefrac) const
IdealHelmholtz(const nlohmann::json &jpures)
std::vector< PureIdealHelmholtz > pures
auto R(const MoleFrac &) const
PureIdealHelmholtz(const nlohmann::json &jpure)
auto alphaig(const TType &T, const RhoType &rho) const
std::vector< IdealHelmholtzTerms > contributions
std::variant< IdealHelmholtzConstant, IdealHelmholtzLead, IdealHelmholtzLogT, IdealHelmholtzPowerT, IdealHelmholtzPlanckEinstein, IdealHelmholtzPlanckEinsteinGeneralized, IdealHelmholtzGERG2004Cosh, IdealHelmholtzGERG2004Sinh, IdealHelmholtzCp0Constant, IdealHelmholtzCp0PowerT > IdealHelmholtzTerms
nlohmann::json load_a_JSON_file(const std::string &path)
Load a JSON file from a specified file.
auto getbaseval(const T &expr)
nlohmann::json CoolProp2teqp_alphaig_term_reformatter(const nlohmann::json &term, double Tri, double rhori, double R)
nlohmann::json convert_CoolProp_idealgas(const std::string &s, int index)
Convert the ideal-gas term for a term from CoolProp-formatted JSON structure.
auto pow(const double &x, const double &e)