Antares Simulator
Power System Simulator
congestionFee.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_CongestionFee_H__
22 #define __SOLVER_VARIABLE_ECONOMY_CongestionFee_H__
23 
24 #include "../../variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "CONG. FEE (ALG.)";
34  }
35 
37  static std::string Unit()
38  {
39  return "Euro";
40  }
41 
43  static std::string Description()
44  {
45  return "Congestion fee collected throughout all MC years (Alg.)";
46  }
47 
49  typedef Results<R::AllYears::Average< // The average values throughout all years
50  R::AllYears::StdDeviation< // The standard deviation values throughout all years
51  R::AllYears::Min< // The minimum values throughout all years
52  R::AllYears::Max< // The maximum values throughout all years
53  >>>>>
55 
57  static constexpr uint8_t categoryDataLevel = Category::DataLevel::link;
59  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
60  & (Category::FileLevel::id
61  | Category::FileLevel::va);
63  static constexpr uint8_t precision = Category::all;
65  static constexpr uint8_t nodeDepthForGUI = +0;
67  static constexpr uint8_t decimal = 0;
69  static constexpr int columnCount = 1;
71  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
72  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
73  static constexpr uint8_t spatialAggregatePostProcessing = 0;
75  static constexpr uint8_t hasIntermediateValues = 1;
77  static constexpr uint8_t isPossiblyNonApplicable = 0;
78 
80  typedef std::vector<IntermediateValues> IntermediateValuesType;
81 
82 }; // class VCard
83 
87 template<class NextT = Container::EndOfList>
88 class CongestionFee: public Variable::IVariable<CongestionFee<NextT>, NextT, VCardCongestionFee>
89 {
90 public:
92  typedef NextT NextType;
97 
100 
102 
103  enum
104  {
106  count = 1 + NextT::count,
107  };
108 
109  template<int CDataLevel, int CFile>
110  struct Statistics
111  {
112  enum
113  {
114  count = ((VCardType::categoryDataLevel & CDataLevel
115  && VCardType::categoryFileLevel & CFile)
116  ? (NextType::template Statistics<CDataLevel, CFile>::count
118  : NextType::template Statistics<CDataLevel, CFile>::count),
119  };
120  };
121 
122 public:
123  void initializeFromStudy(Data::Study& study)
124  {
125  pNbYearsParallel = study.maxNbYearsInParallel;
126 
127  // Average on all years
128  AncestorType::pResults.initializeFromStudy(study);
129  AncestorType::pResults.reset();
130 
131  // Intermediate values
132  pValuesForTheCurrentYear.resize(pNbYearsParallel);
133  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
134  {
135  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
136  }
137 
138  // Next
139  NextType::initializeFromStudy(study);
140  }
141 
142  void initializeFromArea(Data::Study* study, Data::Area* area)
143  {
144  // Next
145  NextType::initializeFromArea(study, area);
146  }
147 
148  void initializeFromAreaLink(Data::Study* study, Data::AreaLink* link)
149  {
150  // Next
151  NextType::initializeFromAreaLink(study, link);
152  }
153 
154  void simulationBegin()
155  {
156  // Next
157  NextType::simulationBegin();
158  }
159 
160  void simulationEnd()
161  {
162  NextType::simulationEnd();
163  }
164 
165  void yearBegin(uint year, unsigned int numSpace)
166  {
167  pValuesForTheCurrentYear[numSpace].reset();
168  // Next variable
169  NextType::yearBegin(year, numSpace);
170  }
171 
172  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
173  {
174  // Next variable
175  NextType::yearEndBuild(state, year, numSpace);
176  }
177 
178  void yearEnd(uint year, unsigned int numSpace)
179  {
180  // Compute all statistics for the current year (daily,weekly,monthly)
181  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
182 
183  // Next variable
184  NextType::yearEnd(year, numSpace);
185  }
186 
187  void computeSummary(unsigned int year, unsigned int numSpace)
188  {
189  // Merge all those values with the global results
190  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
191 
192  // Next variable
193  NextType::computeSummary(year, numSpace);
194  }
195 
196  void hourBegin(uint hourInTheYear)
197  {
198  // Next variable
199  NextType::hourBegin(hourInTheYear);
200  }
201 
202  void hourForEachArea(State& state, unsigned int numSpace)
203  {
204  // Next variable
205  NextType::hourForEachArea(state, numSpace);
206  }
207 
208  void hourForEachLink(State& state, unsigned int numSpace)
209  {
210 #define UPSTREAM_PRICE \
211  state.problemeHebdo->ResultatsHoraires[state.link->from->index] \
212  .CoutsMarginauxHoraires[state.hourInTheWeek]
213 #define DOWNSTREAM_PRICE \
214  state.problemeHebdo->ResultatsHoraires[state.link->with->index] \
215  .CoutsMarginauxHoraires[state.hourInTheWeek]
216 
217  // Congestion Fee
218  pValuesForTheCurrentYear[numSpace].hour[state.hourInTheYear] = state.ntc.ValeurDuFlux
219  [state.link->index]
220  * (UPSTREAM_PRICE
221  - DOWNSTREAM_PRICE);
222  // Next item in the list
223  NextType::hourForEachLink(state, numSpace);
224 
225 #undef UPSTREAM_PRICE
226 #undef DOWNSTREAM_PRICE
227  }
228 
229  void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
230  {
231  // Next
232  NextType::buildDigest(results, digestLevel, dataLevel);
233  }
234 
235  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
236  uint,
237  uint numSpace) const
238  {
239  return pValuesForTheCurrentYear[numSpace].hour;
240  }
241 
242  void localBuildAnnualSurveyReport(SurveyResults& results,
243  int fileLevel,
244  int precision,
245  uint numSpace) const
246  {
247  // Initializing external pointer on current variable non applicable status
248  results.isCurrentVarNA = AncestorType::isNonApplicable;
249 
250  if (AncestorType::isPrinted[0])
251  {
252  // Write the data for the current year
253  results.variableCaption = VCardType::Caption();
254  results.variableUnit = VCardType::Unit();
255  pValuesForTheCurrentYear[numSpace]
256  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
257  }
258  }
259 
260 private:
262  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
263  unsigned int pNbYearsParallel;
264 
265 }; // class CongestionFee
266 
267 } // namespace Antares::Solver::Variable::Economy
268 
269 #endif // __SOLVER_VARIABLE_ECONOMY_CongestionFee_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal CongestionFee.
Definition: congestionFee.h:89
VCardCongestionFee VCardType
VCard.
Definition: congestionFee.h:94
@ count
How many items have we got.
Definition: congestionFee.h:106
Variable::IVariable< CongestionFee< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: congestionFee.h:96
VCardType::ResultsType ResultsType
List of expected results.
Definition: congestionFee.h:99
NextT NextType
Type of the next static variable.
Definition: congestionFee.h:92
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 Unit()
Unit.
Definition: congestionFee.h:37
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: congestionFee.h:65
static constexpr uint8_t precision
Precision (views)
Definition: congestionFee.h:63
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: congestionFee.h:75
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: congestionFee.h:69
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: congestionFee.h:77
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: congestionFee.h:57
static std::string Description()
The short description of the variable.
Definition: congestionFee.h:43
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: congestionFee.h:71
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: congestionFee.h:54
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: congestionFee.h:59
static constexpr uint8_t decimal
Decimal precision.
Definition: congestionFee.h:67
static std::string Caption()
Caption.
Definition: congestionFee.h:31