Antares Simulator
Power System Simulator
links.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_INC_LINK_HXX__
22 #define __SOLVER_VARIABLE_INC_LINK_HXX__
23 
24 #include <antares/study/filter.h>
25 #include "antares/solver/variable/endoflist.h" // For UNUSED_VARIABLE, should be somewhere else
26 
27 namespace Antares::Solver::Variable
28 {
29 
30 template<class VariablePerLink>
32 {
33  // Do nothing
34 }
35 
36 template<class VariablePerLink>
37 inline void Links<VariablePerLink>::initializeFromStudy([[maybe_unused]] Data::Study& study)
38 {
39  // Do nothing
40 }
41 
42 template<class VariablePerLink>
43 inline void Links<VariablePerLink>::initializeFromAreaLink(Data::Study*, Data::AreaLink*)
44 {
45  // Nothing to do here
46 }
47 
48 template<class VariablePerLink>
49 inline void Links<VariablePerLink>::initializeFromThermalCluster(Data::Study*,
50  Data::Area*,
52 {
53  // This method should not be called at this stage
54 }
55 
56 template<class VariablePerLink>
57 inline void Links<VariablePerLink>::broadcastNonApplicability(bool applyNonApplicable)
58 {
59  for (uint i = 0; i != pLinkCount; ++i)
60  {
61  pLinks[i].broadcastNonApplicability(applyNonApplicable);
62  }
63 }
64 
65 template<class VariablePerLink>
66 inline void Links<VariablePerLink>::getPrintStatusFromStudy(Data::Study& study)
67 {
68  for (uint i = 0; i != pLinkCount; ++i)
69  {
70  pLinks[i].getPrintStatusFromStudy(study);
71  }
72 }
73 
74 template<class VariablePerLink>
75 inline void Links<VariablePerLink>::supplyMaxNumberOfColumns(Data::Study& study)
76 {
77  for (uint i = 0; i != pLinkCount; ++i)
78  {
79  pLinks[i].supplyMaxNumberOfColumns(study);
80  }
81 }
82 
83 template<class VariablePerLink>
84 inline void Links<VariablePerLink>::yearBegin(uint year, unsigned int numSpace)
85 {
86  for (uint i = 0; i != pLinkCount; ++i)
87  {
88  pLinks[i].yearBegin(year, numSpace);
89  }
90 }
91 
92 template<class VariablePerLink>
93 inline void Links<VariablePerLink>::yearEndBuildPrepareDataForEachThermalCluster(
94  State& state,
95  uint year,
96  unsigned int numSpace)
97 {
98  for (uint i = 0; i != pLinkCount; ++i)
99  {
100  pLinks[i].yearEndBuildPrepareDataForEachThermalCluster(state, year, numSpace);
101  }
102 }
103 
104 template<class VariablePerLink>
105 inline void Links<VariablePerLink>::yearEndBuildForEachThermalCluster(State& state,
106  uint year,
107  unsigned int numSpace)
108 {
109  for (uint i = 0; i != pLinkCount; ++i)
110  {
111  pLinks[i].yearEndBuildForEachThermalCluster(state, year, numSpace);
112  }
113 }
114 
115 template<class VariablePerLink>
116 inline void Links<VariablePerLink>::yearEndBuild(State& state, uint year)
117 {
118  for (uint i = 0; i != pLinkCount; ++i)
119  {
120  pLinks[i].yearEndBuild(state, year);
121  }
122 }
123 
124 template<class VariablePerLink>
125 inline void Links<VariablePerLink>::yearEnd(uint year, uint numSpace)
126 {
127  for (uint i = 0; i != pLinkCount; ++i)
128  {
129  pLinks[i].yearEnd(year, numSpace);
130  }
131 }
132 
133 template<class VariablePerLink>
134 inline void Links<VariablePerLink>::computeSummary(unsigned int year, unsigned int numSpace)
135 {
136  for (uint i = 0; i != pLinkCount; ++i)
137  {
138  pLinks[i].computeSummary(year, numSpace);
139  }
140 }
141 
142 template<class VariablePerLink>
143 inline void Links<VariablePerLink>::weekBegin(State& state)
144 {
145  for (uint i = 0; i != pLinkCount; ++i)
146  {
147  pLinks[i].weekBegin(state);
148  }
149 }
150 
151 template<class VariablePerLink>
152 inline void Links<VariablePerLink>::weekForEachArea(State&, uint numSpace)
153 {
154  // do nothing
155  UNUSED_VARIABLE(numSpace);
156 }
157 
158 template<class VariablePerLink>
159 inline void Links<VariablePerLink>::weekEnd(State& state)
160 {
161  for (uint i = 0; i != pLinkCount; ++i)
162  {
163  pLinks[i].weekEnd(state);
164  }
165 }
166 
167 template<class VariablePerLink>
168 inline void Links<VariablePerLink>::hourBegin(uint hourInTheYear)
169 {
170  for (uint i = 0; i != pLinkCount; ++i)
171  {
172  pLinks[i].hourBegin(hourInTheYear);
173  }
174 }
175 
176 template<class VariablePerLink>
177 inline void Links<VariablePerLink>::hourForEachArea(State& state, unsigned int numSpace)
178 {
179  for (uint i = 0; i != pLinkCount; ++i)
180  {
181  pLinks[i].hourForEachArea(state, numSpace);
182  }
183 }
184 
185 template<class VariablePerLink>
186 inline void Links<VariablePerLink>::hourForEachLink(State& state, unsigned int numSpace)
187 {
188  pLinks[state.link->indexForArea].hourForEachLink(state, numSpace);
189 }
190 
191 template<class VariablePerLink>
192 inline void Links<VariablePerLink>::hourEnd(State& state, uint hourInTheYear)
193 {
194  for (uint i = 0; i != pLinkCount; ++i)
195  {
196  pLinks[i].hourEnd(state, hourInTheYear);
197  }
198 }
199 
200 template<class VariablePerLink>
201 inline void Links<VariablePerLink>::buildSurveyReport(SurveyResults& results,
202  int dataLevel,
203  int fileLevel,
204  int precision) const
205 {
206  int count_int = count;
207  bool link_dataLevel = (dataLevel & Category::DataLevel::link);
208  if (count_int && link_dataLevel)
209  {
210  assert(results.data.link != NULL
211  && "The link must not be null to generate a survey report");
212 
213  // Build the survey results for the given area
214  auto& link = *results.data.link;
215 
216  // Filtering
217  switch (precision)
218  {
219  case Category::hourly:
220  if (!(link.filterSynthesis & Data::filterHourly))
221  {
222  return;
223  }
224  break;
225  case Category::daily:
226  if (!(link.filterSynthesis & Data::filterDaily))
227  {
228  return;
229  }
230  break;
231  case Category::weekly:
232  if (!(link.filterSynthesis & Data::filterWeekly))
233  {
234  return;
235  }
236  break;
237  case Category::monthly:
238  if (!(link.filterSynthesis & Data::filterMonthly))
239  {
240  return;
241  }
242  break;
243  case Category::annual:
244  if (!(link.filterSynthesis & Data::filterAnnual))
245  {
246  return;
247  }
248  break;
249  case Category::all:
250  break;
251  }
252  auto& linkOutputData = pLinks[link.indexForArea];
253  linkOutputData.buildSurveyReport(results, dataLevel, fileLevel, precision);
254  }
255 }
256 
257 template<class VariablePerLink>
258 inline void Links<VariablePerLink>::buildAnnualSurveyReport(SurveyResults& results,
259  int dataLevel,
260  int fileLevel,
261  int precision,
262  uint numSpace) const
263 {
264  int count_int = count;
265  bool link_dataLevel = (dataLevel & Category::DataLevel::link);
266  if (count_int && link_dataLevel)
267  {
268  assert(results.data.link != NULL
269  && "The link must not be null to generate a survey report");
270 
271  auto& link = *results.data.link;
272 
273  // Filtering
274  switch (precision)
275  {
276  case Category::hourly:
277  if (not(link.filterYearByYear & Data::filterHourly))
278  {
279  return;
280  }
281  break;
282  case Category::daily:
283  if (not(link.filterYearByYear & Data::filterDaily))
284  {
285  return;
286  }
287  break;
288  case Category::weekly:
289  if (not(link.filterYearByYear & Data::filterWeekly))
290  {
291  return;
292  }
293  break;
294  case Category::monthly:
295  if (not(link.filterYearByYear & Data::filterMonthly))
296  {
297  return;
298  }
299  break;
300  case Category::annual:
301  if (not(link.filterYearByYear & Data::filterAnnual))
302  {
303  return;
304  }
305  break;
306  case Category::all:
307  break;
308  }
309 
310  // Build the survey results for the given area
311  auto& linkOutputData = pLinks[results.data.link->indexForArea];
312  linkOutputData.buildAnnualSurveyReport(results, dataLevel, fileLevel, precision, numSpace);
313  }
314 }
315 
316 template<class VariablePerLink>
317 template<class I>
318 inline void Links<VariablePerLink>::provideInformations(I& infos)
319 {
320  // Begining of the node
321  if (VCardType::nodeDepthForGUI)
322  {
323  infos.template beginNode<VCardType>();
324  // Next variable in the list
325  NextType::template provideInformations<I>(infos);
326  // End of the node
327  infos.endNode();
328  }
329  else
330  {
331  // Giving our VCard
332  infos.template addVCard<VCardType>();
333  // Next variable in the list
334  NextType::template provideInformations<I>(infos);
335  }
336 }
337 
338 template<class VariablePerLink>
339 template<class PredicateT>
341 {
342  NextType::RetrieveVariableList(predicate);
343 }
344 
345 template<class VariablePerLink>
347 {
348  // Releasing the memory occupied by the areas
349  delete[] pLinks;
350 }
351 
352 template<class VariablePerLink>
354 {
355  // Assert
356  assert(study && "A study pointer must not be null");
357  assert(area && "An area pointer must not be null");
358 
359  pLinkCount = (uint)area->links.size();
360  if (pLinkCount)
361  {
362  pLinks = new NextType[pLinkCount];
363 
364  // For each link...
365  uint lnkIndex = 0;
366  auto end = area->links.end();
367  for (auto i = area->links.begin(); i != end; ++i, ++lnkIndex)
368  {
369  // Instancing a new set of variables of the area
370  NextType& n = pLinks[lnkIndex];
371 
372  // Initialize the variables
373  // From the study
374  n.initializeFromStudy(*study);
375  // From the area
376  n.initializeFromArea(study, area);
377  // From the link
378  n.initializeFromAreaLink(study, i->second);
379  }
380  }
381  else
382  {
383  pLinks = nullptr;
384  }
385 }
386 
387 template<class VariablePerLink>
388 void Links<VariablePerLink>::simulationBegin()
389 {
390  for (uint i = 0; i != pLinkCount; ++i)
391  {
392  pLinks[i].simulationBegin();
393  }
394 }
395 
396 template<class VariablePerLink>
397 void Links<VariablePerLink>::simulationEnd()
398 {
399  for (uint i = 0; i != pLinkCount; ++i)
400  {
401  pLinks[i].simulationEnd();
402  }
403 }
404 
405 template<class VariablePerLink>
406 void Links<VariablePerLink>::buildDigest(SurveyResults& results,
407  int digestLevel,
408  int dataLevel) const
409 {
410  int count_int = count;
411  bool linkDataLevel = dataLevel & Category::DataLevel::link;
412  bool areaDataLevel = dataLevel & Category::DataLevel::area;
413  if (count_int && (linkDataLevel || areaDataLevel))
414  {
415  if (not results.data.area->links.empty())
416  {
417  auto end = results.data.area->links.cend();
418  for (auto i = results.data.area->links.cbegin(); i != end; ++i)
419  {
420  results.data.link = i->second;
421  pLinks[results.data.link->indexForArea].buildDigest(results,
422  digestLevel,
423  Category::DataLevel::link);
424  }
425  }
426  }
427 }
428 
429 template<class VariablePerLink>
430 void Links<VariablePerLink>::beforeYearByYearExport(uint year, uint numSpace)
431 {
432  for (uint i = 0; i != pLinkCount; ++i)
433  {
434  pLinks[i].beforeYearByYearExport(year, numSpace);
435  }
436 }
437 
438 } // namespace Antares::Solver::Variable
439 
440 #endif // __SOLVER_VARIABLE_INC_LINK_HXX__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
A single thermal cluster.
Definition: cluster.h:76
Definition: cbuilder.h:120