Example #1
0
def test_set_attr_errors():
    """Test errors of set_attr methods."""
    nw = network(['water', 'air'])
    comb = combustion.combustion_engine('combustion engine')
    pipeline = piping.pipe('pipeline')
    conn = connection(comb, 'out1', pipeline, 'in1')
    mybus = bus('mybus')

    # ValueErrors
    set_attr_ValueError(comb, offdesign=['Q'])

    set_attr_ValueError(conn, offdesign=['f'])

    set_attr_ValueError(nw, m_unit='kg')
    set_attr_ValueError(nw, h_unit='kg')
    set_attr_ValueError(nw, p_unit='kg')
    set_attr_ValueError(nw, T_unit='kg')
    set_attr_ValueError(nw, v_unit='kg')
    set_attr_ValueError(conn, state=5)

    # TypeErrors
    set_attr_TypeError(comb, P=[5])
    set_attr_TypeError(comb, tiP_char=7)
    set_attr_TypeError(comb, design='f')
    set_attr_TypeError(comb, lamb=dc_cc())
    set_attr_TypeError(comb, design_path=7)
    set_attr_TypeError(comb, local_design=5)
    set_attr_TypeError(comb, local_offdesign=5)
    set_attr_TypeError(pipeline, hydro_group=5)
    set_attr_TypeError(comb, printout=5)

    set_attr_TypeError(conn, design='h')
    set_attr_TypeError(conn, fluid_balance=1)
    set_attr_TypeError(conn, h0=[4])
    set_attr_TypeError(conn, fluid=5)
    set_attr_TypeError(conn, design_path=5)
    set_attr_TypeError(conn, local_design=5)
    set_attr_TypeError(conn, local_offdesign=5)
    set_attr_TypeError(conn, printout=5)
    set_attr_TypeError(conn, label=5)
    set_attr_TypeError(conn, state='f')

    set_attr_TypeError(nw, m_range=5)
    set_attr_TypeError(nw, p_range=5)
    set_attr_TypeError(nw, h_range=5)
    set_attr_TypeError(nw, iterinfo=5)
    set_attr_TypeError(mybus, P='some value')
    set_attr_TypeError(mybus, printout=5)

    # KeyErrors
    set_attr_KeyError(dc_cc(), x=7)
    set_attr_KeyError(comb, wow=5)
    set_attr_KeyError(conn, jey=5)
    set_attr_KeyError(mybus, power_output=100000)

    # NotImplementedError
    set_attr_NotImplementedError(conn, Td_bp=ref(conn, 1, 0))
Example #2
0
 def get_variables(self):
     return {
         'pr':
         dc_cp(min_val=1e-4,
               max_val=1,
               num_eq=1,
               deriv=self.pr_deriv,
               func=self.pr_func,
               func_params={'pr': 'pr'},
               latex=self.pr_func_doc),
         'zeta':
         dc_cp(min_val=0,
               max_val=1e15,
               num_eq=1,
               deriv=self.zeta_deriv,
               func=self.zeta_func,
               func_params={'zeta': 'zeta'},
               latex=self.zeta_func_doc),
         'dp_char':
         dc_cc(param='m',
               num_eq=1,
               deriv=self.dp_char_deriv,
               func=self.dp_char_func,
               char_params={'type': 'abs'},
               latex=self.dp_char_func_doc)
     }
Example #3
0
 def attr():
     return {
         'pr': dc_cp(min_val=1e-4, max_val=1),
         'zeta': dc_cp(min_val=0),
         'dp_char': dc_cc(param='m'),
         'Sirr': dc_simple()
     }
Example #4
0
 def get_variables(self):
     return {
         'P':
         dc_cp(max_val=0,
               num_eq=1,
               deriv=self.energy_balance_deriv,
               func=self.energy_balance_func,
               latex=self.energy_balance_func_doc),
         'eta_s':
         dc_cp(min_val=0,
               max_val=1,
               num_eq=1,
               deriv=self.eta_s_deriv,
               func=self.eta_s_func,
               latex=self.eta_s_func_doc),
         'eta_s_char':
         dc_cc(param='m',
               num_eq=1,
               deriv=self.eta_s_char_deriv,
               func=self.eta_s_char_func,
               latex=self.eta_s_char_func_doc),
         'pr':
         dc_cp(min_val=0,
               max_val=1,
               num_eq=1,
               deriv=self.pr_deriv,
               func=self.pr_func,
               func_params={'pr': 'pr'},
               latex=self.pr_func_doc),
         'cone':
         dc_simple(deriv=self.cone_deriv,
                   num_eq=1,
                   func=self.cone_func,
                   latex=self.cone_func_doc)
     }
Example #5
0
 def get_variables(self):
     return {
         'P': dc_cp(
             min_val=0, num_eq=1,
             deriv=self.energy_balance_deriv,
             func=self.energy_balance_func,
             latex=self.energy_balance_func_doc),
         'eta_s': dc_cp(
             min_val=0, max_val=1, num_eq=1,
             deriv=self.eta_s_deriv,
             func=self.eta_s_func, latex=self.eta_s_func_doc),
         'eta_s_char': dc_cc(
             param='m', num_eq=1,
             deriv=self.eta_s_char_deriv,
             func=self.eta_s_char_func, latex=self.eta_s_char_func_doc),
         'pr': dc_cp(
             min_val=1, num_eq=1,
             deriv=self.pr_deriv,
             func=self.pr_func, func_params={'pr': 'pr'},
             latex=self.pr_func_doc),
         'igva': dc_cp(min_val=-90, max_val=90, d=1e-3, val=0),
         'char_map_eta_s': dc_cm(),
         'char_map_eta_s_group': dc_gcp(
             elements=['char_map_eta_s', 'igva'], num_eq=1,
             latex=self.char_map_eta_s_func_doc,
             func=self.char_map_eta_s_func,
             deriv=self.char_map_eta_s_deriv),
         'char_map_pr': dc_cm(),
         'char_map_pr_group': dc_gcp(
             elements=['char_map_pr', 'igva'],
             deriv=self.char_map_pr_deriv, num_eq=1,
             func=self.char_map_pr_func, latex=self.char_map_pr_func_doc)
     }
