tespy.networks module#

tespy.networks.network module#

Module for tespy network class.

The network is the container for every TESPy simulation. The network class automatically creates the system of equations describing topology and parametrization of a specific model and solves it.

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/networks/networks.py

SPDX-License-Identifier: MIT

class tespy.networks.network.Network(fluids, memorise_fluid_properties=True, **kwargs)[source]#

Bases: object

Class component is the base class of all TESPy components.

Parameters
  • fluids (list) – A list of all fluids within the network container.

  • memorise_fluid_properties (boolean) – Activate or deactivate fluid property value memorization. Default state is activated (True).

  • h_range (list) – List with minimum and maximum values for enthalpy value range.

  • h_unit (str) – Specify the unit for enthalpy: ‘J / kg’, ‘kJ / kg’, ‘MJ / kg’.

  • iterinfo (boolean) – Print convergence progress to console.

  • m_range (list) – List with minimum and maximum values for mass flow value range.

  • m_unit (str) – Specify the unit for mass flow: ‘kg / s’, ‘t / h’.

  • p_range (list) – List with minimum and maximum values for pressure value range.

  • p_unit (str) – Specify the unit for pressure: ‘Pa’, ‘psi’, ‘bar’, ‘MPa’.

  • s_unit (str) – Specify the unit for specific entropy: ‘J / kgK’, ‘kJ / kgK’, ‘MJ / kgK’.

  • T_unit (str) – Specify the unit for temperature: ‘K’, ‘C’, ‘F’, ‘R’.

  • v_unit (str) – Specify the unit for volumetric flow: ‘m3 / s’, ‘m3 / h’, ‘l / s’, ‘l / h’.

  • vol_unit (str) – Specify the unit for specific volume: ‘m3 / kg’, ‘l / kg’.

  • x_unit (str) – Specify the unit for steam mass fraction: ‘-‘, ‘%’.

Note

Unit specification is optional: If not specified the SI unit (first element in above lists) will be applied!

Range specification is optional, too. The value range is used to stabilize the newton algorithm. For more information see the “getting started” section in the online-documentation.

Example

Basic example for a setting up a tespy.networks.network.Network object. Specifying the fluids is mandatory! Unit systems, fluid property range and iterinfo are optional.

Standard value for iterinfo is True. This will print out convergence progress to the console. You can stop the printouts by setting this property to False.

>>> from tespy.networks import Network
>>> fluid_list = ['water', 'air', 'R134a']
>>> mynetwork = Network(fluids=fluid_list, p_unit='bar', T_unit='C')
>>> mynetwork.set_attr(p_range=[1, 10])
>>> type(mynetwork)
<class 'tespy.networks.network.Network'>
>>> mynetwork.set_attr(iterinfo=False)
>>> mynetwork.iterinfo
False
>>> mynetwork.set_attr(iterinfo=True)
>>> mynetwork.iterinfo
True

A simple network consisting of a source, a pipe and a sink. This example shows how the printout parameter can be used. We specify printout=False for both connections, the pipe as well as the heat bus. Therefore the .print_results() method should not print any results.

>>> from tespy.networks import Network
>>> from tespy.components import Source, Sink, Pipe
>>> from tespy.connections import Connection, Bus
>>> nw = Network(['CH4'], T_unit='C', p_unit='bar', v_unit='m3 / s')
>>> so = Source('source')
>>> si = Sink('sink')
>>> p = Pipe('pipe', Q=0, pr=0.95, printout=False)
>>> a = Connection(so, 'out1', p, 'in1')
>>> b = Connection(p, 'out1', si, 'in1')
>>> nw.add_conns(a, b)
>>> a.set_attr(fluid={'CH4': 1}, T=30, p=10, m=10, printout=False)
>>> b.set_attr(printout=False)
>>> b = Bus('heat bus')
>>> b.add_comps({'comp': p})
>>> nw.add_busses(b)
>>> b.set_attr(printout=False)
>>> nw.set_attr(iterinfo=False)
>>> nw.solve('design')
>>> nw.print_results()
add_busses(*args)[source]#

