tespy.connections package¶
tespy.connections.connection module¶
Module of class Connection and class Ref.
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/connections/connection.py
SPDX-License-Identifier: MIT
- class tespy.connections.connection.Connection(source, outlet_id, target, inlet_id, label=None, **kwargs)[source]¶
Bases:
ConnectionBaseClass connection is the container for fluid properties between components.
- Parameters:
m (float, tespy.connections.connection.Ref) – Mass flow specification.
m0 (float) – Starting value specification for mass flow.
p (float, tespy.connections.connection.Ref) – Pressure specification.
p0 (float) – Starting value specification for pressure.
h (float, tespy.connections.connection.Ref) – Enthalpy specification.
h0 (float) – Starting value specification for enthalpy.
fluid (dict) – Fluid compostition specification.
fluid0 (dict) – Starting value specification for fluid compostition.
fluid_balance (boolean) – Fluid balance equation specification.
x (float) – Gas phase mass fraction specification.
T (float, tespy.connections.connection.Ref) – Temperature specification.
v (float) – Volumetric flow specification.
state (str) – State of the pure fluid on this connection: liquid (‘l’) or gaseous (‘g’).
design (list) – List containing design parameters (stated as string).
offdesign (list) – List containing offdesign parameters (stated as string).
design_path (str) – Path to individual design case for this connection.
local_offdesign (boolean) – Treat this connection in offdesign mode in a design calculation.
local_design (boolean) – Treat this connection in design mode in an offdesign calculation.
printout (boolean) – Include this connection in the network’s results printout.
label (str) – Label of the connection. The default value is:
'source:source_id_target:target_id'.
Note
The fluid balance parameter applies a balancing of the fluid vector on the specified conntion to 100 %. For example, you have four fluid components (a, b, c and d) in your vector, you set two of them (a and b) and want the other two (components c and d) to be a result of your calculation. If you set this parameter to True, the equation (0 = 1 - a - b - c - d) will be applied.
The specification of values for design and/or offdesign is used for automatic switch from design to offdesign calculation: All parameters given in ‘design’, e.g.
design=['T', 'p'], are unset in any offdesign calculation, parameters given in ‘offdesign’ are set for offdesign calculation.
Example
This example shows how to create connections and specify parameters. First create the required components and connect them in the next step. After that, it is possible specify parameters with the
set_attrmethod.>>> from tespy.components import Sink, Source >>> from tespy.connections import Connection, Ref >>> so1 = Source('source1') >>> so2 = Source('source2') >>> si1 = Sink('sink1') >>> si2 = Sink('sink2') >>> so_si1 = Connection(so1, 'out1', si1, 'in1', label='connection 1') >>> so_si2 = Connection(so2, 'out1', si2, 'in1') >>> so_si1.label 'connection 1' >>> so_si2.label 'source2:out1_sink2:in1'
There are different ways of setting parameters on connections: Specify
a numeric value (for attributes mass flow, pressure and enthalpy)
a numeric starting value (for attributes mass flow, pressure and enthalpy)
a dictionary (for attributes fluid and fluid0)
a boolean value (for attributes fluid_balance, local_design, local_offdesign).
a referenced value (mass flow, pressure, temperature, enthalpy).
numpy.nan or None (unsetting a value).
a string (for attributes design_path and state).
a list (for attributes design and offdesign).
>>> so_si1.set_attr(v=0.012, m0=10, p=5, h=400, fluid={'H2O': 1}) >>> so_si2.set_attr(m=Ref(so_si1, 2, -5), h0=700, T=200, ... fluid={'N2': 1}, fluid_balance=True, ... design=['T'], offdesign=['m', 'v'])
The set_attr method automatically converts your input in data_container information.
>>> type(so_si1.v) <class 'tespy.tools.data_containers.FluidProperties'> >>> type(so_si1.fluid) <class 'tespy.tools.data_containers.FluidComposition'>
If you want get a specific value use the logic: connection.property.*. Additionally, it is possible to use the
get_attrmethod.>>> so_si1.m.val0 10 >>> so_si1.m.is_set False >>> so_si1.m.get_attr('is_set') False >>> type(so_si2.m_ref.ref) <class 'tespy.connections.connection.Ref'> >>> so_si2.fluid_balance.is_set True >>> so_si2.m_ref.ref.get_attr('delta') -5 >>> so_si2.m_ref.is_set True >>> type(so_si2.m_ref.ref.get_attr('obj')) <class 'tespy.connections.connection.Connection'>
Unset the specified temperature:
>>> so_si2.T.is_set True >>> so_si2.set_attr(T=None) >>> so_si2.T.is_set False
Bubble line or dew line temperature difference:
>>> so_si2.set_attr(td_bubble=5) >>> so_si2.td_bubble.is_set True >>> so_si2.td_bubble.val 5.0 >>> so_si2.set_attr(td_bubble=None) >>> so_si2.td_bubble.is_set False >>> so_si2.set_attr(td_dew=5) >>> so_si2.td_dew.is_set True >>> so_si2.td_dew.val 5.0 >>> so_si2.set_attr(td_dew=None) >>> so_si2.td_dew.is_set False
Specify the state keyword: The fluid will be forced to liquid or gaseous state in this case.
>>> so_si2.set_attr(state='l') >>> so_si2.state.is_set True >>> so_si2.set_attr(state=None) >>> so_si2.state.is_set False >>> so_si2.set_attr(state='g') >>> so_si2.state.is_set True >>> so_si2.set_attr(state=None) >>> so_si2.state.is_set False
- T_func(**kwargs)[source]¶
Equation for temperature specification
\[0 = T\left(p, h\right) - T\]- Returns:
float – residual value of equation
- T_ref_func(**kwargs)[source]¶
Equation for reference temperature specification \(T\)
\[0 = T\left(p, h\right) - \left[ T\left(p_\text{ref},h_\text{ref}\right) \cdot \text{factor} + \text{delta} \right]\]- Returns:
float – residual value of equation
- fluid_balance_func(**kwargs)[source]¶
Equation for fluid vector balance
\[0 = 1 - \sum x_\text{fluid_i}\]- Returns:
float – residual value of equation
- property fluid_data¶
- primary_ref_structure_matrix(k, **kwargs)[source]¶
Create a linear relationship between two variables
\[0 = var - \left( var_\text{ref} \cdot \text{factor} + \text{delta} \right)\]- Parameters:
k (int) – equation set number to create the structure matrix for Network preprocessing
- set_attr(**kwargs)[source]¶
Set, reset or unset attributes of a connection.
- Parameters:
m (float, tespy.connections.connection.Ref) – Mass flow specification.
m0 (float) – Starting value specification for mass flow.
p (float, tespy.connections.connection.Ref) – Pressure specification.
p0 (float) – Starting value specification for pressure.
h (float, tespy.connections.connection.Ref) – Enthalpy specification.
h0 (float) – Starting value specification for enthalpy.
fluid (dict) – Fluid composition specification.
fluid0 (dict) – Starting value specification for fluid composition.
fluid_balance (boolean) – Fluid balance equation specification.
x (float) – Gas phase mass fraction specification.
T (float, tespy.connections.connection.Ref) – Temperature specification.
v (float) – Volumetric flow specification.
state (str) – State of the pure fluid on this connection: liquid (‘l’) or gaseous (‘g’).
design (list) – List containing design parameters (stated as string).
offdesign (list) – List containing offdesign parameters (stated as string).
design_path (str) – Path to individual design case for this connection.
local_offdesign (boolean) – Treat this connection in offdesign mode in a design calculation.
local_design (boolean) – Treat this connection in design mode in an offdesign calculation.
printout (boolean) – Include this connection in the network’s results printout.
Note
The fluid balance parameter applies a balancing of the fluid vector on the specified connection to 100 %. For example, you have four fluid components (a, b, c and d) in your vector, you set two of them (a and b) and want the other two (components c and d) to be a result of your calculation. If you set this parameter to True, the equation (0 = 1 - a - b - c - d) will be applied.
The specification of values for design and/or offdesign is used for automatic switch from design to offdesign calculation: All parameters given in ‘design’, e.g.
design=['T', 'p'], are unset in any offdesign calculation, parameters given in ‘offdesign’ are set for offdesign calculation.The property state is applied on pure fluids only. If you specify the desired state of the fluid at a connection the convergence check will adjust the enthalpy values of that connection for the first iterations in order to meet the state requirement.
- td_bubble_func(**kwargs)[source]¶
Equation for fixed dew temperature superheating \(\Delta T\)
\[0 = T\left(p,h\right) - T_\text{bubble}\left(p\right) - \Delta T\]- Returns:
float – residual value of equation
- td_dew_func(**kwargs)[source]¶
Equation for fixed bubble temperature subcooling \(\Delta T\)
\[0 = T_\text{dew}\left(p\right) - T\left(p,h\right) - \Delta T\]- Returns:
float – residual value of equation
- v_func(**kwargs)[source]¶
Equation for volumetric flow specification \(\dot V\)
\[0 = \dot m \cdot vol\left(p, h\right) - \dot V\]- Returns:
float – residual value of equation
- class tespy.connections.connection.ConnectionBase[source]¶
Bases:
object
- class tespy.connections.connection.Ref(ref_obj, factor, delta)[source]¶
Bases:
objectA reference object is used to reference (unknown) properties of connections to other connections.
For example, reference the mass flow of one connection \(\dot{m}\) to another mass flow \(\dot{m}_{ref}\):
\[\dot{m} = \dot{m}_\text{ref} \cdot \text{factor} + \text{delta}\]- Parameters:
obj (tespy.connections.connection.Connection) – Connection to be referenced.
factor (float) – Factor to multiply specified property with.
delta (float) – Delta to add after multiplication.
tespy.connections.heatconnection module¶
- class tespy.connections.heatconnection.HeatConnection(source, outlet_id, target, inlet_id, label=None, **kwargs)[source]¶
Bases:
PowerConnection
tespy.connections.humidairconnection module¶
Module of class Connection and class Ref.
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/connections/humidairconnection.py
SPDX-License-Identifier: MIT
- class tespy.connections.humidairconnection.HAConnection(source, outlet_id, target, inlet_id, label=None, **kwargs)[source]¶
Bases:
Connection- property mixing_rule¶
tespy.connections.powerconnection module¶
- class tespy.connections.powerconnection.PowerConnection(source, outlet_id, target, inlet_id, label=None, **kwargs)[source]¶
Bases:
ConnectionBase- set_attr(**kwargs)[source]¶
Set, reset or unset attributes of a connection.
- Parameters:
E (float) – Energy flow specification.
design (list) – List containing design parameters (stated as string).
offdesign (list) – List containing offdesign parameters (stated as string).
design_path (str) – Path to individual design case for this connection.
local_offdesign (boolean) – Treat this connection in offdesign mode in a design calculation.
local_design (boolean) – Treat this connection in design mode in an offdesign calculation.
printout (boolean) – Include this connection in the network’s results printout.