Example #6
0
 def get_variables(self):
     return {
         'Q': dc_cp(
             deriv=self.energy_balance_deriv,
             latex=self.energy_balance_func_doc, num_eq=1,
             func=self.energy_balance_func),
         'pr': dc_cp(
             min_val=1e-4, max_val=1, num_eq=1,
             deriv=self.pr_deriv, latex=self.pr_func_doc,
             func=self.pr_func, func_params={'pr': 'pr'}),
         'zeta': dc_cp(
             min_val=0, max_val=1e15, num_eq=1,
             deriv=self.zeta_deriv, func=self.zeta_func,
             latex=self.zeta_func_doc,
             func_params={'zeta': 'zeta'}),
         'D': dc_cp(min_val=1e-2, max_val=2, d=1e-4),
         'L': dc_cp(min_val=1e-1, d=1e-3),
         'ks': dc_cp(val=1e-4, min_val=1e-7, max_val=1e-3, d=1e-8),
         'kA': dc_cp(min_val=0, d=1),
         'kA_char': dc_cc(param='m'), 'Tamb': dc_cp(),
         'dissipative': dc_simple(val=True),
         'hydro_group': dc_gcp(
             elements=['L', 'ks', 'D'], num_eq=1,
             latex=self.hydro_group_func_doc,
             func=self.hydro_group_func, deriv=self.hydro_group_deriv),
         'kA_group': dc_gcp(
             elements=['kA', 'Tamb'], num_eq=1,
             latex=self.kA_group_func_doc,
             func=self.kA_group_func, deriv=self.kA_group_deriv),
         'kA_char_group': dc_gcp(
             elements=['kA_char', 'Tamb'], num_eq=1,
             latex=self.kA_char_group_func_doc,
             func=self.kA_char_group_func, deriv=self.kA_char_group_deriv)
     }
Example #7
0
 def attr(self):
     return {'P': dc_cp(min_val=0),
             'Q': dc_cp(max_val=0),
             'eta': dc_cp(min_val=0, max_val=1),
             'e': dc_cp(),
             'pr_c': dc_cp(max_val=1),
             'zeta': dc_cp(min_val=0),
             'eta_char': dc_cc(method='GENERIC'),
             'S': dc_simple()}
Example #8
0
 def attr():
     return {'P': dc_cp(min_val=0),
             'Q': dc_cp(max_val=0),
             'eta': dc_cp(min_val=0, max_val=1),
             'e': dc_cp(),
             'pr_c': dc_cp(max_val=1),
             'zeta': dc_cp(min_val=0),
             'eta_char': dc_cc(),
             'S': dc_simple()}
Example #9
0
 def get_variables(self):
     return {
         'Q': dc_cp(
             max_val=0, func=self.energy_balance_hot_func, num_eq=1,
             deriv=self.energy_balance_hot_deriv,
             latex=self.energy_balance_hot_func_doc),
         'kA': dc_cp(
             min_val=0, num_eq=1, func=self.kA_func, latex=self.kA_func_doc,
             deriv=self.kA_deriv),
         'td_log': dc_cp(min_val=0),
         'ttd_u': dc_cp(
             min_val=0, num_eq=1, func=self.ttd_u_func,
             deriv=self.ttd_u_deriv, latex=self.ttd_u_func_doc),
         'ttd_l': dc_cp(
             min_val=0, num_eq=1, func=self.ttd_l_func,
             deriv=self.ttd_l_deriv, latex=self.ttd_l_func_doc),
         'pr1': dc_cp(
             min_val=1e-4, max_val=1, num_eq=1, deriv=self.pr_deriv,
             latex=self.pr_func_doc,
             func=self.pr_func, func_params={'pr': 'pr1'}),
         'pr2': dc_cp(
             min_val=1e-4, max_val=1, num_eq=1, latex=self.pr_func_doc,
             deriv=self.pr_deriv, func=self.pr_func,
             func_params={'pr': 'pr2', 'inconn': 1, 'outconn': 1}),
         'zeta1': dc_cp(
             min_val=0, max_val=1e15, num_eq=1, latex=self.zeta_func_doc,
             deriv=self.zeta_deriv, func=self.zeta_func,
             func_params={'zeta': 'zeta1'}),
         'zeta2': dc_cp(
             min_val=0, max_val=1e15, num_eq=1, latex=self.zeta_func_doc,
             deriv=self.zeta_deriv, func=self.zeta_func,
             func_params={'zeta': 'zeta2', 'inconn': 1, 'outconn': 1}),
         'kA_char': dc_gcc(
             elements=['kA_char1', 'kA_char2'],
             num_eq=1, latex=self.kA_char_func_doc, func=self.kA_char_func,
             deriv=self.kA_char_deriv),
         'kA_char1': dc_cc(param='m'),
         'kA_char2': dc_cc(
             param='m', char_params={
                 'type': 'rel', 'inconn': 1, 'outconn': 1}),
         'subcooling': dc_simple(
             val=False, num_eq=1, latex=self.subcooling_func_doc,
             deriv=self.subcooling_deriv, func=self.subcooling_func)
     }
