tespy.components package

tespy.components.component module

Module class component.

All tespy components inherit from this class.

This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/components/components.py

SPDX-License-Identifier: MIT

class tespy.components.component.Component(label, **kwargs)[source]

Bases: object

Class Component is the base class of all TESPy components.

Parameters:
  • label (str) – The label of the component.

  • design (list) – List containing design parameters (stated as String).

  • offdesign (list) – List containing offdesign parameters (stated as String).

  • design_path (str) – Path to the components design case.

  • local_offdesign (boolean) – Treat this component in offdesign mode in a design calculation.

  • local_design (boolean) – Treat this component in design mode in an offdesign calculation.

  • char_warnings (boolean) – Ignore warnings on default characteristics usage for this component.

  • printout (boolean) – Include this component in the network’s results printout.

  • **kwargs – See the class documentation of desired component for available keywords.

Note

The initialisation method (__init__), setter method (set_attr) and getter method (get_attr) are used for instances of class component and its children.

Allowed keywords in kwargs are ‘design_path’, ‘design’ and ‘offdesign’. Additional keywords depend on the type of component you want to create.

Example

Basic example for a setting up a tespy.components.component.Component object. This example does not run a tespy calculation.

>>> from tespy.components.component import Component
>>> comp = Component('myComponent')
>>> type(comp)
<class 'tespy.components.component.Component'>
property all_connections
property all_inlets
property all_outlets
calc_parameters()[source]

Postprocessing parameter calculation.

Each ComponentProperties whose calc attribute is set is called here in topological order (respecting calc_deps dependencies).

Note

Two patterns exist for calc methods, and it is important to keep them distinct:

Pattern A - solver variables only (p, h, m, fluid composition, connection energies E): methods like _calc_P() read only quantities that are unknowns of the solver, therefore these methods can also be used in the residual calculations during iterations.

Pattern B - derived properties (T, v, x, …): methods like _calc_ttd_u or _calc_td_log call helpers such as calc_T() which rely on values that are computed during connection postprocessing (e.g. connection.T.val_SI). These methods must only be called in postprocessing, never during iteration, because the derived values are not yet available.

When adding a new calc method, choose Pattern A if the result depends solely on solver variables; choose Pattern B otherwise, and make sure no caller invokes it during iteration.

check_parameter_bounds()[source]

Check parameter value limits.

collect_results()[source]
convergence_check()[source]
dp_structure_matrix(k, dp=None, inconn=0, outconn=0)[source]

Create linear relationship between inflow and outflow pressure

\[p_{in} - dp = p_{out}\]
Parameters:
  • k (int) – equation number in systems of equations

  • dp (str) – Component parameter, e.g. dp1.

  • inconn (int) – Connection index of inlet.

  • outconn (int) – Connection index of outlet.

entropy_balance()[source]

Entropy balance calculation method.

get_attr(key)[source]

Get the value of a component’s attribute.

Parameters:

key (str) – The attribute you want to retrieve.

Returns:

out – Value of specified attribute.

get_bypass_constraints()[source]
get_char_expr(param, type='rel', inconn=0, outconn=0)[source]

Generic method to access characteristic function parameters.

Parameters:
  • param (str) – Parameter for characteristic function evaluation.

  • type (str) – Type of expression:

    • rel: relative to design value

    • abs: absolute value

  • inconn (int) – Index of inlet connection.

  • outconn (int) – Index of outlet connection.

Returns:

expr (float) – Value of expression

get_mandatory_constraints()[source]
get_parameters()[source]
get_plotting_data()[source]
get_variables()[source]
static heatinlets()[source]
static heatoutlets()[source]
initialise_source(c, key)[source]

Return a starting value for pressure and enthalpy at outlet.

Parameters:
  • c (tespy.connections.connection.Connection) – Connection to perform initialisation on.

  • key (str) – Fluid property to retrieve.

Returns:

val (float) – Starting value for pressure/enthalpy in SI units.

\[\begin{split}val = \begin{cases} 0 & \text{key = 'p'}\\ 0 & \text{key = 'h'} \end{cases}\end{split}\]

initialise_target(c, key)[source]

Return a starting value for pressure and enthalpy at inlet.

Parameters:
  • c (tespy.connections.connection.Connection) – Connection to perform initialisation on.

  • key (str) – Fluid property to retrieve.

Returns:

val (float) – Starting value for pressure/enthalpy in SI units.

\[\begin{split}val = \begin{cases} 0 & \text{key = 'p'}\\ 0 & \text{key = 'h'} \end{cases}\end{split}\]

static inlets()[source]
static outlets()[source]
static powerinlets()[source]
static poweroutlets()[source]
pr_structure_matrix(k, pr=None, inconn=0, outconn=0)[source]

Create linear relationship between inflow and outflow pressure

\[p_{in} \cdot pr = p_{out}\]
Parameters:
  • k (int) – equation number in systems of equations

  • pr (str) – Component parameter, e.g. pr1.

  • inconn (int) – Connection index of inlet.

  • outconn (int) – Connection index of outlet.

propagate_wrapper_to_target(branch)[source]
set_attr(**kwargs)[source]

Set, reset or unset attributes of a component for provided arguments.

