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

Query on Property Calculation in the Two-Phase Region #303

Open
Sush1090 opened this issue Oct 17, 2024 · 16 comments
Open

Query on Property Calculation in the Two-Phase Region #303

Sush1090 opened this issue Oct 17, 2024 · 16 comments
Labels
flash Issues related to flash calculations

Comments

@Sush1090
Copy link
Contributor

Hello,

I am currently working on computing bulk properties, such as density, volume, temperature, entropy, and specific heats (Cp, Cv), using enthalpy and pressure as inputs.

In most cases, my local solver finds the temperature via the Tproperty function and then computes the required property. This approach works well outside the two-phase region. However, I am looking for a robust method to handle calculations in the two-phase region as well.

Specifically, I am searching for a tool similar to PropsSI that computes properties accurately using pressure and enthalpy. Is such functionality available in Clapeyron, or is there a recommended method for handling this?

Your guidance would be greatly appreciated.

Thank you,
Sushrut

@longemen3000
Copy link
Member

Hello,
technically, what you need is a T-H (T-S and T-V) flash. At the moment, we only have P-T flash implementations. I think we need to track this, is ok if we use this issue for that purpose?

@Sush1090
Copy link
Contributor Author

Yes indeed :)

@longemen3000
Copy link
Member

longemen3000 commented Nov 19, 2024

i think i got an idea on how to do this.

  • on Clapeyron 0.6.5, i introduced some modules (PT,PH,PS,VT), the idea is to do something like:
VT.enthalpy(model,v,T,z) #equivalent to Clapeyron.VT_enthalpy(model,v,T,z)
PT.enthalpy(model,p,T,z) #equivalent to enthalpy(model,p,T,z)
PS.enthalpy(model,p,s,z) #equivalent to calling TProperty and then evaluating enthalpy at p,T conditions

the idea is to add flash functions in the following way

result = PT.flash(model,p,T,z) #equivalent to a modified Clapeyron.tp_flash2(model,p,T,z), changing the output of tp_flash is breaking
comps,fractions,volumes,data = result #if you need specific data
hmix = enthalpy(model,result) #if you need to calculate a weighed sum of property for all phases, the "glide".

A good thing with Tproperty is that identifies equilibria conditions (when prop_bub < prop < prop_dew), so we can modify it to also return the condition (as you already saw in #309) Now, the idea is to hook an adequate flash for each pair of specifications, using the output of Tproperty as an starting point.

@Sush1090
Copy link
Contributor Author

Hello,
I saw the new modules in the latest update, I was locally trying to make this work as well.
Correct me if I am wrong, if we rely on Tproperty internally for our calculations we can achieve this functionality only when we are gas or liquid. We probably will not be able to locate property when the state point is in "two-phase" region.

Because (p,T) cannot represent point in two-phase region (at least for single component systems).
Would we be able to have something like the following in CoolProp:

using CoolProp
fluid = "Water"
p = 101325
H_g = PropsSI("H","Q",1,"P",p,fluid);
H_l = PropsSI("H","Q",0,"P",p,fluid);
H_ = (H_g + H_l)/2 # in TwoPhase region

@show PhaseSI("H",H_,"P",p,fluid)
@show PropsSI("S","H",H_,"P",p,fluid)

Here we can compute entropy in two-phase. But if we do the same with Tproperty we will internally return saturation temperature and then we will end up returning entropy at liquid phase.

Unless there is something different in tp_flash2 I am not sure if Tproperty can handle this.

Do correct me if I am wrong here.

@longemen3000
Copy link
Member

You are correct, p, T is not enough for exactly determining the state point, but if we know that we are in a equilibria state, then we can call a flash. In the latest master I added PS and PH flashes for single components, expecting to add the multicomponent versions soon

@Sush1090
Copy link
Contributor Author

Ah I see. I'll check this too. Thanks

@longemen3000
Copy link
Member

You are correct, p, T is not enough for exactly determining the state point, but if we know that we are in a equilibria state, then we can call a flash. In the latest master I added PS and PH flashes for single components, expecting to add the multicomponent versions soon.

@longemen3000
Copy link
Member

on the current master:

julia> model = cPR(["ethane","propane"],idealmodel=ReidIdeal)
PR{ReidIdeal, TwuAlpha, NoTranslation, vdW1fRule} with 2 components:
 "ethane"
 "propane"
Contains parameters: a, b, Tc, Pc, Mw

julia> p = 101325.0
101325.0

julia> h = -13831.0 #enthalpy at T = 0.5*T_bubble + 0.5*T_dew
-13831.0

julia> z = [0.5,0.5]
2-element Vector{Float64}:
 0.5
 0.5

julia> Clapeyron.ph_flash(model,p,h,z)
([[0.17317188972407677, 0.8268281102759232], [0.6229562865518485, 0.37704371344815146]], [0.4753594797398013, 0.5246405202601987], [6.610779468339207e-5, 0.017026792382129566], Clapeyron.PTFlashData{Float64}(101325.0, 213.38726377112155, -162.11074278396245))

julia> enthalpy(model,result)
-13830.999999999996

@Sush1090
Copy link
Contributor Author

I get this error when running the script

ERROR: UndefVarError: `spec` not defined in `Clapeyron`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] Clapeyron.FlashSpecifications(spec1::typeof(pressure), val1::Float64, spec2::typeof(enthalpy), val2::Float64)
   @ Clapeyron C:\Users\sush9\.julia\packages\Clapeyron\splf7\src\methods\property_solvers\multicomponent\flash.jl:133

I added the master branch using

add https://github.com/ClapeyronThermo/Clapeyron.jl.git

status

[7c7805af] Clapeyron v0.6.5 `https://github.com/ClapeyronThermo/Clapeyron.jl.git#master`

@longemen3000
Copy link
Member

longemen3000 commented Nov 20, 2024

huh, weird, it works in my REPL right now, let me check.

btw, the formulation of the ph flash was made totally generic, so the next steps are adding a ps flash (and other specifications)

@Sush1090
Copy link
Contributor Author

This is actually amazing. This is very close to CoolProp or RefProp

@Sush1090
Copy link
Contributor Author

There is a difference in your version or the version on the master branch?
Because I cannot precompile it:

(ClapeyronFlash) pkg> precompile
Precompiling project...
  ✗ Clapeyron
  0 dependencies successfully precompiled in 5 seconds. 121 already precompiled.

ERROR: The following 1 direct dependency failed to precompile:

Clapeyron

Failed to precompile Clapeyron [7c7805af-46cc-48c9-995b-ed0ed2dc909a] to "C:\\Users\\sush9\\.julia\\compiled\\v1.11\\Clapeyron\\jl_CD2A.tmp".
ERROR: LoadError: UndefVarError: `helmholtz_energy` not defined in `Clapeyron`
Stacktrace:
  [1] top-level scope
    @ C:\Users\sush9\.julia\packages\Clapeyron\GVLnz\src\methods\property_solvers\multicomponent\flash.jl:212

@longemen3000
Copy link
Member

longemen3000 commented Nov 20, 2024

yes, fixing that right now.

by the way, the current result type from ph_flash could change between master and the release, but the way to use it (result = ph_flash(args...), h = enthalpy(model,result) will be the same

@Sush1090
Copy link
Contributor Author

It works! thank you

@Sush1090
Copy link
Contributor Author

Can we close this issue?

@longemen3000
Copy link
Member

This needs a release and a lot of polish, so not now.

@longemen3000 longemen3000 added the flash Issues related to flash calculations label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flash Issues related to flash calculations
Projects
None yet
Development

No branches or pull requests

2 participants