Antares Simulator
Power System Simulator
container.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_CONTAINER_CONTAINER_HXX__
22 #define __SOLVER_CONTAINER_CONTAINER_HXX__
23 
24 #include <yuni/core/static/types.h>
25 
26 #include "antares/solver/variable/surveyresults/reportbuilder.hxx"
27 
28 namespace Antares::Solver::Variable::Container
29 {
30 template<class NextT>
32 {
33  // Store a pointer to the current study
34  pStudy = &study;
35  // Next
36  NextT::initializeFromStudy(study);
37 }
38 
39 template<class NextT>
41 {
42  // Ask to the first variable to do it
43  NextT::initializeFromArea(study, area);
44 }
45 
46 template<class NextT>
48 {
49  // Next
50  NextT::initializeFromAreaLink(study, link);
51 }
52 
53 template<class NextT>
55  Data::Area* area,
56  Data::ThermalCluster* cluster)
57 {
58  // Next
59  NextT::initializeFromThermalCluster(study, area, cluster);
60 }
61 
62 template<class NextT>
64 {
65  NextT::simulationBegin();
66 }
67 
68 template<class NextT>
70 {
71  NextT::simulationEnd();
72 }
73 
74 template<class NextT>
75 inline void List<NextT>::yearBegin(unsigned int year, unsigned int numSpace)
76 {
77  NextT::yearBegin(year, numSpace);
78 }
79 
80 template<class NextT>
81 inline void List<NextT>::yearEnd(unsigned int year, unsigned int numSpace)
82 {
83  NextT::yearEnd(year, numSpace);
84 }
85 
86 template<class NextT>
87 inline void List<NextT>::computeSummary(unsigned int year, unsigned int numSpace)
88 {
89  NextT::computeSummary(year, numSpace);
90 }
91 
92 template<class NextT>
93 template<class V>
94 inline void List<NextT>::yearEndSpatialAggregates(V& allVars,
95  unsigned int year,
96  unsigned int numSpace)
97 {
98  // Next variable
99  NextT::yearEndSpatialAggregates(allVars, year, numSpace);
100 }
101 
102 template<class NextT>
103 template<class V, class SetT>
104 inline void List<NextT>::yearEndSpatialAggregates(V& allVars, unsigned int year, const SetT& set)
105 {
106  // Next variable
107  NextT::yearEndSpatialAggregates(allVars, year, set);
108 }
109 
110 template<class NextT>
111 template<class V>
112 inline void List<NextT>::computeSpatialAggregatesSummary(V& allVars,
113  unsigned int year,
114  unsigned int numSpace)
115 {
116  // Next variable
117  NextT::computeSpatialAggregatesSummary(allVars, year, numSpace);
118 }
119 
120 template<class NextT>
121 template<class V>
122 inline void List<NextT>::simulationEndSpatialAggregates(V& allVars)
123 {
124  // Next variable
125  NextT::simulationEndSpatialAggregates(allVars);
126 }
127 
128 template<class NextT>
129 template<class V, class SetT>
130 inline void List<NextT>::simulationEndSpatialAggregates(V& allVars, const SetT& set)
131 {
132  // Next variable
133  NextT::simulationEndSpatialAggregates(allVars, set);
134 }
135 
136 template<class NextT>
137 inline void List<NextT>::hourBegin(unsigned int hourInTheYear)
138 {
139  NextT::hourBegin(hourInTheYear);
140 }
141 
142 template<class NextT>
143 inline void List<NextT>::weekBegin(State& state)
144 {
145  NextT::weekBegin(state);
146 }
147 
148 template<class NextT>
149 inline void List<NextT>::weekEnd(State& state)
150 {
151  NextT::weekEnd(state);
152 }
153 
154 template<class NextT>
155 inline void List<NextT>::hourForEachArea(State& state, unsigned int numSpace)
156 {
157  NextT::hourForEachArea(state, numSpace);
158 }
159 
160 template<class NextT>
161 inline void List<NextT>::hourForEachLink(State& state)
162 {
163  NextT::hourForEachLink(state);
164 }
165 
166 template<class NextT>
167 inline void List<NextT>::hourEnd(State& state, unsigned int hourInTheYear)
168 {
169  NextT::hourEnd(state, hourInTheYear);
170 }
171 
172 template<class NextT>
173 template<class SearchVCardT, class O>
174 inline void List<NextT>::computeSpatialAggregateWith(O& out)
175 {
176  NextT::template computeSpatialAggregateWith<SearchVCardT, O>(out);
177 }
178 
179 template<class NextT>
180 template<class SearchVCardT, class O>
181 inline void List<NextT>::computeSpatialAggregateWith(O& out,
182  const Data::Area* area,
183  unsigned int numSpace)
184 {
185  NextT::template computeSpatialAggregateWith<SearchVCardT, O>(out, area, numSpace);
186 }
187 
188 template<class NextT>
189 template<class VCardToFindT>
190 inline void List<NextT>::retrieveResultsForArea(
192  const Data::Area* area)
193 {
194  NextT::template retrieveResultsForArea<VCardToFindT>(result, area);
195 }
196 
197 template<class NextT>
198 template<class VCardToFindT>
199 inline void List<NextT>::retrieveResultsForThermalCluster(
201  const Data::ThermalCluster* cluster)
202 {
203  NextT::template retrieveResultsForThermalCluster<VCardToFindT>(result, cluster);
204 }
205 
206 template<class NextT>
207 template<class VCardToFindT>
208 inline void List<NextT>::retrieveResultsForLink(
210  const Data::AreaLink* link)
211 {
212  NextT::template retrieveResultsForLink<VCardToFindT>(result, link);
213 }
214 
215 template<class NextT>
217  int dataLevel,
218  int fileLevel,
219  int precision) const
220 {
221  // Reset
222  results.data.columnIndex = 0;
223 
224  // The new filename
225  results.data.filename.clear();
226  results.data.filename << std::filesystem::path(static_cast<std::string>(results.data.output))
227  / "";
228  Category::FileLevelToStream(results.data.filename, fileLevel);
229  results.data.filename << '-';
230  Category::PrecisionLevelToStream(results.data.filename, precision);
231  results.data.filename << ".txt";
232 
233  // Ask to all variables
234  NextT::buildSurveyReport(results, dataLevel, fileLevel, precision);
235 
236  // If the column index is still equals to 0, that would mean we have nothing
237  // to do (there is no data to write)
238  if (results.data.columnIndex > 0)
239  {
240  results.saveToFile(dataLevel, fileLevel, precision);
241  }
242 }
243 
244 template<class NextT>
246  int dataLevel,
247  int fileLevel,
248  int precision,
249  unsigned int numSpace) const
250 {
251  // Reset
252  results.data.columnIndex = 0;
253 
254  // The new filename
255  results.data.filename.clear();
256  results.data.filename << std::filesystem::path(static_cast<std::string>(results.data.output))
257  / "";
258  Category::FileLevelToStream(results.data.filename, fileLevel);
259  results.data.filename << '-';
260  Category::PrecisionLevelToStream(results.data.filename, precision);
261  results.data.filename.append(".txt", 4);
262 
263  // Ask to all variables
264  NextT::buildAnnualSurveyReport(results, dataLevel, fileLevel, precision, numSpace);
265 
266  // If the column index is still equals to 0, that would mean we have nothing
267  // to do (there is no data to write)
268  if (results.data.columnIndex > 0)
269  {
270  results.saveToFile(dataLevel, fileLevel, precision);
271  }
272 }
273 
274 template<class NextT>
275 void List<NextT>::buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
276 {
277  // Reset
278  results.data.columnIndex = 0;
279  results.data.thermalCluster = nullptr;
280  results.data.area = nullptr;
281  results.data.link = nullptr;
282  results.variableCaption.clear();
283 
284  // Building the digest
285  NextT::buildDigest(results, digestLevel, dataLevel);
286 }
287 
288 template<class NextT>
290  const Yuni::String& output,
291  unsigned int numSpace,
292  IResultWriter& writer)
293 {
294  using namespace Antares;
295 
296  // Infos
297  if (global)
298  {
299  logs.info(); // empty line
300  logs.checkpoint() << "Exporting the survey results...";
301  }
302  else
303  {
304  logs.info() << "Exporting the annual results";
305  }
306 
307  SurveyResults survey(*pStudy, output, writer);
308 
309  // Year by year ?
310  survey.yearByYearResults = !global;
311 
312  if (global)
313  {
314  // alias to the type of the report builder
315  using Builder = SurveyReportBuilder<true, ListType>;
316  // Building the survey results for each possible state
317  Builder::Run(*this, survey);
318 
319  // Exporting the Grid (information about the study)
320  survey.exportGridInfos();
321 
322  // Exporting the digest
323  // The digest must be exported after the real report because some values
324  // are computed at this moment.
325  Builder::RunDigest(*this, survey, writer);
326  }
327  else
328  {
329  // alias to the type of the report builder
330  using Builder = SurveyReportBuilder<false, ListType>;
331  // Building the survey results for each possible state
332  Builder::Run(*this, survey, numSpace);
333  }
334 }
335 
336 } // namespace Antares::Solver::Variable::Container
337 
338 #endif // __SOLVER_CONTAINER_CONTAINER_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
A single thermal cluster.
Definition: cluster.h:76
Definition: i_writer.h:32
Static list for all output variables.
Definition: container.h:44
void simulationEnd()
Notify to all variables that the simulation has finished.
Definition: container.hxx:69
void simulationBegin()
Notify to all variables that the simulation is about to begin.
Definition: container.hxx:63
void yearBegin(unsigned int year, unsigned int numSpace)
Notify to all variables that a new year is about to start.
Definition: container.hxx:75
void yearEnd(unsigned int year, unsigned int numSpace)
Notify to all variables that the year is now over.
Definition: container.hxx:81
void initializeFromStudy(Data::Study &study)
Initialize all output variables.
Definition: container.hxx:31
void initializeFromLink(Data::Study *study, Data::AreaLink *link)
Initialize all output variables according a given link.
Definition: container.hxx:47
void initializeFromArea(Data::Study *study, Data::Area *area)
Initialize all output variables according a given area.
Definition: container.hxx:40
void buildDigest(SurveyResults &results, int digestLevel, int dataLevel) const
Ask to all variables to fullfil the digest.
Definition: container.hxx:275
void initializeFromThermalCluster(Data::Study *study, Data::Area *area, Data::ThermalCluster *cluster)
Initialize all output variables according a given thermal cluster.
Definition: container.hxx:54
void hourBegin(unsigned int hourInTheYear)
Notify to all variables that a new hour is about to begin.
Definition: container.hxx:137
void buildSurveyReport(SurveyResults &results, int dataLevel, int fileLevel, int precision) const
Ask to all variables to fullfil the report.
Definition: container.hxx:216
void exportSurveyResults(bool global, const Yuni::String &output, unsigned int numSpace, IResultWriter &writer)
Ask to all variables to fullfil additional reports (like the digest for example)
Definition: container.hxx:289
const Data::ThermalCluster * thermalCluster
Current thermal cluster.
Definition: data.h:61
unsigned int columnIndex
The current column index.
Definition: data.h:53
const Data::AreaLink * link
Current link.
Definition: data.h:65
Yuni::String output
The folder output where to write the results.
Definition: data.h:77
const Data::Area * area
Current area.
Definition: data.h:63
Yuni::String filename
The filename to use for the current report.
Definition: data.h:79
Definition: state.h:71
Class utility for building CSV results files.
Definition: surveyresults.h:41
CaptionType variableCaption
Caption for the current variable.
Definition: surveyresults.h:95
void exportGridInfos()
Export informations about the current study.
Definition: surveyresults.cpp:811
Solver::Variable::Private::SurveyResultsData data
Data (not related to the template parameter)
Definition: surveyresults.h:92
bool yearByYearResults
Flag to known if we are in the year-by-year mode.
Definition: surveyresults.h:122
void saveToFile(int dataLevel, int fileLevel, int precisionLevel)
Write the data into a file.
Definition: surveyresults.cpp:689
Definition: cbuilder.h:120
VariableAccessor< typename VCardT::ResultsType, VCardT::columnCount >::Type ResultsType
The true type used for the results.
Definition: info.h:760