Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
area.hxx
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_AREA_HXX__
22#define __SOLVER_VARIABLE_AREA_HXX__
23
24#include <antares/study/filter.h>
25#include "antares/solver/variable/economy/dispatchable-generation-margin.h"
26
27namespace Antares
28{
29namespace Solver
30{
31namespace Variable
32{
33template<class NextT>
35{
36 // Do nothing
37}
38
39template<class NextT>
41{
42 // Nothing to do here
43 // This method is called by initializeFromStudy() to all children
44}
45
46template<class NextT>
47inline void Areas<NextT>::initializeFromAreaLink(Data::Study*, Data::AreaLink*)
48{
49 // Nothing to do here
50}
51
52template<class NextT>
53inline void Areas<NextT>::initializeFromThermalCluster(Data::Study*,
56{
57 // This method should not be called at this point
58}
59
60template<class NextT>
61void Areas<NextT>::buildSurveyReport(SurveyResults& results,
62 int dataLevel,
63 int fileLevel,
64 int precision) const
65{
66 int count_int = count;
67 bool linkDataLevel = dataLevel & Category::DataLevel::link;
68 bool areaDataLevel = dataLevel & Category::DataLevel::area;
69 bool thermalAggregateDataLevel = dataLevel & Category::DataLevel::thermalAggregate;
70 if (count_int && (linkDataLevel || areaDataLevel || thermalAggregateDataLevel))
71 {
72 assert(results.data.area != NULL
73 && "The area must not be null to generate a survey report");
74
75 // Build the survey results for the given area
76 auto& area = *results.data.area;
77
78 // Filtering
79 if (0 == (dataLevel & Category::DataLevel::link)) // filter on all but links
80 {
81 switch (precision)
82 {
83 case Category::hourly:
84 if (not(area.filterSynthesis & Data::filterHourly))
85 {
86 return;
87 }
88 break;
89 case Category::daily:
90 if (not(area.filterSynthesis & Data::filterDaily))
91 {
92 return;
93 }
94 break;
95 case Category::weekly:
96 if (not(area.filterSynthesis & Data::filterWeekly))
97 {
98 return;
99 }
100 break;
101 case Category::monthly:
102 if (not(area.filterSynthesis & Data::filterMonthly))
103 {
104 return;
105 }
106 break;
107 case Category::annual:
108 if (not(area.filterSynthesis & Data::filterAnnual))
109 {
110 return;
111 }
112 break;
113 case Category::all:
114 break;
115 }
116 }
117 pAreas[area.index].buildSurveyReport(results, dataLevel, fileLevel, precision);
118 }
119}
120
121template<class NextT>
122void Areas<NextT>::buildAnnualSurveyReport(SurveyResults& results,
123 int dataLevel,
124 int fileLevel,
125 int precision,
126 uint numSpace) const
127{
128 int count_int = count;
129 bool linkDataLevel = dataLevel & Category::DataLevel::link;
130 bool areaDataLevel = dataLevel & Category::DataLevel::area;
131 bool thermalAggregateDataLevel = dataLevel & Category::DataLevel::thermalAggregate;
132 if (count_int && (linkDataLevel || areaDataLevel || thermalAggregateDataLevel))
133 {
134 assert(results.data.area != NULL
135 && "The area must not be null to generate a survey report");
136
137 auto& area = *results.data.area;
138
139 // Filtering
140 if (0 == (dataLevel & Category::DataLevel::link)) // filter on all but links
141 {
142 switch (precision)
143 {
144 case Category::hourly:
145 if (!(area.filterYearByYear & Data::filterHourly))
146 {
147 return;
148 }
149 break;
150 case Category::daily:
151 if (!(area.filterYearByYear & Data::filterDaily))
152 {
153 return;
154 }
155 break;
156 case Category::weekly:
157 if (!(area.filterYearByYear & Data::filterWeekly))
158 {
159 return;
160 }
161 break;
162 case Category::monthly:
163 if (!(area.filterYearByYear & Data::filterMonthly))
164 {
165 return;
166 }
167 break;
168 case Category::annual:
169 if (!(area.filterYearByYear & Data::filterAnnual))
170 {
171 return;
172 }
173 break;
174 case Category::all:
175 break;
176 }
177 }
178
179 // Build the survey results for the given area
180 pAreas[area.index].buildAnnualSurveyReport(results,
181 dataLevel,
182 fileLevel,
183 precision,
184 numSpace);
185 }
186}
187
188template<class NextT>
189void Areas<NextT>::buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
190{
191 int count_int = count;
192 if (count_int)
193 {
194 if (dataLevel & Category::DataLevel::area)
195 {
196 assert(pAreaCount == results.data.study.areas.size());
197
198 // Reset captions
199 results.data.rowCaptions.clear();
200 results.data.rowCaptions.resize(pAreaCount);
201
202 // For each area
203 // for (uint i = 0; i != results.data.study.areas.byIndex.size(); ++i)
204 for (uint i = 0; i != pAreaCount; ++i)
205 {
206 results.data.area = results.data.study.areas[i];
207 uint index = results.data.area->index;
208 results.data.rowIndex = index;
209 results.data.rowCaptions[index] = results.data.area->id;
210 results.data.columnIndex = 0;
211 results.resetValuesAtLine(i);
212 pAreas[i].buildDigest(results, digestLevel, dataLevel);
213 }
214 }
215 }
216}
217
218template<class NextT>
219template<class PredicateT>
220inline void Areas<NextT>::RetrieveVariableList(PredicateT& predicate)
221{
222 NextType::RetrieveVariableList(predicate);
223}
224
225template<class NextT>
226template<class I>
227inline void Areas<NextT>::provideInformations(I& infos)
228{
229 // Begining of the node
230 if (VCardType::nodeDepthForGUI)
231 {
232 infos.template beginNode<VCardType>();
233 // Next variable in the list
234 NextType::template provideInformations<I>(infos);
235 // End of the node
236 infos.endNode();
237 }
238 else
239 {
240 // Giving our VCard
241 infos.template addVCard<VCardType>();
242 // Next variable in the list
243 NextType::template provideInformations<I>(infos);
244 }
245}
246
247template<class NextT>
248template<class SearchVCardT, class O>
249inline void Areas<NextT>::computeSpatialAggregateWith(O&)
250{
251 // Do nothing
252}
253
254template<class NextT>
255template<class SearchVCardT, class O>
256inline void Areas<NextT>::computeSpatialAggregateWith(O& out, const Data::Area* area, uint numSpace)
257{
258 assert(NULL != area);
259 pAreas[area->index].template computeSpatialAggregateWith<SearchVCardT, O>(out, numSpace);
260}
261
262template<class NextT>
263template<class VCardToFindT>
264const double* Areas<NextT>::retrieveHourlyResultsForCurrentYear() const
265{
266 return nullptr;
267}
268
269template<class NextT>
270template<class VCardToFindT>
271inline void Areas<NextT>::retrieveResultsForArea(
272 typename Storage<VCardToFindT>::ResultsType** result,
273 const Data::Area* area)
274{
275 pAreas[area->index].template retrieveResultsForArea<VCardToFindT>(result, area);
276}
277
278template<class NextT>
279template<class VCardToFindT>
280inline void Areas<NextT>::retrieveResultsForThermalCluster(
281 typename Storage<VCardToFindT>::ResultsType** result,
282 const Data::ThermalCluster* cluster)
283{
284 pAreas[cluster->parentArea->index]
285 .template retrieveResultsForThermalCluster<VCardToFindT>(result, cluster);
286}
287
288template<class NextT>
289template<class VCardToFindT>
290inline void Areas<NextT>::retrieveResultsForLink(
291 typename Storage<VCardToFindT>::ResultsType** result,
292 const Data::AreaLink* link)
293{
294 pAreas[link->from->index].template retrieveResultsForLink<VCardToFindT>(result, link);
295}
296
297template<class NextT>
299{
300 // Releasing the memory occupied by the areas
301 delete[] pAreas;
302}
303
304template<class NextT>
306{
307 // The total number of areas
308 pAreaCount = study.areas.size();
309
310 // Reserving the memory
311 pAreas = new NextType[pAreaCount];
312
313 // For each area...
314 uint tick = 6;
315 uint oldPercent = 0;
316 for (uint i = 0; i != pAreaCount; ++i)
317 {
318 // Instancing a new set of variables of the area
319 auto* currentArea = study.areas.byIndex[i];
320 if (!(--tick))
321 {
322 uint newPercent = ((i * 100u) / pAreaCount);
323 if (newPercent != oldPercent)
324 {
325 logs.info() << "Allocating resources " << ((i * 100u) / pAreaCount) << "%";
326 oldPercent = newPercent;
327 }
328 // Reset the tick
329 tick = 6;
330 }
331
332 // Initialize the variables
333 // From the study
334 pAreas[i].initializeFromStudy(study);
335 // From the area
336 pAreas[i].initializeFromArea(&study, currentArea);
337 // Does current output variable appears non applicable in areas' output files, not
338 // districts'. Note that digest gather area and district results.
339 pAreas[i].broadcastNonApplicability(not currentArea->hydro.reservoirManagement);
340
341 // For each current area's variable, getting the print status, that is :
342 // is variable's column(s) printed in output (areas) reports ?
343 pAreas[i].getPrintStatusFromStudy(study);
344
345 pAreas[i].supplyMaxNumberOfColumns(study);
346 }
347}
348
349template<class NextT>
350void Areas<NextT>::simulationBegin()
351{
352 for (uint i = 0; i != pAreaCount; ++i)
353 {
354 pAreas[i].simulationBegin();
355 }
356}
357
358template<class NextT>
359void Areas<NextT>::simulationEnd()
360{
361 for (uint i = 0; i != pAreaCount; ++i)
362 {
363 pAreas[i].simulationEnd();
364 }
365}
366
367template<class NextT>
368void Areas<NextT>::hourForEachArea(State& state, uint numSpace)
369{
370 // For each area...
371 state.study.areas.each(
372 [this, &state, &numSpace](Data::Area& area)
373 {
374 state.area = &area; // the current area
375
376 // Initializing the state for the current area
377 state.initFromAreaIndex(area.index, numSpace);
378
379 for (const auto& cluster: area.thermal.list.each_enabled())
380 {
381 // Intiializing the state for the current thermal cluster
382 state.initFromThermalClusterIndex(cluster->enabledIndex);
383 }
384
385 // Variables
386 auto& variablesForArea = pAreas[area.index];
387 variablesForArea.hourForEachArea(state, numSpace);
388
389 // All links
390 auto end = area.links.end();
391 for (auto i = area.links.begin(); i != end; ++i)
392 {
393 state.link = i->second;
394 // Variables
395 variablesForArea.hourForEachLink(state, numSpace);
396 }
397 }); // for each area
398}
399
400template<class NextT>
401void Areas<NextT>::weekForEachArea(State& state, uint numSpace)
402{
403 // For each area...
404 state.study.areas.each(
405 [this, &state, &numSpace](Data::Area& area)
406 {
407 state.area = &area; // the current area
408
409 // Initializing the state for the current area
410 state.initFromAreaIndex(area.index, numSpace);
411
412 auto& variablesForArea = pAreas[area.index];
413
414 // DTG MRG
415 state.dispatchableMargin = variablesForArea.template retrieveHourlyResultsForCurrentYear<
416 Economy::VCardDispatchableGenMargin>(numSpace);
417
418 variablesForArea.weekForEachArea(state, numSpace);
419
420 // NOTE
421 // currently, the event is not broadcasted to thermal
422 // clusters and links
423 }); // for each area
424}
425
426template<class NextT>
427void Areas<NextT>::yearBegin(uint year, uint numSpace)
428{
429 for (uint i = 0; i != pAreaCount; ++i)
430 {
431 pAreas[i].yearBegin(year, numSpace);
432 }
433}
434
435template<class NextT>
436void Areas<NextT>::yearEndBuild(State& state, uint year, uint numSpace)
437{
438 // For each area...
439 state.study.areas.each(
440 [this, &state, &year, &numSpace](Data::Area& area)
441 {
442 state.area = &area; // the current area
443
444 // Initializing the state for the current area
445 state.initFromAreaIndex(area.index, numSpace);
446
447 // Variables
448 auto& variablesForArea = pAreas[area.index];
449
450 for (const auto& cluster: area.thermal.list.each_enabled())
451 {
452 state.thermalCluster = cluster.get();
453 state.yearEndResetThermal();
454
455 // Variables
456 variablesForArea.yearEndBuildPrepareDataForEachThermalCluster(state, year, numSpace);
457
458 // Building the end of year
459 state.yearEndBuildFromThermalClusterIndex(cluster->enabledIndex);
460
461 // Variables
462 variablesForArea.yearEndBuildForEachThermalCluster(state, year, numSpace);
463 } // for each thermal cluster
464 }); // for each area
465}
466
467template<class NextT>
468void Areas<NextT>::yearEnd(uint year, uint numSpace)
469{
470 for (uint i = 0; i != pAreaCount; ++i)
471 {
472 // Broadcast to all areas
473 pAreas[i].yearEnd(year, numSpace);
474 }
475}
476
477template<class NextT>
478void Areas<NextT>::computeSummary(std::map<unsigned int, unsigned int>& numSpaceToYear,
479 unsigned int nbYearsForCurrentSummary)
480{
481 for (uint i = 0; i != pAreaCount; ++i)
482 {
483 // Broadcast to all areas
484 pAreas[i].computeSummary(numSpaceToYear, nbYearsForCurrentSummary);
485 }
486}
487
488template<class NextT>
489void Areas<NextT>::weekBegin(State& state)
490{
491 for (uint i = 0; i != pAreaCount; ++i)
492 {
493 pAreas[i].weekBegin(state);
494 }
495}
496
497template<class NextT>
498void Areas<NextT>::weekEnd(State& state)
499{
500 for (uint i = 0; i != pAreaCount; ++i)
501 {
502 pAreas[i].weekEnd(state);
503 }
504}
505
506template<class NextT>
507void Areas<NextT>::hourBegin(uint hourInTheYear)
508{
509 for (uint i = 0; i != pAreaCount; ++i)
510 {
511 pAreas[i].hourBegin(hourInTheYear);
512 }
513}
514
515template<class NextT>
516void Areas<NextT>::hourForEachLink(State& state, uint numSpace)
517{
518 for (uint i = 0; i != pAreaCount; ++i)
519 {
520 pAreas[i].hourForEachLink(state, numSpace);
521 }
522}
523
524template<class NextT>
525void Areas<NextT>::hourEnd(State& state, uint hourInTheYear)
526{
527 for (uint i = 0; i != pAreaCount; ++i)
528 {
529 pAreas[i].hourEnd(state, hourInTheYear);
530 }
531}
532
533template<class NextT>
534void Areas<NextT>::beforeYearByYearExport(uint year, uint numSpace)
535{
536 for (uint i = 0; i != pAreaCount; ++i)
537 {
538 pAreas[i].beforeYearByYearExport(year, numSpace);
539 }
540}
541} // namespace Variable
542} // namespace Solver
543} // namespace Antares
544
545#endif // __SOLVER_VARIABLE_AREA_HXX__
Definition for a single area.
Definition area.h:52
uint index
Index of the area - only valid when already added to an area list.
Definition area.h:217
Area * parentArea
The associate area (alias)
Definition cluster.h:114
Definition study.h:61
A single thermal cluster.
Definition cluster.h:78
Areas()
Default Constructor.
Definition area.hxx:34
static void RetrieveVariableList(PredicateT &predicate)
Retrieve the list of all individual variables.
Definition area.hxx:220
~Areas()
Destructor.
Definition area.hxx:298
Definition cbuilder.h:120
Definition variable.h:25
VariableAccessor< typenameVCardT::ResultsType, VCardT::columnCount >::Type ResultsType
The true type used for the results.
Definition info.h:764