Example #10
0
 def get_variables(self):
     return {
         'P':
         dc_cp(min_val=0,
               num_eq=1,
               deriv=self.energy_balance_deriv,
               func=self.energy_balance_func,
               latex=self.energy_balance_func_doc),
         'eta_s':
         dc_cp(min_val=0,
               max_val=1,
               num_eq=1,
               deriv=self.eta_s_deriv,
               func=self.eta_s_func,
               latex=self.eta_s_func_doc),
         'pr':
         dc_cp(min_val=1,
               num_eq=1,
               deriv=self.pr_deriv,
               func=self.pr_func,
               func_params={'pr': 'pr'},
               latex=self.pr_func_doc),
         'eta_s_char':
         dc_cc(param='v',
               num_eq=1,
               deriv=self.eta_s_char_deriv,
               func=self.eta_s_char_func,
               latex=self.eta_s_char_func_doc),
         'flow_char':
         dc_cc(param='v',
               num_eq=1,
               deriv=self.flow_char_deriv,
               func=self.flow_char_func,
               char_params={
                   'type': 'abs',
                   'inconn': 0,
                   'outconn': 0
               },
               latex=self.flow_char_func_doc)
     }
Example #11
0
def test_turbine_missing_char_parameter():
    """Turbine with invalid parameter for eta_s_char function."""
    nw = network(['CH4'])
    so = basics.source('source')
    si = basics.sink('sink')
    instance = turbomachinery.turbine('turbine')
    c1 = connection(so, 'out1', instance, 'in1')
    c2 = connection(instance, 'out1', si, 'in1')
    nw.add_conns(c1, c2)
    instance.set_attr(eta_s_char=dc_cc(
        func=char_line([0, 1], [1, 2]), is_set=True, param=None))
    nw.solve('design', init_only=True)
    with raises(ValueError):
        instance.eta_s_char_func()
Example #12
0
def test_compressor_missing_char_parameter():
    """
    Compressor with invalid parameter for eta_s_char function.
    """
    nw = network(['CH4'])
    so = basics.source('source')
    si = basics.sink('sink')
    instance = turbomachinery.compressor('compressor')
    c1 = connection(so, 'out1', instance, 'in1')
    c2 = connection(instance, 'out1', si, 'in1')
    nw.add_conns(c1, c2)
    instance.set_attr(
        eta_s_char=dc_cc(method='GENERIC', is_set=True, param=None))
    nw.solve('design', init_only=True)
    instance.eta_s_char_func()
Example #13
0
 def get_variables(self):
     return {
         'P':
         dc_cp(min_val=0),
         'Q':
         dc_cp(max_val=0,
               num_eq=1,
               deriv=self.heat_deriv,
               func=self.heat_func,
               latex=self.heat_func_doc),
         'pr':
         dc_cp(max_val=1,
               num_eq=1,
               deriv=self.pr_deriv,
               func=self.pr_func,
               func_params={'pr': 'pr'},
               latex=self.pr_func_doc),
         'zeta':
         dc_cp(min_val=0,
               num_eq=1,
               deriv=self.zeta_deriv,
               func=self.zeta_func,
               func_params={'zeta': 'zeta'},
               latex=self.zeta_func_doc),
         'eta':
         dc_cp(min_val=0,
               max_val=1,
               num_eq=1,
               latex=self.eta_func_doc,
               deriv=self.eta_deriv,
               func=self.eta_func),
         'eta_char':
         dc_cc(deriv=self.eta_char_deriv,
               func=self.eta_char_func,
               latex=self.eta_char_func_doc,
               num_eq=1,
               param='m_out',
               char_params={
                   'type': 'rel',
                   'outconn': 2
               }),
         'e':
         dc_cp(min_val=0,
               num_eq=1,
               deriv=self.specific_energy_consumption_deriv,
               func=self.specific_energy_consumption_func,
               latex=self.specific_energy_consumption_func_doc)
     }
Example #14
0
    def test_valve(self):
        """
        Test component properties of valves.
        """
        instance = valve('valve')
        self.setup_piping_network(instance)

        # parameter specification
        self.c1.set_attr(fluid={'CH4': 1}, m=10, p=10, T=120)
        self.c2.set_attr(p=1)

        # test variable pressure ration
        instance.set_attr(pr='var')
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
        pr = round(self.c2.p.val_SI / self.c1.p.val_SI, 2)
        msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' +
               str(round(instance.pr.val, 2)) + '.')
        eq_(pr, round(instance.pr.val, 2), msg)

        # test variable zeta value
        zeta = round(instance.zeta.val, 0)
        instance.set_attr(zeta='var', pr=np.nan)
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
        msg = ('Value of dimension independent zeta value must be ' +
               str(zeta) + ', is ' + str(round(instance.zeta.val, 0)) + '.')
        eq_(zeta, round(instance.zeta.val, 0), msg)

        # dp char
        x = np.array([8, 9, 10, 11, 12])
        y = np.array([5, 8, 9, 9.5, 9.6]) * 1e5
        dp_char = char_line(x, y)
        instance.set_attr(zeta=np.nan,
                          dp_char=dc_cc(func=dp_char, is_set=True))
        m = 11
        self.c1.set_attr(m=m)
        self.c2.set_attr(p=np.nan)
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
        self.nw.print_results()
        dp = round(-dp_char.evaluate(m), 0)
        dp_act = round(self.c2.p.val_SI - self.c1.p.val_SI)
        msg = ('The pressure drop at the valve should be ' + str(dp) + ' but '
               'is ' + str(dp_act) + '.')
        eq_(dp, dp_act, msg)
