From efce934fa81a0e92ef62ab5d43c8f403d9d69f24 Mon Sep 17 00:00:00 2001 From: longemen3000 Date: Sun, 1 Dec 2024 17:35:25 -0300 Subject: [PATCH] typos, add test for #309 --- src/methods/property_solvers/Tproperty.jl | 4 ++-- .../property_solvers/multicomponent/flash.jl | 17 +++++-------- .../multicomponent/flash/general_flash.jl | 24 +++++++++---------- test/test_methods_api.jl | 13 ++++++++++ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/methods/property_solvers/Tproperty.jl b/src/methods/property_solvers/Tproperty.jl index a29fce32b..1dfaff9cb 100644 --- a/src/methods/property_solvers/Tproperty.jl +++ b/src/methods/property_solvers/Tproperty.jl @@ -225,8 +225,8 @@ function Tproperty_pure(model,p,prop,z,property::F,rootsolver,phase,abstol,relto prop_v = vvsat prop_l = vlsat else - prop_v = property(model,P,Tsat,z,phase = :v) - prop_l = property(model,P,Tsat,z,phase = :l) + prop_v = property(model,p,Tsat,z,phase = :v) + prop_l = property(model,p,Tsat,z,phase = :l) end β = (prop - prop_l)/(prop_v - prop_l) diff --git a/src/methods/property_solvers/multicomponent/flash.jl b/src/methods/property_solvers/multicomponent/flash.jl index 2e40f24a9..e2a934c2b 100644 --- a/src/methods/property_solvers/multicomponent/flash.jl +++ b/src/methods/property_solvers/multicomponent/flash.jl @@ -175,18 +175,13 @@ end temperature(state::FlashResult) = state.data.T pressure(state::FlashResult) = state.data.p +volume(state::FlashResult) = dot(state.fractions,state.volumes) +molar_density(state::FlashResult) = sum(state.fractions)/volume(state) -function volume(model::EoSModel,state::FlashResult) - comps, β, volumes, data = state - return dot(β,volumes) -end - -function molar_density(model::EoSModel,state::FlashResult) - comps, β, volumes, data = state - v = volume(model,state) - n = sum(β) - return n/v -end +pressure(model::EoSModel,state::FlashResult) = pressure(state) +temperature(model::EoSModel,state::FlashResult) = temperature(state) +volume(model::EoSModel,state::FlashResult) = volume(state) +molar_density(model::EoSModel,state::FlashResult) = molar_density(state) function __molecular_weight(model,state::FlashResult) comps, β, volumes, data = state diff --git a/src/methods/property_solvers/multicomponent/flash/general_flash.jl b/src/methods/property_solvers/multicomponent/flash/general_flash.jl index 18799b55f..694f30501 100644 --- a/src/methods/property_solvers/multicomponent/flash/general_flash.jl +++ b/src/methods/property_solvers/multicomponent/flash/general_flash.jl @@ -47,24 +47,24 @@ function Base.show(io::IO,x::FlashSpecifications) print(io,spec2," => ",val2,")") end -spec_intensive(::typeof(pressure)) = false -spec_intensive(::typeof(temperature)) = false -spec_intensive(x) = true +spec_intensive(::typeof(pressure)) = true +spec_intensive(::typeof(temperature)) = true +spec_intensive(x) = false function normalize_spec(s::FlashSpecifications,k) _1 = oneunit(1/k) spec1,spec2,val1,val2 = s.spec1,s.spec2,s.val1,s.val2 - if !spec_intensive(spec1) - newval1 = val1/k - else + if spec_intensive(spec1) newval1 = val1*_1 + else + newval1 = val1/k end - if !spec_intensive(spec2) - newval2 = val2/k - else + if spec_intensive(spec2) newval2 = val2*_1 + else + newval2 = val2/k end return FlashSpecifications(spec1,newval1,spec2,newval2) @@ -705,13 +705,13 @@ end function tx_flash_x0(model,T,x,z,spec::F,method::GeneralizedXYFlash) where F if method.p0 == nothing - p,_phase = _Pproperty(model,p,x,z,spec) + p,_phase = _Pproperty(model,T,x,z,spec) else p = method.p0 _phase = :eq #we suppose this end - - TT = Base.promote_eltype(model,p,x,z,T) + + TT = Base.promote_eltype(model,T,x,z,T) if _phase != :eq return FlashResult(model,p,T,z,phase = _phase) end diff --git a/test/test_methods_api.jl b/test/test_methods_api.jl index 8ee4a02dc..5a12e2343 100644 --- a/test/test_methods_api.jl +++ b/test/test_methods_api.jl @@ -440,6 +440,19 @@ end T3_calc = Tproperty(model3,p3,s30,z3,entropy) s3 = entropy(model3,p3,T3_calc,z3) @test s3 ≈ s30 + + #issue 309 (https://github.com/ClapeyronThermo/Clapeyron.jl/issues/309#issuecomment-2508038968) + model4 = cPR("R134A",idealmodel= ReidIdeal) + T_crit,p_crit,_ = crit_pure(model4) + T1 = 300.0 + p1 = saturation_pressure(model4,T1)[1] + 101325 + s1 = entropy(model4,p1,T1) + h1 = enthalpy(model4,p1,T1) + p2 = p_crit + 2*101325 + T2 = Tproperty(model4,p2,s1,Clapeyron.SA[1.0],entropy) + s2 = entropy(model4,p2,T2) + h2 = enthalpy(model4,p2,T2) + @test s2 ≈ s1 end @testset "bubble/dew point algorithms" begin