Add one or more busses to the network.

Parameters

b (tespy.connections.bus.Bus) – The bus to be added to the network, bus objects bi add_busses(b1, b2, b3, ...).

add_conns(*args)[source]#

Add one or more connections to the network.

Parameters

c (tespy.connections.connection.Connection) – The connection to be added to the network, connections objects ci add_conns(c1, c2, c3, ...).

add_subsys(*args)[source]#

Add one or more subsystems to the network.

Parameters

c (tespy.components.subsystem.Subsystem) – The subsystem to be added to the network, subsystem objects si network.add_subsys(s1, s2, s3, ...).

add_ude(*args)[source]#

Add a user defined function to the network.

Parameters

c (tespy.tools.helpers.UserDefinedEquation) – The objects to be added to the network, UserDefinedEquation objects ci del_conns(c1, c2, c3, ...).

check_busses(b)[source]#

Checksthe busses to be added for type, duplicates and identical labels.

Parameters

b (tespy.connections.bus.Bus) – The bus to be checked.

check_conns()[source]#

Check connections for multiple usage of inlets or outlets.

check_network()[source]#

Check if components are connected properly within the network.

del_busses(*args)[source]#

Remove one or more busses from the network.

Parameters

b (tespy.connections.bus.Bus) – The bus to be removed from the network, bus objects bi add_busses(b1, b2, b3, ...).

del_conns(*args)[source]#

Remove one or more connections from the network.

Parameters

c (tespy.connections.connection.Connection) – The connection to be removed from the network, connections objects ci del_conns(c1, c2, c3, ...).

del_ude(*args)[source]#

Remove a user defined function from the network.

Parameters

c (tespy.tools.helpers.UserDefinedEquation) – The objects to be added deleted from the network, UserDefinedEquation objects ci del_conns(c1, c2, c3, ...).

get_attr(key)[source]#

Get the value of a network attribute.

Parameters

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

Returns

out – Specified attribute.

static get_bus_data(c, *args)[source]#

Return bus information of a component.

static get_busses(c, *args)[source]#

Return the list of busses a component is integrated in.

static get_class_base(c)[source]#

Return the class name.

get_comp(label)[source]#

Get Component via label.

Parameters

label (str) – Label of the Component object.

Returns

c (tespy.components.component.Component) – Component object with specified label, None if no Component of the network has this label.

get_conn(label)[source]#

Get Connection via label.

Parameters

label (str) – Label of the Connection object.

Returns

c (tespy.connections.connection.Connection) – Connection object with specified label, None if no Connection of the network has this label.

static get_id(c)[source]#

Return the id of the python object.

static get_props(c, *args)[source]#

Return properties.

init_comp_design_params(component, data)[source]#

Write design point information to components.

Parameters
  • component (tespy.components.component.Component) – Write design point information to this component.

  • data (pandas.core.series.Series, pandas.core.frame.DataFrame) – Design point information.

init_components()[source]#

Set up necessary component information.

init_conn_design_params(c, df)[source]#

Write design point information to connections.

Parameters
  • c (tespy.connections.connection.Connection) – Write design point information to this connection.

  • df (pandas.core.frame.DataFrame) – Dataframe containing design point information.

init_count_connections_parameters(c)[source]#

Count the number of parameters set on a connection.

Parameters

c (tespy.connections.connection.Connection) – Connection count parameters of.

init_design()[source]#

Initialise a design calculation.

Offdesign parameters are unset, design parameters are set. If local_offdesign is True for connections or components, the design point information are read from the .csv-files in the respective design_path. In this case, the design values are unset, the offdesign values set.

init_fluids()[source]#

