Пример #1
0
def test_offsettransformer__too_many_input_flows():
    """Too many Input Flows defined."""
    with pytest.raises(ValueError,
                       match=r"OffsetTransformer` must not have more than 1"):
        bgas = Bus(label='GasBus')
        bcoal = Bus(label='CoalBus')
        components.OffsetTransformer(label='ostf_2_in',
                                     inputs={
                                         bgas:
                                         Flow(nominal_value=60,
                                              min=0.5,
                                              max=1.0,
                                              nonconvex=NonConvex()),
                                         bcoal:
                                         Flow(nominal_value=30,
                                              min=0.3,
                                              max=1.0,
                                              nonconvex=NonConvex())
                                     },
                                     coefficients=(20, 0.5))
Пример #2
0
def test_offsettransformer_too_many_output_flows():
    """Too many Output Flows defined."""
    with pytest.raises(ValueError,
                       match='OffsetTransformer` must not have more than 1'):
        bm1 = Bus(label='my_offset_Bus1')
        bm2 = Bus(label='my_offset_Bus2')

        components.OffsetTransformer(label='ostf_2_out',
                                     inputs={
                                         bm1:
                                         Flow(nominal_value=60,
                                              min=0.5,
                                              max=1.0,
                                              nonconvex=NonConvex())
                                     },
                                     outputs={
                                         bm1: Flow(),
                                         bm2: Flow()
                                     },
                                     coefficients=(20, 0.5))
Пример #3
0
def diesel_only(mode,
                feedin,
                initial_batt_cap,
                cost,
                iterstatus=None,
                PV_source=True,
                storage_source=True,
                logger=False):

    if logger == 1:
        logger.define_logging()

    ##################################### Initialize the energy system##################################################

    # times = pd.DatetimeIndex(start='04/01/2017', periods=10, freq='H')
    times = feedin.index

    energysystem = EnergySystem(timeindex=times)

    # switch on automatic registration of entities of EnergySystem-object=energysystem

    Node.registry = energysystem

    # add components

    b_el = Bus(label='electricity')
    b_dc = Bus(label='electricity_dc')
    b_oil = Bus(label='diesel_source')

    demand_feedin = feedin['demand_el']

    Sink(label='demand',
         inputs={
             b_el: Flow(actual_value=demand_feedin,
                        nominal_value=1,
                        fixed=True)
         })

    Sink(label='excess', inputs={b_el: Flow()})

    Source(label='diesel', outputs={b_oil: Flow()})

    generator1 = custom.DieselGenerator(
        label='pp_oil_1',
        fuel_input={b_oil: Flow(variable_costs=cost['pp_oil_1']['var'])},
        electrical_output={
            b_el:
            Flow(nominal_value=186,
                 min=0.3,
                 max=1,
                 nonconvex=NonConvex(om_costs=cost['pp_oil_1']['o&m']),
                 fixed_costs=cost['pp_oil_1']['fix'])
        },
        fuel_curve={
            '1': 42,
            '0.75': 33,
            '0.5': 22,
            '0.25': 16
        })

    generator2 = custom.DieselGenerator(
        label='pp_oil_2',
        fuel_input={b_oil: Flow(variable_costs=cost['pp_oil_2']['var'])},
        electrical_output={
            b_el:
            Flow(nominal_value=186,
                 min=0.3,
                 max=1,
                 nonconvex=NonConvex(om_costs=cost['pp_oil_2']['o&m']),
                 fixed_costs=cost['pp_oil_2']['fix'],
                 variable_costs=0)
        },
        fuel_curve={
            '1': 42,
            '0.75': 33,
            '0.5': 22,
            '0.25': 16
        })

    generator3 = custom.DieselGenerator(
        label='pp_oil_3',
        fuel_input={b_oil: Flow(variable_costs=cost['pp_oil_3']['var'])},
        electrical_output={
            b_el:
            Flow(nominal_value=320,
                 min=0.3,
                 max=1,
                 nonconvex=NonConvex(om_costs=cost['pp_oil_3']['o&m']),
                 fixed_costs=cost['pp_oil_3']['fix'],
                 variable_costs=0)
        },
        fuel_curve={
            '1': 73,
            '0.75': 57,
            '0.5': 38,
            '0.25': 27
        })

    # List all generators in a list called gen_set
    gen_set = [generator1, generator2, generator3]

    sim_params = get_sim_params(cost)

    if mode == 'simulation':
        nominal_cap_pv = sim_params['pv']['nominal_capacity']
        inv_pv = None
        nominal_cap_batt = sim_params['storage']['nominal_capacity']
        inv_batt = None
    elif mode == 'investment':
        nominal_cap_pv = None
        inv_pv = sim_params['pv']['investment']
        nominal_cap_batt = None
        inv_batt = sim_params['storage']['investment']
    else:
        raise (
            UserWarning,
            'Energysystem cant be build. Check if mode is spelled correctely. '
            'It can be either [simulation] or [investment]')

    if PV_source == 1:
        PV = Source(label='PV',
                    outputs={
                        b_dc:
                        Flow(nominal_value=nominal_cap_pv,
                             fixed_costs=cost['pv']['fix'],
                             actual_value=feedin['PV'],
                             fixed=True,
                             investment=inv_pv)
                    })
    else:
        PV = None

    if storage_source == 1:
        storage = components.GenericStorage(
            label='storage',
            inputs={b_dc: Flow()},
            outputs={
                b_dc:
                Flow(variable_costs=cost['storage']['var'],
                     fixed_costs=cost['storage']['fix'])
            },
            nominal_capacity=nominal_cap_batt,
            capacity_loss=0.00,
            initial_capacity=initial_batt_cap,
            nominal_input_capacity_ratio=0.546,
            nominal_output_capacity_ratio=0.546,
            inflow_conversion_factor=0.92,
            outflow_conversion_factor=0.92,
            capacity_min=0.5,
            capacity_max=1,
            investment=inv_batt,
            initial_iteration=iterstatus)
    else:
        storage = None

    if storage_source == 1 or PV_source == 1:
        inverter1 = add_inverter(b_dc, b_el, 'Inv_pv')

    ################################# optimization ############################
    # create Optimization model based on energy_system
    logging.info("Create optimization problem")

    m = Model(energysystem)

    ################################# constraints ############################

    sr_requirement = 0.2
    sr_limit = demand_feedin * sr_requirement

    rm_requirement = 0.4
    rm_limit = demand_feedin * rm_requirement

    constraints.spinning_reserve_constraint(m,
                                            sr_limit,
                                            groups=gen_set,
                                            storage=storage)

    # constraints.n1_constraint(m, demand_feedin, groups=gen_set)

    constraints.gen_order_constraint(m, groups=gen_set)

    constraints.rotating_mass_constraint(m,
                                         rm_limit,
                                         groups=gen_set,
                                         storage=storage)

    return [m, gen_set]
