@@ -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+ R̄ = Rgas (model)
301302 nRTp = sum (z)* R̄* T/ p
302303 _poly,c̄ = cubic_poly (model,p,T,z)
303304
304305 c = 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 > 4 eps (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