Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
congestionProbability.h
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21#ifndef __SOLVER_VARIABLE_ECONOMY_CongestionProbability_H__
22#define __SOLVER_VARIABLE_ECONOMY_CongestionProbability_H__
23
24#include <antares/study/area/constants.h>
25
26#include "../../variable.h"
27
28namespace Antares::Solver::Variable::Economy
29{
31{
33 static std::string Caption()
34 {
35 return "CONG. PROB. (+/-)";
36 }
37
39 static std::string Unit()
40 {
41 return "%";
42 }
43
45 static std::string Description()
46 {
47 return "Probability for the line to be congested in the upstream-downstream way";
48 }
49
51 typedef Results<R::AllYears::Raw< // The raw values throughout all years
52 >>
54
56 static constexpr uint8_t categoryDataLevel = Category::DataLevel::link;
58 static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
59 & (Category::FileLevel::va);
61 static constexpr uint8_t precision = Category::all;
63 static constexpr uint8_t nodeDepthForGUI = +0;
65 static constexpr uint8_t decimal = 2;
67 static constexpr int columnCount = 2;
69 static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
70 static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
71 static constexpr uint8_t spatialAggregatePostProcessing = 0;
73 static constexpr uint8_t hasIntermediateValues = 1;
75 static constexpr uint8_t isPossiblyNonApplicable = 0;
76
77 typedef IntermediateValues IntermediateValuesBaseType[columnCount];
78 typedef IntermediateValuesBaseType* IntermediateValuesType;
79
80 struct Multiple
81 {
82 static std::string Caption(uint indx)
83 {
84 switch (indx)
85 {
86 case 0:
87 return "CONG. PROB +";
88 case 1:
89 return "CONG. PROB -";
90 default:
91 return "<unknown>";
92 }
93 }
94
95 static std::string Unit([[maybe_unused]] const unsigned int indx)
96 {
98 }
99 };
100
101}; // class VCard
102
106template<class NextT = Container::EndOfList>
108 : public Variable::IVariable<CongestionProbability<NextT>, NextT, VCardCongestionProbability>
109{
110public:
112 typedef NextT NextType;
117
120
122
123 enum
124 {
126 count = 1 + NextT::count,
127 };
128
129 template<int CDataLevel, int CFile>
131 {
132 enum
133 {
134 count = ((VCardType::categoryDataLevel & CDataLevel
136 ? (NextType::template Statistics<CDataLevel, CFile>::count
138 : NextType::template Statistics<CDataLevel, CFile>::count),
139 };
140 };
141
142public:
144 {
145 delete[] pValuesForTheCurrentYear;
146 delete[] pValuesForYearLocalReport;
147 }
148
149 void initializeFromStudy(Data::Study& study)
150 {
151 pNbYearsParallel = study.maxNbYearsInParallel;
152
153 yearsWeight = study.parameters.getYearsWeight();
154 yearsWeightSum = study.parameters.getYearsWeightSum();
155
156 // Average on all years
157 for (uint i = 0; i != VCardType::columnCount; ++i)
158 {
159 AncestorType::pResults[i].initializeFromStudy(study);
160 AncestorType::pResults[i].reset();
161 }
162
163 pValuesForTheCurrentYear = new VCardType::IntermediateValuesBaseType[pNbYearsParallel];
164 for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; ++numSpace)
165 {
166 for (unsigned int i = 0; i != VCardType::columnCount; ++i)
167 {
168 pValuesForTheCurrentYear[numSpace][i].initializeFromStudy(study);
169 }
170 }
171
172 pValuesForYearLocalReport = new VCardType::IntermediateValuesBaseType[pNbYearsParallel];
173 for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; ++numSpace)
174 {
175 for (unsigned int i = 0; i != VCardType::columnCount; ++i)
176 {
177 pValuesForYearLocalReport[numSpace][i].initializeFromStudy(study);
178 }
179 }
180
181 // Next
182 NextType::initializeFromStudy(study);
183 }
184
185 void initializeFromArea(Data::Study* study, Data::Area* area)
186 {
187 // Next
188 NextType::initializeFromArea(study, area);
189 }
190
191 void initializeFromAreaLink(Data::Study* study, Data::AreaLink* link)
192 {
193 // Next
194 NextType::initializeFromAreaLink(study, link);
195 }
196
197 void simulationBegin()
198 {
199 for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; ++numSpace)
200 {
201 pValuesForTheCurrentYear[numSpace][0].reset();
202 pValuesForTheCurrentYear[numSpace][1].reset();
203 }
204
205 // Next
206 NextType::simulationBegin();
207 }
208
209 void simulationEnd()
210 {
211 // Next variable
212 NextType::simulationEnd();
213 }
214
215 void yearBegin(uint year, unsigned int numSpace)
216 {
217 // Reset
218 pValuesForTheCurrentYear[numSpace][0].reset();
219 pValuesForTheCurrentYear[numSpace][1].reset();
220
221 pValuesForYearLocalReport[numSpace][0].reset();
222 pValuesForYearLocalReport[numSpace][1].reset();
223
224 // Next variable
225 NextType::yearBegin(year, numSpace);
226 }
227
228 void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
229 {
230 // Next variable
231 NextType::yearEndBuild(state, year, numSpace);
232 }
233
234 void yearEnd(uint year, uint numSpace)
235 {
236 for (uint i = 0; i != VCardType::columnCount; ++i)
237 {
238 // Compute all statistics for the current year (daily,weekly,monthly)
239 pValuesForTheCurrentYear[numSpace][i].computeProbabilitiesForTheCurrentYear();
240 }
241
242 // Next variable
243 NextType::yearEnd(year, numSpace);
244 }
245
246 void computeSummary(std::map<unsigned int, unsigned int>& numSpaceToYear,
247 unsigned int nbYearsForCurrentSummary)
248 {
249 for (unsigned int numSpace = 0; numSpace < nbYearsForCurrentSummary; ++numSpace)
250 {
251 for (uint i = 0; i != VCardType::columnCount; ++i)
252 {
253 // Merge all those values with the global results
254 AncestorType::pResults[i].merge(numSpaceToYear[numSpace],
255 pValuesForTheCurrentYear[numSpace][i]);
256 }
257 }
258
259 // Next variable
260 NextType::computeSummary(numSpaceToYear, nbYearsForCurrentSummary);
261 }
262
263 void hourBegin(uint hourInTheYear)
264 {
265 // Next variable
266 NextType::hourBegin(hourInTheYear);
267 }
268
269 void hourForEachArea(State& state, unsigned int numSpace)
270 {
271 // Next variable
272 NextType::hourForEachArea(state, numSpace);
273 }
274
275 void hourForEachLink(State& state, unsigned int numSpace)
276 {
277 // Ratio take into account MC year weight
278 float ratio = yearsWeight[state.year] / yearsWeightSum;
279
280 assert(state.link != NULL);
281 const auto& linkDirectCapa = state.link->directCapacities;
282 const auto& linkIndirectCapa = state.link->indirectCapacities;
283 // CONG. PROB +
284 if (state.ntc.ValeurDuFlux[state.link->index]
285 > +linkDirectCapa.getCoefficient(state.year, state.hourInTheYear) - 10e-6)
286 {
287 pValuesForTheCurrentYear[numSpace][0].hour[state.hourInTheYear] += 100.0 * ratio;
288 }
289 // CONG. PROB -
290 if (state.ntc.ValeurDuFlux[state.link->index]
291 < -linkIndirectCapa.getCoefficient(state.year, state.hourInTheYear) + 10e-6)
292 {
293 pValuesForTheCurrentYear[numSpace][1].hour[state.hourInTheYear] += 100.0 * ratio;
294 }
295
296 // Next item in the list
297 NextType::hourForEachLink(state, numSpace);
298 }
299
300 void beforeYearByYearExport(uint /*year*/, uint numSpace)
301 {
302 for (uint i = 0; i != VCardType::columnCount; ++i)
303 {
304 for (uint h = 0; h != HOURS_PER_YEAR; ++h)
305 {
306 pValuesForYearLocalReport[numSpace][i].hour[h] = (pValuesForTheCurrentYear[numSpace]
307 [i]
308 .hour[h]
309 > 0.)
310 ? 100.
311 : 0.;
312 }
313
314 for (uint d = 0; d != DAYS_PER_YEAR; ++d)
315 {
316 pValuesForYearLocalReport[numSpace][i].day[d] = (pValuesForTheCurrentYear[numSpace]
317 [i]
318 .day[d]
319 > 0.)
320 ? 100.
321 : 0.;
322 }
323
324 for (uint w = 0; w != WEEKS_PER_YEAR; ++w)
325 {
326 pValuesForYearLocalReport[numSpace][i].week[w] = (pValuesForTheCurrentYear[numSpace]
327 [i]
328 .week[w]
329 > 0.)
330 ? 100.
331 : 0.;
332 }
333
334 for (uint m = 0; m != MONTHS_PER_YEAR; ++m)
335 {
336 pValuesForYearLocalReport[numSpace][i].month[m] = (pValuesForTheCurrentYear
337 [numSpace][i]
338 .month[m]
339 > 0.)
340 ? 100.
341 : 0.;
342 }
343
344 pValuesForYearLocalReport[numSpace][i].year = (pValuesForTheCurrentYear[numSpace][i]
345 .year
346 > 0.)
347 ? 100.
348 : 0.;
349 }
350 }
351
352 Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
353 uint column,
354 uint numSpace) const
355 {
356 return pValuesForTheCurrentYear[numSpace][column].hour;
357 }
358
359 void localBuildAnnualSurveyReport(SurveyResults& results,
360 int fileLevel,
361 int precision,
362 uint numSpace) const
363 {
364 // The current variable is actually a multiple-variable.
365 results.isCurrentVarNA = AncestorType::isNonApplicable;
366
367 for (uint i = 0; i != VCardType::columnCount; ++i)
368 {
369 if (AncestorType::isPrinted[i])
370 {
371 // Write the data for the current year
372 results.variableCaption = VCardType::Multiple::Caption(i);
373 results.variableUnit = VCardType::Multiple::Unit(i);
374 pValuesForYearLocalReport[numSpace][i]
375 .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
376 }
377 results.isCurrentVarNA++;
378 }
379 }
380
381private:
382 std::vector<float> yearsWeight;
383 float yearsWeightSum;
385 typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
386 typename VCardType::IntermediateValuesType pValuesForYearLocalReport;
387 unsigned int pNbYearsParallel;
388
389}; // class CongestionProbability
390
391} // namespace Antares::Solver::Variable::Economy
392
393#endif // __SOLVER_VARIABLE_ECONOMY_CongestionProbability_H__
Definition for a single area.
Definition area.h:52
Definition study.h:61
Marginal CongestionProbability.
Definition congestionProbability.h:109
Variable::IVariable< CongestionProbability< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition congestionProbability.h:116
VCardCongestionProbability VCardType
VCard.
Definition congestionProbability.h:114
@ count
How many items have we got.
Definition congestionProbability.h:126
VCardType::ResultsType ResultsType
List of expected results.
Definition congestionProbability.h:119
NextT NextType
Type of the next static variable.
Definition congestionProbability.h:112
Interface for any variable.
Definition variable.h:51
StoredResultType pResults
All the results about this variable.
Definition variable.h:327
Temporary buffer for allocating results for a single year.
Definition intermediate.h:46
Definition results.h:48
@ count
The count if item in the list.
Definition results.h:56
Definition cbuilder.h:120
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition congestionProbability.h:73
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition congestionProbability.h:75
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition congestionProbability.h:67
Results< R::AllYears::Raw< > > ResultsType
The expecte results.
Definition congestionProbability.h:53
static constexpr uint8_t decimal
Decimal precision.
Definition congestionProbability.h:65
static constexpr uint8_t categoryDataLevel
Data Level.
Definition congestionProbability.h:56
static std::string Description()
The short description of the variable.
Definition congestionProbability.h:45
static std::string Caption()
Caption.
Definition congestionProbability.h:33
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition congestionProbability.h:69
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition congestionProbability.h:63
static std::string Unit()
Unit.
Definition congestionProbability.h:39
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition congestionProbability.h:58
static constexpr uint8_t precision
Precision (views)
Definition congestionProbability.h:61