Пример #4
0
bel = Bus(label="bel")

bgas = Bus(label="bgas")

bth = Bus(label="bth")

Source(label="gas", outputs={bgas: Flow(variable_costs=35)})

Transformer(label='boiler',
            inputs={bgas: Flow()},
            outputs={
                bth:
                Flow(nominal_value=500,
                     variable_cost=50,
                     nonconvex=NonConvex())
            },
            conversion_factors={bth: 0.9})

Transformer(label='chp',
            inputs={bgas: Flow()},
            outputs={
                bel: Flow(nominal_value=300, min=0.5, nonconvex=NonConvex()),
                bth: Flow()
            },
            conversion_factors={
                bth: 0.3,
                bel: 0.45
            })

Sink(label='demand_th',
Пример #5
0
         bel: Flow(actual_value=timeseries['demand_el'],
                   fixed=True, nominal_value=100)})

Source(label='pp_wind',
       outputs={
           bel: Flow(nominal_value=40, fixed=True,
                     actual_value=timeseries['wind'])})

Source(label='pp_pv',
       outputs={
           bel: Flow(nominal_value=20, fixed=True,
                     actual_value=timeseries['pv'])})

Source(label='pp_gas',
       outputs={
           bel: Flow(nominal_value=50, nonconvex=NonConvex(),
                     variable_costs=60,
                     negative_gradient={'ub': 0.05, 'costs': 0},
                     positive_gradient={'ub': 0.05, 'costs': 0})})

Source(label='pp_bio',
       outputs={
           bel: Flow(nominal_value=5,
                     variable_costs=100)})

