Skip to content

Commit

Permalink
Merge 9582cae into 262f2e2
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Feb 13, 2020
2 parents 262f2e2 + 9582cae commit d77f2a2
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 178 deletions.
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ Examples
For a short introduction on how TESPy works and how you can use it, we provide
some
`examples and tutorials <http://tespy.readthedocs.io/en/latest/getting_started.html>`_,
go and check them out. You can download the python scripts of all example plants from
the `tespy_examples <https://github.com/oemof/oemof-examples/tree/master/oemof_examples/tespy>`_
go and check them out. You can download the python scripts of all example plants
from the
`tespy_examples <https://github.com/oemof/oemof-examples/tree/master/oemof_examples/tespy>`_
repository.

License
Expand Down
12 changes: 12 additions & 0 deletions doc/whats_new/v0-2-2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,25 @@ Parameter renaming

Testing
#######
- Add convergence checks for all component tests. Some tests did not fail, even
if the calculation did not converge
(`PR #153 <https://github.com/oemof/tespy/pull/153>`_).
- Improve coverage of the networks module
(`PR #153 <https://github.com/oemof/tespy/pull/153>`_).

Bug fixes
#########

Other changes
#############
- Use the method :py:meth:`tespy.components.components.component.fluid_deriv`
for all components, that do not change composition between an inlet and the
respective outlet (`PR #153 <https://github.com/oemof/tespy/pull/153>`_).
- Adjust the method :py:meth:`tespy.components.components.component.zeta_func`
to work with all zeta value specifications
(`PR #153 <https://github.com/oemof/tespy/pull/153>`_).

Contributors
############

- Francesco Witte (@fwitte)
20 changes: 1 addition & 19 deletions tespy/components/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,24 +494,6 @@ def derivatives(self, vek_z):
######################################################################
# all derivatives are static

def fluid_deriv(self):
r"""
Calculate the partial derivatives for all fluid balance equations.
Returns
-------
deriv : list
Matrix with partial derivatives for the fluid equations.
"""
deriv = np.zeros((self.num_nw_fluids * self.num_i,
2 * self.num_i,
self.num_nw_vars))
for i in range(self.num_i):
for j in range(self.num_nw_fluids):
deriv[i * self.num_nw_fluids + j, i, j + 3] = 1
deriv[i * self.num_nw_fluids + j, self.num_i + i, j + 3] = -1
return deriv.tolist()