Initialise the fluid vector on every connection of the network.

  • Create fluid vector for every component as dict, index: nw.fluids, values: 0 if not set by user.

  • Create fluid_set vector with same logic, index: nw.fluids, values: False if not set by user.

  • If there are any combustion chambers in the network, calculate fluid vector starting from there.

  • Propagate fluid vector in direction of sources and targets.

init_offdesign()[source]#

Switch components and connections from design to offdesign mode.

Note

components

All parameters stated in the component’s attribute cp.design will be unset and all parameters stated in the component’s attribute cp.offdesign will be set instead.

Additionally, all component parameters specified as variables are unset and the values from design point are set.

connections

All parameters given in the connection’s attribute c.design will be unset and all parameters stated in the connections’s attribute cp.offdesign will be set instead. This does also affect referenced values!

init_offdesign_params()[source]#

Read design point information from specified design_path.

If a design_path has been specified individually for components or connections, the data will be read from the specified individual path instead.

Note

The methods tespy.networks.network.Network.init_comp_design_params() (components) and the tespy.networks.network.Network.init_conn_design_params() (connections) handle the parameter specification.

init_precalc_properties(c)[source]#

Precalculate enthalpy values for connections.

Precalculation is performed only if temperature, vapor mass fraction, temperature difference to boiling point or phase is specified.

Parameters

c (tespy.connections.connection.Connection) – Connection to precalculate values for.

init_properties()[source]#

Initialise the fluid properties on every connection of the network.

  • Set generic starting values for mass flow, enthalpy and pressure if not user specified, read from ìnit_path or available from previous calculation.

  • For generic starting values precalculate enthalpy value at points of given temperature, vapor mass fraction, temperature difference to boiling point or fluid state.

static init_read_connections(base_path)[source]#

Read connection information from base_path.

Parameters

base_path (str) – Path to network information.

init_set_properties()[source]#

Specification of SI values for user set values.

init_val0(c, key)[source]#

Set starting values for fluid properties.

The component classes provide generic starting values for their inlets and outlets.

Parameters

c (tespy.connections.connection.Connection) – Connection to initialise.

initialise()[source]#

Initilialise the network depending on calclation mode.

Design

  • Generic fluid composition and fluid property initialisation.

  • Starting values from initialisation path if provided.

Offdesign

  • Check offdesign path specification.

  • Set component and connection design point properties.

  • Switch from design/offdesign parameter specification.

matrix_inversion()[source]#

Invert matrix of derivatives and caluclate increment.

postprocessing()[source]#

Calculate connection, bus and component parameters.

print_components(c, *args)[source]#

Get the print values for the component data.

Parameters
  • c (pandas.core.series.Series) – Series containing the component data.

  • param (str) – Component parameter to print.

  • colored (booloean) – Color the printout.

  • coloring (dict) – Coloring information for colored printout.

Returns

value (str) – String representation of the value to print.

print_iterinfo_body()[source]#

Print convergence progress.

print_iterinfo_head()[source]#

Print head of convergence progress.

print_iterinfo_tail()[source]#

Print tail of convergence progress.

print_results(colored=True, colors={})[source]#

Print the calculations results to prompt.

process_busses()[source]#

Process the bus results.

process_components()[source]#

Process the component results.

process_connections()[source]#

Process the Connection results.

property_range_message(c, prop)[source]#

Return debugging message for fluid property range adjustments.

Parameters
  • c (tespy.connections.connection.Connection) – Connection to check fluid properties.

  • prop (str) – Fluid property.

Returns

msg (str) – Debugging message.

save(path, **kwargs)[source]#

Save the results to results files.

Parameters

filename (str) – Path for the results.

Note

Results will be saved to path. The results contain:

  • network.json (network information)

  • connections.csv (connection information)

  • folder components containing .csv files for busses and characteristics as well as .csv files for all types of components within your network.

save_busses(fn)[source]#

Save the bus properties.

Parameters

fn (str) – Path/filename for the file.

