Problem using Cubic Backend in C++ - Version 6.4.2

95 views
Skip to first unread message

Breno Avancini

unread,
Mar 1, 2022, 10:35:59 AM3/1/22
to coolprop-users
Hello,

I am having problems when using cubic equations of state in mixtures in a C++ code that i am building (when using the "HEOS" everything works fine, but too slow).

When I run the calculation of a "CH4&CO2" mixture with a composition of [0.7,0.3] (or any other composition) I get very strange values of thermodynamic properties (like 1700 m/s of speed of sound in 293K and 1e5 Pa).

Can you give a example of how to code properly the calculation of thermodynamic properties of mixtures using a cubic equation of state?

Best regards,

Breno Avancini

unread,
Mar 1, 2022, 10:50:38 AM3/1/22
to coolprop-users
Just to give more information about the problem, bellow I put a few commands that I am using currently:

    std::vector<double> moleFractions;
    std::shared_ptr<CoolProp::AbstractState> Rhofluid_;

    Rhofluid_(CoolProp::AbstractState::factory("PR","CH4&CO2"))

    moleFractions.resize(2);
    moleFractions[0] = 0.7;
    moleFractions[1] = 0.3;

    Rhofluid_->set_mole_fractions(moleFractions);
    Rhofluid_->unspecify_phase();
    Rhofluid_->update(CoolProp::PT_INPUTS, 1e5, 300);
    std::cout <<"C = " <<" || "<< Rhofluid_->speed_sound() <<std::endl;

Output: "C =  || 7204.67"

I really need to use cubic equation and in C++.
In python I verified and everything run as expected.

Breno Avancini

unread,
Mar 3, 2022, 6:17:36 AM3/3/22
to coolprop-users
Can anyone think about what is causing that difference? And perhaps instruct me about a work around?

Ian Bell

unread,
Mar 6, 2022, 12:19:07 PM3/6/22
to coolpro...@googlegroups.com
How do the values from HEOS compare to cubics? How about AS.d2Alpha_dTau() (this is the contribution from the ideal gas part)?  How about the density?

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coolprop-users/69e72936-bb54-45c3-8622-4c46f32038fen%40googlegroups.com.

Breno Avancini

unread,
Mar 14, 2022, 7:04:31 PM3/14/22
to coolprop-users
Hi, sorry for my late reply.
Thank you for the attention.

The values given by the PR EOS are:
C =  7204.67 m/s
rhomass = 0.982499 kg/m^3

The values given by the H EOS are:
C =  363.614 m/s
rhomass = 0.981828 kg/m^3

I couldn't find the function that you pointed, but I ran some that might be what you were asking me to calculate, and the result are:

for PR EOS: AS.d2alpha0_dTau2() = 0;
for H EOS : AS.d2alpha0_dTau2() = -6.32519;

for PR EOS: AS.d2alphar_dTau2() = -178.617;
for H EOS : AS.d2alphar_dTau2() = -0.00594519;

for PR EOS: AS.dalpha0_dTau() = 0;
for H EOS : AS.dalpha0_dTau() = 7.97786;

for PR EOS: AS.dalphar_dTau() = -1.97233;
for H EOS : AS.dalphar_dTau() = -0.00783012;

I hope I sent enough information.

Awaiting for your judgment.

Best regards.

Ian Bell

unread,
Mar 15, 2022, 8:54:39 PM3/15/22
to coolpro...@googlegroups.com
For some reason, the ideal gas part seems to be missing, you might need to do a horrible workaround where you get the ideal-gas part from the HEOS backend and the residual part from the PR backend. Better to fix it, but I can't do that right now.

Breno Avancini

unread,
Mar 17, 2022, 11:14:21 AM3/17/22
to coolprop-users
Hi,

Doing some more investigations I found out that not only the speed of sound calculations were different but also others, such as entropy and enthalpy.

I know that it must be very difficult to manage to have time to update the code, but if you could tell me when you think that the update will be possible I would be very thankful.

Best regards

Breno Avancini

unread,
Mar 20, 2022, 11:54:08 AM3/20/22
to coolprop-users
Ian,

Do you think that if I downgrade to other version the problem won't exist?
If so, what version would you recommend?

Att,

Ian Bell

unread,
Mar 21, 2022, 9:08:17 PM3/21/22
to coolpro...@googlegroups.com
Nope, that won't do it.  You'll need to do the workaround I mention: obtain the alpha0 from the HEOS backend, all the rest from the cubic backend.

Friederike Boehm

unread,
Mar 23, 2022, 6:02:18 AM3/23/22
to coolprop-users
Hi,

i think I might have found the problem. In the calculation of the alpha0 derivatives (HelmholtzEOSMixtureBackend::calc_alpha0_deriv_nocache) Rcomponent is read from components[i].EOS().R_u. As far as I can tell this is not set for the cubic components and Rcomponent is very very small in this case (e-115 or something ridiculous). This leads to d2a0_dTau2 being pretty much zero. Hardcoding Rcomponent to get_config_double(R_U_CODATA) (8.3144598) leads to a lot more reasonable values in my problem (https://groups.google.com/g/coolprop-users/c/dE5aK0GWHhA), at least for the gas phase, and your example also yields a similar result to the HEOS backend with this fix. I am working on implementing this properly and just created the issue on GitHub.

Breno Avancini

unread,
Mar 23, 2022, 7:21:09 PM3/23/22
to coolprop-users
Hi,

Wonderful news.
Could you update us when the code is updated?
How much time do you think this issue will take to be solved?

Best regards,

Ian Bell

unread,
Mar 24, 2022, 5:59:46 PM3/24/22
to coolpro...@googlegroups.com

Breno Avancini

unread,
Mar 24, 2022, 6:04:48 PM3/24/22
to coolprop-users
Thank you all for the effort!

I will verify this weekend if everything is working properly now.

Best regards,
Reply all
Reply to author
Forward
0 new messages