Antares Simulator
Power System Simulator
dispatchableGeneration.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 #pragma once
22 
23 #include <antares/utils/utils.h>
24 #include "antares/solver/variable/variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "Dispatch. Gen.";
34  }
35 
37  static std::string Unit()
38  {
39  return "MWh";
40  }
41 
43  static std::string Description()
44  {
45  return "Value of all the dispatchable generation throughout all MC years";
46  }
47 
49  typedef Results<R::AllYears::Average< // The average values throughout all years
50  R::AllYears::StdDeviation< // The standard deviation values throughout all years
51  R::AllYears::Min< // The minimum values throughout all years
52  R::AllYears::Max< // The maximum values throughout all years
53  >>>>>
55 
58 
60  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
62  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
63  & (Category::FileLevel::id
64  | Category::FileLevel::va);
66  static constexpr uint8_t precision = Category::all;
68  static constexpr uint8_t nodeDepthForGUI = +0;
70  static constexpr uint8_t decimal = 0;
72  static constexpr int columnCount = Category::dynamicColumns;
74  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
75  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
76  static constexpr uint8_t spatialAggregatePostProcessing = 0;
78  static constexpr uint8_t hasIntermediateValues = 1;
80  static constexpr uint8_t isPossiblyNonApplicable = 0;
81 
83  typedef std::vector<IntermediateValues> IntermediateValuesBaseType;
84  typedef std::vector<IntermediateValuesBaseType> IntermediateValuesType;
85 
86 }; // class VCard
87 
91 template<class NextT = Container::EndOfList>
93  : public Variable::IVariable<DispatchableGeneration<NextT>, NextT, VCardDispatchableGeneration>
94 {
95 public:
97  typedef NextT NextType;
102 
105 
107 
108  enum
109  {
111  count = 1 + NextT::count,
112  };
113 
114  template<int CDataLevel, int CFile>
115  struct Statistics
116  {
117  enum
118  {
119  count = ((VCardType::categoryDataLevel & CDataLevel
120  && VCardType::categoryFileLevel & CFile)
121  ? (NextType::template Statistics<CDataLevel, CFile>::count
123  : NextType::template Statistics<CDataLevel, CFile>::count),
124  };
125  };
126 
127  void initializeFromArea(Data::Study* study, Data::Area* area)
128  {
129  pNbYearsParallel = study->maxNbYearsInParallel;
130  pValuesForTheCurrentYear.resize(pNbYearsParallel);
131 
132  // Building the vector of group names the clusters belong to.
133  std::set<std::string> names;
134  for (const auto& cluster: area->thermal.list.each_enabled())
135  {
136  names.insert(cluster->getGroup());
137  }
138  groupNames_ = {names.begin(), names.end()};
139  groupToNumbers_ = Utils::giveNumbersToStrings(groupNames_);
140 
141  nbColumns_ = groupNames_.size();
142 
143  if (nbColumns_)
144  {
145  AncestorType::pResults.resize(nbColumns_);
146 
147  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
148  {
149  pValuesForTheCurrentYear[numSpace].resize(nbColumns_);
150  }
151 
152  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
153  {
154  for (unsigned int i = 0; i != nbColumns_; ++i)
155  {
156  pValuesForTheCurrentYear[numSpace][i].initializeFromStudy(*study);
157  }
158  }
159 
160  for (unsigned int i = 0; i != nbColumns_; ++i)
161  {
162  AncestorType::pResults[i].initializeFromStudy(*study);
163  AncestorType::pResults[i].reset();
164  }
165  }
166  else
167  {
168  AncestorType::pResults.clear();
169  }
170  // Next
171  NextType::initializeFromArea(study, area);
172  }
173 
174  size_t getMaxNumberColumns() const
175  {
176  return nbColumns_ * ResultsType::count;
177  }
178 
179  void yearBegin(unsigned int year, unsigned int numSpace)
180  {
181  // Reset the values for the current year
182  for (unsigned int i = 0; i != nbColumns_; ++i)
183  {
184  pValuesForTheCurrentYear[numSpace][i].reset();
185  }
186  // Next variable
187  NextType::yearBegin(year, numSpace);
188  }
189 
190  void yearEnd(unsigned int year, unsigned int numSpace)
191  {
192  for (unsigned int column = 0; column < nbColumns_; column++)
193  {
194  pValuesForTheCurrentYear[numSpace][column].computeStatisticsForTheCurrentYear();
195  }
196 
197  // Next variable
198  NextType::yearEnd(year, numSpace);
199  }
200 
201  void computeSummary(unsigned int year, unsigned int numSpace)
202  {
203  // Merge all those values with the global results
204 
205  VariableAccessorType::ComputeSummary(pValuesForTheCurrentYear[numSpace],
207  year);
208 
209  // Next variable
210  NextType::computeSummary(year, numSpace);
211  }
212 
213  void hourBegin(unsigned int hourInTheYear)
214  {
215  // Next variable
216  NextType::hourBegin(hourInTheYear);
217  }
218 
219  void hourForEachArea(State& state, unsigned int numSpace)
220  {
221  auto area = state.area;
222  auto& thermal = state.thermal;
223  for (auto& cluster: area->thermal.list.each_enabled())
224  {
225  unsigned int groupNumber = groupToNumbers_[cluster->getGroup()];
226 
227  pValuesForTheCurrentYear[numSpace][groupNumber][state.hourInTheYear]
228  += thermal[area->index].thermalClustersProductions[cluster->enabledIndex];
229  }
230 
231  // Next variable
232  NextType::hourForEachArea(state, numSpace);
233  }
234 
235  inline void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
236  {
237  // Ask to build the digest to the next variable
238  NextType::buildDigest(results, digestLevel, dataLevel);
239  }
240 
241  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
242  unsigned int column,
243  unsigned int numSpace) const
244  {
245  return pValuesForTheCurrentYear[numSpace][column].hour;
246  }
247 
248  void localBuildAnnualSurveyReport(SurveyResults& results,
249  int fileLevel,
250  int precision,
251  unsigned int numSpace) const
252  {
253  // The current variable is actually a multiple-variable.
254  results.isCurrentVarNA = AncestorType::isNonApplicable;
255 
256  if (!AncestorType::isPrinted[0])
257  {
258  return;
259  }
260 
261  for (unsigned int column = 0; column < nbColumns_; column++)
262  {
263  results.variableCaption = groupNames_[column];
264  results.variableUnit = VCardType::Unit();
265  pValuesForTheCurrentYear[numSpace][column]
266  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
267  }
268  }
269 
270  void buildSurveyReport(SurveyResults& results,
271  int dataLevel,
272  int fileLevel,
273  int precision) const
274  {
275  // Building synthesis results
276  // ------------------------------
277 
278  if (AncestorType::isPrinted[0])
279  {
280  // And only if we match the current data level _and_ precision level
281  if ((dataLevel & VCardType::categoryDataLevel)
282  && (fileLevel & VCardType::categoryFileLevel) && (precision & VCardType::precision))
283  {
284  results.isCurrentVarNA[0] = AncestorType::isNonApplicable[0];
285 
286  for (unsigned int column = 0; column < nbColumns_; column++)
287  {
288  results.variableCaption = groupNames_[column];
289  results.variableUnit = VCardType::Unit();
290  AncestorType::pResults[column]
291  .template buildSurveyReport<ResultsType, VCardType>(
292  results,
293  AncestorType::pResults[column],
294  dataLevel,
295  fileLevel,
296  precision);
297  }
298  }
299  }
300  // Ask to the next item in the static list to export its results as well
301  NextType::buildSurveyReport(results, dataLevel, fileLevel, precision);
302  }
303 
304 private:
306  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
307  std::vector<std::string> groupNames_; // Names of group containing the clusters of the area
308  std::map<std::string, unsigned int> groupToNumbers_; // Gives to each group (of area) a number
309  size_t nbColumns_ = 0;
310  unsigned int pNbYearsParallel;
311 
312 }; // class DispatchableGeneration
313 
314 } // namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal DispatchableGeneration.
Definition: dispatchableGeneration.h:94
VCardDispatchableGeneration VCardType
VCard.
Definition: dispatchableGeneration.h:99
VCardType::ResultsType ResultsType
List of expected results.
Definition: dispatchableGeneration.h:104
NextT NextType
Type of the next static variable.
Definition: dispatchableGeneration.h:97
Variable::IVariable< DispatchableGeneration< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: dispatchableGeneration.h:101
@ count
How many items have we got.
Definition: dispatchableGeneration.h:111
Interface for any variable.
Definition: variable.h:47
StoredResultType pResults
All the results about this variable.
Definition: variable.h:323
Temporary buffer for allocating results for a single year.
Definition: intermediate.h:42
Definition: results.h:44
@ count
The count if item in the list.
Definition: results.h:52
Definition: cbuilder.h:120
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: dispatchableGeneration.h:78
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: dispatchableGeneration.h:62
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: dispatchableGeneration.h:80
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expected results.
Definition: dispatchableGeneration.h:54
static constexpr uint8_t precision
Precision (views)
Definition: dispatchableGeneration.h:66
VCardDispatchableGeneration VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: dispatchableGeneration.h:57
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: dispatchableGeneration.h:60
static std::string Description()
The short description of the variable.
Definition: dispatchableGeneration.h:43
static std::string Unit()
Unit.
Definition: dispatchableGeneration.h:37
static constexpr uint8_t decimal
Decimal precision.
Definition: dispatchableGeneration.h:70
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: dispatchableGeneration.h:74
static constexpr int columnCount
Nb of columns occupied by this variable in year-by-year results.
Definition: dispatchableGeneration.h:72
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: dispatchableGeneration.h:68
static std::string Caption()
Caption.
Definition: dispatchableGeneration.h:31