Ejemplo n.º 1
0
def test_network_component_labels():
    nw = nwk.network(['water'])
    source = cmp.source('label')
    sink = cmp.sink('label')
    a = con.connection(source, 'out1', sink, 'in1')
    nw.add_conns(a)
    nw.check_network()
Ejemplo n.º 2
0
def test_network_overdetermination():
    nw = nwk.network(['water'])
    source = cmp.source('source')
    sink = cmp.sink('sink')
    a = con.connection(source, 'out1', sink, 'in1', m=1, p=1e5, x=1, h=1e6, fluid={'water': 1}, fluid_balance=True)
    nw.add_conns(a)
    nw.solve('design')
Ejemplo n.º 3
0
def test_network_underdetermination():
    nw = nwk.network(['water'])
    source = cmp.source('source')
    sink = cmp.sink('sink')
    a = con.connection(source, 'out1', sink, 'in1', m=1)
    nw.add_conns(a)
    nw.solve('design')
Ejemplo n.º 4
0
def test_network_network_consistency_inlets():
    nw = nwk.network(['water'])
    merge = cmp.merge('merge')
    sink = cmp.sink('label')
    a = con.connection(merge, 'out1', sink, 'in1')
    nw.add_conns(a)
    nw.check_network()
Ejemplo n.º 5
0
def test_network_network_consistency_outlets():
    nw = nwk.network(['water', 'air'])
    source = cmp.source('source')
    splitter = cmp.splitter('splitter')
    a = con.connection(source, 'out1', splitter, 'in1')
    nw.add_conns(a)
    nw.check_network()
Ejemplo n.º 6
0
def test_network_instanciation_no_fluids():
    nw = nwk.network([])
    so = cmp.source('source')
    si = cmp.sink('sink')
    conn = con.connection(so, 'out1', si, 'in1')
    nw.add_conns(conn)
    nw.solve('design', init_only=True)
Ejemplo n.º 7
0
def construct_network(path):
    """
    creates TESPy network from the data provided in the .csv-file

    :param path: path to stored network data
    :type path: str
    :returns: nw (*tespy.networks.network*) - TESPy network object
    """

    # read network .csv-file
    netw = pd.read_csv(path + '/netw.csv',
                       sep=';',
                       decimal='.',
                       converters={'fluids': ast.literal_eval})
    f_list = netw['fluids'][0]

    kwargs = {}
    kwargs['m_unit'] = netw['m_unit'][0]
    kwargs['p_unit'] = netw['p_unit'][0]
    kwargs['p_range'] = [netw['p_min'][0], netw['p_max'][0]]
    kwargs['h_unit'] = netw['h_unit'][0]
    kwargs['h_range'] = [netw['h_min'][0], netw['h_max'][0]]
    kwargs['T_unit'] = netw['T_unit'][0]
    kwargs['T_range'] = [netw['T_min'][0], netw['T_max'][0]]

    # create network object with its properties
    nw = nwk.network(fluids=f_list, **kwargs)

    return nw
Ejemplo n.º 8
0
 def setup(self):
     self.nw = nwk.network(['water', 'air'])
     self.comp = cmp.cogeneration_unit('cogeneration unit')
     self.pipe = cmp.pipe('pipe')
     self.conn = con.connection(self.comp, 'out1', self.pipe, 'in1')
     self.bus = con.bus('mybus')
     self.sub = subsys.subsystem('MySub')
Ejemplo n.º 9
0
def construct_network(path):
    r"""
    Creates 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
        TESPy network object.
    """
    # read network .csv-file
    netw = pd.read_csv(path + 'netw.csv', sep=';', decimal='.',
                       converters={'fluids': ast.literal_eval})
    f_list = netw['fluids'][0]

    kwargs = {}
    kwargs['m_unit'] = netw['m_unit'][0]
    kwargs['p_unit'] = netw['p_unit'][0]
    kwargs['p_range'] = [netw['p_min'][0], netw['p_max'][0]]
    kwargs['h_unit'] = netw['h_unit'][0]
    kwargs['h_range'] = [netw['h_min'][0], netw['h_max'][0]]
    kwargs['T_unit'] = netw['T_unit'][0]
    kwargs['T_range'] = [netw['T_min'][0], netw['T_max'][0]]

    # create network object with its properties
    nw = nwk.network(fluids=f_list, **kwargs)

    return nw
