Skip to content

Commit

Permalink
added __init__.py for submodule components
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Jan 30, 2018
1 parent 9ff537c commit 7eb61fa
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 58 deletions.
4 changes: 4 additions & 0 deletions tespy/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
.. moduleauthor:: Francesco Witte <francesco.witte@hs-flensburg.de>
"""
6 changes: 0 additions & 6 deletions tespy/components/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
)

from tespy.components import characteristics as cmp_char
#
#from numba import double
#from numba.decorators import jit, autojit
#
#s_mix_pT = autojit(s_mix_pT)
#h_mix_pT = autojit(h_mix_pT)


def init_target(nw, c, start):
Expand Down
80 changes: 40 additions & 40 deletions tespy/components/subsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from tespy import networks as nwk
from tespy.connections import connection, ref
from tespy.components import components as comp
from tespy.components import components as cmp


class subsystem:
Expand Down Expand Up @@ -146,7 +146,7 @@ def from_network(self, nw):
num_inter = 0
for c in nw.conns.index:
self.nw.add_conns(c)
if isinstance(c, comp.subsys_interface):
if isinstance(c, cmp.subsys_interface):
num_inter += 1

if num_inter != 2:
Expand Down Expand Up @@ -221,13 +221,13 @@ def create_comps(self):

self.num_i = 2
self.num_o = 2
self.inlet = comp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = comp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.pump = comp.pump(label=self.label + '_pump')
self.drum = comp.drum(label=self.label + '_drum')
self.evaporator = comp.heat_exchanger(label=self.label + '_evaporator')
self.inlet = cmp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = cmp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.pump = cmp.pump(label=self.label + '_pump')
self.drum = cmp.drum(label=self.label + '_drum')
self.evaporator = cmp.heat_exchanger(label=self.label + '_evaporator')

def set_comps(self):

Expand Down Expand Up @@ -287,13 +287,13 @@ def create_comps(self):

self.num_i = 2
self.num_o = 2
self.inlet = comp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = comp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.drum = comp.drum(label=self.label + '_drum')
self.evaporator = comp.heat_exchanger(label=self.label + '_evaporator',
mode='man')
self.inlet = cmp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = cmp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.drum = cmp.drum(label=self.label + '_drum')
self.evaporator = cmp.heat_exchanger(label=self.label + '_evaporator',
mode='man')

def set_comps(self):

Expand Down Expand Up @@ -351,13 +351,13 @@ def create_comps(self):

self.num_i = 2
self.num_o = 2
self.inlet = comp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = comp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.desup = comp.desuperheater(label=self.label + '_desup')
self.condenser = comp.condenser(label=self.label + '_condenser')
self.vessel = comp.vessel(label=self.label + '_vessel', mode='man')
self.inlet = cmp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = cmp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.desup = cmp.desuperheater(label=self.label + '_desup')
self.condenser = cmp.condenser(label=self.label + '_condenser')
self.vessel = cmp.vessel(label=self.label + '_vessel', mode='man')

def set_comps(self):

Expand Down Expand Up @@ -394,14 +394,14 @@ def create_comps(self):

self.num_i = 2
self.num_o = 2
self.inlet = comp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = comp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.desup = comp.desuperheater(label=self.label + '_desup')
self.condenser = comp.condenser(label=self.label + '_condenser')
self.subcooler = comp.heat_exchanger(label=self.label + '_subcooler')
self.vessel = comp.vessel(label=self.label + '_vessel', mode='man')
self.inlet = cmp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = cmp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.desup = cmp.desuperheater(label=self.label + '_desup')
self.condenser = cmp.condenser(label=self.label + '_condenser')
self.subcooler = cmp.heat_exchanger(label=self.label + '_subcooler')
self.vessel = cmp.vessel(label=self.label + '_vessel', mode='man')

def set_comps(self):

Expand Down Expand Up @@ -444,15 +444,15 @@ def create_comps(self):

self.num_i = 3
self.num_o = 2
self.inlet = comp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = comp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.desup = comp.desuperheater(label=self.label + '_desup')
self.condenser = comp.condenser(label=self.label + '_condenser')
self.subcooler = comp.heat_exchanger(label=self.label + '_subcooler')
self.vessel = comp.vessel(label=self.label + '_vessel', mode='man')
self.merge = comp.merge(label=self.label + '_merge')
self.inlet = cmp.subsys_interface(label=self.label + '_inlet',
num_inter=self.num_i)
self.outlet = cmp.subsys_interface(label=self.label + '_outlet',
num_inter=self.num_o)
self.desup = cmp.desuperheater(label=self.label + '_desup')
self.condenser = cmp.condenser(label=self.label + '_condenser')
self.subcooler = cmp.heat_exchanger(label=self.label + '_subcooler')
self.vessel = cmp.vessel(label=self.label + '_vessel', mode='man')
self.merge = cmp.merge(label=self.label + '_merge')

def set_comps(self):

Expand Down
48 changes: 38 additions & 10 deletions tespy/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class connection:
- T (*numeric*, *ref object*)
- x (*numeric*)
- fluid (*dict*), fluid_balance (*bool*)
- design (*list*), offdesign (*list*)
**(off-)design parameters**
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. :code:`design=['T', 'p']`, are unset in any offdesign
calculation, parameters given in 'offdesign' are set for offdesign
calculation.
.. note::
The fluid balance parameter applies a balancing of the fluid vector on
Expand All @@ -64,9 +73,6 @@ class connection:
**improvements**
- add a "design" attribute, specifing the attributes of the connections
to be set "False" in offdesing calculation
"""
def __init__(self, comp1, outlet_id, comp2, inlet_id, **kwargs):

