EnergySystemModel class

A description of the class is given below.

Class description:

Last edited: November 12 2020
@author: FINE Developer Team (FZJ IEK-3)

class energySystemModel.EnergySystemModel(locations, commodities, commodityUnitsDict, numberOfTimeSteps=8760, hoursPerTimeStep=1, costUnit='1e9 Euro', lengthUnit='km', verboseLogLevel=0, balanceLimit=None, lowerBound=False)[source]

EnergySystemModel class

The functionality provided by the EnergySystemModel class is fourfold:

  • With it, the basic structure (spatial and temporal resolution, considered commodities) of the investigated energy system is defined.
  • It serves as a container for all components investigated in the energy system model. These components, namely sources and sinks, conversion options, storage options, and transmission options (in the core module), can be added to an EnergySystemModel instance.
  • It provides the core functionality of modeling and optimizing the energy system based on the specified structure and components on the one hand and of specified simulation parameters on the other hand.
  • It stores optimization results which can then be post-processed with other modules.

The parameters which are stored in an instance of the class refer to:

  • the modeled spatial representation of the energy system (locations, lengthUnit)
  • the modeled temporal representation of the energy system (totalTimeSteps, hoursPerTimeStep, years, periods, periodsOrder, periodsOccurrences, timeStepsPerPeriod, interPeriodTimeSteps, isTimeSeriesDataClustered, typicalPeriods, tsaInstance, timeUnit)
  • the considered commodities in the energy system (commodities, commodityUnitsDict)
  • the considered components in the energy system (componentNames, componentModelingDict, costUnit)
  • optimization related parameters (pyM, solverSpecs)

The parameters are first set when a class instance is initiated. The parameters which are related to the components (e.g. componentNames) are complemented by adding the components to the class instance.

Instances of this class provide functions for

  • adding components and their respective modeling classes (add)

  • clustering the time series data of all added components using the time series aggregation package tsam, cf. https://github.com/FZJ-IEK3-VSA/tsam (cluster)

  • optimizing the specified energy system (optimize), for which a pyomo concrete model instance is built and filled with

    1. basic time sets,
    2. sets, variables and constraints contributed by the component modeling classes,
    3. basic, component overreaching constraints, and
    4. an objective function.

    The pyomo instance is then optimized by a specified solver. The optimization results are processed once available.

  • getting components and their attributes (getComponent, getCompAttr, getOptimizationSummary)

Last edited: November 12 2020
@author: FINE Developer Team (FZJ IEK-3)

__init__(locations, commodities, commodityUnitsDict, numberOfTimeSteps=8760, hoursPerTimeStep=1, costUnit='1e9 Euro', lengthUnit='km', verboseLogLevel=0, balanceLimit=None, lowerBound=False)[source]

Constructor for creating an EnergySystemModel class instance

Required arguments:

Parameters:
  • locations (set of strings) – locations considered in the energy system
  • commodities (set of strings) – commodities considered in the energy system
  • commodityUnitsDict (dictionary of strings) – dictionary which assigns each commodity a quantitative unit per time (e.g. GW_el, GW_H2, Mio.t_CO2/h). The dictionary is used for results output. Note for advanced users: the scale of these units can influence the numerical stability of the optimization solver, cf. http://files.gurobi.com/Numerics.pdf where a reasonable range of model coefficients is suggested.

Default arguments:

