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:
objectClass 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.Componentobject. This example does not run a tespy calculation.>>> from tespy.components.component import Component >>> comp = Component('myComponent') >>> type(comp) <class 'tespy.components.component.Component'>
- bus_func(bus)[source]¶
Base method for calculation of the value of the bus function.
- Parameters:
bus (tespy.connections.bus.Bus) – TESPy bus object.
- Returns:
residual (float) – Residual value of bus equation.
- calc_bus_efficiency(bus)[source]¶
Return the busses’ efficiency.
- Parameters:
bus (tespy.connections.bus.Bus) – Bus to calculate the efficiency value on.
- Returns:
efficiency (float) – Efficiency value of the bus.
\[\begin{split}\eta_\mathrm{bus} = \begin{cases} \eta\left( \frac{\dot{E}_\mathrm{bus}}{\dot{E}_\mathrm{bus,ref}}\right) & \text{bus base = 'bus'}\\ \eta\left( \frac{\dot{E}_\mathrm{component}} {\dot{E}_\mathrm{component,ref}}\right) & \text{bus base = 'component'} \end{cases}\end{split}\]
Note
If the base value of the bus is the bus value itself, a newton iteration is used to find the bus value satisfying the corresponding equation (case 1).
- calc_bus_expr(bus)[source]¶
Return the busses’ characteristic line input expression.
- Parameters:
bus (tespy.connections.bus.Bus) – Bus to calculate the characteristic function expression for.
- Returns:
expr (float) – Ratio of power to power design depending on the bus base specification.
- calc_bus_value(bus)[source]¶
Return the busses’ value of the component’s energy transfer.
- Parameters:
bus (tespy.connections.bus.Bus) – Bus to calculate energy transfer on.
- Returns:
bus_value (float) – Value of the energy transfer on the specified bus.
\[\begin{split}\dot{E}_\mathrm{bus} = \begin{cases} \frac{\dot{E}_\mathrm{component}}{f\left( \frac{\dot{E}_\mathrm{bus}}{\dot{E}_\mathrm{bus,ref}}\right)} & \text{bus base = 'bus'}\\ \dot{E}_\mathrm{component} \cdot f\left( \frac{\dot{E}_\mathrm{component}} {\dot{E}_\mathrm{component,ref}}\right) & \text{bus base = 'component'} \end{cases}\end{split}\]
Note
If the base value of the bus is the bus value itself, a newton iteration is used to find the bus value satisfying the corresponding equation (case 1).
- 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.
- exergy_balance(T0)[source]¶
Exergy balance calculation method.
- Parameters:
T0 (float) – Ambient temperature T0 / K.
- 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_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 valueabs: absolute value
inconn (int) – Index of inlet connection.
outconn (int) – Index of outlet connection.
- Returns:
expr (float) – Value of expression
- 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}\]
- 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.
- 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
varfor 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_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 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:
\[\frac{\zeta}{D^4} = \frac{\Delta p \cdot \pi^2} {8 \cdot \dot{m}^2 \cdot v}\]
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:
objectClass 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_networkmethod. 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_topologymethod 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_networkmethod 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'>