Antares Simulator
Power System Simulator
priceCSR.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 "yuni/yuni.h"
30 
31 #include "../variable.h"
32 
33 namespace Antares::Solver::Variable::Economy
34 {
36 {
38  static std::string Caption()
39  {
40  return "MRG. PRICE CSR";
41  }
42 
44  static std::string Unit()
45  {
46  return "Euro";
47  }
48 
50  static std::string Description()
51  {
52  return "Marginal Price CSR, throughout all MC years";
53  }
54 
56  typedef Results<R::AllYears::Average< // The average values thoughout all years
57  R::AllYears::StdDeviation< // The standard deviation values throughout all years
58  R::AllYears::Min< // The minimum values thoughout all years
59  R::AllYears::Max< // The maximum values thoughout all years
60  >>>>>
62 
65 
67  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
69  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
70  & (Category::FileLevel::id
71  | Category::FileLevel::va);
73  static constexpr uint8_t precision = Category::all;
75  static constexpr uint8_t nodeDepthForGUI = +0;
77  static constexpr uint8_t decimal = 4;
79  static constexpr int columnCount = 1;
81  static constexpr uint8_t spatialAggregate = Category::spatialAggregateAverage;
82  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
83  static constexpr uint8_t spatialAggregatePostProcessing = Category::
84  spatialAggregatePostProcessingPrice;
86  static constexpr uint8_t hasIntermediateValues = 1;
88  static constexpr uint8_t isPossiblyNonApplicable = 0;
89 
91  typedef std::vector<IntermediateValues> IntermediateValuesType;
92 
93  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
94 
95 }; // class VCard
96 
100 template<class NextT = Container::EndOfList>
101 class PriceCSR: public Variable::IVariable<PriceCSR<NextT>, NextT, VCardPriceCSR>
102 {
103 public:
105  typedef NextT NextType;
110 
113 
115 
116  enum
117  {
119  count = 1 + NextT::count,
120  };
121 
122  template<int CDataLevel, int CFile>
123  struct Statistics
124  {
125  enum
126  {
127  count = ((VCardType::categoryDataLevel & CDataLevel
128  && VCardType::categoryFileLevel & CFile)
129  ? (NextType::template Statistics<CDataLevel, CFile>::count
131  : NextType::template Statistics<CDataLevel, CFile>::count),
132  };
133  };
134 
135 public:
136  void initializeFromStudy(Data::Study& study)
137  {
138  pNbYearsParallel = study.maxNbYearsInParallel;
139 
140  // Average thoughout all years
141  InitializeResultsFromStudy(AncestorType::pResults, study);
142 
143  // Intermediate values
144  pValuesForTheCurrentYear.resize(pNbYearsParallel);
145  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
146  {
147  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
148  }
149 
150  // Next
151  NextType::initializeFromStudy(study);
152  }
153 
154  template<class R>
155  static void InitializeResultsFromStudy(R& results, Data::Study& study)
156  {
157  VariableAccessorType::InitializeAndReset(results, study);
158  }
159 
160  void initializeFromArea(Data::Study* study, Data::Area* area)
161  {
162  // Next
163  NextType::initializeFromArea(study, area);
164  }
165 
166  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
167  {
168  // Next
169  NextType::initializeFromAreaLink(study, link);
170  }
171 
172  void simulationBegin()
173  {
174  // Next
175  NextType::simulationBegin();
176  }
177 
178  void simulationEnd()
179  {
180  NextType::simulationEnd();
181  }
182 
183  void yearBegin(uint year, unsigned int numSpace)
184  {
185  // Reset the values for the current year
186  pValuesForTheCurrentYear[numSpace].reset();
187  // Next variable
188  NextType::yearBegin(year, numSpace);
189  }
190 
191  void yearEndBuild(State& state, unsigned int year)
192  {
193  // Next variable
194  NextType::yearEndBuild(state, year);
195  }
196 
197  void yearEnd(uint year, unsigned int numSpace)
198  {
199  // Compute all statistics for the current year (daily,weekly,monthly)
200  pValuesForTheCurrentYear[numSpace].computeAveragesForCurrentYearFromHourlyResults();
201 
202  // Next variable
203  NextType::yearEnd(year, numSpace);
204  }
205 
206  void computeSummary(unsigned int year, unsigned int numSpace)
207  {
208  // Merge all those values with the global results
209  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
210 
211  // Next variable
212  NextType::computeSummary(year, numSpace);
213  }
214 
215  void hourBegin(uint hourInTheYear)
216  {
217  // Next variable
218  NextType::hourBegin(hourInTheYear);
219  }
220 
221  void hourForEachArea(State& state, unsigned int numSpace)
222  {
223  pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = -state.hourlyResults
224  ->CoutsMarginauxHorairesCSR
225  [state.hourInTheWeek];
226  // Next variable
227  NextType::hourForEachArea(state, numSpace);
228  }
229 
230  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
231  uint,
232  unsigned int numSpace) const
233  {
234  return pValuesForTheCurrentYear[numSpace].hour;
235  }
236 
237  void localBuildAnnualSurveyReport(SurveyResults& results,
238  int fileLevel,
239  int precision,
240  unsigned int numSpace) const
241  {
242  // Initializing external pointer on current variable non applicable status
243  results.isCurrentVarNA = AncestorType::isNonApplicable;
244 
245  if (AncestorType::isPrinted[0])
246  {
247  // Write the data for the current year
248  results.variableCaption = VCardType::Caption();
249  results.variableUnit = VCardType::Unit();
250  pValuesForTheCurrentYear[numSpace]
251  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
252  }
253  }
254 
255 private:
257  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
258  unsigned int pNbYearsParallel;
259 
260 }; // class PriceCSR
261 
262 } // namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal Price.
Definition: priceCSR.h:102
Variable::IVariable< PriceCSR< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: priceCSR.h:109
@ count
How many items have we got.
Definition: priceCSR.h:119
NextT NextType
Type of the next static variable.
Definition: priceCSR.h:105
VCardPriceCSR VCardType
VCard.
Definition: priceCSR.h:107
VCardType::ResultsType ResultsType
List of expected results.
Definition: priceCSR.h:112
Interface for any variable.
Definition: variable.h:47
const StoredResultType & results() const
The results.
Definition: variable.hxx:544
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 categoryDataLevel
Data Level.
Definition: priceCSR.h:67
static constexpr uint8_t decimal
Decimal precision.
Definition: priceCSR.h:77
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: priceCSR.h:69
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: priceCSR.h:75
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: priceCSR.h:79
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: priceCSR.h:86
VCardPrice VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: priceCSR.h:64
static constexpr uint8_t precision
Precision (views)
Definition: priceCSR.h:73
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: priceCSR.h:81
static std::string Unit()
Unit.
Definition: priceCSR.h:44
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: priceCSR.h:61
static std::string Description()
The short description of the variable.
Definition: priceCSR.h:50
static std::string Caption()
Caption.
Definition: priceCSR.h:38
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: priceCSR.h:88