Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
spatial-aggregate.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_SPATIAL_AGGREGATE_H__
22#define __SOLVER_VARIABLE_ECONOMY_SPATIAL_AGGREGATE_H__
23
24#include "antares/solver/variable/variable.h"
25
26// #include <antares/logs/logs.h> // In case it is needed
27
28namespace Antares
29{
30namespace Solver
31{
32namespace Variable
33{
34namespace Common
35{
36template<int ColumnCountT, class VCardT>
38{
39 static std::string Caption(const uint indx)
40 {
41 return VCardT::Multiple::Caption(indx);
42 }
43
44 static std::string Unit(const unsigned int indx)
45 {
46 return VCardT::Multiple::Unit(indx);
47 }
48};
49
50template<class VCardT>
51struct MultipleCaptionProxy<0, VCardT>
52{
53 static std::string Caption(const uint)
54 {
55 return "";
56 }
57
58 static std::string Unit(const uint)
59 {
60 return "";
61 }
62};
63
64template<class VCardT>
65struct MultipleCaptionProxy<1, VCardT>
66{
67 static std::string Caption(const uint)
68 {
69 return "";
70 }
71
72 static std::string Unit(const uint)
73 {
74 return "";
75 }
76};
77
78template<class VCardT>
79struct MultipleCaptionProxy<Category::dynamicColumns, VCardT>
80{
81 static std::string Caption(const uint)
82 {
83 return "";
84 }
85
86 static std::string Unit(const uint)
87 {
88 return "";
89 }
90};
91
92template<template<class> class V>
94{
96 typedef typename V<Container::EndOfList>::VCardType VCardOrigin;
97
99 static std::string Caption()
100 {
101 return VCardOrigin::Caption();
102 }
103
105 static std::string Unit()
106 {
107 return VCardOrigin::Unit();
108 }
109
111 static std::string Description()
112 {
113 return VCardOrigin::Description();
114 }
115
117 typedef typename VCardOrigin::ResultsType ResultsType;
119 typedef typename VCardOrigin::VCardForSpatialAggregate VCardForSpatialAggregate;
120
121 typedef typename VCardOrigin::IntermediateValuesType IntermediateValuesType;
122 typedef typename VCardOrigin::IntermediateValuesBaseType IntermediateValuesBaseType;
123 typedef
124 typename VCardOrigin::IntermediateValuesTypeForSpatialAg IntermediateValuesTypeForSpatialAg;
125
127 static constexpr uint8_t categoryDataLevel = Category::DataLevel::setOfAreas;
129 static constexpr uint8_t categoryFileLevel = VCardOrigin::categoryFileLevel;
131 static constexpr uint8_t precision = VCardOrigin::precision;
133 static constexpr uint8_t nodeDepthForGUI = +0;
135 static constexpr uint8_t decimal = VCardOrigin::decimal;
137 static constexpr int columnCount = VCardOrigin::columnCount;
139 static constexpr uint8_t spatialAggregate = Category::noSpatialAggregate;
140 static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
141 static constexpr uint8_t spatialAggregatePostProcessing = 0;
142
144 static constexpr uint8_t hasIntermediateValues = 1;
146 static constexpr uint8_t isPossiblyNonApplicable = VCardOrigin::isPossiblyNonApplicable;
147
148 struct Multiple
149 {
150 static std::string Caption(const uint indx)
151 {
153 }
154
155 static std::string Unit(const unsigned int indx)
156 {
158 }
159 };
160
161}; // class VCard
162
163template<template<class> class VarT, class NextT = Container::EndOfList>
165 : public Variable::IVariable<SpatialAggregate<VarT, NextT>, NextT, VCardProxy<VarT>>
166{
167public:
169 typedef NextT NextType;
170
175
178
180
181 enum
182 {
184 count = 1 + NextT::count,
185 };
186
187 template<int CDataLevel, int CFile>
189 {
190 enum
191 {
192 count = ((VCardType::categoryDataLevel & CDataLevel
194 ? (NextType::template Statistics<CDataLevel, CFile>::count
195 + VCardType::columnCount * ResultsType::count)
196 : NextType::template Statistics<CDataLevel, CFile>::count),
197 };
198 };
199
200public:
201 void initializeFromStudy(Data::Study& study)
202 {
203 typedef
204 typename VCardType::VCardOrigin::IntermediateValuesBaseType IntermediateValuesBaseType;
205 pNbYearsParallel = study.maxNbYearsInParallel;
206
207 // Intermediate values
208 VarT<Container::EndOfList>::InitializeResultsFromStudy(AncestorType::pResults, study);
209 pValuesForTheCurrentYear = new IntermediateValuesBaseType[pNbYearsParallel];
210 for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
211 {
212 VariableAccessorType::InitializeAndReset(pValuesForTheCurrentYear[numSpace], study);
213 }
214
215 auto& limits = study.runtime.rangeLimits;
216
217 pRatioYear = 100. / (double)limits.year[Data::rangeCount];
218 pRatioDay = 100. / (double)limits.day[Data::rangeCount];
219 pRatioMonth = 100. / (double)limits.month[Data::rangeCount];
220 pRatioWeek = 100. / (double)limits.week[Data::rangeCount];
221
222 // Next
223 NextType::initializeFromStudy(study);
224 }
225
226 void initializeFromArea(Data::Study* study, Data::Area* area)
227 {
228 // Next
229 NextType::initializeFromArea(study, area);
230 }
231
232 void initializeFromLink(Data::Study* study, Data::AreaLink* link)
233 {
234 // Next
235 NextType::initializeFromAreaLink(study, link);
236 }
237
238 void simulationBegin()
239 {
240 // Next
241 NextType::simulationBegin();
242 }
243
244 void simulationEnd()
245 {
246 NextType::simulationEnd();
247 }
248
249 void yearBegin(uint year)
250 {
251 // Next variable
252 NextType::yearBegin(year);
253 }
254
255 void yearEndBuildPrepareDataForEachThermalCluster(State& state, uint year)
256 {
257 // Next variable
258 NextType::yearEndBuildPrepareDataForEachThermalCluster(state, year);
259 }
260
261 void yearEndBuildForEachThermalCluster(State& state, uint year)
262 {
263 // Next variable
264 NextType::yearEndBuildForEachThermalCluster(state, year);
265 }
266
267 void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
268 {
269 // Next variable
270 NextType::yearEndBuild(state, year, numSpace);
271 }
272
273 void yearEnd(uint year)
274 {
275 // Next variable
276 NextType::yearEnd(year);
277 }
278
279 void weekBegin(State& state)
280 {
281 // Next variable
282 NextType::weekBegin(state);
283 }
284
285 void weekEnd(State& state)
286 {
287 // Next variable
288 NextType::weekEnd(state);
289 }
290
291 void hourBegin(uint hourInTheYear)
292 {
293 // Next variable
294 NextType::hourBegin(hourInTheYear);
295 }
296
297 void hourForEachArea(State& state, unsigned int numSpace)
298 {
299 // Next variable
300 NextType::hourForEachArea(state, numSpace);
301 }
302
303 template<class V, class SetT>
304 void yearEndSpatialAggregates(V& allVars, uint year, const SetT& set, uint numSpace)
305 {
306 if (VCardType::VCardOrigin::spatialAggregateMode & Category::spatialAggregateEachYear)
307 {
308 internalSpatialAggregateForCurrentYear(allVars, set, numSpace);
309 }
310
311 // Next variable
312 NextType::yearEndSpatialAggregates(allVars, year, set, numSpace);
313 }
314
315 template<class V>
316 void computeSpatialAggregatesSummary(V& allVars,
317 std::map<unsigned int, unsigned int>& numSpaceToYear,
318 uint nbYearsForCurrentSummary)
319 {
320 if (VCardType::VCardOrigin::spatialAggregateMode & Category::spatialAggregateEachYear)
321 {
322 internalSpatialAggregateForParallelYears(numSpaceToYear, nbYearsForCurrentSummary);
323 }
324
325 // Next variable
326 NextType::computeSpatialAggregatesSummary(allVars,
327 numSpaceToYear,
328 nbYearsForCurrentSummary);
329 }
330
331 template<class V, class SetT>
332 void simulationEndSpatialAggregates(V& allVars, const SetT& set)
333 {
334 if (VCardType::VCardOrigin::spatialAggregateMode & Category::spatialAggregateOnce)
335 {
336 internalSpatialAggregate(allVars, 0, set);
337 }
338
339 // Next variable
340 NextType::simulationEndSpatialAggregates(allVars, set);
341 }
342
343 inline void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
344 {
345 // Generate the Digest for the local results (districts part)
347 && (VCardType::categoryDataLevel & Category::DataLevel::setOfAreas))
348 {
349 // Initializing pointer on variable non applicable and print stati arrays to beginning
350 results.isPrinted = AncestorType::isPrinted;
351 results.isCurrentVarNA = AncestorType::isNonApplicable;
352
353 VariableAccessorType::template BuildDigest<typename VCardType::VCardOrigin>(
354 results,
356 digestLevel,
357 dataLevel);
358 }
359 // Ask to build the digest to the next variable
360 NextType::buildDigest(results, digestLevel, dataLevel);
361 }
362
363 void localBuildAnnualSurveyReport(SurveyResults& results,
364 int fileLevel,
365 int precision,
366 uint numSpace) const
367 {
369 && (VCardType::categoryDataLevel & Category::DataLevel::setOfAreas))
370 {
371 // Initializing pointer on variable non applicable and print stati arrays to beginning
372 results.isPrinted = AncestorType::isPrinted;
373 results.isCurrentVarNA = AncestorType::isNonApplicable;
374
375 typedef VariableAccessor<typename VCardType::IntermediateValuesBaseType,
377 VAType;
378 VAType::template BuildAnnualSurveyReport<typename VCardType::VCardOrigin>(
379 results,
380 pValuesForTheCurrentYear[numSpace],
381 fileLevel,
382 precision);
383 }
384 }
385
386private:
387 template<class V, class SetT>
388 void internalSpatialAggregate(V& allVars, uint year, const SetT& set)
389 {
390 typedef typename VCardType::VCardOrigin VCardOrigin;
391 // Reset the results
392 VariableAccessorType::Reset(pValuesForTheCurrentYear[0]);
393
394 // Make the spatial cluster
395 if (!set.empty())
396 {
397 auto end = set.end();
398 for (auto i = set.begin(); i != end; ++i)
399 {
400 allVars.template computeSpatialAggregateWith<
401 typename VCardType::VCardForSpatialAggregate> //<typename VCardType::VCardOrigin>
402 (pValuesForTheCurrentYear[0], *i /* the current area */, 0);
403 }
404
405 // The spatial cluster may be an average
406 if (VCardType::VCardOrigin::spatialAggregate & Category::spatialAggregateAverage)
407 {
408 VariableAccessorType::MultiplyHourlyResultsBy(pValuesForTheCurrentYear[0],
409 1. / set.size());
410 }
411 // The spatial cluster may be an average
413 & Category::spatialAggregateSumThen1IfPositive)
414 {
415 VariableAccessorType::SetTo1IfPositive(pValuesForTheCurrentYear[0]);
416 }
417 if (VCardType::VCardOrigin::spatialAggregate & Category::spatialAggregateOr)
418 {
419 VariableAccessorType::Or(pValuesForTheCurrentYear[0]);
420 }
421 }
422 else
423 {
424 assert(!set.empty() && "The set should not be empty at this point");
425 }
426
427 // Compute all statistics for the current year (daily,weekly,monthly,...)
428 VariableAccessorType::template ComputeStatistics<VCardOrigin>(pValuesForTheCurrentYear[0]);
429 VariableAccessorType::ComputeSummary(pValuesForTheCurrentYear[0],
431 year);
432 }
433
434 template<class V, class SetT>
435 void internalSpatialAggregateForCurrentYear(V& allVars, const SetT& set, uint numSpace)
436 {
437 typedef typename VCardType::VCardOrigin VCardOrigin;
438 // Reset the results
439 VariableAccessorType::Reset(pValuesForTheCurrentYear[numSpace]);
440
441 // Make the spatial cluster
442 if (!set.empty())
443 {
444 auto end = set.end();
445 for (auto i = set.begin(); i != end; ++i)
446 {
447 allVars.template computeSpatialAggregateWith<
448 typename VCardType::VCardForSpatialAggregate> //<typename VCardType::VCardOrigin>
449 (pValuesForTheCurrentYear[numSpace], *i /* the current area */, numSpace);
450 }
451
452 // The spatial cluster may be an average
453 if (VCardType::VCardOrigin::spatialAggregate & Category::spatialAggregateAverage)
454 {
455 VariableAccessorType::MultiplyHourlyResultsBy(pValuesForTheCurrentYear[numSpace],
456 1. / set.size());
457 }
458 // The spatial cluster may be an average
460 & Category::spatialAggregateSumThen1IfPositive)
461 {
462 VariableAccessorType::SetTo1IfPositive(pValuesForTheCurrentYear[numSpace]);
463 }
464 if (VCardType::VCardOrigin::spatialAggregate & Category::spatialAggregateOr)
465 {
466 VariableAccessorType::Or(pValuesForTheCurrentYear[numSpace]);
467 }
468 }
469 else
470 {
471 assert(!set.empty() && "The set should not be empty at this point");
472 }
473
474 // Compute all statistics for the current year (daily,weekly,monthly,...)
475 VariableAccessorType::template ComputeStatistics<VCardOrigin>(
476 pValuesForTheCurrentYear[numSpace]);
477 }
478
479 void internalSpatialAggregateForParallelYears(
480 std::map<unsigned int, unsigned int>& numSpaceToYear,
481 uint nbYearsForCurrentSummary)
482 {
483 for (unsigned int numSpace = 0; numSpace < nbYearsForCurrentSummary; ++numSpace)
484 {
485 // Merge all those values with the global results
486 VariableAccessorType::ComputeSummary(pValuesForTheCurrentYear[numSpace],
488 numSpaceToYear[numSpace]);
489 }
490 }
491
492private:
494 typename VCardType::IntermediateValuesTypeForSpatialAg pValuesForTheCurrentYear;
495
496 double pRatioYear;
497 double pRatioDay;
498 double pRatioMonth;
499 double pRatioWeek;
500 unsigned int pNbYearsParallel;
501
502}; // class SpatialAggregate
503
504} // namespace Common
505} // namespace Variable
506} // namespace Solver
507} // namespace Antares
508
509#endif // __SOLVER_VARIABLE_ECONOMY_SPATIAL_AGGREGATE_H__
Definition for a single area.
Definition area.h:52
Definition study.h:61
Definition spatial-aggregate.h:166
VCardProxy< VarT > VCardType
VCard.
Definition spatial-aggregate.h:172
@ count
How many items have we got.
Definition spatial-aggregate.h:184
NextT NextType
Type of the next static variable.
Definition spatial-aggregate.h:169
VCardType::ResultsType ResultsType
List of expected results.
Definition spatial-aggregate.h:177
Variable::IVariable< SpatialAggregate< VarT, NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition spatial-aggregate.h:174
Interface for any variable.
Definition variable.h:51
StoredResultType pResults
All the results about this variable.
Definition variable.h:327
Definition cbuilder.h:120
Definition variable.h:25
Definition spatial-aggregate.h:94
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition spatial-aggregate.h:139
V< Container::EndOfList >::VCardType VCardOrigin
The real VCard for the variable.
Definition spatial-aggregate.h:96
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition spatial-aggregate.h:129
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition spatial-aggregate.h:146
static constexpr uint8_t decimal
Decimal precision.
Definition spatial-aggregate.h:135
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition spatial-aggregate.h:137
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition spatial-aggregate.h:133
static constexpr uint8_t precision
Precision (views)
Definition spatial-aggregate.h:131
static std::string Caption()
Caption.
Definition spatial-aggregate.h:99
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition spatial-aggregate.h:144
VCardOrigin::ResultsType ResultsType
The expecte results.
Definition spatial-aggregate.h:117
static std::string Unit()
Unit.
Definition spatial-aggregate.h:105
static constexpr uint8_t categoryDataLevel
Data Level.
Definition spatial-aggregate.h:127
static std::string Description()
The short description of the variable.
Definition spatial-aggregate.h:111
VCardOrigin::VCardForSpatialAggregate VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition spatial-aggregate.h:119