示例#1
0
def add_decentralised_heating_systems(table_collection, nodes, extra_regions):
    logging.debug("Add decentralised_heating_systems to nodes dictionary.")
    cs = table_collection["commodity_source"]["DE"]
    dts = table_collection["demand_series"]
    dh = table_collection["decentralised_heat"]
    demand_regions = list({"DE_demand"}.union(set(extra_regions)))

    for d_region in demand_regions:
        region_name = d_region.replace("_demand", "")

        if region_name not in dh:
            data_name = "DE_demand"
        else:
            data_name = d_region

        fuels = [f for f in dh[data_name].columns if f in dts[d_region]]
        for fuel in fuels:
            src = dh.loc["source", (data_name, fuel)]
            bus_label = Label("bus", "commodity", src.replace(" ", "_"),
                              region_name)

            # Check if source bus exists
            if bus_label not in nodes:
                create_fuel_bus_with_source(nodes, src, region_name, cs)

            # Create heating bus as Bus
            heat_bus_label = Label("bus", "heat", fuel.replace(" ", "_"),
                                   region_name)
            nodes[heat_bus_label] = Bus(label=heat_bus_label)

            # Create heating system as Transformer
            trsf_label = Label("trsf", "heat", fuel.replace(" ", "_"),
                               region_name)

            efficiency = float(dh.loc["efficiency", (data_name, fuel)])

            nodes[trsf_label] = Transformer(
                label=trsf_label,
                inputs={nodes[bus_label]: Flow()},
                outputs={nodes[heat_bus_label]: Flow()},
                conversion_factors={nodes[heat_bus_label]: efficiency},
            )

            # Create demand as Sink
            d_heat_demand_label = Label("demand", "heat",
                                        fuel.replace(" ", "_"), region_name)
            nodes[d_heat_demand_label] = Sink(
                label=d_heat_demand_label,
                inputs={
                    nodes[heat_bus_label]:
                    Flow(
                        actual_value=dts[d_region, fuel],
                        nominal_value=1,
                        fixed=True,
                    )
                },
            )
示例#2
0
def add_transmission_lines_between_electricity_nodes(table_collection, nodes):
    logging.debug("Add transmission lines to nodes dictionary.")
    power_lines = table_collection["transmission"]["electrical"]
    for idx, values in power_lines.iterrows():
        b1, b2 = idx.split("-")
        lines = [(b1, b2), (b2, b1)]
        for line in lines:
            line_label = Label("line", "electricity", line[0], line[1])
            bus_label_in = Label("bus", "electricity", "all", line[0])
            bus_label_out = Label("bus", "electricity", "all", line[1])
            if bus_label_in not in nodes:
                raise ValueError(
                    "Bus {0} missing for power line from {0} to {1}".format(
                        bus_label_in, bus_label_out))
            if bus_label_out not in nodes:
                raise ValueError(
                    "Bus {0} missing for power line from {0} to {1}".format(
                        bus_label_out, bus_label_in))
            if values.capacity != float("inf"):
                logging.debug("Line {0} has a capacity of {1}".format(
                    line_label, values.capacity))
                nodes[line_label] = Transformer(
                    label=line_label,
                    inputs={nodes[bus_label_in]: Flow()},
                    outputs={
                        nodes[bus_label_out]:
                        Flow(nominal_value=values.capacity)
                    },
                    conversion_factors={
                        nodes[bus_label_out]: values.efficiency
                    },
                )
            else:
                logging.debug(
                    "Line {0} has no capacity limit".format(line_label))
                nodes[line_label] = Transformer(
                    label=line_label,
                    inputs={nodes[bus_label_in]: Flow()},
                    outputs={nodes[bus_label_out]: Flow()},
                    conversion_factors={
                        nodes[bus_label_out]: values.efficiency
                    },
                )
示例#3
0
    def setUpClass(cls):
        cls.period = 24
        cls.es = EnergySystem(timeindex=pandas.date_range(
            '2016-01-01', periods=cls.period, freq='H'))

        # BUSSES
        b_el1 = Bus(label="b_el1")
        b_el2 = Bus(label="b_el2")
        b_diesel = Bus(label='b_diesel', balanced=False)
        cls.es.add(b_el1, b_el2, b_diesel)

        # TEST DIESEL:
        dg = Transformer(
            label='diesel',
            inputs={b_diesel: Flow(variable_costs=2)},
            outputs={
                b_el1: Flow(variable_costs=1,
                            investment=Investment(ep_costs=0.5))
            },
            conversion_factors={b_el1: 2},
        )

        batt = GenericStorage(
            label='storage',
            inputs={b_el1: Flow(variable_costs=3)},
            outputs={b_el2: Flow(variable_costs=2.5)},
            capacity_loss=0.00,
            initial_capacity=0,
            invest_relation_input_capacity=1 / 6,
            invest_relation_output_capacity=1 / 6,
            inflow_conversion_factor=1,
            outflow_conversion_factor=0.8,
            fixed_costs=35,
            investment=Investment(ep_costs=0.4),
        )

        cls.demand_values = [100] * 8760
        cls.demand_values[0] = 0.0
        demand = Sink(label="demand_el",
                      inputs={
                          b_el2:
                          Flow(nominal_value=1,
                               actual_value=cls.demand_values,
                               fixed=True)
                      })
        cls.es.add(dg, batt, demand)
        cls.om = Model(cls.es)
        cls.om.receive_duals()
        cls.om.solve()
        cls.mod = Model(cls.es)
        cls.mod.solve()