Example #15
0
def construct_comps(c, *args):
    r"""
    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.components.component
        TESPy component object.
    """
    target_class = comp_target_classes[c.cp]
    instance = target_class(c.label)
    kwargs = {}

    # basic properties
    for key in [
            'design', 'offdesign', 'design_path', 'local_design',
            'local_offdesign'
    ]:
        if key in c:
            kwargs[key] = c[key]

    for key, value in instance.variables.items():
        if key in c:
            # component parameters
            if isinstance(value, dc_cp):
                kwargs[key] = dc_cp(val=c[key],
                                    is_set=c[key + '_set'],
                                    is_var=c[key + '_var'])

            # component parameters
            elif isinstance(value, dc_simple):
                kwargs[key] = dc_simple(val=c[key], is_set=c[key + '_set'])

            # component characteristics
            elif isinstance(value, dc_cc):
                # finding x and y values of the characteristic function
                values = args[0]['id'] == c[key]

                try:
                    x = args[0][values].x.values[0]
                    y = args[0][values].y.values[0]
                    extrapolate = False
                    if 'extrapolate' in args[0].columns:
                        extrapolate = args[0][values].extrapolate.values[0]
                    char = char_line(x=x, y=y, extrapolate=extrapolate)

                except IndexError:

                    char = None
                    msg = ('Could not find x and y values for characteristic '
                           'line, using defaults instead for function ' + key +
                           ' at component ' + c.label + '.')
                    logging.warning(msg)

                kwargs[key] = dc_cc(is_set=c[key + '_set'],
                                    param=c[key + '_param'],
                                    func=char)

            # component characteristics
            elif isinstance(value, dc_cm):
                # finding x and y values of the characteristic function
                values = args[1]['id'] == c[key]

                try:
                    x = list(args[1][values].x.values[0])
                    y = list(args[1][values].y.values[0])
                    z1 = list(args[1][values].z1.values[0])
                    z2 = list(args[1][values].z2.values[0])
                    target_class = map_target_classes[args[1]
                                                      [values].type.values[0]]
                    char = target_class(x=x, y=y, z1=z1, z2=z2)

                except IndexError:
                    char = None
                    msg = ('Could not find x, y, z1 and z2 values for '
                           'characteristic map of component ' + c.label + '!')
                    logging.warning(msg)

                kwargs[key] = dc_cm(is_set=c[key + '_set'],
                                    param=c[key + '_param'],
                                    func=char)

            # grouped component parameters
            elif isinstance(value, dc_gcp):
                kwargs[key] = dc_gcp(method=c[key])

    instance.set_attr(**kwargs)
    return instance
    0.039057719437241, 0.041010605409104, 0.042963491380966, 0.044916377352828,
    0.04686926332469, 0.048822149296552, 0.050775035268414, 0.052727921240276,
    0.054680807212138, 0.056633693184
])

# provide head in Pa
y = np.array([
    0.47782539, 0.47725723, 0.47555274, 0.47271192, 0.46873478, 0.46362130,
    0.45737151, 0.44998538, 0.44146293, 0.43180416, 0.4220905, 0.40907762,
    0.39600986, 0.38180578, 0.36646537, 0.34998863, 0.33237557, 0.31362618,
    0.29374046, 0.27271841, 0.25056004, 0.22726535, 0.20283432, 0.17726697,
    0.15056329, 0.12272329, 0.09374696, 0.06363430, 0.03238531, 0.00000000
]) * 1e5

char = char_line(x=x, y=y)
pu.set_attr(flow_char=dc_cc(func=char, is_set=True))
pu.set_attr(eta_s=0.90)

# bhes
bhe1.set_attr(D=2, L=0.1, ks=0.00001)
bhe2.set_attr(D=2, L=0.1, ks=0.00001)
bhe3.set_attr(D=2, L=0.1, ks=0.00001)