save_characteristics(path)[source]#

Save the characteristics.

Parameters

fn (str) – Path/filename for the file.

save_components(path)[source]#

Save the component properties.

  • Uses components labels as row identifier.

  • Writes:

    • component’s incomming and outgoing connections (object id) and

    • component’s parametrisation.

Parameters

path (str) – Path/filename for the file.

save_connections(fn)[source]#

Save the connection properties.

  • Uses connections object id as row identifier and saves

    • connections source and target as well as

    • properties with references and

    • fluid vector (including user specification if structure is True).

  • Connections source and target are identified by its labels.

Parameters

fn (str) – Path/filename for the file.

save_network(fn)[source]#

Save basic network configuration.

Parameters

fn (str) – Path/filename for the network configuration file.

set_attr(**kwargs)[source]#

Set, resets or unsets attributes of a network.

Parameters
  • h_range (list) – List with minimum and maximum values for enthalpy value range.

  • h_unit (str) – Specify the unit for enthalpy: ‘J / kg’, ‘kJ / kg’, ‘MJ / kg’.

  • iterinfo (boolean) – Print convergence progress to console.

  • m_range (list) – List with minimum and maximum values for mass flow value range.

  • m_unit (str) – Specify the unit for mass flow: ‘kg / s’, ‘t / h’.

  • p_range (list) – List with minimum and maximum values for pressure value range.

  • p_unit (str) – Specify the unit for pressure: ‘Pa’, ‘psi’, ‘bar’, ‘MPa’.

  • s_unit (str) – Specify the unit for specific entropy: ‘J / kgK’, ‘kJ / kgK’, ‘MJ / kgK’.

  • T_unit (str) – Specify the unit for temperature: ‘K’, ‘C’, ‘F’, ‘R’.

  • v_unit (str) – Specify the unit for volumetric flow: ‘m3 / s’, ‘m3 / h’, ‘l / s’, ‘l / h’.

  • vol_unit (str) – Specify the unit for specific volume: ‘m3 / kg’, ‘l / kg’.

set_defaults()[source]#

Set default network properties.

set_fluid_back_ends(memorise_fluid_properties)[source]#

Set the fluid back ends.

solve(mode, init_path=None, design_path=None, max_iter=50, min_iter=4, init_only=False, init_previous=True, use_cuda=False, always_all_equations=True)[source]#

Solve the network.

  • Check network consistency.

  • Initialise calculation and preprocessing.

  • Perform actual calculation.

  • Postprocessing.

Parameters
  • mode (str) – Choose from ‘design’ and ‘offdesign’.

  • init_path (str) – Path to the folder, where your network was saved to, e.g. saving to nw.save('myplant/tests') would require loading from init_path='myplant/tests'.

  • design_path (str) – Path to the folder, where your network’s design case was saved to, e.g. saving to nw.save('myplant/tests') would require loading from design_path='myplant/tests'.

  • max_iter (int) – Maximum number of iterations before calculation stops, default: 50.

  • min_iter (int) – Minimum number of iterations before calculation stops, default: 4.

  • init_only (boolean) – Perform initialisation only, default: False.

  • init_previous (boolean) – Initialise the calculation with values from the previous calculation, default: True.

  • use_cuda (boolean) – Use cuda instead of numpy for matrix inversion, default: False.

  • always_all_equations (boolean) – Calculate all equations in every iteration. Disabling this flag, will increase calculation speed, especially for mixtures, default: True.

Note

For more information on the solution process have a look at the online documentation at tespy.readthedocs.io in the section “TESPy modules”.

solve_busses()[source]#

Calculate the equations and the partial derivatives for the busses.

  • Iterate through busses in network to get residuals and derivatives.

  • Place residual values in residual value vector of the network.

  • Place partial derivatives in jacobian matrix of the network.

solve_check_props(c)[source]#

Check for invalid fluid property values.

Parameters

