ibell / coolprop

Deprecated version - go to
https://github.com/CoolProp/CoolProp
MIT License
24 stars 16 forks source link

Open for discussion: Two-phase properties #25

Closed jowr closed 10 years ago

jowr commented 11 years ago

Thanks to Martin's initiative, we now have some more values that can be calculated in the two-phase region. However, some of the make sense because they have a thermodynamic definition (speed of sound, cv, ...), but others are some kind of arbitrary. I now added a linear interpolation in some cases.

I attached a picture with graphs generated for water and a comparison with the standard implementation in Modelica. The first value on all the graphs is standard CoolProp, the second one is the reference implementation (name+Ref) and the third one uses the tables (name+TTSE).

twophase

... and now the question: Should we merge this into the main branch or should we introduce some sort of switch à la calc_transport so people can turn them on and off?

Comments are welcome.

ibell commented 11 years ago

My feeling is that it is fine to implement and use any of the definitions that are thermodynamically based, like cv or speed of sound for instance. Otherwise, my preference would be to add a flag.

For the transport properties we should weight 1/eta by the quality so 1/eta = x/eta_v+(1-x)/eta_l, and weight the thermal conductivity linearly. Perhaps that should happen in the Modelica wrapper, but I am also fine with it happening in the CoolProp C++ file. The two-phase properties for transport properties are not really defined for 0>x>1.

Probably we should aim that our default implementation is consistent with Modelica's.

On Thu, Sep 19, 2013 at 6:00 PM, jowr notifications@github.com wrote:

Thanks to Martin's initiative, we now have some more values that can be calculated in the two-phase region. However, some of the make sense because they have a thermodynamic definition (speed of sound, cv, ...), but others are some kind of arbitrary. I now added a linear interpolation in some cases.

I attached a picture with graphs generated for water and a comparison with the standard implementation in Modelica.

[image: twophase]https://f.cloud.github.com/assets/769593/1174197/47174396-2144-11e3-8408-9044defded36.png

... and now the question: Should we merge this into the main branch or should we introduce some sort of switch à la calc_transport so people can turn them on and off?

Comments are welcome.

— Reply to this email directly or view it on GitHubhttps://github.com/ibell/coolprop/issues/25 .

kaern commented 11 years ago

I say the cv and a should be there surely, because their mathematical definition make sense, similar to drhodp_consth and drhodh_constp, eventhough they physically do not, only for homogeneous fluid as far as i know.

cp, kappa and beta cannot be mathematically evaluated in the two-phase region. I am not sure why Modelica.Media.StandardWater uses a linearization of these partial derivatives that cannot be evaluated (their values does not make sense at all). It could be because of the solver in any Modelica environment might catch the discontinuity across the phase boundary during iterations, which might destroy the solution progress? But I am only guessing. A flag would be nice in this case! My greatest concern is the speed of the library, which should not be affected from adding these properties. Especially, the added TTSE equations for these properties should be examined with "speed" in mind, before merging.

The transport properties are also not defined for two-phase region. They may be mass averaged, or volume averaged, nothing is universal. see e.g. http://www.engr.mun.ca/muzychka/ETFS2008.pdf for other methods. Again might be due to robustness issues, that Modelica.Media.StandardWater includes them (however, lambda looks strange above).. Also speed should not lack from this..

jowr commented 11 years ago

OK guys, I now included cv and speed of sound in the standard calculation procedures for two-phase properties. All other values return -_HUGE since they are not defined. In case you need them, you can now turn on the "enable_EXTTP=1" switch on the Modelica wrapper. I attach a picture showing the twp-phase region of water as calculated from CoolProp2Modelica with default settings, standard water implementation (name+Ref) and with extended two-phase properties (name+EXTTP).

twophase01

Below is a picture from the same calculations with TTSE enabled. The results are similar. I guess we can merge the code into master.

twophase02

jowr commented 10 years ago

This does not work any more. Does anyone have an idea about what happened?

kaern commented 10 years ago

It seems that the source code has been deleted:

compare computation of cv:

