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