c (tespy.connections.connection.Connection) – Connection to check fluid properties.

solve_check_temperature(c)[source]#

Check if temperature is within user specified limits.

Parameters

c (tespy.connections.connection.Connection) – Connection to check fluid properties.

solve_components()[source]#

Calculate the residual and derivatives of component equations.

  • Iterate through components in network to get residuals and derivatives.

  • Place residual values in residual value vector of the network.

  • Place partial derivatives in jacobian matrix of the network.

solve_connections()[source]#

Calculate the residual and derivatives of connection equations.

  • Iterate through connections in network to get residuals and derivatives.

  • Place residual values in residual value vector of the network.

  • Place partial derivatives in jacobian matrix of the network.

Note

Equations

mass flow, pressure and enthalpy

\[val = 0\]

temperatures

\[val = T_{j} - T \left( p_{j}, h_{j}, fluid_{j} \right)\]

volumetric flow

\[val = \dot{V}_{j} - v \left( p_{j}, h_{j} \right) \cdot \dot{m}_j\]

superheating or subcooling Works with pure fluids only!

\[ \begin{align}\begin{aligned}val = T_{j} - td_{bp} - T_{bp}\left( p_{j}, fluid_{j} \right)\\\text{td: temperature difference, bp: boiling point}\end{aligned}\end{align} \]

vapour mass fraction Works with pure fluids only!

\[val = h_{j} - h \left( p_{j}, x_{j}, fluid_{j} \right)\]

Referenced values

mass flow, pressure and enthalpy

\[val = x_{j} - x_{j,ref} \cdot a + b\]

temperatures

\[val = T \left( p_{j}, h_{j}, fluid_{j} \right) - T \left( p_{j}, h_{j}, fluid_{j} \right) \cdot a + b\]

Derivatives

mass flow, pressure and enthalpy

\[\begin{split}J\left(\frac{\partial f_{i}}{\partial m_{j}}\right) = 1\\ \text{for equation i, connection j}\\ \text{pressure and enthalpy analogously}\end{split}\]

temperatures

\[ \begin{align}\begin{aligned}\begin{split}J\left(\frac{\partial f_{i}}{\partial p_{j}}\right) = -\frac{\partial T_{j}}{\partial p_{j}}\\ J\left(\frac{\partial f_{i}}{\partial h_{j}}\right) = -\frac{\partial T_{j}}{\partial h_{j}}\\ J\left(\frac{\partial f_{i}}{\partial fluid_{j,k}}\right) = - \frac{\partial T_{j}}{\partial fluid_{j,k}}\end{split}\\\begin{split}\forall k \in \text{fluid components}\\ \text{for equation i, connection j}\end{split}\end{aligned}\end{align} \]

volumetric flow

\[ \begin{align}\begin{aligned}\begin{split}J\left(\frac{\partial f_{i}}{\partial m_{j}}\right) = -v \left( p_{j}, h_{j} \right)\\ J\left(\frac{\partial f_{i}}{\partial p_{j}}\right) = -\frac{\partial v_{j}}{\partial p_{j}} \cdot \dot{m}_j\\ J\left(\frac{\partial f_{i}}{\partial h_{j}}\right) = -\frac{\partial v_{j}}{\partial h_{j}} \cdot \dot{m}_j\\\end{split}\\\begin{split}\forall k \in \text{fluid components}\\ \text{for equation i, connection j}\end{split}\end{aligned}\end{align} \]

superheating or subcooling Works with pure fluids only!

\[ \begin{align}\begin{aligned}\begin{split}J\left(\frac{\partial f_{i}}{\partial p_{j}}\right) = \frac{\partial T \left( p_{j}, h_{j}, fluid_{j} \right)} {\partial p_{j}} - \frac{\partial T_{bp} \left( p_{j}, fluid_{j} \right)} {\partial p_{j}} \\ J\left(\frac{\partial f_{i}}{\partial h_{j}}\right) = \frac{\partial T \left( p_{j}, h_{j}, fluid_{j} \right)} {\partial h_{j}}\\\end{split}\\\begin{split}\text{for equation i, connection j}\\ \text{td: temperature difference, bp: boiling point}\end{split}\end{aligned}\end{align} \]

