Antares Simulator
Power System Simulator
nearPriceCap.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 #pragma once
22 
23 #include "antares/solver/variable/variable.h"
24 
25 namespace Antares::Solver::Variable::Economy
26 {
27 
28 constexpr double eps = 1e-2;
29 constexpr double margin = 5.;
30 
32 {
34  static std::string Caption()
35  {
36  return "NPCAP HOURS";
37  }
38 
40  static std::string Unit()
41  {
42  return "Hours";
43  }
44 
46  static std::string Description()
47  {
48  return "Near Price Cap Hours";
49  }
50 
52  typedef Results<R::AllYears::Average< // The average values throughout all years
53  R::AllYears::StdDeviation< // The standard deviation values throughout all years
54  R::AllYears::Min< // The minimum values throughout all years
55  R::AllYears::Max< // The maximum values throughout all years
56  >>>>>
58 
61 
63  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
65  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
66  & (Category::FileLevel::id
67  | Category::FileLevel::va);
69  static constexpr uint8_t precision = Category::all;
71  static constexpr uint8_t nodeDepthForGUI = +0;
73  static constexpr uint8_t decimal = 4;
75  static constexpr int columnCount = 1;
77  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSumThen1IfPositive;
78  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
79  static constexpr uint8_t spatialAggregatePostProcessing = 0;
81  static constexpr uint8_t hasIntermediateValues = 1;
83  static constexpr uint8_t isPossiblyNonApplicable = 0;
84 
86  typedef std::vector<IntermediateValues> IntermediateValuesType;
87 
88  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
89 
90 }; // class VCardNearPriceCap
91 
95 template<class NextT = Container::EndOfList>
96 class NearPriceCap: public Variable::IVariable<NearPriceCap<NextT>, NextT, VCardNearPriceCap>
97 {
98 public:
100  typedef NextT NextType;
105 
108 
110 
111  enum
112  {
114  count = 1 + NextT::count,
115  };
116 
117  template<int CDataLevel, int CFile>
118  struct Statistics
119  {
120  enum
121  {
122  count = ((VCardType::categoryDataLevel & CDataLevel
123  && VCardType::categoryFileLevel & CFile)
124  ? (NextType::template Statistics<CDataLevel, CFile>::count
126  : NextType::template Statistics<CDataLevel, CFile>::count),
127  };
128  };
129 
130 public:
131  void initializeFromStudy(Data::Study& study)
132  {
133  pNbYearsParallel = study.maxNbYearsInParallel;
134 
135  InitializeResultsFromStudy(AncestorType::pResults, study);
136 
137  pValuesForTheCurrentYear.resize(pNbYearsParallel);
138  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
139  {
140  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
141  }
142 
143  NextType::initializeFromStudy(study);
144  }
145 
146  template<class R>
147  static void InitializeResultsFromStudy(R& results, Data::Study& study)
148  {
149  VariableAccessorType::InitializeAndReset(results, study);
150  }
151 
152  void initializeFromArea(Data::Study* study, Data::Area* area)
153  {
154  unsuppliedEnergyCost = area->thermal.unsuppliedEnergyCost;
155 
156  NextType::initializeFromArea(study, area);
157  }
158 
159  void simulationBegin()
160  {
161  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
162  {
163  pValuesForTheCurrentYear[numSpace].reset();
164  }
165  NextType::simulationBegin();
166  }
167 
168  void yearBegin(unsigned int year, unsigned int numSpace)
169  {
170  // Reset the values for the current year
171  pValuesForTheCurrentYear[numSpace].reset();
172 
173  NextType::yearBegin(year, numSpace);
174  }
175 
176  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
177  {
178  NextType::yearEndBuild(state, year, numSpace);
179  }
180 
181  void yearEnd(unsigned int year, unsigned int numSpace)
182  {
183  // Time related aggregations to daily, weekly, monthly and annual results
184  // are computed by summing hourly results
185  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
186 
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 hourForEachArea(State& state, unsigned int numSpace)
200  {
201  double mrgPrice = -state.hourlyResults->CoutsMarginauxHoraires[state.hourInTheWeek];
202  if (mrgPrice > unsuppliedEnergyCost - margin + eps)
203  {
204  pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = 1.;
205  }
206  NextType::hourForEachArea(state, numSpace);
207  }
208 
209  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
210  unsigned int,
211  unsigned int numSpace) const
212  {
213  return pValuesForTheCurrentYear[numSpace].hour;
214  }
215 
216  void localBuildAnnualSurveyReport(SurveyResults& results,
217  int fileLevel,
218  int precision,
219  unsigned int numSpace) const
220  {
221  // Initializing external pointer on current variable non applicable status
222  results.isCurrentVarNA = AncestorType::isNonApplicable;
223 
224  if (AncestorType::isPrinted[0])
225  {
226  // Write the data for the current year
227  results.variableCaption = VCardType::Caption();
228  results.variableUnit = VCardType::Unit();
229  pValuesForTheCurrentYear[numSpace]
230  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
231  }
232  }
233 
234 private:
236  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
237  unsigned int pNbYearsParallel;
238  double unsuppliedEnergyCost = 0.;
239 }; // class NearPriceCap
240 
241 } // namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
NextT NextType
Type of the next static variable.
Definition: nearPriceCap.h:100
Variable::IVariable< NearPriceCap< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: nearPriceCap.h:104
VCardType::ResultsType ResultsType
List of expected results.
Definition: nearPriceCap.h:107
VCardNearPriceCap VCardType
VCard.
Definition: nearPriceCap.h:102
@ count
How many items have we got.
Definition: nearPriceCap.h:114
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 Caption()
Caption.
Definition: nearPriceCap.h:34
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: nearPriceCap.h:81
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: nearPriceCap.h:83
static std::string Description()
The short description of the variable.
Definition: nearPriceCap.h:46
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: nearPriceCap.h:75
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: nearPriceCap.h:63
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: nearPriceCap.h:65
static constexpr uint8_t decimal
Decimal precision.
Definition: nearPriceCap.h:73
static std::string Unit()
Unit.
Definition: nearPriceCap.h:40
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: nearPriceCap.h:71
VCardNearPriceCap VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: nearPriceCap.h:60
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: nearPriceCap.h:57
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: nearPriceCap.h:77
static constexpr uint8_t precision
Precision (views)
Definition: nearPriceCap.h:69