Antares Simulator
Power System Simulator
renewableGeneration.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 "Renewable 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 renewable 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<RenewableGeneration<NextT>, NextT, VCardRenewableGeneration>
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->renewable.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  for (const auto& renewableCluster: state.area->renewable.list.each_enabled())
222  {
223  unsigned int groupNumber = groupToNumbers_[renewableCluster->getGroup()];
224 
225  double renewableClusterProduction = renewableCluster->valueAtTimeStep(
226  state.year,
227  state.hourInTheYear);
228 
229  pValuesForTheCurrentYear[numSpace][groupNumber][state.hourInTheYear]
230  += renewableClusterProduction;
231  }
232 
233  // Next variable
234  NextType::hourForEachArea(state, numSpace);
235  }
236 
237  inline void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
238  {
239  // Ask to build the digest to the next variable
240  NextType::buildDigest(results, digestLevel, dataLevel);
241  }
242 
243  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
244  unsigned int column,
245  unsigned int numSpace) const
246  {
247  return pValuesForTheCurrentYear[numSpace][column].hour;
248  }
249 
250  void localBuildAnnualSurveyReport(SurveyResults& results,
251  int fileLevel,
252  int precision,
253  unsigned int numSpace) const
254  {
255  // The current variable is actually a multiple-variable.
256  results.isCurrentVarNA = AncestorType::isNonApplicable;
257 
258  if (!AncestorType::isPrinted[0])
259  {
260  return;
261  }
262 
263  for (unsigned int column = 0; column < nbColumns_; column++)
264  {
265  results.variableCaption = groupNames_[column];
266  results.variableUnit = VCardType::Unit();
267  pValuesForTheCurrentYear[numSpace][column]
268  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
269  }
270  }
271 
272  void buildSurveyReport(SurveyResults& results,
273  int dataLevel,
274  int fileLevel,
275  int precision) const
276  {
277  // Building synthesis results
278  // ------------------------------
279 
280  if (AncestorType::isPrinted[0])
281  {
282  // And only if we match the current data level _and_ precision level
283  if ((dataLevel & VCardType::categoryDataLevel)
284  && (fileLevel & VCardType::categoryFileLevel) && (precision & VCardType::precision))
285  {
286  results.isCurrentVarNA[0] = AncestorType::isNonApplicable[0];
287 
288  for (unsigned int column = 0; column < nbColumns_; column++)
289  {
290  results.variableCaption = groupNames_[column];
291  results.variableUnit = VCardType::Unit();
292  AncestorType::pResults[column]
293  .template buildSurveyReport<ResultsType, VCardType>(
294  results,
295  AncestorType::pResults[column],
296  dataLevel,
297  fileLevel,
298  precision);
299  }
300  }
301  }
302  // Ask to the next item in the static list to export its results as well
303  NextType::buildSurveyReport(results, dataLevel, fileLevel, precision);
304  }
305 
306 private:
308  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
309  std::vector<std::string> groupNames_; // Names of group containing the clusters of the area
310  std::map<std::string, unsigned int> groupToNumbers_; // Gives to each group (of area) a number
311  size_t nbColumns_ = 0;
312  unsigned int pNbYearsParallel;
313 
314 }; // class RenewableGeneration
315 
316 } // namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal RenewableGeneration.
Definition: renewableGeneration.h:94
@ count
How many items have we got.
Definition: renewableGeneration.h:111
VCardRenewableGeneration VCardType
VCard.
Definition: renewableGeneration.h:99
NextT NextType
Type of the next static variable.
Definition: renewableGeneration.h:97
VCardType::ResultsType ResultsType
List of expected results.
Definition: renewableGeneration.h:104
Variable::IVariable< RenewableGeneration< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: renewableGeneration.h:101
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 decimal
Decimal precision.
Definition: renewableGeneration.h:70
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: renewableGeneration.h:78
VCardRenewableGeneration VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: renewableGeneration.h:57
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: renewableGeneration.h:54
static std::string Caption()
Caption.
Definition: renewableGeneration.h:31
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: renewableGeneration.h:62
static constexpr int columnCount
Nb of columns occupied by this variable in year-by-year results.
Definition: renewableGeneration.h:72
static std::string Unit()
Unit.
Definition: renewableGeneration.h:37
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: renewableGeneration.h:80
static std::string Description()
The short description of the variable.
Definition: renewableGeneration.h:43
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: renewableGeneration.h:68
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: renewableGeneration.h:60
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: renewableGeneration.h:74
static constexpr uint8_t precision
Precision (views)
Definition: renewableGeneration.h:66