How to use the tespy.connections.bus function in tespy

To help you get started, we’ve selected a few tespy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oemof / tespy / tests / test_errors.py View on Github external
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})
github oemof / tespy / tests / error_tests.py View on Github external
def test_network_buslabel_duplicate(self):
        with pytest.raises(TESPyNetworkError):
            b = bus('mybus')
            self.nw.add_busses(self.bus)
            self.nw.add_busses(b)
github oemof / tespy / tests / test_errors.py View on Github external
def setup(self):
        self.nw = network(['water', 'air'])
        self.instance = combustion.combustion_engine('combustion engine')
        self.bus = bus('power')
        self.bus.add_comps({'comp': self.instance, 'param': 'Param'})
github oemof / tespy / tests / test_busses.py View on Github external
0.997, 0.998, 0.999, 1.000, 0.999, 0.99]) * 0.975
        self.generator = char_line(x=x, y=y)

        power_bus_total = bus('total power output')
        power_bus_total.add_comps(
            {'comp': cp, 'char': self.motor_bus_based, 'base': 'bus'},
            {'comp': gt, 'char': self.generator})

        thermal_input = bus('thermal input')
        thermal_input.add_comps({'comp': cc})

        compressor_power_comp = bus('compressor power input')
        compressor_power_comp.add_comps(
            {'comp': cp, 'char': self.motor_comp_based})

        compressor_power_bus = bus('compressor power input bus based')
        compressor_power_bus.add_comps(
            {'comp': cp, 'char': self.motor_bus_based, 'base': 'bus'})

        self.nw.add_busses(
            power_bus_total, thermal_input, compressor_power_comp,
            compressor_power_bus)

        # %% solving
        self.nw.solve('design')
        self.nw.save('tmp')
github oemof / tespy / tests / test_components / test_heat_exchangers.py View on Github external
def test_heat_ex(self):
        """Test component properties of heat exchanger."""
        instance = heat_exchanger('heat exchanger')
        self.setup_heat_exchanger_network(instance)

        # design specification
        instance.set_attr(pr1=0.98, pr2=0.98, ttd_u=5,
                          design=['pr1', 'pr2', 'ttd_u'],
                          offdesign=['zeta1', 'zeta2', 'kA_char'])
        self.c1.set_attr(T=120, p=3, fluid={'Ar': 0, 'H2O': 1, 'S800': 0})
        self.c2.set_attr(T=70)
        self.c3.set_attr(T=40, p=5, fluid={'Ar': 1, 'H2O': 0, 'S800': 0})
        b = bus('heat transfer', P=-80e3)
        b.add_comps({'comp': instance})
        self.nw.add_busses(b)
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
        self.nw.save('tmp')
        Q_design = instance.Q.val

        # test specified kA value
        instance.set_attr(kA=instance.kA.val * 2 / 3)
        b.set_attr(P=None)
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)

        # test heat transfer
        Q = self.c1.m.val_SI * (self.c2.h.val_SI - self.c1.h.val_SI)
        msg = (
github oemof / tespy / tests / test_components / test_heat_exchangers.py View on Github external
instance.hydro_group.is_set = True
        instance.kA_group.is_set = True
        instance.kA_char_group.is_set = True
        self.nw.solve('design', init_only=True)
        msg = ('Hydro group must no be set, if one parameter is missing!')
        assert instance.hydro_group.is_set is False, msg
        msg = ('kA group must no be set, if one parameter is missing!')
        assert instance.kA_group.is_set is False, msg
        msg = ('kA char group must no be set, if one parameter is missing!')
        assert instance.kA_char_group.is_set is False, msg

        # test diameter calculation from specified dimensions (as pipe)
        # with Hazen-Williams method
        instance.set_attr(hydro_group='HW', D='var', L=100,
                          ks=100, pr=0.99, Tamb=20)
        b = bus('heat', P=-1e5)
        b.add_comps({'comp': instance})
        self.nw.add_busses(b)
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
        pr = round(self.c2.p.val_SI / self.c1.p.val_SI, 3)
        msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' +
               str(instance.pr.val) + '.')
        assert pr == round(instance.pr.val, 3), msg

        # make zeta system variable and use previously calculated diameter
        # to calculate zeta. The value for zeta must not change
        zeta = round(instance.zeta.val, 0)
        instance.set_attr(D=instance.D.val, zeta='var', pr=np.nan)
        instance.D.is_var = False
        self.nw.solve('design')
        convergence_check(self.nw.lin_dep)
github oemof / tespy / tests / test_models / test_heat_pump_model.py View on Github external
# 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({'comp': cp1}, {'comp': cp2})
        self.heat = bus('total delivered heat')
        self.heat.add_comps({'comp': 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')
github oemof / tespy / tests / test_components / test_combustion.py View on Github external
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({'comp': instance, 'param': 'TI'})
        Q1.add_comps({'comp': instance, 'param': 'Q1'})
        Q2.add_comps({'comp': instance, 'param': 'Q2'})
        Q.add_comps({'comp': instance, 'param': 'Q'})
        Qloss.add_comps({'comp': instance, 'param': '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')
        convergence_check(self.nw.lin_dep)
github oemof / tespy / tests / test_components / test_combustion.py View on Github external
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({'comp': instance, 'param': 'TI'})
        Q1.add_comps({'comp': instance, 'param': 'Q1'})
        Q2.add_comps({'comp': instance, 'param': 'Q2'})
        Q.add_comps({'comp': instance, 'param': 'Q'})
        Qloss.add_comps({'comp': instance, 'param': 'Qloss'})

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

        # test specified thermal input bus value
        ti = 1e6
        TI.set_attr(P=ti)
github oemof / tespy / src / tespy / networks / networks.py View on Github external
def check_busses(self, b):
        r"""
        Checksthe busses to be added for type, duplicates and identical labels.

        Parameters
        ----------
        b : tespy.connections.bus
            The bus to be checked.
        """
        if isinstance(b, con.bus):
            if len(self.busses) > 0:
                if b in self.busses.values():
                    msg = ('Network contains the bus ' + b.label + ' (' +
                           str(b) + ') already.')
                    logging.error(msg)
                    raise hlp.TESPyNetworkError(msg)
                elif b.label in self.busses.keys():
                    msg = ('Network already has a bus with the name ' +
                           b.label + '.')
                    logging.error(msg)
                    raise hlp.TESPyNetworkError(msg)
                else:
                    return True
            else:
                return True
        else: