Welcome to oemof’s documentation!¶
oemof.solph¶
A model generator for energy system modelling and optimisation (LP/MILP)
Introduction¶
The oemof.solph package is part of the Open energy modelling framework (oemof). This an organisational framework to bundle tools for energy (system) modelling. oemof-solph is a model generator for energy system modelling and optimisation.
The oemof.solph
package is very often called just oemof
as it was part of the
oemof meta package. Now you need to install oemof.solph
separately, but
everything else is still the same.
Since v0.4.0. it is not possible to install just oemof, use
pip install oemof.solph
instead.
Everybody is welcome to use and/or develop oemof.solph. Read our contribution section.
Contribution is already possible on a low level by simply fixing typos in oemof’s documentation or rephrasing sections which are unclear. If you want to support us that way please fork the oemof repository to your own github account and make changes as described in the github guidelines: https://guides.github.com/activities/hello-world/
If you have questions regarding the use of oemof you can visit the forum at openmod-initiative.org and open a new thread if your questions hasn’t been already answered.
Keep in touch! - You can become a watcher at our github site, but this will bring you quite a few mails and might be more interesting for developers. If you just want to get the latest news, like when is the next oemof meeting, you can follow our news-blog at oemof.org.
Documentation¶
The oemof.solph documentation is powered by readthedocs. Use the project site of oemof.solph to choose the version of the documentation. Go to the download page to download different versions and formats (pdf, html, epub) of the documentation.
Installation¶
If you have a working Python3 environment, use pypi to install the latest oemof version. Python >= 3.6 is recommended. Lower versions may work but are not tested.
pip install oemof.solph
If you want to use the latest features, you might want to install the developer version. The developer version is not recommended for productive use:
pip install https://github.com/oemof/oemof-solph/archive/dev.zip
For running an oemof-solph optimisation model, you need to install a solver. Following you will find guidelines for the installation process for different operation systems.
Installing a solver¶
There are various commercial and open-source solvers that can be used with oemof. There are two common OpenSource solvers available (CBC, GLPK), while oemof recommends CBC (Coin-or branch and cut). But sometimes its worth comparing the results of different solvers. Other commercial solvers like Gurobi or Cplex can be used as well. Have a look at the pyomo docs to learn about which solvers are supported.
Check the solver installation by executing the test_installation example below (section Installation test).
Linux
To install the solvers have a look at the package repository of your Linux distribution or search for precompiled packages. GLPK and CBC ares available at Debian, Feodora, Ubuntu and others.
Windows
- Download CBC (64 or 32 bit)
- Download GLPK (64/32 bit)
- Unpack CBC/GLPK to any folder (e.g. C:/Users/Somebody/my_programs)
- Add the path of the executable files of both solvers to the PATH variable using this tutorial
- Restart Windows
Check the solver installation by executing the test_installation example (see the Installation test section).
Mac OSX
Please follow the installation instructions on the respective homepages for details.
CBC-solver: https://projects.coin-or.org/Cbc
GLPK-solver: http://arnab-deka.com/posts/2010/02/installing-glpk-on-a-mac/
If you install the CBC solver via brew (highly recommended), it should work without additional configuration.
Installation test¶
Test the installation and the installed solver by running the installation test in your virtual environment:
oemof_installation_test
If the installation was successful, you will receive something like this:
*********
Solver installed with oemof:
glpk: working
cplex: not working
cbc: working
gurobi: not working
*********
oemof.solph successfully installed.
as an output.
Contributing¶
A warm welcome to all who want to join the developers and contribute to oemof.solph.
Information on the details and how to approach us can be found in the oemof documentation .
Citing¶
For explicitly citing solph, you might want to refer to DOI:10.1016/j.simpa.2020.100028, which gives an overview over the capabilities of solph. The core ideas of oemof as a whole are described in DOI:10.1016/j.esr.2018.07.001 (preprint at arXiv:1808.0807). To allow citing specific versions, we use the zenodo project to get a DOI for each version.
Examples¶
The linkage of specific modules of the various packages is called an application (app) and depicts for example a concrete energy system model. You can find a large variety of helpful examples in oemof’s example repository on github to download or clone. The examples show optimisations of different energy systems and are supposed to help new users to understand the framework’s structure. There is some elaboration on the examples in the respective repository. The repository has sections for each major release.
You are welcome to contribute your own examples via a pull request or by sending us an e-mail (see here for contact information).
License¶
Copyright (c) 2019 oemof developer group
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
User’s guide¶
Solph is an oemof-package, designed to create and solve linear or mixed-integer linear optimization problems. The package is based on pyomo. To create an energy system model generic and specific components are available. To get started with solph, checkout the examples in the Examples section.
This User’s guide provides a user-friendly introduction into oemof-solph, which includes small examples and nice illustrations. However, the functionality of oemof-solph go beyond the content of this User’s guide section. So, if you want to know all details of a certain component or a function, please go the API Reference. There, you will find a detailed and complete description of all oemof-solph modules.
How can I use solph?¶
To use solph you have to install oemof and at least one solver (see Installation), which can be used together with pyomo (e.g. CBC, GLPK, Gurobi, Cplex). See the pyomo installation guide for all supported solver. You can test it by executing one of the existing examples (see Examples, or directly oemof’s example repository). Be aware that the examples require the CBC solver but you can change the solver name in the example files to your solver.
Once the example work you are close to your first energy model.
Handling of Warnings¶
The solph library is designed to be as generic as possible to make it possible to use it in different use cases. This concept makes it difficult to raise Error or Warnings because sometimes untypical combinations of parameters are allowed even though they might be wrong in over 99% of the use cases.
Therefore, a SuspiciousUsageWarning was introduced. This warning will warn you if you do something untypical. If you are sure that you know what you are doing you can switch the warning off.
See the debugging module of oemof-tools for more information.
Set up an energy system¶
In most cases an EnergySystem object is defined when we start to build up an energy system model. The EnergySystem object will be the main container for the model.
To define an EnergySystem we need a Datetime index to define the time range and increment of our model. An easy way to this is to use the pandas time_range function. The following code example defines the year 2011 in hourly steps. See pandas date_range guide for more information.
import pandas as pd
my_index = pd.date_range('1/1/2011', periods=8760, freq='H')
This index can be used to define the EnergySystem:
import oemof.solph as solph
my_energysystem = solph.EnergySystem(timeindex=my_index)
Now you can start to add the components of the network.
Add components to the energy system¶
After defining an instance of the EnergySystem class you have to add all nodes you define in the following to your EnergySystem.
Basically, there are two types of nodes - components and buses. Every Component has to be connected with one or more buses. The connection between a component and a bus is the flow.
All solph components can be used to set up an energy system model but you should read the documentation of each component to learn about usage and restrictions. For example it is not possible to combine every component with every flow. Furthermore, you can add your own components in your application (see below) but we would be pleased to integrate them into solph if they are of general interest (see Feature requests and feedback).
An example of a simple energy system shows the usage of the nodes for real world representations:
The figure shows a simple energy system using the four basic network classes and the Bus class. If you remove the transmission line (transport 1 and transport 2) you get two systems but they are still one energy system in terms of solph and will be optimised at once.
There are different ways to add components to an energy system. The following line adds a bus object to the energy system defined above.
my_energysystem.add(solph.Bus())
It is also possible to assign the bus to a variable and add it afterwards. In that case it is easy to add as many objects as you like.
my_bus1 = solph.Bus()
my_bus2 = solph.Bus()
my_energysystem.add(my_bus1, my_bus2)
Therefore it is also possible to add lists or dictionaries with components but you have to dissolve them.
# add a list
my_energysystem.add(*my_list)
# add a dictionary
my_energysystem.add(*my_dictionary.values())
Bus¶
All flows into and out of a bus are balanced. Therefore an instance of the Bus class represents a grid or network without losses. To define an instance of a Bus only a unique label is necessary. If you do not set a label a random label is used but this makes it difficult to get the results later on.
To make it easier to connect the bus to a component you can optionally assign a variable for later use.
solph.Bus(label='natural_gas')
electricity_bus = solph.Bus(label='electricity')
Note
See the Bus
class for all parameters and the mathematical background.
Flow¶
The flow class has to be used to connect. An instance of the Flow class is normally used in combination with the definition of a component.
A Flow can be limited by upper and lower bounds (constant or time-dependent) or by summarised limits.
For all parameters see the API documentation of the Flow
class or the examples of the nodes below. A basic flow can be defined without any parameter.
solph.Flow()
Oemof has different types of flows but you should be aware that you cannot connect every flow type with every component.
Note
See the Flow
class for all parameters and the mathematical background.
Components¶
Components are divided in three categories. Basic components (solph.network), additional components (solph.components) and custom components (solph.custom). The custom section was created to lower the entry barrier for new components. Be aware that these components are in an experimental state. Let us know if you have used and tested these components. This is the first step to move them to the components section.
See Solph components for a list of all components.
Optimise your energy system¶
The typical optimisation of an energy system in solph is the dispatch optimisation, which means that the use of the sources is optimised to satisfy the demand at least costs. Therefore, variable cost can be defined for all components. The cost for gas should be defined in the gas source while the variable costs of the gas power plant are caused by operating material. You can deviate from this scheme but you should keep it consistent to make it understandable for others.
Costs do not have to be monetary costs but could be emissions or other variable units.
Furthermore, it is possible to optimise the capacity of different components (see Using the investment mode).
# set up a simple least cost optimisation
om = solph.Model(my_energysystem)
# solve the energy model using the CBC solver
om.solve(solver='cbc', solve_kwargs={'tee': True})
If you want to analyse the lp-file to see all equations and bounds you can write the file to you disc. In that case you should reduce the timesteps to 3. This will increase the readability of the file.
# set up a simple least cost optimisation
om = solph.Model(my_energysystem)
# write the lp file for debugging or other reasons
om.write('path/my_model.lp', io_options={'symbolic_solver_labels': True})
Analysing your results¶
If you want to analyse your results, you should first dump your EnergySystem instance, otherwise you have to run the simulation again.
my_energysystem.results = processing.results(om)
my_energysystem.dump('my_path', 'my_dump.oemof')
If you need the meta results of the solver you can do the following:
my_energysystem.results['main'] = processing.results(om)
my_energysystem.results['meta'] = processing.meta_results(om)
my_energysystem.dump('my_path', 'my_dump.oemof')
To restore the dump you can simply create an EnergySystem instance and restore your dump into it.
import oemof.solph as solph
my_energysystem = solph.EnergySystem()
my_energysystem.restore('my_path', 'my_dump.oemof')
results = my_energysystem.results
# If you use meta results do the following instead of the previous line.
results = my_energysystem.results['main']
meta = my_energysystem.results['meta']
If you call dump/restore without any parameters, the dump will be stored as ‘es_dump.oemof’ into the ‘.oemof/dumps/’ folder created in your HOME directory.
See Handling Results to learn how to process, plot and analyse the results.
Solph components¶
Sink (basic)¶
A sink is normally used to define the demand within an energy model but it can also be used to detect excesses.
The example shows the electricity demand of the electricity_bus defined above. The ‘my_demand_series’ should be sequence of normalised valueswhile the ‘nominal_value’ is the maximum demand the normalised sequence is multiplied with. Giving ‘my_demand_series’ as parameter ‘fix’ means that the demand cannot be changed by the solver.
solph.Sink(label='electricity_demand', inputs={electricity_bus: solph.Flow(
fix=my_demand_series, nominal_value=nominal_demand)})
In contrast to the demand sink the excess sink has normally less restrictions but is open to take the whole excess.
solph.Sink(label='electricity_excess', inputs={electricity_bus: solph.Flow()})
Note
The Sink class is only a plug and provides no additional constraints or variables.
Source (basic)¶
A source can represent a pv-system, a wind power plant, an import of natural gas or a slack variable to avoid creating an in-feasible model.
While a wind power plant will have an hourly feed-in depending on the weather conditions the natural_gas import might be restricted by maximum value (nominal_value) and an annual limit (summed_max). As we do have to pay for imported gas we should set variable costs. Comparable to the demand series an fix is used to define a fixed the normalised output of a wind power plant. Alternatively, you might use max to allow for easy curtailment. The nominal_value sets the installed capacity.
solph.Source(
label='import_natural_gas',
outputs={my_energysystem.groups['natural_gas']: solph.Flow(
nominal_value=1000, summed_max=1000000, variable_costs=50)})
solph.Source(label='wind', outputs={electricity_bus: solph.Flow(
fix=wind_power_feedin_series, nominal_value=1000000)})
Note
The Source class is only a plug and provides no additional constraints or variables.
Transformer (basic)¶
An instance of the Transformer class can represent a node with multiple input and output flows such as a power plant, a transport line or any kind of a transforming process as electrolysis, a cooling device or a heat pump. The efficiency has to be constant within one time step to get a linear transformation. You can define a different efficiency for every time step (e.g. the thermal powerplant efficiency according to the ambient temperature) but this series has to be predefined and cannot be changed within the optimisation.
A condensing power plant can be defined by a transformer with one input (fuel) and one output (electricity).
b_gas = solph.Bus(label='natural_gas')
b_el = solph.Bus(label='electricity')
solph.Transformer(
label="pp_gas",
inputs={bgas: solph.Flow()},
outputs={b_el: solph.Flow(nominal_value=10e10)},
conversion_factors={electricity_bus: 0.58})
A CHP power plant would be defined in the same manner but with two outputs:
b_gas = solph.Bus(label='natural_gas')
b_el = solph.Bus(label='electricity')
b_th = solph.Bus(label='heat')
solph.Transformer(
label='pp_chp',
inputs={b_gas: Flow()},
outputs={b_el: Flow(nominal_value=30),
b_th: Flow(nominal_value=40)},
conversion_factors={b_el: 0.3, b_th: 0.4})
A CHP power plant with 70% coal and 30% natural gas can be defined with two inputs and two outputs:
b_gas = solph.Bus(label='natural_gas')
b_coal = solph.Bus(label='hard_coal')
b_el = solph.Bus(label='electricity')
b_th = solph.Bus(label='heat')
solph.Transformer(
label='pp_chp',
inputs={b_gas: Flow(), b_coal: Flow()},
outputs={b_el: Flow(nominal_value=30),
b_th: Flow(nominal_value=40)},
conversion_factors={b_el: 0.3, b_th: 0.4,
b_coal: 0.7, b_gas: 0.3})
A heat pump would be defined in the same manner. New buses are defined to make the code cleaner:
b_el = solph.Bus(label='electricity')
b_th_low = solph.Bus(label='low_temp_heat')
b_th_high = solph.Bus(label='high_temp_heat')
# The cop (coefficient of performance) of the heat pump can be defined as
# a scalar or a sequence.
cop = 3
solph.Transformer(
label='heat_pump',
inputs={b_el: Flow(), b_th_low: Flow()},
outputs={b_th_high: Flow()},
conversion_factors={b_el: 1/cop,
b_th_low: (cop-1)/cop})
If the low-temperature reservoir is nearly infinite (ambient air heat pump) the low temperature bus is not needed and, therefore, a Transformer with one input is sufficient.
Note
See the Transformer
class for all parameters and the mathematical background.
ExtractionTurbineCHP (component)¶
The ExtractionTurbineCHP
inherits from the Transformer (basic) class. Like the name indicates,
the application example for the component is a flexible combined heat and power
(chp) plant. Of course, an instance of this class can represent also another
component with one input and two output flows and a flexible ratio between
these flows, with the following constraints:
where
is defined as:
where the first equation is the result of the relation between the input flow and the two output flows, the second equation stems from how the two output flows relate to each other, and the symbols used are defined as follows (with Variables (V) and Parameters (P)):
symbol attribute type explanation flow[i, n, t] V fuel input flow flow[n, main_output, t] V electric power flow[n, tapped_output, t] V thermal output main_flow_loss_index[n, t] P power loss index conversion_factor_full_condensation[n, t] P
- electric efficiency
- without heat extraction
conversion_factors[main_output][n, t] P
- electric efficiency
- with max heat extraction
conversion_factors[tapped_output][n, t] P
- thermal efficiency with
- maximal heat extraction
These constraints are applied in addition to those of a standard
Transformer
. The constraints limit the range of
the possible operation points, like the following picture shows. For a certain
flow of fuel, there is a line of operation points, whose slope is defined by
the power loss factor (in some contexts also referred to as
). The second constraint limits the decrease of electrical power and
incorporates the backpressure coefficient
.
For now, ExtractionTurbineCHP
instances must
have one input and two output flows. The class allows the definition
of a different efficiency for every time step that can be passed as a series
of parameters that are fixed before the optimisation. In contrast to the
Transformer
, a main flow and a tapped flow is
defined. For the main flow you can define a separate conversion factor that
applies when the second flow is zero (`conversion_factor_full_condensation`).
solph.ExtractionTurbineCHP(
label='variable_chp_gas',
inputs={b_gas: solph.Flow(nominal_value=10e10)},
outputs={b_el: solph.Flow(), b_th: solph.Flow()},
conversion_factors={b_el: 0.3, b_th: 0.5},
conversion_factor_full_condensation={b_el: 0.5})
The key of the parameter ‘conversion_factor_full_condensation’ defines which of the two flows is the main flow. In the example above, the flow to the Bus ‘b_el’ is the main flow and the flow to the Bus ‘b_th’ is the tapped flow. The following plot shows how the variable chp (right) schedules it’s electrical and thermal power production in contrast to a fixed chp (left). The plot is the output of an example in the example repository.
Note
See the ExtractionTurbineCHP
class for all parameters and the mathematical background.
GenericCHP (component)¶
With the GenericCHP class it is possible to model different types of CHP plants (combined cycle extraction turbines, back pressure turbines and motoric CHP), which use different ranges of operation, as shown in the figure below.
Combined cycle extraction turbines: The minimal and maximal electric power without district heating (red dots in the figure) define maximum load and minimum load of the plant. Beta defines electrical power loss through heat extraction. The minimal thermal condenser load to cooling water and the share of flue gas losses at maximal heat extraction determine the right boundary of the operation range.
solph.components.GenericCHP(
label='combined_cycle_extraction_turbine',
fuel_input={bgas: solph.Flow(
H_L_FG_share_max=[0.19 for p in range(0, periods)])},
electrical_output={bel: solph.Flow(
P_max_woDH=[200 for p in range(0, periods)],
P_min_woDH=[80 for p in range(0, periods)],
Eta_el_max_woDH=[0.53 for p in range(0, periods)],
Eta_el_min_woDH=[0.43 for p in range(0, periods)])},
heat_output={bth: solph.Flow(
Q_CW_min=[30 for p in range(0, periods)])},
Beta=[0.19 for p in range(0, periods)],
back_pressure=False)
For modeling a back pressure CHP, the attribute back_pressure has to be set to True. The ratio of power and heat production in a back pressure plant is fixed, therefore the operation range is just a line (see figure). Again, the P_min_woDH and P_max_woDH, the efficiencies at these points and the share of flue gas losses at maximal heat extraction have to be specified. In this case “without district heating” is not to be taken literally since an operation without heat production is not possible. It is advised to set Beta to zero, so the minimal and maximal electric power without district heating are the same as in the operation point (see figure). The minimal thermal condenser load to cooling water has to be zero, because there is no condenser besides the district heating unit.
solph.components.GenericCHP(
label='back_pressure_turbine',
fuel_input={bgas: solph.Flow(
H_L_FG_share_max=[0.19 for p in range(0, periods)])},
electrical_output={bel: solph.Flow(
P_max_woDH=[200 for p in range(0, periods)],
P_min_woDH=[80 for p in range(0, periods)],
Eta_el_max_woDH=[0.53 for p in range(0, periods)],
Eta_el_min_woDH=[0.43 for p in range(0, periods)])},
heat_output={bth: solph.Flow(
Q_CW_min=[0 for p in range(0, periods)])},
Beta=[0 for p in range(0, periods)],
back_pressure=True)
A motoric chp has no condenser, so Q_CW_min is zero. Electrical power does not depend on the amount of heat used so Beta is zero. The minimal and maximal electric power (without district heating) and the efficiencies at these points are needed, whereas the use of electrical power without using thermal energy is not possible. With Beta=0 there is no difference between these points and the electrical output in the operation range. As a consequence of the functionality of a motoric CHP, share of flue gas losses at maximal heat extraction but also at minimal heat extraction have to be specified.
solph.components.GenericCHP(
label='motoric_chp',
fuel_input={bgas: solph.Flow(
H_L_FG_share_max=[0.18 for p in range(0, periods)],
H_L_FG_share_min=[0.41 for p in range(0, periods)])},
electrical_output={bel: solph.Flow(
P_max_woDH=[200 for p in range(0, periods)],
P_min_woDH=[100 for p in range(0, periods)],
Eta_el_max_woDH=[0.44 for p in range(0, periods)],
Eta_el_min_woDH=[0.40 for p in range(0, periods)])},
heat_output={bth: solph.Flow(
Q_CW_min=[0 for p in range(0, periods)])},
Beta=[0 for p in range(0, periods)],
back_pressure=False)
Modeling different types of plants means telling the component to use different constraints. Constraint 1 to 9 are active in all three cases. Constraint 10 depends on the attribute back_pressure. If true, the constraint is an equality, if not it is a less or equal. Constraint 11 is only needed for modeling motoric CHP which is done by setting the attribute H_L_FG_share_min.
where
depends on the CHP being back pressure or not.
The coefficients
and
can be determined given the efficiencies maximal/minimal load:
If is given, e.g. for a motoric CHP:
The symbols used are defined as follows (with Variables (V) and Parameters (P)):
math. symbol attribute type explanation H_F[n,t] V
- input of enthalpy
- through fuel input
P[n,t] V
- provided
- electric power
P_woDH[n,t] V
- electric power without
- district heating
P_min_woDH[n,t] P
- min. electric power
- without district heating
P_max_woDH[n,t] P
- max. electric power
- without district heating
Q[n,t] V provided heat Q_CW_min[n,t] P
- minimal therm. condenser
- load to cooling water
H_L_FG_min[n,t] V
- flue gas enthalpy loss
- at min heat extraction
H_L_FG_max[n,t] V
- flue gas enthalpy loss
- at max heat extraction
H_L_FG_share_min[n,t] P
- share of flue gas loss
- at min heat extraction
H_L_FG_share_max[n,t] P
- share of flue gas loss
- at max heat extraction
Y[n,t] V
- status variable
- on/off
n.alphas[0][n,t] P
- coefficient
- describing efficiency
n.alphas[1][n,t] P
- coefficient
- describing efficiency
Beta[n,t] P power loss index Eta_el_min_woDH[n,t] P
- el. eff. at min. fuel
- flow w/o distr. heating
Eta_el_max_woDH[n,t] P
- el. eff. at max. fuel
- flow w/o distr. heating
Note
See the GenericCHP
class for all parameters and the mathematical background.
GenericStorage (component)¶
A component to model a storage with its basic characteristics. The
GenericStorage is designed for one input and one output.
The nominal_storage_capacity
of the storage signifies the storage capacity. You can either set it to the net capacity or to the gross capacity and limit it using the min/max attribute.
To limit the input and output flows, you can define the nominal_value
in the Flow objects.
Furthermore, an efficiency for loading, unloading and a loss rate can be defined.
solph.GenericStorage(
label='storage',
inputs={b_el: solph.Flow(nominal_value=9, variable_costs=10)},
outputs={b_el: solph.Flow(nominal_value=25, variable_costs=10)},
loss_rate=0.001, nominal_storage_capacity=50,
inflow_conversion_factor=0.98, outflow_conversion_factor=0.8)
For initialising the state of charge before the first time step (time step zero) the parameter initial_storage_level
(default value: None
) can be set by a numeric value as fraction of the storage capacity.
Additionally the parameter balanced
(default value: True
) sets the relation of the state of charge of time step zero and the last time step.
If balanced=True
, the state of charge in the last time step is equal to initial value in time step zero.
Use balanced=False
with caution as energy might be added to or taken from the energy system due to different states of charge in time step zero and the last time step.
Generally, with these two parameters four configurations are possible, which might result in different solutions of the same optimization model:
initial_storage_level=None
,balanced=True
(default setting): The state of charge in time step zero is a result of the optimization. The state of charge of the last time step is equal to time step zero. Thus, the storage is not violating the energy conservation by adding or taking energy from the system due to different states of charge at the beginning and at the end of the optimization period.initial_storage_level=0.5
,balanced=True
: The state of charge in time step zero is fixed to 0.5 (50 % charged). The state of charge in the last time step is also constrained by 0.5 due to the coupling parameterbalanced
set toTrue
.initial_storage_level=None
,balanced=False
: Both, the state of charge in time step zero and the last time step are a result of the optimization and not coupled.initial_storage_level=0.5
,balanced=False
: The state of charge in time step zero is constrained by a given value. The state of charge of the last time step is a result of the optimization.
The following code block shows an example of the storage parametrization for the second configuration:
solph.GenericStorage(
label='storage',
inputs={b_el: solph.Flow(nominal_value=9, variable_costs=10)},
outputs={b_el: solph.Flow(nominal_value=25, variable_costs=10)},
loss_rate=0.001, nominal_storage_capacity=50,
initial_storage_level=0.5, balanced=True,
inflow_conversion_factor=0.98, outflow_conversion_factor=0.8)
If you want to view the temporal course of the state of charge of your storage
after the optimisation, you need to check the storage_content
in the results:
from oemof.solph import processing, views
results = processing.results(om)
column_name = (('your_storage_label', 'None'), 'storage_content')
SC = views.node(results, 'your_storage_label')['sequences'][column_name]
The storage_content
is the absolute value of the current stored energy.
By calling:
views.node(results, 'your_storage_label')['scalars']
you get the results of the scalar values of your storage, e.g. the initial
storage content before time step zero (init_content
).
For more information see the definition of the GenericStorage
class or check the example repository of oemof.
Using an investment object with the GenericStorage component¶
Based on the GenericStorage object the GenericInvestmentStorageBlock adds two main investment possibilities.
- Invest into the flow parameters e.g. a turbine or a pump
- Invest into capacity of the storage e.g. a basin or a battery cell
Investment in this context refers to the value of the variable for the ‘nominal_value’ (installed capacity) in the investment mode.
As an addition to other flow-investments, the storage class implements the possibility to couple or decouple the flows with the capacity of the storage. Three parameters are responsible for connecting the flows and the capacity of the storage:
- ‘ invest_relation_input_capacity ‘ fixes the input flow investment to the capacity investment. A ratio of ‘1’ means that the storage can be filled within one time-period.
- ‘ invest_relation_output_capacity ‘ fixes the output flow investment to the capacity investment. A ratio of ‘1’ means that the storage can be emptied within one period.
- ‘ invest_relation_input_output ‘ fixes the input flow investment to the output flow investment. For values <1, the input will be smaller and for values >1 the input flow will be larger.
You should not set all 3 parameters at the same time, since it will lead to overdetermination.
The following example pictures a Pumped Hydroelectric Energy Storage (PHES). Both flows and the storage itself (representing: pump, turbine, basin) are free in their investment. You can set the parameters to None or delete them as None is the default value.
solph.GenericStorage(
label='PHES',
inputs={b_el: solph.Flow(investment= solph.Investment(ep_costs=500))},
outputs={b_el: solph.Flow(investment= solph.Investment(ep_costs=500)},
loss_rate=0.001,
inflow_conversion_factor=0.98, outflow_conversion_factor=0.8),
investment = solph.Investment(ep_costs=40))
The following example describes a battery with flows coupled to the capacity of the storage.
solph.GenericStorage(
label='battery',
inputs={b_el: solph.Flow()},
outputs={b_el: solph.Flow()},
loss_rate=0.001,
inflow_conversion_factor=0.98,
outflow_conversion_factor=0.8,
invest_relation_input_capacity = 1/6,
invest_relation_output_capacity = 1/6,
investment = solph.Investment(ep_costs=400))
Note
See the GenericStorage
class for all parameters and the mathematical background.
OffsetTransformer (component)¶
The OffsetTransformer object makes it possible to create a Transformer with different efficiencies in part load condition. For this object it is necessary to define the inflow as a nonconvex flow and to set a minimum load. The following example illustrates how to define an OffsetTransformer for given information for the output:
eta_min = 0.5 # efficiency at minimal operation point
eta_max = 0.8 # efficiency at nominal operation point
P_out_min = 20 # absolute minimal output power
P_out_max = 100 # absolute nominal output power
# calculate limits of input power flow
P_in_min = P_out_min / eta_min
P_in_max = P_out_max / eta_max
# calculate coefficients of input-output line equation
c1 = (P_out_max-P_out_min)/(P_in_max-P_in_min)
c0 = P_out_max - c1*P_in_max
# define OffsetTransformer
solph.custom.OffsetTransformer(
label='boiler',
inputs={bfuel: solph.Flow(
nominal_value=P_in_max,
max=1,
min=P_in_min/P_in_max,
nonconvex=solph.NonConvex())},
outputs={bth: solph.Flow()},
coefficients = [c0, c1])
This example represents a boiler, which is supplied by fuel and generates heat. It is assumed that the nominal thermal power of the boiler (output power) is 100 (kW) and the efficiency at nominal power is 80 %. The boiler cannot operate under 20 % of nominal power, in this case 20 (kW) and the efficiency at that part load is 50 %. Note that the nonconvex flow has to be defined for the input flow. By using the OffsetTransformer a linear relation of in- and output power with a power dependent efficiency is generated. The following figures illustrate the relations:
Now, it becomes clear, why this object has been named OffsetTransformer. The
linear equation of in- and outflow does not hit the origin, but is offset. By multiplying
the Offset with the binary status variable of the nonconvex flow, the origin (0, 0) becomes
part of the solution space and the boiler is allowed to switch off:
Variables (V) and Parameters (P)¶ symbol attribute type explanation flow[n, o, t] V Power of output flow[i, n, t] V Power of input status[i, n, t] V binary status variable of nonconvex input flow coefficients[1][n, t] P linear coefficient 1 (slope) coefficients[0][n, t] P linear coefficient 0 (y-intersection)
The following figures shows the efficiency dependent on the output power, which results in a nonlinear relation:
The parameters and
can be given by scalars or by series in order to define a different efficiency equation for every timestep.
Note
See the OffsetTransformer
class for all parameters and the mathematical background.
ElectricalLine (custom)¶
Electrical line.
Note
See the ElectricalLine
class for all parameters and the mathematical background.
GenericCAES (custom)¶
Compressed Air Energy Storage (CAES). The following constraints describe the CAES:
Table: Symbols and attribute names of variables and parameters
Variables (V) and Parameters (P)¶ symbol attribute type explanation cmp_st[n,t] V Status of compression cmp_p[n,t] V Compression power cmp_p_max[n,t] V Max. compression power cmp_q_out_sum[n,t] V
- Summed
- heat flow in compression
cmp_q_waste[n,t] V Waste heat flow from compression exp_st[n,t] V Status of expansion (binary) exp_p[n,t] V Expansion power exp_p_max[n,t] V Max. expansion power exp_q_in_sum[n,t] V Summed heat flow in expansion exp_q_fuel_in[n,t] V Heat (external) flow into expansion exp_q_add_in[n,t] V Additional heat flow into expansion cav_level[n,t] V
- Filling level
- if CAE
cav_e_in[n,t] V Exergy flow into CAS cav_e_out[n,t] V Exergy flow from CAS tes_level[n,t] V Filling level of Thermal Energy Storage (TES) tes_e_in[n,t] V
- Heat
- flow into TES
tes_e_out[n,t] V
- Heat
- flow from TES
cmp_p_max_b[n,t] P
- Specific
- y-intersection
cmp_q_out_b[n,t] P Specific y-intersection exp_p_max_b[n,t] P Specific y-intersection exp_q_in_b[n,t] P Specific y-intersection cav_e_in_b[n,t] P Specific y-intersection cav_e_out_b[n,t] P Specific y-intersection cmp_p_max_m[n,t] P
- Specific
- slope
cmp_q_out_m[n,t] P
- Specific
- slope
exp_p_max_m[n,t] P
- Specific
- slope
exp_q_in_m[n,t] P
- Specific
- slope
cav_e_in_m[n,t] P
- Specific
- slope
cav_e_out_m[n,t] P
- Specific
- slope
cmp_p_min[n,t] P Min. compression power cmp_q_tes_share[n,t] P
- Ratio
- between waste heat flow and heat flow into TES
exp_q_tes_share[n,t] P
- Ratio
- between external heat flow into expansion and heat flows from TES and
- additional source
m.timeincrement[n,t] P
- Time interval
- length
tes_level_max[n,t] P Max. filling level of TES cav_level_max[n,t] P
- Max.
- filling level of TES
cav_eta_tmp[n,t] P
- Temporal efficiency
- (loss factor to take intertemporal losses into account)
flow[list(n.electrical_input.keys())[0], n, t] P Electr. power input into compression flow[n, list(n.electrical_output.keys())[0], t] P Electr. power output of expansion flow[list(n.fuel_input.keys())[0], n, t] P
- Heat input
- (external) into Expansion
Note
See the GenericCAES
class for all parameters and the mathematical background.
SinkDSM (custom)¶
SinkDSM
can used to represent flexibility in a demand time series.
It can represent both, load shifting or load shedding.
For load shifting, elasticity of the demand is described by upper (~oemof.solph.custom.sink_dsm.SinkDSM.capacity_up) and lower (~oemof.solph.custom.SinkDSM.capacity_down) bounds where within the demand is allowed to vary.
Upwards shifted demand is then balanced with downwards shifted demand.
For load shedding, shedding capability is described by ~oemof.solph.custom.SinkDSM.capacity_down.
It both, load shifting and load shedding are allowed, ~oemof.solph.custom.SinkDSM.capacity_down limits the sum of both downshift categories.
SinkDSM
provides three approaches how the Demand-Side Management (DSM) flexibility is represented in constraints
It can be used for both, dispatch and investments modeling.
- “DLR”: Implementation of the DSM modeling approach from by Gils (2015): Balancing of Intermittent Renewable Power Generation by Demand Response and Thermal Energy Storage, Stuttgart,,
Details:
SinkDSMDLRBlock
andSinkDSMDLRInvestmentBlock
- “DIW”: Implementation of the DSM modeling approach by Zerrahn & Schill (2015): On the representation of demand-side management in power system models,
in: Energy (84), pp. 840-845, 10.1016/j.energy.2015.03.037. Details:
SinkDSMDIWBlock
andSinkDSMDIWInvestmentBlock
- “oemof”: Is a fairly simple approach. Within a defined windows of time steps, demand can be shifted within the defined bounds of elasticity.
The window sequentially moves forwards. Details:
SinkDSMOemofBlock
andSinkDSMOemofInvestmentBlock
Cost can be associated to either demand up shifts or demand down shifts or both.
This small example of PV, grid and SinkDSM shows how to use the component
# Create some data
pv_day = [(-(1 / 6 * x ** 2) + 6) / 6 for x in range(-6, 7)]
pv_ts = [0] * 6 + pv_day + [0] * 6
data_dict = {"demand_el": [3] * len(pv_ts),
"pv": pv_ts,
"Cap_up": [0.5] * len(pv_ts),
"Cap_do": [0.5] * len(pv_ts)}
data = pd.DataFrame.from_dict(data_dict)
# Do timestamp stuff
datetimeindex = pd.date_range(start='1/1/2013', periods=len(data.index), freq='H')
data['timestamp'] = datetimeindex
data.set_index('timestamp', inplace=True)
# Create Energy System
es = solph.EnergySystem(timeindex=datetimeindex)
Node.registry = es
# Create bus representing electricity grid
b_elec = solph.Bus(label='Electricity bus')
# Create a back supply
grid = solph.Source(label='Grid',
outputs={
b_elec: solph.Flow(
nominal_value=10000,
variable_costs=50)}
)
# PV supply from time series
s_wind = solph.Source(label='wind',
outputs={
b_elec: solph.Flow(
fix=data['pv'],
nominal_value=3.5)}
)
# Create DSM Sink
demand_dsm = solph.custom.SinkDSM(label="DSM",
inputs={b_elec: solph.Flow()},
demand=data['demand_el'],
capacity_up=data["Cap_up"],
capacity_down=data["Cap_do"],
delay_time=6,
max_demand=1,
max_capacity_up=1,
max_capacity_down=1,
approach="DIW",
cost_dsm_down=5)
Yielding the following results
Note
- Keyword argument method from v0.4.1 has been renamed to approach in v0.4.2 and methods have been renamed.
- The parameters demand, capacity_up and capacity_down have been normalized to allow investments modeling. To retreive the original dispatch behaviour from v0.4.1, set max_demand=1, max_capacity_up=1, max_capacity_down=1.
- This component is a candidate component. It’s implemented as a custom component for users that like to use and test the component at early stage. Please report issues to improve the component.
- See the
SinkDSM
class for all parameters and the mathematical background.
Using the investment mode¶
As described in Optimise your energy system the typical way to optimise an energy system is the dispatch optimisation based on marginal costs. Solph also provides a combined dispatch and investment optimisation. Based on investment costs you can compare the usage of existing components against building up new capacity. The annual savings by building up new capacity must therefore compensate the annuity of the investment costs (the time period does not have to be one year but depends on your Datetime index).
See the API of the Investment
class to see all possible parameters.
Basically an instance of the investment class can be added to a Flow or a Storage. All parameters that usually refer to the nominal_value/capacity will now refer to the investment variables and existing capacity. It is also possible to set a maximum limit for the capacity that can be build. If existing capacity is considered for a component with investment mode enabled, the ep_costs still apply only to the newly built capacity.
The investment object can be used in Flows and some components. See the Solph components section for detailed information of each component.
For example if you want to find out what would be the optimal capacity of a wind power plant to decrease the costs of an existing energy system, you can define this model and add an investment source. The wind_power_time_series has to be a normalised feed-in time series of you wind power plant. The maximum value might be caused by limited space for wind turbines.
solph.Source(label='new_wind_pp', outputs={electricity: solph.Flow(
fix=wind_power_time_series,
investment=solph.Investment(ep_costs=epc, maximum=50000))})
Let’s slightly alter the case and consider for already existing wind power capacity of 20,000 kW. We’re still expecting the total wind power capacity, thus we allow for 30,000 kW of new installations and formulate as follows.
solph.Source(label='new_wind_pp', outputs={electricity: solph.Flow(
fix=wind_power_time_series,
investment=solph.Investment(ep_costs=epc,
maximum=30000,
existing=20000))})
The periodical costs (ep_costs) are typically calculated as follows:
capex = 1000 # investment cost
lifetime = 20 # life expectancy
wacc = 0.05 # weighted average of capital cost
epc = capex * (wacc * (1 + wacc) ** lifetime) / ((1 + wacc) ** lifetime - 1)
This also implemented in the annuity function of the economics module in the oemof.tools package. The code above would look like this:
from oemof.tools import economics
epc = economics.annuity(1000, 20, 0.05)
So far, the investment costs and the installed capacity are mathematically a line through origin. But what if there is a minimum threshold for doing an investment, e.g. you cannot buy gas turbines lower than a certain nominal power, or, the marginal costs of bigger plants decrease. Therefore, you can use the parameter nonconvex and offset of the investment class. Both, work with investment in flows and storages. Here is an example of an transformer:
trafo = solph.Transformer(
label='transformer_nonconvex',
inputs={bus_0: solph.Flow()},
outputs={bus_1: solph.Flow(
investment=solph.Investment(
ep_costs=4,
maximum=100,
minimum=20,
nonconvex=True,
offset=400))},
conversion_factors={bus_1: 0.9})
In this examples, it is assumed, that independent of the size of the transformer, there are always fix investment costs of 400 (€). The minimum investment size is 20 (kW) and the costs per installed unit are 4 (€/kW). With this option, you could theoretically approximate every cost function you want. But be aware that for every nonconvex investment flow or storage you are using, an additional binary variable is created. This might boost your computing time into the limitless.
The following figures illustrates the use of the nonconvex investment flow.
Here, is the offset value and
is
the ep_costs value:
In case of a convex investment (which is the default setting nonconvex=Flase), the minimum attribute leads to a forced investment, whereas in the nonconvex case, the investment can become zero as well.
The calculation of the specific costs per kilowatt installed capacity results in the following relation for convex and nonconvex investments:
See InvestmentFlow
and
GenericInvestmentStorageBlock
for all the
mathematical background, like variables and constraints, which are used.
Note
At the moment the investment class is not compatible with the MIP classes NonConvex
.
Mixed Integer (Linear) Problems¶
Solph also allows you to model components with respect to more technical details
such as a minimal power production. Therefore, the class
NonConvex
exists in the
options
module.
Note that the usage of this class is currently not compatible with the
Investment
class.
If you want to use the functionality of the options-module, the only thing you have to do is to invoke a class instance inside your Flow() - declaration:
b_gas = solph.Bus(label='natural_gas')
b_el = solph.Bus(label='electricity')
b_th = solph.Bus(label='heat')
solph.Transformer(
label='pp_chp',
inputs={b_gas: Flow()},
outputs={b_el: Flow(nominal_value=30,
min=0.5,
nonconvex=NonConvex()),
b_th: Flow(nominal_value=40)},
conversion_factors={b_el: 0.3, b_th: 0.4})
The NonConvex() object of the electrical output of the created LinearTransformer will create
a ‘status’ variable for the flow.
This will be used to model for example minimal/maximal power production constraints if the
attributes min/max of the flow are set. It will also be used to include start up constraints and costs
if corresponding attributes of the class are provided. For more
information see the API of the NonConvex
class and its corresponding
block class NonConvexFlow
.
Note
The usage of this class can sometimes be tricky as there are many interdenpendencies. So check out the examples and do not hesitate to ask the developers if your model does not work as expected.
Adding additional constraints¶
You can add additional constraints to your Model
. See flexible_modelling in the example repository to learn how to do it.
Some predefined additional constraints can be found in the
constraints
module.
- Emission limit for the model ->
emission_limit()
- Generic integral limit (general form of emission limit) ->
generic_integral_limit()
- Coupling of two variables e.g. investment variables) with a factor ->
equate_variables()
- Overall investment limit ->
investment_limit()
- Generic investment limit ->
additional_investment_flow_limit()
- Limit active flow count ->
limit_active_flow_count()
- Limit active flow count by keyword ->
limit_active_flow_count_by_keyword()
The Grouping module (Sets)¶
To construct constraints,
variables and objective expressions inside all Block classes
and the models
modules, so called groups are used. Consequently,
certain constraints are created for all elements of a specific group. Thus,
mathematically the groups depict sets of elements inside the model.
The grouping is handled by the solph grouping module groupings
which is based on the groupings module functionality of oemof network. You
do not need to understand how the underlying functionality works. Instead, checkout
how the solph grouping module is used to create groups.
The simplest form is a function that looks at every node of the energy system and returns a key for the group depending e.g. on node attributes:
def constraint_grouping(node):
if isinstance(node, Bus) and node.balanced:
return blocks.Bus
if isinstance(node, Transformer):
return blocks.Transformer
GROUPINGS = [constraint_grouping]
This function can be passed in a list to groupings of
oemof.solph.network.energy_system.EnergySystem
. So that we end up with two groups,
one with all Transformers and one with all Buses that are balanced. These
groups are simply stored in a dictionary. There are some advanced functionalities
to group two connected nodes with their connecting flow and others
(see for example: FlowsWithNodes class in the oemof.network package).
Using the Excel (csv) reader¶
Alternatively to a manual creation of energy system component objects as describe above, can also be created from a excel sheet (libreoffice, gnumeric…).
The idea is to create different sheets within one spreadsheet file for different components. Afterwards you can loop over the rows with the attributes in the columns. The name of the columns may differ from the name of the attribute. You may even create two sheets for the GenericStorage class with attributes such as C-rate for batteries or capacity of turbine for a PHES.
Once you have create your specific excel reader you can lower the entry barrier for other users. It is some sort of a GUI in form of platform independent spreadsheet software and to make data and models exchangeable in one archive.
See oemof’s example repository for an excel reader example.
Handling Results¶
The main purpose of the processing module is to collect and organise results. The views module will provide some typical representations of the results. Plots are not part of solph, because plots are highly individual. However, the provided pandas.DataFrames are a good start for plots. Some basic functions for plotting of optimisation results can be found in the separate repository oemof_visio.
The processing.results
function gives back the results as a python
dictionary holding pandas Series for scalar values and pandas DataFrames for
all nodes and flows between them. This way we can make use of the full power
of the pandas package available to process the results.
See the pandas documentation to learn how to visualise, read or write or how to access parts of the DataFrame to process them.
The results chapter consists of three parts:
The first step is the processing of the results (Collecting results) This is followed by basic examples of the general analysis of the results (General approach) and finally the use of functionality already included in solph for providing a quick access to your results (Easy access). Especially for larger energy systems the general approach will help you to write your own results processing functions.
Collecting results¶
Collecting results can be done with the help of the processing module. A solved model is needed:
[...]
model.solve(solver=solver)
results = solph.processing.results(model)
The scalars and sequences describe nodes (with keys like (node, None)) and flows between nodes (with keys like (node_1, node_2)). You can directly extract the data in the dictionary by using these keys, where “node” is the name of the object you want to address. Processing the results is the prerequisite for the examples in the following sections.
General approach¶
As stated above, after processing you will get a dictionary with all result data. If you want to access your results directly via labels, you can continue with Easy access. For a systematic analysis list comprehensions are the easiest way of filtering and analysing your results.
The keys of the results dictionary are tuples containing two nodes. Since flows have a starting node and an ending node, you get a list of all flows by filtering the results using the following expression:
flows = [x for x in results.keys() if x[1] is not None]
On the same way you can get a list of all nodes by applying:
nodes = [x for x in results.keys() if x[1] is None]
Probably you will just get storages as nodes, if you have some in your energy system. Note, that just nodes containing decision variables are listed, e.g. a Source or a Transformer object does not have decision variables. These are in the flows from or to the nodes.
All items within the results dictionary are dictionaries and have two items with ‘scalars’ and ‘sequences’ as keys:
for flow in flows:
print(flow)
print(results[flow]['scalars'])
print(results[flow]['sequences'])
There many options of filtering the flows and nodes as you prefer. The following will give you all flows which are outputs of transformer:
flows_from_transformer = [x for x in flows if isinstance(
x[0], solph.Transformer)]
You can filter your flows, if the label of in- or output contains a given string, e.g.:
flows_to_elec = [x for x in results.keys() if 'elec' in x[1].label]
Getting all labels of the starting node of your investment flows:
flows_invest = [x[0].label for x in flows if hasattr(
results[x]['scalars'], 'invest')]
Easy access¶
The solph package provides some functions which will help you to access your results directly via labels, which is helpful especially for small energy systems. So, if you want to address objects by their label, you can convert the results dictionary such that the keys are changed to strings given by the labels:
views.convert_keys_to_strings(results)
print(results[('wind', 'bus_electricity')]['sequences']
Another option is to access data belonging to a grouping by the name of the grouping (note also this section on groupings. Given the label of an object, e.g. ‘wind’ you can access the grouping by its label and use this to extract data from the results dictionary.
node_wind = energysystem.groups['wind']
print(results[(node_wind, bus_electricity)])
However, in many situations it might be convenient to use the views module to collect information on a specific node. You can request all data related to a specific node by using either the node’s variable name or its label:
data_wind = solph.views.node(results, 'wind')
A function for collecting and printing meta results, i.e. information on the objective function, the problem and the solver, is provided as well:
meta_results = solph.processing.meta_results(om)
pp.pprint(meta_results)
API Reference¶
oemof.solph package¶
Submodules¶
oemof.solph.EnergySystem¶
solph version of oemof.network.energy_system
-
class
oemof.solph.network.energy_system.
EnergySystem
(**kwargs)[source]¶ Bases:
oemof.network.energy_system.EnergySystem
A variant of the class EnergySystem from <oemof.network.network.energy_system.EnergySystem> specially tailored to solph.
In order to work in tandem with solph, instances of this class always use solph.GROUPINGS <oemof.solph.GROUPINGS>. If custom groupings are supplied via the groupings keyword argument, solph.GROUPINGS <oemof.solph.GROUPINGS> is prepended to those.
If you know what you are doing and want to use solph without solph.GROUPINGS <oemof.solph.GROUPINGS>, you can just use EnergySystem <oemof.network.network.energy_system.EnergySystem>` of oemof.network directly.
oemof.solph.Bus¶
solph version of oemof.network.bus
-
class
oemof.solph.network.bus.
Bus
(*args, **kwargs)[source]¶ Bases:
oemof.network.network.Bus
A balance object. Every node has to be connected to Bus.
Notes
- The following sets, variables, constraints and objective parts are created
Creating sets, variables, constraints and parts of the objective function for Bus objects.
oemof.solph.Flow¶
solph version of oemof.network.Edge
-
class
oemof.solph.network.flow.
Flow
(**kwargs)[source]¶ Bases:
oemof.network.network.Edge
Defines a flow between two nodes.
Keyword arguments are used to set the attributes of this flow. Parameters which are handled specially are noted below. For the case where a parameter can be either a scalar or an iterable, a scalar value will be converted to a sequence containing the scalar value at every index. This sequence is then stored under the paramter’s key.
Parameters: nominal_value (numeric,
) – The nominal value of the flow. If this value is set the corresponding optimization variable of the flow object will be bounded by this value multiplied with min(lower bound)/max(upper bound).
max (numeric (iterable or scalar),
) – Normed maximum value of the flow. The flow absolute maximum will be calculated by multiplying
nominal_value
withmax
min (numeric (iterable or scalar),
) – Normed minimum value of the flow (see
max
).fix (numeric (iterable or scalar),
) – Normed fixed value for the flow variable. Will be multiplied with the
nominal_value
to get the absolute value. Iffixed
is set toTrue
the flow variable will be fixed to fix * nominal_value, i.e. this value is set exogenous.positive_gradient (
dict
, default: {‘ub’: None, ‘costs’: 0}) –A dictionary containing the following two keys:
- ‘ub’: numeric (iterable, scalar or None), the normed upper bound on the positive difference (flow[t-1] < flow[t]) of two consecutive flow values.
- ‘costs`: numeric (scalar or None), the gradient cost per unit.
negative_gradient (
dict
, default: {‘ub’: None, ‘costs’: 0}) –A dictionary containing the following two keys:
- ‘ub’: numeric (iterable, scalar or None), the normed upper bound on the negative difference (flow[t-1] > flow[t]) of two consecutive flow values.
- ‘costs`: numeric (scalar or None), the gradient cost per unit.
summed_max (numeric,
) – Specific maximum value summed over all timesteps. Will be multiplied with the nominal_value to get the absolute limit.
summed_min (numeric,
) – see above
variable_costs (numeric (iterable or scalar)) – The costs associated with one unit of the flow. If this is set the costs will be added to the objective expression of the optimization problem.
fixed (boolean) – Boolean value indicating if a flow is fixed during the optimization problem to its ex-ante set value. Used in combination with the
fix
.investment (
Investment
) – Object indicating if a nominal_value of the flow is determined by the optimization problem. Note: This will refer all attributes to an investment variable instead of to the nominal_value. The nominal_value should not be set (or set to None) if an investment object is used.nonconvex (
NonConvex
) – If a nonconvex flow object is added here, the flow constraints will be altered significantly as the mathematical model for the flow will be different, i.e. constraint etc. fromNonConvexFlow
will be used instead ofFlow
. Note: at the moment this does not work if the investment attribute is set .
Notes
- The following sets, variables, constraints and objective parts are created
Flow
InvestmentFlow
- (additionally if Investment object is present)
NonConvexFlow
- (If nonconvex object is present, CAUTION: replaces
Flow
class and a MILP will be build)
Examples
Creating a fixed flow object:
>>> f = Flow(fix=[10, 4, 4], variable_costs=5) >>> f.variable_costs[2] 5 >>> f.fix[2] 4
Creating a flow object with time-depended lower and upper bounds:
>>> f1 = Flow(min=[0.2, 0.3], max=0.99, nominal_value=100) >>> f1.max[1] 0.99
Creating sets, variables, constraints and parts of the objective function for Flow objects.
-
class
oemof.solph.blocks.flow.
Flow
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Flow block with definitions for standard flows.
The following variables are created:
- negative_gradient :
- Difference of a flow in consecutive timesteps if flow is reduced indexed by NEGATIVE_GRADIENT_FLOWS, TIMESTEPS.
- positive_gradient :
- Difference of a flow in consecutive timesteps if flow is increased indexed by NEGATIVE_GRADIENT_FLOWS, TIMESTEPS.
The following sets are created: (-> see basic sets at
Model
)- SUMMED_MAX_FLOWS
- A set of flows with the attribute
summed_max
being not None. - SUMMED_MIN_FLOWS
- A set of flows with the attribute
summed_min
being not None. - NEGATIVE_GRADIENT_FLOWS
- A set of flows with the attribute
negative_gradient
being not None. - POSITIVE_GRADIENT_FLOWS
- A set of flows with the attribute
positive_gradient
being not None - INTEGER_FLOWS
- A set of flows where the attribute
integer
is True (forces flow to only take integer values)
The following constraints are build:
- Flow max sum
om.Flow.summed_max[i, o]
- Flow min sum
om.Flow.summed_min[i, o]
- Negative gradient constraint
om.Flow.negative_gradient_constr[i, o]
:
- Positive gradient constraint
om.Flow.positive_gradient_constr[i, o]
:
The following parts of the objective function are created:
- If
variable_costs
are set by the user:
The expression can be accessed by
om.Flow.variable_costs
and their value after optimization byom.Flow.variable_costs()
.
Creating sets, variables, constraints and parts of the objective function for Flow objects with investment option.
-
class
oemof.solph.blocks.investment_flow.
InvestmentFlow
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for all flows with
Investment
being not None.See
oemof.solph.options.Investment
for all parameters of the Investment class.See
oemof.solph.network.Flow
for all parameters of the Flow class.Variables
All InvestmentFlow are indexed by a starting and ending node
, which is omitted in the following for the sake of convenience. The following variables are created:
Actual flow value (created in
oemof.solph.models.BaseModel
).Value of the investment variable, i.e. equivalent to the nominal value of the flows after optimization.
Binary variable for the status of the investment, if
nonconvex
is True.
Constraints
Depending on the attributes of the InvestmentFlow and Flow, different constraints are created. The following constraint is created for all InvestmentFlow:
Upper bound for the flow valueDepeding on the attribute
nonconvex
, the constraints for the bounds of the decision variableare different:
nonconvex = False
nonconvex = True
For all InvestmentFlow (independent of the attribute
nonconvex
), the following additional constraints are created, if the appropriate attribute of the Flow (seeoemof.solph.network.Flow
) is set:fix
is not NoneActual value constraint for investments with fixed flow values
min != 0
Lower bound for the flow values
summed_max is not None
Upper bound for the sum of all flow values (e.g. maximum full load hours)
summed_min is not None
Lower bound for the sum of all flow values (e.g. minimum full load hours)
Objective function
The part of the objective function added by the InvestmentFlow also depends on whether a convex or nonconvex InvestmentFlow is selected. The following parts of the objective function are created:
nonconvex = False
nonconvex = True
The total value of all costs of all InvestmentFlow can be retrieved calling
om.InvestmentFlow.investment_costs.expr()
.List of Variables (in csv table syntax)¶ symbol attribute explanation flow[n, o, t]
Actual flow value invest[i, o]
Invested flow capacity invest_status[i, o]
Binary status of investment List of Variables (in rst table syntax):
symbol attribute explanation flow[n, o, t]
Actual flow value invest[i, o]
Invested flow capacity invest_status[i, o]
Binary status of investment Grid table style:
symbol attribute explanation flow[n, o, t]
Actual flow value invest[i, o]
Invested flow capacity invest_status[i, o]
Binary status of investment List of Parameters¶ symbol attribute explanation flows[i, o].investment.existing
Existing flow capacity flows[i, o].investment.minimum
Minimum investment capacity flows[i, o].investment.maximum
Maximum investment capacity flows[i, o].investment.ep_costs
Variable investment costs flows[i, o].investment.offset
Fix investment costs flows[i, o].fix[t]
Normed fixed value for the flow variable flows[i, o].max[t]
Normed maximum value of the flow flows[i, o].min[t]
Normed minimum value of the flow flows[i, o].summed_max
Specific maximum of summed flow values (per installed capacity) flows[i, o].summed_min
Specific minimum of summed flow values (per installed capacity) timeincrement[t]
Time step width for each time step Note
In case of a nonconvex investment flow (
nonconvex=True
), the existing flow capacityneeds to be zero. At least, it is not tested yet, whether this works out, or makes any sense at all.
Note
See also
oemof.solph.network.Flow
,oemof.solph.blocks.Flow
andoemof.solph.options.Investment
Creating sets, variables, constraints and parts of the objective function for nonconvex Flow objects.
-
class
oemof.solph.blocks.non_convex_flow.
NonConvexFlow
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
The following sets are created: (-> see basic sets at
Model
)- A set of flows with the attribute nonconvex of type
options.NonConvex
.- MIN_FLOWS
- A subset of set NONCONVEX_FLOWS with the attribute min being not None in the first timestep.
- ACTIVITYCOSTFLOWS
- A subset of set NONCONVEX_FLOWS with the attribute activity_costs being not None.
- STARTUPFLOWS
- A subset of set NONCONVEX_FLOWS with the attribute maximum_startups or startup_costs being not None.
- MAXSTARTUPFLOWS
- A subset of set STARTUPFLOWS with the attribute maximum_startups being not None.
- SHUTDOWNFLOWS
- A subset of set NONCONVEX_FLOWS with the attribute maximum_shutdowns or shutdown_costs being not None.
- MAXSHUTDOWNFLOWS
- A subset of set SHUTDOWNFLOWS with the attribute maximum_shutdowns being not None.
- MINUPTIMEFLOWS
- A subset of set NONCONVEX_FLOWS with the attribute minimum_uptime being not None.
- MINDOWNTIMEFLOWS
- A subset of set NONCONVEX_FLOWS with the attribute minimum_downtime being not None.
- POSITIVE_GRADIENT_FLOWS
- A subset of set NONCONVEX_FLOWS with the attribute positive_gradient being not None.
- NEGATIVE_GRADIENT_FLOWS
- A subset of set NONCONVEX_FLOWS with the attribute negative_gradient being not None.
The following variables are created:
- Status variable (binary) om.NonConvexFlow.status:
- Variable indicating if flow is >= 0 indexed by FLOWS
- Startup variable (binary) om.NonConvexFlow.startup:
- Variable indicating startup of flow (component) indexed by STARTUPFLOWS
- Shutdown variable (binary) om.NonConvexFlow.shutdown:
- Variable indicating shutdown of flow (component) indexed by SHUTDOWNFLOWS
- Positive gradient (continuous) om.NonConvexFlow.positive_gradient:
- Variable indicating the positive gradient, i.e. the load increase between two consecutive timesteps, indexed by POSITIVE_GRADIENT_FLOWS
- Negative gradient (continuous) om.NonConvexFlow.negative_gradient:
- Variable indicating the negative gradient, i.e. the load decrease between two consecutive timesteps, indexed by NEGATIVE_GRADIENT_FLOWS
The following constraints are created:
- Minimum flow constraint om.NonConvexFlow.min[i,o,t]
- Maximum flow constraint om.NonConvexFlow.max[i,o,t]
- Startup constraint om.NonConvexFlow.startup_constr[i,o,t]
- Maximum startups constraint
- om.NonConvexFlow.max_startup_constr[i,o,t]
- Shutdown constraint om.NonConvexFlow.shutdown_constr[i,o,t]
- Maximum shutdowns constraint
- om.NonConvexFlow.max_startup_constr[i,o,t]
- Minimum uptime constraint om.NonConvexFlow.uptime_constr[i,o,t]
- Minimum downtime constraint om.NonConvexFlow.downtime_constr[i,o,t]
- Positive gradient constraint
- om.NonConvexFlow.positive_gradient_constr[i, o]:
- flow(i, o, t-1) cdot status(i, o, t-1) geq positive_gradient(i, o, t), \ forall (i, o) in textrm{POSITIVE_GRADIENT_FLOWS}, \ forall t in textrm{TIMESTEPS}.
- Negative gradient constraint
- om.NonConvexFlow.negative_gradient_constr[i, o]:
The following parts of the objective function are created:
- If nonconvex.startup_costs is set by the user:
- If nonconvex.shutdown_costs is set by the user:
- If nonconvex.activity_costs is set by the user:
- If nonconvex.positive_gradient[“costs”] is set by the user:
- If nonconvex.negative_gradient[“costs”] is set by the user:
oemof.solph.Sink¶
solph version of oemof.network.Sink
oemof.solph.Source¶
solph version of oemof.network.Source
oemof.solph.Transformer¶
solph version of oemof.network.Transformer
-
class
oemof.solph.network.transformer.
Transformer
(*args, **kwargs)[source]¶ Bases:
oemof.network.network.Transformer
A linear Transformer object with n inputs and n outputs.
Parameters: conversion_factors (dict) – Dictionary containing conversion factors for conversion of each flow. Keys are the connected bus objects. The dictionary values can either be a scalar or an iterable with length of time horizon for simulation. Examples
Defining an linear transformer:
>>> from oemof import solph >>> bgas = solph.Bus(label='natural_gas') >>> bcoal = solph.Bus(label='hard_coal') >>> bel = solph.Bus(label='electricity') >>> bheat = solph.Bus(label='heat')
>>> trsf = solph.Transformer( ... label='pp_gas_1', ... inputs={bgas: solph.Flow(), bcoal: solph.Flow()}, ... outputs={bel: solph.Flow(), bheat: solph.Flow()}, ... conversion_factors={bel: 0.3, bheat: 0.5, ... bgas: 0.8, bcoal: 0.2}) >>> print(sorted([x[1][5] for x in trsf.conversion_factors.items()])) [0.2, 0.3, 0.5, 0.8]
>>> type(trsf) <class 'oemof.solph.network.transformer.Transformer'>
>>> sorted([str(i) for i in trsf.inputs]) ['hard_coal', 'natural_gas']
>>> trsf_new = solph.Transformer( ... label='pp_gas_2', ... inputs={bgas: solph.Flow()}, ... outputs={bel: solph.Flow(), bheat: solph.Flow()}, ... conversion_factors={bel: 0.3, bheat: 0.5}) >>> trsf_new.conversion_factors[bgas][3] 1
Notes
- The following sets, variables, constraints and objective parts are created
Creating sets, variables, constraints and parts of the objective function for Transformer objects.
-
class
oemof.solph.blocks.transformer.
Transformer
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for the linear relation of nodes with type
Transformer
The following sets are created: (-> see basic sets at
Model
)- TRANSFORMERS
- A set with all
Transformer
objects.
The following constraints are created:
- Linear relation
om.Transformer.relation[i,o,t]
symbol attribute explanation flow[i, n, t] - Transformer
- inflow
flow[n, o, t] - Transformer
- outflow
conversion_factor[i, n, t] - Conversion
- efficiency
oemof.solph.components.ExtractionTurbineCHP¶
ExtractionTurbineCHP and associated individual constraints (blocks) and groupings.
-
class
oemof.solph.components.extraction_turbine_chp.
ExtractionTurbineCHP
(conversion_factor_full_condensation, *args, **kwargs)[source]¶ Bases:
oemof.solph.network.transformer.Transformer
A CHP with an extraction turbine in a linear model. For more options see the
GenericCHP
class.One main output flow has to be defined and is tapped by the remaining flow. The conversion factors have to be defined for the maximum tapped flow ( full CHP mode) and for no tapped flow (full condensing mode). Even though it is possible to limit the variability of the tapped flow, so that the full condensing mode will never be reached.
Parameters: - conversion_factors (dict) – Dictionary containing conversion factors for conversion of inflow to specified outflow. Keys are output bus objects. The dictionary values can either be a scalar or a sequence with length of time horizon for simulation.
- conversion_factor_full_condensation (dict) – The efficiency of the main flow if there is no tapped flow. Only one key is allowed. Use one of the keys of the conversion factors. The key indicates the main flow. The other output flow is the tapped flow.
Notes
- The following sets, variables, constraints and objective parts are created
Examples
>>> from oemof import solph >>> bel = solph.Bus(label='electricityBus') >>> bth = solph.Bus(label='heatBus') >>> bgas = solph.Bus(label='commodityBus') >>> et_chp = solph.components.ExtractionTurbineCHP( ... label='variable_chp_gas', ... inputs={bgas: solph.Flow(nominal_value=10e10)}, ... outputs={bel: solph.Flow(), bth: solph.Flow()}, ... conversion_factors={bel: 0.3, bth: 0.5}, ... conversion_factor_full_condensation={bel: 0.5})
-
class
oemof.solph.components.extraction_turbine_chp.
ExtractionTurbineCHPBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for the linear relation of nodes with type
ExtractionTurbineCHP
The following two constraints are created:
where
is defined as:
where the first equation is the result of the relation between the input flow and the two output flows, the second equation stems from how the two output flows relate to each other, and the symbols used are defined as follows (with Variables (V) and Parameters (P)):
symbol attribute type explanation flow[i, n, t] V fuel input flow flow[n, main_output, t] V electric power flow[n, tapped_output, t] V thermal output main_flow_loss_index[n, t] P power loss index conversion_factor_full_condensation[n, t] P - electric efficiency
- without heat extraction
conversion_factors[main_output][n, t] P - electric efficiency
- with max heat extraction
conversion_factors[tapped_output][n, t] P - thermal efficiency with
- maximal heat extraction
-
CONSTRAINT_GROUP
= True¶
oemof.solph.components.GenericCHP¶
GenericCHP and associated individual constraints (blocks) and groupings.
-
class
oemof.solph.components.generic_chp.
GenericCHP
(*args, **kwargs)[source]¶ Bases:
oemof.network.network.Transformer
Component GenericCHP to model combined heat and power plants.
Can be used to model (combined cycle) extraction or back-pressure turbines and used a mixed-integer linear formulation. Thus, it induces more computational effort than the ExtractionTurbineCHP for the benefit of higher accuracy.
The full set of equations is described in: Mollenhauer, E., Christidis, A. & Tsatsaronis, G. Evaluation of an energy- and exergy-based generic modeling approach of combined heat and power plants Int J Energy Environ Eng (2016) 7: 167. https://doi.org/10.1007/s40095-016-0204-6
For a general understanding of (MI)LP CHP representation, see: Fabricio I. Salgado, P. Short - Term Operation Planning on Cogeneration Systems: A Survey Electric Power Systems Research (2007) Electric Power Systems Research Volume 78, Issue 5, May 2008, Pages 835-848 https://doi.org/10.1016/j.epsr.2007.06.001
Note
An adaption for the flow parameter H_L_FG_share_max has been made to set the flue gas losses at maximum heat extraction H_L_FG_max as share of the fuel flow H_F e.g. for combined cycle extraction turbines. The flow parameter H_L_FG_share_min can be used to set the flue gas losses at minimum heat extraction H_L_FG_min as share of the fuel flow H_F e.g. for motoric CHPs. The boolean component parameter back_pressure can be set to model back-pressure characteristics.
Also have a look at the examples on how to use it.
Parameters: - fuel_input (dict) – Dictionary with key-value-pair of oemof.Bus and oemof.Flow object for the fuel input.
- electrical_output (dict) – Dictionary with key-value-pair of oemof.Bus and oemof.Flow object for the electrical output. Related parameters like P_max_woDH are passed as attributes of the oemof.Flow object.
- heat_output (dict) – Dictionary with key-value-pair of oemof.Bus and oemof.Flow object for the heat output. Related parameters like Q_CW_min are passed as attributes of the oemof.Flow object.
- Beta (list of numerical values) – Beta values in same dimension as all other parameters (length of optimization period).
- back_pressure (boolean) – Flag to use back-pressure characteristics. Set to True and Q_CW_min to zero for back-pressure turbines. See paper above for more information.
Note
- The following sets, variables, constraints and objective parts are created
Examples
>>> from oemof import solph >>> bel = solph.Bus(label='electricityBus') >>> bth = solph.Bus(label='heatBus') >>> bgas = solph.Bus(label='commodityBus') >>> ccet = solph.components.GenericCHP( ... label='combined_cycle_extraction_turbine', ... fuel_input={bgas: solph.Flow( ... H_L_FG_share_max=[0.183])}, ... electrical_output={bel: solph.Flow( ... P_max_woDH=[155.946], ... P_min_woDH=[68.787], ... Eta_el_max_woDH=[0.525], ... Eta_el_min_woDH=[0.444])}, ... heat_output={bth: solph.Flow( ... Q_CW_min=[10.552])}, ... Beta=[0.122], back_pressure=False) >>> type(ccet) <class 'oemof.solph.components.generic_chp.GenericCHP'>
-
alphas
¶ Compute or return the _alphas attribute.
-
class
oemof.solph.components.generic_chp.
GenericCHPBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for the relation of the
nodes with type class:.GenericCHP.
The following constraints are created:
where
depends on the CHP being back pressure or not.
The coefficients
and
can be determined given the efficiencies maximal/minimal load:
For the attribute
being not None, e.g. for a motoric CHP, the following is created:
Constraint:The symbols used are defined as follows (with Variables (V) and Parameters (P)):
math. symbol attribute type explanation H_F[n,t] V - input of enthalpy
- through fuel input
P[n,t] V - provided
- electric power
P_woDH[n,t] V - electric power without
- district heating
P_min_woDH[n,t] P - min. electric power
- without district heating
P_max_woDH[n,t] P - max. electric power
- without district heating
Q[n,t] V provided heat Q_CW_min[n,t] P - minimal therm. condenser
- load to cooling water
H_L_FG_min[n,t] V - flue gas enthalpy loss
- at min heat extraction
H_L_FG_max[n,t] V - flue gas enthalpy loss
- at max heat extraction
H_L_FG_share_min[n,t] P - share of flue gas loss
- at min heat extraction
H_L_FG_share_max[n,t] P - share of flue gas loss
- at max heat extraction
Y[n,t] V - status variable
- on/off
n.alphas[0][n,t] P - coefficient
- describing efficiency
n.alphas[1][n,t] P - coefficient
- describing efficiency
Beta[n,t] P power loss index Eta_el_min_woDH[n,t] P - el. eff. at min. fuel
- flow w/o distr. heating
Eta_el_max_woDH[n,t] P - el. eff. at max. fuel
- flow w/o distr. heating
-
CONSTRAINT_GROUP
= True¶
oemof.solph.components.GenericStorage¶
GenericStorage and associated individual constraints (blocks) and groupings.
-
class
oemof.solph.components.generic_storage.
GenericInvestmentStorageBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for all storages with
Investment
being not None. Seeoemof.solph.options.Investment
for all parameters of the Investment class.Variables
All Storages are indexed by
, which is omitted in the following for the sake of convenience. The following variables are created as attributes of
om.InvestmentStorage
:Inflow of the storage (created in
oemof.solph.models.BaseModel
).Outflow of the storage (created in
oemof.solph.models.BaseModel
).Current storage content (Absolute level of stored energy).
Invested (nominal) capacity of the storage.
Initial storage content (before timestep 0).
Binary variable for the status of the investment, if
nonconvex
is True.
Constraints
The following constraints are created for all investment storages:
Storage balance (Same as forGenericStorageBlock
)Depending on the attribute
nonconvex
, the constraints for the bounds of the decision variableare different:
nonconvex = False
nonconvex = True
The following constraints are created depending on the attributes of the
components.GenericStorage
:initial_storage_level is None
Constraint for a variable initial storage content:
initial_storage_level is not None
An initial value for the storage content is given:
balanced=True
The energy content of storage of the first and the last timestep are set equal:
invest_relation_input_capacity is not None
Connect the invest variables of the storage and the input flow:
invest_relation_output_capacity is not None
Connect the invest variables of the storage and the output flow:
invest_relation_input_output is not None
Connect the invest variables of the input and the output flow:
max_storage_level
Rule for upper bound constraint for the storage content:
min_storage_level
Rule for lower bound constraint for the storage content:
Objective function
The part of the objective function added by the investment storages also depends on whether a convex or nonconvex investment option is selected. The following parts of the objective function are created:
nonconvex = False
nonconvex = True
The total value of all investment costs of all InvestmentStorages can be retrieved calling
om.GenericInvestmentStorageBlock.investment_costs.expr()
.List of Variables¶ symbol attribute explanation flow[i[n], n, t]
Inflow of the storage flow[n, o[n], t]
Outlfow of the storage storage_content[n, t]
Current storage content (current absolute stored energy) invest[n, t]
Invested (nominal) capacity of the storage init_cap[n]
Initial storage capacity (before timestep 0) invest_status[i, o]
Binary variable for the status of investment InvestmentFlow.invest[i[n], n]
Invested (nominal) inflow (Investmentflow) InvestmentFlow.invest[n, o[n]]
Invested (nominal) outflow (Investmentflow) List of Parameters¶ symbol attribute explanation flows[i, o].investment.existing Existing storage capacity flows[i, o].investment.minimum Minimum investment value flows[i, o].investment.maximum Maximum investment value flows[i[n], n].investment.existing Existing inflow capacity flows[n, o[n]].investment.existing Existing outlfow capacity flows[i, o].investment.ep_costs Variable investment costs flows[i, o].investment.offset Fix investment costs invest_relation_input_capacity
Relation of storage capacity and nominal inflow invest_relation_output_capacity
Relation of storage capacity and nominal outflow invest_relation_input_output
Relation of nominal in- and outflow loss_rate[t] Fraction of lost energy as share of per time unit
fixed_losses_relative[t] Fixed loss of energy relative to per time unit
fixed_losses_absolute[t] Absolute fixed loss of energy per time unit inflow_conversion_factor[t] Conversion factor (i.e. efficiency) when storing energy outflow_conversion_factor[t] Conversion factor when (i.e. efficiency) taking stored energy initial_storage_level Initial relativ storage content (before timestep 0) flows[i, o].max[t] Normed maximum value of storage content flows[i, o].min[t] Normed minimum value of storage content Duration of time step Time unit of losses ,
,
and timeincrement
-
CONSTRAINT_GROUP
= True¶
-
class
oemof.solph.components.generic_storage.
GenericStorage
(*args, max_storage_level=1, min_storage_level=0, **kwargs)[source]¶ Bases:
oemof.network.network.Node
Component GenericStorage to model with basic characteristics of storages.
The GenericStorage is designed for one input and one output.
Parameters: - nominal_storage_capacity (numeric,
) – Absolute nominal capacity of the storage
- invest_relation_input_capacity (numeric or None,
) – Ratio between the investment variable of the input Flow and the investment variable of the storage:
- invest_relation_output_capacity (numeric or None,
) – Ratio between the investment variable of the output Flow and the investment variable of the storage:
- invest_relation_input_output (numeric or None,
) – Ratio between the investment variable of the output Flow and the investment variable of the input flow. This ratio used to fix the flow investments to each other. Values < 1 set the input flow lower than the output and > 1 will set the input flow higher than the output flow. If None no relation will be set:
- initial_storage_level (numeric,
) – The relative storage content in the timestep before the first time step of optimization (between 0 and 1).
- balanced (boolean) – Couple storage level of first and last time step. (Total inflow and total outflow are balanced.)
- loss_rate (numeric (iterable or scalar)) – The relative loss of the storage content per time unit.
- fixed_losses_relative (numeric (iterable or scalar),
) – Losses independent of state of charge between two consecutive timesteps relative to nominal storage capacity.
- fixed_losses_absolute (numeric (iterable or scalar),
) – Losses independent of state of charge and independent of nominal storage capacity between two consecutive timesteps.
- inflow_conversion_factor (numeric (iterable or scalar),
) – The relative conversion factor, i.e. efficiency associated with the inflow of the storage.
- outflow_conversion_factor (numeric (iterable or scalar),
) – see: inflow_conversion_factor
- min_storage_level (numeric (iterable or scalar),
) – The normed minimum storage content as fraction of the nominal storage capacity (between 0 and 1). To set different values in every time step use a sequence.
- max_storage_level (numeric (iterable or scalar),
) – see: min_storage_level
- investment (
oemof.solph.options.Investment
object) – Object indicating if a nominal_value of the flow is determined by the optimization problem. Note: This will refer all attributes to an investment variable instead of to the nominal_storage_capacity. The nominal_storage_capacity should not be set (or set to None) if an investment object is used.
Notes
- The following sets, variables, constraints and objective parts are created
GenericStorageBlock
(if no Investment object present)GenericInvestmentStorageBlock
(if Investment object present)
Examples
Basic usage examples of the GenericStorage with a random selection of attributes. See the Flow class for all Flow attributes.
>>> from oemof import solph
>>> my_bus = solph.Bus('my_bus')
>>> my_storage = solph.components.GenericStorage( ... label='storage', ... nominal_storage_capacity=1000, ... inputs={my_bus: solph.Flow(nominal_value=200, variable_costs=10)}, ... outputs={my_bus: solph.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.93)
>>> my_investment_storage = solph.components.GenericStorage( ... label='storage', ... investment=solph.Investment(ep_costs=50), ... inputs={my_bus: solph.Flow()}, ... outputs={my_bus: solph.Flow()}, ... loss_rate=0.02, ... initial_storage_level=None, ... invest_relation_input_capacity=1/6, ... invest_relation_output_capacity=1/6, ... inflow_conversion_factor=1, ... outflow_conversion_factor=0.8)
- nominal_storage_capacity (numeric,
-
class
oemof.solph.components.generic_storage.
GenericStorageBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Storage without an
Investment
object.The following sets are created: (-> see basic sets at
Model
)- STORAGES
- A set with all
Storage
objects, which do not have an - attr:investment of type
Investment
.
- A set with all
- STORAGES_BALANCED
- A set of all
GenericStorage
objects, with ‘balanced’ attribute set to True. - STORAGES_WITH_INVEST_FLOW_REL
- A set with all
Storage
objects with two investment flows coupled with the ‘invest_relation_input_output’ attribute.
The following variables are created:
- storage_content
- Storage content for every storage and timestep. The value for the storage content at the beginning is set by the parameter initial_storage_level or not set if initial_storage_level is None. The variable of storage s and timestep t can be accessed by: om.Storage.storage_content[s, t]
The following constraints are created:
- Set storage_content of last time step to one at t=0 if balanced == True
- Storage balance
om.Storage.balance[n, t]
- Connect the invest variables of the input and the output flow.
symbol explanation attribute energy currently stored storage_content nominal capacity of the energy storage nominal_storage_capacity state before initial time step initial_storage_level minimum allowed storage min_storage_level[t] maximum allowed storage max_storage_level[t] fraction of lost energy as share of per time unit
loss_rate[t] fixed loss of energy relative to per time unit
fixed_losses_relative[t] absolute fixed loss of energy per time unit fixed_losses_absolute[t] energy flowing in inputs energy flowing out outputs conversion factor (i.e. efficiency) when storing energy inflow_conversion_factor[t] conversion factor when (i.e. efficiency) taking stored energy outflow_conversion_factor[t] duration of time step time unit of losses ,
and timeincrement
The following parts of the objective function are created:
Nothing added to the objective function.
-
CONSTRAINT_GROUP
= True¶
oemof.solph.components.OffsetTransformer¶
OffsetTransformer and associated individual constraints (blocks) and groupings.
-
class
oemof.solph.components.offset_transformer.
OffsetTransformer
(*args, **kwargs)[source]¶ Bases:
oemof.network.network.Transformer
An object with one input and one output.
Parameters: coefficients (tuple) – Tuple containing the first two polynomial coefficients i.e. the y-intersection and slope of a linear equation. The tuple values can either be a scalar or a sequence with length of time horizon for simulation. Notes
- The sets, variables, constraints and objective parts are created
Examples
>>> from oemof import solph
>>> bel = solph.Bus(label='bel') >>> bth = solph.Bus(label='bth')
>>> ostf = solph.components.OffsetTransformer( ... label='ostf', ... inputs={bel: solph.Flow( ... nominal_value=60, min=0.5, max=1.0, ... nonconvex=solph.NonConvex())}, ... outputs={bth: solph.Flow()}, ... coefficients=(20, 0.5))
>>> type(ostf) <class 'oemof.solph.components.offset_transformer.OffsetTransformer'>
-
class
oemof.solph.components.offset_transformer.
OffsetTransformerBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for the relation of nodes with type
OffsetTransformer
The following constraints are created:
Variables (V) and Parameters (P)¶ symbol attribute type explanation flow[n, o, t] V Power of output flow[i, n, t] V Power of input status[i, n, t] V binary status variable of nonconvex input flow coefficients[1][n, t] P linear coefficient 1 (slope) coefficients[0][n, t] P linear coefficient 0 (y-intersection) -
CONSTRAINT_GROUP
= True¶
-
oemof.solph.constraints module¶
Additional constraints to be used in an oemof energy model.
-
oemof.solph.constraints.
equate_variables
(model, var1, var2, factor1=1, name=None)[source]¶ Adds a constraint to the given model that set two variables to equal adaptable by a factor.
The following constraints are build:
Parameters: - var1 (pyomo.environ.Var) – First variable, to be set to equal with Var2 and multiplied with factor1.
- var2 (pyomo.environ.Var) – Second variable, to be set equal to (Var1 * factor1).
- factor1 (float) – Factor to define the proportion between the variables.
- name (str) – Optional name for the equation e.g. in the LP file. By default the name is: equate + string representation of var1 and var2.
- model (oemof.solph.Model) – Model to which the constraint is added.
Examples
The following example shows how to define a transmission line in the investment mode by connecting both investment variables. Note that the equivalent periodical costs (epc) of the line are 40. You could also add them to one line and set them to 0 for the other line.
>>> import pandas as pd >>> from oemof import solph >>> date_time_index = pd.date_range('1/1/2012', periods=5, freq='H') >>> energysystem = solph.EnergySystem(timeindex=date_time_index) >>> bel1 = solph.Bus(label='electricity1') >>> bel2 = solph.Bus(label='electricity2') >>> energysystem.add(bel1, bel2) >>> energysystem.add(solph.Transformer( ... label='powerline_1_2', ... inputs={bel1: solph.Flow()}, ... outputs={bel2: solph.Flow( ... investment=solph.Investment(ep_costs=20))})) >>> energysystem.add(solph.Transformer( ... label='powerline_2_1', ... inputs={bel2: solph.Flow()}, ... outputs={bel1: solph.Flow( ... investment=solph.Investment(ep_costs=20))})) >>> om = solph.Model(energysystem) >>> line12 = energysystem.groups['powerline_1_2'] >>> line21 = energysystem.groups['powerline_2_1'] >>> solph.constraints.equate_variables( ... om, ... om.InvestmentFlow.invest[line12, bel2], ... om.InvestmentFlow.invest[line21, bel1])
-
oemof.solph.constraints.
limit_active_flow_count
(model, constraint_name, flows, lower_limit=0, upper_limit=None)[source]¶ Set limits (lower and/or upper) for the number of concurrently active NonConvex flows. The flows are given as a list.
Total actual counts after optimization can be retrieved calling the
om.oemof.solph.Model.$(constraint_name)_count()
.Parameters: - model (oemof.solph.Model) – Model to which constraints are added
- constraint_name (string) – name for the constraint
- flows (list of flows) – flows (have to be NonConvex) in the format [(in, out)]
- lower_limit (integer) – minimum number of active flows in the list
- upper_limit (integer) – maximum number of active flows in the list
Returns: the updated model
Note
Flow objects required to be NonConvex
Constraint:
With F being the set of considered flows and T being the set of time steps.
The symbols used are defined as follows (with Variables (V) and Parameters (P)):
math. symbol type explanation V status (0 or 1) of the flow at time step
P lower_limit P lower_limit
-
oemof.solph.constraints.
limit_active_flow_count_by_keyword
(model, keyword, lower_limit=0, upper_limit=None)[source]¶ This wrapper for limit_active_flow_count allows to set limits to the count of concurrently active flows by using a keyword instead of a list. The constraint will be named $(keyword)_count.
Parameters: - model (oemof.solph.Model) – Model to which constraints are added
- keyword (string) – keyword to consider (searches all NonConvexFlows)
- lower_limit (integer) – minimum number of active flows having the keyword
- upper_limit (integer) – maximum number of active flows having the keyword
Returns: the updated model
See also
limit_active_flow_count()
,constraint_name()
,flows()
-
oemof.solph.constraints.
emission_limit
(om, flows=None, limit=None)[source]¶ Short handle for generic_integral_limit() with keyword=”emission_factor”.
Note
Flow objects required an attribute “emission_factor”!
-
oemof.solph.constraints.
generic_integral_limit
(om, keyword, flows=None, limit=None)[source]¶ Set a global limit for flows weighted by attribute called keyword. The attribute named by keyword has to be added to every flow you want to take into account.
Total value of keyword attributes after optimization can be retrieved calling the
om.oemof.solph.Model.integral_limit_${keyword}()
.Parameters: - om (oemof.solph.Model) – Model to which constraints are added.
- flows (dict) – Dictionary holding the flows that should be considered in constraint. Keys are (source, target) objects of the Flow. If no dictionary is given all flows containing the keyword attribute will be used.
- keyword (string) – attribute to consider
- limit (numeric) – Absolute limit of keyword attribute for the energy system.
Note
Flow objects required an attribute named like keyword!
Constraint:
With F_I being the set of flows considered for the integral limit and T being the set of time steps.
The symbols used are defined as follows (with Variables (V) and Parameters (P)):
math. symbol type explanation V power flow at time step
P weight given to Flow named according to keyword P width of time step P global limit given by keyword limit Examples
>>> import pandas as pd >>> from oemof import solph >>> date_time_index = pd.date_range('1/1/2012', periods=5, freq='H') >>> energysystem = solph.EnergySystem(timeindex=date_time_index) >>> bel = solph.Bus(label='electricityBus') >>> flow1 = solph.Flow(nominal_value=100, my_factor=0.8) >>> flow2 = solph.Flow(nominal_value=50) >>> src1 = solph.Source(label='source1', outputs={bel: flow1}) >>> src2 = solph.Source(label='source2', outputs={bel: flow2}) >>> energysystem.add(bel, src1, src2) >>> model = solph.Model(energysystem) >>> flow_with_keyword = {(src1, bel): flow1, } >>> model = solph.constraints.generic_integral_limit( ... model, "my_factor", flow_with_keyword, limit=777)
-
oemof.solph.constraints.
additional_investment_flow_limit
(model, keyword, limit=None)[source]¶ Global limit for investment flows weighted by an attribute keyword.
This constraint is only valid for Flows not for components such as an investment storage.
The attribute named by keyword has to be added to every Investment attribute of the flow you want to take into account. Total value of keyword attributes after optimization can be retrieved calling the
oemof.solph.Model.invest_limit_${keyword}()
.With IF being the set of InvestmentFlows considered for the integral limit.
The symbols used are defined as follows (with Variables (V) and Parameters (P)):
symbol attribute type explanation InvestmentFlow.invest[i, o] V installed capacity of investment flow keyword P weight given to investment flow named according to keyword limit P global limit given by keyword limit Parameters: - model (oemof.solph.Model) – Model to which constraints are added.
- keyword (attribute to consider) – All flows with Investment attribute containing the keyword will be used.
- limit (numeric) – Global limit of keyword attribute for the energy system.
Note
The Investment attribute of the considered (Investment-)flows requires an attribute named like keyword!
Examples
>>> import pandas as pd >>> from oemof import solph >>> date_time_index = pd.date_range('1/1/2020', periods=5, freq='H') >>> es = solph.EnergySystem(timeindex=date_time_index) >>> bus = solph.Bus(label='bus_1') >>> sink = solph.Sink(label="sink", inputs={bus: ... solph.Flow(nominal_value=10, fix=[10, 20, 30, 40, 50])}) >>> src1 = solph.Source(label='source_0', outputs={bus: solph.Flow( ... investment=solph.Investment(ep_costs=50, space=4))}) >>> src2 = solph.Source(label='source_1', outputs={bus: solph.Flow( ... investment=solph.Investment(ep_costs=100, space=1))}) >>> es.add(bus, sink, src1, src2) >>> model = solph.Model(es) >>> model = solph.constraints.additional_investment_flow_limit( ... model, "space", limit=1500) >>> a = model.solve(solver="cbc") >>> int(round(model.invest_limit_space())) 1500
-
oemof.solph.constraints.
investment_limit
(model, limit=None)[source]¶ Set an absolute limit for the total investment costs of an investment optimization problem:
Parameters: - model (oemof.solph.Model) – Model to which the constraint is added
- limit (float) – Absolute limit of the investment (i.e. RHS of constraint)
Adds a constraint to the given model that restricts the weighted sum of variables to a corridor.
The following constraints are build:
Parameters: - model (oemof.solph.Model) – Model to which the constraint is added.
- limit_name (string) – Name of the constraint to create
- quantity (pyomo.core.base.var.IndexedVar) – Shared Pyomo variable for all components of a type.
- components (list of components) – list of components of the same type
- weights (list of numeric values) – has to have the same length as the list of components
- lower_limit (numeric) – the lower limit
- upper_limit (numeric) – the lower limit
Examples
The constraint can e.g. be used to define a common storage that is shared between parties but that do not exchange energy on balance sheet. Thus, every party has their own bus and storage, respectively, to model the energy flow. However, as the physical storage is shared, it has a common limit.
>>> import pandas as pd >>> from oemof import solph >>> date_time_index = pd.date_range('1/1/2012', periods=5, freq='H') >>> energysystem = solph.EnergySystem(timeindex=date_time_index) >>> b1 = solph.Bus(label="Party1Bus") >>> b2 = solph.Bus(label="Party2Bus") >>> storage1 = solph.components.GenericStorage( ... label="Party1Storage", ... nominal_storage_capacity=5, ... inputs={b1: solph.Flow()}, ... outputs={b1: solph.Flow()}) >>> storage2 = solph.components.GenericStorage( ... label="Party2Storage", ... nominal_storage_capacity=5, ... inputs={b1: solph.Flow()}, ... outputs={b1: solph.Flow()}) >>> energysystem.add(b1, b2, storage1, storage2) >>> components = [storage1, storage2] >>> model = solph.Model(energysystem) >>> solph.constraints.shared_limit( ... model, ... model.GenericStorageBlock.storage_content, ... "limit_storage", components, ... [1, 1], upper_limit=5)
oemof.solph.console_scripts module¶
This module can be used to check the installation.
This is not an illustrated example.
oemof.solph.custom.ElectricalLine¶
In-development electrical line components.
-
class
oemof.solph.custom.electrical_line.
ElectricalBus
(*args, **kwargs)[source]¶ Bases:
oemof.solph.network.bus.Bus
A electrical bus object. Every node has to be connected to Bus. This Bus is used in combination with ElectricalLine objects for linear optimal power flow (lopf) calculations.
Parameters: - slack (boolean) – If True Bus is slack bus for network
- v_max (numeric) – Maximum value of voltage angle at electrical bus
- v_min (numeric) – Mininum value of voltag angle at electrical bus
- Note (This component is experimental. Use it with care.)
Notes
- The following sets, variables, constraints and objective parts are created
- The objects are also used inside:
-
class
oemof.solph.custom.electrical_line.
ElectricalLine
(*args, **kwargs)[source]¶ Bases:
oemof.solph.network.flow.Flow
An ElectricalLine to be used in linear optimal power flow calculations. based on angle formulation. Check out the Notes below before using this component!
Parameters: - reactance (float or array of floats) – Reactance of the line to be modelled
- Note (This component is experimental. Use it with care.)
Notes
- To use this object the connected buses need to be of the type
ElectricalBus
. - It does not work together with flows that have set the attr.`nonconvex`, i.e. unit commitment constraints are not possible
- Input and output of this component are set equal, therefore just use either only the input or the output to parameterize.
- Default attribute min of in/outflows is overwritten by -1 if not set differently by the user
- The following sets, variables, constraints and objective parts are created
-
class
oemof.solph.custom.electrical_line.
ElectricalLineBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for the linear relation of nodes with type class:.ElectricalLine
Note: This component is experimental. Use it with care.
The following constraints are created:
- Linear relation
om.ElectricalLine.electrical_flow[n,t]
TODO: Add equate constraint of flows
The following variable are created:
TODO: Add voltage angle variable
TODO: Add fix slack bus voltage angle to zero constraint / bound
TODO: Add tests
-
CONSTRAINT_GROUP
= True¶
- Linear relation
oemof.solph.custom.GenericCAES¶
In-development generic compressed air energy storage.
-
class
oemof.solph.custom.generic_caes.
GenericCAES
(*args, **kwargs)[source]¶ Bases:
oemof.network.network.Transformer
Component GenericCAES to model arbitrary compressed air energy storages.
The full set of equations is described in: Kaldemeyer, C.; Boysen, C.; Tuschy, I. A Generic Formulation of Compressed Air Energy Storage as Mixed Integer Linear Program – Unit Commitment of Specific Technical Concepts in Arbitrary Market Environments Materials Today: Proceedings 00 (2018) 0000–0000 [currently in review]
Parameters: - electrical_input (dict) – Dictionary with key-value-pair of oemof.Bus and oemof.Flow object for the electrical input.
- fuel_input (dict) – Dictionary with key-value-pair of oemof.Bus and oemof.Flow object for the fuel input.
- electrical_output (dict) – Dictionary with key-value-pair of oemof.Bus and oemof.Flow object for the electrical output.
- Note (This component is experimental. Use it with care.)
Notes
- The following sets, variables, constraints and objective parts are created
GenericCAES
TODO: Add description for constraints. See referenced paper until then!
Examples
>>> from oemof import solph >>> bel = solph.Bus(label='bel') >>> bth = solph.Bus(label='bth') >>> bgas = solph.Bus(label='bgas') >>> # dictionary with parameters for a specific CAES plant >>> concept = { ... 'cav_e_in_b': 0, ... 'cav_e_in_m': 0.6457267578, ... 'cav_e_out_b': 0, ... 'cav_e_out_m': 0.3739636077, ... 'cav_eta_temp': 1.0, ... 'cav_level_max': 211.11, ... 'cmp_p_max_b': 86.0918959849, ... 'cmp_p_max_m': 0.0679999932, ... 'cmp_p_min': 1, ... 'cmp_q_out_b': -19.3996965679, ... 'cmp_q_out_m': 1.1066036114, ... 'cmp_q_tes_share': 0, ... 'exp_p_max_b': 46.1294016678, ... 'exp_p_max_m': 0.2528340303, ... 'exp_p_min': 1, ... 'exp_q_in_b': -2.2073411014, ... 'exp_q_in_m': 1.129249765, ... 'exp_q_tes_share': 0, ... 'tes_eta_temp': 1.0, ... 'tes_level_max': 0.0} >>> # generic compressed air energy storage (caes) plant >>> caes = solph.custom.GenericCAES( ... label='caes', ... electrical_input={bel: solph.Flow()}, ... fuel_input={bgas: solph.Flow()}, ... electrical_output={bel: solph.Flow()}, ... params=concept, fixed_costs=0) >>> type(caes) <class 'oemof.solph.custom.generic_caes.GenericCAES'>
-
class
oemof.solph.custom.generic_caes.
GenericCAESBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for nodes of class:.GenericCAES.
Note: This component is experimental. Use it with care.
The following constraints are created:
Table: Symbols and attribute names of variables and parameters
Variables (V) and Parameters (P)¶ symbol attribute type explanation cmp_st[n,t] V Status of compression cmp_p[n,t] V Compression power cmp_p_max[n,t] V Max. compression power cmp_q_out_sum[n,t] V - Summed
- heat flow in compression
cmp_q_waste[n,t] V Waste heat flow from compression exp_st[n,t] V Status of expansion (binary) exp_p[n,t] V Expansion power exp_p_max[n,t] V Max. expansion power exp_q_in_sum[n,t] V Summed heat flow in expansion exp_q_fuel_in[n,t] V Heat (external) flow into expansion exp_q_add_in[n,t] V Additional heat flow into expansion cav_level[n,t] V - Filling level
- if CAE
cav_e_in[n,t] V Exergy flow into CAS cav_e_out[n,t] V Exergy flow from CAS tes_level[n,t] V Filling level of Thermal Energy Storage (TES) tes_e_in[n,t] V - Heat
- flow into TES
tes_e_out[n,t] V - Heat
- flow from TES
cmp_p_max_b[n,t] P - Specific
- y-intersection
cmp_q_out_b[n,t] P Specific y-intersection exp_p_max_b[n,t] P Specific y-intersection exp_q_in_b[n,t] P Specific y-intersection cav_e_in_b[n,t] P Specific y-intersection cav_e_out_b[n,t] P Specific y-intersection cmp_p_max_m[n,t] P - Specific
- slope
cmp_q_out_m[n,t] P - Specific
- slope
exp_p_max_m[n,t] P - Specific
- slope
exp_q_in_m[n,t] P - Specific
- slope
cav_e_in_m[n,t] P - Specific
- slope
cav_e_out_m[n,t] P - Specific
- slope
cmp_p_min[n,t] P Min. compression power cmp_q_tes_share[n,t] P - Ratio
- between waste heat flow and heat flow into TES
exp_q_tes_share[n,t] P - Ratio
- between external heat flow into expansion and heat flows from TES and
- additional source
m.timeincrement[n,t] P - Time interval
- length
tes_level_max[n,t] P Max. filling level of TES cav_level_max[n,t] P - Max.
- filling level of TES
cav_eta_tmp[n,t] P - Temporal efficiency
- (loss factor to take intertemporal losses into account)
flow[list(n.electrical_input.keys())[0], n, t] P Electr. power input into compression flow[n, list(n.electrical_output.keys())[0], t] P Electr. power output of expansion flow[list(n.fuel_input.keys())[0], n, t] P - Heat input
- (external) into Expansion
-
CONSTRAINT_GROUP
= True¶
oemof.solph.custom.Link¶
In-development component to add some intelligence to connection between two Nodes.
-
class
oemof.solph.custom.link.
Link
(*args, **kwargs)[source]¶ Bases:
oemof.network.network.Transformer
A Link object with 1…2 inputs and 1…2 outputs.
Parameters: - conversion_factors (dict) – Dictionary containing conversion factors for conversion of each flow. Keys are the connected tuples (input, output) bus objects. The dictionary values can either be a scalar or an iterable with length of time horizon for simulation.
- Note (This component is experimental. Use it with care.)
Notes
- The sets, variables, constraints and objective parts are created
Examples
>>> from oemof import solph >>> bel0 = solph.Bus(label="el0") >>> bel1 = solph.Bus(label="el1")
>>> link = solph.custom.Link( ... label="transshipment_link", ... inputs={bel0: solph.Flow(), bel1: solph.Flow()}, ... outputs={bel0: solph.Flow(), bel1: solph.Flow()}, ... conversion_factors={(bel0, bel1): 0.92, (bel1, bel0): 0.99}) >>> print(sorted([x[1][5] for x in link.conversion_factors.items()])) [0.92, 0.99]
>>> type(link) <class 'oemof.solph.custom.link.Link'>
>>> sorted([str(i) for i in link.inputs]) ['el0', 'el1']
>>> link.conversion_factors[(bel0, bel1)][3] 0.92
-
class
oemof.solph.custom.link.
LinkBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for the relation of nodes with type
Link
Note: This component is experimental. Use it with care.
The following constraints are created:
TODO: Add description for constraints TODO: Add tests
-
CONSTRAINT_GROUP
= True¶
-
oemof.solph.custom.PiecewiseLinearTransformer¶
In-development transfomer with piecewise linar efficiencies.
-
class
oemof.solph.custom.piecewise_linear_transformer.
PiecewiseLinearTransformer
(*args, **kwargs)[source]¶ Bases:
oemof.network.network.Transformer
Component to model a transformer with one input and one output and an arbitrary piecewise linear conversion function.
Parameters: - in_breakpoints (list) – List containing the domain breakpoints, i.e. the breakpoints for the incoming flow.
- conversion_function (func) – The function describing the relation between incoming flow and outgoing flow which is to be approximated.
- pw_repn (string) – Choice of piecewise representation that is passed to pyomo.environ.Piecewise
Examples
>>> import oemof.solph as solph
>>> b_gas = solph.Bus(label='biogas') >>> b_el = solph.Bus(label='electricity')
>>> pwltf = solph.custom.PiecewiseLinearTransformer( ... label='pwltf', ... inputs={b_gas: solph.Flow( ... nominal_value=100, ... variable_costs=1)}, ... outputs={b_el: solph.Flow()}, ... in_breakpoints=[0,25,50,75,100], ... conversion_function=lambda x: x**2, ... pw_repn='CC')
>>> type(pwltf) <class 'oemof.solph.custom.piecewise_linear_transformer.PiecewiseLinearTransformer'>
-
class
oemof.solph.custom.piecewise_linear_transformer.
PiecewiseLinearTransformerBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for the relation of nodes with type
PiecewiseLinearTransformer
The following constraints are created:
-
CONSTRAINT_GROUP
= True¶
-
oemof.solph.custom.SinkDSM¶
In-development functionality for demand-side management.
-
class
oemof.solph.custom.sink_dsm.
SinkDSM
(demand, capacity_up, capacity_down, approach, shift_interval=None, delay_time=None, shift_time=None, shed_time=None, max_demand=None, max_capacity_down=None, max_capacity_up=None, flex_share_down=None, flex_share_up=None, cost_dsm_up=0, cost_dsm_down_shift=0, cost_dsm_down_shed=0, efficiency=1, recovery_time_shift=None, recovery_time_shed=None, ActivateYearLimit=False, ActivateDayLimit=False, n_yearLimit_shift=None, n_yearLimit_shed=None, t_dayLimit=None, addition=True, fixes=True, shed_eligibility=True, shift_eligibility=True, **kwargs)[source]¶ Bases:
oemof.solph.network.sink.Sink
Demand Side Management implemented as Sink with flexibility potential.
There are several approaches possible which can be selected: - DIW: Based on the paper by Zerrahn, Alexander and Schill, Wolf-Peter (2015): On the representation of demand-side management in power system models, in: Energy (84), pp. 840-845, 10.1016/j.energy.2015.03.037, accessed 08.01.2021, pp. 842-843. - DLR: Based on the PhD thesis of Gils, Hans Christian (2015): Balancing of Intermittent Renewable Power Generation by Demand Response and Thermal Energy Storage, Stuttgart, <http://dx.doi.org/10.18419/opus-6888>, accessed 08.01.2021, pp. 67-70. - oemof: Created by Julian Endres. A fairly simple DSM representation which demands the energy balance to be levelled out in fixed cycles
An evaluation of different modeling approaches has been carried out and presented at the INREC 2020. Some of the results are as follows: - DIW: A solid implementation with the tendency of slight overestimization of potentials since a shift_time is not accounted for. It may get computationally expensive due to a high time-interlinkage in constraint formulations. - DLR: An extensive modeling approach for demand response which neither leads to an over- nor underestimization of potentials and balances modeling detail and computation intensity.
fixes
andaddition
should both be set to True which is the default value. - oemof: A very computationally efficient approach which only requires the energy balance to be levelled out in certain intervals. If demand response is not at the center of the research and/or parameter availability is limited, this approach should be chosen. Note that approach oemof does allow for load shedding, but does not impose a limit on maximum amount of shedded energy.SinkDSM adds additional constraints that allow to shift energy in certain time window constrained by
capacity_up
andcapacity_down
.Parameters: demand (numeric) – original electrical demand (normalized) For investment modeling, it is advised to use the maximum of the demand timeseries and the cumulated (fixed) infeed time series for normalization, because the balancing potential may be determined by both. Elsewhise, underinvestments may occur.
capacity_up (int or array) – maximum DSM capacity that may be increased (normalized)
capacity_down (int or array) – maximum DSM capacity that may be reduced (normalized)
approach (‘oemof’, ‘DIW’, ‘DLR’) – Choose one of the DSM modeling approaches. Read notes about which parameters to be applied for which approach.
oemof :
Simple model in which the load shift must be compensated in a predefined fixed interval (
shift_interval
is mandatory). Within time windows of the lengthshift_interval
DSM up and down shifts are balanced. SeeSinkDSMOemofBlock
for details.DIW :
Sophisticated model based on the formulation by Zerrahn & Schill (2015a). The load shift of the component must be compensated in a predefined delay time (
delay_time
is mandatory). For details seeSinkDSMDIWBlock
.DLR :
Sophisticated model based on the formulation by Gils (2015). The load shift of the component must be compensated in a predefined delay time (
delay_time
is mandatory). For details seeSinkDSMDLRBlock
.shift_interval (int) – Only used when
approach
is set to ‘oemof’. Otherwise, can be None. It’s the interval in which betweenand
have to be compensated.
delay_time (int) – Only used when
approach
is set to ‘DIW’ or ‘DLR’. Otherwise, can be None. Length of symmetrical time windows aroundin which
and
have to be compensated. Note: For approach ‘DLR’, an iterable is constructed in order to model flexible delay times
shift_time (int) – Only used when
approach
is set to ‘DLR’. Duration of a single upwards or downwards shift (half a shifting cycle if there is immediate compensation)shed_time (int) – Only used when
shed_eligibility
is set to True. Maximum length of a load shedding process at full capacity (used within energy limit constraint)max_demand (numeric) – Maximum demand prior to demand response
max_capacity_down (numeric) – Maximum capacity eligible for downshifts prior to demand response (used for dispatch mode)
max_capacity_up (numeric) – Maximum capacity eligible for upshifts prior to demand response (used for dispatch mode)
flex_share_down (float) – Flexible share of installed capacity eligible for downshifts (used for invest mode)
flex_share_up (float) – Flexible share of installed capacity eligible for upshifts (used for invest mode)
cost_dsm_up (int) – Cost per unit of DSM activity that increases the demand
cost_dsm_down_shift (int) – Cost per unit of DSM activity that decreases the demand for load shifting
cost_dsm_down_shed (int) – Cost per unit of DSM activity that decreases the demand for load shedding
efficiency (float) – Efficiency factor for load shifts (between 0 and 1)
recovery_time_shift (int) – Only used when
approach
is set to ‘DIW’. Minimum time between the end of one load shifting process and the start of another for load shifting processesrecovery_time_shed (int) – Only used when
approach
is set to ‘DIW’. Minimum time between the end of one load shifting process and the start of another for load shedding processesActivateYearLimit (boolean) – Only used when
approach
is set to ‘DLR’. Control parameter; activates constraints for year limit if set to TrueActivateDayLimit (boolean) – Only used when
approach
is set to ‘DLR’. Control parameter; activates constraints for day limit if set to Truen_yearLimit_shift (int) – Only used when
approach
is set to ‘DLR’. Maximum number of load shifts at full capacity per year, used to limit the amount of energy shifted per year. Optional parameter that is only needed when ActivateYearLimit is Truen_yearLimit_shed (int) – Only used when
approach
is set to ‘DLR’. Maximum number of load sheds at full capacity per year, used to limit the amount of energy shedded per year. Mandatory parameter if load shedding is allowed by setting shed_eligibility to Truet_dayLimit (int) – Only used when
approach
is set to ‘DLR’. Maximum duration of load shifts at full capacity per day, used to limit the amount of energy shifted per day. Optional parameter that is only needed when ActivateDayLimit is Trueaddition (boolean) – Only used when
approach
is set to ‘DLR’. Boolean parameter indicating whether or not to include additional constraint (which corresponds to Eq. 10 from Zerrahn and Schill (2015a)fixes (boolean) – Only used when
approach
is set to ‘DLR’. Boolean parameter indicating whether or not to include additional fixes. These comprise prohibiting shifts which cannot be balanced within the optimization timeframeshed_eligibility (boolean) – Boolean parameter indicating whether unit is eligible for load shedding
shift_eligibility (boolean) – Boolean parameter indicating whether unit is eligible for load shifting
Note
method
has been renamed toapproach
.- As many constraints and dependencies are created in approach ‘DIW’, computational cost might be high with a large ‘delay_time’ and with model of high temporal resolution
- The approach ‘DLR’ preforms better in terms of calculation time, compared to the approach ‘DIW’
- Using
approach
‘DIW’ or ‘DLR’ might result in demand shifts that exceed the specified delay time by activating up and down simultaneously in the time steps between to DSM events. Thus, the purpose of this component is to model demand response portfolios rather than individual demand units. - It’s not recommended to assign cost to the flow that connects
SinkDSM
with a bus. Instead, usecost_dsm_up
orcost_dsm_down_shift
- Variable costs may be attributed to upshifts, downshifts or both. Costs for shedding may deviate from that for shifting (usually costs for shedding are much larger and equal to the value of lost load).
-
class
oemof.solph.custom.sink_dsm.
SinkDSMDIWBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Constraints for SinkDSM with “DIW” approach
The following constraints are created for approach = ‘DIW’:
Note: For the sake of readability, the handling of indices is not displayed here. E.g. evaluating a variable for t-L may lead to a negative and therefore infeasible index. This is addressed by limiting the sums to non-negative indices within the model index bounds. Please refer to the constraints implementation themselves.
The following parts of the objective function are created:
Table: Symbols and attribute names of variables and parameters
Variables (V) and Parameters (P)¶ symbol attribute type explanation dsm_up[g,t]
V DSM up shift (additional load) in hour t dsm_do_shift[g,t,tt]
V DSM down shift (less load) in hour tt to compensate for upwards shifts in hour t dsm_do_shed[g,t]
V DSM shedded (capacity shedded, i.e. not compensated for) flow[g,t]
V Energy flowing in from (electrical) inflow bus delay_time
P Maximum delay time for load shift (time until the energy balance has to be levelled out again; roundtrip time of one load shifting cycle, i.e. time window for upshift and compensating downshift) shed_time
P Maximum time for one load shedding process demand[t]
P (Electrical) demand series (normalized) max_demand
P Maximum demand value capacity_down[t]
P Capacity allowed for a load adjustment downwards (normalized) (DSM down shift + DSM shedded) capacity_up[t]
P Capacity allowed for a shift upwards (normalized) (DSM up shift) max_capacity_down
P Maximum capacity allowed for a load adjustment downwards (DSM down shift + DSM shedded) max_capacity_up
P Capacity allowed for a shift upwards (normalized) (DSM up shift) efficiency
P Efficiency loss for load shifting processes P Time steps shift_eligibility
P Boolean parameter indicating if unit can be used for load shifting shed_eligibility
P Boolean parameter indicating if unit can be used for load shedding cost_dsm_up[t]
P Variable costs for an upwards shift cost_dsm_down_shift[t]
P Variable costs for a downwards shift (load shifting) cost_dsm_down_shed[t]
P Variable costs for shedding load recovery_time_shift
P Minimum time between the end of one load shifting process and the start of another timeincrement
P The time increment of the model -
CONSTRAINT_GROUP
= True¶
-
-
class
oemof.solph.custom.sink_dsm.
SinkDSMDIWInvestmentBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Constraints for SinkDSM with “DIW” approach and
investment
The following constraints are created for approach = ‘DIW’ with an investment object defined:
Note: For the sake of readability, the handling of indices is not displayed here. E.g. evaluating a variable for t-L may lead to a negative and therefore infeasible index. This is addressed by limiting the sums to non-negative indices within the model index bounds. Please refer to the constraints implementation themselves.
The following parts of the objective function are created:
- Investment annuity:
- Variable costs:
Table: Symbols and attribute names of variables and parameters
Please refer to
oemof.solph.custom.SinkDSMDIWBlock
.The following variables and parameters are exclusively used for investment modeling:
Variables (V) and Parameters (P)¶ symbol attribute type explanation invest
V DSM capacity invested in. Equals to the additionally installed capacity. The capacity share eligible for a shift is determined by flex share(s). minimum
P minimum investment maximum
P maximum investment existing
P existing DSM capacity flex_share_up
P Share of invested capacity that may be shift upwards at maximum flex_share_do
P Share of invested capacity that may be shift downwards at maximum ep_costs
P specific investment annuity P Overall amount of time steps (cardinality) -
CONSTRAINT_GROUP
= True¶
-
class
oemof.solph.custom.sink_dsm.
SinkDSMDLRBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Constraints for SinkDSM with “DLR” approach
The following constraints are created for approach = ‘DLR’:
Note: For the sake of readability, the handling of indices is not displayed here. E.g. evaluating a variable for t-L may lead to a negative and therefore infeasible index. This is addressed by limiting the sums to non-negative indices within the model index bounds. Please refer to the constraints implementation themselves.
The following parts of the objective function are created:
Table: Symbols and attribute names of variables and parameters
Variables (V) and Parameters (P)¶ symbol attribute type explanation dsm_up[g,h,t]
V DSM up shift (additional load) in hour t with delay time h dsm_do_shift[g,h, t]
V DSM down shift (less load) in hour t with delay time h balance_dsm_up[g,h,t]
V DSM down shift (less load) in hour t with delay time h to balance previous upshift balance_dsm_do[g,h,t]
V DSM up shift (additional load) in hour t with delay time h to balance previous downshift dsm_do_shed[g, t]
V DSM shedded (capacity shedded, i.e. not compensated for) flow[g,t]
V Energy flowing in from (electrical) inflow bus element of delay_time
P delay time for load shift (integer value from set of feasible delay times per DSM portfolio) (time until the energy balance has to be levelled out again; roundtrip time of one load shifting cycle, i.e. time window for upshift and compensating downshift) range(length(:attr:`~SinkDSM.delay_time) + 1)` P Set of feasible delay times for load shift of a certain DSM portfolio (time until the energy balance has to be levelled out again; roundtrip time of one load shifting cycle, i.e. time window for upshift and compensating downshift) shift_time
P Maximum time for a shift in one direction, i. e. maximum time for an upshift or a downshift in a load shifting cycle shed_time
P Maximum time for one load shedding process demand[t]
P (Electrical) demand series (normalized) max_demand
P Maximum demand value capacity_down[t]
P Capacity allowed for a load adjustment downwards (normalized) (DSM down shift + DSM shedded) capacity_up[t]
P Capacity allowed for a shift upwards (normalized) (DSM up shift) max_capacity_down
P Maximum capacity allowed for a load adjustment downwards (DSM down shift + DSM shedded) max_capacity_up
P Capacity allowed for a shift upwards (normalized) (DSM up shift) efficiency
P Efficiency loss for load shifting processes P Set of time steps P Overall amount of time steps (cardinality) shift_eligibility
P Boolean parameter indicating if unit can be used for load shifting shed_eligibility
P Boolean parameter indicating if unit can be used for load shedding cost_dsm_up[t]
P Variable costs for an upwards shift cost_dsm_down_shift[t]
P Variable costs for a downwards shift (load shifting) cost_dsm_down_shed[t]
P Variable costs for shedding load timeincrement
P The time increment of the model n_yearLimitShift
P Maximum allowed number of load shifts (at full capacity) in the optimization timeframe n_yearLimitShed
P Maximum allowed number of load sheds (at full capacity) in the optimization timeframe t_dayLimit
P Maximum duration of load shifts at full capacity per day resp. in the last hours before the current -
CONSTRAINT_GROUP
= True¶
-
-
class
oemof.solph.custom.sink_dsm.
SinkDSMDLRInvestmentBlock
(*args, **kwargs)[source]¶ Bases:
oemof.solph.custom.sink_dsm.SinkDSMDLRBlock
Constraints for SinkDSM with “DLR” approach and
investment
The following constraints are created for approach = ‘DLR’ with an investment object defined:
Note: For the sake of readability, the handling of indices is not displayed here. E.g. evaluating a variable for t-L may lead to a negative and therefore infeasible index. This is addressed by limiting the sums to non-negative indices within the model index bounds. Please refer to the constraints implementation themselves.
The following parts of the objective function are created:
- Investment annuity:
- Variable costs:
Table: Symbols and attribute names of variables and parameters
Please refer to
oemof.solph.custom.SinkDSMDLRBlock
.The following variables and parameters are exclusively used for investment modeling:
Variables (V) and Parameters (P)¶ symbol attribute type explanation invest
V DSM capacity invested in. Equals to the additionally installed capacity. The capacity share eligible for a shift is determined by flex share(s). minimum
P minimum investment maximum
P maximum investment existing
P existing DSM capacity flex_share_up
P Share of invested capacity that may be shift upwards at maximum flex_share_do
P Share of invested capacity that may be shift downwards at maximum ep_costs
P specific investment annuity -
CONSTRAINT_GROUP
= True¶
-
class
oemof.solph.custom.sink_dsm.
SinkDSMOemofBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Constraints for SinkDSM with “oemof” approach
The following constraints are created for approach = ‘oemof’:
The following parts of the objective function are created:
Table: Symbols and attribute names of variables and parameters
Variables (V) and Parameters (P)¶ symbol attribute type explanation dsm_up[g, t]
V DSM up shift (capacity shifted upwards) dsm_do_shift[g, t]
V DSM down shift (capacity shifted downwards) dsm_do_shed[g, t]
V DSM shedded (capacity shedded, i.e. not compensated for) inputs
V Energy flowing in from (electrical) inflow bus demand[t]
P (Electrical) demand series (normalized) max_demand
P Maximum demand value capacity_down[t]
P Capacity allowed for a load adjustment downwards (normalized) (DSM down shift + DSM shedded) capacity_up[t]
P Capacity allowed for a shift upwards (normalized) (DSM up shift) max_capacity_down
P Maximum capacity allowed for a load adjustment downwards (DSM down shift + DSM shedded) max_capacity_up
P Capacity allowed for a shift upwards (normalized) (DSM up shift) shift_interval
P Shift interval (time within which the energy balance must be levelled out efficiency
P Efficiency loss forload shifting processes P Time steps shift_eligibility
P Boolean parameter indicating if unit can be used for load shifting shed_eligibility
P Boolean parameter indicating if unit can be used for load shedding cost_dsm_up[t]
P Variable costs for an upwards shift cost_dsm_down_shift[t]
P Variable costs for a downwards shift (load shifting) cost_dsm_down_shed[t]
P Variable costs for shedding load -
CONSTRAINT_GROUP
= True¶
-
-
class
oemof.solph.custom.sink_dsm.
SinkDSMOemofInvestmentBlock
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Constraints for SinkDSM with “oemof” approach and
investment
The following constraints are created for approach = ‘oemof’ with an investment object defined:
The following parts of the objective function are created:
- Investment annuity:
- Variable costs:
See remarks in
oemof.solph.custom.SinkDSMOemofBlock
.Symbols and attribute names of variables and parameters
Please refer to
oemof.solph.custom.SinkDSMOemofBlock
.The following variables and parameters are exclusively used for investment modeling:
Variables (V) and Parameters (P)¶ symbol attribute type explanation invest
V DSM capacity invested in. Equals to the additionally installed capacity. The capacity share eligible for a shift is determined by flex share(s). minimum
P minimum investment maximum
P maximum investment existing
P existing DSM capacity flex_share_up
P Share of invested capacity that may be shift upwards at maximum flex_share_do
P Share of invested capacity that may be shift downwards at maximum epcosts
P specific investment annuity -
CONSTRAINT_GROUP
= True¶
oemof.solph.groupings module¶
Groupings needed on an energy system for it to work with solph.
If you want to use solph on an energy system, you need to create it with these groupings specified like this:
from oemof.network import EnergySystem import solph
energy_system = EnergySystem(groupings=solph.GROUPINGS)
-
oemof.solph.groupings.
constraint_grouping
(node, fallback=<function <lambda>>)[source]¶ Grouping function for constraints.
This function can be passed in a list to
groupings
ofoemof.solph.network.EnergySystem
.Parameters: - node (
Node <oemof.network.Node
) – The node for which the figure out a constraint group. - fallback (callable, optional) – A function of one argument. If node doesn’t have a constraint_group attribute, this is used to group the node instead. Defaults to not group the node at all.
- node (
oemof.solph.helpers module¶
This is a collection of helper functions which work on their own and can be used by various classes. If there are too many helper-functions, they will be sorted in different modules.
-
oemof.solph.helpers.
calculate_timeincrement
(timeindex, fill_value=None)[source]¶ Calculates timeincrement for timeindex
Parameters: - timeindex (pd.DatetimeIndex) – timeindex of energysystem
- fill_value (numerical) – timeincrement for first timestep in hours
-
oemof.solph.helpers.
extend_basic_path
(subfolder)[source]¶ Returns a path based on the basic oemof path and creates it if necessary. The subfolder is the name of the path extension.
-
oemof.solph.helpers.
flatten
(d, parent_key='', sep='_')[source]¶ Flatten dictionary by compressing keys.
- See: https://stackoverflow.com/questions/6027558/
- flatten-nested-python-dictionaries-compressing-keys
d : dictionary sep : separator for flattening keys
Returns: dict
oemof.solph.models module¶
Solph Optimization Models.
-
class
oemof.solph.models.
BaseModel
(energysystem, **kwargs)[source]¶ Bases:
pyomo.core.base.PyomoModel.ConcreteModel
The BaseModel for other solph-models (Model, MultiPeriodModel, etc.)
Parameters: - energysystem (EnergySystem object) – Object that holds the nodes of an oemof energy system graph
- constraint_groups (list (optional)) – Solph looks for these groups in the given energy system and uses them to create the constraints of the optimization problem. Defaults to Model.CONSTRAINTS
- objective_weighting (array like (optional)) – Weights used for temporal objective function expressions. If nothing is passed timeincrement will be used which is calculated from the freq length of the energy system timeindex .
- auto_construct (boolean) – If this value is true, the set, variables, constraints, etc. are added, automatically when instantiating the model. For sequential model building process set this value to False and use methods _add_parent_block_sets, _add_parent_block_variables, _add_blocks, _add_objective
- Attributes
- ———–
- timeincrement (sequence) – Time increments.
- flows (dict) – Flows of the model.
- name (str) – Name of the model.
- es (solph.EnergySystem) – Energy system of the model.
- meta (pyomo.opt.results.results_.SolverResults or None) – Solver results.
- dual (… or None)
- rc (… or None)
-
CONSTRAINT_GROUPS
= []¶
-
receive_duals
()[source]¶ Method sets solver suffix to extract information about dual variables from solver. Shadow prices (duals) and reduced costs (rc) are set as attributes of the model.
-
solve
(solver='cbc', solver_io='lp', **kwargs)[source]¶ Takes care of communication with solver to solve the model.
Parameters: - solver (string) – solver to be used e.g. “glpk”,”gurobi”,”cplex”
- solver_io (string) – pyomo solver interface file format: “lp”,”python”,”nl”, etc.
- **kwargs (keyword arguments) – Possible keys can be set see below:
Other Parameters: - solve_kwargs (dict) – Other arguments for the pyomo.opt.SolverFactory.solve() method Example : {“tee”:True}
- cmdline_options (dict) – Dictionary with command line options for solver e.g. {“mipgap”:”0.01”} results in “–mipgap 0.01” {“interior”:” “} results in “–interior” Gurobi solver takes numeric parameter values such as {“method”: 2}
-
class
oemof.solph.models.
Model
(energysystem, **kwargs)[source]¶ Bases:
oemof.solph.models.BaseModel
An energy system model for operational and investment optimization.
Parameters: - energysystem (EnergySystem object) – Object that holds the nodes of an oemof energy system graph
- constraint_groups (list) – Solph looks for these groups in the given energy system and uses them to create the constraints of the optimization problem. Defaults to Model.CONSTRAINTS
- **The following basic sets are created**
- NODES – A set with all nodes of the given energy system.
- TIMESTEPS – A set with all timesteps of the given time horizon.
- FLOWS – A 2 dimensional set with all flows. Index: (source, target)
- **The following basic variables are created**
- flow – Flow from source to target indexed by FLOWS, TIMESTEPS. Note: Bounds of this variable are set depending on attributes of the corresponding flow object.
-
CONSTRAINT_GROUPS
= [<class 'oemof.solph.blocks.bus.Bus'>, <class 'oemof.solph.blocks.transformer.Transformer'>, <class 'oemof.solph.blocks.investment_flow.InvestmentFlow'>, <class 'oemof.solph.blocks.flow.Flow'>, <class 'oemof.solph.blocks.non_convex_flow.NonConvexFlow'>]¶
oemof.solph.network module¶
Classes used to model energy supply systems within solph.
Classes are derived from oemof core network classes and adapted for specific optimization tasks. An energy system is modelled as a graph/network of nodes with very specific constraints on which types of nodes are allowed to be connected.
oemof.solph.options module¶
Optional classes to be added to a network class.
-
class
oemof.solph.options.
Investment
(maximum=inf, minimum=0, ep_costs=0, existing=0, nonconvex=False, offset=0, **kwargs)[source]¶ Bases:
object
Parameters: - maximum (float,
or
) – Maximum of the additional invested capacity
- minimum (float,
or
) – Minimum of the additional invested capacity. If nonconvex is True, minimum defines the threshold for the invested capacity.
- ep_costs (float,
) – Equivalent periodical costs for the investment per flow capacity.
- existing (float,
or
) – Existing / installed capacity. The invested capacity is added on top of this value. Not applicable if nonconvex is set to True.
- nonconvex (bool) – If True, a binary variable for the status of the investment is created. This enables additional fix investment costs (offset) independent of the invested flow capacity. Therefore, use the offset parameter.
- offset (float,
) – Additional fix investment costs. Only applicable if nonconvex is set to True.
For the variables, constraints and parts of the objective function, which are created, see
oemof.solph.blocks.investment_flow.InvestmentFlow
andoemof.solph.components.generic_storage.GenericInvestmentStorageBlock
.- maximum (float,
-
class
oemof.solph.options.
NonConvex
(**kwargs)[source]¶ Bases:
object
Parameters: startup_costs (numeric (iterable or scalar)) – Costs associated with a start of the flow (representing a unit).
shutdown_costs (numeric (iterable or scalar)) – Costs associated with the shutdown of the flow (representing a unit).
activity_costs (numeric (iterable or scalar)) – Costs associated with the active operation of the flow, independently from the actual output.
minimum_uptime (numeric (1 or positive integer)) – Minimum time that a flow must be greater then its minimum flow after startup. Be aware that minimum up and downtimes can contradict each other and may lead to infeasible problems.
minimum_downtime (numeric (1 or positive integer)) – Minimum time a flow is forced to zero after shutting down. Be aware that minimum up and downtimes can contradict each other and may to infeasible problems.
maximum_startups (numeric (0 or positive integer)) – Maximum number of start-ups.
maximum_shutdowns (numeric (0 or positive integer)) – Maximum number of shutdowns.
initial_status (numeric (0 or 1)) – Integer value indicating the status of the flow in the first time step (0 = off, 1 = on). For minimum up and downtimes, the initial status is set for the respective values in the edge regions e.g. if a minimum uptime of four timesteps is defined, the initial status is fixed for the four first and last timesteps of the optimization period. If both, up and downtimes are defined, the initial status is set for the maximum of both e.g. for six timesteps if a minimum downtime of six timesteps is defined in addition to a four timestep minimum uptime.
positive_gradient (
dict
, default: {‘ub’: None, ‘costs’: 0}) –A dictionary containing the following two keys:
- ‘ub’: numeric (iterable, scalar or None), the normed upper bound on the positive difference (flow[t-1] < flow[t]) of two consecutive flow values.
- ‘costs`: numeric (scalar or None), the gradient cost per unit.
negative_gradient (
dict
, default: {‘ub’: None, ‘costs’: 0}) –A dictionary containing the following two keys:
- ‘ub’: numeric (iterable, scalar or None), the normed upper bound on the negative difference (flow[t-1] > flow[t]) of two consecutive flow values.
- ‘costs`: numeric (scalar or None), the gradient cost per unit.
-
max_up_down
¶ Compute or return the _max_up_down attribute.
oemof.solph.plumbing module¶
Plumbing stuff.
-
oemof.solph.plumbing.
sequence
(iterable_or_scalar)[source]¶ Tests if an object is iterable (except string) or scalar and returns a the original sequence if object is an iterable and a ‘emulated’ sequence object of class _Sequence if object is a scalar or string.
Parameters: iterable_or_scalar (iterable or None or int or float) Examples
>>> sequence([1,2]) [1, 2]
>>> x = sequence(10) >>> x[0] 10
>>> x[10] 10 >>> print(x) [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
oemof.solph.processing module¶
Modules for providing a convenient data structure for solph results.
Information about the possible usage is provided within the examples.
-
oemof.solph.processing.
convert_keys_to_strings
(result, keep_none_type=False)[source]¶ Convert the dictionary keys to strings.
All (tuple) keys of the result object e.g. results[(pp1, bus1)] are converted into strings that represent the object labels e.g. results[(‘pp1’,’bus1’)].
-
oemof.solph.processing.
create_dataframe
(om)[source]¶ Create a result dataframe with all optimization data.
Results from Pyomo are written into pandas DataFrame where separate columns are created for the variable index e.g. for tuples of the flows and components or the timesteps.
-
oemof.solph.processing.
get_timestep
(x)[source]¶ Get the timestep from oemof tuples.
The timestep from tuples (n, n, int), (n, n), (n, int) and (n,) is fetched as the last element. For time-independent data (scalars) zero ist returned.
-
oemof.solph.processing.
get_tuple
(x)[source]¶ Get oemof tuple within iterable or create it.
Tuples from Pyomo are of type (n, n, int), (n, n) and (n, int). For single nodes n a tuple with one object (n,) is created.
-
oemof.solph.processing.
meta_results
(om, undefined=False)[source]¶ Fetch some meta data from the Solver. Feel free to add more keys.
Valid keys of the resulting dictionary are: ‘objective’, ‘problem’, ‘solver’.
- om : oemof.solph.Model
- A solved Model.
- undefined : bool
- By default (False) only defined keys can be found in the dictionary. Set to True to get also the undefined keys.
Returns: dict
-
oemof.solph.processing.
parameter_as_dict
(system, exclude_none=True)[source]¶ Create a result dictionary containing node parameters.
Results are written into a dictionary of pandas objects where a Series holds all scalar values and a dataframe all sequences for nodes and flows. The dictionary is keyed by flows (n, n) and nodes (n, None), e.g. parameter[(n, n)][‘sequences’] or parameter[(n, n)][‘scalars’].
Parameters: - system (energy_system.EnergySystem) – A populated energy system.
- exclude_none (bool) – If True, all scalars and sequences containing None values are excluded
Returns: dict (Parameters for all nodes and flows)
-
oemof.solph.processing.
remove_timestep
(x)[source]¶ Remove the timestep from oemof tuples.
The timestep is removed from tuples of type (n, n, int) and (n, int).
-
oemof.solph.processing.
results
(om)[source]¶ Create a result dictionary from the result DataFrame.
Results from Pyomo are written into a dictionary of pandas objects where a Series holds all scalar values and a dataframe all sequences for nodes and flows. The dictionary is keyed by the nodes e.g. results[idx][‘scalars’] and flows e.g. results[n, n][‘sequences’].
oemof.solph.views module¶
Modules for providing convenient views for solph results.
Information about the possible usage is provided within the examples.
-
class
oemof.solph.views.
NodeOption
[source]¶ Bases:
str
,enum.Enum
An enumeration.
-
All
= 'all'¶
-
HasInputs
= 'has_inputs'¶
-
HasOnlyInputs
= 'has_only_inputs'¶
-
HasOnlyOutputs
= 'has_only_outputs'¶
-
HasOutputs
= 'has_outputs'¶
-
-
oemof.solph.views.
convert_to_multiindex
(group, index_names=None, droplevel=None)[source]¶ Convert dict to pandas DataFrame with multiindex
Parameters: - group (dict) – Sequences of the oemof.solph.Model.results dictionary
- index_names (arraylike) – Array with names of the MultiIndex
- droplevel (arraylike) – List containing levels to be dropped from the dataframe
-
oemof.solph.views.
filter_nodes
(results, option=<NodeOption.All: 'all'>, exclude_busses=False)[source]¶ Get set of nodes from results-dict for given node option.
This function filters nodes from results for special needs. At the moment, the following options are available:
NodeOption.All
: ‘all’: Returns all nodesNodeOption.HasOutputs
: ‘has_outputs’:- Returns nodes with an output flow (eg. Transformer, Source)
NodeOption.HasInputs
: ‘has_inputs’:- Returns nodes with an input flow (eg. Transformer, Sink)
NodeOption.HasOnlyOutputs
: ‘has_only_outputs’:- Returns nodes having only output flows (eg. Source)
NodeOption.HasOnlyInputs
: ‘has_only_inputs’:- Returns nodes having only input flows (eg. Sink)
Additionally, busses can be excluded by setting exclude_busses to True.
Parameters: - results (dict)
- option (NodeOption)
- exclude_busses (bool) – If set, all bus nodes are excluded from the resulting node set.
Returns: set
– A set of Nodes.
-
oemof.solph.views.
get_node_by_name
(results, *names)[source]¶ Searches results for nodes
Names are looked up in nodes from results and either returned single node (in case only one name is given) or as list of nodes. If name is not found, None is returned.
-
oemof.solph.views.
net_storage_flow
(results, node_type)[source]¶ Calculates the net storage flow for storage models that have one input edge and one output edge both with flows within the domain of non-negative reals.
Parameters: - results (dict) – A result dictionary from a solved oemof.solph.Model object
- node_type (oemof.solph class) – Specifies the type for which (storage) type net flows are calculated
Returns: - pandas.DataFrame object with multiindex colums. Names of levels of columns
- are (from, to, net_flow.)
Examples
import oemof.solph as solph from oemof.outputlib import views
# solve oemof solph model ‘m’ # Then collect node weights views.net_storage_flow(m.results(), node_type=solph.GenericStorage)
-
oemof.solph.views.
node
(results, node, multiindex=False, keep_none_type=False)[source]¶ Obtain results for a single node e.g. a Bus or Component.
Either a node or its label string can be passed. Results are written into a dictionary which is keyed by ‘scalars’ and ‘sequences’ holding respective data in a pandas Series and DataFrame.
-
oemof.solph.views.
node_input_by_type
(results, node_type, droplevel=None)[source]¶ Gets all inputs for all nodes of the type node_type and returns a dataframe.
Parameters: - results (dict) – A result dictionary from a solved oemof.solph.Model object
- node_type (oemof.solph class) – Specifies the type of the node for that inputs are selected
- droplevel (list)
Notes
from oemof import solph from oemof.outputlib import views
# solve oemof solph model ‘m’ # Then collect node weights views.node_input_by_type(m.results(), node_type=solph.Sink)
-
oemof.solph.views.
node_output_by_type
(results, node_type, droplevel=None)[source]¶ Gets all outputs for all nodes of the type node_type and returns a dataframe.
Parameters: - results (dict) – A result dictionary from a solved oemof.solph.Model object
- node_type (oemof.solph class) – Specifies the type of the node for that outputs are selected
- droplevel (list)
Notes
import oemof.solph as solph from oemof.outputlib import views
# solve oemof solph model ‘m’ # Then collect node weights views.node_output_by_type(m.results(), node_type=solph.Transformer)
-
oemof.solph.views.
node_weight_by_type
(results, node_type)[source]¶ Extracts node weights (if exist) of all components of the specified node_type.
Node weight are endogenous optimzation variables associated with the node and not the edge between two node, foxample the variable representing the storage level.
Parameters: - results (dict) – A result dictionary from a solved oemof.solph.Model object
- node_type (oemof.solph class) – Specifies the type for which node weights should be collected
Example
from oemof.outputlib import views
# solve oemof model ‘m’ # Then collect node weights views.node_weight_by_type(m.results(), node_type=solph.GenericStorage)
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
Bug reports¶
When reporting a bug please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Documentation improvements¶
oemof-solph could always use more documentation, whether as part of the official oemof-solph docs, in docstrings, or even on the web in blog posts, articles, and such.
Feature requests and feedback¶
The best way to send feedback is to file an issue at https://github.com/oemof/oemof-solph/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that code contributions are welcome :)
Development¶
To set up oemof-solph for local development:
Fork oemof-solph (look for the “Fork” button).
Clone your fork locally:
git clone git@github.com:oemof/oemof-solph.git
Create a branch for local development:
git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes run all the checks and docs builder with tox one command:
tox
Commit your changes and push your branch to GitHub:
git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
If you need some code review or feedback while you’re developing the code just make the pull request.
For merging, you should:
- Include passing tests (run
tox
) [1]. - Update documentation when there’s new API, functionality etc.
- Add a note to
CHANGELOG.rst
about the changes. - Add yourself to
AUTHORS.rst
.
[1] | If you don’t have all the necessary python versions available locally you can rely on Travis - it will run the tests for each change you add in the pull request. It will be slower though … |
Tests¶
To run the all tests run:
tox
Note, to combine the coverage data from all the tox environments run:
Windows | set PYTEST_ADDOPTS=--cov-append
tox
|
---|---|
Other | PYTEST_ADDOPTS=--cov-append tox
|
Tips¶
To run a subset of tests:
tox -e envname -- pytest -k test_myfeature
To run all the test environments in parallel (you need to pip install detox
):
detox
Authors¶
–alphabetic order–
- Birgit Schachler
- Brian Michael Lancien
- Caroline Möller
- Caterina Köhl
- Clemens Wingenbach
- Cord Kaldemeyer
- Daniel Rank
- Elisa Gaudchau
- Elisa Papadis
- Fabian Büllesbach
- Francesco Witte
- Guido Plessmann
- Hendrik Hyskens
- Jakob Wolf
- Jann Launer
- Jens-Olaf Delfs
- Johannes Kochems
- Johannes Röder
- Jonathan Amme
- Julian Endres
- Lluis Millet
- Martin Soethe
- Patrik Schönfeldt
- Simon Hilpert
- Stephan Günther
- Uwe Krien
Changelog¶
These are new features and improvements of note in each release
Releases
- v0.4.4 (June 1st, 2021)
- v0.4.2 (May, 11, 2021)
- v0.4.1 (June 24, 2020)
- v0.4.0 (June 6, 2020)
- v0.3.2 (November 29, 2019)
- v0.3.1 (June 11, 2019)
- v0.3.0 (June 5, 2019)
- v0.2.3 (November 21, 2018)
- v0.2.2 (July 1, 2018)
- v0.2.1 (March 19, 2018)
- v0.2.0 (January 12, 2018)
- v0.1.4 (March 28, 2017)
- v0.1.2 (March 27, 2017)
- v0.1.1 (November 2, 2016)
- v0.1.0 (November 1, 2016)
- v0.0.7 (May 4, 2016)
- v0.0.6 (April 29, 2016)
- v0.0.5 (April 1, 2016)
- v0.0.4 (March 03, 2016)
- v0.0.3 (January 29, 2016)
- v0.0.2 (December 22, 2015)
- v0.0.1 (November 25, 2015)
v0.4.4 (June 1st, 2021)¶
API changes¶
- Allow conversion factor of zero for GenericTransformer
- Python 3.6 is no longer officially supported. It may still work for a while though.
New components/constraints¶
- Custom component: oemof.solph.custom.PiecewiseLinearTransformer. A transformer model with one input and one output and an arbitrary piecewise linear conversion function. On how to use the component, refer to the test script and example.
- Enhanced custom SinkDSM:
- Renamed keyword argument method to approach
- Renamed approaches interval to oemof and delay to DIW
- Added modeling approach DLR (PhD thesis of Hans Christian Gils 2015)
- Included load shedding
- Introduced recovery_time in DIW approach
- Introduced shift_time and other parameters for DLR approach
- Included investments in DSM
- Normalized keyword arguments demand, capapcity_up and capacity_down
Bug fixes¶
- Check number of Flow s in GenericStorage
Contributors¶
- Jann Launer
- Johannes Kochems
- Patrik Schönfeldt
- Stefan Schirmeister
- Uwe Krien
v0.4.2 (May, 11, 2021)¶
- Exclude Pyomo version 5.7.3, because this version causes an unusual high computing time to create a model.
v0.4.1 (June 24, 2020)¶
Bug fixes¶
- Fixed incompatibility with recent Pyomo release (5.7)
Known issues¶
- Results of one-time-step optimisation counterintuitive
- If an optimisation with one time-step is performed, at the processing of the results, the scalars of the results is stored in the dict of the sequences. (See Issue #693)
Contributors¶
- Uwe Krien
- Patrik Schönfeldt
v0.4.0 (June 6, 2020)¶
API changes¶
- New package name
- For installation via pypi use
pip install oemof.solph
.
- Change the import of oemof-solph due to unbundling oemof solph
- The import statements have changed, for example
from outputlib.views import processing
–>from oemof.solph import processing
. There are further changes for the modulesviews
,helpers
,economics
,logger
,network
.
- Rename GenericStorage attributes
- The attribute
capacity
of the GenericStorage describing the current absolute stored energy/material/water etc. has been renamed tostorage_content
. In the GenericStorageBlock and GenericInvestmentStorageBlock, the attributeinit_cap
has been renamedinit_content
. This change is intended to avoid confusion withnominal_storage_capacity
or capacity in terms of installed capacity.
- Rename the flow attribute ``actual_value`` to ``fix`` and remove ``fixed``
New features¶
- Allows having a non equidistant timeindex
- By adding the calculate_timeincrement function to tools/helpers.py a non equidistant timeincrement can be calculated. The EnergySystem will now be defined by the timeindex and the calculated timeincrement.
- Allows non-convex investments for flows and storages.
- With this feature, fix investment costs, which do not dependent on the nominal capacity, can be considered.
- Add user warnings for debugging.
- A UserWarning is raised for untypical uses even though this kind of usage is valid if you really know what you are doing. This will help users to debug their code but can be turned of for experienced users.
- Add fixed losses to GenericStorage
- ~oemof.solph.GenericStorage can now have
fixed_losses
, that are independent from storage content.
New components/constraints¶
- Allows a generic limit for attribute weighted investment flows
- InvestmentFlow, which share other limited resources (e.g. space), can be considered.
- Allow to limit count of concurrently active flows in group of flows
- Flows have to be NonConvex, the limit can be an upper or lower one.
- New constraint shared_limit
- Shared limit allows to restrict the weighted sum of arbitrary variables to a corridor. This can be used, e.g. to model shared space is used to store wood pallets and logs with their respective energy density.
Documentation¶
- Restructure and clean-up documentation due to the unbundling
- Improved documentation of ExtractionTurbineCHP
Known issues¶
- Results of one-time-step optimisation counterintuitive
- If an optimisation with one time-step is performed, at the processing of the results, the scalars of the results is stored in the dict of the sequences. (See Issue #693)
Testing¶
- Use
tox
for testing - Now, pep8 tests and build of documentation are tested.
- Use
- Skip github link checks when testing locally
Other changes¶
- Redefine
loss_rate
of GenericStorage - The
loss_rate
of ~oemof.solph.components.GenericStorage is now defined per time increment.
- Redefine
- Change parameters’ data type in the docstrings
- The parameters’ data type is changed from numeric (sequence or scalar) to numeric (iterable or scalar) (Issue #673).
- Add python 3.8 support, remove python 3.5 support
Contributors¶
- Caterina Köhl
- Jonathan Amme
- Uwe Krien
- Johannes Röder
- Jann Launer
- Daniel Rank
- Patrik Schönfeldt
- Stephan Günther
v0.3.2 (November 29, 2019)¶
New features¶
- Allow generic limits for integral over weighted flows. (This is a generalised version of <solph.constraints.emission_limit>.)
- Allow time-dependent weights for integrated weighted limit.
New components¶
- Custom component: ~oemof.solph.custom.SinkDSM. Demand Side Management component that allows to represent flexibile demand. How the component is used is shown in SinkDSM (custom).
Documentation¶
- Revision of the outputlib documentation.
Other changes¶
- The license hase been changed from GPLv3 to the MIT license
- The BaseModel has been revised (test, docstring, warnings, internal naming) (PR #605)
- Style revision to meet pep8 and other pep rules.
Contributors¶
- Guido Plessmann
- Johannes Röder
- Julian Endres
- Patrik Schönfeldt
- Uwe Krien
v0.3.1 (June 11, 2019)¶
Other changes¶
- The API of the GenericStorage changed. Due to the open structure of solph the old parameters are still accepted. Therefore users may not notice that the default value is used instead of the given value after an update from v0.2.x to v0.3.x. With this version an error is raised. We work on a structure to avoid such problems in the future.
Contributors¶
- Patrik Schönfeldt
- Stephan Günther
- Uwe Krien
v0.3.0 (June 5, 2019)¶
API changes¶
- The
param_results
function does not exist anymore. It has been renamed toparameter_as_dict
(Issue #537). - The storage API has been revised. Please check the API documentation for all details.
- The OffsetTransformer is now a regular oemof.solph component. It has been tested and the documentation has been improved. So it has been move from custom to components. Use oemof.solph.components.OffsetTransformer ( Issue #522).
New features¶
- Now it is possible to model just one time step. This is important for time step based models and all other models with an outer loop (Issue #519).
- The storage can be used unbalanced now, which means that the level at the end could be different to the level at the beginning of the modeled time period. See the storage documentation for more details.
- NonConvexFlow <oemof.solph.blocks.NonConvexFlow> can now have activity_costs, maximum_startups, and maximum_shutdowns. This helps, to model e.g. terms of maintannace contracts for small CHP plants.
- Namedtuples and tuples as labels work now without problems. This makes it much easier to find objects and results in large energy systems (Issue #507).
- Groups are now fully lazy. This means that groups are only computed when they are accessed. Previously, whenever nodes where added to an energy system, groups where computed for all but the most recently added node. This node was then only grouped upon addition of another node or upon access of the groups property.
- There is now an explicit Edge <oemof.network.Edge> class. This means that an energy system now consists of Buses <oemof.network.Bus>, Components <oemof.network.Component> and Edges <oemof.network.Edge>. For implementation reasons, Edges <oemof.network.Edge> are still Nodes <oemof.network.Node>. If you know a bit of graph theory and this seems strange to you, think of these Edges <oemof.network.Edge> as classical graph theoretic edges, reified as nodes with an in- and outdegree of one.
- Energy systems <oemof.energy_system.EnergySystem> now support blinker signals. The first supported signal gets emitted, whenever a node <oemof.network.node> is added <oemof.energy_system.EnergySystem.add> to an energy system <oemof.energy_system.EnergySystem>. (blinker)
Documentation¶
- The template for docstrings with equations (docstring of block classes) has been improved.
- A lot of improvements on the documentation
Bug fixes¶
- The timeincrement attribute of the model is not set to one anymore. In earlier versions the timeincrement was set to one by default. This was a problem if a wrong time index was passed. In that case the timeincrement was set to one without a warning. Now an error is raised if no timeincrement or valid time index is found (Issue #549).
Testing¶
- Automatic test coverage control was implemented. Now a PR will not be accepted if it decreases the test coverage.
- Test coverage was increased to over 90%. A badge was added to the oemof github page that shows the actual test coverage.
- Test coverage on the groupings <oemof.groupings> and network <oemof.network> modules has significantly increased. These modules where historically very weakly tested and are now approaching 90% and 95% respectively with more tests being planned.
Contributors¶
(alphabetical order)
- ajimenezUCLA
- FranziPl
- Johannes Röder
- Jakob Wolf
- Jann Launer
- Lluis Millet
- Patrik Schönfeldt
- Simon Hilpert
- Stephan Günther
- Uwe Krien
v0.2.3 (November 21, 2018)¶
Bug fixes¶
- Some functions did not work with tuples as labels. It has been fixed for the ExtractionTurbineCHP, the graph module and the parameter_as_dict function. (Issue #507)
Contributors¶
- Simon Hilpert
- Stephan Günther
- Uwe Krien
v0.2.2 (July 1, 2018)¶
API changes¶
- The storage API has been revised, even though it is still possible to use the old API. In that case a warning is raised (Issue #491).
- The newly introduced parm_results are not results and therefore renamed to parameter_as_dict. The old name is still valid but raises a warning.
New features¶
- We added a new attribute existing to the solph.options.Investement class. It will now be possible to run investment optimization based on already installed capacity of a component. Take a look on Using the investment mode for usage of this option. (Issue #489).
- Investement variables for the capacity and the flows are now decoupled to enable more flexibility. It is possible to couple the flows to the capacity, the flows to itself or to not couple anything. The newly added attributes invest_relation_input_output, invest_relation_input_capacity and invest_relation_output_capacity replace the existing attributes nominal_input_capacity_ratio and nominal_input_capacity_ratio for the investment mode. In case of the dispatch mode one should use the nominal_value of the Flow classes. The attributes nominal_input_capacity_ratio and nominal_input_capacity_ratio will be removed in v0.3.0. Please adapt your application to avoid problems in the future (Issue #480).
- We now have experimental support for deserializing an energy system from a tabular data package. Since we have to extend the datapackage format a bit, the specification is not yet finalized and documentation as well as tests range from sparse to nonexistent. But anyone who wishes to help with the code is welcome to check it out in the datapackage <oemof.tools.datapackage> module.
New components¶
Documentation¶
- The documentation of the storage storage component has been improved.
- The documentation of the Extraction Turbine has been improved.
Known issues¶
- It is not possible to model one time step with oemof.solph. You have to model at least two timesteps (Issue #306). Please leave a comment if this bug affects you.
Bug fixes¶
- Fix file extension check to dump a graph correctly as .graphml-file
- The full constraint set of the ExtractionTurbineCHP class was only build for one object. If more than one object was present the input/output constraint was missing. This lead to wrong results.
- In the solph constraints module the emission constraint did not include the timeincrement from the model which has now be fixed.
- The parameter_as_dict (former: param_results) do work with the views functions now (Issue #494).
Testing¶
- The test coverage has been increased (>80%). oemof has experimental areas to test new functions. These functions are marked as experimental and will not be tested. Therefore the real coverage is even higher.
Other changes¶
- Subclasses of Node <oemof.network.Node> are no longer optimized using __slots__. The abstract parent class still defines __slots__ <oemof.network.Node.__slots__> so that custom subclasses still have the option of using it.
Contributors¶
- Fabian Büllesbach
- Guido Plessmann
- Simon Hilpert
- Stephan Günther
- Uwe Krien
v0.2.1 (March 19, 2018)¶
API changes¶
- The function create_nx_graph only takes an energysystem as argument, not a solph model. As it is not a major release you can still pass a Model but you should adapt your application as soon as possible. (Issue #439)
New features¶
- It is now possible determine minimum up and downtimes for nonconvex flows. Check the oemof_examples repository for an exemplary usage.
- Startup and shutdown costs can now be defined time-dependent.
- The graph module has been revised. (Issue #439)
- You can now store a graph to disc as .graphml file to open it in yEd with labels.
- You can add weight to edges.
- Labels are attached to the nodes.
- Two functions get_node_by_name and filter_nodes have been added that allow to get specified nodes or nodes of one kind from the results dictionary. (Issue #426)
- A new function param_results() collects all parameters of nodes and flows in a dictionary similar to the results dictionary. (Issue #445)
- In outputlib.views.node(), an option for multiindex dataframe has been added.
Documentation¶
- Some small fixes and corrected typos.
Known issues¶
- It is not possible to model one time step with oemof.solph. You have to model at least two timesteps (Issue #306). Please leave a comment if this bug affects you.
Bug fixes¶
- Shutdown costs for nonconvex flows are now accounted within the objective which was not the case before due to a naming error.
- Console script oemof_test_installation has been fixed. (Issue #452)
- Adapt solph to API change in the Pyomo package.
- Deserializing a Node <oemof.network.Node> leads to an object which was no longer serializable. This is fixed now. Node <oemof.network.Node> instances should be able to be dumped and restored an arbitraty amount of times.
- Adding timesteps to index of constraint for component el-line fixes an issue with pyomo.
Testing¶
- New console script test_oemof has been added (experimental). (Issue #453)
Other changes¶
- Internal change: Unnecessary list extensions while creating a model are avoided, which leads to a decrease in runtime. (Issue #438)
- The negative/positive gradient attributes are dictionaries. In the constructor they moved from sequences to a new dictionaries argument. (Issue #437)
- License agreement was adapted according to the reuse project (Issue #442)
- Code of conduct was added. (Issue #440)
- Version of required packages is now limited to the most actual version (Issue #464)
Contributors¶
- Cord Kaldemeyer
- Jann Launer
- Simon Hilpert
- Stephan Günther
- Uwe Krien
v0.2.0 (January 12, 2018)¶
API changes¶
- The NodesFromCSV has been removed from the code base. An alternative excel (spreadsheet) reader is provided in the newly created excel example in the oemof_examples repository.
- LinearTransformer and LinearN1Transformer classes are now combined within one Transformer class. The new class has n inputs and n outputs. Please note that the definition of the conversion factors (for N1) has changed. See the new docstring of ~oemof.solph.network.Transformer class to avoid errors (Issue #351).
- The oemof.solph.network.Storage class has been renamed and moved to oemof.solph.components.GenericStorage.
- As the example section has been moved to a new repository the oemof_example command was removed. Use oemof_installation_test to check your installation and the installed solvers.
- OperationalModel has been renamed to Model. The es parameter was renamed to energysystem parameter.
- Nodes <oemof.network.Node> are no longer automatically added to the most recently created energy system <oemof.energy_system.EnergySystem>. You can still restore the old automatic registration by manually assigning an energy system <oemof.energy_system.EnergySystem> to Node.registry <oemof.network.Node.registry>. On the other hand you can still explicitly add <oemof.energy_system.EnergySystem.add> nodes <oemof.network.Node> to an energy system <oemof.energy_system.EnergySystem>. This option has been made a bit more feature rich by the way, but see below for more on this. Also check the oemof_examples repository for more information on the usage.
- The fixed_costs attribute of the nodes <oemof.solph.network.Flow> has been removed. See (Issue #407) for more information.
- The classes DataFramePlot <outputlib.DataFramePlot> and ResultsDataFrame <outputlib.ResultsDataFrame> have been removed due to the redesign of the outputlib module.
New features¶
- A new oemof_examples repository with some new examples was created.
- A new outputlib module has been created to provide a convenient data structure for optimization results and enable quick analyses. All decision variables of a Node are now collected automatically which enables an easier development of custom components. See the revised Handling Results documentation for more details or have a look at the oemof_examples repository for information on the usage. Keep your eyes open, some new functions will come soon that make the processing of the results easier. See the actual pull request or issues for detailed information.
- The transformer class can now be used with n inputs and n outputs ( ~oemof.solph.network.Transformer)
- A new module with useful additional constraints were created with these constraints global emission or investment limits can be set. Furthermore it is possible to connect investment variables. Please add your own additional constraints or let us know what is needed in the future.
- A module to create a networkx graph from your energy system or your optimisation model was added. You can use networkx to plot and analyse graphs. See the graph module in the documentation of oemof-network for more information.
- It’s now possible to modify a node’s <oemof.network.Node> inputs <oemof.network.Node.inputs> and outputs <oemof.network.Node.outputs> by inserting and removing nodes <oemof.network.Node> to and from the correspoding dictionaries. Outputs <oemof.network.Node.outputs> where already working previously, but due to an implementation quirk, inputs <oemof.network.Node.inputs> did not behave as expected. This is now fixed.
- One can now explicitly add <oemof.energy_system.EnergySystem.add> nodes <oemof.network.Node> to an energy system <oemof.energy_system.EnergySystem> in bulk using * and ** syntax. For the latter case, the values <dict.values> of the dictionary passed in will be added.
- New components can now be added to the custom.py module. Components in this module are indicated as in a testing state. Use them with care. This lowers the entry barriers to test new components within the solph structure and find other testers.
New components¶
- The nodes ElectricalLine <oemof.solph.custom.ElectricalLine> and ElectricalBus <oemof.solph.custom.ElectricalBus> can be used for Linear Optimal Powerflow calculation based on angle formulations. These components have been added to the solph.custom module. Though it should work correctly, it is in a preliminary stage. Please check your results. Feedback is welcome!
- The custom component Link <oemof.solph.custom.Link> can now be used to model a bidirectional connection within one component. Check out the example in the oemof_examples repository.
- The component GenericCHP <oemof.solph.components.GenericCHP> can be used to model different CHP types such as extraction or back-pressure turbines and motoric plants. The component uses a mixed-integer linear formulation and can be adapted to different technical layouts with a high level of detail. Check out the example in the oemof_examples repository.
- The component GenericCAES <oemof.solph.custom.GenericCAES> can be used to model different concepts of compressed air energy storage. Technical concepts such as diabatic or adiabatic layouts can be modelled at a high level of detail. The component uses a mixed-integer linear formulation.
- The custom component GenericOffsetTransformer <oemof.solph.custom.GenericOffsetTransformer> can be used to model components with load ranges such as heat pumps and also uses a mixed-integer linear formulation.
Documentation¶
- Large parts of the documentation have been proofread and improved since the last developer meeting in Flensburg.
- The solph documentation has got an extra section with all existing components (Solph components).
- The developer documentation has been developed to lower the barriers for new developers. Furthermore, a template for pull request was created.
Known issues¶
- It is not possible to model one time step with oemof.solph. You have to model at least two timesteps (Issue #306). Please leave a comment if this bug affects you.
Bug fixes¶
- LP-file tests are now invariant against sign changes in equations, because the equations are now normalized to always have non-negative right hand sides.
Testing¶
- All known and newly created components are now tested within an independent testing environment which can be found in /tests/.
- Other testing routines have been streamlined and reviewed and example tests have been integrated in the nosetest environment.
Other changes¶
- The plot functionalities have been removed completely from the outputlib as they are less a necessary part but more an optional tool . Basic plotting examples that show how to quickly create plots from optimization results can now be found in the oemof_examples repository. You can still find the “old” standard plots within the oemof_visio repository as they are now maintained separately.
- A user forum has been created to answer use questions.
Contributors¶
- Cord Kaldemeyer
- Jens-Olaf Delfs
- Stephan Günther
- Simon Hilpert
- Uwe Krien
v0.1.4 (March 28, 2017)¶
Bug fixes¶
- fix examples (issue #298)
Documentation¶
- Adapt installation guide.
Contributors¶
- Uwe Krien
- Stephan Günther
v0.1.2 (March 27, 2017)¶
New features¶
- Revise examples - clearer naming, cleaner code, all examples work with cbc solver (issue #238, issue #247).
- Add option to choose solver when executing the examples (issue #247).
- Add new transformer class: VariableFractionTransformer (child class of LinearTransformer). This class represents transformers with a variable fraction between its output flows. In contrast to the LinearTransformer by now it is restricted to two output flows.(issue #248)
- Add new transformer class: N1Transformer (counterpart of LinearTransformer). This class allows to have multiple inputflows that are converted into one output flow e.g. heat pumps or mixing-components.
- Allow to set addtional flow attributes inside NodesFromCSV in solph inputlib
- Add economics module to calculate investment annuities (more to come in future versions)
- Add module to store input data in multiple csv files and merge by preprocessing
- Allow to slice all information around busses via a new method of the ResultsDataFrame
- Add the option to save formatted balances around busses as single csv files via a new method of the ResultsDataFrame
Documentation¶
- Improve the installation guide.
Bug fixes¶
- Allow conversion factors as a sequence in the CSV reader
Other changes¶
- Speed up constraint-building process by removing unnecessary method call
- Clean up the code according to pep8 and pylint
Contributors¶
- Cord Kaldemeyer
- Guido Plessmann
- Uwe Krien
- Simon Hilpert
- Stephan Günther
v0.1.1 (November 2, 2016)¶
Hot fix release to make examples executable.
Bug fixes¶
- Fix copy of default logging.ini (issue #235)
- Add matplotlib to requirements to make examples executable after installation (issue #236)
Contributors¶
- Guido Plessmann
- Uwe Krien
v0.1.0 (November 1, 2016)¶
The framework provides the basis for a great range of different energy system model types, ranging from LP bottom-up (power and heat) economic dispatch models with optional investment to MILP operational unit commitment models.
With v0.1.0 we refactored oemof (not backward compatible!) to bring the implementation in line with the general concept. Hence, the API of components has changed significantly and we introduced the new ‘Flow’ component. Besides an extensive grouping functionality for automatic creation of constraints based on component input data the documentation has been revised.
We provide examples to show the broad range of possible applications and the frameworks flexibility.
API changes¶
- The demandlib is no longer part of the oemof package. It has its own package now: (demandlib)
New features¶
Solph’s EnergySystem <oemof.solph.network.EnergySystem> now automatically uses solph’s GROUPINGS <oemof.solph.groupings.GROUPINGS> in addition to any user supplied ones. See the API documentation for more information.
The groupings <oemof.groupings.Grouping> introduced in version 0.0.5 now have more features, more documentation and should generally be pretty usable:
- They moved to their own module: oemof.groupings and deprecated constructs ensuring compatibility with prior versions have been removed.
- It’s possible to assign a node to multiple groups from one Grouping <oemof.groupings.Grouping> by returning a list of group keys from key <oemof.groupings.Grouping.key>.
- If you use a non callable object as the key <oemof.groupings.Grouping.key> parameter to Groupings <oemof.groupings.Grouping>, the constructor will not make an attempt to call them, but use the object directly as a key.
- There’s now a filter <oemof.groupings.Grouping.filter> parameter, enabling a more concise way of filtering group contents than using value <oemof.groupings.Grouping.value>.
Documentation¶
- Complete revision of the documentation. We hope it is now more intuitive and easier to understand.
Testing¶
- Create a structure to use examples as system tests (issue #160)
Bug fixes¶
- Fix relative path of logger (issue #201)
- More path fixes regarding installation via pip
Other changes¶
- Travis CI will now check PR’s automatically
- Examples executable from command-line (issue #227)
Contributors¶
- Stephan Günther
- Simon Hilpert
- Uwe Krien
- Guido Pleßmann
- Cord Kaldemeyer
v0.0.7 (May 4, 2016)¶
Bug fixes¶
- Exclude non working pyomo version
v0.0.6 (April 29, 2016)¶
New features¶
- It is now possible to choose whether or not the heat load profile generated with the BDEW heat load profile method should only include space heating or space heating and warm water combined. (Issue #130)
- Add possibility to change the order of the columns of a DataFrame subset. This is useful to change the order of stacked plots. (Issue #148)
Documentation¶
Testing¶
- Fix constraint tests (Issue #137)
Bug fixes¶
- Use of wrong columns in generation of SF vector in BDEW heat load profile generation (Issue #129)
- Use of wrong temperature vector in generation of h vector in BDEW heat load profile generation.
Other changes¶
Contributors¶
- Uwe Krien
- Stephan Günther
- Simon Hilpert
- Cord Kaldemeyer
- Birgit Schachler
v0.0.5 (April 1, 2016)¶
New features¶
- There’s now a flexible transformer <oemof.core.network.entities.components.transformers.TwoInputsOneOutput> with two inputs and one output. (Issue #116)
- You now have the option create special groups of entities in your energy system. The feature is not yet fully implemented, but simple use cases are usable already. (Issue #60)
Documentation¶
- The documentation of the electrical demand <oemof.demandlib.demand.electrical_demand> class has been cleaned up.
- The API documentation now has its own section so it doesn’t clutter up the main navigation sidebar so much anymore.
Testing¶
- There’s now a dedicated module/suite testing solph constraints.
- This suite now has proper fixtures (i.e. setup/teardown methods) making them (hopefully) independent of the order in which they are run (which, previously, they where not).
Bug fixes¶
- Searching for oemof’s configuration directory is now done in a platform independent manner. (Issue #122)
- Weeks no longer have more than seven days. (Issue #126)
Other changes¶
Contributors¶
- Uwe Krien
- Stephan Günther
- Guido Pleßmann
v0.0.4 (March 03, 2016)¶
New features¶
Documentation¶
- Update developer notes
Testing¶
- Described testing procedures in developer notes
- New constraint tests for heating buses
Bug fixes¶
- Use of pyomo fast build
- Broken result-DataFrame in outputlib
- Dumping of EnergySystem
Other changes¶
- PEP8
Contributors¶
- Cord Kaldemeyer
- Uwe Krien
- Simon Hilpert
- Stephan Günther
- Clemens Wingenbach
- Elisa Papdis
- Martin Soethe
- Guido Plessmann
v0.0.3 (January 29, 2016)¶
New features¶
- Added a class to convert the results dictionary to a multiindex DataFrame (issue #36)
- Added a basic plot library (issue #36)
- Add logging functionalities (issue #28)
- Add entities_from_csv functionality for creating of entities from csv-files
- Add a time-depended upper bound for the output of a component (issue #65)
- Add fast_build functionlity for pyomo models in solph module (issue #68)
- The package is no longer named oemof_base but is now just called oemof.
- The results dictionary stored in the energy system now contains an attribute for the objective function and for objects which have special result attributes, those are now accessible under the object keys, too. (issue #58)
Documentation¶
- Added the Readme.rst as “Getting started” to the documentation.
- Fixed installation description (issue #38)
- Improved the developer notes.
Testing¶
Bug fixes¶
- Fix contraints in solph
- Fix pep8
Other changes¶
Contributors¶
- Cord Kaldemeyer
- Uwe Krien
- Clemens Wingenbach
- Simon Hilpert
- Stephan Günther
v0.0.2 (December 22, 2015)¶
New features¶
- Adding a definition of a default oemof logger (issue #28)
- Revise the EnergySystem class according to the oemof developing meeting (issue #25)
- Add a dump and restore method to the EnergySystem class to dump/restore its attributes (issue #31)
- Functionality for minimum up- and downtime constraints (oemof.solph.linear_mixed_integer_constraints module)
- Add relax option to simulation class for calculation of linear relaxed mixed integer problems
- Instances of EnergySystem <oemof.core.energy_system.EnergySystem> now keep track of Entities <oemof.core.network.Entity> via the entities <oemof.core.energy_system.EnergySystem.entities> attribute. (issue #20)
- There’s now a standard way of working with the results obtained via a call to OptimizationModel#results <oemof.solph.optimization_model.OptimizationModel.results>. See its documentation, the documentation of EnergySystem#optimize <oemof.core.energy_system.EnergySystem.optimize> and finally the discussion at issue #33 for more information.
- New class VariableEfficiencyCHP <oemof.core.network.entities.components.transformers.VariableEfficiencyCHP> to model combined heat and power units with variable electrical efficiency.
- New methods for VariableEfficiencyCHP <oemof.core.network.entities.components.transformers.VariableEfficiencyCHP> inside the solph-module:
- MILP-constraint <oemof.solph.linear_mixed_integer_constraints.add_variable_linear_eta_relation>
- Linear-constraint <oemof.solph.linear_constraints.add_eta_total_chp_relation>
Documentation¶
Testing¶
Bug fixes¶
- now the api-docs can be read on readthedocs.org
- a storage automically calculates its maximum output/input if the capacity and the c-rate is given (issue #27)
- Fix error in accessing dual variables in oemof.solph.postprocessing
Other changes¶
Contributors¶
- Uwe Krien
- Simon Hilpert
- Cord Kaldemeyer
- Guido Pleßmann
- Stephan Günther
v0.0.1 (November 25, 2015)¶
First release by the oemof developing group.