示例#4
0
def add_inverter(i, o, name, eta=1):
    """
     The function returns an inverter with defined input i and output o flows a certain
     label/name and an assigned efficiency Transfromer object
     :param cost:   i   input flows
                    o   output flows
                    name label of inverter as str
                    eta efficiency takes float values from 0-1

     :return: sim_params dict parameter inputs for the energy system model
     """
    return Transformer( label=name,
                        inputs={i: Flow()},
                        outputs={o: Flow()},
                        conversion_factors={o: eta} )
示例#5
0
def run_add_constraints_example(solver='cbc', nologg=False):
    if not nologg:
        logging.basicConfig(level=logging.INFO)
    # ##### creating an oemof solph optimization model, nothing special here ##
    # create an energy system object for the oemof solph nodes
    es = EnergySystem(timeindex=pd.date_range('1/1/2017', periods=4, freq='H'))
    # add some nodes

    boil = Bus(label="oil", balanced=False)
    blig = Bus(label="lignite", balanced=False)
    b_el = Bus(label="b_el")

    es.add(boil, blig, b_el)

    sink = Sink(label="Sink",
                inputs={
                    b_el:
                    Flow(nominal_value=40,
                         actual_value=[0.5, 0.4, 0.3, 1],
                         fixed=True)
                })
    pp_oil = Transformer(
        label='pp_oil',
        inputs={boil: Flow()},
        outputs={b_el: Flow(nominal_value=50, variable_costs=25)},
        conversion_factors={b_el: 0.39})
    pp_lig = Transformer(
        label='pp_lig',
        inputs={blig: Flow()},
        outputs={b_el: Flow(nominal_value=50, variable_costs=10)},
        conversion_factors={b_el: 0.41})

    es.add(sink, pp_oil, pp_lig)

    # create the model
    om = Model(energysystem=es)

    # add specific emission values to flow objects if source is a commodity bus
    for s, t in om.flows.keys():
        if s is boil:
            om.flows[s, t].emission_factor = 0.27  # t/MWh
        if s is blig:
            om.flows[s, t].emission_factor = 0.39  # t/MWh
    emission_limit = 60e3

    # add the outflow share
    om.flows[(boil, pp_oil)].outflow_share = [1, 0.5, 0, 0.3]

    # Now we are going to add a 'sub-model' and add a user specific constraint
    # first we add a pyomo Block() instance that we can use to add our
    # constraints. Then, we add this Block to our previous defined
    # Model instance and add the constraints.
    myblock = po.Block()

    # create a pyomo set with the flows (i.e. list of tuples),
    # there will of course be only one flow inside this set, the one we used to
    # add outflow_share
    myblock.MYFLOWS = po.Set(initialize=[
        k for (k, v) in om.flows.items() if hasattr(v, 'outflow_share')
    ])

    # pyomo does not need a po.Set, we can use a simple list as well
    myblock.COMMODITYFLOWS = [
        k for (k, v) in om.flows.items() if hasattr(v, 'emission_factor')
    ]

    # add the sub-model to the oemof Model instance
    om.add_component('MyBlock', myblock)

    def _inflow_share_rule(m, s, e, t):
        """pyomo rule definition: Here we can use all objects from the block or
        the om object, in this case we don't need anything from the block
        except the newly defined set MYFLOWS.
        """
        expr = (om.flow[s, e, t] >= om.flows[s, e].outflow_share[t] *
                sum(om.flow[i, o, t] for (i, o) in om.FLOWS if o == e))
        return expr

    myblock.inflow_share = po.Constraint(myblock.MYFLOWS,
                                         om.TIMESTEPS,
                                         rule=_inflow_share_rule)
    # add emission constraint
    myblock.emission_constr = po.Constraint(
        expr=(sum(om.flow[i, o, t] for (i, o) in myblock.COMMODITYFLOWS
                  for t in om.TIMESTEPS) <= emission_limit))

    # solve and write results to dictionary
    # you may print the model with om.pprint()
    om.solve(solver=solver)
    logging.info("Successfully finished.")
示例#6
0
def add_inverter(i, o, name, eta=1):
    return Transformer(label=name,
                       inputs={i: Flow()},
                       outputs={o: Flow()},
                       conversion_factors={o: eta})
示例#7
0
# Creating the necessary buses

elbus = Bus(label='electricity')
gasbus = Bus(label='gas')
thbus = Bus(label='heat')