Expand Down Expand Up @@ -121,20 +127,31 @@ def __init__(self, comp1, outlet_id, comp2, inlet_id, **kwargs):
self.T_set = False
self.x_set = False

self.design = kwargs.get('design', [])
self.design = []
self.offdesign = []

# setters for specified values
for key in kwargs:
if (isinstance(kwargs[key], float) or
isinstance(kwargs[key], int) or
isinstance(kwargs[key], ref)):
isinstance(kwargs[key], int) or
isinstance(kwargs[key], ref)):
self.__dict__.update({key + '_set': True})
if key == 'fluid':
for fluid, x in sorted(kwargs[key].items()):
self.fluid[fluid] = x
self.fluid_set[fluid] = True
if key == 'fluid_balance':
self.fluid_balance = kwargs[key]
if key == 'design' or key == 'offdesign':
if not isinstance(self.design, list):
msg = 'Please provide the design parameters as list!'
raise ValueError(msg)
if set(kwargs[key]).issubset(self.attr()):
self.__dict__.update({key: kwargs[key]})
else:
msg = ('Available parameters for (off-)design'
'specification are: ' + str(self.attr()) + '.')
raise ValueError(msg)

if self.m_set and not isinstance(self.m, ref):
self.m0 = self.m
Expand All @@ -153,13 +170,24 @@ def set_attr(self, **kwargs):
if key not in self.attr():
invalid_keys = np.append(invalid_keys, key)
if (isinstance(kwargs[key], float) or
isinstance(kwargs[key], int) or
isinstance(kwargs[key], ref)):
isinstance(kwargs[key], int) or
isinstance(kwargs[key], ref)):
self.__dict__.update({key: kwargs[key]})
if isinstance(kwargs[key], ref):
self.__dict__.update({key + '_set': True})
elif key == 'fluid_balance':
self.fluid_balance = kwargs[key]
elif key == 'design' or key == 'offdesign':
if not isinstance(self.design, list):
msg = ('Please provide the (off-)design parameters as'
' list!')
raise ValueError(msg)
if set(kwargs[key]).issubset(self.attr()):
self.__dict__.update({key: kwargs[key]})
else:
msg = ('Available parameters for (off-)design'
'specification are: ' + str(self.attr()) + '.')
raise ValueError(msg)
else:
if np.isnan(kwargs[key]):
self.__dict__.update({key + '_set': False})
Expand Down Expand Up @@ -201,7 +229,7 @@ def attr(self):
:returns: list object
"""
return ['m', 'p', 'h', 'T', 'x', 'm0', 'p0', 'h0', 'fluid',
'fluid_balance']
'fluid_balance', 'design', 'offdesign']

def as_list(self):
"""
Expand Down Expand Up @@ -274,7 +302,7 @@ def check_comp(self, comp):
for c in self.comps.index:
if type(comp) != type(c):
if (type(comp).__bases__[0] == type(c).__bases__[0] and
type(comp).__bases__[0] == cmp.component):
type(comp).__bases__[0] == cmp.component):

if type(c).__bases__[0] == cmp.component:
msg = ('Error adding component to power bus. '
Expand Down
1 change: 0 additions & 1 deletion tespy/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import math
import numpy as np
import pandas as pd
import sys

from scipy.optimize import fsolve
Expand Down
1 change: 0 additions & 1 deletion tespy/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from tespy.components import components as cmp
from tespy import connections as con

from tespy import helpers as hlp

import matplotlib.pyplot as plt
Expand Down

0 comments on commit 7eb61fa

Please sign in to comment.