Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def comp_init(self, nw):
component.comp_init(self, nw)
self.Tamb.val_SI = ((self.Tamb.val + nw.T[nw.T_unit][0]) *
nw.T[nw.T_unit][1])
# parameters for hydro group
self.hydro_group.set_attr(elements=[self.L, self.ks, self.D])
is_set = self.L.is_set and self.ks.is_set and self.D.is_set
if is_set:
self.hydro_group.set_attr(is_set=True)
if self.hydro_group.method == 'HW':
method = 'Hazen-Williams equation'
else:
method = 'darcy friction factor'
msg = (
def comp_init(self, nw):
if not self.P.is_set:
self.set_attr(P='var')
msg = ('The power output of cogeneration units must be set! '
'We are adding the power output of component ' +
self.label + ' as custom variable of the system.')
logging.info(msg)
component.comp_init(self, nw)
o2 = [x for x in nw.fluids if x in [
a.replace(' ', '') for a in CP.get_aliases('O2')]]
if len(o2) == 0:
msg = ('Missing oxygen in network fluids, component ' +
self.label + ' of type ' + self.component() +
' requires oxygen in network fluids.')
logging.error(msg)
raise TESPyComponentError(msg)
else:
self.o2 = o2[0]
h2o = [x for x in nw.fluids if x in [
a.replace(' ', '') for a in CP.get_aliases('H2O')]]
if len(h2o) == 0:
msg = ('Missing water in network fluids, component ' +
def comp_init(self, nw):
component.comp_init(self, nw)
# number of mandatroy equations for
# pressure: 1
# enthalpy: 1
self.num_eq = 2
self.jacobian = np.zeros((
self.num_eq,
self.num_i + self.num_o + self.num_vars,
self.num_nw_vars))
self.residual = np.ones(self.num_eq)
# derivatives for pressure
self.jacobian[0, 0, 1] = 1
self.jacobian[0, 1, 1] = -1
# derivatives for enthalpy
def comp_init(self, nw):
component.comp_init(self, nw)
# number of mandatroy equations for
# fluid balance: num_fl
# mass flow: 1
self.num_eq = self.num_nw_fluids + 1
for var in [self.P, self.pr]:
if var.is_set is True:
self.num_eq += 1
self.jacobian = np.zeros((
self.num_eq,
self.num_i + self.num_o + self.num_vars,
self.num_nw_vars))
self.residual = np.zeros(self.num_eq)
pos = self.num_nw_fluids
def comp_init(self, nw):
component.comp_init(self, nw)
# number of mandatroy equations for
# fluid: num_inter * num_nw_fluids
# mass flow: num_inter
# pressure: num_inter
# enthalpy: num_inter
self.num_eq = (self.num_nw_fluids + 3) * self.num_i
self.jacobian = np.zeros((
self.num_eq,
2 * self.num_i,
self.num_nw_vars))
self.residual = np.ones(self.num_eq)
stop = self.num_nw_fluids * self.num_i
self.jacobian[0:stop] = self.fluid_deriv()
def comp_init(self, nw):
component.comp_init(self, nw)
# number of mandatroy equations for
# fluid balance: num_fl * 2
# mass flow: 2
# energy balance: 1
self.num_eq = self.num_nw_fluids * 2 + 3
# enthalpy hot side outlet (if not subcooling): 1
if self.subcooling.val is False:
self.num_eq += 1
for var in [self.Q, self.kA, self.kA_char, self.ttd_u, self.ttd_l,
self.pr1, self.pr2, self.zeta1, self.zeta2]:
if var.is_set is True:
self.num_eq += 1
if self.kA.is_set:
msg = (
def comp_init(self, nw):
component.comp_init(self, nw)
self.Tamb.val_SI = ((self.Tamb.val + nw.T[nw.T_unit][0]) *
nw.T[nw.T_unit][1])
# parameters for hydro group
self.hydro_group.set_attr(elements=[self.L, self.ks, self.D])
is_set = True
for e in self.hydro_group.elements:
if e.is_set is False:
is_set = False
if is_set is True:
self.hydro_group.set_attr(is_set=True)
elif self.hydro_group.is_set is True:
msg = (
def comp_init(self, nw):
component.comp_init(self, nw)
# number of mandatroy equations for
# mass flow: 1
# pressure: number of inlets + number of outlets - 1
# fluid: number of outlets * number of fluid_set
# enthalpy: number of outlets
self.num_eq = self.num_i + self.num_o * (2 + self.num_nw_fluids)
self.jacobian = np.zeros((
self.num_eq,
self.num_i + self.num_o + self.num_vars,
self.num_nw_vars))
self.residual = np.zeros(self.num_eq)
self.jacobian[0:1] = self.mass_flow_deriv()
def comp_init(self, nw):
component.comp_init(self, nw)
# number of mandatroy equations for
# mass flow: 1
# pressure: number of inlets + number of outlets - 1
# the number of fluid and enthalpy equations is variable for a node!
self.num_eq = 1 + self.num_i + self.num_o - 1
# number of fluid equations
self.num_eq += self.num_nw_fluids * self.num_o
# number of enthalpy equations
self.num_eq += self.num_o
self.jacobian = np.zeros((
self.num_eq,
self.num_i + self.num_o + self.num_vars,
def comp_init(self, nw):
component.comp_init(self, nw)
# number of mandatroy equations for
# fluid balance: num_fl
# mass flow: 1
# enthalpy: 1
self.num_eq = self.num_nw_fluids + 2
for var in [self.pr, self.zeta, self.dp_char]:
if var.is_set is True:
self.num_eq += 1
self.jacobian = np.zeros((
self.num_eq,
self.num_i + self.num_o + self.num_vars,
self.num_nw_vars))
self.residual = np.zeros(self.num_eq)