# consumer
cons.set_attr(D=2, L=0.1, ks=0.00001)
# busses
heat = bus('consumer heat demand')
heat.add_comps({'c': cons, 'p': 'P'})
btes.add_busses(heat)
# consumer heat demand
heat.set_attr(P=-3000)  # W
Example #17
0
    def test_compressor(self):
        """Test component properties of compressors."""
        instance = compressor('compressor')
        self.setup_network(instance)

        # compress NH3, other fluids in network are for turbine, pump, ...
        fl = {'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'NH3': 1}
        self.c1.set_attr(fluid=fl, v=1, p=5, T=100)
        self.c2.set_attr(p=7)
        instance.set_attr(eta_s=0.8)
        self.nw.solve('design')
        self.nw.save('tmp')

        # test isentropic efficiency value
        eta_s_d = ((instance.h_os('') - self.c1.h.val_SI) /
                   (self.c2.h.val_SI - self.c1.h.val_SI))
        msg = ('Value of isentropic efficiency must be ' + str(eta_s_d) +
               ', is ' + str(instance.eta_s.val) + '.')
        eq_(round(eta_s_d, 3), round(instance.eta_s.val, 3), msg)

        # trigger invalid value for isentropic efficiency
        instance.set_attr(eta_s=1.1)
        self.nw.solve('design')

        # test calculated value
        eta_s = ((instance.h_os('') - self.c1.h.val_SI) /
                 (self.c2.h.val_SI - self.c1.h.val_SI))
        msg = ('Value of isentropic efficiency must be ' + str(eta_s) +
               ', is ' + str(instance.eta_s.val) + '.')
        eq_(round(eta_s, 3), round(instance.eta_s.val, 3), msg)

        # remove pressure at outlet, use characteristic map for pressure
        # rise calculation
        self.c2.set_attr(p=np.nan)
        instance.set_attr(char_map=dc_cm(func=ldc('compressor', 'char_map',
                                                  'DEFAULT', compressor_map),
                                         is_set=True),
                          eta_s=np.nan)

        # offdesign test, efficiency value should be at design value
        self.nw.solve('offdesign', design_path='tmp')
        msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) +
               ') must be identical to design case (' + str(eta_s) + ').')
        eq_(round(eta_s_d, 2), round(instance.eta_s.val, 2), msg)

        # move to highest available speedline, mass flow below lowest value
        # at that line
        self.c1.set_attr(v=np.nan, m=self.c1.m.val * 0.8, T=30)
        self.nw.solve('offdesign', design_path='tmp')
        # should be value
        eta_s = eta_s_d * instance.char_map.func.z2[6, 0]
        msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) +
               ') must be at (' + str(round(eta_s, 4)) + ').')
        eq_(round(eta_s, 4), round(instance.eta_s.val, 4), msg)

        # going below lowest available speedline, above highest mass flow at
        # that line
        self.c1.set_attr(T=300)
        self.nw.solve('offdesign', design_path='tmp', init_path='tmp')
        # should be value
        eta_s = eta_s_d * instance.char_map.func.z2[0, 9]
        msg = ('Value of isentropic efficiency (' + str(instance.eta_s.val) +
               ') must be at (' + str(round(eta_s, 4)) + ').')
        eq_(round(eta_s, 4), round(instance.eta_s.val, 4), msg)

        # back to design properties, test eta_s_char
        self.c2.set_attr(p=7)
        self.c1.set_attr(v=1, T=100, m=np.nan)

        # test parameter specification for eta_s_char with unset char map
        instance.set_attr(eta_s_char=dc_cc(func=ldc('compressor', 'eta_s_char',
                                                    'DEFAULT', char_line),
                                           is_set=True,
                                           param='m'))
        instance.char_map.is_set = False
        self.nw.solve('offdesign', design_path='tmp')
        msg = ('Value of isentropic efficiency must be ' + str(eta_s_d) +
               ', is ' + str(instance.eta_s.val) + '.')
        eq_(round(eta_s_d, 3), round(instance.eta_s.val, 3), msg)

        # move up in volumetric flow
        self.c1.set_attr(v=1.5)
        self.nw.solve('offdesign', design_path='tmp')
        eta_s = round(
            eta_s_d * instance.eta_s_char.func.evaluate(
                self.c1.m.val_SI / self.c1.m.design), 3)
        msg = ('Value of isentropic efficiency must be ' + str(eta_s) +
               ', is ' + str(round(instance.eta_s.val, 3)) + '.')
        eq_(eta_s, round(instance.eta_s.val, 3), msg)

        # test parameter specification for pr
        instance.eta_s_char.set_attr(param='pr')
        self.c1.set_attr(v=1)
        self.c2.set_attr(p=7.5)
        self.nw.solve('offdesign', design_path='tmp')
        expr = (self.c2.p.val_SI * self.c1.p.design /
                (self.c2.p.design * self.c1.p.val_SI))
        eta_s = round(eta_s_d * instance.eta_s_char.func.evaluate(expr), 3)
        msg = ('Value of isentropic efficiency must be ' + str(eta_s) +
               ', is ' + str(round(instance.eta_s.val, 3)) + '.')
        eq_(eta_s, round(instance.eta_s.val, 3), msg)

        shutil.rmtree('./tmp', ignore_errors=True)
