Antares Simulator
Power System Simulator
unsupliedEnergyCsr.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 {
28 {
30  static std::string Caption()
31  {
32  return "UNSP. ENRG CSR";
33  }
34 
36  static std::string Unit()
37  {
38  return "MWh";
39  }
40 
42  static std::string Description()
43  {
44  return "Unsuplied Energy after CSR (demand that cannot be satisfied)";
45  }
46 
48  typedef Results<R::AllYears::Average< // The average values throughout all years
49  R::AllYears::StdDeviation< // The standard deviation values throughout all years
50  R::AllYears::Min< // The minimum values throughout all years
51  R::AllYears::Max< // The maximum values throughout all years
52  >>>>>
54 
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 
86 template<class NextT = Container::EndOfList>
88  : public Variable::IVariable<UnsupliedEnergyCSR<NextT>, NextT, VCardUnsupliedEnergyCSR>
89 {
90 public:
92  typedef NextT NextType;
97 
100 
102 
103  enum
104  {
106  count = 1 + NextT::count,
107  };
108 
109  template<int CDataLevel, int CFile>
110  struct Statistics
111  {
112  enum
113  {
114  count = ((VCardType::categoryDataLevel & CDataLevel
115  && VCardType::categoryFileLevel & CFile)
116  ? (NextType::template Statistics<CDataLevel, CFile>::count
118  : NextType::template Statistics<CDataLevel, CFile>::count),
119  };
120  };
121 
122 public:
123  void initializeFromStudy(Data::Study& study)
124  {
125  pNbYearsParallel = study.maxNbYearsInParallel;
126 
127  // Intermediate values
128  InitializeResultsFromStudy(AncestorType::pResults, study);
129 
130  pValuesForTheCurrentYear.resize(pNbYearsParallel);
131  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
132  {
133  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
134  }
135 
136  // Next
137  NextType::initializeFromStudy(study);
138  }
139 
140  template<class R>
141  static void InitializeResultsFromStudy(R& results, Data::Study& study)
142  {
143  VariableAccessorType::InitializeAndReset(results, study);
144  }
145 
146  void initializeFromArea(Data::Study* study, Data::Area* area)
147  {
148  // Next
149  NextType::initializeFromArea(study, area);
150  }
151 
152  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
153  {
154  // Next
155  NextType::initializeFromAreaLink(study, link);
156  }
157 
158  void simulationBegin()
159  {
160  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
161  {
162  pValuesForTheCurrentYear[numSpace].reset();
163  }
164  // Next
165  NextType::simulationBegin();
166  }
167 
168  void simulationEnd()
169  {
170  NextType::simulationEnd();
171  }
172 
173  void yearBegin(unsigned int year, unsigned int numSpace)
174  {
175  // Reset the values for the current year
176  pValuesForTheCurrentYear[numSpace].reset();
177 
178  // Next variable
179  NextType::yearBegin(year, numSpace);
180  }
181 
182  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
183  {
184  // Next variable
185  NextType::yearEndBuild(state, year, numSpace);
186  }
187 
188  void yearEnd(unsigned int year, unsigned int numSpace)
189  {
190  // Compute all statistics for the current year (daily,weekly,monthly)
191  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
192 
193  // Next variable
194  NextType::yearEnd(year, numSpace);
195  }
196 
197  void computeSummary(unsigned int year, unsigned int numSpace)
198  {
199  // Merge all those values with the global results
200  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
201 
202  // Next variable
203  NextType::computeSummary(year, numSpace);
204  }
205 
206  void hourBegin(unsigned int hourInTheYear)
207  {
208  // Next variable
209  NextType::hourBegin(hourInTheYear);
210  }
211 
212  void hourForEachArea(State& state, unsigned int numSpace)
213  {
214  pValuesForTheCurrentYear[numSpace][state.hourInTheYear]
215  = state.hourlyResults->ValeursHorairesDeDefaillancePositiveCSR[state.hourInTheWeek];
216  // Next variable
217  NextType::hourForEachArea(state, numSpace);
218  }
219 
220  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
221  unsigned int,
222  unsigned int numSpace) const
223  {
224  return pValuesForTheCurrentYear[numSpace].hour;
225  }
226 
227  void localBuildAnnualSurveyReport(SurveyResults& results,
228  int fileLevel,
229  int precision,
230  unsigned int numSpace) const
231  {
232  // Initializing external pointer on current variable non applicable status
233  results.isCurrentVarNA = AncestorType::isNonApplicable;
234 
235  if (AncestorType::isPrinted[0])
236  {
237  // Write the data for the current year
238  results.variableCaption = VCardType::Caption();
239  results.variableUnit = VCardType::Unit();
240  pValuesForTheCurrentYear[numSpace]
241  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
242  }
243  }
244 
245 private:
247  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
248  unsigned int pNbYearsParallel;
249 
250 }; // class UnsupliedEnergyCSR
251 
252 } // namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Variable::IVariable< UnsupliedEnergyCSR< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: unsupliedEnergyCsr.h:96
NextT NextType
Type of the next static variable.
Definition: unsupliedEnergyCsr.h:92
VCardType::ResultsType ResultsType
List of expected results.
Definition: unsupliedEnergyCsr.h:99
@ count
How many items have we got.
Definition: unsupliedEnergyCsr.h:106
VCardUnsupliedEnergyCSR VCardType
VCard.
Definition: unsupliedEnergyCsr.h:94
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 precision
Precision (views)
Definition: unsupliedEnergyCsr.h:63
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: unsupliedEnergyCsr.h:75
static constexpr uint8_t decimal
Decimal precision.
Definition: unsupliedEnergyCsr.h:67
VCardUnsupliedEnergyCSR VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: unsupliedEnergyCsr.h:56
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: unsupliedEnergyCsr.h:65
static std::string Description()
The short description of the variable.
Definition: unsupliedEnergyCsr.h:42
static std::string Unit()
Unit.
Definition: unsupliedEnergyCsr.h:36
static std::string Caption()
Caption.
Definition: unsupliedEnergyCsr.h:30
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: unsupliedEnergyCsr.h:53
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: unsupliedEnergyCsr.h:59
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: unsupliedEnergyCsr.h:77
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: unsupliedEnergyCsr.h:69
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: unsupliedEnergyCsr.h:71