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