Antares Simulator
Power System Simulator
balance.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_BALANCE_H__
22 #define __SOLVER_VARIABLE_ECONOMY_BALANCE_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 "BALANCE";
34  }
35 
37  static std::string Unit()
38  {
39  return "MWh";
40  }
41 
43  static std::string Description()
44  {
45  return "Nodal energy balance, throughout all MC years";
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 
92 template<class NextT = Container::EndOfList>
93 class Balance: public Variable::IVariable<Balance<NextT>, NextT, VCardBalance>
94 {
95 public:
97  typedef NextT NextType;
102 
105 
107 
108  enum
109  {
111  count = 1 + NextT::count,
112  };
113 
114  template<int CDataLevel, int CFile>
115  struct Statistics
116  {
117  enum
118  {
119  count = ((VCardType::categoryDataLevel & CDataLevel
120  && VCardType::categoryFileLevel & CFile)
121  ? (NextType::template Statistics<CDataLevel, CFile>::count
123  : NextType::template Statistics<CDataLevel, CFile>::count),
124  };
125  };
126 
127 public:
128  ~Balance() = default;
129 
130  void initializeFromStudy(Data::Study& study)
131  {
132  pNbYearsParallel = study.maxNbYearsInParallel;
133 
134  InitializeResultsFromStudy(AncestorType::pResults, study);
135 
136  pValuesForTheCurrentYear.resize(pNbYearsParallel);
137  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
138  {
139  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
140  }
141 
142  // Next
143  NextType::initializeFromStudy(study);
144  }
145 
146  template<class R>
147  static void InitializeResultsFromStudy(R& results, Data::Study& study)
148  {
149  VariableAccessorType::InitializeAndReset(results, study);
150  }
151 
152  void initializeFromArea(Data::Study* study, Data::Area* area)
153  {
154  // Next
155  NextType::initializeFromArea(study, area);
156  }
157 
158  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
159  {
160  // Next
161  NextType::initializeFromAreaLink(study, link);
162  }
163 
164  void simulationBegin()
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  // A single reset is enough
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  double bilanPays = 0.;
216  int Interco = state.problemeHebdo->IndexDebutIntercoOrigine[state.area->index];
217  while (Interco >= 0)
218  {
219  bilanPays += state.ntc.ValeurDuFlux[static_cast<std::size_t>(Interco)];
220  Interco = state.problemeHebdo
221  ->IndexSuivantIntercoOrigine[static_cast<std::size_t>(Interco)];
222  }
223  Interco = state.problemeHebdo->IndexDebutIntercoExtremite[state.area->index];
224  while (Interco >= 0)
225  {
226  bilanPays -= state.ntc.ValeurDuFlux[static_cast<std::size_t>(Interco)];
227  Interco = state.problemeHebdo
228  ->IndexSuivantIntercoExtremite[static_cast<std::size_t>(Interco)];
229  }
230 
231  pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = bilanPays;
232  // Next variable
233  NextType::hourForEachArea(state, numSpace);
234  }
235 
236  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
237  unsigned int,
238  unsigned int numSpace) const
239  {
240  return pValuesForTheCurrentYear[numSpace].hour;
241  }
242 
243  void localBuildAnnualSurveyReport(SurveyResults& results,
244  int fileLevel,
245  int precision,
246  unsigned int numSpace) const
247  {
248  // Initializing external pointer on current variable non applicable status
249  results.isCurrentVarNA = AncestorType::isNonApplicable;
250 
251  if (AncestorType::isPrinted[0])
252  {
253  // Write the data for the current year
254  results.variableCaption = VCardType::Caption();
255  results.variableUnit = VCardType::Unit();
256  pValuesForTheCurrentYear[numSpace]
257  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
258  }
259  }
260 
261 private:
263  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
264  unsigned int pNbYearsParallel;
265 
266 }; // class Balance
267 
268 } // namespace Antares::Solver::Variable::Economy
269 
270 #endif // __SOLVER_VARIABLE_ECONOMY_BALANCE_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal Balance.
Definition: balance.h:94
VCardType::ResultsType ResultsType
List of expected results.
Definition: balance.h:104
@ count
How many items have we got.
Definition: balance.h:111
Variable::IVariable< Balance< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: balance.h:101
NextT NextType
Type of the next static variable.
Definition: balance.h:97
VCardBalance VCardType
VCard.
Definition: balance.h:99
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 int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: balance.h:72
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: balance.h:62
static std::string Description()
The short description of the variable.
Definition: balance.h:43
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: balance.h:60
VCardBalance VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: balance.h:57
static std::string Unit()
Unit.
Definition: balance.h:37
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: balance.h:74
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: balance.h:54
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: balance.h:68
static std::string Caption()
Caption.
Definition: balance.h:31
static constexpr uint8_t decimal
Decimal precision.
Definition: balance.h:70
static constexpr uint8_t precision
Precision (views)
Definition: balance.h:66
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: balance.h:78
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: balance.h:80