Antares Simulator
Power System Simulator
nbOfDispatchedUnitsByPlant.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_ECONOMY_NbOfDispatchedUnitsByPlant_H__
22 #define __SOLVER_VARIABLE_ECONOMY_NbOfDispatchedUnitsByPlant_H__
23 
24 #include "antares/solver/variable/variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "NODU by plant";
34  }
35 
37  static std::string Unit()
38  {
39  return "NODU";
40  }
41 
43  static std::string Description()
44  {
45  return "Number of Dispatchable Units by plant";
46  }
47 
49  typedef Results<R::AllYears::Average< // The average values throughout all years
50  >>
52 
55 
57  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
59  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
60  & (Category::FileLevel::de);
62  static constexpr uint8_t precision = Category::all;
64  static constexpr uint8_t nodeDepthForGUI = +0;
66  static constexpr uint8_t decimal = 0;
68  static constexpr int columnCount = Category::dynamicColumns;
70  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
71  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
72  static constexpr uint8_t spatialAggregatePostProcessing = 0;
74  static constexpr uint8_t hasIntermediateValues = 1;
76  static constexpr uint8_t isPossiblyNonApplicable = 0;
77 
79  typedef std::vector<IntermediateValues> IntermediateValuesBaseType;
80  typedef std::vector<IntermediateValuesBaseType> IntermediateValuesType;
81 
82 }; // class VCard
83 
88 template<class NextT = Container::EndOfList>
89 class NbOfDispatchedUnitsByPlant: public Variable::IVariable<NbOfDispatchedUnitsByPlant<NextT>,
90  NextT,
91  VCardNbOfDispatchedUnitsByPlant>
92 {
93 public:
95  typedef NextT NextType;
100 
103 
105 
106  enum
107  {
109  count = 1 + NextT::count,
110  };
111 
112  template<int CDataLevel, int CFile>
113  struct Statistics
114  {
115  enum
116  {
117  count = ((VCardType::categoryDataLevel & CDataLevel
118  && VCardType::categoryFileLevel & CFile)
119  ? (NextType::template Statistics<CDataLevel, CFile>::count
121  : NextType::template Statistics<CDataLevel, CFile>::count),
122  };
123  };
124 
125 public:
127  pSize(0)
128  {
129  }
130 
131  void initializeFromStudy(Data::Study& study)
132  {
133  // Next
134  NextType::initializeFromStudy(study);
135  }
136 
137  void initializeFromArea(Data::Study* study, Data::Area* area)
138  {
139  pNbYearsParallel = study->maxNbYearsInParallel;
140  pValuesForTheCurrentYear.resize(pNbYearsParallel);
141 
142  // Get the area
143  pSize = area->thermal.list.enabledCount();
144  if (pSize)
145  {
146  AncestorType::pResults.resize(pSize);
147  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
148  {
149  pValuesForTheCurrentYear[numSpace].resize(pSize);
150  }
151 
152  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
153  {
154  for (unsigned int i = 0; i != pSize; ++i)
155  {
156  pValuesForTheCurrentYear[numSpace][i].initializeFromStudy(*study);
157  }
158  }
159 
160  for (unsigned int i = 0; i != pSize; ++i)
161  {
162  AncestorType::pResults[i].initializeFromStudy(*study);
163  AncestorType::pResults[i].reset();
164  }
165  }
166  else
167  {
168  AncestorType::pResults.clear();
169  }
170 
171  // Next
172  NextType::initializeFromArea(study, area);
173  }
174 
175  size_t getMaxNumberColumns() const
176  {
177  return pSize * ResultsType::count;
178  }
179 
180  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
181  {
182  // Next
183  NextType::initializeFromAreaLink(study, link);
184  }
185 
186  void simulationBegin()
187  {
188  // Next
189  NextType::simulationBegin();
190  }
191 
192  void simulationEnd()
193  {
194  NextType::simulationEnd();
195  }
196 
197  void yearBegin(unsigned int year, unsigned int numSpace)
198  {
199  // Reset the values for the current year
200  for (unsigned int i = 0; i != pSize; ++i)
201  {
202  pValuesForTheCurrentYear[numSpace][i].reset();
203  }
204 
205  // Next variable
206  NextType::yearBegin(year, numSpace);
207  }
208 
209  void yearEndBuildPrepareDataForEachThermalCluster(State& state,
210  uint year,
211  unsigned int numSpace)
212  {
213  for (unsigned int i = 0; i <= state.study.runtime.rangeLimits.hour[Data::rangeEnd]; ++i)
214  {
215  state.thermalClusterDispatchedUnitsCountForYear[i] += static_cast<uint>(
216  pValuesForTheCurrentYear[numSpace][state.thermalCluster->enabledIndex].hour[i]);
217  }
218 
219  // Next variable
220  NextType::yearEndBuildPrepareDataForEachThermalCluster(state, year, numSpace);
221  }
222 
223  void yearEndBuildForEachThermalCluster(State& state, uint year, unsigned int numSpace)
224  {
225  // Get end year calculations
226  for (unsigned int i = state.study.runtime.rangeLimits.hour[Data::rangeBegin];
227  i <= state.study.runtime.rangeLimits.hour[Data::rangeEnd];
228  ++i)
229  {
230  pValuesForTheCurrentYear[numSpace][state.thermalCluster->enabledIndex].hour[i]
231  = state.thermalClusterDispatchedUnitsCountForYear[i];
232  }
233 
234  // Next variable
235  NextType::yearEndBuildForEachThermalCluster(state, year, numSpace);
236  }
237 
238  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
239  {
240  // Next variable
241  NextType::yearEndBuild(state, year, numSpace);
242  }
243 
244  void yearEnd(unsigned int year, unsigned int numSpace)
245  {
246  // Merge all results for all thermal clusters
247  {
248  for (unsigned int i = 0; i < pSize; ++i)
249  {
250  // Compute all statistics for the current year (daily,weekly,monthly)
251  pValuesForTheCurrentYear[numSpace][i].computeStatisticsForTheCurrentYear();
252  }
253  }
254  // Next variable
255  NextType::yearEnd(year, numSpace);
256  }
257 
258  void computeSummary(unsigned int year, unsigned int numSpace)
259  {
260  for (unsigned int i = 0; i < pSize; ++i)
261  {
262  // Merge all those values with the global results
263  AncestorType::pResults[i].merge(year, pValuesForTheCurrentYear[numSpace][i]);
264  }
265 
266  // Next variable
267  NextType::computeSummary(year, numSpace);
268  }
269 
270  void hourBegin(unsigned int hourInTheYear)
271  {
272  // Next variable
273  NextType::hourBegin(hourInTheYear);
274  }
275 
276  void hourForEachArea(State& state, unsigned int numSpace)
277  {
278  auto area = state.area;
279  auto& thermal = state.thermal;
280  for (auto& cluster: area->thermal.list.each_enabled())
281  {
282  pValuesForTheCurrentYear[numSpace][cluster->enabledIndex].hour[state.hourInTheYear]
283  = thermal[area->index].numberOfUnitsONbyCluster[cluster->enabledIndex];
284  }
285 
286  // Next variable
287  NextType::hourForEachArea(state, numSpace);
288  }
289 
290  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
291  unsigned int,
292  unsigned int numSpace) const
293  {
294  return pValuesForTheCurrentYear[numSpace][0].hour;
295  }
296 
297  void localBuildAnnualSurveyReport(SurveyResults& results,
298  int fileLevel,
299  int precision,
300  unsigned int numSpace) const
301  {
302  // Initializing external pointer on current variable non applicable status
303  results.isCurrentVarNA = AncestorType::isNonApplicable;
304 
305  if (AncestorType::isPrinted[0])
306  {
307  assert(NULL != results.data.area);
308  const auto& thermal = results.data.area->thermal;
309 
310  // Write the data for the current year
311  for (auto& cluster: thermal.list.each_enabled())
312  {
313  // Write the data for the current year
314  results.variableCaption = cluster->name(); // VCardType::Caption();
315  results.variableUnit = VCardType::Unit();
316  pValuesForTheCurrentYear[numSpace][cluster->enabledIndex]
317  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
318  }
319  }
320  }
321 
322 private:
324  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
325  size_t pSize;
326  unsigned int pNbYearsParallel;
327 
328 }; // class NbOfDispatchedUnitsByPlant
329 
330 } // namespace Antares::Solver::Variable::Economy
331 
332 #endif // __SOLVER_VARIABLE_ECONOMY_NbOfDispatchedUnitsByPlant_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
C02 Average value of the overrall OperatingCost emissions expected from all the thermal dispatchable ...
Definition: nbOfDispatchedUnitsByPlant.h:92
NextT NextType
Type of the next static variable.
Definition: nbOfDispatchedUnitsByPlant.h:95
Variable::IVariable< NbOfDispatchedUnitsByPlant< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: nbOfDispatchedUnitsByPlant.h:99
@ count
How many items have we got.
Definition: nbOfDispatchedUnitsByPlant.h:109
VCardType::ResultsType ResultsType
List of expected results.
Definition: nbOfDispatchedUnitsByPlant.h:102
VCardNbOfDispatchedUnitsByPlant VCardType
VCard.
Definition: nbOfDispatchedUnitsByPlant.h:97
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 std::string Caption()
Caption.
Definition: nbOfDispatchedUnitsByPlant.h:31
static constexpr int columnCount
Number of columns used by the variable.
Definition: nbOfDispatchedUnitsByPlant.h:68
static std::string Unit()
Unit.
Definition: nbOfDispatchedUnitsByPlant.h:37
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: nbOfDispatchedUnitsByPlant.h:70
VCardNbOfDispatchedUnitsByPlant VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: nbOfDispatchedUnitsByPlant.h:54
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: nbOfDispatchedUnitsByPlant.h:74
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: nbOfDispatchedUnitsByPlant.h:59
static std::string Description()
The short description of the variable.
Definition: nbOfDispatchedUnitsByPlant.h:43
Results< R::AllYears::Average< > > ResultsType
The expected results.
Definition: nbOfDispatchedUnitsByPlant.h:51
static constexpr uint8_t precision
Precision (views)
Definition: nbOfDispatchedUnitsByPlant.h:62
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: nbOfDispatchedUnitsByPlant.h:64
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: nbOfDispatchedUnitsByPlant.h:57
static constexpr uint8_t decimal
Decimal precision.
Definition: nbOfDispatchedUnitsByPlant.h:66
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: nbOfDispatchedUnitsByPlant.h:76