Example #18
0
    def test_pump(self):
        """Test component properties of pumps."""
        instance = pump('pump')
        self.setup_network(instance)
        fl = {'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 1, 'NH3': 0}
        self.c1.set_attr(fluid=fl, v=1, p=5, T=50)
        self.c2.set_attr(p=7)
        instance.set_attr(eta_s=1)
        self.nw.solve('design')

        # test calculated value for efficiency
        eta_s = ((instance.h_os('') - self.c1.h.val_SI) /
                 (self.c2.h.val_SI - self.c1.h.val_SI))
        msg = ('Value of isentropic efficiency must be ' + str(eta_s) +
               ', is ' + str(instance.eta_s.val) + '.')
        eq_(eta_s, instance.eta_s.val, msg)

        # isentropic efficiency of 1 means inlet and outlet entropy are
        # identical
        s1 = round(s_mix_ph(self.c1.to_flow()), 4)
        s2 = round(s_mix_ph(self.c2.to_flow()), 4)
        msg = ('Value of entropy must be identical for inlet (' + str(s1) +
               ') and outlet (' + str(s2) +
               ') at 100 % isentropic efficiency.')
        eq_(s1, s2, msg)

        # specify realistic value for efficiency, outlet pressure from flow
        # char
        eta_s_d = 0.8
        instance.set_attr(eta_s=eta_s_d)
        self.nw.solve('design')
        self.nw.save('tmp')
        self.c2.set_attr(p=np.nan)

        # flow char (pressure rise vs. volumetric flow)
        x = [0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4]
        y = np.array([14, 13.5, 12.5, 11, 9, 6.5, 3.5, 0]) * 1e5
        char = dc_cc(func=char_line(x, y), is_set=True)
        # apply flow char and eta_s char
        instance.set_attr(flow_char=char,
                          eta_s=np.nan,
                          eta_s_char=dc_cc(func=ldc('pump', 'eta_s_char',
                                                    'DEFAULT', char_line),
                                           is_set=True))
        self.nw.solve('offdesign', design_path='tmp')

        # value for difference pressure
        dp = 650000.0
        msg = ('Value of pressure rise must be ' + str(dp) + ', is ' +
               str(self.c2.p.val_SI - self.c1.p.val_SI) + '.')
        eq_(round(self.c2.p.val_SI - self.c1.p.val_SI, 0), dp, msg)

        # test ohter volumetric flow on flow char
        self.c1.set_attr(v=0.9)
        self.nw.solve('offdesign', design_path='tmp')
        dp = 775000.0
        msg = ('Value of pressure rise must be ' + str(dp) + ', is ' +
               str(self.c2.p.val_SI - self.c1.p.val_SI) + '.')
        eq_(self.c2.p.val_SI - self.c1.p.val_SI, dp, msg)

        # test value of isentropic efficiency
        eta_s = round(
            eta_s_d * instance.eta_s_char.func.evaluate(
                self.c1.v.val_SI / self.c1.v.design), 3)
        msg = ('Value of isentropic efficiency must be ' + str(eta_s) +
               ', is ' + str(instance.eta_s.val) + '.')
        eq_(eta_s, round(instance.eta_s.val, 3), msg)
        instance.eta_s_char.is_set = False

        # test boundaries of characteristic line:
        # lower boundary
        self.c2.set_attr(T=ref(self.c1, 0, 20))
        self.c1.set_attr(v=-0.1)
        self.nw.solve('design')
        msg = ('Value of power must be ' + str(14e5) + ', is ' +
               str(self.c2.p.val_SI - self.c1.p.val_SI) + '.')
        eq_(self.c2.p.val_SI - self.c1.p.val_SI, 14e5, msg)

        # upper boundary
        self.c1.set_attr(v=1.5)
        self.nw.solve('design')
        msg = ('Value of power must be ' + str(0) + ', is ' +
               str(self.c2.p.val_SI - self.c1.p.val_SI) + '.')
        eq_(self.c2.p.val_SI - self.c1.p.val_SI, 0, msg)
        shutil.rmtree('./tmp', ignore_errors=True)
Example #19
0
heat_out.add_comps({'c': cond_dh})

heat_cond = bus('heat cond')
heat_cond.add_comps({'c': cond})

heat_in = bus('heat input')
heat_in.add_comps({'c': c_c})

nw.add_busses(power, gt_power, heat_out, heat_cond, heat_in)

# %% component parameters

# characteristic line for compressor isentropic efficiency
x = np.array([0.000, 0.400, 1.000, 1.600, 2.000])
y = np.array([0.500, 0.900, 1.000, 1.050, 0.9500])
cp_char1 = dc_cc(func=char_line(x, y), param='m')
cp_char2 = dc_cc(func=char_line(x, y), param='m')

# characteristic line for turbine isentropic efficiency
x = np.array([
    0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4,
    1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5
])
y = np.array([
    0.7, 0.7667, 0.8229, 0.8698, 0.9081, 0.9387, 0.9623, 0.9796, 0.9913,
    0.9979, 1.0, 0.9981, 0.9926, 0.9839, 0.9725, 0.9586, 0.9426, 0.9248,
    0.9055, 0.8848, 0.8631, 0.8405, 0.8171, 0.7932, 0.7689, 0.7444
])
eta_s_gt = dc_cc(func=char_line(x, y), param='m')

# characteristic line for pump isentropic efficiency
Example #20
0
    def setup(self):
        # %% network

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

        # %% components

        # sources & sinks

        c_in = source('coolant in')
        cb = source('consumer back flow')
        cf = sink('consumer feed flow')
        amb_in = source('source ambient')
        amb_out = sink('sink ambient')
        ic_in = source('source intercool')
        ic_out = sink('sink intercool')

        c_out = sink('coolant out')

        # consumer system

        cd = heat_exchanger('condenser')
        rp = pump('recirculation pump')
        cons = heat_exchanger_simple('consumer')

        # evaporator system

        va = valve('valve')
        dr = drum('drum')
        ev = heat_exchanger('evaporator')
        su = heat_exchanger('superheater')
        pu = pump('pump evaporator')

        # compressor-system

        cp1 = compressor('compressor 1')
        cp2 = compressor('compressor 2')
        he = heat_exchanger('intercooler')

        # busses

        self.power = bus('total compressor power')
        self.power.add_comps({'c': cp1}, {'c': cp2})
        self.heat = bus('total delivered heat')
        self.heat.add_comps({'c': cd, 'char': -1})
        self.nw.add_busses(self.power, self.heat)

        # %% connections

        # consumer system

        c_in_cd = connection(c_in, 'out1', cd, 'in1')

        cb_rp = connection(cb, 'out1', rp, 'in1')
        rp_cd = connection(rp, 'out1', cd, 'in2')
        self.cd_cons = connection(cd, 'out2', cons, 'in1')
        cons_cf = connection(cons, 'out1', cf, 'in1')

        self.nw.add_conns(c_in_cd, cb_rp, rp_cd, self.cd_cons, cons_cf)

        # connection condenser - evaporator system

        cd_va = connection(cd, 'out1', va, 'in1')

        self.nw.add_conns(cd_va)

        # evaporator system

        va_dr = connection(va, 'out1', dr, 'in1')
        dr_pu = connection(dr, 'out1', pu, 'in1')
        pu_ev = connection(pu, 'out1', ev, 'in2')
        ev_dr = connection(ev, 'out2', dr, 'in2')
        dr_su = connection(dr, 'out2', su, 'in2')

        self.nw.add_conns(va_dr, dr_pu, pu_ev, ev_dr, dr_su)

        self.amb_in_su = connection(amb_in, 'out1', su, 'in1')
        su_ev = connection(su, 'out1', ev, 'in1')
        ev_amb_out = connection(ev, 'out1', amb_out, 'in1')

        self.nw.add_conns(self.amb_in_su, su_ev, ev_amb_out)

        # connection evaporator system - compressor system

        su_cp1 = connection(su, 'out2', cp1, 'in1')

        self.nw.add_conns(su_cp1)

        # compressor-system

        cp1_he = connection(cp1, 'out1', he, 'in1')
        he_cp2 = connection(he, 'out1', cp2, 'in1')
        cp2_c_out = connection(cp2, 'out1', c_out, 'in1')

        ic_in_he = connection(ic_in, 'out1', he, 'in2')
        he_ic_out = connection(he, 'out2', ic_out, 'in1')

        self.nw.add_conns(cp1_he, he_cp2, ic_in_he, he_ic_out, cp2_c_out)

        # %% component parametrization

        # condenser system

        x = np.array([
            0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625,
            0.6375, 0.7125, 0.7875, 0.9, 0.9875, 1, 1.0625, 1.125, 1.175,
            1.2125, 1.2375, 1.25
        ])
        y = np.array([
            0.0076, 0.1390, 0.2731, 0.4003, 0.5185, 0.6263, 0.7224, 0.8056,
            0.8754, 0.9312, 0.9729, 1.0006, 1.0203, 1.0158, 1.0051, 1.0000,
            0.9746, 0.9289, 0.8832, 0.8376, 0.7843, 0.7614
        ])
        rp.set_attr(eta_s=0.8,
                    design=['eta_s'],
                    offdesign=['eta_s_char'],
                    eta_s_char=dc_cc(func=char_line(x, y), param='m'))
        cons.set_attr(pr=1, design=['pr'], offdesign=['zeta'])

        # evaporator system

        x = np.linspace(0, 2.5, 26)
        y = np.array([
            0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840,
            0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516,
            1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051
        ])
        kA_char1 = dc_cc(func=char_line(x, y), param='m')

        x = np.array([
            0.0100, 0.0400, 0.0700, 0.1100, 0.1500, 0.2000, 0.2500, 0.3000,
            0.3500, 0.4000, 0.4500, 0.5000, 0.5500, 0.6000, 0.6500, 0.7000,
            0.7500, 0.8000, 0.8500, 0.9000, 0.9500, 1.0000, 1.5000, 2.0000
        ])

        y = np.array([
            0.0185, 0.0751, 0.1336, 0.2147, 0.2997, 0.4118, 0.5310, 0.6582,
            0.7942, 0.9400, 0.9883, 0.9913, 0.9936, 0.9953, 0.9966, 0.9975,
            0.9983, 0.9988, 0.9992, 0.9996, 0.9998, 1.0000, 1.0008, 1.0014
        ])
        kA_char2 = dc_cc(func=char_line(x, y), param='m')
        ev.set_attr(pr1=1,
                    pr2=.999,
                    ttd_l=5,
                    design=['ttd_l'],
                    offdesign=['kA'],
                    kA_char1=kA_char1,
                    kA_char2=kA_char2)

        # no kA modification for hot side!
        x = np.array([0, 1])
        y = np.array([1, 1])
        kA_char1 = dc_cc(func=char_line(x, y), param='m')

        # characteristic line for superheater kA
        x = np.array(
            [0, 0.045, 0.136, 0.244, 0.43, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2])
        y = np.array(
            [0, 0.037, 0.112, 0.207, 0.5, 0.8, 0.85, 0.9, 0.95, 1, 1.04, 1.07])
        kA_char2 = dc_cc(func=char_line(x, y), param='m')
        su.set_attr(kA_char1=kA_char1,
                    kA_char2=kA_char2,
                    offdesign=['zeta1', 'zeta2', 'kA'])

        x = np.array([
            0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625,
            0.6375, 0.7125, 0.7875, 0.9, 0.9875, 1, 1.0625, 1.125, 1.175,
            1.2125, 1.2375, 1.25
        ])
        y = np.array([
            0.0076, 0.1390, 0.2731, 0.4003, 0.5185, 0.6263, 0.7224, 0.8056,
            0.8754, 0.9312, 0.9729, 1.0006, 1.0203, 1.0158, 1.0051, 1.0000,
            0.9746, 0.9289, 0.8832, 0.8376, 0.7843, 0.7614
        ])
        pu.set_attr(eta_s=0.8,
                    design=['eta_s'],
                    offdesign=['eta_s_char'],
                    eta_s_char=dc_cc(func=char_line(x, y), param='m'))

        # compressor system

        x = np.array([0, 0.4, 1, 1.2])
        y = np.array([0.5, 0.9, 1, 1.1])

        cp1.set_attr(eta_s=0.8,
                     design=['eta_s'],
                     offdesign=['eta_s_char'],
                     eta_s_char=dc_cc(func=char_line(x, y), param='m'))
        cp2.set_attr(eta_s=0.8,
                     design=['eta_s'],
                     offdesign=['eta_s_char'],
                     eta_s_char=dc_cc(func=char_line(x, y), param='m'))

        # characteristic line for intercooler kA
        x = np.linspace(0, 2.5, 26)
        y = np.array([
            0.0000, 0.2455, 0.3747, 0.4798, 0.5718, 0.6552, 0.7323, 0.8045,
            0.8727, 0.9378, 1.0000, 1.0599, 1.1176, 1.1736, 1.2278, 1.2806,
            1.3320, 1.3822, 1.4313, 1.4792, 1.5263, 1.5724, 1.6176, 1.6621,
            1.7058, 1.7488
        ])
        # x = np.array([0, 1])
        # y = np.array([1, 1])
        kA_char1 = dc_cc(func=char_line(x, y), param='m')

        x = np.linspace(0, 2.5, 26)
        y = np.array([
            0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840,
            0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516,
            1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051
        ])
        # x = np.array([0, 1])
        # y = np.array([1, 1])
        kA_char2 = dc_cc(func=char_line(x, y), param='m')

        he.set_attr(kA_char1=kA_char1,
                    kA_char2=kA_char2,
                    offdesign=['zeta1', 'zeta2', 'kA'])

        # characteristic line for condenser kA
        x = np.linspace(0, 2.5, 26)
        y = np.array([
            0.0000, 0.2455, 0.3747, 0.4798, 0.5718, 0.6552, 0.7323, 0.8045,
            0.8727, 0.9378, 1.0000, 1.0599, 1.1176, 1.1736, 1.2278, 1.2806,
            1.3320, 1.3822, 1.4313, 1.4792, 1.5263, 1.5724, 1.6176, 1.6621,
            1.7058, 1.7488
        ])
        kA_char1 = dc_cc(func=char_line(x, y), param='m')

        x = np.linspace(0, 2.5, 26)
        y = np.array([
            0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840,
            0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516,
            1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051
        ])
        kA_char2 = dc_cc(func=char_line(x, y), param='m')

        cd.set_attr(kA_char1=kA_char1,
                    kA_char2=kA_char2,
                    pr2=0.9998,
                    design=['pr2'],
                    offdesign=['zeta2', 'kA'])

        # %% connection parametrization

        # condenser system

        c_in_cd.set_attr(fluid={'water': 0, 'NH3': 1}, p=60)
        rp_cd.set_attr(T=60, fluid={'water': 1, 'NH3': 0}, p=10)
        self.cd_cons.set_attr(T=105)
        cons_cf.set_attr(h=ref(cb_rp, 1, 0), p=ref(cb_rp, 1, 0))
        cd_va.set_attr(p=ref(c_in_cd, 1, -1000),
                       Td_bp=-5,
                       h0=500,
                       design=['Td_bp'])

        # evaporator system cold side

        pu_ev.set_attr(m=ref(va_dr, 10, 0), p0=5)
        dr_su.set_attr(p0=5, T=5)
        su_cp1.set_attr(p=ref(dr_su, 1, -5000),
                        Td_bp=5,
                        h0=1700,
                        design=['Td_bp', 'p'])

        # evaporator system hot side

        self.amb_in_su.set_attr(m=20, T=12, p=1, fluid={'water': 1, 'NH3': 0})
        su_ev.set_attr(p=ref(self.amb_in_su, 1, -100), design=['p'])
        ev_amb_out.set_attr()

        # compressor-system

        cp1_he.set_attr(p=15)
        he_cp2.set_attr(T=40, p=ref(cp1_he, 1, -1000), design=['T', 'p'])
        ic_in_he.set_attr(p=1, T=20, m=5, fluid={'water': 1, 'NH3': 0})
        he_ic_out.set_attr(p=ref(ic_in_he, 1, -200), design=['p'])
        cp2_c_out.set_attr(p=ref(c_in_cd, 1, 0), h=ref(c_in_cd, 1, 0))
Example #21
0
    def test_set_attr_errors(self):
        #
        labels = [5, 'Label,', 'Labe;l', 'Label.']
        for l in labels:
            self.cmp_instanciation_ValueError(l)

        # ValueErrors
        self.set_attr_ValueError(self.comp, offdesign=['Q'])

        self.set_attr_ValueError(self.conn, offdesign=['f'])
        self.set_attr_ValueError(self.conn, state='f')

        self.set_attr_ValueError(self.nw, m_unit='kg')
        self.set_attr_ValueError(self.nw, h_unit='kg')
        self.set_attr_ValueError(self.nw, p_unit='kg')
        self.set_attr_ValueError(self.nw, T_unit='kg')
        self.set_attr_ValueError(self.nw, v_unit='kg')

        self.create_connection_ValueError('source')
        self.create_connection_ValueError('target')

        # TypeErrors
        self.set_attr_TypeError(self.comp, P=[5])
        self.set_attr_TypeError(self.comp, tiP_char=None)
        self.set_attr_TypeError(self.comp, design='f')
        self.set_attr_TypeError(self.comp, lamb=dc_cc())
        self.set_attr_TypeError(self.comp, design_path=7)
        self.set_attr_TypeError(self.comp, local_design=5)
        self.set_attr_TypeError(self.comp, local_offdesign=5)
        self.set_attr_TypeError(self.pipe, hydro_group=5)
        self.set_attr_TypeError(self.comp, printout=5)

        self.set_attr_TypeError(self.conn, design='h')
        self.set_attr_TypeError(self.conn, fluid_balance=1)
        self.set_attr_TypeError(self.conn, h0=[4])
        self.set_attr_TypeError(self.conn, fluid=5)
        self.set_attr_TypeError(self.conn, state=5)
        self.set_attr_TypeError(self.conn, design_path=5)
        self.set_attr_TypeError(self.conn, local_design=5)
        self.set_attr_TypeError(self.conn, local_offdesign=5)
        self.set_attr_TypeError(self.conn, printout=5)

        self.set_attr_TypeError(self.nw, m_range=5)
        self.set_attr_TypeError(self.nw, p_range=5)
        self.set_attr_TypeError(self.nw, h_range=5)
        self.set_attr_TypeError(self.nw, T_range=5)
        self.set_attr_TypeError(self.nw, iterinfo=5)
        self.set_attr_TypeError(self.bus, P='some value')
        self.set_attr_TypeError(self.bus, printout=5)

        self.bus_add_comps_TypeError({'c': self.conn})
        self.bus_add_comps_TypeError({'f': self.comp})
        self.bus_add_comps_TypeError({'c': self.comp, 'char': 'Hi'})
        self.bus_add_comps_TypeError({'c': self.comp, 'p': 5})
        self.bus_add_comps_TypeError({'c': self.comp, 'P_ref': 'what'})

        self.create_ref_TypeError([self.conn, 7, 'hi'])
        self.create_ref_TypeError([self.conn, 'hi', 0])
        self.create_ref_TypeError([self.comp, 1, 0])

        # KeyErrors
        self.set_attr_KeyError(dc_cc(), x=7)
        self.set_attr_KeyError(self.comp, wow=5)
        self.set_attr_KeyError(self.conn, jey=5)
        self.set_attr_KeyError(self.bus, power_output=100000)

        self.get_attr_KeyError(self.comp, 'wow')
        self.get_attr_KeyError(self.conn, 'key')
        self.get_attr_KeyError(self.bus, 'components')
        self.get_attr_KeyError(self.nw, 'missing')
        self.get_attr_KeyError(ref(self.conn, 1, 0), 'comp')
        self.get_attr_KeyError(self.sub, 'test')
        self.get_attr_KeyError(char_line(), 'test')
        self.get_attr_KeyError(data_container(), 'somekey')