Connections

This section provides an overview of the available Connection classes in the tabs below. Beyond that, it gives an introduction on how to parametrize instances. Connections hold the variables that are solved for in the system of equations of all your models.

Class documentation and example: Connection

Table of parameters

Parameter

Description

Quantity

Method

m

mass flow of the fluid (system variable)

mass_flow

None

p

absolute pressure of the fluid (system variable)

pressure

None

h

mass specific enthalpy of the fluid (system variable)

enthalpy

None

T

temperature of the fluid

temperature

T_func

T_bubble

determine pressure based on the provided bubble temperature of the fluid

temperature

None

T_dew

determine pressure based on the provided dew temperature of the fluid

temperature

None

v

volumetric flow of the fluid

volumetric_flow

v_func

x

vapor mass fraction/quality of the two-phase fluid

quality

x_func

td_dew

superheating temperature difference to dew line temperature

temperature_difference

td_dew_func

td_bubble

subcooling temperature difference to bubble line temperature

temperature_difference

td_bubble_func

m_ref

equation for linear relationship between two mass flows

mass_flow

primary_ref_structure_matrix

p_ref

equation for linear relationship between two pressure values

pressure

primary_ref_structure_matrix

h_ref

equation for linear relationship between two enthalpy values

enthalpy

primary_ref_structure_matrix

T_ref

equation for linear relationship between two temperature values

temperature_difference

T_ref_func

v_ref

equation for linear relationship between two volumetric flows

volumetric_flow

v_ref_func

vol

specific volume of the fluid (output only)

specific_volume

None

s

specific entropy of the fluid (output only)

entropy

None

fluid

mass fractions of the fluid composition (system variable)

None

None

fluid_balance

apply an equation which closes the fluid balance with at least two unknown fluid mass fractions

None

fluid_balance_func

Td_bp

temperature difference to boiling point (deprecated)

temperature_difference

Td_bp_func

Class documentation and example: PowerConnection

Table of parameters

Parameter

Description

Quantity

Method

E

None

power

None

Connection Overview

The tables above indicate, which specification parameters are available for each class. To set/unset values the same logic applies as is used in components.

Setting and unsetting values

We will create a simple problem using a SimpleHeatExchanger to showcase specification options. Further down there is a second simple problem showcasing the PowerConnection.

A Connection always connects two components:

>>> from tespy.networks import Network
>>> from tespy.connections import Connection
>>> from tespy.components import Sink, Source, SimpleHeatExchanger
>>> nw = Network(iterinfo=False)
>>> nw.units.set_defaults(
...     temperature="°C", power="kW", pressure="bar", enthalpy="kJ/kg"
... )
>>> source = Source('source')
>>> heatexchanger = SimpleHeatExchanger('heat exchanger')
>>> sink = Sink('sink')
>>> c1 = Connection(source, "out1", heatexchanger, "in1", label="c1")
>>> c2 = Connection(heatexchanger, "out1", sink, "in1", label="c2")
>>> nw.add_conns(c1, c2)

It is possible to set simple values and then solve, e.g.:

  • mass flow, pressure and temperature (and fluid) at inlet

  • enthalpy at outlet

  • (pressure drop in heat exchanger)

>>> c1.set_attr(fluid={"R290": 1}, m=5, p=3, T=50)
>>> c2.set_attr(h=500)
>>> heatexchanger.set_attr(dp=0)
>>> nw.solve("design")

Both connections will have all results available, these can be accessed

  • as SI value

  • as value in the network’s default unit of the respective quantity

  • as value with the corresponding quantity (pint.Quantity)

The results include mass flow, pressure, enthalpy, temperature, temperature, vapor quality, specific volume vol and volumetric flow.

>>> round(c1.h.val, 1)  # value in kJ/kg but without unit attached
668.9
>>> round(c1.vol.val_with_unit, 3)  # will be in m3/kg
<Quantity(0.195, 'm3 / kilogram')>
>>> round(c2.T.val_SI, 1)  # SI value
259.0
>>> round(c2.T.val_with_unit, 1)  # will be in °C
<Quantity(-14.2, 'degree_Celsius')>

