Skip to content

Commit f7623f9

Browse files
committed
implicit AD test for tp_flash
1 parent b5d003b commit f7623f9

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/test_methods_api_flash.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,30 @@
262262
[0.3618699698927814 0.6381300301072186;
263263
0.17888243310648602 0.821117566893514] rtol = 1e-6
264264
end
265+
266+
@testset "Michelsen Algorithm in Implicit AD" begin
267+
admodel = cPR(["ethane","propane"])
268+
function dflash(t)
269+
T = 200*t
270+
res = Clapeyron.tp_flash2(admodel,1e5,T,[0.5,0.5])
271+
return res.volumes[2]
272+
end
273+
#=
274+
275+
julia> Clapeyron.tp_flash2(admodel,1e5,200.0,[0.5,0.5])
276+
Flash result at T = 200.0, p = 100000.0 with 2 phases:
277+
(x = [0.407352, 0.592648], β = 0.799439, v = 6.10901e-5)
278+
(x = [0.869296, 0.130704], β = 0.200561, v = 0.0161798)
279+
280+
julia> Clapeyron.tp_flash2(admodel,1e5,300.0,[0.5,0.5])
281+
Flash result at T = 300.0, p = 100000.0 with 2 phases:
282+
(x = [0.5, 0.5], β = 0.0, v = 0.0246478)
283+
(x = [0.5, 0.5], β = 1.0, v = 0.0246478)
284+
=#
285+
286+
@test Clapeyron.Solvers.derivative(dflash,1.0) Clapeyron.derivx(dflash,1.0) rtol = 1e-5
287+
@test Clapeyron.Solvers.derivative(dflash,1.5) Clapeyron.derivx(dflash,1.5) rtol = 1e-5
288+
end
265289
end
266290

267291
@testset "XY flash" begin
@@ -604,6 +628,12 @@ end
604628
cpr = cPR("Propane",idealmodel = ReidIdeal)
605629
crit_cpr = crit_pure(cpr)
606630
@test saturation_temperature(cpr,crit_cpr[2] - 1e3)[1] 369.88681908031606 rtol = 1e-6
631+
632+
#implicit AD
633+
dsatp(T) = first(saturation_pressure(cpr,250.0*T))
634+
dsatt(p) = first(saturation_temperature(cpr,1e5*p))
635+
@test Clapeyron.Solvers.derivative(dsatp,1.0) Clapeyron.derivx(dsatp,1.0) rtol = 1e-6
636+
@test Clapeyron.Solvers.derivative(dsatt,1.0) Clapeyron.derivx(dsatt,1.0) rtol = 1e-6
607637
end
608638

609639
@testset "Tproperty/Property" begin
@@ -815,7 +845,6 @@ end
815845
@test Clapeyron.Solvers.derivative(dp,1.0) Clapeyron.derivx(dp,1.0) rtol = 1e-5
816846
@test Clapeyron.Solvers.derivative(bt,1.0) Clapeyron.derivx(bt,1.0) rtol = 1e-5
817847
@test Clapeyron.Solvers.derivative(dt,1.0) Clapeyron.derivx(dt,1.0) rtol = 1e-5
818-
819848
end
820849

821850
end

0 commit comments

Comments
 (0)