Antares Simulator
Power System Simulator
max-mrg-csr.h
1 /*
2 ** Copyright 2007-2023 RTE
3 ** Authors: Antares_Simulator Team
4 **
5 ** This file is part of Antares_Simulator.
6 **
7 ** Antares_Simulator is free software: you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation, either version 3 of the License, or
10 ** (at your option) any later version.
11 **
12 ** There are special exceptions to the terms and conditions of the
13 ** license as they are applied to this software. View the full text of
14 ** the exceptions in file COPYING.txt in the directory of this software
15 ** distribution
16 **
17 ** Antares_Simulator is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
21 **
22 ** You should have received a copy of the GNU General Public License
23 ** along with Antares_Simulator. If not, see <http://www.gnu.org/licenses/>.
24 **
25 ** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
26 */
27 #pragma once
28 
29 #include "../variable.h"
30 #include "max-mrg-utils.h"
31 
32 namespace Antares::Solver::Variable::Economy
33 {
35 {
37  static std::string Caption()
38  {
39  return "MAX MRG CSR";
40  }
41 
43  static std::string Unit()
44  {
45  return "MWh";
46  }
47 
49  static std::string Description()
50  {
51  return "Max margin for CSR";
52  }
53 
55  typedef Results<R::AllYears::Average< // The average values throughout all years
56  R::AllYears::StdDeviation< // The standard deviation values throughout all years
57  R::AllYears::Min< // The minimum values throughout all years
58  R::AllYears::Max< // The maximum values throughout all years
59  >>>>>
61 
64 
65  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
67  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
68  & (Category::FileLevel::id
69  | Category::FileLevel::va);
71  static constexpr uint8_t precision = Category::all;
73  static constexpr uint8_t nodeDepthForGUI = +0;
75  static constexpr uint8_t decimal = 0;
77  static constexpr int columnCount = 1;
79  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
80  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
81  static constexpr uint8_t spatialAggregatePostProcessing = 0;
83  static constexpr uint8_t hasIntermediateValues = 1;
85  static constexpr uint8_t isPossiblyNonApplicable = 0;
86 
88  typedef std::vector<IntermediateValues> IntermediateValuesType;
89 
90  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
91 
92 }; // class VCard
93 
97 template<bool WithSimplexT>
98 void PrepareMaxMRGFor(const State& state, double* opmrg, uint numSpace);
99 
103 template<class NextT = Container::EndOfList>
104 class MaxMrgCsr: public Variable::IVariable<MaxMrgCsr<NextT>, NextT, VCardMAX_MRG_CSR>
105 {
106 public:
108  typedef NextT NextType;
113 
116 
118 
119  enum
120  {
122  count = 1 + NextT::count,
123  };
124 
125  template<int CDataLevel, int CFile>
126  struct Statistics
127  {
128  enum
129  {
130  count = ((VCardType::categoryDataLevel & CDataLevel
131  && VCardType::categoryFileLevel & CFile)
132  ? (NextType::template Statistics<CDataLevel, CFile>::count
134  : NextType::template Statistics<CDataLevel, CFile>::count),
135  };
136  };
137 
138 public:
139  void initializeFromStudy(Data::Study& study)
140  {
141  pNbYearsParallel = study.maxNbYearsInParallel;
142 
143  // Intermediate values
144  InitializeResultsFromStudy(AncestorType::pResults, study);
145 
146  pValuesForTheCurrentYear.resize(pNbYearsParallel);
147  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
148  {
149  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
150  }
151 
152  // Next
153  NextType::initializeFromStudy(study);
154  }
155 
156  template<class R>
157  static void InitializeResultsFromStudy(R& results, Data::Study& study)
158  {
159  VariableAccessorType::InitializeAndReset(results, study);
160  }
161 
162  void yearBegin(unsigned int year, unsigned int numSpace)
163  {
164  // Reset the values for the current year
165  pValuesForTheCurrentYear[numSpace].reset();
166  // Next variable
167  NextType::yearBegin(year, numSpace);
168  }
169 
170  void yearEnd(unsigned int year, unsigned int numSpace)
171  {
172  // Compute all statistics for the current year (daily,weekly,monthly)
173  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
174 
175  // Next variable
176  NextType::yearEnd(year, numSpace);
177  }
178 
179  void computeSummary(unsigned int year, unsigned int numSpace)
180  {
181  // Merge all those values with the global results
182  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
183 
184  // Next variable
185  NextType::computeSummary(year, numSpace);
186  }
187 
188  void weekForEachArea(State& state, unsigned int numSpace)
189  {
190  double* rawhourly = Memory::RawPointer(pValuesForTheCurrentYear[numSpace].hour);
191 
192  // Getting data required to compute max margin
193  MaxMrgCSRdataFactory maxMRGcsrDataFactory(state, numSpace);
194  MaxMRGinput maxMRGinput = maxMRGcsrDataFactory.data();
195  computeMaxMRG(rawhourly + state.hourInTheYear, maxMRGinput);
196 
197  // next
198  NextType::weekForEachArea(state, numSpace);
199  }
200 
201  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
202  unsigned int,
203  unsigned int numSpace) const
204  {
205  return pValuesForTheCurrentYear[numSpace].hour;
206  }
207 
208  void localBuildAnnualSurveyReport(SurveyResults& results,
209  int fileLevel,
210  int precision,
211  unsigned int numSpace) const
212  {
213  // Initializing external pointer on current variable non applicable status
214  results.isCurrentVarNA = AncestorType::isNonApplicable;
215 
216  if (AncestorType::isPrinted[0])
217  {
218  // Write the data for the current year
219  results.variableCaption = VCardType::Caption();
220  results.variableUnit = VCardType::Unit();
221  pValuesForTheCurrentYear[numSpace]
222  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
223  }
224  }
225 
226 private:
228  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
229  unsigned int pNbYearsParallel;
230 
231 }; // class MaxMrgCsr
232 
233 } // namespace Antares::Solver::Variable::Economy
Definition: study.h:57
Max MRG.
Definition: max-mrg-csr.h:105
VCardMAX_MRG_CSR VCardType
VCard.
Definition: max-mrg-csr.h:110
Variable::IVariable< MaxMrgCsr< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: max-mrg-csr.h:112
VCardType::ResultsType ResultsType
List of expected results.
Definition: max-mrg-csr.h:115
@ count
How many items have we got.
Definition: max-mrg-csr.h:122
NextT NextType
Type of the next static variable.
Definition: max-mrg-csr.h:108
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: state.h:71
Definition: cbuilder.h:120
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: max-mrg-csr.h:60
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: max-mrg-csr.h:79
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: max-mrg-csr.h:73
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: max-mrg-csr.h:83
static std::string Unit()
Unit.
Definition: max-mrg-csr.h:43
static std::string Description()
The short description of the variable.
Definition: max-mrg-csr.h:49
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: max-mrg-csr.h:77
static std::string Caption()
Caption.
Definition: max-mrg-csr.h:37
static constexpr uint8_t precision
Precision (views)
Definition: max-mrg-csr.h:71
VCardMAX_MRG_CSR VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: max-mrg-csr.h:63
static constexpr uint8_t decimal
Decimal precision.
Definition: max-mrg-csr.h:75
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: max-mrg-csr.h:67
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: max-mrg-csr.h:85