vapour mass fraction Works with pure fluids only!

\[\begin{split}J\left(\frac{\partial f_{i}}{\partial p_{j}}\right) = -\frac{\partial h \left( p_{j}, x_{j}, fluid_{j} \right)} {\partial p_{j}}\\ J\left(\frac{\partial f_{i}}{\partial h_{j}}\right) = 1\\ \text{for equation i, connection j, x: vapour mass fraction}\end{split}\]

Referenced values

mass flow, pressure and enthalpy

\[\begin{split}J\left(\frac{\partial f_{i}}{\partial m_{j}}\right) = 1\\ J\left(\frac{\partial f_{i}}{\partial m_{j,ref}}\right) = - a\\ \text{for equation i, connection j}\\ \text{pressure and enthalpy analogously}\end{split}\]

temperatures

\[\begin{split}J\left(\frac{\partial f_{i}}{\partial p_{j}}\right) = \frac{dT_{j}}{dp_{j}}\\ J\left(\frac{\partial f_{i}}{\partial h_{j}}\right) = \frac{dT_{j}}{dh_{j}}\\ J\left(\frac{\partial f_{i}}{\partial fluid_{j,k}}\right) = \frac{dT_{j}}{dfluid_{j,k}} \; , \forall k \in \text{fluid components}\\ J\left(\frac{\partial f_{i}}{\partial p_{j,ref}}\right) = \frac{dT_{j,ref}}{dp_{j,ref}} \cdot a \\ J\left(\frac{\partial f_{i}}{\partial h_{j,ref}}\right) = \frac{dT_{j,ref}}{dh_{j,ref}} \cdot a \\ J\left(\frac{\partial f_{i}}{\partial fluid_{j,k,ref}}\right) = \frac{dT_{j}}{dfluid_{j,k,ref}} \cdot a \; , \forall k \in \text{fluid components}\\ \text{for equation i, connection j}\end{split}\]
solve_control()[source]#

Control iteration step of the newton algorithm.

  • Calculate the residual value for each equation

  • Calculate the jacobian matrix

  • Calculate new values for variables

  • Restrict fluid properties to value ranges

  • Check component parameters for consistency

solve_determination()[source]#

Check, if the number of supplied parameters is sufficient.

solve_loop()[source]#

Loop of the newton algorithm.

solve_user_defined_eq()[source]#

Calculate the residual and jacobian of user defined equations.

  • Iterate through user defined functions and calculate residual value and corresponding jacobian.

  • Place residual values in residual value vector of the network.

  • Place partial derivatives regarding connection parameters in jacobian matrix of the network.

tespy.networks.network_reader module#

Module for loading a tespy network from saved state.

Use the method tespy.networks.network_reader.load_network() for importing a network from a saved state.

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/networks/network_reader.py

SPDX-License-Identifier: MIT

tespy.networks.network_reader.busses_add_comps(c, *args)[source]#

Add components to busses according to data from .csv file.

Parameters
  • c (pandas.core.series.Series) – Component information from .csv-file.

  • args[0] (pandas.core.frame.DataFrame) – DataFrame containing all created busses.

  • args[1] (pandas.core.frame.DataFrame) – DataFrame containing all created characteristic lines.

tespy.networks.network_reader.conns_set_ref(c, *args)[source]#

Set references on connections as specified in connection data.

Parameters
  • c (pandas.core.series.Series) – Connection information from .csv-file.

  • args[0] (pandas.core.frame.DataFrame) – DataFrame containing all created connections.

Returns

instance (tespy.connections.ref) – TESPy reference object.