Ejemplo n.º 10
0
 def setup(self):
     self.nw = nwk.network(['H2O', 'N2', 'O2', 'Ar', 'CO2', 'H2'])
     self.comb = cmp.combustion_chamber('combustion chamber')
     c1 = con.connection(cmp.source('air'), 'out1', self.comb, 'in1')
     c2 = con.connection(cmp.source('fuel'), 'out1', self.comb, 'in2')
     c3 = con.connection(self.comb, 'out1', cmp.sink('flue gas'), 'in1')
     self.nw.add_conns(c1, c2, c3)
Ejemplo n.º 11
0
def test_network_missing_data_in_individual_design_case_file():
    nw = nwk.network(['water'])
    source = cmp.source('source')
    pipe = cmp.pipe('pipe', Q=0, pr=0.95, design=['pr'], offdesign=['zeta'])
    sink = cmp.sink('sink')
    a = con.connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=293.15,
                       fluid={'water': 1})
    b = con.connection(pipe, 'out1', sink, 'in1', design_path='tmp2')
    nw.add_conns(a, b)
    nw.solve('design')
    nw.save('tmp')
    nw.save('tmp2')

    inputs = open('./tmp/conn.csv')
    all_lines = inputs.readlines()
    all_lines.pop(len(all_lines) - 1)
    inputs.close()

    with open('./tmp2/conn.csv', 'w') as out:
        for line in all_lines:
            out.write(line.strip() + '\n')
    try:
        nw.solve('offdesign', design_path='tmp')
    except hlp.TESPyNetworkError:
        pass

    shutil.rmtree('./tmp', ignore_errors=True)
    shutil.rmtree('./tmp2', ignore_errors=True)
Ejemplo n.º 12
0
 def setup(self):
     self.nw = nwk.network(['TESPy::fuel', 'TESPy::fuel_fg', 'Air'])
     self.comb = cmp.combustion_chamber_stoich('combustion chamber')
     c1 = con.connection(cmp.source('air'), 'out1', self.comb, 'in1')
     c2 = con.connection(cmp.source('fuel'), 'out1', self.comb, 'in2')
     c3 = con.connection(self.comb, 'out1', cmp.sink('flue gas'), 'in1')
     self.nw.add_conns(c1, c2, c3)
Ejemplo n.º 13
0
def test_network_mode():
    nw = nwk.network(['water'])
    source = cmp.source('source')
    sink = cmp.sink('sink')
    a = con.connection(source, 'out1', sink, 'in1')
    nw.add_conns(a)
    nw.solve('ofdesign')
Ejemplo n.º 14
0
def test_network_linear_dependency():
    nw = nwk.network(['water'])
    source = cmp.source('source')
    sink = cmp.sink('sink')
    a = con.connection(source, 'out1', sink, 'in1', m=1, p=1e5, h=1e6, x=1)
    nw.add_conns(a)
    nw.solve('design')
    eq_(nw.lin_dep, True, 'This test must result in a linear dependency of the jacobian matrix.')
Ejemplo n.º 15
0
 def setup(self):
     self.nw = nwk.network(
         ['INCOMP::DowQ', 'H2O', 'NH3', 'N2', 'O2', 'Ar', 'CO2', 'CH4'],
         T_unit='C',
         p_unit='bar',
         v_unit='m3 / s')
     self.source = cmp.source('source')
     self.sink = cmp.sink('sink')
Ejemplo n.º 16
0
def test_network_connection_error_target():
    nw = nwk.network(['water'])
    source1 = cmp.source('source1')
    source2 = cmp.source('source2')
    sink = cmp.sink('sink')
    a = con.connection(source1, 'out1', sink, 'in1')
    b = con.connection(source2, 'out1', sink, 'in1')
    nw.add_conns(a, b)
    nw.check_network()
