Skip to content

Commit b116de1

Browse files
committed
remove unused code on x0_sat_pure_near0, use virial volume + zero volumeif pressure is too low
1 parent ece14e8 commit b116de1

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/methods/initial_guess.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,7 @@ function x0_sat_pure_near0(model, T, vl0 = volume(model,zero(T),T,phase = :l);B
386386
lnϕ_liq0 = ares - 1 + log(RT/vl0)
387387
p = exp(lnϕ_liq0)
388388
pB = -0.25*RT/B
389-
if lnϕ_liq0 < log(eps(eltype(T)))
390-
p = oneunit(p)*0.5*pB
391-
vl0 = volume(model,p,T,z,vol0 = vl0,phase = :l)
392-
end
393389
vv = volume_virial(B,p,T)
394-
395390
if refine_vl && pB/p > 10
396391
vl = volume(model,p,T,z,vol0 = vl0,phase = :l)
397392
if vl vv #refinement failed, stick with vl0

src/models/cubic/equations.jl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,30 @@ function volume_impl(model::CubicModel,p,T,z,phase,threaded,vol0)
298298
_1 = one(_0)
299299
return _1/_0
300300
end
301+
= Rgas(model)
301302
nRTp = sum(z)**T/p
302303
_poly,c̄ = cubic_poly(model,p,T,z)
303304

304305
c =*sum(z)
305-
num_isreal, z1, z2, z3 = Solvers.real_roots3(_poly)
306-
if num_isreal == 2
307-
vvl,vvg = nRTp*z1 - c,nRTp*z2 - c
308-
elseif num_isreal == 3
309-
vvl,vvg = nRTp*z1 - c,nRTp*z3 - c
306+
307+
B = lb_v*p/(R̄*T)
308+
if B > 4eps(typeof(B))
309+
num_isreal, z1, z2, z3 = Solvers.real_roots3(_poly)
310+
311+
if num_isreal == 2
312+
vvl,vvg = nRTp*z1 - c,nRTp*z2 - c
313+
elseif num_isreal == 3
314+
vvl,vvg = nRTp*z1 - c,nRTp*z3 - c
315+
else
316+
vvl,vvg = nRTp*z1 - c,nRTp*z1 - c
317+
end
310318
else
311-
vvl,vvg = nRTp*z1 - c,nRTp*z1 - c
319+
vl0,_ = zero_pressure_impl(model,T,z)
320+
vvg = volume_virial(model,p,T,z) #TODO refine (necessary?)
321+
vvl = _volume_compress(model,p,T,z,vl0)
322+
num_isreal = 3
312323
end
324+
313325
#err() = @error("model $model Failed to converge to a volume root at pressure p = $p [Pa], T = $T [K] and compositions = $z")
314326
if !isfinite(vvl) && !isfinite(vvg) && phase != :unknown
315327
V0 = x0_volume(model, p, T, z; phase)
@@ -322,7 +334,7 @@ function volume_impl(model::CubicModel,p,T,z,phase,threaded,vol0)
322334
_vl = vvl
323335
vl = ifelse(_vl > lb_v, _vl, vg) #catch case where solution is unphysical
324336
else # 1 real root (or 2 with the second one degenerate)
325-
vg = vl = z1 * nRTp - c
337+
vg = vl = vvg
326338
end
327339

328340
function gibbs(v)

0 commit comments

Comments
 (0)