Skip to content

Commit

Permalink
Fix a couple of bus derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Sep 10, 2023
1 parent 28d39a8 commit d76088b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 48 deletions.
16 changes: 10 additions & 6 deletions src/tespy/components/combustion/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,17 @@ def bus_deriv(self, bus):
deriv : ndarray
Matrix of partial derivatives.
"""
deriv = np.zeros((1, 3, self.num_nw_vars))
f = self.calc_bus_value
for i in range(3):
deriv[0, i, 0] = self.numeric_deriv(f, 'm', i, bus=bus)
deriv[0, i, 3:] = self.numeric_deriv(f, 'fluid', i, bus=bus)

return deriv
for c in self.inl + self.outl:
if c.m.is_var:
if c.m.J_col not in bus.jacobian:
bus.jacobian[c.m.J_col] = 0
bus.jacobian[c.m.J_col] = -self.numeric_deriv(f, 'm', c, bus=bus)

for fluid in c.fluid.is_var:
if c.fluid.J_col[fluid] not in bus.jacobian:
bus.jacobian[c.fluid.J_col[fluid]] = 0
bus.jacobian[c.fluid.J_col[fluid]] = -self.numeric_deriv(f, fluid, c, bus=bus)

def initialise_fluids(self):
"""Calculate reaction balance for generic starting values at outlet."""
Expand Down
32 changes: 0 additions & 32 deletions src/tespy/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,38 +620,6 @@ def bus_func(self, bus):
"""
return 0

def bus_func_doc(self, bus):
r"""
Base method for LaTeX equation generation of the bus function.
Parameters
----------
bus : tespy.connections.bus.Bus
TESPy bus object.
Returns
-------
latex : str
Bus function in LaTeX format.
"""
return None

def bus_deriv(self, bus):
r"""
Base method for partial derivatives of the bus function.
Parameters
----------
bus : tespy.connections.bus.Bus
TESPy bus object.
Returns
-------
deriv : ndarray
Matrix of partial derivatives.
"""
return np.zeros((1, self.num_i + self.num_o, self.num_nw_vars))

def calc_bus_expr(self, bus):
r"""
Return the busses' characteristic line input expression.
Expand Down
19 changes: 14 additions & 5 deletions src/tespy/components/heat_exchangers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,12 +734,21 @@ def bus_deriv(self, bus):
deriv : ndarray
Matrix of partial derivatives.
"""
deriv = np.zeros((1, 4, self.num_nw_vars))
f = self.calc_bus_value
deriv[0, 0, 0] = self.numeric_deriv(f, 'm', 0, bus=bus)
deriv[0, 0, 2] = self.numeric_deriv(f, 'h', 0, bus=bus)
deriv[0, 2, 2] = self.numeric_deriv(f, 'h', 2, bus=bus)
return deriv
if self.inl[0].m.is_var:
if self.inl[0].m.J_col not in bus.jacobian:
bus.jacobian[self.inl[0].m.J_col] = 0
bus.jacobian[self.inl[0].m.J_col] -= self.numeric_deriv(f, 'm', self.inl[0], bus=bus)

if self.inl[0].h.is_var:
if self.inl[0].h.J_col not in bus.jacobian:
bus.jacobian[self.inl[0].h.J_col] = 0
bus.jacobian[self.inl[0].h.J_col] -= self.numeric_deriv(f, 'h', self.inl[0], bus=bus)

if self.outl[0].h.is_var:
if self.outl[0].h.J_col not in bus.jacobian:
bus.jacobian[self.outl[0].h.J_col] = 0
bus.jacobian[self.outl[0].h.J_col] -= self.numeric_deriv(f, 'h', self.outl[0], bus=bus)

def initialise_source(self, c, key):
r"""
Expand Down
19 changes: 14 additions & 5 deletions src/tespy/components/heat_exchangers/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,12 +794,21 @@ def bus_deriv(self, bus):
deriv : ndarray
Matrix of partial derivatives.
"""
deriv = np.zeros((1, 2, self.num_nw_vars))
f = self.calc_bus_value
deriv[0, 0, 0] = self.numeric_deriv(f, 'm', 0, bus=bus)
deriv[0, 0, 2] = self.numeric_deriv(f, 'h', 0, bus=bus)
deriv[0, 1, 2] = self.numeric_deriv(f, 'h', 1, bus=bus)
return deriv
if self.inl[0].m.is_var:
if self.inl[0].m.J_col not in bus.jacobian:
bus.jacobian[self.inl[0].m.J_col] = 0
bus.jacobian[self.inl[0].m.J_col] -= self.numeric_deriv(f, 'm', self.inl[0], bus=bus)

if self.inl[0].h.is_var:
if self.inl[0].h.J_col not in bus.jacobian:
bus.jacobian[self.inl[0].h.J_col] = 0
bus.jacobian[self.inl[0].h.J_col] -= self.numeric_deriv(f, 'h', self.inl[0], bus=bus)

if self.outl[0].h.is_var:
if self.outl[0].h.J_col not in bus.jacobian:
bus.jacobian[self.outl[0].h.J_col] = 0
bus.jacobian[self.outl[0].h.J_col] -= self.numeric_deriv(f, 'h', self.outl[0], bus=bus)

def initialise_source(self, c, key):
r"""
Expand Down

0 comments on commit d76088b

Please sign in to comment.