Ejemplo n.º 17
0
def test_network_connection_error_source():
    nw = nwk.network(['water'])
    source = cmp.source('source')
    sink1 = cmp.sink('sink1')
    sink2 = cmp.sink('sink2')
    a = con.connection(source, 'out1', sink1, 'in1')
    b = con.connection(source, 'out1', sink2, 'in1')
    nw.add_conns(a, b)
    nw.check_network()
Ejemplo n.º 18
0
def test_network_max_iter():
    nw = nwk.network(['water'])
    source = cmp.source('source')
    pipe = cmp.pipe('pipe', pr=1, Q=100e3)
    sink = cmp.sink('sink')
    a = con.connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=280, fluid={'water': 1})
    b = con.connection(pipe, 'out1', sink, 'in1')
    nw.add_conns(a, b)
    nw.solve('design', max_iter=2)
    eq_(nw.max_iter, nw.iter + 1, 'This test must result in the itercount being equal to the max iter statement.')
Ejemplo n.º 19
0
def test_network_no_progress():
    nw = nwk.network(['water'])
    source = cmp.source('source')
    pipe = cmp.pipe('pipe', pr=1, Q=-100e3)
    sink = cmp.sink('sink')
    a = con.connection(source, 'out1', pipe, 'in1', m=1, p=1e5, T=280, fluid={'water': 1})
    b = con.connection(pipe, 'out1', sink, 'in1')
    nw.add_conns(a, b)
    nw.solve('design')
    eq_(nw.progress, False, 'This test must result in a calculation making no progress, as the pipe\'s outlet enthalpy is below fluid property range.')
Ejemplo n.º 20
0
 def test_combustion_chamber_missing_fuel(self):
     """
     Test no fuel in network.
     """
     nw = nwk.network(['H2O', 'N2', 'O2', 'Ar', 'CO2'])
     comb = cmp.combustion_chamber('combustion chamber')
     c1 = con.connection(cmp.source('air'), 'out1', comb, 'in1')
     c2 = con.connection(cmp.source('fuel'), 'out1', comb, 'in2')
     c3 = con.connection(comb, 'out1', cmp.sink('flue gas'), 'in1')
     nw.add_conns(c1, c2, c3)
     nw.solve('design', init_only=True)
Ejemplo n.º 21
0
from tespy import cmp, con, nwk

# %% network

nw = nwk.network(fluids=['water', 'NH3'],
                 T_unit='C',
                 p_unit='bar',
                 h_unit='kJ / kg',
                 m_unit='kg / s',
                 p_range=[0.1, 100],
                 T_range=[1, 500],
                 h_range=[15, 5000])

# %% components

# sources & sinks

c_in = cmp.source('coolant in')
cb = cmp.source('consumer back flow')
cf = cmp.sink('consumer feed flow')
amb_in = cmp.source('source ambient')
amb_out = cmp.sink('sink ambient')

cp1 = cmp.sink('compressor 1')

# consumer system

cd = cmp.condenser('condenser')
rp = cmp.pump('recirculation pump')
cons = cmp.heat_exchanger_simple('consumer')
Ejemplo n.º 22
0
# -*- coding: utf-8 -*-

from tespy import con, cmp, nwk
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# %% network

fluids = ['water']

nw = nwk.network(fluids=fluids, p_unit='bar', T_unit='C', h_unit='kJ / kg')

# %% components

# turbine part
valve_turb = cmp.valve(label='valve_turb')
turbine_hp = cmp.turbine(label='turbine_hp')
split = cmp.splitter(label='splitter1')
turbine_lp = cmp.turbine(label='turbine_lp')

# condenser and preheater
condenser = cmp.condenser(label='condenser')
preheater = cmp.condenser(label='preheater')
valve_pre = cmp.valve(label='valve_pre')
valve = cmp.valve(label='valve1')
merge = cmp.merge(label='merge1')

