Antares Simulator
Power System Simulator
overallCostCsr.h
1 /*
2 ** Copyright 2007-2023 RTE
3 ** Authors: Antares_Simulator Team
4 **
5 ** This file is part of Antares_Simulator.
6 **
7 ** Antares_Simulator is free software: you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation, either version 3 of the License, or
10 ** (at your option) any later version.
11 **
12 ** There are special exceptions to the terms and conditions of the
13 ** license as they are applied to this software. View the full text of
14 ** the exceptions in file COPYING.txt in the directory of this software
15 ** distribution
16 **
17 ** Antares_Simulator is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
21 **
22 ** You should have received a copy of the GNU General Public License
23 ** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
24 **
25 ** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
26 */
27 #pragma once
28 
29 #include "../variable.h"
30 
31 namespace Antares::Solver::Variable::Economy
32 {
34 {
36  static std::string Caption()
37  {
38  return "OV. COST CSR";
39  }
40 
42  static std::string Unit()
43  {
44  return "Euro";
45  }
46 
48  static std::string Description()
49  {
50  return "Overall Cost throughout all MC years";
51  }
52 
54  typedef Results<R::AllYears::Average< // The average values throughout all years
55  >,
56  R::AllYears::Average // Use these values for spatial cluster
57  >
59 
62 
63  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
65  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
66  & (Category::FileLevel::id
67  | Category::FileLevel::va);
69  static constexpr uint8_t precision = Category::all;
71  static constexpr uint8_t nodeDepthForGUI = +0;
73  static constexpr uint8_t decimal = 0;
75  static constexpr int columnCount = 1;
77  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
78  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
79  static constexpr uint8_t spatialAggregatePostProcessing = 0;
81  static constexpr uint8_t hasIntermediateValues = 1;
83  static constexpr uint8_t isPossiblyNonApplicable = 0;
84 
86  typedef std::vector<IntermediateValues> IntermediateValuesType;
87 
88  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
89 
90 }; // class VCard
91 
96 template<class NextT = Container::EndOfList>
97 class OverallCostCsr: public Variable::IVariable<OverallCostCsr<NextT>, NextT, VCardOverallCostCsr>
98 {
99 public:
101  typedef NextT NextType;
106 
109 
111 
112  enum
113  {
115  count = 1 + NextT::count,
116  };
117 
118  template<int CDataLevel, int CFile>
119  struct Statistics
120  {
121  enum
122  {
123  count = ((VCardType::categoryDataLevel & CDataLevel
124  && VCardType::categoryFileLevel & CFile)
125  ? (NextType::template Statistics<CDataLevel, CFile>::count
127  : NextType::template Statistics<CDataLevel, CFile>::count),
128  };
129  };
130 
131 public:
132  void initializeFromStudy(Data::Study& study)
133  {
134  pNbYearsParallel = study.maxNbYearsInParallel;
135 
136  // Intermediate values
137  InitializeResultsFromStudy(AncestorType::pResults, study);
138 
139  // Intermediate values
140  pValuesForTheCurrentYear.resize(pNbYearsParallel);
141  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
142  {
143  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
144  }
145 
146  NextType::initializeFromStudy(study);
147  }
148 
149  template<class R>
150  static void InitializeResultsFromStudy(R& results, Data::Study& study)
151  {
152  VariableAccessorType::InitializeAndReset(results, study);
153  }
154 
155  void yearBegin(unsigned int year, unsigned int numSpace)
156  {
157  // Reset the values for the current year
158  pValuesForTheCurrentYear[numSpace].reset();
159 
160  NextType::yearBegin(year, numSpace);
161  }
162 
163  void yearEndBuildForEachThermalCluster(State& state, uint year, unsigned int numSpace)
164  {
165  for (unsigned int i = state.study.runtime.rangeLimits.hour[Data::rangeBegin];
166  i <= state.study.runtime.rangeLimits.hour[Data::rangeEnd];
167  ++i)
168  {
169  pValuesForTheCurrentYear[numSpace][i] += state.thermalClusterOperatingCostForYear[i];
170  }
171 
172  NextType::yearEndBuildForEachThermalCluster(state, year, numSpace);
173  }
174 
175  void yearEnd(unsigned int year, unsigned int numSpace)
176  {
177  // Compute all statistics for the current year (daily, weekly, monthly)
178  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
179 
180  NextType::yearEnd(year, numSpace);
181  }
182 
183  void computeSummary(unsigned int year, unsigned int numSpace)
184  {
185  // Merge all those values with the global results
186  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
187 
188  // Next variable
189  NextType::computeSummary(year, numSpace);
190  }
191 
192  void hourForEachArea(State& state, unsigned int numSpace)
193  {
194  const double costForSpilledOrUnsuppliedEnergyCSR =
195  // Total UnsupliedEnergy emissions
196  (state.hourlyResults->ValeursHorairesDeDefaillancePositiveCSR[state.hourInTheWeek]
197  * state.area->thermal.unsuppliedEnergyCost)
198  + (state.hourlyResults->ValeursHorairesDeDefaillanceNegative[state.hourInTheWeek]
199  * state.area->thermal.spilledEnergyCost);
200 
201  pValuesForTheCurrentYear[numSpace][state.hourInTheYear]
202  += costForSpilledOrUnsuppliedEnergyCSR;
203 
204  NextType::hourForEachArea(state, numSpace);
205  }
206 
207  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
208  unsigned int,
209  unsigned int numSpace) const
210  {
211  return pValuesForTheCurrentYear[numSpace].hour;
212  }
213 
214  void localBuildAnnualSurveyReport(SurveyResults& results,
215  int fileLevel,
216  int precision,
217  unsigned int numSpace) const
218  {
219  // Initializing external pointer on current variable non applicable status
220  results.isCurrentVarNA = AncestorType::isNonApplicable;
221 
222  if (AncestorType::isPrinted[0])
223  {
224  // Write the data for the current year
225  results.variableCaption = VCardType::Caption();
226  results.variableUnit = VCardType::Unit();
227  pValuesForTheCurrentYear[numSpace]
228  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
229  }
230  }
231 
232 private:
234  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
235  unsigned int pNbYearsParallel;
236 
237 }; // class OverallCostCsr
238 
239 } // namespace Antares::Solver::Variable::Economy
Definition: study.h:57
C02 Average value of the overall OverallCostCsr emissions expected from all the thermal dispatchable ...
Definition: overallCostCsr.h:98
VCardOverallCostCsr VCardType
VCard.
Definition: overallCostCsr.h:103
VCardType::ResultsType ResultsType
List of expected results.
Definition: overallCostCsr.h:108
NextT NextType
Type of the next static variable.
Definition: overallCostCsr.h:101
@ count
How many items have we got.
Definition: overallCostCsr.h:115
Variable::IVariable< OverallCostCsr< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: overallCostCsr.h:105
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
VCardOverallCostCsr VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: overallCostCsr.h:61
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: overallCostCsr.h:77
Results< R::AllYears::Average< >, R::AllYears::Average > ResultsType
The expecte results.
Definition: overallCostCsr.h:58
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: overallCostCsr.h:83
static std::string Caption()
Caption.
Definition: overallCostCsr.h:36
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: overallCostCsr.h:65
static constexpr uint8_t precision
Precision (views)
Definition: overallCostCsr.h:69
static std::string Description()
The short description of the variable.
Definition: overallCostCsr.h:48
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: overallCostCsr.h:81
static std::string Unit()
Unit.
Definition: overallCostCsr.h:42
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: overallCostCsr.h:71
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: overallCostCsr.h:75
static constexpr uint8_t decimal
Decimal precision.
Definition: overallCostCsr.h:73