Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QP flash bugs #325

Closed
Sush1090 opened this issue Dec 24, 2024 · 12 comments
Closed

QP flash bugs #325

Sush1090 opened this issue Dec 24, 2024 · 12 comments

Comments

@Sush1090
Copy link
Contributor

Hello,
The following will not work

using Clapeyron
model = cPR(["methane"],idealmodel = ReidIdeal)
p = 101325.0; q = 1.0; z = [5.0]
Clapeyron.qp_flash(model,q,p,z)

error:

ERROR: UndefVarError: `βv` not defined in `Clapeyron`
Suggestion: check for spelling errors or missing imports.
longemen3000 added a commit that referenced this issue Dec 24, 2024
@Sush1090
Copy link
Contributor Author

There is one in qt_flash as well:
This will not work:

 Clapeyron.qt_flash(model,0.99,300,z)

error:

ERROR: UndefVarError: `T` not defined in local scope
Suggestion: check for an assignment to a local variable that shadows a global of the same name.

longemen3000 added a commit that referenced this issue Dec 24, 2024
@longemen3000
Copy link
Member

if nothing is found in 24 hours, i'm releasing a new version with the fixes for the problems found here and in #320

@Sush1090
Copy link
Contributor Author

I have not found any other bugs for now. If incase I will post it here.

@Sush1090
Copy link
Contributor Author

Hello,
This is probably more of a question than a bug. I decided to plot the vapour fraction vs temperature for a 2 component mixture.

This is the graph I get:
qT

This discontinuity seems a bit odd to me? This is expected?
With different fluids the temperature returned sometimes is also NaN example ["isobutane","methanol"]

I am attaching my code below for reproducibility:

using Clapeyron, Plots
using Clapeyron.PH


function qp_temperature(model,q,p,z)
    res = qp_flash(model,q,p,z)
    return Clapeyron.temperature(model,res)
end

function qp_entropy(model,q,p,z)
    res = qp_flash(model,q,p,z)
    return Clapeyron.entropy(model,res)
end

function qp_enthalpy(model,q,p,z)
    res = qp_flash(model,q,p,z)
    return Clapeyron.enthalpy(model,res)
end
fluids = ["isobutane","pentane"]
model = cPR(fluids,idealmodel=ReidIdeal)
p = 101325; z = [5.0,5.0]; 
q = collect(range(0.001,0.999,100))
for i in eachindex(q)
    T[i] = qp_temperature(model,q[i],p,z)
end
scatter(q,T,xlabel = "vapour fraction",ylabel = "temperature",title = "$(fluids)")

@longemen3000
Copy link
Member

definitely a bug. Caused mainly by a lot of missing scalings and improper initial points. It is fixed in the latest master.
image

@Sush1090
Copy link
Contributor Author

Sush1090 commented Dec 27, 2024

Hello,
This is not a post for a bug :)

With the latest fix we can do something nice:
So before qp_flash was implemented we had a linear approximation to the glide for mixtures - I had shown it in a previous issue here #295. That linear approximation does not respect qp_flash, but now we can have a much accurate approximation for this using just T and p as inputs to the bulk property.

Here is an example:
TS-glide

This non-linear glide in the two-phase zone is probably the correct way to interpret the behaviour of the fluid.

I have attached my code to replicate it:

using Clapeyron, Plots, Roots
function qp_temperature(model,q,p,z)
    res = qp_flash(model,q,p,z)
    return Clapeyron.temperature(model,res)
end

function qp_entropy(model,q,p,z)
    res = qp_flash(model,q,p,z)
    return Clapeyron.entropy(model,res)
end

function qp_enthalpy(model,q,p,z)
    res = qp_flash(model,q,p,z)
    return Clapeyron.enthalpy(model,res)