components.GenericStorage(
    label='storage_el',
    inputs={
        bel: Flow()},
    outputs={
        bel: Flow()},
Пример #6
0
def create_energysystem_model(mode, feedin, initial_batt_cap, cost, iterstatus=None, PV_source=True,
                              storage_source=True):
    """
       The function stes up the energy system model and resturns the operational model m, which equals the
       MILP formulation
       :param cost:     mode    optimization mode ['simulation','investment' ] as    str
                        feed    timeseries holding pv and demand_el values          pd.DataFrame
                        initial_batt_cap initial SOC of the battery  takes          float values from 0-1
                        cost    cost dict derived from get_cost_dict()              dict
                        iterstatus None (only important for RH)                     boolean
                        PV_source include PV source 'True', exclude 'False'         boolean
                        storage_source include BSS source 'True', exclude 'False'   boolean


       :return: m       operational model   oemof.solph.model
                gen_set list of oemof.solph.custom.EngineGenerator objects integrated in the model
       """

    ##################################### Initialize the energy system##################################################
    # initialize time steps
    # times = pd.DatetimeIndex(start='04/01/2017', periods=10, freq='H')
    times = feedin.index

    # initialize energy system object
    energysystem = EnergySystem( timeindex=times )

    # switch on automatic registration of entities of EnergySystem-object=energysystem

    Node.registry = energysystem

    # add components

    b_el = Bus( label='electricity' )
    b_dc = Bus( label='electricity_dc' )
    b_oil = Bus( label='diesel_source' )

    demand_feedin = feedin['demand_el']


    Sink( label='demand',
          inputs={b_el: Flow( actual_value=demand_feedin,
                              nominal_value=1,
                              fixed=True )} )

    Sink( label='excess',
          inputs={b_el: Flow()} )

    # add source in case of capacity shortages, to still find a feasible solution to the problem
    # Source(label='shortage_el',
    #        outputs={b_el: Flow(variable_costs=1000)})

    Source( label='diesel',
            outputs={b_oil: Flow()} )

    generator1 = custom.EngineGenerator( label='pp_oil_1',
                                         fuel_input={b_oil: Flow( variable_costs=cost['pp_oil_1']['var'] )},
                                         electrical_output={b_el: Flow( nominal_value=186,
                                                                        min=0.3,
                                                                        max=1,
                                                                        nonconvex=NonConvex(
                                                                            om_costs=cost['pp_oil_1']['o&m'] ),
                                                                        fixed_costs=cost['pp_oil_1']['fix']
                                                                        )},
                                         fuel_curve={'1': 42, '0.75': 33, '0.5': 22, '0.25': 16} )

    generator2 = custom.EngineGenerator( label='pp_oil_2',
                                         fuel_input={b_oil: Flow( variable_costs=cost['pp_oil_2']['var'] )},
                                         electrical_output={b_el: Flow( nominal_value=186,
                                                                        min=0.3,
                                                                        max=1,
                                                                        nonconvex=NonConvex(
                                                                            om_costs=cost['pp_oil_2']['o&m'] ),
                                                                        fixed_costs=cost['pp_oil_2']['fix'],
                                                                        variable_costs=0 )},
                                         fuel_curve={'1': 42, '0.75': 33, '0.5': 22, '0.25': 16} )

    generator3 = custom.EngineGenerator( label='pp_oil_3',
                                         fuel_input={b_oil: Flow( variable_costs=cost['pp_oil_3']['var'] )},
                                         electrical_output={b_el: Flow( nominal_value=320,
                                                                        min=0.3,
                                                                        max=1,
                                                                        nonconvex=NonConvex(
                                                                            om_costs=cost['pp_oil_3']['o&m'] ),
                                                                        fixed_costs=cost['pp_oil_3']['fix'],
                                                                        variable_costs=0 )},
                                         fuel_curve={'1': 73, '0.75': 57, '0.5': 38, '0.25': 27} )

    # List all generators in a list called gen_set
    gen_set = [generator1, generator2, generator3]

    sim_params = get_sim_params( cost )

    if mode == 'simulation':
        nominal_cap_pv = sim_params['pv']['nominal_capacity']
        inv_pv = None
        nominal_cap_batt = sim_params['storage']['nominal_capacity']
        inv_batt = None
    elif mode == 'investment':
        nominal_cap_pv = None
        inv_pv = sim_params['pv']['investment']
        nominal_cap_batt = None
        inv_batt = sim_params['storage']['investment']
    else:
        raise (UserWarning, 'Energysystem cant be build. Check if mode is spelled correctely. '
                            'It can be either [simulation] or [investment]')

    if PV_source == 1:
        PV = Source( label='PV',
                     outputs={b_dc: Flow( nominal_value=nominal_cap_pv,
                                          fixed_costs=cost['pv']['fix'],
                                          actual_value=feedin['PV'],
                                          fixed=True,
                                          investment=inv_pv )} )
    else:
        PV = None

    if storage_source == 1:
        storage = components.GenericStorage( label='storage',
                                             inputs={b_dc: Flow()},
                                             outputs={b_dc: Flow( variable_costs=cost['storage']['var'] )},
                                             fixed_costs=cost['storage']['fix'],
                                             nominal_capacity=nominal_cap_batt,
                                             capacity_loss=0.00,
                                             initial_capacity=initial_batt_cap,
                                             nominal_input_capacity_ratio=0.546,
                                             nominal_output_capacity_ratio=0.546,
                                             inflow_conversion_factor=0.92,
                                             outflow_conversion_factor=0.92,
                                             capacity_min=0.5,
                                             capacity_max=1,
                                             investment=inv_batt,
                                             initial_iteration=iterstatus )
    else:
        storage = None

    if storage_source == 1 or PV_source == 1:
        inverter1 = add_inverter( b_dc, b_el, 'Inv_pv' )

    ################################# optimization ############################
    # create Optimization model based on energy_system
    logging.info( "Create optimization problem" )

    m = Model( energysystem )

    ################################# constraints ############################
    # add constraints to the model

    #spinning reserve constraint
    sr_requirement = 0.2
    sr_limit = demand_feedin * sr_requirement

    #rotating mass constraint
    rm_requirement = 0.4
    rm_limit = demand_feedin * rm_requirement

    constraints.spinning_reserve_constraint( m, sr_limit, groups=gen_set, storage=storage )

    #(N-1) is turned of for Lifuka case study
    # constraints.n1_constraint(m, demand_feedin, groups=gen_set)

    #generator order constraint
    constraints.gen_order_constraint( m, groups=gen_set )

    constraints.rotating_mass_constraint( m, rm_limit, groups=gen_set, storage=storage )

    return [m, gen_set]