Backbone.gms 6.46 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
59
60
61
--input_dir=<path>
    Directory to read input from. Defaults to './input'.

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

62
63
64

References
----------
65
66
67
68
[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
69
70
71
    system using stochastic model predictive control,  Automatica, vol. 44,
    no. 6, pp. 15851594, Jun. 2008.

72
==========================================================================
73
74
$offtext

75
76
77
* Set default debugging level
$if not set debug $setglobal debug 0

78
79
80
81
82
83
* Default values for input and output dir
$if not set input_dir $setglobal input_dir 'input'
$if not set output_dir $setglobal output_dir 'output'

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

85
86
87
* Activate end of line comments and set comment character to '//'
$oneolcom
$eolcom //
88
$onempty   // Allow empty data definitions
89

90
* Output file streams
Erkka Rinne's avatar
Erkka Rinne committed
91
files log /''/, gdx, f_info /'%output_dir%/info.txt'/;
92

93
* Include options file to control the solver
Erkka Rinne's avatar
Erkka Rinne committed
94
$include '%input_dir%/1_options.gms';
95

96
97
* === Libraries ===============================================================
$libinclude scenred2
98

99
* === Definitions, sets, parameters and input data=============================
Erkka Rinne's avatar
Erkka Rinne committed
100
101
102
103
104
$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
105

106
* === Variables and equations =================================================
Erkka Rinne's avatar
Erkka Rinne committed
107
108
109
110
$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';
111
$else
Erkka Rinne's avatar
Erkka Rinne committed
112
    $$include 'inc/2c_objective.gms'
113
$endif
Erkka Rinne's avatar
Erkka Rinne committed
114
$include 'inc/2d_constraints.gms'                       // Define constraint equations for the models
115
116
$ifthen exist '%input_dir%/2e_additional_constraints.gms'
   $$include '%input_dir%/2e_additional_constraints.gms'      // Define additional constraints from the input data
117
118
$endif

119

120
* === Model definition files ==================================================
Erkka Rinne's avatar
Erkka Rinne committed
121
122
123
$include 'defModels/schedule.gms'
$include 'defModels/building.gms'
$include 'defModels/invest.gms'
124
125

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

128

129
* === Simulation ==============================================================
Erkka Rinne's avatar
Erkka Rinne committed
130
$include 'inc/3a_periodicInit.gms'  // Initialize modelling loop
131
loop(modelSolves(mSolve, tSolve)$(execError = 0),
132
    solveCount = solveCount + 1;
133
134
    $$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
135
    $$include 'inc/3d_setVariableLimits.gms'    // Set new variable limits (.lo and .up)
136
$iftheni.dummy not %dummy% == 'yes'
Erkka Rinne's avatar
Erkka Rinne committed
137
138
139
    $$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
140
$endif.dummy
141
$ifthene.debug %debug%>1
142
        putclose gdx;
Erkka Rinne's avatar
Erkka Rinne committed
143
        put_utility 'gdxout' / '%output_dir%/' mSolve.tl:0 '-' tSolve.tl:0 '.gdx';
144
            execute_unload
Erkka Rinne's avatar
Erkka Rinne committed
145
            $$include defOutput/debugSymbols.inc
146
        ;
Topi Rasku's avatar
Topi Rasku committed
147
$endif.debug
148
149
);

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

152
* === Output ==================================================================
153
154
$echon "'version' " > 'version'
$call 'git describe --dirty=+ --always >> version'
155
$ifi not %dummy% == 'yes'
Erkka Rinne's avatar
Erkka Rinne committed
156
157
$include 'inc/4b_outputInvariant.gms'
$include 'inc/4c_outputQuickFile.gms'
158
159

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

Erkka Rinne's avatar
Erkka Rinne committed
162
163
execute_unload '%output_dir%/results.gdx',
    $$include 'defOutput/resultSymbols.inc'
164
165
;

166
$ife %debug%>0
Erkka Rinne's avatar
Erkka Rinne committed
167
execute_unload '%output_dir%/debug.gdx';
Erkka Rinne's avatar
Erkka Rinne committed
168
169
170
171
if(execError,
   putclose log "!!! Errors encountered: " execError:0:0/;
   abort "FAILED";
);
172
* === THE END =================================================================