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