예제 #1
0
 def setup(self):
     self.nw = network(['water', 'air'])
     self.comp = combustion.combustion_engine('combustion engine')
     self.pipe = piping.pipe('pipe')
     self.conn = connection(self.comp, 'out1', self.pipe, 'in1')
     self.bus = bus('mybus')
     self.sub = subsystems.subsystem('MySub')
예제 #2
0
def test_ref_creation_error():
    """Test errors creating reference objects."""
    comb = combustion.combustion_engine('combustion engine')
    pipeline = piping.pipe('pipeline')
    conn = connection(comb, 'out1', pipeline, 'in1')
    create_ref_TypeError([conn, 7, 'hi'])
    create_ref_TypeError([conn, 'hi', 0])
    create_ref_TypeError([comb, 1, 0])
예제 #3
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))
예제 #4
0
def test_connection_creation_ValueError():
    """Test ValueErrors creating connections."""
    comb = combustion.combustion_engine('combustion engine')
    pipeline = piping.pipe('pipeline')

    with raises(ValueError):
        connection(comb, 'out6', pipeline, 'in1')

    with raises(ValueError):
        connection(comb, 'out1', pipeline, 'in5')
예제 #5
0
def test_bus_add_comps_errors():
    """Test errors adding components to busses."""
    mybus = bus('mybus')
    comb = combustion.combustion_engine('combustion engine')
    pipeline = piping.pipe('pipeline')
    conn = connection(comb, 'out1', pipeline, 'in1')
    bus_add_comps_TypeError(mybus, {'comp': conn})
    bus_add_comps_TypeError(mybus, {'f': comb})
    bus_add_comps_TypeError(mybus, {'comp': comb, 'char': 'Hi'})
    bus_add_comps_TypeError(mybus, {'comp': comb, 'param': 5})
    bus_add_comps_TypeError(mybus, {'comp': comb, 'P_ref': 'what'})
    bus_add_comps_TypeError(mybus, comb)

    with raises(ValueError):
        mybus.add_comps({'comp': comb, 'base': 5})
