%load_ext autoreload
%autoreload 2
On 2017-09-20, I'm noticing a problem with the reflux stream class. It comes up with non-monotonic (T,q) curve. I suspect that the property lookups are not well-behaved, that is, they are not monotonic.
from ammonia_props import convert_state_list_to_array, CStateTable
import ammonia1
import system_aqua1
import numpy as np
import matplotlib.pyplot as plt
xC = np.array([0.51284472, 277.97717012, 312.16427764, 313.6952877,
310.24856734, 374.14020482])
ch = system_aqua1.makeChiller(xC)
ch.getRectifierStream()
The error occurs in the vapor phase enthalpy around a temperature of 347 K. Maybe we can zoom in on that. Using functions of (P, T, Qu):
P=ch.gen_vapor_outlet.P
x=ch.gen_vapor_outlet.x
vap, liq = [], []
a_T = np.linspace(346.,348.)
#a_T = np.linspace(300.,400.)
for T in a_T:
vap.append(ammonia1.amm.props2(P=P, T=T, Qu=1))
liq.append(ammonia1.amm.props2(P=P, T=T, Qu=0))
a_vap = convert_state_list_to_array(vap)
a_liq = convert_state_list_to_array(liq)
#display(CStateTable(a_vap))
plt.figure(1)
plt.plot(a_T, a_vap['h'],'.')
plt.figure(2)
plt.plot(a_T, a_liq['h'],'.')
plt.show()
That shows no problems - ie, the curves are monotonic. Perhaps the problem is with the inputs to the property functions. The code uses AmmoniaProps.equilibriumStates2
, which in turn calls props2
first for the vapor properties with inputs (P, x, Qu), and then for the liquid properties with inputs (P, T, Qu).
P=ch.gen_vapor_outlet.P
a_x_wide = np.linspace(0.9, 0.9999)
a_x_narrow = np.linspace(0.990, 0.992)
for a_x in (a_x_wide, a_x_narrow):
vap, liq = [], []
for x in a_x:
vap.append(ammonia1.amm.props2(P=P, x=x, Qu=1))
liq.append(ammonia1.amm.props2(P=P, x=x, Qu=0))
a_vap = convert_state_list_to_array(vap)
a_liq = convert_state_list_to_array(liq)
plt.figure()
plt.plot(a_x, a_vap['h'],'r.')
plt.xlabel("Mass fraction ammonia in vapor (kg/kg)")
plt.ylabel("Enthalpy in vapor (kJ/kg)")
plt.figure()
plt.plot(a_x, a_liq['h'],'b.')
plt.xlabel("Mass fraction ammonia in vapor (kg/kg)")
plt.ylabel("Enthalpy in vapor (kJ/kg)")
plt.show()
display(CStateTable(a_vap))
From what I observe, I would guess that there is a transition between fitting functions that was not smoothed. Another possibility for a discrepancy is that the (P, x, Qu) inputs require an iterative solve with different inputs, but that would not explain this jump. We probably ought to apply some smoothing or use a different set of inputs. Argh.
After making some changes, here is the output for the same test case:
rs = ch.getRectifierStream()
rs
No error means the inerpolation was successfully performed.