double CoolPropStateClassSI::cv(void){ if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_LIQUID) { return pIncompLiquid->c(_T, _p); } else if (fluid_type == FLUID_TYPE_INCOMPRESSIBLE_SOLUTION) { // TODO SOLUTION double val_KSI = Props("C",'T',_T,'P',_p,brine_string); return convert_from_unit_system_to_SI(iC,val_KSI,get_standard_unit_system()); } else if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP, p(), iH, h()) ) { if (TwoPhase && _Q>0 && _Q < 1) { return -1; } else { // cv is also given by -B*T/D which is tabulated (indirectly) _h = h(); return -B_over_D_TTSE(_p,_h)*pFluid->TTSESinglePhase.evaluate(iT,_p,_logp,_h); } } else { return -pFluid->R()*pow(tau,2)*(d2phi0_dTau2(tau,delta)+d2phir_dTau2(tau,delta)); //[J/kg/K] } }

with old working revision:

double CoolPropStateClassSI::cv(void){ if (pFluid->enabled_TTSE_LUT && within_TTSE_range(iP, p(), iH, h()) ) { if (TwoPhase && _Q>0 && _Q < 1) { /// As given by Thorade-EES-2013 double dsdTL = pFluid->TTSESatL.evaluate_sat_derivative(iS,_p)/pFluid->TTSESatL.evaluate_sat_derivative(iT,_p); double dsdTV = pFluid->TTSESatV.evaluate_sat_derivative(iS,_p)/pFluid->TTSESatV.evaluate_sat_derivative(iT,_p); double drhodTL = pFluid->TTSESatL.evaluate_sat_derivative(iD,_p)/pFluid->TTSESatL.evaluate_sat_derivative(iT,_p); double drhodTV = pFluid->TTSESatV.evaluate_sat_derivative(iD,_p)/pFluid->TTSESatV.evaluate_sat_derivative(iT,_p); double dvdTL = -drhodTL/rhoL()/rhoL(); double dvdTV = -drhodTV/rhoV()/rhoV(); double dxdT_v = (_Q*dvdTV + (1-_Q)*dvdTL)/(1/rhoL()-1/rhoV()); double Tsat = (TV() - TL()) * _Q + TL(); return Tsat*dsdTL + Tsat*dxdT_v*(sV()-sL()) + _Q*Tsat*(dsdTV - dsdTL); } else { // cv is also given by -B*T/D which is tabulated (indirectly) _h = h(); return -B_over_D_TTSE(_p,_h)*pFluid->TTSESinglePhase.evaluate(iT,_p,_logp,_h); } } else { if (TwoPhase) { /// As given by Thorade-EES-2013 double dsdTL = dsdT_along_sat_liquid(); double dsdTV = dsdT_along_sat_vapor(); double dvdTL = -drhodT_along_sat_liquid()/rhoL()/rhoL(); double dvdTV = -drhodT_along_sat_vapor()/rhoV()/rhoV(); double dxdT_v = (_Q*dvdTV + (1-_Q)*dvdTL)/(1/rhoL()-1/rhoV()); double Tsat = (TV() - TL()) * _Q + TL(); return Tsat*dsdTL + Tsat*dxdT_v*(sV()-sL()) + _Q*Tsat*(dsdTV - dsdTL); } else { return -pFluid->R()*pow(tau,2)*(d2phi0_dTau2(tau,delta)+d2phir_dTau2(tau,delta)); //[J/kg/K] } } }

ibell commented 10 years ago

Ill take a look and add a test to make sure it stays working in the future. Thanks for the report.

On 2/25/14, Jorrit Wronski notifications@github.com wrote:

This does not work any more. Does anyone have an idea about what happened?


Reply to this email directly or view it on GitHub: https://github.com/ibell/coolprop/issues/25#issuecomment-35986568

jowr commented 10 years ago

I am currently browsing revision to find the commit that deleted things...

kaern commented 10 years ago

have a look at rev: 717b8b19b6c44516cfd3def6c876d9bf0ebff7b1

jowr commented 10 years ago

Thank you Martin, I'll try to add the functions again.

jowr commented 10 years ago

Back in business two-phase

ibell commented 10 years ago

What had happened? Did some code get merged that shouldn't have? This is a pretty compelling argument for more aggressive unit testing.

On Tue, Feb 25, 2014 at 11:52 AM, Jorrit Wronski notifications@github.comwrote:

Closed #25 https://github.com/ibell/coolprop/issues/25 via 48b9807https://github.com/ibell/coolprop/commit/48b9807b6766b2b21991779c74a75a8f1736376f .

Reply to this email directly or view it on GitHubhttps://github.com/ibell/coolprop/issues/25 .

jowr commented 10 years ago

Ian, I am afraid you deleted the code when you merged local changes to the master in 717b8b1, but yes, more testing had saved us some time...

ibell commented 10 years ago

Oops. Probably late night coding I suspect.

On Tue, Feb 25, 2014 at 12:01 PM, Jorrit Wronski notifications@github.comwrote:

Ian, I am afraid you deleted the code when you merged local changes to the master in 717b8b1 https://github.com/ibell/coolprop/commit/717b8b1, but yes, more testing had saved us some time...

Reply to this email directly or view it on GitHubhttps://github.com/ibell/coolprop/issues/25#issuecomment-35996609 .