Parameters:
  • design (list) – List containing design parameters (stated as String).

  • offdesign (list) – List containing offdesign parameters (stated as String).

  • design_path (str) – Path to the components design case.

  • **kwargs – See the class documentation of desired component for available keywords.

Note

Allowed keywords in kwargs are obtained from class documentation as all components share the tespy.components.component.Component.set_attr() method.

variable_equality_structure_matrix(k, **kwargs)[source]

Create pairwise linear relationship between two variables var for all inlets and the respective outlets. This usually is applied to mass flow, pressure, enthalpy and fluid composition.

\[var_\text{in,i} = var_\text{out,i}\]
Parameters:
  • k (int) – equation number in systems of equations

  • variable (str) – Connection variable name, e.g. h.

zeta_dependents(zeta=None, inconn=0, outconn=0)[source]
zeta_func(zeta=None, inconn=0, outconn=0)[source]

Calculate residual value of \(\zeta\)-function.

Parameters:
  • zeta (str) – Component parameter to evaluate the zeta_func on, e.g. zeta1.

  • inconn (int) – Connection index of inlet.

  • outconn (int) – Connection index of outlet.

Returns:

residual (float) – Residual value of function.

\[\begin{split}0 = \begin{cases} p_{in} - p_{out} & |\dot{m}| < \epsilon \\ \frac{\zeta}{D^4} - \frac{(p_{in} - p_{out}) \cdot \pi^2} {8 \cdot \dot{m}_{in} \cdot |\dot{m}_{in}| \cdot \frac{v_{in} + v_{out}}{2}} & |\dot{m}| > \epsilon \end{cases}\end{split}\]

Note

The zeta value is calculated 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:

\[\frac{\zeta}{D^4} = \frac{\Delta p \cdot \pi^2} {8 \cdot \dot{m}^2 \cdot v}\]
tespy.components.component.component_registry(type)[source]

tespy.components.subsystem module

Module for custom component groups.

It is possible to create subsystems of component groups in tespy. The subsystem class is the base class for custom subsystems.

This file is part of project TESPy (github.com/oemof/tespy). It’s copyrighted by the contributors recorded in the version control history of the file, available from its original location tespy/components/subsystems.py

SPDX-License-Identifier: MIT

class tespy.components.subsystem.Subsystem(label)[source]

Bases: object

Class Subsystem is the base class of all TESPy subsystems.

Parameters:

label (str) – The label of the subsystem.

Example

Basic example for a setting up a Subsystem object. This example does not run a TESPy calculation!

>>> from tespy.components import Subsystem
>>> class MySubsystem(Subsystem):
...     def create_network(self):
...         pass
>>> mysub = MySubsystem('mySubsystem')
>>> type(mysub)
<class 'tespy.components.subsystem.MySubsystem'>
>>> mysub.label
'mySubsystem'
>>> type(mysub.inlet)
<class 'tespy.components.basics.subsystem_interface.SubsystemInterface'>
>>> type(mysub.outlet)
<class 'tespy.components.basics.subsystem_interface.SubsystemInterface'>

If you want to connect to the subsystem from outside of it in a Network, then you have to pass the respective number of inlet and outlet connections. The number is to your choice, but for the Subsystem to be functional, all of the available interfaces must be wired properly internally in the create_network method. For example, consider a subsystem which is just passing its inlet to the outlet:

>>> from tespy.components import Source, Sink
>>> from tespy.connections import Connection
>>> from tespy.networks import Network
>>> class MySubsystem(Subsystem):
...     def __init__(self, label):
...         self.num_in = 1
...         self.num_out = 1
...         super().__init__(label)
...
...     def create_network(self):
...         c1 = Connection(self.inlet, "out1", self.outlet, "in1", label="1")
...         self.add_conns(c1)
>>> mysub = MySubsystem('mySubsystem')
>>> nw = Network()
>>> so = Source("source")
>>> si = Sink("sink")
>>> c1 = Connection(so, "out1", mysub, "in1", label="1")
>>> c2 = Connection(mysub, "out1", si, "in1", label="2")
>>> nw.add_conns(c1, c2)
>>> nw.add_subsystems(mysub)

We can run the check_topology method to check if everything is properly connected and a valid topology was created, without needing to parametrize the system (for the sake of simplicity in this example).

>>> nw.check_topology()

You can retrieve components and connections from inside the subsystem with their label, which is used inside the create_network method of the subsystem.

>>> type(mysub.get_conn("1"))
<class 'tespy.connections.connection.Connection'>
>>> type(mysub.get_comp("inlet"))
<class 'tespy.components.basics.subsystem_interface.SubsystemInterface'>

Their actual label is prefixed with the subsystem’s label, and therefore to get it from the network level, you must use that label:

>>> mysub.get_conn("1").label
'mySubsystem_1'
>>> type(nw.get_conn('mySubsystem_1'))
<class 'tespy.connections.connection.Connection'>

The same is true for components:

>>> mysub.get_comp("inlet").label
'mySubsystem_inlet'
>>> type(nw.get_comp("mySubsystem_inlet"))
<class 'tespy.components.basics.subsystem_interface.SubsystemInterface'>
add_conns(*args)[source]
create_network()[source]

Create the subsystem’s network.

get_comp(label)[source]
get_conn(label)[source]