예제 #1
0
 def test_compressor(self):
     """
     Test component properties of compressors.
     """
     instance = cmp.compressor('compressor')
     c1, c2 = self.setup_network_11(instance)
     fl = {'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 0, 'H2O': 0, 'NH3': 1, 'CO2': 0, 'CH4': 0}
     c1.set_attr(fluid=fl, v=1, p=5, T=100)
     c2.set_attr(p=7)
     instance.set_attr(eta_s=0.8)
     self.nw.solve('design')
     self.nw.save('tmp')
     # calculate isentropic efficiency the old fashioned way
     eta_s_d = (instance.h_os('') - c1.h.val_SI) / (c2.h.val_SI - c1.h.val_SI)
     eq_(round(eta_s_d, 3), round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(eta_s_d) + ', is ' + str(instance.eta_s.val) + '.')
     # trigger invalid isentropic efficiency
     instance.set_attr(eta_s=1.1)
     self.nw.solve('design')
     # calculate isentropic efficiency the old fashioned way
     eta_s = (instance.h_os('') - c1.h.val_SI) / (c2.h.val_SI - c1.h.val_SI)
     eq_(round(eta_s, 3), round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(instance.eta_s.val) + '.')
     c2.set_attr(p=np.nan)
     instance.set_attr(char_map=hlp.dc_cm(method='GENERIC', is_set=True), eta_s=np.nan)
     self.nw.solve('offdesign', design_path='tmp')
     eta_s = (instance.h_os('') - c1.h.val_SI) / (c2.h.val_SI - c1.h.val_SI)
     eq_(round(eta_s, 2), round(instance.eta_s.val, 2), 'Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be identical to design case (' + str(eta_s) + ').')
     # going above highes available speedline, beneath lowest mass flow at that line
     c1.set_attr(v=np.nan, m=c1.m.val*0.8, T=30)
     self.nw.solve('offdesign', design_path='tmp')
     eq_(round(eta_s * instance.char_map.z2[6, 0], 4), round(instance.eta_s.val, 4), 'Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be at (' + str(round(eta_s * instance.char_map.z2[6, 0], 4)) + ').')
     # going below lowest available speedline, above highest mass flow at that line
     c1.set_attr(T=300)
     self.nw.solve('offdesign', design_path='tmp')
     eq_(round(eta_s * instance.char_map.z2[0, 9], 4), round(instance.eta_s.val, 4), 'Value of isentropic efficiency (' + str(instance.eta_s.val) + ') must be at (' + str(round(eta_s * instance.char_map.z2[0, 9], 4)) + ').')
     # back to design properties, test eta_s_char
     c2.set_attr(p=7)
     c1.set_attr(v=1, T=100, m=np.nan)
     # test param specification m
     instance.set_attr(eta_s_char=hlp.dc_cc(method='GENERIC', is_set=True, param='m'))
     instance.char_map.is_set = False
     self.nw.solve('offdesign', design_path='tmp')
     eq_(round(eta_s, 3), round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(instance.eta_s.val) + '.')
     c1.set_attr(v=1.5)
     self.nw.solve('offdesign', design_path='tmp')
     eq_(0.88, round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(0.88) + ', is ' + str(instance.eta_s.val) + '.')
     # test param specification pr
     instance.eta_s_char.set_attr(param='pr')
     c1.set_attr(v=1)
     c2.set_attr(p=7.5)
     self.nw.solve('offdesign', design_path='tmp')
     eq_(0.829, round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(0.829) + ', is ' + str(instance.eta_s.val) + '.')
     instance.eta_s_char.set_attr(param=None)
     # test for missing parameter declaration
     try:
         self.nw.solve('offdesign', design_path='tmp')
     except ValueError:
         pass
     shutil.rmtree('./tmp', ignore_errors=True)
예제 #2
0
 def test_pump(self):
     """
     Test component properties of pumps.
     """
     instance = cmp.pump('pump')
     c1, c2 = self.setup_network_11(instance)
     fl = {'N2': 0, 'O2': 0, 'Ar': 0, 'INCOMP::DowQ': 1, 'H2O': 0, 'NH3': 0, 'CO2': 0, 'CH4': 0}
     c1.set_attr(fluid=fl, v=1, p=5,T=50)
     c2.set_attr(p=7)
     instance.set_attr(eta_s=1)
     self.nw.solve('design')
     # calculate isentropic efficiency the old fashioned way
     eta_s = (instance.h_os('') - c1.h.val_SI) / (c2.h.val_SI - c1.h.val_SI)
     eq_(eta_s, instance.eta_s.val, 'Value of isentropic efficiency must be ' + str(eta_s) + ', is ' + str(instance.eta_s.val) + '.')
     s1 = round(hlp.s_mix_ph(c1.to_flow()), 4)
     s2 = round(hlp.s_mix_ph(c2.to_flow()), 4)
     eq_(s1, s2, 'Value of entropy must be identical for inlet (' + str(s1) + ') and outlet (' + str(s2) + ') at 100 % isentropic efficiency.')
     instance.set_attr(eta_s=0.7)
     self.nw.solve('design')
     self.nw.save('tmp')
     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 = hlp.dc_cc(x=x, y=y, is_set=True)
     # apply flow char and eta_s char
     instance.set_attr(flow_char=char, eta_s=np.nan, eta_s_char=hlp.dc_cc(method='GENERIC', is_set=True))
     self.nw.solve('offdesign', design_path='tmp')
     eq_(round(c2.p.val_SI - c1.p.val_SI, 0), 650000, 'Value of pressure rise must be ' + str(650000) + ', is ' + str(c2.p.val_SI - c1.p.val_SI) + '.')
     c1.set_attr(v=0.9)
     self.nw.solve('offdesign', design_path='tmp')
     eq_(c2.p.val_SI - c1.p.val_SI, 775000.0, 'Value of pressure rise must be ' + str(775000.0) + ', is ' + str(c2.p.val_SI - c1.p.val_SI) + '.')
     eq_(0.694, round(instance.eta_s.val, 3), 'Value of isentropic efficiency must be ' + str(0.694) + ', is ' + str(instance.eta_s.val) + '.')
     instance.eta_s_char.is_set = False
     # test boundaries of characteristic line
     c2.set_attr(T=con.ref(c1, 0, 20))
     c1.set_attr(v=-0.1)
     self.nw.solve('design')
     eq_(c2.p.val_SI - c1.p.val_SI, 14e5, 'Value of power must be ' + str(14e5) + ', is ' + str(c2.p.val_SI - c1.p.val_SI) + '.')
     c1.set_attr(v=1.5)
     self.nw.solve('design')
     eq_(c2.p.val_SI - c1.p.val_SI, 0, 'Value of power must be ' + str(0) + ', is ' + str(c2.p.val_SI - c1.p.val_SI) + '.')
     shutil.rmtree('./tmp', ignore_errors=True)
예제 #3
0
def construct_comps(c, *args):
    """
    creates TESPy component from class name provided in the .csv-file and
    specifies its parameter

    :param c: component information
    :type c: pandas.core.series.Series
    :returns: instance (*tespy.components.component*) - TESPy component object

    **additional arguments in args**

    - args[0]: char (*pandas.core.frame.DataFrame*) - DataFrame containing the
      x and y data of characteristic functions
    """

    target_class = getattr(cmp, c.cp)
    instance = target_class(c.label)
    kwargs = {}

    # basic properties
    for key in ['mode', 'design', 'offdesign']:
        kwargs[key] = c[key]

    for key, value in instance.attr().items():
        if key in c:
            # component parameters
            if isinstance(value, hlp.dc_cp):
                dc = hlp.dc_cp(val=c[key],
                               is_set=c[key + '_set'],
                               is_var=c[key + '_var'])
                kwargs[key] = dc
            # component characteristics
            elif isinstance(value, hlp.dc_cc):
                # finding x and y values of the characteristic function
                values = args[0]['id'] == c[key]
                x = args[0][values]['x'].values[0]
                y = args[0][values]['y'].values[0]
                dc = hlp.dc_cc(is_set=c[key + '_set'],
                               method=c[key + '_method'],
                               param=c[key + '_param'],
                               x=x,
                               y=y)
                kwargs[key] = dc
            else:
                continue

    instance.set_attr(**kwargs)
    return instance
예제 #4
0
            kA_char1='EVA_HOT',
            kA_char2='EVA_COLD',
            design=['pr1', 'ttd_l'],
            offdesign=['zeta1', 'kA'])
