Operational mode¶
Tutorial 1: Operational Multi-Node Example¶
This example analyzes the energy system of a hypothetical region (Utopia) which is divided into two locations: Utopia-north and Utopia-south.
The Reference Energy System of the northern region includes a natural gas extraction technology, two renewable power supply technologies (Wind and Hydro), and one conventional power plant (Combined Heat and Power) which converts the natural gas fuel to both heat and electricity. Moreover, two types of transmission (Electricity Transmission and Distribution and Gas Pipelines) are considered for transporting the electricity and gas to the demand side. The transmitted electricity is directly entered into the final electricity demand technology, while the transmitted gas is converted by gas boilers to heat which ultimately enters the final heat demand technology.
On the other hand, the Reference Energy System of the southern region consists of only two renewable power supply technologies (Geothermal and Solar). The produced electricity from these power plants is then delivered to the Final Electricity Demand technology after passing through the local Electricity Transmission and Distribution.
The two locations can do a bilateral electricity trade through the installed Cross Border Transmission Link.
1. Building the excel-based structural input (set) files:¶
Considering that there are two locations in the Utopia region, three excel files are required:
Note: The name of the excel files must be determined as above. It is not possible to include arbitrary file names
1.1“global” excel file:¶
As it is described in the building model documentation, the structural input excels consists of several tables for different sets of the model. The first table in the global file is “Regions” including the locations of the study and the name of each location as below:
The second table is “Technologies_glob” which includes all the technologies within the Utopia regardless of the location. In this table, the technologies are coming with their names, categories, capacity units, and activity units as shown below. Please note that the technology categories must be chosen from Supply, Conversion, Conversion_plus, Transmission, and Storage categories and can not be anything different from the mentioned names.
After global technologies, global carriers must be indicated in the table “Carriers_glob”. In this table, all the carriers with their names, types and units must be included as below. The allowed carrier types are Resource, Intermediate, and Demand.
The next table to be specified is the “Emissions” table. In this table, the user must indicate all the emissions represented in the model with their names and units of measure. Currently, Hypatia allows to conisder only one type of emission in terms of CO2 or CO2-equivalent.
Ultimately, the time horizon and temporal resolution of the model must be determined by “Years” and “Timesteps” tables respectively.
Considering that in this case study, the temporal resolution is hourly (8760 hours within the year), we avoided bringing the full table in this tutorial. The “Timesteps” table must include the intra-year time slices, their names, and their length fraction compared to the whole year which is 1/8760 in this case.
1.2 “reg1” excel file:¶
The regional excel files consist of regional technologies, carriers, and the interconnections among them based on the Reference Energy System. The first table of regional files is named “Technologies” where the user must indicate all the technologies within the specific location (Utopia-north) as shown below:
The second table is named “Carriers” which is dedicated to determining all the carriers within the Utopia-north.
The connections among the technologies and carriers within the reference energy system are determined by “Carrier-input” and “Carrier_output” tables. In the former, the input carriers of the technologies, and in the latter, the output carriers of technologies are represented. Please note that the “Supply” technologies and “Demand” technologies should not be included in “Carrier-input” and “Carrier-output” tables respectively because the “Supply” category of technologies just provide energy carrier to the system without any conversion process and the “Demand” category just sinks and removes the demand energy carriers from the system.
Carrier Input
Carrier Output
There are a few important things to note about the structural input files:
Formulas tab of the ribbon > Name Manager > Edit > Name
2. Initializing the Hypatia model by reading the excel-based set files¶
After specifying all the sets of the model, it is time to initialize the Hypatia model and read the structural input files.
Importing the hypatia model¶
from hypatia import Model
Intializing the hypatia model by passing the optimization mode and the path of the structural input files (sets of the model)¶
utopia = Model(
path = 'sets',
mode = 'Operation'
)
3. Creating the excel-based parameter files¶
Now the model can create the parameter files with their default values through running the following commands.
After running this command line, we are going to open the created parameter files and fill them with the model data.
#utopia.create_data_excels(
# path = 'parameters'
#)
In this case, as we have a multi-node approach, it is expected to see the following files in the given path:
4. Filling the parameter files with the input data¶
Now it is time to insert the input data in their related parameter files.
4.1 Regional parameter files:¶
In this case study, we are focusing on the operational mode of the energy system. Therefore, the following sheets can be found in the excel files:
It should be noted that the data for the Utopia-south region can be inserted following the same instruction of Utopia-north parameter file. The data in “parameters_global.xlsx” are all based on the default values as no global scenarios are considered for this specific case study.
4.2. “parameters-connections” file:¶
The cross-border links have almost the same techno-economic parameters as the regional technologies including fixed and variable costs, residual capacity, capacity factor, efficiency, and annual production per each unit of capacity. In this case study, among all the possible connections for all the global carriers considered within Utopia, it is assumed that the northern and southern regions have only the bilateral trade of electricity. Therefore, the residual capacity of all the links for all the carriers except the electricity must be indicated equal to zero, and consequently, the user must be only concerned with the parameters that are related to this link and can leave the others with their default values. The capacity unit of the electricity cross-border link is based on MW in the case study.
5. Reading the input data¶
After filling out the parameter files, it is time to ask the model to read the input data following the below command line.
utopia.read_input_data(
path = 'parameters'
)
6. Running the model¶
Now we can run the model by giving the preferred solver, verbosity and the force_rewrite parameter which avoids overwriting the output results when it is equal to False and allows to overwrite them by taking a backuo from the previous results when it is equal to True.
utopia.run(
solver = 'scipy',
verbosity = True,
)
=============================================================================== CVXPY v1.1.17 =============================================================================== (CVXPY) Jan 30 02:06:34 PM: Your problem has 306600 variables, 61 constraints, and 0 parameters. (CVXPY) Jan 30 02:06:34 PM: It is compliant with the following grammars: DCP, DQCP (CVXPY) Jan 30 02:06:34 PM: (If you need to solve this problem multiple times, but with different data, consider using parameters.) (CVXPY) Jan 30 02:06:34 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution. ------------------------------------------------------------------------------- Compilation ------------------------------------------------------------------------------- (CVXPY) Jan 30 02:06:34 PM: Compiling problem (target solver=SCIPY). (CVXPY) Jan 30 02:06:34 PM: Reduction chain: Dcp2Cone -> CvxAttr2Constr -> ConeMatrixStuffing -> SCIPY (CVXPY) Jan 30 02:06:34 PM: Applying reduction Dcp2Cone (CVXPY) Jan 30 02:06:34 PM: Applying reduction CvxAttr2Constr (CVXPY) Jan 30 02:06:34 PM: Applying reduction ConeMatrixStuffing (CVXPY) Jan 30 02:06:35 PM: Applying reduction SCIPY (CVXPY) Jan 30 02:06:35 PM: Finished problem compilation (took 1.280e+00 seconds). ------------------------------------------------------------------------------- Numerical solver ------------------------------------------------------------------------------- (CVXPY) Jan 30 02:06:35 PM: Invoking solver SCIPY to obtain a solution.
/opt/anaconda3/envs/hypatia/lib/python3.8/site-packages/cvxpy/reductions/solvers/conic_solvers/scipy_conif.py:154: UserWarning: It is best to specify the 'method' parameter within scipy_options. The main advantage of this solver, is its ability to use the HiGHS LP solvers via scipy.optimize.linprog() which require a SciPy version >= 1.6.1 . The default method 'highs' will be used in this case.
Solver terminated with message: Optimization terminated successfully. ------------------------------------------------------------------------------- Summary ------------------------------------------------------------------------------- (CVXPY) Jan 30 02:06:36 PM: Problem status: optimal (CVXPY) Jan 30 02:06:36 PM: Optimal value: 3.175e+09 (CVXPY) Jan 30 02:06:36 PM: Compilation took 1.280e+00 seconds (CVXPY) Jan 30 02:06:36 PM: Solver (including time spent in interface) took 1.093e+00 seconds
7. Exporting the raw results to csv files¶
There is the possibility to export the raw results into the csv files by passing the arbitary folder path and force_rewrite parameter which avoids to overwrite the results when it is equal to False.
utopia.to_csv(path='results')
8. Visualizing the raw results¶
After solving the model, we can visualize the raw results by importing the plotting tool of the Hypatia model but before that, we need to ask the model to create the configuration excel file for indicating the desired information on technologies, fuels and regions.
# utopia.create_config_file(path=r'config.xlsx')
from hypatia import Plotter
Now, it is the time to initiallize the plotter class by passing the model's name, the created config file for the plots and the hourly resolution boolean parameter. The latter is True when the model has a hourly stepwise resolution and False when the timesteps are not in a hourly basis.
myplots = Plotter(utopia,config=r'config.xlsx',hourly_resolution= True)
# Sketching the hourly dispatch of the technologies for a given time horizom
myplots.plot_hourly_prod_by_tech(
path = r'plots/dispatch.html',
tech_group='Power Generation',
regions = ['reg1','reg2'],
year = 2021,
start="01-01 00:00:00",
end="01-03 23:00:00",
)
# Sketching the hourly dispatch of the technologies for the whole modelling period
myplots.plot_hourly_prod_by_tech(
path = r'plots/full_dispatch.html',
tech_group='Power Generation',
regions = ['reg1','reg2'],
year = 2021,
start="01-01 00:00:00",
end="12-29 23:00:00",
)
# Skething the prduction and consumption share of each technology including the imports and exports
myplots.plot_fuel_prod_cons(
path = r'plots/prod_con_share.html',
years = [2021],
fuel_group = "Electricity",
regions = ['reg1','reg2'],
trade=True,
)
# Sketching the annual CO2-equivalent emissions
myplots.plot_emissions(
path = r'plots/emissions.html',
regions = ['reg1','reg2'],
tech_group = 'Resource Extraction',
)