ClapeyronThermo / Clapeyron.jl

Clapeyron provides a framework for the development and use of fluid-thermodynamic models, including SAFT, cubic, activity, multi-parameter, and COSMO-SAC.
MIT License
198 stars 51 forks source link

support for H/S reference states #254

Closed longemen3000 closed 7 months ago

longemen3000 commented 7 months ago

This PR adds support for setting reference states for enthalpy and entropy:

julia> model = GERG2008("water",reference_state = :nbp)
MultiFluid{EmpiricAncillary, AsymmetricMixing, EmpiricDeparture} with 1 component:
 "water"
Contains parameters: Mw, Tc, Pc, Vc, acentricfactor, lb_volume, reference_state

julia> T,v,_ = saturation_temperature(model, 101325.0)
(373.17465532626215, 1.880337570758312e-5, 0.030073599887549093)

julia> Clapeyron.VT_enthalpy(model,v,T)
5.31106965587669e-11

julia> Clapeyron.VT_entropy(model,v,T)
1.8474111129762605e-13

Technical details: the reference state is stored in a new struct, ReferenceState <: ClapeyronParam. this struct was added to almost all ideal models (except BasicIdeal). Clapeyron.eos was modified into the following:

function eos(model,V,T,z=SA[1.0])
  return Rgas(model)*T*sum(z)*(a_ideal(idealmodel(model),V,T,z) + a_res(model,V,T,z) + reference_state_eval(model,V,T,z)
end

were reference_state_eval(model,V,T,z) is just:

ref = reference_state(model)
a0 = dot(z,ref.a0) #constant term
a1 = dot(z,ref.a1) #temperature dependent term
return a0 + a1*T

a0 and a1 are a function of the entropy and enthalpy at the reference conditions and can be obtained easily.

The @newmodel macros automatically add the keyword argument reference_state = nothing to each model created this way.

Most of the changes were in the docs department :sweat_smile: , formatting fixes and adding the reference_state keyword to each documented eos

longemen3000 commented 7 months ago

errors in nightly are unrelated