Parameters:
  • numberOfTimeSteps – number of time steps considered when modeling the energy system (for each time step, or each representative time step, variables and constraints are constituted). Together with the hoursPerTimeStep, the total number of hours considered can be derived. The total number of hours is again used for scaling the arising costs to the arising total annual costs (TAC) which are minimized during optimization.
    * the default value is 8760.
  • hoursPerTimeStep (strictly positive float) – hours per time step
    * the default value is 1
  • costUnit (string) – cost unit of all cost related values in the energy system. This argument sets the unit of all cost parameters which are given as an input to the EnergySystemModel instance (e.g. for the invest per capacity or the cost per operation). Note for advanced users: the scale of this unit can influence the numerical stability of the optimization solver, cf. http://files.gurobi.com/Numerics.pdf where a reasonable range of model coefficients is suggested.
    * the default value is ‘10^9 Euro’ (billion euros), which can be a suitable scale for national energy systems.
  • lengthUnit (string) – length unit for all length-related values in the energy system. Note for advanced users: the scale of this unit can influence the numerical stability of the optimization solver, cf. http://files.gurobi.com/Numerics.pdf where a reasonable range of model coefficients is suggested.
    * the default value is ‘km’ (kilometers).
  • verboseLogLevel (integer (0, 1 or 2)) –

    defines how verbose the console logging is:

    • 0: general model logging, warnings and optimization solver logging are displayed.
    • 1: warnings are displayed.
    • 2: no general model logging or warnings are displayed, the optimization solver logging is set to a minimum.

    Note: if required, the optimization solver logging can be separately enabled in the optimizationSpecs of the optimize function.
    * the default value is 0

  • balanceLimit (pd.DataFrame or pd.Series) – defines the balanceLimit constraint (various different balanceLimitIDs possible) for specific regions or the whole model. The balancelimitID can be assigned to various components of e.g. SourceSinkModel or TransmissionModel to limit the balance of production, consumption and im/export. If the balanceLimit is passed as pd.Series it will apply to the overall model, if it is passed as pd.Dataframe each column will apply to one region of the multi-node model. In the latter case, the number and names of the columns should match the regions/region names in the model. Each row contains an individual balanceLimitID as index and the corresponding values for the model (pd.Series) or regions (pd.Dataframe). Values are always given in the unit of the esM commodities unit. Note: If bounds for sinks shall be specified (e.g. min. export, max. sink volume), values must be defined as negative. Example: pd.DataFrame(columns=[“Region1”], index=[“electricity”], data=[1000])
    * the default value is None
  • lowerBound (bool) –

    defines whether a lowerBound or an upperBound is considered in the balanceLimitConstraint. By default an upperBound is considered. However, multiple cases can be considered: 1) Sources:

    a) LowerBound=False: UpperBound for commodity from SourceComponent (Define positive value in balanceLimit). Example: Limit CO2-Emission b) LowerBound=True: LowerBound for commodity from SourceComponent (Define positive value in balanceLimit). Example: Require minimum production from renewables.
    1. Sinks:
      a) LowerBound=False: UpperBound in a mathematical sense for commodity from SinkComponent (Logically minimum limit for negative values, define negative value in balanceLimit). Example: Minimum export/consumption of hydrogen. b) LowerBound=True: LowerBound in a mathematical sense for commodity from SourceComponent (Logically maximum limit for negative values, define negative value in balanceLimit). Example: Define upper limit for Carbon Capture & Storage.


    * the default value is False

add(component)[source]

Function for adding a component and, if required, its respective modeling class to the EnergySystemModel instance. The added component has to inherit from the FINE class Component.

Parameters:component (An object which inherits from the FINE Component class) – the component to be added
removeComponent(componentName, track=False)[source]

Function which removes a component from the energy system.

Parameters:
  • componentName (string) – name of the component that should be removed
  • track (boolean) – specifies if the removed components should be tracked or not
    * the default value is False
Returns:

dictionary with the removed componentName and component instance if track is set to True else None.

Return type:

dict or None

getComponent(componentName)[source]

Function which returns a component of the energy system.

Parameters:componentName (string) – name of the component that should be returned
Returns:the component which has the name componentName
Return type:Component
getComponentAttribute(componentName, attributeName)[source]

Function which returns an attribute of a component considered in the energy system.

Parameters:
  • componentName (string) – name of the component from which the attribute should be obtained
  • attributeName (string) – name of the attribute that should be returned
Returns:

the attribute specified by the attributeName of the component with the name componentName

Return type:

depends on the specified attribute

getOptimizationSummary(modelingClass, outputLevel=0)[source]