su.set_attr(pr1=0.999,
            pr2=0.99,
            ttd_u=2,
            design=['pr1', 'pr2', 'ttd_u'],
            offdesign=['zeta1', 'zeta2', 'kA'])
erp.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'])

# compressor system

x = np.array([0.000, 0.400, 1.000, 1.500])
y = np.array([0.500, 0.900, 1.000, 1.025])
cp_char = hlp.dc_cc(x=x, y=y, param='m')
cp1.set_attr(eta_s=0.8,
             design=['eta_s'],
             offdesign=['eta_s_char'],
             eta_s_char=cp_char)
cp2.set_attr(eta_s=0.8,
             pr=5,
             design=['eta_s'],
             offdesign=['eta_s_char'],
             eta_s_char=cp_char)
ic.set_attr(pr1=0.98,
            pr2=0.999,
            design=['pr1', 'pr2'],
            offdesign=['zeta1', 'zeta2', 'kA'])

# %% connection parametrization
예제 #5
0
def construct_comps(c, *args):
    r"""
    Creates TESPy component from class name provided in the .csv-file and specifies its parameters.

    Parameters
    ----------
    c : pandas.core.series.Series
        Component information from .csv-file.

    args[0] : pandas.core.frame.DataFrame
        DataFrame containing the x and y data of characteristic functions.

    args[1] : pandas.core.frame.DataFrame
        DataFrame containing the x, y, z1 and z2 data of characteristic maps.

    Returns
    -------
    instance : tespy.components.components.component
        TESPy component object.
    """
    if c.interface:
        instance = cmp.subsys_interface(c.label, num_inter=1)
    else:
        target_class = getattr(cmp, c.cp)
        instance = target_class(c.label)
    kwargs = {}

    # basic properties
    for key in ['mode', 'design', 'offdesign']:
        kwargs[key] = c[key]

    for key, value in instance.attr().items():
        if key in c:
            # component parameters
            if isinstance(value, hlp.dc_cp):
                dc = hlp.dc_cp(val=c[key],
                               is_set=c[key + '_set'], is_var=c[key + '_var'])
                kwargs[key] = dc
            # component parameters
            if isinstance(value, hlp.dc_simple):
                dc = hlp.dc_simple(val=c[key], val_set=c[key + '_set'])
                kwargs[key] = dc
            # component characteristics
            elif isinstance(value, hlp.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]
                except IndexError:
                    # if characteristics are missing (for compressor map atm)
                    x = cmp_char.characteristics().x
                    y = cmp_char.characteristics().y
                    msg = 'Could not find x and y values for characteristic line, using defaults instead for function ' + key + ' at component ' + c.label + '.'
                    logging.warning(msg)

                char = cmp_char.characteristics(x=x, y=y, method=c[key + '_method'], comp=instance.component())

                dc = hlp.dc_cc(is_set=c[key + '_set'],
                               method=c[key + '_method'],
                               param=c[key + '_param'],
                               func=char,
                               x=x, y=y)
                kwargs[key] = dc
            # component characteristics
            elif isinstance(value, hlp.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])
                except IndexError:
                    # if characteristics are missing (for compressor map atm)
                    x = cmp_char.char_map().x
                    y = cmp_char.char_map().y
                    z1 = cmp_char.char_map().z1
                    z2 = cmp_char.char_map().z2

                    msg = 'Could not find x, y, z1 and z2 values for characteristic map, using defaults instead.'
                    logging.warning(msg)

                char_map = cmp_char.char_map(x=x, y=y, z1=z1, z2=z2, method=c[key + '_method'], comp=instance.component())

                dc = hlp.dc_cm(is_set=c[key + '_set'],
                               method=c[key + '_method'],
                               param=c[key + '_param'],
                               func=char_map,
                               x=x, y=y, z1=z1, z2=z2)
                kwargs[key] = dc
            # grouped component parameters
            elif isinstance(value, hlp.dc_gcp):
                dc = hlp.dc_gcp(method=c[key])
                kwargs[key] = dc

    instance.set_attr(**kwargs)
    return instance
