Antares Simulator
Power System Simulator
overallCost.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_ADEQUACY_OverallCost_H__
22 #define __SOLVER_VARIABLE_ADEQUACY_OverallCost_H__
23 
24 #include "antares/solver/variable/variable.h"
25 
26 namespace Antares::Solver::Variable::Adequacy
27 {
29 {
31  static std::string Caption()
32  {
33  return "OV. COST";
34  }
35 
37  static std::string Unit()
38  {
39  return "Euro";
40  }
41 
43  static std::string Description()
44  {
45  return "Overall Cost throughout all MC years";
46  }
47 
49  typedef Results<R::AllYears::Average< // The average values throughout all years
50  >,
51  R::AllYears::Average // Use these values for spatial cluster
52  >
54 
57 
59  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
61  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
62  & (Category::FileLevel::id
63  | Category::FileLevel::va);
65  static constexpr uint8_t precision = Category::all;
67  static constexpr uint8_t nodeDepthForGUI = +0;
69  static constexpr uint8_t decimal = 0;
71  static constexpr int columnCount = 1;
73  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
74  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
75  static constexpr uint8_t spatialAggregatePostProcessing = 0;
77  static constexpr uint8_t hasIntermediateValues = 1;
79  static constexpr uint8_t isPossiblyNonApplicable = 0;
80 
82  typedef std::vector<IntermediateValues> IntermediateValuesType;
83 
84  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
85 
86 }; // class VCard
87 
92 template<class NextT = Container::EndOfList>
93 class OverallCost: public Variable::IVariable<OverallCost<NextT>, NextT, VCardOverallCost>
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 public:
128  void initializeFromStudy(Data::Study& study)
129  {
130  pNbYearsParallel = study.maxNbYearsInParallel;
131 
132  // Intermediate values
133  InitializeResultsFromStudy(AncestorType::pResults, study);
134 
135  // Intermediate values
136  pValuesForTheCurrentYear.resize(pNbYearsParallel);
137  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
138  {
139  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
140  }
141 
142  // Next
143  NextType::initializeFromStudy(study);
144  }
145 
146  template<class R>
147  static void InitializeResultsFromStudy(R& results, Data::Study& study)
148  {
149  VariableAccessorType::InitializeAndReset(results, study);
150  }
151 
152  void initializeFromArea(Data::Study* study, Data::Area* area)
153  {
154  // Next
155  NextType::initializeFromArea(study, area);
156  }
157 
158  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
159  {
160  // Next
161  NextType::initializeFromAreaLink(study, link);
162  }
163 
164  void simulationBegin()
165  {
166  // Next
167  NextType::simulationBegin();
168  }
169 
170  void simulationEnd()
171  {
172  NextType::simulationEnd();
173  }
174 
175  void yearBegin(unsigned int year, unsigned int numSpace)
176  {
177  // Reset the values for the current year
178  pValuesForTheCurrentYear[numSpace].reset();
179  // Next variable
180  NextType::yearBegin(year, numSpace);
181  }
182 
183  void yearEndBuildForEachThermalCluster(State& state, uint year, unsigned int numSpace)
184  {
185  // Get end year calculations
186  for (unsigned int i = 0; i < state.study.runtime.rangeLimits.hour[Data::rangeCount]; ++i)
187  {
188  pValuesForTheCurrentYear[numSpace][i] += state.thermalClusterOperatingCostForYear[i];
189  }
190 
191  // Next variable
192  NextType::yearEndBuildForEachThermalCluster(state, year, numSpace);
193  }
194 
195  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
196  {
197  // Next variable
198  NextType::yearEndBuild(state, year, numSpace);
199  }
200 
201  void yearEnd(unsigned int year, unsigned int numSpace)
202  {
203  // Compute all statistics for the current year (daily,weekly,monthly)
204  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
205 
206  // Next variable
207  NextType::yearEnd(year, numSpace);
208  }
209 
210  void computeSummary(unsigned int year, unsigned int numSpace)
211  {
212  // Merge all those values with the global results
213  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
214 
215  // Next variable
216  NextType::computeSummary(year, numSpace);
217  }
218 
219  void hourBegin(unsigned int hourInTheYear)
220  {
221  // Next variable
222  NextType::hourBegin(hourInTheYear);
223  }
224 
225  void hourForEachArea(State& state, unsigned int numSpace)
226  {
227  auto area = state.area;
228  auto& thermal = state.thermal;
229  // Total UnsupliedEnergy emissions
230  pValuesForTheCurrentYear[numSpace][state.hourInTheYear] +=
231  // Current Hydro Storage generation
232  (state.hourlyResults->ValeursHorairesDeDefaillancePositive[state.hourInTheWeek]
233  * area->thermal.unsuppliedEnergyCost)
234  + ((state.hourlyResults->ValeursHorairesDeDefaillanceNegative[state.hourInTheWeek]
235  + state.resSpilled.entry[area->index][state.hourInTheWeek])
236  * area->thermal.spilledEnergyCost);
237 
238  // Hydro costs : water value and pumping
239  pValuesForTheCurrentYear[numSpace].hour[state.hourInTheYear]
240  += state.problemeHebdo->CaracteristiquesHydrauliques[state.area->index]
241  .WeeklyWaterValueStateRegular
242  * (state.hourlyResults->TurbinageHoraire[state.hourInTheWeek]
243  - area->hydro.pumpingEfficiency
244  * state.hourlyResults->PompageHoraire[state.hourInTheWeek]);
245 
246  // Thermal costs
247  for (auto& cluster: area->thermal.list.each_enabled())
248  {
249  pValuesForTheCurrentYear[numSpace][state.hourInTheYear]
250  += thermal[area->index].thermalClustersOperatingCost[cluster->enabledIndex];
251  }
252 
253  // Next variable
254  NextType::hourForEachArea(state, numSpace);
255  }
256 
257  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
258  unsigned int,
259  unsigned int numSpace) const
260  {
261  return pValuesForTheCurrentYear[numSpace].hour;
262  }
263 
264  void localBuildAnnualSurveyReport(SurveyResults& results,
265  int fileLevel,
266  int precision,
267  unsigned int numSpace) const
268  {
269  // Initializing external pointer on current variable non applicable status
270  results.isCurrentVarNA = AncestorType::isNonApplicable;
271 
272  if (AncestorType::isPrinted[0])
273  {
274  // Write the data for the current year
275  results.variableCaption = VCardType::Caption();
276  results.variableUnit = VCardType::Unit();
277 
278  pValuesForTheCurrentYear[numSpace]
279  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
280  }
281  }
282 
283 private:
285  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
286  unsigned int pNbYearsParallel;
287 }; // class OverallCost
288 
289 } // namespace Antares::Solver::Variable::Adequacy
290 
291 #endif // __SOLVER_VARIABLE_ADEQUACY_OverallCost_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
C02 Average value of the overrall OverallCost emissions expected from all the thermal dispatchable cl...
Definition: overallCost.h:94
Variable::IVariable< OverallCost< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: overallCost.h:101
VCardOverallCost VCardType
VCard.
Definition: overallCost.h:99
VCardType::ResultsType ResultsType
List of expected results.
Definition: overallCost.h:104
NextT NextType
Type of the next static variable.
Definition: overallCost.h:97
@ count
How many items have we got.
Definition: overallCost.h:111
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: overallCost.h:31
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: overallCost.h:79
static std::string Unit()
Unit.
Definition: overallCost.h:37
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: overallCost.h:73
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: overallCost.h:67
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: overallCost.h:77
Results< R::AllYears::Average< >, R::AllYears::Average > ResultsType
The expecte results.
Definition: overallCost.h:53
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: overallCost.h:71
VCardOverallCost VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: overallCost.h:56
static constexpr uint8_t precision
Precision (views)
Definition: overallCost.h:65
static std::string Description()
The short description of the variable.
Definition: overallCost.h:43
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: overallCost.h:61
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: overallCost.h:59
static constexpr uint8_t decimal
Decimal precision.
Definition: overallCost.h:69