You can also provide quantities to a specific parameter to individually specify a unit to a parameter, e.g. inlet mass flow. Note, that units are retained when set with individual quantity.

>>> Q = nw.units.ureg.Quantity
>>> c1.set_attr(m=Q(2, "t/h"))
>>> nw.solve("design")
>>> c1.m.val_with_unit
<Quantity(2, 'metric_ton / hour')>
>>> round(c2.m.val_with_unit, 2)
<Quantity(0.56, 'kilogram / second')>

For pure fluids or CoolProp/REFPROP mixtures we can also specify two-phase properties:

  • vapor mass fraction/quality x

  • dew line temperature difference for superheating td_dew

  • bubble line temperature difference for subcooling td_bubble

  • dew line temperature T_dew and bubble line temperature T_bubble to impose the corresponding pressure to the model

We can replace the inlet temperature specification e.g. with superheating. The unit of temperature_difference is different from the unit for temperature. Unsetting a value is simple: Just set it to None.

>>> c1.set_attr(T=None)  # unset the value
>>> nw.units.default["temperature"]
'°C'
>>> nw.units.default["temperature_difference"]
'delta_degC'
>>> c1.set_attr(td_dew=20)
>>> nw.solve("design")
>>> round(c1.T.val, 2)
5.82

Setting starting values

Setting starting values for the variables can be helpful in some situations. You can do this for the following properties:

  • mass flow m0

  • pressure p0

  • enthalpy h0

These specifications are optional!

>>> c1.set_attr(m0=4)
>>> c2.set_attr(h0=300, p0=4)

Referencing specifications

It is also possible to set up linear relationships between parameters between different instances of Connection in your system in the following form:

\[x_0 = a * x_1 + b\]

It is possible to specify these for

  • mass flow, pressure and enthalpy as well as

  • temperature and volumetric flow.

For example, instead of h we can specify a reference to the temperature at c1. The factor is always based on SI value, the delta is in the default unit of the respective property. The starting value for h is required in this context because in the previous calculation the fluid was in two-phase state, meaning the partial derivative of the temperature of c2 with respect to enthalpy would be zero otherwise.

>>> from tespy.connections import Ref
>>> factor = 1
>>> delta = 25
>>> c2.set_attr(h=None, T=Ref(c1, factor, delta), h0=1000)
>>> nw.solve("design")
>>> round(c1.T.val_SI * factor + delta - 273.15, 2)
30.82
>>> round(c2.T.val, 2)
30.82

Instead we could also reference volumetric flow at outlet to find the temperature at outlet.

>>> c2.set_attr(T=None)
>>> factor = 1.2
>>> delta = 0
>>> c2.set_attr(v=Ref(c1, factor, delta))
>>> nw.solve("design")
>>> round(c1.v.val_SI * factor + delta, 2)
0.11
>>> round(c2.v.val_SI, 2)
0.11
>>> round(c2.T.val, 2)
52.91

For more complex (and arbitrary) relationships between variables of the system use the UserDefinedEquation class. Some examples can be found in this section.

Fluid specification

This sections shows some details on the specification of fluids.

# set both elements of the fluid vector
>>> c1.set_attr(fluid={'water': 1})

# set starting values (might be necessary sometimes)
>>> c1.set_attr(fluid0={'water': 1})

# overwrite the existing fluid vector
>>> c1.fluid.is_set
{'water'}
>>> c1.set_attr(fluid={'N2': 0.7, "O2": 0.3})
>>> c1.fluid.is_set == {'N2', 'O2'}
True

# remove a single specification while keeping the other component inside
>>> c1.fluid.is_set.remove('N2')
>>> c1.fluid.is_set
{'O2'}
>>> c1.fluid.val
{'N2': 0.7, 'O2': 0.3}

CoolProp and REFPROP

It is possible to specify the fluid property back end of the fluids by adding the name of the back end in front of the fluid’s name. For incompressible binary mixtures, you can append the water volume/mass fraction to the fluid’s name, for example:

