Antares Simulator
Power System Simulator
STStorageLevelsByCluster.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/solver/variable/variable.h"
24 
25 namespace Antares::Solver::Variable::Economy
26 {
28 {
30  static std::string Caption()
31  {
32  return "STS lvl by plant";
33  }
34 
36  static std::string Unit()
37  {
38  return "Levels - MWh";
39  }
40 
42  static std::string Description()
43  {
44  return "Levels by ST storage clusters";
45  }
46 
48  typedef Results<R::AllYears::Average< // The average values throughout all years
49  >>
51 
54 
56  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
58  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
59  & (Category::FileLevel::de_sts);
61  static constexpr uint8_t precision = Category::all;
63  static constexpr uint8_t nodeDepthForGUI = +0;
65  static constexpr uint8_t decimal = 0;
67  static constexpr int columnCount = Category::dynamicColumns;
69  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
70  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
71  static constexpr uint8_t spatialAggregatePostProcessing = 0;
73  static constexpr uint8_t hasIntermediateValues = 1;
75  static constexpr uint8_t isPossiblyNonApplicable = 0;
76 
78  typedef std::vector<IntermediateValues> IntermediateValuesBaseType;
79  typedef std::vector<IntermediateValuesBaseType> IntermediateValuesType;
80 
81 }; // class VCard
82 
86 template<class NextT = Container::EndOfList>
87 class STstorageLevelsByCluster: public Variable::IVariable<STstorageLevelsByCluster<NextT>,
88  NextT,
89  VCardSTstorageLevelsByCluster>
90 {
91 public:
93  typedef NextT NextType;
98 
101 
103 
104  enum
105  {
107  count = 1 + NextT::count,
108  };
109 
110  template<int CDataLevel, int CFile>
111  struct Statistics
112  {
113  enum
114  {
115  count = ((VCardType::categoryDataLevel & CDataLevel
116  && VCardType::categoryFileLevel & CFile)
117  ? (NextType::template Statistics<CDataLevel, CFile>::count
119  : NextType::template Statistics<CDataLevel, CFile>::count),
120  };
121  };
122 
123 public:
124  void initializeFromArea(Data::Study* study, Data::Area* area)
125  {
126  // Get the number of years in parallel
127  pNbYearsParallel = study->maxNbYearsInParallel;
128  pValuesForTheCurrentYear.resize(pNbYearsParallel);
129 
130  // Get the area
131  nbClusters_ = area->shortTermStorage.count();
132  if (nbClusters_)
133  {
134  AncestorType::pResults.resize(nbClusters_);
135 
136  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
137  {
138  pValuesForTheCurrentYear[numSpace].resize(nbClusters_);
139  }
140 
141  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
142  {
143  for (unsigned int i = 0; i != nbClusters_; ++i)
144  {
145  pValuesForTheCurrentYear[numSpace][i].initializeFromStudy(*study);
146  }
147  }
148 
149  for (unsigned int i = 0; i != nbClusters_; ++i)
150  {
151  AncestorType::pResults[i].initializeFromStudy(*study);
152  AncestorType::pResults[i].reset();
153  }
154  }
155  else
156  {
157  AncestorType::pResults.clear();
158  }
159  // Next
160  NextType::initializeFromArea(study, area);
161  }
162 
163  size_t getMaxNumberColumns() const
164  {
165  return nbClusters_ * ResultsType::count;
166  }
167 
168  void yearBegin(unsigned int year, unsigned int numSpace)
169  {
170  // Reset the values for the current year
171  for (unsigned int i = 0; i != nbClusters_; ++i)
172  {
173  pValuesForTheCurrentYear[numSpace][i].reset();
174  }
175  // Next variable
176  NextType::yearBegin(year, numSpace);
177  }
178 
179  void yearEnd(unsigned int year, unsigned int numSpace)
180  {
181  for (unsigned int clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
182  {
183  // Compute all statistics from hourly results for the current year (daily, weekly,
184  // monthly, ...)
185  pValuesForTheCurrentYear[numSpace][clusterIndex]
186  .computeAveragesForCurrentYearFromHourlyResults();
187  }
188  // Next variable
189  NextType::yearEnd(year, numSpace);
190  }
191 
192  void computeSummary(unsigned int year, unsigned int numSpace)
193  {
194  for (unsigned int clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
195  {
196  // Merge all those values with the global results
197  AncestorType::pResults[clusterIndex]
198  .merge(year, pValuesForTheCurrentYear[numSpace][clusterIndex]);
199  }
200 
201  // Next variable
202  NextType::computeSummary(year, numSpace);
203  }
204 
205  void hourBegin(unsigned int hourInTheYear)
206  {
207  // Next variable
208  NextType::hourBegin(hourInTheYear);
209  }
210 
211  void hourForEachArea(State& state, unsigned int numSpace)
212  {
213  for (uint clusterIndex = 0; clusterIndex != state.area->shortTermStorage.count();
214  ++clusterIndex)
215  {
216  // ST storage levels for the current cluster and this hour
217  pValuesForTheCurrentYear[numSpace][clusterIndex].hour[state.hourInTheYear]
218  = state.hourlyResults->ShortTermStorage[clusterIndex].level[state.hourInTheWeek];
219  }
220 
221  // Next variable
222  NextType::hourForEachArea(state, numSpace);
223  }
224 
225  inline void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
226  {
227  // Ask to build the digest to the next variable
228  NextType::buildDigest(results, digestLevel, dataLevel);
229  }
230 
231  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
232  unsigned int column,
233  unsigned int numSpace) const
234  {
235  return pValuesForTheCurrentYear[numSpace][column].hour;
236  }
237 
238  void localBuildAnnualSurveyReport(SurveyResults& results,
239  int fileLevel,
240  int precision,
241  unsigned int numSpace) const
242  {
243  // Initializing external pointer on current variable non applicable status
244  results.isCurrentVarNA = AncestorType::isNonApplicable;
245 
246  if (AncestorType::isPrinted[0])
247  {
248  assert(NULL != results.data.area);
249  const auto& shortTermStorage = results.data.area->shortTermStorage;
250 
251  // Write the data for the current year
252  uint clusterIndex = 0;
253  for (const auto& sts: shortTermStorage.storagesByIndex)
254  {
255  // Write the data for the current year
256  results.variableCaption = sts.properties.name;
257  results.variableUnit = VCardType::Unit();
258  pValuesForTheCurrentYear[numSpace][clusterIndex]
259  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
260 
261  clusterIndex++;
262  }
263  }
264  }
265 
266 private:
268  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
269  size_t nbClusters_;
270  unsigned int pNbYearsParallel;
271 
272 }; // class STstorageLevelsByCluster
273 
274 } // End namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Energy generated by short term storage clusters.
Definition: STStorageLevelsByCluster.h:90
NextT NextType
Type of the next static variable.
Definition: STStorageLevelsByCluster.h:93
Variable::IVariable< STstorageLevelsByCluster< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: STStorageLevelsByCluster.h:97
VCardType::ResultsType ResultsType
List of expected results.
Definition: STStorageLevelsByCluster.h:100
VCardSTstorageLevelsByCluster VCardType
VCard.
Definition: STStorageLevelsByCluster.h:95
@ count
How many items have we got.
Definition: STStorageLevelsByCluster.h:107
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: STStorageLevelsByCluster.h:73
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: STStorageLevelsByCluster.h:75
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: STStorageLevelsByCluster.h:63
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: STStorageLevelsByCluster.h:58
Results< R::AllYears::Average< > > ResultsType
The expecte results.
Definition: STStorageLevelsByCluster.h:50
static constexpr uint8_t decimal
Decimal precision.
Definition: STStorageLevelsByCluster.h:65
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: STStorageLevelsByCluster.h:69
static constexpr int columnCount
Number of columns used by the variable.
Definition: STStorageLevelsByCluster.h:67
VCardSTstorageLevelsByCluster VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: STStorageLevelsByCluster.h:53
static std::string Caption()
Caption.
Definition: STStorageLevelsByCluster.h:30
static std::string Unit()
Unit.
Definition: STStorageLevelsByCluster.h:36
static std::string Description()
The short description of the variable.
Definition: STStorageLevelsByCluster.h:42
static constexpr uint8_t precision
Precision (views)
Definition: STStorageLevelsByCluster.h:61
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: STStorageLevelsByCluster.h:56