braamvandyk / SteamTables.jl

Julia implementation of steam tables according to IAPWS Industrial Formulation (1997)
Other
12 stars 4 forks source link

replace Psat2 with derivative, remove forwarddiff dependence #11

Closed longemen3000 closed 4 months ago

longemen3000 commented 3 years ago

im working on a fork of this package, and to drop the dependency of ForwardDiff, i wrote the derivative by hand:

const dpsat_a = [ -7.85951783000,
1.84408259000,
-11.78664970000,
22.68074110000,
-15.96187190000,
1.80122502000
]
const Tc_inv = 1.0/Tc
function ∂Psat∂T(T)
    a = dpsat_a
    θ = Tc_inv 
    τ = 1 - θ
    ∂τ = - Tc_inv
    ∂T = one(T)
    τhalf = sqrt(τ)
    τ15 = τ*τhalf
    τ2 = τ*τ
    τ25 = τ2*τhalf
    τ3 = τ2*τ
    τ35=τ3*τhalf
    τ4=τ2*τ2
    τ65 = τ35*τ3
    τ75 = τ35*τ4

    x = Tc*(a[1]*τ + a[2]*τ15 + a[3]*τ3 + a[4]*τ35 + a[5]*τ4 + a[6]*τ75)
    ∂x = Tc*∂τ*(a[1] + 1.5*a[2]*τhalf + 3.0*a[3]*τ2 + 3.5*a[4]*τ25 + 4.0*a[5]*τ3 + 7.5*a[6]*τ65)
    xT = x/T
    #res =  Pc*exp(xT)
    ∂res = Pc*exp(xT)*(∂x - xT*∂T)/T
end
braamvandyk commented 3 years ago

Looks great. At the moment I am eyeballs deep in other stuff and hardly touching this.