3b_inputsLoop.gms 6.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ontext
This file is part of Backbone.

Backbone 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.

Backbone 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 Backbone.  If not, see <http://www.gnu.org/licenses/>.
$offtext
17

18
* =============================================================================
19
* --- Update the Forecast Data ------------------------------------------------
20
* =============================================================================
21

22
23
put log 'ord tSolve: ';
put log ord(tSolve) /;
24
putclose log;
25

26
27
28
29
30
31
32
33
loop(mTimeseries_loop_read(mSolve, timeseries)${ord(tSolve) >= tForecastNext(mSolve)},
    put_utility 'gdxin' / 'input\' timeseries.tl:0 '\' tSolve.tl:0 '.gdx';
    if (mTimeseries_loop_read(mSolve, 'ts_unit'), execute_load ts_unit);
    if (mTimeseries_loop_read(mSolve, 'ts_effUnit'), execute_load ts_effUnit);
    if (mTimeseries_loop_read(mSolve, 'ts_effGroupUnit'), execute_load ts_effGroupUnit);
    if (mTimeseries_loop_read(mSolve, 'ts_influx'), execute_load ts_influx);
    if (mTimeseries_loop_read(mSolve, 'ts_cf'), execute_load ts_cf);
    if (mTimeseries_loop_read(mSolve, 'ts_reserveDemand'), execute_load ts_reserveDemand);
34
    if (mTimeseries_loop_read(mSolve, 'ts_node'), execute_load ts_node);
35
36
37
38
39
    if (mTimeseries_loop_read(mSolve, 'ts_fuelPriceChange'), execute_load ts_fuelPriceChange);
    if (mTimeseries_loop_read(mSolve, 'ts_unavailability'), execute_load ts_unavailability);
);

if (ord(tSolve) >= tForecastNext(mSolve),
40
    // Update the next forecast
41
    tForecastNext(mSolve)
42
        = tForecastNext(mSolve) + mSettings(mSolve, 't_forecastJump');
43
);
44

45
$ontext
46
47
48
    // Define t_latestForecast
    Option clear = t_latestForecast;
    t_latestForecast(tSolve) = yes;
49
50

    // Define updated time window
51
    Option clear = tt_forecast;
52
    tt_forecast(t_full(t))${    ord(t) >= ord(tSolve)
53
                                and ord(t) <= ord(tSolve) + mSettings(mSolve, 't_forecastLengthUnchanging') + mSettings(mSolve, 't_forecastJump')
54
                                }
55
        = yes;
56

57
58
59
    // Define temporary time displacement to reach t_latestForecast
    Option clear = ddt;
    ddt(tt_forecast(t)) = ord(tSolve) - ord(t);
60

61
62
* --- Update Forecast Data ----------------------------------------------------

63
64
65
66
    ts_cf(flowNode(flow, node), f_solve(f), tt_forecast(t))${   ts_forecast(flow, node, t+ddt(t), f, t) // Only update data for capacity factors with forecast. NOTE! This results in problems if the forecast has values of zero!
                                                                and mf(mSolve, f)
                                                                }
        = ts_forecast(flow, node, t+ddt(t), f, t);
67
68

* --- Read the Tertiary Reserve Requirements ----------------------------------
69
70
71

    put_utility 'gdxin' / 'input\tertiary\' tSolve.tl:0 '.gdx';
    execute_load ts_tertiary;
Topi Rasku's avatar
Topi Rasku committed
72
73
74
75
    ts_reserveDemand(restypeDirectionNode('tertiary', up_down, node), f_solve(f), tt_forecast(t))${ mf(mSolve, f)
                                                                                                    and not mf_realization(mSolve, f)
                                                                                                    and flowNode('wind', node)
                                                                                                    }
76
77
        = ts_tertiary('wind', node, t+ddt(t), up_down, t)
            * sum(flowUnit('wind', unit), p_gnu('elec', node, unit, 'maxGen'));
78

79
$offtext
80

81
82

* --- Improve forecasts -------------------------------------------------------
83
$ontext
84
// !!! TEMPORARY MEASURES !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
85

86
87
if(mSettings(mSolve, 'forecasts') > 0,

88
89
90
91
92
93
94
    // Define updated time window
    Option clear = tt_forecast;
    tt_forecast(t_full(t))${    ord(t) >= ord(tSolve)
                                and ord(t) <= ord(tSolve) + mSettings(mSolve, 't_forecastLengthUnchanging') + mSettings(mSolve, 't_forecastJump')
                                }
        = yes;

95
    // Define updated time window
96
    Option clear = tt;
Topi Rasku's avatar
Topi Rasku committed
97
    tt(tt_forecast(t))${    ord(t) > ord(tSolve)
98
99
                            and ord(t) <= ord(tSolve) + f_improve
                            }
100
        = yes;
101

102
103
104
105
106
107
108
109
110
111
    // Temporary forecast displacement to reach the central forecast
    Option clear = ddf;
    ddf(f_solve(f), tt(t))${ not mf_central(mSolve, f) }
        = sum(mf_central(mSolve, f_), ord(f_) - ord(f));

    // Temporary forecast displacement to reach the realized forecast
    Option clear = ddf_;
    ddf_(f_solve(f), tt(t))${ not mf_realization(mSolve, f) }
        = sum(mf_realization(mSolve, f_), ord(f_) - ord(f));

112
    // Calculate the upper and lower forecasts based on the original central forecast
113
114
115
116
117
    ts_cf(flowNode(flow, node), f_solve(f), tt(t))${    not mf_realization(mSolve, f)
                                                        and not mf_central(mSolve, f)
                                                        }
                = ts_cf(flow, node, f, t) - ts_cf(flow, node, f+ddf(f,t), t);

118
    // Improve forecasts during the dispatch
119
120
    // Improve central capacity factors, linear improvement towards fRealization
    ts_cf(flowNode(flow, node), f_solve(f), tt(t))${    not mf_realization(mSolve, f)
121
                                                        and mf_central(mSolve, f)
122
                                                        }
123
124
125
126
        = (
            (ord(t) - ord(tSolve)) * ts_cf(flow, node, f, t)
            + (f_improve + ord(tSolve) - ord(t)) * ts_cf(flow, node, f+ddf_(f,t), t)
            )
127
                / f_improve;
128
129
130
131
132
133
134

    // Update the upper and lower forecasts based on the improved central forecast
    ts_cf(flowNode(flow, node), f_solve(f), tt(t))${    not mf_realization(mSolve, f)
                                                        and not mf_central(mSolve, f)
                                                        }
        = min(max( ts_cf(flow, node, f, t) + ts_cf(flow, node, f+ddf(f,t), t), 0),1);

135
); // END IF forecasts
136
$offtext