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.
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
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, their name, and categories 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 and types must be included as below. The allowed carrier types are Resource, Intermediate, and Demand.
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.
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.
There are a few important things to note about the structural input files:
Formulas tab of the ribbon > Name Manager > Edit > Name
After specifying all the sets of the model, it is time to initialize the Hypatia model and read the structural input files.
from hypatia import Model
utopia = Model(
path = 'sets',
mode = 'Operation'
)
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:
Now it is time to insert the input data in their related 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.
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.
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'
)
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) Dec 06 01:35:55 PM: Your problem has 306600 variables, 61 constraints, and 0 parameters. (CVXPY) Dec 06 01:35:55 PM: It is compliant with the following grammars: DCP, DQCP (CVXPY) Dec 06 01:35:55 PM: (If you need to solve this problem multiple times, but with different data, consider using parameters.) (CVXPY) Dec 06 01:35:55 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution. ------------------------------------------------------------------------------- Compilation ------------------------------------------------------------------------------- (CVXPY) Dec 06 01:35:55 PM: Compiling problem (target solver=SCIPY). (CVXPY) Dec 06 01:35:55 PM: Reduction chain: Dcp2Cone -> CvxAttr2Constr -> ConeMatrixStuffing -> SCIPY (CVXPY) Dec 06 01:35:55 PM: Applying reduction Dcp2Cone (CVXPY) Dec 06 01:35:55 PM: Applying reduction CvxAttr2Constr (CVXPY) Dec 06 01:35:55 PM: Applying reduction ConeMatrixStuffing (CVXPY) Dec 06 01:35:56 PM: Applying reduction SCIPY (CVXPY) Dec 06 01:35:57 PM: Finished problem compilation (took 1.153e+00 seconds). ------------------------------------------------------------------------------- Numerical solver ------------------------------------------------------------------------------- (CVXPY) Dec 06 01:35:57 PM: Invoking solver SCIPY to obtain a solution.
/opt/anaconda3/envs/hypatia_suite/lib/python3.8/site-packages/cvxpy-1.1.17-py3.8-macosx-10.9-x86_64.egg/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) Dec 06 01:35:58 PM: Problem status: optimal (CVXPY) Dec 06 01:35:58 PM: Optimal value: 3.175e+09 (CVXPY) Dec 06 01:35:58 PM: Compilation took 1.153e+00 seconds (CVXPY) Dec 06 01:35:58 PM: Solver (including time spent in interface) took 1.038e+00 seconds
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')
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',
)