Antares Simulator
Power System Simulator
localMatchingRuleViolations.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_LMR_VIOLATIONS_H__
22 #define __SOLVER_VARIABLE_ECONOMY_LMR_VIOLATIONS_H__
23 
24 #include "antares/solver/variable/variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "LMR VIOL.";
34  }
35 
37  static std::string Unit()
38  {
39  return " ";
40  }
41 
43  static std::string Description()
44  {
45  return "Local Matching Rule is violated more than the provided threshold";
46  }
47 
49  typedef Results<R::AllYears::Average< // The average values throughout all years
50  >>
52 
55 
57  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
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  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
83 
84 }; // class VCard
85 
90 template<class NextT = Container::EndOfList>
91 class LMRViolations: public Variable::IVariable<LMRViolations<NextT>, NextT, VCardLMRViolations>
92 {
93 public:
95  typedef NextT NextType;
100 
103 
105 
106  enum
107  {
109  count = 1 + NextT::count,
110  };
111 
112  template<int CDataLevel, int CFile>
113  struct Statistics
114  {
115  enum
116  {
117  count = ((VCardType::categoryDataLevel & CDataLevel
118  && VCardType::categoryFileLevel & CFile)
119  ? (NextType::template Statistics<CDataLevel, CFile>::count
121  : NextType::template Statistics<CDataLevel, CFile>::count),
122  };
123  };
124 
125  void initializeFromStudy(Data::Study& study)
126  {
127  pNbYearsParallel = study.maxNbYearsInParallel;
128 
129  // Intermediate values
130  InitializeResultsFromStudy(AncestorType::pResults, study);
131 
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  template<class R>
143  static void InitializeResultsFromStudy(R& results, Data::Study& study)
144  {
145  VariableAccessorType::InitializeAndReset(results, study);
146  }
147 
148  void initializeFromArea(Data::Study* study, Data::Area* area)
149  {
150  // Next
151  NextType::initializeFromArea(study, area);
152  }
153 
154  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
155  {
156  // Next
157  NextType::initializeFromAreaLink(study, link);
158  }
159 
160  void simulationBegin()
161  {
162  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
163  {
164  pValuesForTheCurrentYear[numSpace].reset();
165  }
166  // Next
167  NextType::simulationBegin();
168  }
169 
170  void simulationEnd()
171  {
172  NextType::simulationEnd();
173  }
174 
175  void yearBegin(unsigned int year, unsigned int numSpace)
176  {
177  // Reset the values for the current year
178  pValuesForTheCurrentYear[numSpace].reset();
179  // Next variable
180  NextType::yearBegin(year, numSpace);
181  }
182 
183  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
184  {
185  // Next variable
186  NextType::yearEndBuild(state, year, numSpace);
187  }
188 
189  void yearEnd(unsigned int year, unsigned int numSpace)
190  {
191  // Compute all statistics for the current year (daily,weekly,monthly)
192  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
193 
194  // Next variable
195  NextType::yearEnd(year, numSpace);
196  }
197 
198  void computeSummary(unsigned int year, unsigned int numSpace)
199  {
200  // Merge all those values with the global results
201  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
202 
203  // Next variable
204  NextType::computeSummary(year, numSpace);
205  }
206 
207  void hourBegin(unsigned int hourInTheYear)
208  {
209  // Next variable
210  NextType::hourBegin(hourInTheYear);
211  }
212 
213  void hourForEachArea(State& state, unsigned int numSpace)
214  {
215  // Total LocalMatchingRule Violations
216  pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = state.hourlyResults
217  ->ValeursHorairesLmrViolations
218  [state.hourInTheWeek];
219 
220  // Next variable
221  NextType::hourForEachArea(state, numSpace);
222  }
223 
224  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
225  unsigned int,
226  unsigned int numSpace) const
227  {
228  return pValuesForTheCurrentYear[numSpace].hour;
229  }
230 
231  void localBuildAnnualSurveyReport(SurveyResults& results,
232  int fileLevel,
233  int precision,
234  unsigned int numSpace) const
235  {
236  // Initializing external pointer on current variable non applicable status
237  results.isCurrentVarNA = AncestorType::isNonApplicable;
238 
239  if (AncestorType::isPrinted[0])
240  {
241  // Write the data for the current year
242  results.variableCaption = VCardType::Caption();
243  results.variableUnit = VCardType::Unit();
244  pValuesForTheCurrentYear[numSpace]
245  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
246  }
247  }
248 
249 private:
251  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
252  unsigned int pNbYearsParallel;
253 
254 }; // class LMRViolations
255 
256 } // namespace Antares::Solver::Variable::Economy
257 
258 #endif // __SOLVER_VARIABLE_ECONOMY_LMR_VIOLATIONS_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
C02 Average value of the overrall CO2 emissions expected from all the thermal dispatchable clusters.
Definition: localMatchingRuleViolations.h:92
VCardType::ResultsType ResultsType
List of expected results.
Definition: localMatchingRuleViolations.h:102
VCardLMRViolations VCardType
VCard.
Definition: localMatchingRuleViolations.h:97
@ count
How many items have we got.
Definition: localMatchingRuleViolations.h:109
Variable::IVariable< LMRViolations< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: localMatchingRuleViolations.h:99
NextT NextType
Type of the next static variable.
Definition: localMatchingRuleViolations.h:95
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
Definition: localMatchingRuleViolations.h:114
Definition: localMatchingRuleViolations.h:29
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: localMatchingRuleViolations.h:69
static constexpr uint8_t decimal
Decimal precision.
Definition: localMatchingRuleViolations.h:67
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: localMatchingRuleViolations.h:59
static std::string Description()
The short description of the variable.
Definition: localMatchingRuleViolations.h:43
static std::string Caption()
Caption.
Definition: localMatchingRuleViolations.h:31
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: localMatchingRuleViolations.h:75
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: localMatchingRuleViolations.h:77
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: localMatchingRuleViolations.h:57
static std::string Unit()
Unit.
Definition: localMatchingRuleViolations.h:37
Results< R::AllYears::Average< > > ResultsType
The expecte results.
Definition: localMatchingRuleViolations.h:51
VCardLMRViolations VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: localMatchingRuleViolations.h:54
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: localMatchingRuleViolations.h:71
static constexpr uint8_t precision
Precision (views)
Definition: localMatchingRuleViolations.h:63
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: localMatchingRuleViolations.h:65