Antares Simulator
Power System Simulator
max-mrg.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_MARGE_H__
22 #define __SOLVER_VARIABLE_ECONOMY_MARGE_H__
23 
24 #include "antares/solver/variable/variable.h"
25 
26 #include "max-mrg-utils.h"
27 
28 namespace Antares::Solver::Variable::Economy
29 {
30 struct VCardMARGE
31 {
33  static std::string Caption()
34  {
35  return "MAX MRG";
36  }
37 
39  static std::string Unit()
40  {
41  return "MWh";
42  }
43 
45  static std::string Description()
46  {
47  return "Maximum margin throughout all MC years";
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 
60 
62  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
64  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
65  & (Category::FileLevel::id
66  | Category::FileLevel::va);
68  static constexpr uint8_t precision = Category::all;
70  static constexpr uint8_t nodeDepthForGUI = +0;
72  static constexpr uint8_t decimal = 0;
74  static constexpr int columnCount = 1;
76  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
77  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
78  static constexpr uint8_t spatialAggregatePostProcessing = 0;
80  static constexpr uint8_t hasIntermediateValues = 1;
82  static constexpr uint8_t isPossiblyNonApplicable = 0;
83 
85  typedef std::vector<IntermediateValues> IntermediateValuesType;
86 
87  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
88 
89 }; // class VCard
90 
94 template<class NextT = Container::EndOfList>
95 class Marge: public Variable::IVariable<Marge<NextT>, NextT, VCardMARGE>
96 {
97 public:
99  typedef NextT NextType;
104 
107 
109 
110  enum
111  {
113  count = 1 + NextT::count,
114  };
115 
116  template<int CDataLevel, int CFile>
117  struct Statistics
118  {
119  enum
120  {
121  count = ((VCardType::categoryDataLevel & CDataLevel
122  && VCardType::categoryFileLevel & CFile)
123  ? (NextType::template Statistics<CDataLevel, CFile>::count
125  : NextType::template Statistics<CDataLevel, CFile>::count),
126  };
127  };
128 
129 public:
130  void initializeFromStudy(Data::Study& study)
131  {
132  pNbYearsParallel = study.maxNbYearsInParallel;
133 
134  // Intermediate values
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  // 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  // Next
174  NextType::simulationEnd();
175  }
176 
177  void yearBegin(unsigned int year, unsigned int numSpace)
178  {
179  // Reset the values for the current year
180  pValuesForTheCurrentYear[numSpace].reset();
181  // Next variable
182  NextType::yearBegin(year, numSpace);
183  }
184 
185  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
186  {
187  // Next variable
188  NextType::yearEndBuild(state, year, numSpace);
189  }
190 
191  void yearEnd(unsigned int year, unsigned int numSpace)
192  {
193  // Compute all statistics for the current year (daily,weekly,monthly)
194  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
195 
196  // Next variable
197  NextType::yearEnd(year, numSpace);
198  }
199 
200  void computeSummary(unsigned int year, unsigned int numSpace)
201  {
202  // Merge all those values with the global results
203  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
204 
205  // Next variable
206  NextType::computeSummary(year, numSpace);
207  }
208 
209  void hourBegin(unsigned int hourInTheYear)
210  {
211  // Next variable
212  NextType::hourBegin(hourInTheYear);
213  }
214 
215  void hourForEachArea(State& state, unsigned int numSpace)
216  {
217  // Next variable
218  NextType::hourForEachArea(state, numSpace);
219  }
220 
221  void weekForEachArea(State& state, unsigned int numSpace)
222  {
223  double* rawhourly = Memory::RawPointer(pValuesForTheCurrentYear[numSpace].hour);
224 
225  // Getting data required to compute max margin
226  MaxMrgUsualDataFactory maxMRGdataFactory(state, numSpace);
227  MaxMRGinput maxMRGinput = maxMRGdataFactory.data();
228  computeMaxMRG(rawhourly + state.hourInTheYear, maxMRGinput);
229 
230  // next
231  NextType::weekForEachArea(state, numSpace);
232  }
233 
234  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
235  unsigned int,
236  unsigned int numSpace) const
237  {
238  return pValuesForTheCurrentYear[numSpace].hour;
239  }
240 
241  void localBuildAnnualSurveyReport(SurveyResults& results,
242  int fileLevel,
243  int precision,
244  unsigned int numSpace) const
245  {
246  // Initializing external pointer on current variable non applicable status
247  results.isCurrentVarNA = AncestorType::isNonApplicable;
248 
249  if (AncestorType::isPrinted[0])
250  {
251  // Write the data for the current year
252  results.variableCaption = VCardType::Caption();
253  results.variableUnit = VCardType::Unit();
254  pValuesForTheCurrentYear[numSpace]
255  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
256  }
257  }
258 
259 private:
261  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
262  unsigned int pNbYearsParallel;
263 
264 }; // class Marge
265 
266 } // namespace Antares::Solver::Variable::Economy
267 
268 #endif // __SOLVER_VARIABLE_ECONOMY_MARGE_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Max MRG.
Definition: max-mrg.h:96
Variable::IVariable< Marge< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: max-mrg.h:103
VCardType::ResultsType ResultsType
List of expected results.
Definition: max-mrg.h:106
@ count
How many items have we got.
Definition: max-mrg.h:113
NextT NextType
Type of the next static variable.
Definition: max-mrg.h:99
VCardMARGE VCardType
VCard.
Definition: max-mrg.h:101
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 precision
Precision (views)
Definition: max-mrg.h:68
static constexpr uint8_t decimal
Decimal precision.
Definition: max-mrg.h:72
static std::string Description()
The short description of the variable.
Definition: max-mrg.h:45
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: max-mrg.h:70
VCardMARGE VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: max-mrg.h:59
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: max-mrg.h:80
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: max-mrg.h:64
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: max-mrg.h:62
static std::string Unit()
Unit.
Definition: max-mrg.h:39
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: max-mrg.h:56
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: max-mrg.h:82
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: max-mrg.h:76
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: max-mrg.h:74
static std::string Caption()
Caption.
Definition: max-mrg.h:33