def delta_temperature_underwood_callback(b): r""" This is a callback for a temperature difference expression to calculate :math:`\Delta T` in the heat exchanger model using log-mean temperature difference (LMTD) approximation given by Underwood (1970). It can be supplied to "delta_temperature_callback" HeatExchanger configuration option. This uses a cube root function that works with negative numbers returning the real negative root. This should always evaluate successfully. This form is .. math:: \Delta T = \left(\frac{ \Delta T_1^\frac{1}{3} + \Delta T_2^\frac{1}{3}}{2}\right)^3 where :math:`\Delta T_1` is the temperature difference at the hot inlet end and :math:`\Delta T_2` is the temperature difference at the hot outlet end. """ dT1 = b.delta_temperature_in dT2 = b.delta_temperature_out temp_units = pyunits.get_units(dT1[dT1.index_set().first()]) # external function that ruturns the real root, for the cuberoot of negitive # numbers, so it will return without error for positive and negitive dT. b.cbrt = ExternalFunction(library=functions_lib(), function="cbrt", arg_units=[temp_units]) @b.Expression(b.flowsheet().time) def delta_temperature(b, t): return ((b.cbrt(dT1[t]) + b.cbrt(dT2[t])) / 2.0)**3 * temp_units
def test_cbrt_values(): m = pyo.ConcreteModel() flib = functions_lib() m.cbrt = pyo.ExternalFunction(library=flib, function="cbrt") assert (abs(pyo.value(m.cbrt(-27.0)) + 3.0) < 0.00001) assert (abs(pyo.value(m.cbrt(0.0))) < 0.00001) assert (abs(pyo.value(m.cbrt(27.0)) - 3.0) < 0.00001)
def eq_lmtd(b, t): dT_in = b.delta_temperature_in dT_out = b.delta_temperature_out temp_units = pyunits.get_units(dT_in) dT_avg = (dT_in + dT_out) / 2 # external function that ruturns the real root, for the cuberoot of negitive # numbers, so it will return without error for positive and negitive dT. b.cbrt = ExternalFunction(library=functions_lib(), function="cbrt", arg_units=[temp_units**3]) return b.lmtd == b.cbrt((dT_in * dT_out * dT_avg)) * temp_units
def test_cbrt_hes(): m = pyo.ConcreteModel() flib = functions_lib() m.cbrt = pyo.ExternalFunction(library=flib, function="cbrt") h = 1e-6 tol = 1e-5 for v in [-27.0, -0.5, 0.5, 27]: f1, g1, h1 = m.cbrt.evaluate_fgh(args=(v, )) f2, g2, h2 = m.cbrt.evaluate_fgh(args=(v + h, )) hfd = (g2[0] - g1[0]) / h assert (abs(h1[0] - hfd) < tol)
def delta_temperature_underwood_callback(b): """ This is a callback for a temperature difference expression to calculate :math:`\Delta T` in the heat exchanger model using log-mean temperature difference (LMTD) approximation given by Underwood (1970). It can be supplied to "delta_temperature_callback" HeatExchanger configuration option. This uses a cube root function that works with negative numbers returning the real negative root. This should always evaluate successfully. """ # external function that ruturns the real root, for the cuberoot of negitive # numbers, so it will return without error for positive and negitive dT. b.cbrt = ExternalFunction(library=functions_lib(), function="cbrt") dT1 = b.delta_temperature_in dT2 = b.delta_temperature_out @b.Expression(b.flowsheet().config.time) def delta_temperature(b, t): return ((b.cbrt(dT1[t]) + b.cbrt(dT2[t])) / 2.0)**3
def delta_temperature_chen_callback(b): r""" This is a callback for a temperature difference expression to calculate :math:`\Delta T` in the heat exchanger model using log-mean temperature difference (LMTD) approximation given by Chen (1987). It can be supplied to "delta_temperature_callback" HeatExchanger configuration option. This uses a cube root function that works with negative numbers returning the real negative root. This should always evaluate successfully. """ dT1 = b.delta_temperature_in dT2 = b.delta_temperature_out temp_units = pyunits.get_units(dT1) # external function that ruturns the real root, for the cuberoot of negitive # numbers, so it will return without error for positive and negitive dT. b.cbrt = ExternalFunction(library=functions_lib(), function="cbrt", arg_units=[temp_units**3]) @b.Expression(b.flowsheet().time) def delta_temperature(b, t): return b.cbrt(dT1[t] * dT2[t] * 0.5 * (dT1[t] + dT2[t])) * temp_units