33# Copyright Hugo Vale 2024
44
55import numpy as np
6+ import pytest
67from numpy import allclose , isclose
78from scipy .constants import gas_constant as R
89
1617 Wilson ,
1718)
1819from polykin .thermo .acm .base import SmallSpeciesActivityModel
20+ from polykin .utils .exceptions import ShapeError
1921
2022
2123def check_gE_gamma (acm : SmallSpeciesActivityModel , x , T = 298 ):
@@ -30,6 +32,8 @@ def test_IdealSolution():
3032 T = 298.0
3133 x = np .array ([0.5 , 0.5 ])
3234 assert isclose (acm .gE (T , x ), 0.0 )
35+ assert isclose (acm .hE (T , x ), 0.0 )
36+ assert isclose (acm .sE (T , x ), 0.0 )
3337 assert allclose (acm .gamma (T , x ), [1.0 , 1.0 ])
3438
3539
@@ -49,6 +53,12 @@ def test_NRTL():
4953 assert allclose (acm .gamma (T , np .array ([1.0 , 0.0 ])), [1.0 , 4.557085 ], rtol = 1e-6 )
5054 assert isclose (acm .Dgmix (T , np .array ([0.5 , 0.5 ])), - 0.98183e3 , rtol = 1e-4 )
5155 assert check_gE_gamma (acm , np .array ([0.3 , 0.7 ]))
56+ # trivial case: ideal solution
57+ acm = NRTL (2 , name = "ideal" )
58+ assert isclose (acm .gE (T , x = np .array ([0.4 , 0.6 ])), 0.0 )
59+ # invalid shape
60+ with pytest .raises (ShapeError ):
61+ _ = NRTL (2 , a = np .zeros ((2 , 3 )), b = np .zeros ((2 , 2 )))
5262
5363
5464def test_UNIQUAC ():
@@ -61,6 +71,11 @@ def test_UNIQUAC():
6171 T = 45 + 273.15
6272 assert allclose (acm .gamma (T , x ), [7.15 , 1.25 , 1.06 ], rtol = 2e-3 )
6373 assert check_gE_gamma (acm , x )
74+ # invalid shape
75+ with pytest .raises (ShapeError ):
76+ _ = UNIQUAC (N , q , r [0 :2 ])
77+ with pytest .raises (ShapeError ):
78+ _ = UNIQUAC (3 , q , r , a = np .zeros ((2 , 3 )))
6479
6580
6681def test_UNIQUAC_2 ():
@@ -159,3 +174,9 @@ def test_Wilson():
159174 assert allclose (acm .gamma (T , np .array ([1.0 , 0.0 ])), [1.0 , 4.90196 ], rtol = 1e-6 )
160175 assert isclose (acm .Dgmix (T , np .array ([0.5 , 0.5 ])), - 0.983275e3 , rtol = 1e-4 )
161176 assert check_gE_gamma (acm , x = np .array ([0.4 , 0.6 ]))
177+ # trivial case: ideal solution
178+ acm = Wilson (N , name = "ideal" )
179+ assert isclose (acm .gE (T , x = np .array ([0.4 , 0.6 ])), 0.0 )
180+ # invalid shape
181+ with pytest .raises (ShapeError ):
182+ _ = Wilson (2 , a = np .zeros ((2 , 3 )), b = np .zeros ((2 , 2 )))
0 commit comments