end
function my_mixture_entropy(model::EoSModel,p,T,z)
    @assert size(model.components,1) >=2
    crit = crit_mix(model,z)
    T_,p_,_ = crit
    @assert T <T_
    @assert p < p_
    bt = bubble_temperature(model,p,z)[1]
    dt = dew_temperature(model,p,z)[1]
    
    if T <= bt || T >= dt
        return entropy(model,p,T,z)
    end
    if bt<=T<=dt
        f(x) = qp_temperature(model,x,p,z) - T
        sol_q = find_zero(f,(0,1))
        return qp_entropy(model,sol_q,p,z)
    end
end
fluids = ["isopentane","toluene"]
model = cPR(fluids,idealmodel=ReidIdeal)
p = 101325.0; z = [5.0,5.0]; 
T = collect(range(310.0,380.0,100))
s = similar(T)
for i in eachindex(T)
    s[i] = my_mixture_entropy(model,p,T[i],z)
end
scatter(s,T,xlabel = "Entropy",ylabel = "Temperature",title = "$(fluids)")

There are some downsides:

  1. We rely on bubble and dew temperatures to not return NaN values. This happens when we go closer to critical pressure.
  2. When there is VLLE type fluid for example methanol, ethanol etc .. qp_flash is not still completely robust.

Thank you
Sushrut

@Sush1090
Copy link
Contributor Author

Hello,
The following returns NaN.

fluids = ["isobutane","toluene"]
model = cPR(fluids,idealmodel=ReidIdeal)
p = 8*101325.0; z = [5.0,5.0]; 
julia> qp_flash(model,0.4,101325*8,z)
Flash result at T = NaN, p = 810600.0 with 2 phases:
 (x = [NaN, NaN], β = NaN, v = NaN)
 (x = [NaN, NaN], β = NaN, v = NaN)

It returns NaN for q between 0.33 and 0.48. This is extended to other fluids for different pressures as well.

@longemen3000
Copy link
Member

yeah, something is going on in the initial point:

julia> Clapeyron.qp_flash_x0(model,0.4,p,z,GeneralizedXYFlash())
Flash result at T = 392.3, p = 810600.0 with 2 phases:
 (x = [0.1395, 0.8605], β = 0.0, v = 0.000117428)
 (x = [0.5, 0.5], β = 10.0, v = 0.000119718)

@longemen3000
Copy link
Member

I'm gonna close this for the moment, Clapeyron 0.6.7 was released
On qp/qt flash as an alternative for Tproperty/Pproperty, seems like a good idea overall, probably worth exploring.

@Sush1090
Copy link
Contributor Author

Sush1090 commented Jan 7, 2025

Hello,
Is it possible to reopen this? Or should I make a new issue?

@Sush1090
Copy link
Contributor Author

Sush1090 commented Jan 7, 2025

There is a z scaling bug in qp_flash.

using Clapeyron

fluids= ["isopentane","isobutane"]
model = cPR(fluids,idealmodel=ReidIdeal)

p = 2*101325.0; z = [2.0,5.0]; 
q = 0.062744140625
# Perform a QP flash calculation
result_1 = qp_flash(model,q,p, z)

@show result_1

result_2 = qp_flash(model,q,p, z./10)
@show result_2

result_1 works while result_2 will return NaN

@longemen3000
Copy link
Member

longemen3000 commented Jan 7, 2025

I am happy to inform that we have some cases in which we converge in our ps_flash, while it fails in CoolProp:

using Clapeyron,CoolProp

#CoolProp 
#(https://github.com/CoolProp/CoolProp/issues/1870#issuecomment-2526192810)
p1 = 2.5e5
T = 133+273.15
sm1 = PropsSI("Smolar", "P", p1, "T", T, "Pentane")
p2 = 22e5
h1 = PropsSI("H", "P", p2, "Smolar", sm1, "Pentane") #fails

#Clapeyron:
model = SingleFluid("pentane")
sm2 = entropy(model,p1,T) #in this particular case, a flash is not necessary, an alternative that returns a flash object is Clapeyron.tp_flash2(model,p1,T,[1.0])
res1 = ps_flash(model,p2,sm2,[1.0]) #calculates successfully
h2 = enthalpy(model,res1)
res2 = ph_flash(model,p2,h2,[1.0])
sm3 = entropy(model,res2)
sm2  sm3 #true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants