Backbone.gms 8.2 KB
Newer Older
1
2
3
$title Backbone
$ontext
Backbone - chronological energy systems model
4
Copyright (C) 2016 - 2019  VTT Technical Research Centre of Finland
5
6
7
8
9
10
11
12
13
14
15
16
17
18

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Juha Kiviluoma's avatar
Juha Kiviluoma committed
19
==========================================================================
20
Created by:
Juha Kiviluoma's avatar
Juha Kiviluoma committed
21
22
23
    Juha Kiviluoma
    Erkka Rinne
    Topi Rasku
24
    Niina Helist
Niina Helistö's avatar
Niina Helistö committed
25
26
27
    Dana Kirchem
    Ran Li
    Ciara O'Dwyer
28

29
30
31
This is a GAMS implementation of the Backbone energy system modelling framework
[1]. Features include:
- Based on Stochastic Model Predictive Control method [2].
32
33
- Time steps (t) can vary in length.
- Short term forecast stochasticity (f) and longer term statistical uncertainty (s).
34
35
36


GAMS command line arguments
37

38
39
40
41
42
--debug=[0|1|2]
    Set level of debugging information. Default is 0 when no extra information is
    saved or displayded. At level 1, file 'debug.gdx' containing all GAMS symbols
    is written at the end of execution. At level 2, debug information is written
    for each solve separately.
43

44
45
46
47
--diag=[yes|no]
    Switch on/off diagnostics. Writes some additional diagnostic results in
    'results.gdx' about data updates and efficiency approximations.

48
49
50
51
--dummy=[yes|no]
    Do not solve the model, just do preliminary calculations.
    For testing purposes.

52
53
54
--penalty=<value>
    Changes the value of the penalty cost. Default penalty value is 1e9
    if not provided.
55

56
57
58
--input_dir=<path>
    Directory to read input from. Defaults to './input'.

59
60
--input_file_gdx=<filename.gdx>
    Filename of the GDX input file. Defaults to 'inputData.gdx'.
61
62
    --input_file_gdx=<path> including the filename also works (when used with
    input_file_excel, the file is always stored in input_dir).
63

64
65
66
67
68
69
70
71
72
73
74
--input_file_excel=<filename>
    Filename of the Excel input file. If this filename is given, the GDX input
    file is generated from this file using Gdxxrw.

--input_excel_index=<spreadsheet name>
    Used with input_file_excel: the spreadsheet where the options and symbols
    are read. Defaults to 'INDEX'.

--input_excel_checkdate=checkDate
    Used with input_file_excel: write GDX file only if the input file is more
    recent than the GDX file. Disabled by default.
75

76
77
78
--output_dir=<path>
    Directory to write output to. Defaults to './output'.

79
80
--output_file=<filename.gdx>
    Filename of the results file. Defaults to 'results.gdx'
81

82

83
84
References
----------
85
86
87
88
[1] N. Helist et al., Backbone---An Adaptable Energy Systems Modelling Framework,
    Energies, vol. 12, no. 17, p. 3388, Sep. 2019. Available at:
    https://dx.doi.org/10.3390/en12173388.
[2] K. Nolde, M. Uhr, and M. Morari, Medium term scheduling of a hydro-thermal
89
90
91
    system using stochastic model predictive control,  Automatica, vol. 44,
    no. 6, pp. 15851594, Jun. 2008.

92
==========================================================================
93
94
$offtext

Erkka Rinne's avatar
Erkka Rinne committed
95
96
97
* Check current GAMS version
$ife %system.gamsversion%<240 $abort GAMS distribution 24.0 or later required!

98
99
100
* Set default debugging level
$if not set debug $setglobal debug 0

101
102
103
* Default values for input and output dir as well as input data GDX file and index sheet when importing data from Excel file
* When reading an Excel file, you can opt to read the file only if the Gdxxrw detects changes by using 'checkDate' for
*   input_excel_checkdate. It is off by default, since there has been some problems with it.
104
105
$if not set input_dir $setglobal input_dir 'input'
$if not set output_dir $setglobal output_dir 'output'
106
$if not set input_file_gdx $setglobal input_file_gdx 'inputData.gdx'
107
$if not set input_excel_index $setglobal input_excel_index 'INDEX'
108
$if not set input_excel_checkdate $setglobal input_excel_checkdate ''
109
110
111

* Make sure output dir exists
$if not dexist %output_dir% $call 'mkdir %output_dir%'
112

113
114
115
* Activate end of line comments and set comment character to '//'
$oneolcom
$eolcom //
116
$onempty   // Allow empty data definitions
117

118
* Output file streams
Erkka Rinne's avatar
Erkka Rinne committed
119
Files log /''/, gdx /''/, f_info /'%output_dir%/info.txt'/;
120

121
122
123
124
125
* Include options file to control the solver (if it does not exist, uses defaults)
$ifthen exist '%input_dir%/1_options.gms'
    $$include '%input_dir%/1_options.gms';
$endif

126
127
* === Libraries ===============================================================
$libinclude scenred2
128

129
* === Definitions, sets, parameters and input data=============================
Erkka Rinne's avatar
Erkka Rinne committed
130
131
132
133
134
$include 'inc/1a_definitions.gms'   // Definitions for possible model settings
$include 'inc/1b_sets.gms'          // Set definitions used by the models
$include 'inc/1c_parameters.gms'    // Parameter definitions used by the models
$include 'inc/1d_results.gms'       // Parameter definitions for model results
$include 'inc/1e_inputs.gms'        // Load input data
135

136
* === Variables and equations =================================================
Erkka Rinne's avatar
Erkka Rinne committed
137
138
139
140
$include 'inc/2a_variables.gms'                         // Define variables for the models
$include 'inc/2b_eqDeclarations.gms'                    // Equation declarations
$ifthen exist '%input_dir%/2c_alternative_objective.gms'      // Objective function - either the default or an alternative from input files
    $$include '%input_dir%/2c_alternative_objective.gms';
141
$else
Erkka Rinne's avatar
Erkka Rinne committed
142
    $$include 'inc/2c_objective.gms'
143
$endif
Erkka Rinne's avatar
Erkka Rinne committed
144
$include 'inc/2d_constraints.gms'                       // Define constraint equations for the models
145
146
$ifthen exist '%input_dir%/2e_additional_constraints.gms'
   $$include '%input_dir%/2e_additional_constraints.gms'      // Define additional constraints from the input data
147
148
$endif

149

150
* === Model definition files ==================================================
Erkka Rinne's avatar
Erkka Rinne committed
151
152
153
$include 'defModels/schedule.gms'
$include 'defModels/building.gms'
$include 'defModels/invest.gms'
154
155

// Load model input parameters
Erkka Rinne's avatar
Erkka Rinne committed
156
$include '%input_dir%/modelsInit.gms'
157

158

159
* === Simulation ==============================================================
160
161
162
163
164
165
// Macro for checking solve status (1 = normal completion)
$macro checkSolveStatus(mdl) \
    if(mdl.solveStat > 1 and (mdl.modelStat <> 1 or mdl.modelStat <> 8), \
        execError = execError + 1 \
    )

Erkka Rinne's avatar
Erkka Rinne committed
166
$include 'inc/3a_periodicInit.gms'  // Initialize modelling loop
167
loop(modelSolves(mSolve, tSolve)$(execError = 0),
168
    solveCount = solveCount + 1;
169
170
    $$include 'inc/3b_periodicLoop.gms'         // Update modelling loop
    $$include 'inc/3c_inputsLoop.gms'           // Read input data that is updated within the loop
Erkka Rinne's avatar
Erkka Rinne committed
171
    $$include 'inc/3d_setVariableLimits.gms'    // Set new variable limits (.lo and .up)
172
$iftheni.dummy not %dummy% == 'yes'
Erkka Rinne's avatar
Erkka Rinne committed
173
174
175
    $$include 'inc/3e_solve.gms'                // Solve model(s)
    $$include 'inc/3f_afterSolve.gms'           // Post-processing variables after the solve
    $$include 'inc/4a_outputVariant.gms'        // Store results from the loop
176
$endif.dummy
177
$ifthene.debug %debug%>1
178
        putclose gdx;
Erkka Rinne's avatar
Erkka Rinne committed
179
        put_utility 'gdxout' / '%output_dir%/' mSolve.tl:0 '-' tSolve.tl:0 '.gdx';
180
            execute_unload
Erkka Rinne's avatar
Erkka Rinne committed
181
            $$include defOutput/debugSymbols.inc
182
        ;
Topi Rasku's avatar
Topi Rasku committed
183
$endif.debug
184
185
);

Erkka Rinne's avatar
Erkka Rinne committed
186
$if exist '%input_dir%/3z_modelsClose.gms' $include '%input_dir%/3z_modelsClose.gms';
187

188
* === Output ==================================================================
189
190
$echon "'version' " > 'version'
$call 'git describe --dirty=+ --always >> version'
191
$ifi not %dummy% == 'yes'
Erkka Rinne's avatar
Erkka Rinne committed
192
193
$include 'inc/4b_outputInvariant.gms'
$include 'inc/4c_outputQuickFile.gms'
194
195

* Post-process results
Erkka Rinne's avatar
Erkka Rinne committed
196
$if exist '%input_dir%/4d_postProcess.gms' $include '%input_dir%/4d_postProcess.gms'
197

198
199
200
$if not set output_file $setglobal output_file 'results.gdx'

execute_unload '%output_dir%/%output_file%',
Erkka Rinne's avatar
Erkka Rinne committed
201
    $$include 'defOutput/resultSymbols.inc'
202
203
;

204
$ife %debug%>0
Erkka Rinne's avatar
Erkka Rinne committed
205
execute_unload '%output_dir%/debug.gdx';
Erkka Rinne's avatar
Erkka Rinne committed
206
207
208
209
if(execError,
   putclose log "!!! Errors encountered: " execError:0:0/;
   abort "FAILED";
);
210
* === THE END =================================================================