logging.info('Necessary buses for the system created')

# Now creating the necessary components for the system

gas = Source(label='gas_com', outputs={gasbus: Flow()})

pv = Source(label='pv', outputs={elbus: Flow(nominal_value=65, fixed=True, actual_value=data['pv'])})

chp_gas = Transformer(label='chp_gas',
                      inputs={gasbus: Flow()},
                      outputs={elbus: Flow(nominal_value=55), thbus: Flow(nominal_value=55)},
                      conversion_factors={elbus: 0.3, thbus: 0.4})

el_storage = GenericStorage(label='el_storage',
                            nominal_storage_capacity=1000,
                            inputs={elbus: Flow(nominal_value=9)},
                            outputs={elbus: Flow(nominal_value=9)},
                            loss_rate=0.01,
                            initial_storage_level=0,
                            max_storage_level=0.9,
                            inflow_conversion_factor=0.9,
                            outflow_conversion_factor=0.9)

"""
COP = np.random.uniform(low=3.0, high=5.0, size=(8760,))
示例#8
0
shortage = Source(label='shortage_el',
                  outputs={bus_el: Flow(variable_costs=1e12)})

# create demand
demand_el = Sink(label='demand_el',
                 inputs={bus_el: Flow(nominal_value=1,
                                      actual_value=data['demand_el'],
                                      fixed=True)})

epc_coal = economics.annuity(capex=1500000, n=50, wacc=0.05)
epc_gas = economics.annuity(capex=900000, n=20, wacc=0.05)

# create power plants
pp_coal = Transformer(label='pp_coal',
                      inputs={bus_coal: Flow()},
                      outputs={bus_el: Flow(nominal_value=5000,
                                            variable_costs=25)},
                      conversion_factors={bus_el: 0.39})

pp_gas = Transformer(label='pp_gas',
                     inputs={bus_gas: Flow()},
                     outputs={bus_el: Flow(nominal_value=2000,
                                           variable_costs=40)},
                     conversion_factors={bus_el: 0.50})

# add all components to energysystem
energysystem.add(bus_coal, bus_gas, bus_el,
                 wind, pv, excess, shortage, demand_el,
                 pp_coal, pp_gas)

示例#9
0
         inputs={
             bel:
             Flow(nominal_value=85, actual_value=data['demand_el'], fixed=True)
         }))

energysystem.add(
    Sink(label='demand_th',
         inputs={
             bth:
             Flow(nominal_value=40, actual_value=data['demand_th'], fixed=True)
         }))

# power plants
energysystem.add(
    Transformer(label='pp_coal',
                inputs={bcoal: Flow()},
                outputs={bel: Flow(nominal_value=20.2, variable_costs=25)},
                conversion_factors={bel: 0.39}))

energysystem.add(
    Transformer(label='pp_lig',
                inputs={blig: Flow()},
                outputs={bel: Flow(nominal_value=11.8, variable_costs=19)},
                conversion_factors={bel: 0.41}))

energysystem.add(
    Transformer(label='pp_gas',
                inputs={bgas: Flow()},
                outputs={bel: Flow(nominal_value=41, variable_costs=40)},
                conversion_factors={bel: 0.50}))

energysystem.add(
示例#10
0
    return bcoal, bgas, bel, energysystem


bcoal, bgas, bel, energysystem = initialize_basic_energysystem()

# power plants
energysystem.add(
    solph.Transformer(
        label='pp_coal',
        inputs={bcoal: Flow()},
        outputs={bel: Flow(nominal_value=20.2, variable_costs=25)},
        conversion_factors={bel: 0.5}))

energysystem.add(
    Transformer(label='pp_gas',
                inputs={bgas: Flow()},
                outputs={bel: Flow(nominal_value=41, variable_costs=40)},
                conversion_factors={bel: 0.50}))

energysystem.add(
    solph.custom.OffsetTransformer(label='ostf',
                                   inputs={
                                       bgas:
                                       solph.Flow(nominal_value=60,
                                                  min=0.5,
                                                  max=1.0,
                                                  nonconvex=solph.NonConvex())
                                   },
                                   outputs={bel: solph.Flow()},
                                   coefficients={(bgas, bel): [20, 0.5]}))

# create the model
示例#11
0
def test_dispatch_example(solver='cbc', periods=24*5):
    """Create an energy system and optimize the dispatch at least costs."""
    Node.registry = None

    filename = os.path.join(os.path.dirname(__file__), 'input_data.csv')
    data = pd.read_csv(filename, sep=",")

    # ######################### create energysystem components ################

    # resource buses
    bcoal = Bus(label='coal', balanced=False)
    bgas = Bus(label='gas', balanced=False)
    boil = Bus(label='oil', balanced=False)
    blig = Bus(label='lignite', balanced=False)

    # electricity and heat
    bel = Bus(label='b_el')
    bth = Bus(label='b_th')

    # an excess and a shortage variable can help to avoid infeasible problems
    excess_el = Sink(label='excess_el', inputs={bel: Flow()})
    # shortage_el = Source(label='shortage_el',
    #                      outputs={bel: Flow(variable_costs=200)})

    # sources
    ep_wind = economics.annuity(capex=1000, n=20, wacc=0.05)
    wind = Source(label='wind', outputs={bel: Flow(
                    fix=data['wind'],
                    investment=Investment(ep_costs=ep_wind, existing=100))})

    ep_pv = economics.annuity(capex=1500, n=20, wacc=0.05)
    pv = Source(label='pv', outputs={bel: Flow(
                    fix=data['pv'],
                    investment=Investment(ep_costs=ep_pv, existing=80))})

    # demands (electricity/heat)
    demand_el = Sink(label='demand_elec', inputs={bel: Flow(nominal_value=85,
                     fix=data['demand_el'])})

    demand_th = Sink(label='demand_therm',
                     inputs={bth: Flow(nominal_value=40,
                                       fix=data['demand_th'])})

    # power plants
    pp_coal = Transformer(label='pp_coal',
                          inputs={bcoal: Flow()},
                          outputs={bel: Flow(nominal_value=20.2,
                                             variable_costs=25)},
                          conversion_factors={bel: 0.39})

    pp_lig = Transformer(label='pp_lig',
                         inputs={blig: Flow()},
                         outputs={bel: Flow(nominal_value=11.8,
                                            variable_costs=19)},
                         conversion_factors={bel: 0.41})

    pp_gas = Transformer(label='pp_gas',
                         inputs={bgas: Flow()},
                         outputs={bel: Flow(nominal_value=41,
                                            variable_costs=40)},
                         conversion_factors={bel: 0.50})

    pp_oil = Transformer(label='pp_oil',
                         inputs={boil: Flow()},
                         outputs={bel: Flow(nominal_value=5,
                                            variable_costs=50)},
                         conversion_factors={bel: 0.28})

    # combined heat and power plant (chp)
    pp_chp = Transformer(label='pp_chp',
                         inputs={bgas: Flow()},
                         outputs={bel: Flow(nominal_value=30,
                                            variable_costs=42),
                                  bth: Flow(nominal_value=40)},
                         conversion_factors={bel: 0.3, bth: 0.4})

    # heatpump with a coefficient of performance (COP) of 3
    b_heat_source = Bus(label='b_heat_source')

    heat_source = Source(label='heat_source', outputs={b_heat_source: Flow()})

    cop = 3
    heat_pump = Transformer(label='el_heat_pump',
                            inputs={bel: Flow(), b_heat_source: Flow()},
                            outputs={bth: Flow(nominal_value=10)},
                            conversion_factors={
                                        bel: 1/3, b_heat_source: (cop-1)/cop})

    datetimeindex = pd.date_range('1/1/2012', periods=periods, freq='H')
    energysystem = EnergySystem(timeindex=datetimeindex)
    energysystem.add(bcoal, bgas, boil, bel, bth, blig, excess_el, wind, pv,
                     demand_el, demand_th, pp_coal, pp_lig, pp_oil, pp_gas,
                     pp_chp, b_heat_source, heat_source, heat_pump)

    # ################################ optimization ###########################

    # create optimization model based on energy_system
    optimization_model = Model(energysystem=energysystem)

    # solve problem
    optimization_model.solve(solver=solver)

    # write back results from optimization object to energysystem
    optimization_model.results()

    # ################################ results ################################

    # generic result object
    results = processing.results(om=optimization_model)

    # subset of results that includes all flows into and from electrical bus
    # sequences are stored within a pandas.DataFrames and scalars e.g.
    # investment values within a pandas.Series object.
    # in this case the entry data['scalars'] does not exist since no investment
    # variables are used
    data = views.node(results, 'b_el')

    # generate results to be evaluated in tests
    comp_results = data['sequences'].sum(axis=0).to_dict()
    comp_results['pv_capacity'] = results[(pv, bel)]['scalars'].invest
    comp_results['wind_capacity'] = results[(wind, bel)]['scalars'].invest

    test_results = {
        (('wind', 'b_el'), 'flow'): 9239,
        (('pv', 'b_el'), 'flow'): 1147,
        (('b_el', 'demand_elec'), 'flow'): 7440,
        (('b_el', 'excess_el'), 'flow'): 6261,
        (('pp_chp', 'b_el'), 'flow'): 477,
        (('pp_lig', 'b_el'), 'flow'): 850,
        (('pp_gas', 'b_el'), 'flow'): 934,
        (('pp_coal', 'b_el'), 'flow'): 1256,
        (('pp_oil', 'b_el'), 'flow'): 0,
        (('b_el', 'el_heat_pump'), 'flow'): 202,
        'pv_capacity': 44,
        'wind_capacity': 246,
    }

    for key in test_results.keys():
        eq_(int(round(comp_results[key])), int(round(test_results[key])))
示例#12
0
def add_power_and_heat_plants(table_collection, nodes, extra_regions):
    trsf = table_collection["transformer"]
    cs = table_collection["commodity_source"]["DE"]

    for region in trsf.columns.get_level_values(0).unique():
        bus_heat = Label("bus", "heat", "district", region)
        bus_elec = Label("bus", "electricity", "all", region)
        for fuel in trsf[region].columns:
            # Connect to global fuel bus if not defined as extra region
            if region in extra_regions:
                bus_fuel = Label("bus", "commodity", fuel.replace(" ", "_"),
                                 region)
                create_fuel_bus_with_source(nodes, fuel, region, cs)
            else:
                bus_fuel = Label("bus", "commodity", fuel.replace(" ", "_"),
                                 "DE")
                if bus_fuel not in nodes:
                    create_fuel_bus_with_source(nodes, fuel.replace(" ", "_"),
                                                "DE", cs)
            params = trsf[region, fuel]

            # Create power plants as 1x1 Transformer
            if params.capacity > 0:
                # Define output flow with or without summed_max attribute
                if params.limit_elec_pp == float("inf"):
                    outflow = Flow(nominal_value=params.capacity)
                else:
                    smax = params.limit_elec_pp / params.capacity
                    outflow = Flow(nominal_value=params.capacity,
                                   summed_max=smax)

                trsf_label = Label("trsf", "pp", fuel.replace(" ", "_"),
                                   region)
                nodes[trsf_label] = Transformer(
                    label=trsf_label,
                    inputs={nodes[bus_fuel]: Flow()},
                    outputs={nodes[bus_elec]: outflow},
                    conversion_factors={nodes[bus_elec]: params.efficiency},
                )

            # Create chp plants as 1x2 Transformer
            if params.capacity_heat_chp > 0:
                trsf_label = Label("trsf", "chp", fuel.replace(" ", "_"),
                                   region)

                smax = (params.limit_heat_chp / params.efficiency_heat_chp) / (
                    params.capacity_heat_chp / params.efficiency_heat_chp)

                nodes[trsf_label] = Transformer(
                    label=trsf_label,
                    inputs={
                        nodes[bus_fuel]:
                        Flow(
                            nominal_value=(params.capacity_heat_chp /
                                           params.efficiency_heat_chp),
                            summed_max=smax,
                        )
                    },
                    outputs={
                        nodes[bus_elec]: Flow(),
                        nodes[bus_heat]: Flow(),
                    },
                    conversion_factors={
                        nodes[bus_elec]: params.efficiency_elec_chp,
                        nodes[bus_heat]: params.efficiency_heat_chp,
                    },
                )

            # Create heat plants as 1x1 Transformer
            if params.capacity_hp > 0:
                trsf_label = Label("trsf", "hp", fuel.replace(" ", "_"),
                                   region)
                smax = params.limit_hp / params.capacity_hp

                nodes[trsf_label] = Transformer(
                    label=trsf_label,
                    inputs={nodes[bus_fuel]: Flow()},
                    outputs={
                        nodes[bus_heat]:
                        Flow(nominal_value=params.capacity_hp, summed_max=smax)
                    },
                    conversion_factors={nodes[bus_heat]: params.efficiency_hp},
                )
示例#13
0
    Sink,
    Source,
    Transformer,
    Bus,
    Flow,
    GenericStorage,
)
from oemof_visio import ESGraphRenderer

es = EnergySystem()
bus_ac = Bus(label="AC")
bus_dc = Bus(label="DC")
wind = Source(label="wind", outputs={bus_ac: Flow()})
pv = Source(label="pv", outputs={bus_dc: Flow()})
demand_el = Sink(label="demand_el", inputs={bus_ac: Flow()})
storage_el = GenericStorage(
    label="storage_el",
    inputs={bus_ac: Flow()},
    outputs={bus_ac: Flow()},
)
pv_converter = Transformer(label="chp_gas",
                           inputs={bus_dc: Flow()},
                           outputs={bus_ac: Flow()})
excess_el = Sink(label="excess_el", inputs={bus_ac: Flow()})
es.add(bus_ac, bus_dc, wind, pv, demand_el, storage_el, excess_el,
       pv_converter)
gr = ESGraphRenderer(energy_system=es,
                     filepath="energy_system",
                     img_format="png")
gr.view()
示例#14
0
# Create oemof objects
##########################################################################

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
            })
示例#15
0
def run_basic_energysystem(args):
    n_val_wind = args[0]
    n_val_solar = args[1]
    start = time.time()
    # initialize and provide data
    energysystem = EnergySystem(timeindex=datetimeindex)

    # buses
    bcoal = Bus(label='coal', balanced=False)
    bgas = Bus(label='gas', balanced=False)
    bel = Bus(label='electricity')
    energysystem.add(bcoal, bgas, bel)

    # sources
    energysystem.add(
        Source(label='wind',
               outputs={
                   bel:
                   Flow(actual_value=data['wind'],
                        nominal_value=n_val_wind,
                        fixed=True)
               }))

    energysystem.add(
        Source(label='pv',
               outputs={
                   bel:
                   Flow(actual_value=data['pv'],
                        nominal_value=n_val_solar,
                        fixed=True)
               }))

    # excess and shortage to avoid infeasibilies
    energysystem.add(Sink(label='excess_el', inputs={bel: Flow()}))
    energysystem.add(
        Source(label='shortage_el', outputs={bel: Flow(variable_costs=200)}))

    # demands (electricity/heat)
    energysystem.add(
        Sink(label='demand_el',
             inputs={
                 bel:
                 Flow(nominal_value=65,
                      actual_value=data['demand_el'],
                      fixed=True)
             }))

    # power plants
    energysystem.add(
        Transformer(label='pp_coal',
                    inputs={bcoal: Flow()},
                    outputs={bel: Flow(nominal_value=20.2, variable_costs=25)},
                    conversion_factors={bel: 0.39}))

    energysystem.add(
        Transformer(label='pp_gas',
                    inputs={bgas: Flow()},
                    outputs={bel: Flow(nominal_value=41, variable_costs=40)},
                    conversion_factors={bel: 0.50}))

    # create optimization model based on energy_system
    optimization_model = Model(energysystem=energysystem)

    # solve problem
    optimization_model.solve(solver=solver,
                             solve_kwargs={
                                 'tee': False,
                                 'keepfiles': False
                             })

    results = outputlib.processing.results(optimization_model)

    results_el = outputlib.views.node(results, 'electricity')
    el_sequences = results_el['sequences']
    el_prod = el_sequences[[(('wind', 'electricity'), 'flow'),
                            (('pv', 'electricity'), 'flow'),
                            (('pp_coal', 'electricity'), 'flow'),
                            (('pp_gas', 'electricity'), 'flow'),
                            (('shortage_el', 'electricity'), 'flow')]]

    inputs = outputlib.processing.convert_keys_to_strings(
        outputlib.processing.parameter_as_dict(optimization_model))
    nom_vals = [[key, value['scalars']['nominal_value']]
                for key, value in inputs.items()
                if 'nominal_value' in value['scalars']]
    nom_vals = pd.DataFrame(nom_vals, columns=['flow', 'nominal_value'])
    summed_flows = [
        (key, value['sequences'].sum()[0])
        for key, value in outputlib.processing.convert_keys_to_strings(
            results).items()
    ]
    summed_flows = pd.DataFrame(summed_flows, columns=['flow', 'summed_flows'])

    end = time.time()
    print('simulation lasted: ', end - start, 'sec')

    return el_prod
示例#16
0
bgas = Bus(label='bgas')

Source(label='gas',
       outputs={
           bgas: Flow()})


Sink(label='demand_th',
     inputs={
         bth: Flow(actual_value=timeseries['demand_th'],
                   fixed=True, nominal_value=100)})

Transformer(label='pth',
            inputs={
                bel: Flow()},
            outputs={
                bth: Flow(nominal_value=30)},
            conversion_factors={bth: 0.99})

Transformer(label='chp',
            inputs={
                bgas: Flow(variable_costs=80)},
            outputs={
                 bel: Flow(nominal_value=40),
                 bth: Flow()},
            conversion_factors={bel: 0.4,
                                bth: 0.4})

Source(label='boiler_bio',
       outputs={
           bth: Flow(nominal_value=100,
示例#17
0
x = np.arange(0, periods, 1)
demand_ts = 0.5 * np.cos(x) + 1

pv_ts = 0.5 * np.sin(x) + 0.5

es = EnergySystem(timeindex=timeindex)

bus_el = Bus(label='electricity_bus')

bus_gas = Bus(label='gas_bus')

source_gas = Source(label='gas_source',
                    outputs={bus_gas: Flow(variable_costs=100)})

gas_pp = Transformer(label='powerplant',
                     inputs={bus_gas: Flow()},
                     outputs={bus_el: Flow(nominal_value=10)})

pv = Source(label='pv',
            outputs={bus_el: Flow(nominal_value=5,
                                  fixed=True,
                                  actual_value=pv_ts)})

demand_el = Sink(label='electricity_demand',
                 inputs={bus_el: Flow(nominal_value=2,
                                      fixed=True,
                                      actual_value=demand_ts)})

curtailment = Sink(label='curtailment',
                   inputs={bus_el: Flow(nominal_value=5,
                                        max=pv_ts)})
示例#18
0
def test_connect_invest():
    date_time_index = pd.date_range('1/1/2012', periods=24 * 7, freq='H')

    energysystem = EnergySystem(timeindex=date_time_index)
    network.Node.registry = energysystem

    # Read data file
    full_filename = os.path.join(os.path.dirname(__file__),
                                 'connect_invest.csv')
    data = pd.read_csv(full_filename, sep=",")

    logging.info('Create oemof objects')

    # create electricity bus
    bel1 = Bus(label="electricity1")
    bel2 = Bus(label="electricity2")

    # create excess component for the electricity bus to allow overproduction
    Sink(label='excess_bel', inputs={bel2: Flow()})
    Source(label='shortage', outputs={bel2: Flow(variable_costs=50000)})

    # create fixed source object representing wind power plants
    Source(label='wind',
           outputs={bel1: Flow(fix=data['wind'], nominal_value=1000000)})

    # create simple sink object representing the electrical demand
    Sink(label='demand',
         inputs={bel1: Flow(fix=data['demand_el'], nominal_value=1)})

    storage = components.GenericStorage(
        label='storage',
        inputs={bel1: Flow(variable_costs=10e10)},
        outputs={bel1: Flow(variable_costs=10e10)},
        loss_rate=0.00,
        initial_storage_level=0,
        invest_relation_input_capacity=1 / 6,
        invest_relation_output_capacity=1 / 6,
        inflow_conversion_factor=1,
        outflow_conversion_factor=0.8,
        investment=Investment(ep_costs=0.2),
    )

    line12 = Transformer(
        label="line12",
        inputs={bel1: Flow()},
        outputs={bel2: Flow(investment=Investment(ep_costs=20))})

    line21 = Transformer(
        label="line21",
        inputs={bel2: Flow()},
        outputs={bel1: Flow(investment=Investment(ep_costs=20))})

    om = Model(energysystem)

    constraints.equate_variables(om, om.InvestmentFlow.invest[line12, bel2],
                                 om.InvestmentFlow.invest[line21, bel1], 2)
    constraints.equate_variables(
        om, om.InvestmentFlow.invest[line12, bel2],
        om.GenericInvestmentStorageBlock.invest[storage])

    # if tee_switch is true solver messages will be displayed
    logging.info('Solve the optimization problem')
    om.solve(solver='cbc')

    # check if the new result object is working for custom components
    results = processing.results(om)

    my_results = dict()
    my_results['line12'] = float(views.node(results, 'line12')['scalars'])
    my_results['line21'] = float(views.node(results, 'line21')['scalars'])
    stor_res = views.node(results, 'storage')['scalars']
    my_results['storage_in'] = stor_res[(('electricity1', 'storage'),
                                         'invest')]
    my_results['storage'] = stor_res[(('storage', 'None'), 'invest')]
    my_results['storage_out'] = stor_res[(('storage', 'electricity1'),
                                          'invest')]

    connect_invest_dict = {
        'line12': 814705,
        'line21': 1629410,
        'storage': 814705,
        'storage_in': 135784,
        'storage_out': 135784
    }

    for key in connect_invest_dict.keys():
        eq_(int(round(my_results[key])), int(round(connect_invest_dict[key])))
示例#19
0
                 inputs={
                     bus_el:
                     Flow(nominal_value=1,
                          actual_value=data['demand_el'],
                          fixed=True)
                 })

epc_coal = economics.annuity(capex=1500000, n=50, wacc=0.05)
epc_gas = economics.annuity(capex=900000, n=20, wacc=0.05)

# create power plants
pp_coal = Transformer(label='pp_coal',
                      inputs={bus_coal: Flow()},
                      outputs={
                          bus_el:
                          Flow(investment=Investment(ep_costs=epc_coal,
                                                     maximum=5e9,
                                                     existing=0),
                               variable_costs=25)
                      },
                      conversion_factors={bus_el: 0.39})

pp_gas = Transformer(label='pp_gas',
                     inputs={bus_gas: Flow()},
                     outputs={
                         bus_el:
                         Flow(investment=Investment(ep_costs=epc_gas,
                                                    maximum=5e9,
                                                    existing=0),
                              variable_costs=40)
                     },
                     conversion_factors={bus_el: 0.50})
                Flow(actual_value=data['pv'], nominal_value=65.3, fixed=True)
            })

# Electricity demand
demand_el = Sink(label='demand_el',
                 inputs={
                     bus_el:
                     Flow(nominal_value=85,
                          actual_value=data['demand_el'],
                          fixed=True)
                 })

# power plants
pp_coal = Transformer(
    label='pp_coal',
    inputs={bus_coal: Flow()},
    outputs={bus_el: Flow(nominal_value=40, emission_factor=0.335)},
    conversion_factors={bus_el: 0.39})

storage_el = GenericStorage(label='storage_el',
                            nominal_storage_capacity=1000,
                            inputs={bus_el: Flow(nominal_value=200)},
                            outputs={bus_el: Flow(nominal_value=200)},
                            loss_rate=0.01,
                            initial_storage_level=0,
                            max_storage_level=0.9,
                            inflow_conversion_factor=0.9,
                            outflow_conversion_factor=0.9)

# an excess and a shortage variable can help to avoid infeasible problems
excess_el = Sink(label='excess_el', inputs={bus_el: Flow()})
示例#21
0
el_storage = GenericStorage(label='el_storage',
                            inputs={elbus: Flow(variable_costs=0.0001)},
                            outputs={elbus: Flow()},
                            loss_rate=0.00,
                            initial_storage_level=0.5,
                            invest_relation_input_capacity=1 / 6,
                            invest_relation_output_capacity=1 / 6,
                            inflow_conversion_factor=0.9,
                            outflow_conversion_factor=0.9,
                            investment=Investment(ep_costs=epc_storage))

cop = 3
es.add(
    Transformer(label='heat_pump',
                inputs={elbus: Flow()},
                outputs={thbus: Flow(nominal_value=10)},
                conversion_factors={elbus: 1 / cop}))

th_storage = GenericStorage(label='th_storage',
                            nominal_storage_capacity=1000,
                            inputs={thbus: Flow(nominal_value=20)},
                            outputs={thbus: Flow(nominal_value=20)},
                            loss_rate=0.01,
                            initial_storage_level=0,
                            max_storage_level=0.9,
                            inflow_conversion_factor=0.9,
                            outflow_conversion_factor=0.9)

# Adding all the components to the energy system

es.add(excess_el, demand_el, el_storage, th_storage, pv, shortage_el, elbus,
示例#22
0
def test_dispatch_one_time_step(solver='cbc', periods=1):
    """Create an energy system and optimize the dispatch at least costs."""

    # ######################### create energysystem components ################
    Node.registry = None

    # resource buses
    bgas = Bus(label='gas', balanced=False)

    # electricity and heat
    bel = Bus(label='b_el')
    bth = Bus(label='b_th')

    # an excess and a shortage variable can help to avoid infeasible problems
    excess_el = Sink(label='excess_el', inputs={bel: Flow()})

    # sources
    wind = Source(
        label='wind',
        outputs={bel: Flow(actual_value=0.5, nominal_value=66.3, fixed=True)})

    # demands (electricity/heat)
    demand_el = Sink(
        label='demand_elec',
        inputs={bel: Flow(nominal_value=85, actual_value=0.3, fixed=True)})

    demand_th = Sink(
        label='demand_therm',
        inputs={bth: Flow(nominal_value=40, actual_value=0.2, fixed=True)})

    # combined heat and power plant (chp)
    pp_chp = Transformer(label='pp_chp',
                         inputs={bgas: Flow()},
                         outputs={
                             bel: Flow(nominal_value=30, variable_costs=42),
                             bth: Flow(nominal_value=40)
                         },
                         conversion_factors={
                             bel: 0.3,
                             bth: 0.4
                         })

    # heatpump with a coefficient of performance (COP) of 3
    b_heat_source = Bus(label='b_heat_source')

    heat_source = Source(label='heat_source', outputs={b_heat_source: Flow()})

    cop = 3
    heat_pump = Transformer(label='heat_pump',
                            inputs={
                                bel: Flow(),
                                b_heat_source: Flow()
                            },
                            outputs={bth: Flow(nominal_value=10)},
                            conversion_factors={
                                bel: 1 / 3,
                                b_heat_source: (cop - 1) / cop
                            })

    energysystem = EnergySystem(timeindex=[1])
    energysystem.add(bgas, bel, bth, excess_el, wind, demand_el, demand_th,
                     pp_chp, b_heat_source, heat_source, heat_pump)

    # ################################ optimization ###########################

    # create optimization model based on energy_system
    optimization_model = Model(energysystem=energysystem, timeincrement=1)

    # solve problem
    optimization_model.solve(solver=solver)

    # write back results from optimization object to energysystem
    optimization_model.results()

    # ################################ results ################################
    data = views.node(processing.results(om=optimization_model), 'b_el')

    # generate results to be evaluated in tests
    results = data['sequences'].sum(axis=0).to_dict()

    test_results = {
        (('wind', 'b_el'), 'flow'): 33,
        (('b_el', 'demand_elec'), 'flow'): 26,
        (('b_el', 'excess_el'), 'flow'): 5,
        (('b_el', 'heat_pump'), 'flow'): 3,
    }

    for key in test_results.keys():
        eq_(int(round(results[key])), int(round(test_results[key])))
示例#23
0
energysystem.add(
    Source(label="pv",
           outputs={bel: Flow(fix=data["pv"], nominal_value=256e3)}))

# demands (electricity/heat)
energysystem.add(
    Sink(
        label="demand_el",
        inputs={bel: Flow(nominal_value=1e3, fix=data["demand_el"])},
    ))

# power plants
energysystem.add(
    Transformer(
        label="pp_coal",
        inputs={bcoal: Flow()},
        outputs={bel: Flow(nominal_value=14e6, variable_costs=40.7)},
        conversion_factors={bel: 0.35},
    ))

energysystem.add(
    Transformer(
        label="pp_gas",
        inputs={bgas: Flow()},
        outputs={bel: Flow(nominal_value=30e6, variable_costs=23.2)},
        conversion_factors={bel: 0.38},
    ))

energysystem.add(
    Transformer(
        label="pp_oil",
        inputs={boil: Flow()},