# feed water
pump = cmp.pump(label='pump')
steam_generator = cmp.heat_exchanger_simple(label='steam generator')
Ejemplo n.º 23
0
    def __init__(self,
                 press_in=0,
                 press_out=0,
                 temp_in=0,
                 temp_out=0,
                 overh=0,
                 enth_in=0,
                 enth_out=0,
                 entr_in=0,
                 entr_out=0,
                 work_fl='',
                 mass_fl=0,
                 pr=0,
                 q_cap=0,
                 heat_cap=0,
                 amb_press_in=0,
                 amb_press_out=0,
                 amb_temp_in=0,
                 amb_temp_out=0,
                 pinch_point=0,
                 amb_enth_in=0,
                 amb_enth_out=0,
                 amb_entr_in=0,
                 amb_entr_out=0,
                 amb_work_fl='',
                 amb_mass_fl=0,
                 amb_pr=0,
                 cycle_name='',
                 use_aspen=False,
                 exer_in=0,
                 exer_out=0,
                 amb_exer_in=0,
                 amb_exer_out=0):

        super().__init__(press_in, press_out, temp_in, temp_out, enth_in,
                         enth_out, entr_in, entr_out, work_fl, mass_fl,
                         cycle_name)
        self.q_cap = q_cap
        self.heat_cap = heat_cap
        self.pr = pr
        self.amb_enth_in = amb_enth_in
        self.amb_enth_out = amb_enth_out
        self.amb_press_in = amb_press_in
        self.amb_press_out = amb_press_out
        self.amb_temp_in = amb_temp_in
        self.amb_temp_out = amb_temp_out
        self.amb_entr_in = amb_entr_in
        self.amb_entr_out = amb_entr_out
        self.pinch_point = pinch_point
        self.overh = overh
        self.amb_work_fl = amb_work_fl
        self.amb_mass_fl = amb_mass_fl
        self.amb_pr = amb_pr
        self.is_model_correct = True
        self.use_aspen = use_aspen
        self.exer_in = exer_in
        self.exer_out = exer_out
        self.amb_exer_in = amb_exer_in
        self.amb_exer_out = amb_exer_out

        # Applying the condenser model using TESPy. Firstly the components and connections must be set, afterwards
        # the function will set the attributes and TESPy engine will calculate the demanded result.
        # Setting components:
        self.amb_inlet = cmp.sink('inlet of ambient')
        self.amb_outlet = cmp.source('outlet of ambient')
        self.cycle_inlet = cmp.sink('inlet of cycle')
        self.cycle_outlet = cmp.source('outlet of cycle')
        self.evaporator = cmp.heat_exchanger('evaporator')

        # Setting connections between components:
        self.amb_evap = con.connection(self.amb_outlet, 'out1',
                                       self.evaporator, 'in1')
        self.evap_amb = con.connection(self.evaporator, 'out1', self.amb_inlet,
                                       'in1')
        self.cycle_evap = con.connection(self.cycle_outlet, 'out1',
                                         self.evaporator, 'in2')
        self.evap_cycle = con.connection(self.evaporator, 'out2',
                                         self.cycle_inlet, 'in1')

        if self.work_fl == '' or self.amb_work_fl == '':
            print(
                "Working fluid or the ambient working fluid hasn't been set, so creating the TESPy network model"
                "can't be completed.\n")
        else:
            # Putting the connections into the network (TESPy):
            # Because TESPy isn't smart enough and it throws error when the working fluid in the cycle
            # is the same as the one in ambient,
            # it is necessary to make a division of initialization of network basic attributes:
            if self.work_fl == self.amb_work_fl:
                self.nw = nwk.network(fluids=[self.work_fl],
                                      T_unit='K',
                                      p_unit='Pa',
                                      h_unit='J / kg')
            else:
                self.nw = nwk.network(fluids=[self.work_fl, self.amb_work_fl],
                                      T_unit='K',
                                      p_unit='Pa',
                                      h_unit='J / kg')
            self.nw.set_printoptions(print_level='none')
            self.nw.add_conns(self.amb_evap, self.evap_amb, self.cycle_evap,
                              self.evap_cycle)
