Skip to content

Commit

Permalink
Merge branch 'features/data_container' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Jul 3, 2018
2 parents 65ce54c + 679b6f0 commit 83c9ff4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 36 deletions.
106 changes: 71 additions & 35 deletions tespy/components/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
h_ps, s_ph,
molar_massflow, lamb,
molar_masses, err,
dc_cp, dc_cc
dc_cp, dc_cc, dc_gcp
)

from tespy.components import characteristics as cmp_char
Expand Down Expand Up @@ -153,7 +153,8 @@ def set_attr(self, **kwargs):

# data container specification
if (isinstance(kwargs[key], dc_cp) or
isinstance(kwargs[key], dc_cc)):
isinstance(kwargs[key], dc_cc) or
isinstance(kwargs[key], dc_gcp)):
self.__dict__.update({key: kwargs[key]})

elif isinstance(self.get_attr(key), dc_cp):
Expand Down Expand Up @@ -185,7 +186,8 @@ def set_attr(self, **kwargs):
msg = 'Bad datatype for keyword argument ' + str(key)
raise TypeError(msg)

elif isinstance(self.get_attr(key), dc_cc):
elif (isinstance(self.get_attr(key), dc_cc) or
isinstance(self.get_attr(key), dc_gcp)):
# value specification for component characteristics
if isinstance(kwargs[key], str):
self.get_attr(key).set_attr(method=kwargs[key])
Expand Down Expand Up @@ -4607,17 +4609,55 @@ def comp_init(self, nw):
self.t_a_design.val_SI = ((self.t_a_design.val + nw.T[nw.T_unit][0]) *
nw.T[nw.T_unit][1])

# parameters for hydro group
self.hydro_group.set_attr(elements=[self.L, self.ks, self.D])

is_set = True
for e in self.hydro_group.elements:
if not e.is_set:
is_set = False

if is_set:
self.hydro_group.set_attr(is_set=True)
elif self.hydro_group.is_set:
msg = ('All parameters of the component group have to be '
'specified! This component group uses the following '
'parameters: L, ks, D')
raise MyComponentError(msg)
else:
self.hydro_group.set_attr(is_set=False)

# parameters for kA group
self.kA_group.set_attr(elements=[self.kA, self.t_a])

is_set = True
for e in self.kA_group.elements:
if not e.is_set:
is_set = False

if is_set:
self.kA_group.set_attr(is_set=True)
elif self.kA_group.is_set:
msg = ('All parameters of the component group have to be '
'specified! This component group uses the following '
'parameters: kA, t_a')
raise MyComponentError(msg)
else:
self.kA_group.set_attr(is_set=False)

def attr(self):
return ['Q', 'pr', 'zeta', 'D', 'L', 'ks',
'kA', 't_a', 't_a_design', 'kA_char','hydro_char',
'SQ1', 'SQ2', 'Sirr']
'kA', 't_a', 't_a_design', 'kA_char',
'SQ1', 'SQ2', 'Sirr',
'hydro_group', 'kA_group']

def attr_prop(self):
return {'Q': dc_cp(), 'pr': dc_cp(), 'zeta': dc_cp(),
'D': dc_cp(), 'L': dc_cp(), 'ks': dc_cp(),
'kA': dc_cp(), 't_a': dc_cp(), 't_a_design': dc_cp(),
'kA_char': dc_cc(method='HE_HOT', param='m'),
'SQ1': dc_cp(), 'SQ2': dc_cp(), 'Sirr': dc_cp(), 'hydro_char':dc_cc()}
'SQ1': dc_cp(), 'SQ2': dc_cp(), 'Sirr': dc_cp(),
'hydro_group': dc_gcp(), 'kA_group': dc_gcp()}

def default_design(self):
return ['pr']
Expand Down Expand Up @@ -4680,13 +4720,15 @@ def equations(self, nw):
if self.zeta.is_set:
vec_res += [self.zeta_func(inl, outl)]

if self.ks.is_set and self.D.is_set and self.L.is_set:
if self.hydro_char.method == 'HW':
vec_res += [self.hw_func(inl, outl)]
if self.hydro_group.is_set:
if self.hydro_group.method == 'HW':
func = self.hw_func
else:
vec_res += [self.lamb_func(inl, outl)]
func = self.lamb_func

if self.kA.is_set and self.t_a.is_set:
vec_res += [func(inl, outl)]

if self.kA_group.is_set:
vec_res += [self.kA_func(inl, outl)]

return vec_res
Expand Down Expand Up @@ -4735,31 +4777,25 @@ def derivatives(self, nw):
self.ddx_func(inl, outl, self.zeta_func, 'h', i))
mat_deriv += zeta_deriv.tolist()

if self.ks.is_set and self.D.is_set and self.L.is_set:
if self.hydro_char.method == 'HW':
hw_deriv = np.zeros((1, num_i + num_o, num_fl + 3))
for i in range(2):
if i == 0:
hw_deriv[0, i, 0] = (
self.ddx_func(inl, outl, self.hw_func, 'm', i))
hw_deriv[0, i, 1] = (
self.ddx_func(inl, outl, self.hw_func, 'p', i))
hw_deriv[0, i, 2] = (
self.ddx_func(inl, outl, self.hw_func, 'h', i))
mat_deriv += hw_deriv.tolist()
if self.hydro_group.is_set:
if self.hydro_group.method == 'HW':
func = self.hw_func
else:
lamb_deriv = np.zeros((1, num_i + num_o, num_fl + 3))
for i in range(2):
if i == 0:
lamb_deriv[0, i, 0] = (
self.ddx_func(inl, outl, self.lamb_func, 'm', i))
lamb_deriv[0, i, 1] = (
self.ddx_func(inl, outl, self.lamb_func, 'p', i))
lamb_deriv[0, i, 2] = (
self.ddx_func(inl, outl, self.lamb_func, 'h', i))
mat_deriv += lamb_deriv.tolist()

if self.kA.is_set and self.t_a.is_set:
func = self.lamb_func

deriv = np.zeros((1, num_i + num_o, num_fl + 3))
for i in range(2):
if i == 0:
deriv[0, i, 0] = (
self.ddx_func(inl, outl, func, 'm', i))
deriv[0, i, 1] = (
self.ddx_func(inl, outl, func, 'p', i))
deriv[0, i, 2] = (
self.ddx_func(inl, outl, func, 'h', i))
mat_deriv += deriv.tolist()

if self.kA_group.is_set:

kA_deriv = np.zeros((1, num_i + num_o, num_fl + 3))
kA_deriv[0, 0, 0] = self.ddx_func(inl, outl, self.kA_func, 'm', 0)
for i in range(2):
Expand Down
17 changes: 16 additions & 1 deletion tespy/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def attr(self):
class dc_cp(data_container):
"""r
data container for component parameters
data container for component properties
- val (*numeric*) - user specified value
- val_SI (*numeric*) - value in SI units
Expand Down Expand Up @@ -185,6 +185,21 @@ def attr(self):
'method': 'default', 'param': None,
'x': None, 'y': None}


class dc_gcp(data_container):
"""r
data container for grouped component properties
- is_set (*bool*) - is the group set
- method (*str*) - calculation method for identical property groups
- elements (*list*) - list of elements for this group, if you want to make
use of a group, every element's is_set value must be True.
"""
def attr(self):
return {'is_set': False, 'method': 'default', 'elements': []}

# %%


Expand Down

0 comments on commit 83c9ff4

Please sign in to comment.