예제 #6
0
파일: 3bhes.py 프로젝트: vvburlaka/ogs
    0.031246175549793, 0.033199061521655, 0.035151947493517, 0.037104833465379,
    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

f = hlp.dc_cc(x=x, y=y, is_set=True)
pu.set_attr(flow_char=f)

# components paramerization
# system inlet
inflow_head = 2  # bar

fc_pu.set_attr(p=inflow_head, m=0.6, fluid={'water': 1})

# pump
pu.set_attr(eta_s=0.90)

# bhes
bhe1.set_attr(D=0.02733, L=100, ks=0.00001)
bhe2.set_attr(D=0.02733, L=100, ks=0.00001)
bhe3.set_attr(D=0.02733, L=100, ks=0.00001)
예제 #7
0
    def setup(self):
        # %% network

        self.nw = nwk.network(fluids=['water', 'NH3'],
                              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_in = cmp.source('source ambient')
        amb_out = cmp.sink('sink ambient')
        ic_in = cmp.source('source intercool')
        ic_out = cmp.sink('sink intercool')

        c_out = cmp.sink('coolant out')

        # consumer system

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

        # evaporator system

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

        # compressor-system

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

        # busses

        x = np.array([0, 0.7, 1, 1.3])
        y = 1 / np.array([0.8, 0.95, 1, 0.98]) / 0.9583794
        motor = cmp_char.characteristics(x=x, y=y)

        self.power = con.bus('total compressor power')
        self.power.add_comps({
            'c': cp1,
            'char': motor
        }, {
            'c': cp2,
            'char': motor
        })
        self.heat = con.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 = con.connection(c_in, 'out1', cd, 'in1')

        cb_rp = con.connection(cb, 'out1', rp, 'in1')
        rp_cd = con.connection(rp, 'out1', cd, 'in2')
        self.cd_cons = con.connection(cd, 'out2', cons, 'in1')
        cons_cf = con.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 = con.connection(cd, 'out1', va, 'in1')

        self.nw.add_conns(cd_va)

        # evaporator system

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

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

        self.amb_in_su = con.connection(amb_in, 'out1', su, 'in1')
        su_ev = con.connection(su, 'out1', ev, 'in1')
        ev_amb_out = con.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 = con.connection(su, 'out2', cp1, 'in1')

        self.nw.add_conns(su_cp1)

        # compressor-system

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

        ic_in_he = con.connection(ic_in, 'out1', he, 'in2')
        he_ic_out = con.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

        rp.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'])
        cons.set_attr(pr=1, design=['pr'], offdesign=['zeta'])

        # evaporator system

        ev.set_attr(pr1=1,
                    pr2=.999,
                    ttd_l=5,
                    design=['ttd_l'],
                    offdesign=['kA'],
                    kA_char1='EVA_HOT',
                    kA_char2='EVA_COLD')

        # 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])
        su_char = hlp.dc_cc(x=x, y=y, param='m')
        su.set_attr(kA_char1='default',
                    kA_char2=su_char,
                    offdesign=['zeta1', 'zeta2', 'kA'])
        pu.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'])

        # compressor system

        cp1.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'])
        cp2.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'])

        # characteristic line for intercooler kA
        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
        ])
        he_char_cold = hlp.dc_cc(x=x, y=y, param='m')

        he.set_attr(kA_char1='default',
                    kA_char2=he_char_cold,
                    offdesign=['zeta1', 'zeta2', 'kA'])
        cd.set_attr(pr2=0.998, design=['pr2'], offdesign=['zeta2', 'kA'])

        # %% connection parametrization

        # condenser system

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

        # evaporator system cold side

        pu_ev.set_attr(m=con.ref(va_dr, 10, 0), p0=5)
        dr_su.set_attr(p0=5, T=5)
        su_cp1.set_attr(p=con.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=con.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=con.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=con.ref(ic_in_he, 1, -200), design=['p'])
        cp2_c_out.set_attr(p=con.ref(c_in_cd, 1, 0), h=con.ref(c_in_cd, 1, 0))
예제 #8
0
파일: cet.py 프로젝트: maltefritz/SWSH
gt_power.add_comps({'c': g_turb}, {'c': comp})

heat_out = con.bus('heat output')
heat_out.add_comps({'c': cond_dh})

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

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

# %% 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 = hlp.dc_cc(x=x, y=y, param='m')
cp_char2 = hlp.dc_cc(x=x, y=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 = hlp.dc_cc(x=x, y=y, param='m')

# characteristic line for pump isentropic efficiency
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,