Ejemplo n.º 24
0
def test_network_no_connections_error():
    nw = nwk.network(['water'])
    nw.solve('design')
Ejemplo n.º 25
0
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  4 10:37:36 2017

@author: witte
"""

from tespy import con, cmp, nwk
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd

# %% network

fluid_list = ['H2O']
nw = nwk.network(fluids=fluid_list, p_unit='bar', T_unit='C')

# %% components

# sinks & sources
back = cmp.source('to collector')
feed = cmp.sink('from collector')

# collector
coll = cmp.solar_collector(label='solar thermal collector')

# %% connections

b_c = con.connection(back, 'out1', coll, 'in1')
c_f = con.connection(coll, 'out1', feed, 'in1')
Ejemplo n.º 26
0
p_after_pump = 11.8

mass_flow_rate_air = 6142
T_air = -4.7
p_air = 0.61

mass_flow_rate_brine = 3.4199e2
T_brine_in = 146.6
p_brine_in = 9.4
T_brine_out = 69.1

# calculation
T_before_turbine = PropsSI('T', 'P', p_after_pump*0.957627118*0.955752212*1e5, 'Q', 1, 'Isopentane')-273.15+2.3
# basic network
nw = nwk.network(fluids=fluids)
nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg')
# main components
condenser = cmp.condenser('condenser')
ihe = cmp.heat_exchanger('internal heat exchanger')
pump = cmp.pump('feeding pump')
turbine = cmp.turbine('turbine')
p_and_e = cmp.heat_exchanger('preheater and evaporator')
# cooling air
source_ca = cmp.source('cooling air source')
sink_ca = cmp.sink('cooling air sink')
#brine
source_b = cmp.source('brine source')
sink_b = cmp.sink('brine sink')
# working fluid
source_wf_1 = cmp.source('working fluid source before turbine')
Ejemplo n.º 27
0
from tespy import nwk, con, cmp, hlp
import numpy as np
from matplotlib import pyplot as plt

nw = nwk.network(['water'], p_unit='bar', T_unit='C', h_unit='kJ / kg')

# %% components
pipe = cmp.pipe('pipe')
pipe2 = cmp.pipe('pipe2')
pipe3 = cmp.pipe('pipe3')
pipe4 = cmp.pipe('pipe4')
pipe5 = cmp.pipe('pipe5')
pipe6 = cmp.pipe('pipe6')
sink = cmp.sink('sink')
source = cmp.source('source')

# %% connections

a = con.connection(source, 'out1', pipe, 'in1')
b = con.connection(pipe, 'out1', pipe2, 'in1')
c = con.connection(pipe2, 'out1', pipe3, 'in1')
d = con.connection(pipe3, 'out1', pipe4, 'in1')
e = con.connection(pipe4, 'out1', pipe5, 'in1')
f = con.connection(pipe5, 'out1', pipe6, 'in1')
g = con.connection(pipe6, 'out1', sink, 'in1')

nw.add_conns(a, b, c, d, e, f, g)

# %% connection parameters

a.set_attr(h=40, fluid={'water': 1}, p=1, m=10)
Ejemplo n.º 28
0
    def __init__(self,
                 press_in=0,
                 press_out=0,
                 temp_in=0,
                 temp_out=0,
                 enth_in=0,
                 enth_out=0,
                 entr_in=0,
                 entr_out=0,
                 work_fl='',
                 pr=0,
                 heat_val=0,
                 mass_fl=0,
                 temp_cond=0,
                 overcool=0,
                 amb_press_in=0,
                 amb_press_out=0,
                 amb_temp_in=0,
                 amb_temp_out=0,
                 amb_enth_in=0,
                 amb_enth_out=0,
                 amb_work_fl='',
                 amb_mass_fl=0,
                 amb_pr=0,
                 cycle_name=''):

        super().__init__(press_in, press_out, temp_in, temp_out, enth_in,
                         enth_out, entr_in, entr_out, work_fl, mass_fl,
                         cycle_name)
        self.heat_val = heat_val
        self.pr = pr
        self.temp_cond = temp_cond
        self.overcool = overcool
        if temp_out == 0 and enth_out == 0:
            self.temp_out = self.temp_cond - self.overcool
            if self.temp_cond == 0 or self.overcool == 0:
                print(
                    "Condenser.__init__(): The value of temp_out hasn't been declared. Therefore it was initialized"
                    "as: temp_cond minus overcool. It seems however, that one of these values equals 0."
                )
        self.amb_enth_in = amb_enth_in
        self.amb_enth_out = amb_enth_out
        self.amb_press_in = amb_press_in
        self.amb_press_out = amb_press_out
        self.amb_temp_in = amb_temp_in
        self.amb_temp_out = amb_temp_out
        self.amb_work_fl = amb_work_fl
        self.amb_mass_fl = amb_mass_fl
        self.amb_pr = amb_pr
        # For checking if the values are appropriate in function set_attr_pow_cyc():
        self.approved = False

        # Applying the condenser model using TESPy. Firstly the components and connections must be set, afterwards
        # the function will set the attributes and TESPy solver will calculate the demanded result.
        # Setting components:
        self.amb_inlet = cmp.sink("inlet of ambient")
        self.amb_outlet = cmp.source("outlet of ambient")
        self.cycle_inlet = cmp.sink("inlet of cycle")
        self.cycle_outlet = cmp.source("outlet of cycle")
        self.condenser = cmp.heat_exchanger("condenser")

        # Setting connections between components:
        self.amb_cond = con.connection(self.amb_outlet, 'out1', self.condenser,
                                       'in2')
        self.cond_amb = con.connection(self.condenser, 'out2', self.amb_inlet,
                                       'in1')
        self.cycle_cond = con.connection(self.cycle_outlet, 'out1',
                                         self.condenser, 'in1')
        self.cond_cycle = con.connection(self.condenser, 'out1',
                                         self.cycle_inlet, 'in1')

        if self.work_fl == '' or self.amb_work_fl == '':
            print(
                "Working fluid or the ambient working fluid hasn't been set, so creating the TESPy network model"
                "can't be completed.\n")
        else:
            # Putting the connections into the network (TESPy):
            # Because TESPy isn't smart enough and it throws error when the working fluid in the cycle
            # is the same as the one in ambient,
            # it is necessary to make a division of initialization of network basic attributes:
            if self.work_fl == self.amb_work_fl:
                self.nw = nwk.network(fluids=[self.work_fl],
                                      T_unit='K',
                                      p_unit='Pa',
                                      h_unit='J / kg')
            else:
                self.nw = nwk.network(fluids=[self.work_fl, self.amb_work_fl],
                                      T_unit='K',
                                      p_unit='Pa',
                                      h_unit='J / kg')

            self.nw.set_printoptions(print_level='none')
            self.nw.add_conns(self.amb_cond, self.cond_amb, self.cycle_cond,
                              self.cond_cycle)
Ejemplo n.º 29
0
"""
Created on Mon Jul 16 08:44:36 2018

@author: witte
"""

from tespy import cmp, con, nwk, hlp

import numpy as np
import pandas as pd

# %% network

nw = nwk.network(fluids=['water', 'NH3', 'air'],
                 T_unit='C',
                 p_unit='bar',
                 h_unit='kJ / kg',
                 m_unit='kg / s')

# %% components

# sources & sinks
c_in = cmp.source('coolant in')
cb = cmp.source('consumer back flow')
cf = cmp.sink('consumer feed flow')
amb = cmp.source('ambient air')
amb_out1 = cmp.sink('sink ambient 1')
amb_out2 = cmp.sink('sink ambient 2')
c_out = cmp.sink('coolant out')

# ambient air system
Ejemplo n.º 30
0
 def setup(self):
     self.nw = nwk.network(['water', 'air'])
     self.comp = cmp.cogeneration_unit('cogeneration unit')
     self.bus = con.bus('power')
     self.bus.add_comps({'c': self.comp, 'p': 'Param'})