Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pw0908 committed Oct 2, 2024
2 parents 4c8caa3 + 4a6aefd commit 78984df
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/src/properties/bulk.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Clapeyron.internal_energy_res
```@docs
Clapeyron.isochoric_heat_capacity
Clapeyron.isobaric_heat_capacity
Clapeyron.adiabatic_index
Clapeyron.isothermal_compressibility
Clapeyron.isentropic_compressibility
Clapeyron.speed_of_sound
Expand Down
8 changes: 8 additions & 0 deletions src/methods/VT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ function VT_isobaric_heat_capacity(model::EoSModel, V, T, z=SA[1.])
return -T*(∂²A∂T² - ∂²A∂V∂T^2/∂²A∂V²)
end

function VT_adiabatic_index(model::EoSModel, V, T, z=SA[1.])
d²A = f_hess(model,V,T,z)
∂²A∂V∂T = d²A[1,2]
∂²A∂V² = d²A[1,1]
∂²A∂T² = d²A[2,2]
return 1 - ∂²A∂V∂T*∂²A∂V∂T/(∂²A∂V²*∂²A∂T²)
end

function VT_isothermal_compressibility(model::EoSModel, V, T, z=SA[1.])
p0,∂p∂V = p∂p∂V(model,V,T,z)
return -1/V/∂p∂V
Expand Down
7 changes: 3 additions & 4 deletions src/methods/differentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
returns `f` and `∂f/∂T` at constant total volume and composition, where f is the total helmholtz energy, given by `eos(model,V,T,z)`
"""
function ∂f∂T(model,V,T,z=SA[1.0])
function ∂f∂T(model,V,T,z)
f(∂T) = eos(model,V,∂T,z)
return Solvers.derivative(f,T)
end
Expand All @@ -21,9 +21,8 @@ end
returns `f` and `∂f/∂V` at constant temperature and composition, where f is the total helmholtz energy, given by `eos(model,V,T,z)`, and V is the total volume
"""
function ∂f∂V(model,V,T,z)
f(∂V) = a_res(model,∂V,T,z)
dadv = Solvers.derivative(f,V)
return Rgas(model)*T*(dadv - sum(z)/V)
f(∂V) = eos(model,∂V,T,z)
return Solvers.derivative(f,V)
end

#returns a tuple of the form ([∂f∂V,∂f∂T],f),using the least amount of computation
Expand Down
27 changes: 26 additions & 1 deletion src/methods/pT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,31 @@ function isobaric_heat_capacity(model::EoSModel, p, T, z=SA[1.]; phase=:unknown,
V = volume(model, p, T, z; phase, threaded, vol0)
return VT_isobaric_heat_capacity(model,V,T,z)
end

"""
adiabatic_index(model::EoSModel, p, T, z=SA[1.]; phase=:unknown, threaded=true, vol0=nothing)
Default units: `[J/K]`
Calculates the isobaric heat capacity, defined as:
```julia
γ = Cp/Cv
```
Internally, it calls [`Clapeyron.volume`](@ref) to obtain `V` and
calculates the property via `VT_adiabatic_index(model,V,T,z)`.
The keywords `phase`, `threaded` and `vol0` are passed to the [`Clapeyron.volume`](@ref) solver.
!!! warning "Accurate ideal model required"
This property requires at least second order ideal model temperature derivatives. If you are computing these properties, consider using a different ideal model than the `BasicIdeal` default (e.g. `EoS(["species"];idealmodel = ReidIdeal)`).
"""
function adiabatic_index(model::EoSModel, p, T, z=SA[1.]; phase=:unknown, threaded=true, vol0=nothing)
V = volume(model, p, T, z; phase, threaded, vol0)
return VT_adiabatic_index(model,V,T,z)
end

"""
isothermal_compressibility(model::EoSModel, p, T, z=SA[1.]; phase=:unknown, threaded=true, vol0=nothing)
Expand Down Expand Up @@ -762,7 +787,7 @@ end
export entropy, internal_energy, enthalpy, gibbs_free_energy, helmholtz_free_energy
export entropy_res, internal_energy_res, enthalpy_res, gibbs_free_energy_res, helmholtz_free_energy_res
#second derivative order properties
export isochoric_heat_capacity, isobaric_heat_capacity
export isochoric_heat_capacity, isobaric_heat_capacity,adiabatic_index
export isothermal_compressibility, isentropic_compressibility, speed_of_sound
export isobaric_expansivity, joule_thomson_coefficient, inversion_temperature
#higher derivative order properties
Expand Down
4 changes: 4 additions & 0 deletions test/test_methods_eos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Clapeyron, Test, Unitful
system = PCSAFT(["ethanol"])
p = 1e5
T = 298.15
T2 = 373.15
@testset "Bulk properties" begin
@test Clapeyron.volume(system, p, T) 5.907908736304141e-5 rtol = 1e-6
@test Clapeyron.volume(system, p, T;phase=:v) 0.020427920501436134 rtol = 1e-6
Expand All @@ -20,6 +21,9 @@ using Clapeyron, Test, Unitful
@test Clapeyron.helmholtz_free_energy(system, p, T) -18329.785451419295 rtol = 1E-6
@test Clapeyron.isochoric_heat_capacity(system, p, T) 48.37961296309505 rtol = 1E-6
@test Clapeyron.isobaric_heat_capacity(system, p, T) 66.45719988319257 rtol = 1E-6
Cp = Clapeyron.isobaric_heat_capacity(system, p, T2)
Cv = Clapeyron.isochoric_heat_capacity(system, p, T2)
@test Clapeyron.adiabatic_index(system, p, T2) Cp/Cv rtol = 1E-12
@test Clapeyron.isothermal_compressibility(system, p, T) 1.1521981407243432e-9 rtol = 1E-6
@test Clapeyron.isentropic_compressibility(system, p, T) 8.387789464951438e-10 rtol = 1E-6
@test Clapeyron.speed_of_sound(system, p, T) 1236.4846683094133 rtol = 1E-6 #requires that the model has Mr
Expand Down

0 comments on commit 78984df

Please sign in to comment.