tespy.networks.network_reader.construct_busses(c, *args)[source]#

Create busses of the network.

Parameters

c (pandas.core.series.Series) – Bus information from .csv-file.

Returns

b (tespy.connections.bus.Bus) – TESPy bus object.

tespy.networks.network_reader.construct_components(c, *args)[source]#

Create TESPy component from class name and set parameters.

Parameters
  • c (pandas.core.series.Series) – Component information from .csv-file.

  • args[0] (pandas.core.frame.DataFrame) – DataFrame containing the data of characteristic lines.

  • args[1] (pandas.core.frame.DataFrame) – DataFrame containing the data of characteristic maps.

Returns

instance (tespy.components.component.Component) – TESPy component object.

tespy.networks.network_reader.construct_connections(c, *args)[source]#

Create TESPy connection from data in the .csv-file and its parameters.

Parameters
  • c (pandas.core.series.Series) – Connection information from .csv-file.

  • args[0] (pandas.core.frame.DataFrame) – DataFrame containing all created components.

Returns

conn (tespy.connections.connection.Connection) – TESPy connection object.

tespy.networks.network_reader.construct_network(path)[source]#

Create TESPy network from the data provided in the netw.csv-file.

Parameters

path (str) – Base-path to stored network data.

Returns

nw (tespy.networks.network.Network) – TESPy network object.

tespy.networks.network_reader.load_network(path)[source]#

Load a network from a base path.

Parameters

path (str) – The path to the network data.

Returns

nw (tespy.networks.network.Network) – TESPy networks object.

Note

If you save the network structure of an existing TESPy network, it will be saved to the path you specified. The structure of the saved data in that path is the structure you need to provide in the path for loading the network.

The structure of the path must be as follows:

  • Folder: path (e.g. ‘mynetwork’)

  • Subfolder: components (‘mynetwork/components’) containing

    • bus.csv*

    • char.csv*

    • char_map.csv*

    • component_class_name.csv (e.g. heat_exchanger.csv)

  • connections.csv

  • network.json

The imported network has the following additional features:

  • Connections are accessible by label, e.g. myimportednetwork.get_conn('myconnection'). The default label logic is source:source_id_target:target_id, where the source means the label of the component the connection originates from and target means the label of the component, the connections targets on.

  • Components are accessible by label as well, e.g. for a component ‘heat exchanger’ myimportednetwork.get_comp('heat exchanger').

  • Busses are stored in a dict like structure, therefore accessible like follows, e.g. a bus labeld ‘power input’ myimportednetwork.busses['power input'].

Example

Create a network and export it. This is followed by loading the network with the network_reader module. All network information stored will be passed to a new network object. Components, connections and busses will be accessible by label. The following example setup is simple gas turbine setup with compressor, combustion chamber and turbine. The fuel is fed from a pipeline and throttled to the required pressure while keeping the temperature at a constant value.

>>> import numpy as np
>>> from tespy.components import (Sink, Source, CombustionChamber,
... Compressor, Turbine, HeatExchangerSimple)
>>> from tespy.connections import Connection, Ref, Bus
>>> from tespy.networks import load_network, Network
>>> import shutil
>>> fluid_list = ['CH4', 'O2', 'N2', 'CO2', 'H2O', 'Ar']
>>> nw = Network(fluids=fluid_list, p_unit='bar', T_unit='C',
... h_unit='kJ / kg', iterinfo=False)
>>> air = Source('air')
>>> f = Source('fuel')
>>> c = Compressor('compressor')
>>> comb = CombustionChamber('combustion')
>>> t = Turbine('turbine')
>>> p = HeatExchangerSimple('fuel preheater')
>>> si = Sink('sink')
>>> inc = Connection(air, 'out1', c, 'in1', label='ambient air')
>>> cc = Connection(c, 'out1', comb, 'in1')
>>> fp = Connection(f, 'out1', p, 'in1')
>>> pc = Connection(p, 'out1', comb, 'in2')
>>> ct = Connection(comb, 'out1', t, 'in1')
>>> outg = Connection(t, 'out1', si, 'in1')
>>> nw.add_conns(inc, cc, fp, pc, ct, outg)

