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_ECONOMY_OverallCost_H__
22 #define __SOLVER_VARIABLE_ECONOMY_OverallCost_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 "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 = state.study.runtime.rangeLimits.hour[Data::rangeBegin];
187  i <= state.study.runtime.rangeLimits.hour[Data::rangeEnd];
188  ++i)
189  {
190  pValuesForTheCurrentYear[numSpace][i] += state.thermalClusterOperatingCostForYear[i];
191  // Incrementing annual system cost (to be printed in output into a separate file)
192  state.annualSystemCost += state.thermalClusterOperatingCostForYear[i];
193  }
194 
195  // Next variable
196  NextType::yearEndBuildForEachThermalCluster(state, year, numSpace);
197  }
198 
199  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
200  {
201  // Next variable
202  NextType::yearEndBuild(state, year, numSpace);
203  }
204 
205  void yearEnd(unsigned int year, unsigned int numSpace)
206  {
207  // Compute all statistics for the current year (daily,weekly,monthly)
208  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
209 
210  // Next variable
211  NextType::yearEnd(year, numSpace);
212  }
213 
214  void computeSummary(unsigned int year, unsigned int numSpace)
215  {
216  // Merge all those values with the global results
217  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
218 
219  // Next variable
220  NextType::computeSummary(year, numSpace);
221  }
222 
223  void hourBegin(unsigned int hourInTheYear)
224  {
225  // Next variable
226  NextType::hourBegin(hourInTheYear);
227  }
228 
229  void hourForEachArea(State& state, unsigned int numSpace)
230  {
231  const double costForSpilledOrUnsuppliedEnergy =
232  // Total UnsupliedEnergy emissions
233  (state.hourlyResults->ValeursHorairesDeDefaillancePositive[state.hourInTheWeek]
234  * state.area->thermal.unsuppliedEnergyCost)
235  + (state.hourlyResults->ValeursHorairesDeDefaillanceNegative[state.hourInTheWeek]
236  * state.area->thermal.spilledEnergyCost);
237 
238  pValuesForTheCurrentYear[numSpace][state.hourInTheYear] += costForSpilledOrUnsuppliedEnergy;
239 
240  // Incrementing annual system cost (to be printed in output into a separate file)
241  state.annualSystemCost += costForSpilledOrUnsuppliedEnergy;
242 
243  // Next variable
244  NextType::hourForEachArea(state, numSpace);
245  }
246 
247  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
248  unsigned int,
249  unsigned int numSpace) const
250  {
251  return pValuesForTheCurrentYear[numSpace].hour;
252  }
253 
254  void localBuildAnnualSurveyReport(SurveyResults& results,
255  int fileLevel,
256  int precision,
257  unsigned int numSpace) const
258  {
259  // Initializing external pointer on current variable non applicable status
260  results.isCurrentVarNA = AncestorType::isNonApplicable;
261 
262  if (AncestorType::isPrinted[0])
263  {
264  // Write the data for the current year
265  results.variableCaption = VCardType::Caption();
266  results.variableUnit = VCardType::Unit();
267  pValuesForTheCurrentYear[numSpace]
268  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
269  }
270  }
271 
272 private:
274  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
275  unsigned int pNbYearsParallel;
276 
277 }; // class OverallCost
278 
279 } // namespace Antares::Solver::Variable::Economy
280 
281 #endif // __SOLVER_VARIABLE_ECONOMY_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
@ count
How many items have we got.
Definition: overallCost.h:111
VCardType::ResultsType ResultsType
List of expected results.
Definition: overallCost.h:104
VCardOverallCost VCardType
VCard.
Definition: overallCost.h:99
Variable::IVariable< OverallCost< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: overallCost.h:101
NextT NextType
Type of the next static variable.
Definition: overallCost.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 constexpr uint8_t precision
Precision (views)
Definition: overallCost.h:65
static constexpr uint8_t decimal
Decimal precision.
Definition: overallCost.h:69
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: overallCost.h:73
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: overallCost.h:77
VCardOverallCost VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: overallCost.h:56
static std::string Description()
The short description of the variable.
Definition: overallCost.h:43
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: overallCost.h:59
static std::string Caption()
Caption.
Definition: overallCost.h:31
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: overallCost.h:71
Results< R::AllYears::Average< >, R::AllYears::Average > ResultsType
The expecte results.
Definition: overallCost.h:53
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: overallCost.h:67
static std::string Unit()
Unit.
Definition: overallCost.h:37
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: overallCost.h:61
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: overallCost.h:79