Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
# check if fluid properties have been calculated before
fl = tuple(flow[3].keys())
memorisation = fl in memorise.s_ph.keys()
if memorisation is True:
a = memorise.s_ph[fl][:, :-1]
b = np.asarray([flow[1], flow[2]] + list(flow[3].values()))
ix = np.where(np.all(abs(a - b) <= err, axis=1))[0]
if ix.size == 1:
# known fluid properties
s = memorise.s_ph[fl][ix, -1][0]
memorise.s_ph_f[fl] += [s]
return s
# unknown fluid properties
fluid = single_fluid(flow[3])
if fluid is None:
# calculate the fluid properties for fluid mixtures
val = s_mix_pT(flow, T_mix_ph(flow, T0=T0))
else:
# calculate fluid property for pure fluids
val = s_ph(flow[1], flow[2], fluid)
if memorisation is True:
# memorise the newly calculated value
new = np.asarray([[flow[1], flow[2]] + list(flow[3].values()) + [val]])
memorise.s_ph[fl] = np.append(memorise.s_ph[fl], new, axis=0)
return val
Fluid property vector containing mass flow, pressure, enthalpy and
fluid composition.
Q : float
Vapour mass fraction Q / 1.
Returns
-------
h : float
Specific enthalpy h / (J/kg).
Note
----
This function works for pure fluids only!
"""
fluid = single_fluid(flow[3])
if fluid is None:
msg = 'The function h_mix_pQ can only be used for pure fluids.'
logging.error(msg)
raise ValueError(msg)
try:
memorise.state[fluid].update(CP.PQ_INPUTS, flow[1], Q)
except ValueError:
pcrit = memorise.state[fluid].trivial_keyed_output(CP.iP_critical)
memorise.state[fluid].update(CP.PQ_INPUTS, pcrit * 0.99, Q)
return memorise.state[fluid].hmass()
def solve_check_props(self, c):
r"""
Check for invalid fluid property values.
Parameters
----------
c : tespy.connections.connection
Connection to check fluid properties.
"""
fl = hlp.single_fluid(c.fluid.val)
if fl is not None:
# pressure
if c.p.val_SI < fp.memorise.value_range[fl][0] and not c.p.val_set:
c.p.val_SI = fp.memorise.value_range[fl][0]
logging.debug(self.property_range_message(c, 'p'))
if c.p.val_SI > fp.memorise.value_range[fl][1] and not c.p.val_set:
c.p.val_SI = fp.memorise.value_range[fl][1]
logging.debug(self.property_range_message(c, 'p'))
# enthalpy
try:
hmin = fp.h_pT(
c.p.val_SI, fp.memorise.value_range[fl][2] * 1.001, fl)
except ValueError:
f = 1.05
if self.mode == 'design':
b.comps.loc[cp].P_ref = (
cp.bus_func(b.comps.loc[cp]) /
abs(b.comps.loc[cp].char.evaluate(1)))
b.P.val += val
# connections
for c in self.conns.index:
c.T.val_SI = fp.T_mix_ph(c.to_flow(), T0=c.T.val_SI)
c.v.val_SI = fp.v_mix_ph(c.to_flow(), T0=c.T.val_SI) * c.m.val_SI
c.T.val = (c.T.val_SI / self.T[c.T.unit][1] - self.T[c.T.unit][0])
c.m.val = c.m.val_SI / self.m[c.m.unit]
c.p.val = c.p.val_SI / self.p[c.p.unit]
c.h.val = c.h.val_SI / self.h[c.h.unit]
c.v.val = c.v.val_SI / self.v[c.v.unit]
fluid = hlp.single_fluid(c.fluid.val)
if isinstance(fluid, str) and not c.x.val_set:
c.x.val_SI = fp.Q_ph(c.p.val_SI, c.h.val_SI, fluid)
c.x.val = c.x.val_SI
c.T.val0 = c.T.val
c.m.val0 = c.m.val
c.p.val0 = c.p.val
c.h.val0 = c.h.val
c.fluid.val0 = c.fluid.val.copy()
msg = 'Postprocessing complete.'
logging.info(msg)
"""
# check if fluid properties have been calculated before
fl = tuple(flow[3].keys())
memorisation = fl in memorise.v_ph.keys()
if memorisation is True:
a = memorise.v_ph[fl][:, :-1]
b = np.asarray([flow[1], flow[2]] + list(flow[3].values()))
ix = np.where(np.all(abs(a - b) <= err, axis=1))[0]
if ix.size == 1:
# known fluid properties
v = memorise.v_ph[fl][ix, -1][0]
memorise.v_ph_f[fl] += [v]
return v
# unknown fluid properties
fluid = single_fluid(flow[3])
if fluid is None:
# calculate the fluid properties for fluid mixtures
val = v_mix_pT(flow, T_mix_ph(flow, T0=T0))
else:
# calculate fluid property for pure fluids
val = 1 / d_ph(flow[1], flow[2], fluid)
if memorisation is True:
# memorise the newly calculated value
new = np.asarray([[flow[1], flow[2]] + list(flow[3].values()) + [val]])
memorise.v_ph[fl] = np.append(memorise.v_ph[fl], new, axis=0)
return val
# check if fluid properties have been calculated before
fl = tuple(flow[3].keys())
memorisation = fl in memorise.T_ph.keys()
if memorisation is True:
a = memorise.T_ph[fl][:, :-1]
b = np.array([flow[1], flow[2]] + list(flow[3].values()))
ix = np.where(np.all(abs(a - b) <= err, axis=1))[0]
if ix.size == 1:
# known fluid properties
T = memorise.T_ph[fl][ix, -1][0]
memorise.T_ph_f[fl] += [T]
return T
# unknown fluid properties
fluid = single_fluid(flow[3])
if fluid is None:
# calculate the fluid properties for fluid mixtures
if memorisation is True:
valmin = max(
[memorise.value_range[f][2] for f in fl if flow[3][f] > err]
) + 0.1
if T0 < valmin or np.isnan(T0):
T0 = valmin * 1.1
else:
valmin = 70
val = newton(h_mix_pT, dh_mix_pdT, flow, flow[2], val0=T0,
valmin=valmin, valmax=3000, imax=10)
else:
# calculate fluid property for pure fluids
val = T_ph(flow[1], flow[2], fluid)