Antares Simulator
Power System Simulator
variable.h
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_VARIABLE_H__
22 #define __SOLVER_VARIABLE_VARIABLE_H__
23 
24 // Remove the visual studio warning: decorated name length exceeded, name was truncated
25 #ifdef YUNI_OS_MSVC
26 #pragma warning(disable : 4503)
27 #endif
28 
29 #include <yuni/yuni.h>
30 #include <yuni/core/static/if.h>
31 
32 #include "categories.h"
33 #include "container.h"
34 #include "endoflist.h"
35 #include "info.h"
36 #include "storage/intermediate.h"
37 #include "storage/results.h"
38 #include "surveyresults.h"
39 
40 namespace Antares::Solver::Variable
41 {
45 template<class ChildT, class NextT, class VCardT>
46 class IVariable: protected NextT
47 {
48 public:
50  typedef ChildT ChildType;
52  typedef NextT NextType;
56  typedef VCardT VCardType;
58  typedef typename VCardType::ResultsType ResultsType;
63 
64  static constexpr uint8_t categoryDataLevel = VCardType::categoryDataLevel;
65  static constexpr uint8_t categoryFileLevel = VCardType::categoryFileLevel;
66 
67  template<int CDataLevel, int CFile>
68  struct Statistics
69  {
70  enum
71  {
72  count = ((categoryDataLevel & CDataLevel && categoryFileLevel & CFile)
73  ? (NextType::template Statistics<CDataLevel, CFile>::count
74  + ResultsType::count)
75  : NextType::template Statistics<CDataLevel, CFile>::count),
76  };
77  };
78 
79 public:
86  template<class R>
87  static void InitializeResultsFromStudy(R& results, Data::Study& study);
88 
94  template<class PredicateT>
95  static void RetrieveVariableList(PredicateT& predicate);
96 
97  void getPrintStatusFromStudy(Data::Study& study);
98  void supplyMaxNumberOfColumns(Data::Study& study);
99 
100 public:
102 
103 
106  IVariable();
108 
109  ~IVariable();
110 
112 
113 
118  void initializeFromStudy(Data::Study& study);
119 
120  size_t getMaxNumberColumns() const;
121 
128  void initializeFromArea(Data::Study* study, Data::Area* area);
129 
136  void initializeFromLink(Data::Study* study, Data::AreaLink* link);
137 
146  Data::Area* area,
147  Data::ThermalCluster* cluster);
149 
150  void broadcastNonApplicability(bool applyNonApplicable);
151 
153 
154 
157  void simulationBegin();
158 
162  void simulationEnd();
164 
166 
167 
172  void yearBegin(uint year);
173 
182  void yearEndBuild(State& state, uint year);
183 
193  void yearEndBuildPrepareDataForEachThermalCluster(State& state, uint year, uint numSpace);
194 
203  void yearEndBuildForEachThermalCluster(State& state, uint year, uint numSpace);
204 
212  void yearEnd(uint year);
213 
214  template<class V>
215  void yearEndSpatialAggregates(V& allVars, uint year, unsigned int numSpace);
216 
217  template<class V, class SetT>
218  void yearEndSpatialAggregates(V& allVars, uint year, const SetT& set);
219 
220  template<class V>
221  void simulationEndSpatialAggregates(V& allVars);
222 
223  template<class V, class SetT>
224  void simulationEndSpatialAggregates(V& allVars, const SetT& set);
226 
228 
229  void hourBegin(uint hourInTheYear);
232  void hourForEachArea(State& state);
233 
234  void hourForEachArea(State& state, unsigned int numSpace);
235 
237  // for a given area
238  void hourForEachLink(State& state, uint numSpace);
240  void hourEnd(State& state, uint hourInTheYear);
242 
244 
245  void weekBegin(State& state);
246  void weekForEachArea(State& state, uint numSpace);
247 
248  void weekEnd(State& state);
250 
252 
253  void buildSurveyReport(SurveyResults& results,
254  int dataLevel,
255  int fileLevel,
256  int precision) const;
257 
258  void buildAnnualSurveyReport(SurveyResults& results,
259  int dataLevel,
260  int fileLevel,
261  int precision,
262  uint numSpace) const;
263 
264  void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const;
265 
269  void beforeYearByYearExport(uint year, uint numSpace);
271 
275  template<class I>
276  static void provideInformations(I& infos);
277 
285  template<class VCardSearchT, class O>
286  void computeSpatialAggregateWith(O& out, uint numSpace);
287 
295  template<class VCardSearchT, class O>
296  void computeSpatialAggregateWith(O& out, const Data::Area* area);
297 
298  template<class VCardToFindT>
299  const double* retrieveHourlyResultsForCurrentYear(uint numSpace) const;
300 
301  template<class VCardToFindT>
302  void retrieveResultsForArea(typename Storage<VCardToFindT>::ResultsType** result,
303  const Data::Area* area);
304 
305  template<class VCardToFindT>
306  void retrieveResultsForThermalCluster(typename Storage<VCardToFindT>::ResultsType** result,
307  const Data::ThermalCluster* cluster);
308 
309  template<class VCardToFindT>
310  void retrieveResultsForLink(typename Storage<VCardToFindT>::ResultsType** result,
311  const Data::AreaLink* link);
312 
313  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
314  uint column,
315  uint) const;
317 
319  const StoredResultType& results() const;
320 
321 protected:
324  // Does current output variable appears non applicable in all output files.
325  // Following is an array of size :
326  // + 1 if variable is a single variable
327  // + > 1 if variable is a multi-variable
328  bool* isNonApplicable;
329  // Do we print results regarding the current variable in output files ? Or do we skip them ?
330  bool* isPrinted;
331  // Positive column count (original column count can be < 0 for some variable [see variables "by
332  // plant"])
333  uint pColumnCount;
334 
335 }; // class Variable
336 
337 } // namespace Antares::Solver::Variable
338 
339 #include "variable.hxx"
340 
341 #endif // __SOLVER_VARIABLE_VARIABLE_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
A single thermal cluster.
Definition: cluster.h:76
Interface for any variable.
Definition: variable.h:47
Storage< VCardT >::ResultsType StoredResultType
Results.
Definition: variable.h:62
static void RetrieveVariableList(PredicateT &predicate)
Retrieve the list of all individual variables.
Definition: variable.hxx:630
const StoredResultType & results() const
The results.
Definition: variable.hxx:544
VCardT VCardType
VCard.
Definition: variable.h:56
void simulationEnd()
Notify to all variables that the simulation has finished.
Definition: variable.hxx:132
NextT NextType
Type of the next static variable.
Definition: variable.h:52
void hourEnd(State &state, uint hourInTheYear)
Event: A new hour in the year has just ended.
Definition: variable.hxx:257
void yearEnd(uint year)
Notify to all variables that the year is now over.
Definition: variable.hxx:151
void yearEndBuildPrepareDataForEachThermalCluster(State &state, uint year, uint numSpace)
Notify to all variables to prepare data for the close to year end calculations for each thermal clust...
Definition: variable.hxx:178
void hourForEachArea(State &state)
Event: For a given hour in the year, walking through all areas.
Definition: variable.hxx:226
StoredResultType pResults
All the results about this variable.
Definition: variable.h:323
static void provideInformations(I &infos)
"Print" informations about the variable tree
Definition: variable.hxx:361
static void InitializeResultsFromStudy(R &results, Data::Study &study)
Initialize the results of the variable.
Definition: variable.hxx:71
void simulationBegin()
Notify to all variables that the simulation is about to begin.
Definition: variable.hxx:125
ChildT ChildType
Child.
Definition: variable.h:50
void yearEndBuild(State &state, uint year)
Notify to all variables that the year is close to end.
void yearEndBuildForEachThermalCluster(State &state, uint year, uint numSpace)
Notify to all variables that the year is close to end.
Definition: variable.hxx:240
void initializeFromArea(Data::Study *study, Data::Area *area)
Initialize the variable with a specific area.
Definition: variable.hxx:78
IVariable()
Default constructor.
Definition: variable.hxx:32
void initializeFromStudy(Data::Study &study)
Initialize the variable.
Definition: variable.hxx:63
void beforeYearByYearExport(uint year, uint numSpace)
Event triggered before exporting a year-by-year survey report.
Definition: variable.hxx:354
void hourBegin(uint hourInTheYear)
Event: A new hour in the year has just began.
Definition: variable.hxx:219
void initializeFromLink(Data::Study *study, Data::AreaLink *link)
Initialize the variable with a specific link between two areas.
Definition: variable.hxx:86
VCardType::ResultsType ResultsType
List of expected results.
Definition: variable.h:58
IVariable< ChildT, NextT, VCardT > VariableType
Variable.
Definition: variable.h:54
void hourForEachLink(State &state, uint numSpace)
Event: For a given hour in the year, walking through all links.
Definition: variable.hxx:250
void computeSpatialAggregateWith(O &out, uint numSpace)
Compute the spatial cluster with the results of a single variable.
Definition: variable.hxx:383
void initializeFromThermalCluster(Data::Study *study, Data::Area *area, Data::ThermalCluster *cluster)
Initialize the variable with a specific thermal cluster.
Definition: variable.hxx:94
VariableAccessor< ResultsType, VCardType::columnCount > VariableAccessorType
Proxy for accessing to the intermediate results.
Definition: variable.h:60
void yearBegin(uint year)
Notify to all variables that a new year is about to start.
Definition: variable.hxx:144
Definition: state.h:71
Class utility for building CSV results files.
Definition: surveyresults.h:41
VariableAccessor< typename VCardT::ResultsType, VCardT::columnCount >::Type ResultsType
The true type used for the results.
Definition: info.h:760