def inout_deriv(self, pos):
r"""
Calculate partial derivatives.
Expand All @@ -534,4 +516,4 @@ def inout_deriv(self, pos):
deriv[i, i, pos] = 1
for j in range(self.num_i):
deriv[j, j + self.num_i, pos] = -1
return deriv.tolist()
return deriv
44 changes: 27 additions & 17 deletions tespy/components/combustion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,8 +2040,8 @@ class combustion_engine(combustion_chamber):
0 = p_{1,in} \cdot pr1 - p_{1,out}\\
0 = p_{2,in} \cdot pr2 - p_{2,out}
- :func:`tespy.components.components.component.zeta_func`
- :func:`tespy.components.components.component.zeta2_func`
- loop 1 :func:`tespy.components.components.component.zeta_func`
- loop 2 :func:`tespy.components.components.component.zeta_func`
Available fuels
Expand Down Expand Up @@ -2116,11 +2116,11 @@ class combustion_engine(combustion_chamber):
Pressure ratio heat outlet 2, :math:`pr/1`.
zeta1 : str/float/tespy.helpers.dc_cp
Pressure ratio heat outlet 2,
Geometry independent friction coefficient heating loop 1,
:math:`\zeta/\frac{1}{\text{m}^4}`.
zeta2 : str/float/tespy.helpers.dc_cp
Pressure ratio heat outlet 2,
Geometry independent friction coefficient heating loop 2,
:math:`\zeta/\frac{1}{\text{m}^4}`.
tiP_char : str/tespy.helpers.dc_cc
Expand Down Expand Up @@ -2391,12 +2391,12 @@ def equations(self):
# equations for specified zeta values at cooling loops
if self.zeta1.is_set:
if np.absolute(self.vec_res[k]) > err ** 2 or self.it % 4 == 0:
self.vec_res[k] = self.zeta_func()
self.vec_res[k] = self.zeta_func(zeta='zeta1', conn=0)
k += 1

if self.zeta2.is_set:
if np.absolute(self.vec_res[k]) > err ** 2 or self.it % 4 == 0:
self.vec_res[k] = self.zeta2_func()
self.vec_res[k] = self.zeta_func(zeta='zeta2', conn=1)
k += 1

def derivatives(self, vec_z):
Expand Down Expand Up @@ -2601,29 +2601,39 @@ def derivatives(self, vec_z):
if self.zeta1.is_set:
f = self.zeta_func
if not vec_z[0, 0]:
self.mat_deriv[k, 0, 0] = self.numeric_deriv(f, 'm', 0)
self.mat_deriv[k, 0, 0] = self.numeric_deriv(
f, 'm', 0, zeta='zeta1', conn=0)
if not vec_z[0, 1]:
self.mat_deriv[k, 0, 1] = self.numeric_deriv(f, 'p', 0)
self.mat_deriv[k, 0, 1] = self.numeric_deriv(
f, 'p', 0, zeta='zeta1', conn=0)
if not vec_z[0, 2]:
self.mat_deriv[k, 0, 2] = self.numeric_deriv(f, 'h', 0)
self.mat_deriv[k, 0, 2] = self.numeric_deriv(
f, 'h', 0, zeta='zeta1', conn=0)
if not vec_z[4, 1]:
self.mat_deriv[k, 4, 1] = self.numeric_deriv(f, 'p', 4)
self.mat_deriv[k, 4, 1] = self.numeric_deriv(
f, 'p', 4, zeta='zeta1', conn=0)
if not vec_z[4, 2]:
self.mat_deriv[k, 4, 2] = self.numeric_deriv(f, 'h', 4)
self.mat_deriv[k, 4, 2] = self.numeric_deriv(
f, 'h', 4, zeta='zeta1', conn=0)
k += 1

if self.zeta2.is_set:
f = self.zeta2_func
f = self.zeta_func
if not vec_z[1, 0]:
self.mat_deriv[k, 1, 0] = self.numeric_deriv(f, 'm', 1)
self.mat_deriv[k, 1, 0] = self.numeric_deriv(
f, 'm', 1, zeta='zeta2', conn=1)
if not vec_z[1, 1]:
self.mat_deriv[k, 1, 1] = self.numeric_deriv(f, 'p', 1)
self.mat_deriv[k, 1, 1] = self.numeric_deriv(
f, 'p', 1, zeta='zeta2', conn=1)
if not vec_z[1, 2]:
self.mat_deriv[k, 1, 2] = self.numeric_deriv(f, 'h', 1)
self.mat_deriv[k, 1, 2] = self.numeric_deriv(
f, 'h', 1, zeta='zeta2', conn=1)
if not vec_z[5, 1]:
self.mat_deriv[k, 5, 1] = self.numeric_deriv(f, 'p', 5)
self.mat_deriv[k, 5, 1] = self.numeric_deriv(
f, 'p', 5, zeta='zeta2', conn=1)
if not vec_z[5, 2]:
self.mat_deriv[k, 5, 2] = self.numeric_deriv(f, 'h', 5)
self.mat_deriv[k, 5, 2] = self.numeric_deriv(
f, 'h', 5, zeta='zeta2', conn=1)
k += 1

def fluid_func(self):
Expand Down
83 changes: 25 additions & 58 deletions tespy/components/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,13 @@ def fluid_deriv(self):
deriv : list
Matrix with partial derivatives for the fluid equations.
"""
deriv = np.zeros((self.num_nw_fluids,
2 + self.num_vars,
deriv = np.zeros((self.num_nw_fluids * self.num_i,
2 * self.num_i + self.num_vars,
self.num_nw_vars))
i = 0
for fluid in self.nw_fluids:
deriv[i, 0, i + 3] = 1
deriv[i, 1, i + 3] = -1
i += 1
for i in range(self.num_i):
for j in range(self.num_nw_fluids):
deriv[i * self.num_nw_fluids + j, i, j + 3] = 1
deriv[i * self.num_nw_fluids + j, self.num_i + i, j + 3] = -1
return deriv

# %%
Expand Down Expand Up @@ -651,10 +650,22 @@ def numeric_deriv(self, func, dx, pos, **kwargs):

# %%

def zeta_func(self):
def zeta_func(self, zeta='', conn=0):
r"""
Calculate residual value of :math:`\zeta`-function.
Parameters
----------
zeta : str
Component parameter to evaluate the zeta_func on, e. g.
:code:`zeta1`.
conn : int
Connection number of inlet and corresponding outlet.
In order to use the zeta function, the index of the inlet and
the corresponding outlet within the components :code:`ìnl` and
:code:`outl` respectively must be identical!
Returns
-------
val : float
Expand All @@ -681,59 +692,15 @@ def zeta_func(self):
\frac{\zeta}{D^4} = \frac{\Delta p \cdot \pi^2}
{8 \cdot \dot{m}^2 \cdot v}
"""
i = self.inl[0].to_flow()
o = self.outl[0].to_flow()
if hasattr(self, 'zeta'):
val = self.zeta.val
else:
val = self.zeta1.val
zeta = self.get_attr(zeta).val
i = self.inl[conn].to_flow()
o = self.outl[conn].to_flow()

if abs(i[0]) < 1e-4:
return i[1] - o[1]

else:
v_i = v_mix_ph(i, T0=self.inl[0].T.val_SI)
v_o = v_mix_ph(o, T0=self.outl[0].T.val_SI)
return (val - (i[1] - o[1]) * np.pi ** 2 /
(8 * abs(i[0]) * i[0] * (v_i + v_o) / 2))

def zeta2_func(self):
r"""
Calculate residual value of :math:`\zeta_2`-function.
Returns
-------
val : float
Residual value of function.
.. math::
val = \begin{cases}
p_{in} - p_{out} & |\dot{m}| < \epsilon \\
\frac{\zeta_2}{D^4} - \frac{(p_{2,in} - p_{2,out}) \cdot \pi^2}
{8 \cdot \dot{m}_{2,in} \cdot |\dot{m}_{2,in}| \cdot
\frac{v_{2,in} + v_{2,out}}{2}} &
|\dot{m}| > \epsilon
\end{cases}
Note
----
The zeta value is caluclated on the basis of a given pressure loss at
a given flow rate in the design case. As the cross sectional area A
will not change, it is possible to handle the equation in this way:
.. math::
\frac{\zeta_2}{D^4} = \frac{\Delta p_2 \cdot \pi^2}
{8 \cdot \dot{m}_2^2 \cdot v}
"""
i = self.inl[1].to_flow()
o = self.outl[1].to_flow()

if abs(i[0]) < 1e-4:
return i[1] - o[1]
else:
v_i = v_mix_ph(i, T0=self.inl[1].T.val_SI)
v_o = v_mix_ph(o, T0=self.outl[1].T.val_SI)
return (self.zeta2.val - (i[1] - o[1]) * np.pi ** 2 /
v_i = v_mix_ph(i, T0=self.inl[conn].T.val_SI)
v_o = v_mix_ph(o, T0=self.outl[conn].T.val_SI)
return (zeta - (i[1] - o[1]) * np.pi ** 2 /
(8 * abs(i[0]) * i[0] * (v_i + v_o) / 2))

0 comments on commit d77f2a2

Please sign in to comment.