Antares Simulator
Power System Simulator
productionByDispatchablePlant.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_ProductionByDispatchablePlant_H__
22 #define __SOLVER_VARIABLE_ECONOMY_ProductionByDispatchablePlant_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 "DTG by plant";
34  }
35 
37  static std::string Unit()
38  {
39  return "MWh";
40  }
41 
43  static std::string Description()
44  {
45  return "Energy generated by all the clusters";
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 
87 template<class NextT = Container::EndOfList>
89  : public Variable::
90  IVariable<ProductionByDispatchablePlant<NextT>, NextT, VCardProductionByDispatchablePlant>
91 {
92 public:
94  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  pminOfTheClusterForYear(nullptr),
128  pSize(0)
129  {
130  }
131 
133  {
134  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
135  {
136  delete[] pminOfTheClusterForYear[numSpace];
137  }
138  delete[] pminOfTheClusterForYear;
139  }
140 
141  void initializeFromStudy(Data::Study& study)
142  {
143  // Next
144  NextType::initializeFromStudy(study);
145  }
146 
147  void initializeFromArea(Data::Study* study, Data::Area* area)
148  {
149  // Get the number of years in parallel
150  pNbYearsParallel = study->maxNbYearsInParallel;
151  pValuesForTheCurrentYear.resize(pNbYearsParallel);
152  pminOfTheClusterForYear = new double*[pNbYearsParallel];
153 
154  // Get the area
155  pSize = area->thermal.list.enabledCount();
156  if (pSize)
157  {
158  AncestorType::pResults.resize(pSize);
159 
160  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
161  {
162  pValuesForTheCurrentYear[numSpace].resize(pSize);
163  }
164 
165  // Minimum power values of the cluster for the whole year - from the solver in the
166  // accurate mode not to be displayed in the output \todo think of a better place like
167  // the DispatchableMarginForAllAreas done at the beginning of the year
168 
169  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
170  {
171  pminOfTheClusterForYear[numSpace] = new double[pSize * HOURS_PER_YEAR];
172  }
173 
174  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
175  {
176  for (unsigned int i = 0; i != pSize; ++i)
177  {
178  pValuesForTheCurrentYear[numSpace][i].initializeFromStudy(*study);
179  }
180  }
181 
182  for (unsigned int i = 0; i != pSize; ++i)
183  {
184  AncestorType::pResults[i].initializeFromStudy(*study);
185  AncestorType::pResults[i].reset();
186  }
187  }
188  else
189  {
190  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
191  {
192  pminOfTheClusterForYear[numSpace] = nullptr;
193  }
194 
195  AncestorType::pResults.clear();
196  }
197  // Next
198  NextType::initializeFromArea(study, area);
199  }
200 
201  size_t getMaxNumberColumns() const
202  {
203  return pSize * ResultsType::count;
204  }
205 
206  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
207  {
208  // Next
209  NextType::initializeFromAreaLink(study, link);
210  }
211 
212  void simulationBegin()
213  {
214  // Next
215  NextType::simulationBegin();
216  }
217 
218  void simulationEnd()
219  {
220  NextType::simulationEnd();
221  }
222 
223  void yearBegin(unsigned int year, unsigned int numSpace)
224  {
225  // Reset the values for the current year
226  for (unsigned int i = 0; i != pSize; ++i)
227  {
228  pValuesForTheCurrentYear[numSpace][i].reset();
229 
230  for (unsigned int j = 0; j != HOURS_PER_YEAR; ++j)
231  {
232  pminOfTheClusterForYear[numSpace][i * HOURS_PER_YEAR + j] = 0;
233  }
234  }
235  // Next variable
236  NextType::yearBegin(year, numSpace);
237  }
238 
239  void yearEndBuildPrepareDataForEachThermalCluster(State& state,
240  uint year,
241  unsigned int numSpace)
242  {
243  for (unsigned int i = 0; i <= state.study.runtime.rangeLimits.hour[Data::rangeEnd]; ++i)
244  {
245  state.thermalClusterProductionForYear[i] += pValuesForTheCurrentYear
246  [numSpace]
247  [state.thermalCluster->enabledIndex]
248  .hour[i];
249  state.thermalClusterPMinOfTheClusterForYear[i] += pminOfTheClusterForYear
250  [numSpace][(state.thermalCluster->enabledIndex * HOURS_PER_YEAR) + i];
251  }
252 
253  // Next variable
254  NextType::yearEndBuildPrepareDataForEachThermalCluster(state, year, numSpace);
255  }
256 
257  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
258  {
259  // Next variable
260  NextType::yearEndBuild(state, year, numSpace);
261  }
262 
263  void yearEnd(unsigned int year, unsigned int numSpace)
264  {
265  // Merge all results for all thermal clusters
266  {
267  for (unsigned int i = 0; i < pSize; ++i)
268  {
269  // Compute all statistics for the current year (daily,weekly,monthly)
270  pValuesForTheCurrentYear[numSpace][i].computeStatisticsForTheCurrentYear();
271  }
272  }
273  // Next variable
274  NextType::yearEnd(year, numSpace);
275  }
276 
277  void computeSummary(unsigned int year, unsigned int numSpace)
278  {
279  for (unsigned int i = 0; i < pSize; ++i)
280  {
281  // Merge all those values with the global results
282  AncestorType::pResults[i].merge(year, pValuesForTheCurrentYear[numSpace][i]);
283  }
284 
285  // Next variable
286  NextType::computeSummary(year, numSpace);
287  }
288 
289  void hourBegin(unsigned int hourInTheYear)
290  {
291  // Next variable
292  NextType::hourBegin(hourInTheYear);
293  }
294 
295  void hourForEachArea(State& state, unsigned int numSpace)
296  {
297  auto& area = state.area;
298  auto& thermal = state.thermal;
299  for (auto& cluster: area->thermal.list.each_enabled())
300  {
301  // Production for this hour
302  pValuesForTheCurrentYear[numSpace][cluster->enabledIndex].hour[state.hourInTheYear]
303  += thermal[area->index].thermalClustersProductions[cluster->enabledIndex];
304 
305  pminOfTheClusterForYear[numSpace]
306  [(cluster->enabledIndex * HOURS_PER_YEAR) + state.hourInTheYear]
307  = thermal[area->index].PMinOfClusters[cluster->enabledIndex];
308  }
309 
310  // Next variable
311  NextType::hourForEachArea(state, numSpace);
312  }
313 
314  inline void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
315  {
316  // Ask to build the digest to the next variable
317  NextType::buildDigest(results, digestLevel, dataLevel);
318  }
319 
320  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
321  unsigned int column,
322  unsigned int numSpace) const
323  {
324  return pValuesForTheCurrentYear[numSpace][column].hour;
325  }
326 
327  void localBuildAnnualSurveyReport(SurveyResults& results,
328  int fileLevel,
329  int precision,
330  unsigned int numSpace) const
331  {
332  // Initializing external pointer on current variable non applicable status
333  results.isCurrentVarNA = AncestorType::isNonApplicable;
334 
335  if (AncestorType::isPrinted[0])
336  {
337  assert(NULL != results.data.area);
338  const auto& thermal = results.data.area->thermal;
339 
340  // Write the data for the current year
341  for (auto& cluster: thermal.list.each_enabled())
342  {
343  // Write the data for the current year
344  results.variableCaption = cluster->name(); // VCardType::Caption();
345  results.variableUnit = VCardType::Unit();
346  pValuesForTheCurrentYear[numSpace][cluster->enabledIndex]
347  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
348  }
349  }
350  }
351 
352 private:
354  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
355  double** pminOfTheClusterForYear;
356  size_t pSize;
357  unsigned int pNbYearsParallel;
358 
359 }; // class ProductionByDispatchablePlant
360 
361 } // namespace Antares::Solver::Variable::Economy
362 
363 #endif // __SOLVER_VARIABLE_ECONOMY_ProductionByDispatchablePlant_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Energy generated by all thermal dispatchable clusters.
Definition: productionByDispatchablePlant.h:91
@ count
How many items have we got.
Definition: productionByDispatchablePlant.h:109
NextT NextType
Type of the next static variable.
Definition: productionByDispatchablePlant.h:94
VCardProductionByDispatchablePlant VCardType
VCard.
Definition: productionByDispatchablePlant.h:96
Variable::IVariable< ProductionByDispatchablePlant< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: productionByDispatchablePlant.h:99
VCardType::ResultsType ResultsType
List of expected results.
Definition: productionByDispatchablePlant.h:102
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
Definition: variable.h:25
static std::string Description()
The short description of the variable.
Definition: productionByDispatchablePlant.h:43
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: productionByDispatchablePlant.h:57
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: productionByDispatchablePlant.h:59
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: productionByDispatchablePlant.h:76
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: productionByDispatchablePlant.h:74
static std::string Caption()
Caption.
Definition: productionByDispatchablePlant.h:31
static constexpr uint8_t precision
Precision (views)
Definition: productionByDispatchablePlant.h:62
VCardProductionByDispatchablePlant VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: productionByDispatchablePlant.h:54
static constexpr uint8_t decimal
Decimal precision.
Definition: productionByDispatchablePlant.h:66
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: productionByDispatchablePlant.h:70
static constexpr int columnCount
Number of columns used by the variable.
Definition: productionByDispatchablePlant.h:68
static std::string Unit()
Unit.
Definition: productionByDispatchablePlant.h:37
Results< R::AllYears::Average< > > ResultsType
The expecte results.
Definition: productionByDispatchablePlant.h:51
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: productionByDispatchablePlant.h:64