>>> c1.set_attr(fluid={'water': 1})  # HEOS back end
>>> c1.set_attr(fluid={'INCOMP::water': 1})  # incompressible fluid
>>> c1.set_attr(fluid={'BICUBIC::air': 1})  # bicubic back end
>>> c1.set_attr(fluid={'INCOMP::MPG[0.5]|mass': 1})  # binary incompressible mixture

You can also specify REFPROP based fluids, e.g. R513A, which is a mass based mixture of R134a and R1234yf:

>>> c1.set_attr(fluid={'REFPROP::R134A[0.44]&R1234yf[0.56]|mass': 1})  # REFPROP back end

Note

Without further specifications CoolProp will be used as fluid property database. If you do not specify a back end, the default back end HEOS will be used. For an overview of the back ends available please refer to the fluid property section.

Other Backends

You can also change the engine, for example to the iapws library. It is even possible, that you define your own custom engine, e.g. using polynomial equations. Please check out the fluid properties’ section in the docs on how to do this.

>>> from tespy.tools.fluid_properties.wrappers import IAPWSWrapper
>>> c1.set_attr(fluid={'H2O': 1}, fluid_engines={"H2O": IAPWSWrapper})

Please also check out the section on custom fluid properties for more information.

PowerConnection Overview

PowerConnections can be used to represent non-material energy flow, like power or heat. You can make use of generators, motors and buses.

Different use-cases for the implementation of PowerConnection with the respective power components can be:

  • apply motor or generator efficiencies

  • connect multiple turbomachines on a single shaft

  • collect all electricity production and own consumption to calculate net power

The handling of the PowerConnection and the respective components is identical to standard components.

The PowerConnection only holds a single parameter, namely the power flow E (\(\dot E\)), which is measured in Watts. You can create a PowerConnection instance by connecting to a component that has a respective inlet or outlet. For example, consider a turbine generating electricity. First we can set up a system as we are used to do without any PowerConnections:

>>> from tespy.components import Source, Sink, Turbine
>>> from tespy.connections import Connection
>>> from tespy.networks import Network
>>> nw = Network(iterinfo=False)
>>> nw.units.set_defaults(
... temperature="degC", pressure="bar", power="kW"
... )
>>> so = Source("source")
>>> turbine = Turbine("turbine")
>>> si = Sink("sink")
>>> c1 = Connection(so, "out1", turbine, "in1", label="c1")
>>> c2 = Connection(turbine, "out1", si, "in1", label="c2")
>>> nw.add_conns(c1, c2)

We can parametrize the model, e.g. consider the turbine part of a gas turbine, which expands hot flue gases:

>>> c1.set_attr(fluid={"air": 1}, p=10, T=1000, m=1)
>>> c2.set_attr(p=1)
>>> turbine.set_attr(eta_s=0.9)
>>> nw.solve("design")
>>> round(turbine.P.val)
-577

We can add a connection between the turbine and the grid. This will add one extra variable to our problem (the energy flow E) but also one extra equation, namely the turbine energy balance. Therefore, after adding the new connection, there is nothing to change to make the model solve.

>>> from tespy.connections import PowerConnection
>>> from tespy.components import PowerSink
>>> grid = PowerSink("grid")
>>> e1 = PowerConnection(turbine, "power", grid, "power", label="e1")
>>> nw.add_conns(e1)
>>> nw.solve("design")
>>> round(e1.E.val)
577

Note

Note that the value of the energy flow of a PowerConnection will always be positive in the defined direction (from one component’s outlet to another component’s inlet).

To learn what power connections are available in each of the component classes see the respective API documentation. There are a couple of example applications available for the PowerConnection in this section.

Access from the Network object

You may want to access the network’s connections or powerconnections other than using the variable names, for example in an imported network or connections from a subsystem. It is possible to access these using the connection’s label similar as it is possible for components. By default, the label is generated by this logic:

source:source_id_target:target_id, where

  • source and target are the labels of the components that are connected.

  • source_id and target_id are e.g. out1 and in2 respectively.

>>> conn = nw.get_conn('c1')
>>> conn.label
'c1'
>>> powerconn = nw.get_conn('e1')
>>> powerconn.label
'e1'