Antares Simulator
Power System Simulator
hurdleCosts.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_HURDLE_COSTS_H__
22 #define __SOLVER_VARIABLE_ECONOMY_HURDLE_COSTS_H__
23 
24 #include "../../variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "HURDLE COST";
34  }
35 
37  static std::string Unit()
38  {
39  return "Euro";
40  }
41 
43  static std::string Description()
44  {
45  return "Hurdle costs, over all MC years";
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 HurdleCosts: public Variable::IVariable<HurdleCosts<NextT>, NextT, VCardHurdleCosts>
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  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
157  {
158  pValuesForTheCurrentYear[numSpace].reset();
159  }
160  // Next
161  NextType::simulationBegin();
162  }
163 
164  void simulationEnd()
165  {
166  NextType::simulationEnd();
167  }
168 
169  void yearBegin(uint year, unsigned int numSpace)
170  {
171  // Reset
172  pValuesForTheCurrentYear[numSpace].reset();
173  // Next variable
174  NextType::yearBegin(year, numSpace);
175  }
176 
177  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
178  {
179  // Next variable
180  NextType::yearEndBuild(state, year, numSpace);
181  }
182 
183  void yearEnd(unsigned int year, unsigned int numSpace)
184  {
185  // Compute all statistics for the current year (daily,weekly,monthly)
186  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
187 
188  // Next variable
189  NextType::yearEnd(year, numSpace);
190  }
191 
192  void computeSummary(unsigned int year, unsigned int numSpace)
193  {
194  // Merge all those values with the global results
195  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
196 
197  // Next variable
198  NextType::computeSummary(year, numSpace);
199  }
200 
201  void hourForEachArea(State& state, unsigned int numSpace)
202  {
203  // Next variable
204  NextType::hourForEachArea(state, numSpace);
205  }
206 
207  void hourForEachLink(State& state, unsigned int numSpace)
208  {
209  // Flow assessed over all MC years (linear)
210  if (state.link->useHurdlesCost)
211  {
212  const double flowLinear = state.ntc.ValeurDuFlux[state.link->index];
213 
214  if (state.link->useLoopFlow)
215  {
216  const double loopFlow = state.problemeHebdo->ValeursDeNTC[state.hourInTheWeek]
217  .ValeurDeLoopFlowOrigineVersExtremite[state.link->index];
218  if (flowLinear - loopFlow > 0.)
219  {
220  const double hurdleCostDirect = (flowLinear - loopFlow)
221  * state.link->parameters
222  .entry[Data::fhlHurdlesCostDirect]
223  [state.hourInTheYear];
224  pValuesForTheCurrentYear[numSpace].hour[state.hourInTheYear]
225  += hurdleCostDirect;
226  // Incrementing annual system cost (to be printed in output in a separate file)
227  state.annualSystemCost += hurdleCostDirect;
228  }
229  else
230  {
231  const double hurdleCostIndirect = -(flowLinear - loopFlow)
232  * state.link->parameters
233  .entry[Data::fhlHurdlesCostIndirect]
234  [state.hourInTheYear];
235  pValuesForTheCurrentYear[numSpace].hour[state.hourInTheYear]
236  += hurdleCostIndirect;
237  // Incrementing annual system cost (to be printed in output into a separate
238  // file)
239  state.annualSystemCost += hurdleCostIndirect;
240  }
241  }
242  else
243  {
244  if (flowLinear > 0.)
245  {
246  const double hurdleCostDirect = flowLinear
247  * state.link->parameters
248  .entry[Data::fhlHurdlesCostDirect]
249  [state.hourInTheYear];
250  pValuesForTheCurrentYear[numSpace].hour[state.hourInTheYear]
251  += hurdleCostDirect;
252  // Incrementing annual system cost (to be printed in output in a separate file)
253  state.annualSystemCost += hurdleCostDirect;
254  }
255  else
256  {
257  const double hurdleCostIndirect = -flowLinear
258  * state.link->parameters
259  .entry[Data::fhlHurdlesCostIndirect]
260  [state.hourInTheYear];
261  pValuesForTheCurrentYear[numSpace].hour[state.hourInTheYear]
262  += hurdleCostIndirect;
263  // Incrementing annual system cost (to be printed in output into a separate
264  // file)
265  state.annualSystemCost += hurdleCostIndirect;
266  }
267  }
268  }
269  // Next item in the list
270  NextType::hourForEachLink(state, numSpace);
271  }
272 
273  void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
274  {
275  // Next
276  NextType::buildDigest(results, digestLevel, dataLevel);
277  }
278 
279  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
280  unsigned int,
281  unsigned int numSpace) const
282  {
283  return pValuesForTheCurrentYear[numSpace].hour;
284  }
285 
286  void localBuildAnnualSurveyReport(SurveyResults& results,
287  int fileLevel,
288  int precision,
289  unsigned int numSpace) const
290  {
291  // Initializing external pointer on current variable non applicable status
292  results.isCurrentVarNA = AncestorType::isNonApplicable;
293 
294  if (AncestorType::isPrinted[0])
295  {
296  // Write the data for the current year
297  results.variableCaption = VCardType::Caption();
298  results.variableUnit = VCardType::Unit();
299  pValuesForTheCurrentYear[numSpace]
300  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
301  }
302  }
303 
304 private:
306  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
307  unsigned int pNbYearsParallel;
308 }; // class HurdleCosts
309 
310 } // namespace Antares::Solver::Variable::Economy
311 
312 #endif // __SOLVER_VARIABLE_ECONOMY_HURDLE_COSTS_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal HurdleCosts.
Definition: hurdleCosts.h:89
Variable::IVariable< HurdleCosts< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: hurdleCosts.h:96
VCardType::ResultsType ResultsType
List of expected results.
Definition: hurdleCosts.h:99
@ count
How many items have we got.
Definition: hurdleCosts.h:106
NextT NextType
Type of the next static variable.
Definition: hurdleCosts.h:92
VCardHurdleCosts VCardType
VCard.
Definition: hurdleCosts.h:94
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 categoryDataLevel
Data Level.
Definition: hurdleCosts.h:57
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: hurdleCosts.h:75
static std::string Description()
The short description of the variable.
Definition: hurdleCosts.h:43
static std::string Unit()
Unit.
Definition: hurdleCosts.h:37
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: hurdleCosts.h:59
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: hurdleCosts.h:65
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: hurdleCosts.h:69
static std::string Caption()
Caption.
Definition: hurdleCosts.h:31
static constexpr uint8_t precision
Precision (views)
Definition: hurdleCosts.h:63
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: hurdleCosts.h:77
static constexpr uint8_t decimal
Decimal precision.
Definition: hurdleCosts.h:67
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: hurdleCosts.h:54
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: hurdleCosts.h:71