Specify component and connection properties. The intlet pressure at the compressor and the outlet pressure after the turbine are identical. For the compressor, the pressure ratio and isentropic efficiency are design parameters. A compressor map (efficiency vs. mass flow and pressure rise vs. mass flow) is selected for the compressor. Fuel is Methane.

>>> c.set_attr(pr=10, eta_s=0.88, design=['eta_s', 'pr'],
... offdesign=['char_map_eta_s', 'char_map_pr'])
>>> t.set_attr(eta_s=0.9, design=['eta_s'],
... offdesign=['eta_s_char', 'cone'])
>>> inc.set_attr(fluid={'N2': 0.7556, 'O2': 0.2315, 'Ar': 0.0129, 'CH4': 0,
... 'H2O': 0}, fluid_balance=True, T=25, p=1)
>>> fp.set_attr(fluid={'N2': 0, 'O2': 0, 'Ar': 0, 'CH4': 0.96, 'H2O': 0,
... 'CO2': 0.04}, T=25, p=40)
>>> pc.set_attr(T=25)
>>> ct.set_attr(T=1100)
>>> outg.set_attr(p=Ref(inc, 1, 0))
>>> power = Bus('total power output')
>>> power.add_comps({'comp': c}, {'comp': t})
>>> nw.add_busses(power)

For a stable start, we specify the fresh air mass flow.

>>> inc.set_attr(m=3)
>>> nw.solve('design')

The total power output is set to 1 MW, electrical or mechanical efficiencies are not considered in this example. The documentation example in class tespy.connections.bus.Bus provides more information on efficiencies of generators, for instance.

>>> inc.set_attr(m=np.nan)
>>> power.set_attr(P=-1e6)
>>> nw.solve('design')
>>> nw.lin_dep
False
>>> nw.save('exported_nwk')
>>> mass_flow = round(nw.get_conn('ambient air').m.val_SI, 1)
>>> c.set_attr(igva='var')
>>> nw.solve('offdesign', design_path='exported_nwk')
>>> round(t.eta_s.val, 1)
0.9
>>> power.set_attr(P=-0.75e6)
>>> nw.solve('offdesign', design_path='exported_nwk')
>>> nw.lin_dep
False
>>> eta_s_t = round(t.eta_s.val, 3)
>>> igva = round(c.igva.val, 3)
>>> eta_s_t
0.898
>>> igva
20.138

The designed network is exported to the path ‘exported_nwk’. Now import the network and recalculate. Check if the results match with the previous calculation in design and offdesign case.

>>> imported_nwk = load_network('exported_nwk')
>>> imported_nwk.set_attr(iterinfo=False)
>>> imported_nwk.solve('design', init_path='exported_nwk')
>>> imported_nwk.lin_dep
False
>>> round(imported_nwk.get_conn('ambient air').m.val_SI, 1) == mass_flow
True
>>> round(imported_nwk.get_comp('turbine').eta_s.val, 3)
0.9
>>> imported_nwk.get_comp('compressor').set_attr(igva='var')
>>> imported_nwk.solve('offdesign', design_path='exported_nwk')
>>> round(imported_nwk.get_comp('turbine').eta_s.val, 3)
0.9
>>> imported_nwk.busses['total power output'].set_attr(P=-0.75e6)
>>> imported_nwk.solve('offdesign', design_path='exported_nwk')
>>> round(imported_nwk.get_comp('turbine').eta_s.val, 3) == eta_s_t
True
>>> round(imported_nwk.get_comp('compressor').igva.val, 3) == igva
True
>>> shutil.rmtree('./exported_nwk', ignore_errors=True)