Antares Simulator
Power System Simulator
setofareas.hxx
1 /*
2  * Copyright 2007-2025, 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_SET_OF_AREAS_HXX__
22 #define __SOLVER_VARIABLE_SET_OF_AREAS_HXX__
23 
24 namespace Antares::Solver::Variable
25 {
26 template<class NextT>
27 void SetsOfAreas<NextT>::initializeFromStudy(Data::Study& study)
28 {
29  using namespace Antares;
30 
31  // The study
32  pStudy = &study;
33  // alias to the set of sets of areas
34  auto& sets = study.setsOfAreas;
35  // Reserving the memory
36  pSetsOfAreas.reserve(sets.size());
37  pOriginalSets.reserve(sets.size());
38 
39  // For each set...
40  for (uint setIndex = 0; setIndex != sets.size(); ++setIndex)
41  {
42  if (!sets.hasOutput(setIndex))
43  {
44  continue;
45  }
46  // Name of the set
47  const auto& setname = sets.caption(setIndex);
48 
49  // Useless if the result set is empty
50  if (!sets.resultSize(setIndex))
51  {
52  logs.warning() << "The set of areas named '" << setname
53  << "' is empty. No output will be produced for this set.";
54  continue;
55  }
56 
57  auto n = std::make_unique<NextT>();
58 
59  // Initialize the variables
60  // From the study
61  n->initializeFromStudy(study);
62 
63  // Making specific variables non applicable in following output reports :
64  // - annual district reports
65  // - over all years district statistics reports
66  n->broadcastNonApplicability(true);
67 
68  // For each current set's variable, getting the print status, that is :
69  // is variable's column(s) printed in output (set of areas) reports ?
70  n->getPrintStatusFromStudy(study);
71 
72  pSetsOfAreas.push_back(std::move(n));
73 
74  auto* originalSet = &sets[setIndex];
75  assert(originalSet != NULL);
76  assert(!originalSet->empty());
77  pOriginalSets.push_back(originalSet);
78 
79  pNames.push_back(setname);
80  }
81 }
82 
83 template<class NextT>
84 inline void SetsOfAreas<NextT>::initializeFromArea(Data::Study*, Data::Area*)
85 {
86  // Nothing to do here
87 }
88 
89 template<class NextT>
90 inline void SetsOfAreas<NextT>::initializeFromAreaLink(Data::Study*, Data::AreaLink*)
91 {
92  // Nothing to do here
93 }
94 
95 template<class NextT>
96 inline void SetsOfAreas<NextT>::initializeFromThermalCluster(Data::Study*,
97  Data::Area*,
99 {
100  // This method should not be called at this stage
101 }
102 
103 template<class NextT>
104 inline void SetsOfAreas<NextT>::simulationBegin()
105 {
106  // Nothing to do here
107 }
108 
109 template<class NextT>
110 inline void SetsOfAreas<NextT>::simulationEnd()
111 {
112  // Nothing to do here
113 }
114 
115 template<class NextT>
116 inline void SetsOfAreas<NextT>::yearBegin(uint /*year*/, uint /* numSpace */)
117 {
118  // Nothing to do here
119 }
120 
121 template<class NextT>
122 inline void SetsOfAreas<NextT>::yearEndBuild(State& /*state*/, uint /*year*/, uint /*numSpace*/)
123 {
124  // Nothing to do here
125 }
126 
127 template<class NextT>
128 inline void SetsOfAreas<NextT>::yearEnd(uint /*year*/, uint /*numSpace*/)
129 {
130  // Nothing to do here
131 }
132 
133 template<class NextT>
134 inline void SetsOfAreas<NextT>::computeSummary(unsigned int /* year */, unsigned int /* numSpace */)
135 {
136  // Nothing to do here
137 }
138 
139 template<class NextT>
140 inline void SetsOfAreas<NextT>::hourBegin(uint /*hourInTheYear*/)
141 {
142  // Nothing to do here
143 }
144 
145 template<class NextT>
146 inline void SetsOfAreas<NextT>::weekBegin(State&)
147 {
148  // Nothing to do here
149 }
150 
151 template<class NextT>
152 inline void SetsOfAreas<NextT>::weekForEachArea(State&, unsigned int /*numSpace*/)
153 {
154  // Nothing to do here
155 }
156 
157 template<class NextT>
158 inline void SetsOfAreas<NextT>::weekEnd(State&)
159 {
160  // Nothing to do here
161 }
162 
163 template<class NextT>
164 void SetsOfAreas<NextT>::hourForEachArea(State& state, unsigned int)
165 {
166  (void)state;
167 }
168 
169 template<class NextT>
170 inline void SetsOfAreas<NextT>::hourForEachLink(State& state)
171 {
172  (void)state;
173 }
174 
175 template<class NextT>
176 inline void SetsOfAreas<NextT>::hourEnd(State& state, uint hourInTheYear)
177 {
178  (void)state;
179  (void)hourInTheYear;
180 }
181 
182 template<class NextT>
183 inline void SetsOfAreas<NextT>::buildSurveyReport(SurveyResults& results,
184  int dataLevel,
185  int fileLevel,
186  int precision) const
187 {
188  int count_int = count;
189  bool setOfAreasDataLevel = dataLevel & Category::DataLevel::setOfAreas;
190  if (count_int && setOfAreasDataLevel)
191  {
192  pSetsOfAreas[results.data.setOfAreasIndex]->buildSurveyReport(results,
193  dataLevel,
194  fileLevel,
195  precision);
196  }
197 }
198 
199 template<class NextT>
200 inline void SetsOfAreas<NextT>::buildAnnualSurveyReport(SurveyResults& results,
201  int dataLevel,
202  int fileLevel,
203  int precision,
204  uint numSpace) const
205 {
206  int count_int = count;
207  bool setOfAreasDataLevel = dataLevel & Category::DataLevel::setOfAreas;
208  if (count_int && setOfAreasDataLevel)
209  {
210  pSetsOfAreas[results.data.setOfAreasIndex]->buildAnnualSurveyReport(results,
211  dataLevel,
212  fileLevel,
213  precision,
214  numSpace);
215  }
216 }
217 
218 template<class NextT>
219 void SetsOfAreas<NextT>::buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
220 {
221  int count_int = count;
222  bool setOfAreasDataLevel = dataLevel & Category::DataLevel::setOfAreas;
223  if (count_int && setOfAreasDataLevel)
224  {
225  // Reset
226  results.data.rowCaptions.clear();
227  results.data.rowCaptions.resize(pSetsOfAreas.size());
228  results.data.area = nullptr;
229  results.data.rowIndex = 0;
230 
231  for (auto& set: pSetsOfAreas)
232  {
233  results.data.columnIndex = 0;
234  results.data.rowCaptions[results.data.rowIndex].clear()
235  << "@ " << pNames[results.data.rowIndex];
236  set->buildDigest(results, digestLevel, dataLevel);
237  ++results.data.rowIndex;
238  }
239  }
240 }
241 
242 template<class NextT>
243 template<class I>
244 inline void SetsOfAreas<NextT>::provideInformations(I& infos)
245 {
246  // Begining of the node
247  if (VCardType::nodeDepthForGUI)
248  {
249  infos.template beginNode<VCardType>();
250  // Next variable in the list
251  NextType::template provideInformations<I>(infos);
252  // End of the node
253  infos.endNode();
254  }
255  else
256  {
257  // Giving our VCard
258  infos.template addVCard<VCardType>();
259  // Next variable in the list
260  NextType::template provideInformations<I>(infos);
261  }
262 }
263 
264 template<class NextT>
265 template<class V>
266 void SetsOfAreas<NextT>::yearEndSpatialAggregates(V& allVars, uint year, uint numSpace)
267 {
268  for (uint setindex = 0; setindex != pSetsOfAreas.size(); ++setindex)
269  {
270  assert(setindex < pOriginalSets.size());
271  pSetsOfAreas[setindex]->yearEndSpatialAggregates(allVars,
272  year,
273  *(pOriginalSets[setindex]),
274  numSpace);
275  }
276 }
277 
278 template<class NextT>
279 template<class V>
280 void SetsOfAreas<NextT>::computeSpatialAggregatesSummary(V& allVars,
281  unsigned int year,
282  unsigned int numSpace)
283 {
284  for (uint setindex = 0; setindex != pSetsOfAreas.size(); ++setindex)
285  {
286  assert(setindex < pOriginalSets.size());
287  pSetsOfAreas[setindex]->computeSpatialAggregatesSummary(allVars, year, numSpace);
288  }
289 }
290 
291 template<class NextT>
292 template<class V>
293 void SetsOfAreas<NextT>::simulationEndSpatialAggregates(V& allVars)
294 {
295  for (uint i = 0; i != pSetsOfAreas.size(); ++i)
296  {
297  pSetsOfAreas[i]->simulationEndSpatialAggregates(allVars, *(pOriginalSets[i]));
298  }
299 }
300 
301 template<class NextT>
302 void SetsOfAreas<NextT>::beforeYearByYearExport(uint year, uint numSpace)
303 {
304  for (uint i = 0; i != pSetsOfAreas.size(); ++i)
305  {
306  pSetsOfAreas[i]->beforeYearByYearExport(year, numSpace);
307  }
308 }
309 
310 template<class NextT>
311 template<class SearchVCardT, class O>
312 inline void SetsOfAreas<NextT>::computeSpatialAggregateWith(O&)
313 {
314  // Do nothing
315 }
316 
317 template<class NextT>
318 template<class SearchVCardT, class O>
319 inline void SetsOfAreas<NextT>::computeSpatialAggregateWith(O& out,
320  const Data::Area* area,
321  uint numSpace)
322 {
323  (void)out;
324  (void)area;
325  (void)numSpace;
326  // pSetsOfAreas[area->index]->computeSpatialAggregateWith<SearchVCardT,O>(out);
327 }
328 
329 template<class NextT>
330 template<class VCardToFindT>
331 inline const double* SetsOfAreas<NextT>::retrieveHourlyResultsForCurrentYear() const
332 {
333  return nullptr;
334 }
335 
336 template<class NextT>
337 template<class VCardToFindT>
338 inline void SetsOfAreas<NextT>::retrieveResultsForArea(
339  typename Storage<VCardToFindT>::ResultsType** result,
340  const Data::Area* area)
341 {
342  (void)result;
343  (void)area;
344 }
345 
346 template<class NextT>
347 template<class VCardToFindT>
348 inline void SetsOfAreas<NextT>::retrieveResultsForThermalCluster(
349  typename Storage<VCardToFindT>::ResultsType** result,
350  const Data::ThermalCluster* cluster)
351 {
352  (void)result;
353  (void)cluster;
354 }
355 
356 template<class NextT>
357 template<class VCardToFindT>
358 inline void SetsOfAreas<NextT>::retrieveResultsForLink(
359  typename Storage<VCardToFindT>::ResultsType** result,
360  const Data::AreaLink* link)
361 {
362  (void)result;
363  (void)link;
364 }
365 
366 template<class NextT>
367 template<class PredicateT>
368 inline void SetsOfAreas<NextT>::RetrieveVariableList(PredicateT& /*predicate*/)
369 {
370 }
371 
372 } // namespace Antares::Solver::Variable
373 
374 #endif // __SOLVER_VARIABLE_SET_OF_AREAS_HXX__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
A single thermal cluster.
Definition: cluster.h:76
static void RetrieveVariableList(PredicateT &predicate)
Retrieve the list of all individual variables.
Definition: setofareas.hxx:368
Definition: cbuilder.h:120
VariableAccessor< typename VCardT::ResultsType, VCardT::columnCount >::Type ResultsType
The true type used for the results.
Definition: info.h:760