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