예제 #6
0
def test_get_attr_errors():
    """Test errors of get_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')
    sub = subsystems.subsystem('MySub')

    get_attr_KeyError(comb, 'wow')
    get_attr_KeyError(conn, 'key')
    get_attr_KeyError(mybus, 'components')
    get_attr_KeyError(nw, 'missing')
    get_attr_KeyError(ref(conn, 1, 0), 'comp')
    get_attr_KeyError(sub, 'test')
    get_attr_KeyError(char_line(), 'test')
    get_attr_KeyError(data_container(), 'somekey')
    get_attr_KeyError(char_map(), 'Stuff')
예제 #7
0
 def setup(self):
     self.nw = network(['water', 'air'])
     self.instance = combustion.combustion_engine('combustion engine')
     self.bus = bus('power')
     self.bus.add_comps({'c': self.instance, 'p': 'Param'})
예제 #8
0
 def cmp_instanciation_ValueError(self, label):
     combustion.combustion_engine(label)
예제 #9
0
    def test_combustion_engine(self):
        """
        Test component properties of combustion engine.
        """
        instance = combustion_engine('combustion engine')
        self.setup_combustion_engine_network(instance)

        air = {
            'N2': 0.7556,
            'O2': 0.2315,
            'Ar': 0.0129,
            'H2O': 0,
            'CO2': 0,
            'CH4': 0
        }
        fuel = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 0, 'CO2': 0.04, 'CH4': 0.96}
        water1 = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 1, 'CO2': 0, 'CH4': 0}
        water2 = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 1, 'CO2': 0, 'CH4': 0}

        # connection parametrisation
        instance.set_attr(pr1=0.99,
                          pr2=0.99,
                          lamb=1.0,
                          design=['pr1', 'pr2'],
                          offdesign=['zeta1', 'zeta2'])
        self.c1.set_attr(p=5, T=30, fluid=air)
        self.c2.set_attr(T=30, fluid=fuel)
        self.c4.set_attr(p=3, T=60, m=50, fluid=water1)
        self.c5.set_attr(p=3, T=80, m=50, fluid=water2)

        # create busses
        TI = bus('thermal input')
        Q1 = bus('heat output 1')
        Q2 = bus('heat output 2')
        Q = bus('heat output')
        Qloss = bus('thermal heat loss')

        TI.add_comps({'c': instance, 'p': 'TI'})
        Q1.add_comps({'c': instance, 'p': 'Q1'})
        Q2.add_comps({'c': instance, 'p': 'Q2'})
        Q.add_comps({'c': instance, 'p': 'Q'})
        Qloss.add_comps({'c': instance, 'p': 'Qloss'})

        self.nw.add_busses(TI, Q1, Q2, Q, Qloss)

        # test specified thermal input bus value
        ti = 1e6
        TI.set_attr(P=ti)
        self.nw.solve('design')
        self.nw.save('tmp')
        # calculate in offdesign mode
        self.nw.solve('offdesign', init_path='tmp', design_path='tmp')
        msg = ('Value of thermal input must be ' + str(TI.P.val) + ', is ' +
               str(instance.ti.val) + '.')
        eq_(round(TI.P.val, 1), round(instance.ti.val, 1), msg)

        # test specified thermal input in component
        TI.set_attr(P=np.nan)
        instance.set_attr(ti=ti)
        self.nw.solve('offdesign', init_path='tmp', design_path='tmp')
        msg = ('Value of thermal input must be ' + str(ti) + ', is ' +
               str(instance.ti.val) + '.')
        eq_(round(ti, 1), round(instance.ti.val, 1), msg)
        instance.set_attr(ti=np.nan)

        # test specified heat output 1 bus value
        Q1.set_attr(P=instance.Q1.val)
        self.nw.solve('offdesign', init_path='tmp', design_path='tmp')
        # heat output is at design point value, thermal input must therefore
        # not have changed
        msg = ('Value of thermal input must be ' + str(ti) + ', is ' +
               str(instance.ti.val) + '.')
        eq_(round(ti, 1), round(instance.ti.val, 1), msg)

        # calculate heat output over cooling loop
        heat1 = self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI)
        msg = ('Value of thermal input must be ' + str(heat1) + ', is ' +
               str(instance.Q1.val) + '.')
        eq_(round(heat1, 1), round(instance.Q1.val, 1), msg)
        Q1.set_attr(P=np.nan)

        # test specified heat output 2 bus value
        Q2.set_attr(P=1.2 * instance.Q2.val)
        self.nw.solve('offdesign', init_path='tmp', design_path='tmp')

        # calculate heat output over cooling loop, due to characteristic
        # function Q1 is equal to Q2 for this combustion engine
        heat1 = self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI)
        msg = ('Value of heat output 2 must be ' + str(heat1) + ', is ' +
               str(instance.Q2.val) + '.')
        eq_(round(heat1, 1), round(instance.Q2.val, 1), msg)

        # test specified heat output 2 in component
        Q2.set_attr(P=np.nan)
        instance.set_attr(Q2=heat1)
        self.nw.solve('offdesign', init_path='tmp', design_path='tmp')
        heat1 = self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI)
        msg = ('Value of heat output 2 must be ' + str(heat1) + ', is ' +
               str(instance.Q2.val) + '.')
        eq_(round(heat1, 1), round(instance.Q2.val, 1), msg)

        # test total heat output bus value
        instance.set_attr(Q2=np.nan)
        Q.set_attr(P=1.5 * instance.Q1.val)
        self.nw.solve('offdesign', init_path='tmp', design_path='tmp')
        heat = (self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI) +
                self.c5.m.val_SI * (self.c7.h.val_SI - self.c5.h.val_SI))
        msg = ('Value of total heat output must be ' + str(Q.P.val) + ', is ' +
               str(heat) + '.')
        eq_(round(Q.P.val, 1), round(heat, 1), msg)

        # test specified heat loss bus value
        Q.set_attr(P=np.nan)
        Qloss.set_attr(P=1e5)
        self.nw.solve('offdesign', init_path='tmp', design_path='tmp')
        msg = ('Value of heat loss must be ' + str(Qloss.P.val) + ', is ' +
               str(instance.Qloss.val) + '.')
        eq_(round(Qloss.P.val, 1), round(instance.Qloss.val, 1), msg)
        shutil.rmtree('./tmp', ignore_errors=True)
예제 #10
0
def test_connection_creation_TESPyConnectionError():
    comb = combustion.combustion_engine('combustion engine')
    with raises(TESPyConnectionError):
        connection(comb, 'out1', comb, 'in1')
예제 #11
0
def test_connection_creation_TypeError():
    """Test TypeErrors creating connections."""
    comb = combustion.combustion_engine('combustion engine')
    with raises(TypeError):
        connection(comb, 'out1', 7, 'in1')
예제 #12
0
def test_cmp_instanciation_ValueError():
    """Test bad label specification for component."""
    labels = [5, 'Label,', 'Labe;l', 'Label.']
    for label in labels:
        with raises(ValueError):
            combustion.combustion_engine(label)