def initialise_fluids(self): """Fluid initialisation for fluid mixture at outlet of the node.""" num_fl = {} for o in self.outl: num_fl[o] = num_fluids(o.fluid.val) for i in self.inl: num_fl[i] = num_fluids(i.fluid.val) ls = [] if any(num_fl.values()) and not all(num_fl.values()): for conn, num in num_fl.items(): if num == 1: ls += [conn] for c in ls: for fluid in self.nw_fluids: for o in self.outl: if not o.fluid.val_set[fluid]: o.fluid.val[fluid] = c.fluid.val[fluid] for i in self.inl: if not i.fluid.val_set[fluid]: i.fluid.val[fluid] = c.fluid.val[fluid] for o in self.outl: o.target.propagate_fluid_to_target(o, o.target)
def initialise_fluids(self, nw): r""" Fluid initialisation for fluid mixture at outlet of the node. Parameters ---------- nw : tespy.networks.network Network using this component object. """ num_fl = {} for o in self.outl: num_fl[o] = num_fluids(o.fluid.val) for i in self.inl: num_fl[i] = num_fluids(i.fluid.val) ls = [] if any(num_fl.values()) and not all(num_fl.values()): for conn, num in num_fl.items(): if num == 1: ls += [conn] for c in ls: for fluid in nw.fluids: for o in self.outl: if not o.fluid.val_set[fluid]: o.fluid.val[fluid] = c.fluid.val[fluid] for i in self.inl: if not i.fluid.val_set[fluid]: i.fluid.val[fluid] = c.fluid.val[fluid]
def s_mix_ph(flow, T0=300): r""" Calculates the entropy from pressure and enthalpy. Parameters ---------- flow : list Fluid property vector containing mass flow, pressure, enthalpy and fluid composition. Returns ------- s : float Specific entropy s / (J/(kgK)). Note ---- First, check if fluid property has been memorised already. If this is the case, return stored value, otherwise calculate value and store it in the memorisation class. Uses CoolProp interface for pure fluids, newton algorithm for mixtures: .. math:: s_{mix}\left(p,h\right) = s\left(p,T_{mix}(p,h)\right) """ # check if fluid properties have been calculated before fl = tuple(flow[3].keys()) a = memorise.s_ph[fl][:, 0:-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 s = memorise.s_ph[fl][ix, -1][0] memorise.s_ph_f[fl] += [s] return s else: # unknown fluid properties if num_fluids(flow[3]) > 1: # calculate the fluid properties for fluid mixtures val = s_mix_pT(flow, T_mix_ph(flow, T0=T0)) new = np.array([[flow[1], flow[2]] + list(flow[3].values()) + [val]]) # memorise the newly calculated value memorise.s_ph[fl] = np.append(memorise.s_ph[fl], new, axis=0) return val else: # calculate fluid property for pure fluids for fluid, x in flow[3].items(): if x > err: val = s_ph(flow[1], flow[2], fluid) new = np.array([[flow[1], flow[2]] + list(flow[3].values()) + [val]]) # memorise the newly calculated value memorise.s_ph[fl] = np.append(memorise.s_ph[fl], new, axis=0) return val
def T_mix_ps(flow, s, T0=300): r""" Calculates the temperature from pressure and entropy. Parameters ---------- flow : list Fluid property vector containing mass flow, pressure, enthalpy and fluid composition. s : float Entropy of flow in J / (kgK). Returns ------- T : float Temperature T / K. Note ---- First, check if fluid property has been memorised already. If this is the case, return stored value, otherwise calculate value and store it in the memorisation class. Uses CoolProp interface for pure fluids, newton algorithm for mixtures: .. math:: T_{mix}\left(p,s\right) = T_{i}\left(p,s_{i}\right)\; \forall i \in \text{fluid components}\\ s_{i} = s \left(pp_{i}, T_{mix} \right)\\ pp: \text{partial pressure} """ # check if fluid properties have been calculated before fl = tuple(flow[3].keys()) a = memorise.T_ps[fl][:, 0:-1] b = np.array([flow[1], flow[2]] + list(flow[3].values()) + [s]) ix = np.where(np.all(abs(a - b) <= err, axis=1))[0] if ix.size == 1: # known fluid properties T = memorise.T_ps[fl][ix, -1][0] memorise.T_ps_f[fl] += [T] return T else: # unknown fluid properties if num_fluids(flow[3]) > 1: # calculate the fluid properties for fluid mixtures if T0 < 70: T0 = 300 val = newton(s_mix_pT, ds_mix_pdT, flow, s, val0=T0, valmin=70, valmax=3000, imax=10) new = np.array([[flow[1], flow[2]] + list(flow[3].values()) + [s, val]]) # memorise the newly calculated value memorise.T_ps[fl] = np.append(memorise.T_ps[fl], new, axis=0) return val else: # calculate fluid property for pure fluids msg = ('The calculation of temperature from pressure and entropy ' 'for pure fluids should not be required, as the ' 'calculation is always possible from pressure and ' 'enthalpy. If there is a case, where you need to calculate ' 'temperature from these properties, please inform us: ' 'https://github.com/oemof/tespy.') logging.error(msg) raise ValueError(msg)
def T_mix_ph(flow, T0=300): r""" Calculates the temperature from pressure and enthalpy. Parameters ---------- flow : list Fluid property vector containing mass flow, pressure, enthalpy and fluid composition. Returns ------- T : float Temperature T / K. Note ---- First, check if fluid property has been memorised already. If this is the case, return stored value, otherwise calculate value and store it in the memorisation class. Uses CoolProp interface for pure fluids, newton algorithm for mixtures: .. math:: T_{mix}\left(p,h\right) = T_{i}\left(p,h_{i}\right)\; \forall i \in \text{fluid components}\\ h_{i} = h \left(pp_{i}, T_{mix} \right)\\ pp: \text{partial pressure} """ # check if fluid properties have been calculated before fl = tuple(flow[3].keys()) a = memorise.T_ph[fl][:, 0:-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 else: # unknown fluid properties if num_fluids(flow[3]) > 1: # calculate the fluid properties for fluid mixtures if T0 < 70: T0 = 300 val = newton(h_mix_pT, dh_mix_pdT, flow, flow[2], val0=T0, valmin=70, valmax=3000, imax=10) new = np.array([[flow[1], flow[2]] + list(flow[3].values()) + [val]]) # memorise the newly calculated value memorise.T_ph[fl] = np.append(memorise.T_ph[fl], new, axis=0) return val else: # calculate fluid property for pure fluids for fluid, x in flow[3].items(): if x > err: val = T_ph(flow[1], flow[2], fluid) new = np.array([[flow[1], flow[2]] + list(flow[3].values()) + [val]]) # memorise the newly calculated value memorise.T_ph[fl] = np.append(memorise.T_ph[fl], new, axis=0) return val