Function which returns the optimization summary (design variables, aggregated operation variables, objective contributions) of a modeling class.

Parameters:
  • modelingClass (string) – name of the modeling class from which the optimization summary should be obtained
  • outputLevel (integer (0, 1 or 2)) –

    states the level of detail of the output summary:

    • 0: full optimization summary is returned
    • 1: full optimization summary is returned but rows in which all values are NaN (not a number) are dropped
    • 2: full optimization summary is returned but rows in which all values are NaN or 0 are dropped


    * the default value is 0

Returns:

the optimization summary of the requested modeling class

Return type:

pandas DataFrame

cluster(numberOfTypicalPeriods=7, numberOfTimeStepsPerPeriod=24, segmentation=False, numberOfSegmentsPerPeriod=24, clusterMethod='hierarchical', sortValues=True, storeTSAinstance=False, **kwargs)[source]

Cluster the time series data of all components considered in the EnergySystemModel instance and then stores the clustered data in the respective components. For this, the time series data is broken down into an ordered sequence of periods (e.g. 365 days) and to each period a typical period (e.g. 7 typical days with 24 hours) is assigned. Moreover, the time steps within the periods can further be clustered to bigger time steps with an irregular duration using the segmentation option. For the clustering itself, the tsam package is used (cf. https://github.com/FZJ-IEK3-VSA/tsam). Additional keyword arguments for the TimeSeriesAggregation instance can be added (facilitated by kwargs). As an example: it might be useful to add extreme periods to the clustered typical periods. Note: The segmentation option can be freely combined with all subclasses. However, an irregular time step length is not meaningful for the minimumDownTime and minimumUpTime in the conversionDynamic module, because the time would be different for each segment. The same holds true for the DSM module.

Default arguments:

Parameters:
  • numberOfTypicalPeriods (strictly positive integer) – states the number of typical periods into which the time series data should be clustered. The number of time steps per period must be an integer multiple of the total number of considered time steps in the energy system. Note: Please refer to the tsam package documentation of the parameter noTypicalPeriods for more information.
    * the default value is 7
  • numberOfTimeStepsPerPeriod (strictly positive integer) – states the number of time steps per period
    * the default value is 24
  • segmentation (boolean) – states whether the typical periods should be further segmented to fewer time steps
    * the default value is False
  • numberOfSegmentsPerPeriod (strictly positive integer) – states the number of segments per period
    * the default value is 24
  • clusterMethod (string) – states the method which is used in the tsam package for clustering the time series data. Options are for example ‘averaging’,’k_means’,’exact k_medoid’ or ‘hierarchical’. Note: Please refer to the tsam package documentation of the parameter clusterMethod for more information.
    * the default value is ‘hierarchical’
  • sortValues (boolean) – states if the algorithm in the tsam package should use (a) the sorted duration curves (-> True) or (b) the original profiles (-> False) of the time series data within a period for clustering. Note: Please refer to the tsam package documentation of the parameter sortValues for more information.
    * the default value is True
  • storeTSAinstance (boolean) – states if the TimeSeriesAggregation instance created during clustering should be stored in the EnergySystemModel instance.
    * the default value is False

Last edited: November 12 2020
@author: FINE Developer Team (FZJ IEK-3)

declareTimeSets(pyM, timeSeriesAggregation, segmentation)[source]

Set and initialize basic time parameters and sets.

Parameters:
  • pyM (pyomo ConcreteModel) – a pyomo ConcreteModel instance which contains parameters, sets, variables, constraints and objective required for the optimization set up and solving.
  • timeSeriesAggregation (boolean) – states if the optimization of the energy system model should be done with (a) the full time series (False) or (b) clustered time series data (True).
    * the default value is False
  • segmentation (boolean) – states if the optimization of the energy system model based on clustered time series data should be done with (a) aggregated typical periods with the original time step length (False) or (b) aggregated typical periods with further segmented time steps (True).
    * the default value is False
declareBalanceLimitConstraint(pyM, timeSeriesAggregation)[source]

Declare balance limit constraint.

Balance limit constraint can limit the exchange of commodities within the model or over the model region boundaries. See the documentation of the parameters for further explanation. In general the following equation applies:

E_source - E_sink + E_exchange,in - E_exchange,out <= E_lim (self.LowerBound=False) E_source - E_sink + E_exchange,in - E_exchange,out >= E_lim (self.LowerBound=True)
Parameters:
  • pyM (pyomo ConcreteModel) – a pyomo ConcreteModel instance which contains parameters, sets, variables, constraints and objective required for the optimization set up and solving.
  • timeSeriesAggregation (boolean) – states if the optimization of the energy system model should be done with (a) the full time series (False) or (b) clustered time series data (True).
    * the default value is False
declareSharedPotentialConstraints(pyM)[source]

Declare shared potential constraints, e.g. if a maximum potential of salt caverns has to be shared by salt cavern storing methane and salt caverns storing hydrogen.

\underset{\text{comp} \in \mathcal{C}^{ID}}{\sum} \text{cap}^{comp}_{loc} / \text{capMax}^{comp}_{loc} \leq 1

Parameters:pyM (pyomo ConcreteModel) – a pyomo ConcreteModel instance which contains parameters, sets, variables, constraints and objective required for the optimization set up and solving.
declareComponentLinkedQuantityConstraints(pyM)[source]

Declare linked component quantity constraint, e.g. if an engine (E-Motor) is built also a storage (Battery) and a vehicle body (e.g. BEV Car) needs to be built. Not the capacity of the components, but the number of the components is linked.

Parameters:pyM (pyomo ConcreteModel) – a pyomo ConcreteModel instance which contains parameters, sets, variables, constraints and objective required for the optimization set up and solving.
declareCommodityBalanceConstraints(pyM)[source]

Declare commodity balance constraints (one balance constraint for each commodity, location and time step)

\underset{\text{comp} \in \mathcal{C}^{comm}_{loc}}{\sum} \text{C}^{comp,comm}_{loc,p,t} = 0

Parameters:pyM (pyomo ConcreteModel) – a pyomo ConcreteModel instance which contains parameters, sets, variables, constraints and objective required for the optimization set up and solving.
declareObjective(pyM)[source]

Declare the objective function by obtaining the contributions to the objective function from all modeling classes. Currently, the only objective function which can be selected is the sum of the total annual cost of all components.

z^* = \min \underset{comp \in \mathcal{C}}{\sum} \ \underset{loc \in \mathcal{L}^{comp}}{\sum} 
\left( TAC_{loc}^{comp,cap}  +  TAC_{loc}^{comp,bin} + TAC_{loc}^{comp,op} \right)

Objective Function detailed:

\begin{eqnarray*}
z^* = \min & & \underset{comp \in \mathcal{C}}{\sum}  \ \underset{loc \in \mathcal{L}^{comp}}{\sum}
\left[ \text{F}^{comp,cap}_{loc} \cdot \left(  \frac{\text{investPerCap}^{comp}_{loc}}{\text{CCF}^{comp}_{loc}} \right.
+ \text{opexPerCap}^{comp}_{loc} \right) \cdot cap^{comp}_{loc} \\
& & + \ \text{F}^{comp,bin}_{loc} \cdot \left( \frac{\text{investIfBuilt}^{comp}_{loc}}     {CCF^{comp}_{loc}} 
+ \text{opexIfBuilt}^{comp}_{loc} \right)  \cdot  bin^{comp}_{loc} \\
& & \left. + \left( \underset{(p,t) \in \mathcal{P} \times \mathcal{T}}{\sum} \ \underset{\text{opType} \in \mathcal{O}^{comp}}{\sum} \text{factorPerOp}^{comp,opType}_{loc} \cdot op^{comp,opType}_{loc,p,t} \cdot  \frac{\text{freq(p)}}{\tau^{years}} \right) \right]
\end{eqnarray*}

Parameters:pyM (pyomo ConcreteModel) – a pyomo ConcreteModel instance which contains parameters, sets, variables, constraints and objective required for the optimization set up and solving.
declareOptimizationProblem(timeSeriesAggregation=False, segmentation=False, relaxIsBuiltBinary=False)[source]

Declare the optimization problem belonging to the specified energy system for which a pyomo concrete model instance is built and filled with * basic time sets, * sets, variables and constraints contributed by the component modeling classes, * basic, component overreaching constraints, and * an objective function.

Default arguments:

Parameters:
  • timeSeriesAggregation (boolean) – states if the optimization of the energy system model should be done with (a) the full time series (False) or (b) clustered time series data (True).
    * the default value is False
  • segmentation (boolean) – states if the optimization of the energy system model based on clustered time series data should be done with (a) aggregated typical periods with the original time step length (False) or (b) aggregated typical periods with further segmented time steps (True).
    * the default value is False
  • relaxIsBuiltBinary – states if the optimization problem should be solved as a relaxed LP to get the lower bound of the problem.
    * the default value is False

Last edited: March 26, 2020
@author: FINE Developer Team (FZJ IEK-3)

optimize(declaresOptimizationProblem=True, relaxIsBuiltBinary=False, timeSeriesAggregation=False, logFileName='', threads=3, solver='None', timeLimit=None, optimizationSpecs='', warmstart=False)[source]

Optimize the specified energy system for which a pyomo ConcreteModel instance is built or called upon. A pyomo instance is optimized with the specified inputs, and the optimization results are further processed.

Default arguments:

Parameters:
  • declaresOptimizationProblem (boolean) – states if the optimization problem should be declared (True) or not (False). (a) If true, the declareOptimizationProblem function is called and a pyomo ConcreteModel instance is built. (b) If false a previously declared pyomo ConcreteModel instance is used.
    * the default value is True
  • relaxIsBuiltBinary – states if the optimization problem should be solved as a relaxed LP to get the lower bound of the problem.
    * the default value is False
  • timeSeriesAggregation (boolean) – states if the optimization of the energy system model should be done with (a) the full time series (False) or (b) clustered time series data (True).
    * the default value is False
  • segmentation (boolean) – states if the optimization of the energy system model based on clustered time series data should be done with (a) aggregated typical periods with the original time step length (False) or (b) aggregated typical periods with further segmented time steps (True).
    * the default value is False
  • logFileName (string) – logFileName is used for naming the log file of the optimization solver output if gurobi is used as the optimization solver. If the logFileName is given as an absolute path (e.g. logFileName = os.path.join(os.getcwd(), ‘Results’, ‘logFileName.txt’)) the log file will be stored in the specified directory. Otherwise, it will be stored by default in the directory where the executing python script is called.
    * the default value is ‘job’
  • threads (positive integer) – number of computational threads used for solving the optimization (solver dependent input) if gurobi is used as the solver. A value of 0 results in using all available threads. If a value larger than the available number of threads are chosen, the value will reset to the maximum number of threads.
    * the default value is 3
  • solver (string) – specifies which solver should solve the optimization problem (which of course has to be installed on the machine on which the model is run).
    * the default value is ‘gurobi’
  • timeLimit (string) – if not specified as None, indicates the maximum solve time of the optimization problem in seconds (solver dependent input). The use of this parameter is suggested when running models in runtime restricted environments (such as clusters with job submission systems). If the runtime limitation is triggered before an optimal solution is available, the best solution obtained up until then (if available) is processed.
    * the default value is None
  • optimizationSpecs – specifies parameters for the optimization solver (see the respective solver documentation for more information). Example: ‘LogToConsole=1 OptimalityTol=1e-6’
    * the default value is an empty string (‘’)
  • warmstart (boolean) – specifies if a warm start of the optimization should be considered (not always supported by the solvers).
    * the default value is False

Last edited: March 26, 2020
@author: FINE Developer Team (FZJ IEK-3)