Antares Simulator
Power System Simulator
unsupliedEnergy.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_UnsupliedEnergy_H__
22 #define __SOLVER_VARIABLE_ECONOMY_UnsupliedEnergy_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 "UNSP. ENRG";
34  }
35 
37  static std::string Unit()
38  {
39  return "MWh";
40  }
41 
43  static std::string Description()
44  {
45  return "Unsuplied Energy (demand that cannot be satisfied)";
46  }
47 
49  typedef Results<R::AllYears::Average< // The average values throughout all years
50  R::AllYears::StdDeviation< // The standard deviation values throughout all years
51  R::AllYears::Min< // The minimum values throughout all years
52  R::AllYears::Max< // The maximum values throughout all years
53  >>>>>
55 
58 
60  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
62  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
63  & (Category::FileLevel::id
64  | Category::FileLevel::va);
66  static constexpr uint8_t precision = Category::all;
68  static constexpr uint8_t nodeDepthForGUI = +0;
70  static constexpr uint8_t decimal = 0;
72  static constexpr int columnCount = 1;
74  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
75  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
76  static constexpr uint8_t spatialAggregatePostProcessing = 0;
78  static constexpr uint8_t hasIntermediateValues = 1;
80  static constexpr uint8_t isPossiblyNonApplicable = 0;
81 
83  typedef std::vector<IntermediateValues> IntermediateValuesType;
84 
85  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
86 
87 }; // class VCard
88 
93 template<class NextT = Container::EndOfList>
95  : public Variable::IVariable<UnsupliedEnergy<NextT>, NextT, VCardUnsupliedEnergy>
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  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
168  {
169  pValuesForTheCurrentYear[numSpace].reset();
170  }
171  // Next
172  NextType::simulationBegin();
173  }
174 
175  void simulationEnd()
176  {
177  NextType::simulationEnd();
178  }
179 
180  void yearBegin(unsigned int year, unsigned int numSpace)
181  {
182  // Reset the values for the current year
183  pValuesForTheCurrentYear[numSpace].reset();
184 
185  // Next variable
186  NextType::yearBegin(year, numSpace);
187  }
188 
189  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
190  {
191  // Next variable
192  NextType::yearEndBuild(state, year, numSpace);
193  }
194 
195  void yearEnd(unsigned int year, unsigned int numSpace)
196  {
197  // Compute all statistics for the current year (daily,weekly,monthly)
198  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
199 
200  // Next variable
201  NextType::yearEnd(year, numSpace);
202  }
203 
204  void computeSummary(unsigned int year, unsigned int numSpace)
205  {
206  // Merge all those values with the global results
207  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
208 
209  // Next variable
210  NextType::computeSummary(year, numSpace);
211  }
212 
213  void hourBegin(unsigned int hourInTheYear)
214  {
215  // Next variable
216  NextType::hourBegin(hourInTheYear);
217  }
218 
219  void hourForEachArea(State& state, unsigned int numSpace)
220  {
221  // Total UnsupliedEnergy emissions
222  pValuesForTheCurrentYear[numSpace][state.hourInTheYear] =
223  // Current Hydro Storage generation
224  state.hourlyResults->ValeursHorairesDeDefaillancePositive[state.hourInTheWeek];
225 
226  // Next variable
227  NextType::hourForEachArea(state, numSpace);
228  }
229 
230  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
231  unsigned int,
232  unsigned int numSpace) const
233  {
234  return pValuesForTheCurrentYear[numSpace].hour;
235  }
236 
237  void localBuildAnnualSurveyReport(SurveyResults& results,
238  int fileLevel,
239  int precision,
240  unsigned int numSpace) const
241  {
242  // Initializing external pointer on current variable non applicable status
243  results.isCurrentVarNA = AncestorType::isNonApplicable;
244 
245  if (AncestorType::isPrinted[0])
246  {
247  // Write the data for the current year
248  results.variableCaption = VCardType::Caption();
249  results.variableUnit = VCardType::Unit();
250  pValuesForTheCurrentYear[numSpace]
251  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
252  }
253  }
254 
255 private:
257  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
258  unsigned int pNbYearsParallel;
259 
260 }; // class UnsupliedEnergy
261 
262 } // namespace Antares::Solver::Variable::Economy
263 
264 #endif // __SOLVER_VARIABLE_ECONOMY_UnsupliedEnergy_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
C02 Average value of the overrall UnsupliedEnergy emissions expected from all the thermal dispatchabl...
Definition: unsupliedEnergy.h:96
VCardType::ResultsType ResultsType
List of expected results.
Definition: unsupliedEnergy.h:106
NextT NextType
Type of the next static variable.
Definition: unsupliedEnergy.h:99
VCardUnsupliedEnergy VCardType
VCard.
Definition: unsupliedEnergy.h:101
@ count
How many items have we got.
Definition: unsupliedEnergy.h:113
Variable::IVariable< UnsupliedEnergy< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: unsupliedEnergy.h:103
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 Description()
The short description of the variable.
Definition: unsupliedEnergy.h:43
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: unsupliedEnergy.h:62
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: unsupliedEnergy.h:74
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: unsupliedEnergy.h:68
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: unsupliedEnergy.h:78
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: unsupliedEnergy.h:60
static constexpr uint8_t precision
Precision (views)
Definition: unsupliedEnergy.h:66
static std::string Unit()
Unit.
Definition: unsupliedEnergy.h:37
VCardUnsupliedEnergy VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: unsupliedEnergy.h:57
static constexpr uint8_t decimal
Decimal precision.
Definition: unsupliedEnergy.h:70
static std::string Caption()
Caption.
Definition: unsupliedEnergy.h:31
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: unsupliedEnergy.h:80
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: unsupliedEnergy.h:54
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: unsupliedEnergy.h:72