Antares Simulator
Power System Simulator
rowBalance.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_RowBalance_H__
22 #define __SOLVER_VARIABLE_ECONOMY_RowBalance_H__
23 
24 #include <antares/study/area/constants.h>
25 #include "antares/solver/variable/variable.h"
26 
27 namespace Antares::Solver::Variable::Economy
28 {
30 {
32  static std::string Caption()
33  {
34  return "ROW BAL.";
35  }
36 
38  static std::string Unit()
39  {
40  return "MWh";
41  }
42 
44  static std::string Description()
45  {
46  return "Row Balance";
47  }
48 
50  typedef Results<R::AllYears::Raw< // The raw values
51  >>
53 
56 
58  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
60  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
61  & (Category::FileLevel::id
62  | Category::FileLevel::va);
64  static constexpr uint8_t precision = Category::all;
66  static constexpr uint8_t nodeDepthForGUI = +0;
68  static constexpr uint8_t decimal = 0;
70  static constexpr int columnCount = 1;
72  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
73  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateOnce;
74  static constexpr uint8_t spatialAggregatePostProcessing = 0;
76  static constexpr uint8_t hasIntermediateValues = 1;
78  static constexpr uint8_t isPossiblyNonApplicable = 0;
79 
82 
83  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
84 
85 }; // class VCard
86 
90 template<class NextT = Container::EndOfList>
91 class RowBalance: public Variable::IVariable<RowBalance<NextT>, NextT, VCardRowBalance>
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 public:
126  ~RowBalance()
127  {
128  }
129 
130  void initializeFromStudy(Data::Study& study)
131  {
132  // Average on all years
133  InitializeResultsFromStudy(AncestorType::pResults, study);
134 
135  // Intermediate values
136  pValuesForTheCurrentYear.initializeFromStudy(study);
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  // Copy raw values
151  unsigned int height = area->miscGen.height;
152  (void)::memcpy(pValuesForTheCurrentYear.hour,
153  area->miscGen.entry[Data::fhhRowBalance],
154  sizeof(double) * height);
155 
156  if (study->parameters.mode == Data::SimulationMode::Adequacy)
157  {
158  for (unsigned int h = 0; h != height; ++h)
159  {
160  pValuesForTheCurrentYear.hour[h] -= area->reserves
161  .entry[Data::fhrPrimaryReserve][h];
162  }
163  }
164  // Compute all statistics for the current year (daily,weekly,monthly)
165  pValuesForTheCurrentYear.computeStatisticsForTheCurrentYear();
166 
167  // Merge all those values with the global results
168  AncestorType::pResults.merge(0, pValuesForTheCurrentYear);
169 
170  // Next
171  NextType::initializeFromArea(study, area);
172  }
173 
174  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
175  {
176  // Next
177  NextType::initializeFromAreaLink(study, link);
178  }
179 
180  void simulationBegin()
181  {
182  // Next
183  NextType::simulationBegin();
184  }
185 
186  void simulationEnd()
187  {
188  NextType::simulationEnd();
189  }
190 
191  void yearBegin(unsigned int year, unsigned int numSpace)
192  {
193  // Next variable
194  NextType::yearBegin(year, numSpace);
195  }
196 
197  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
198  {
199  // Next variable
200  NextType::yearEndBuild(state, year, numSpace);
201  }
202 
203  void yearEnd(unsigned int year, unsigned int numSpace)
204  {
205  // Next variable
206  NextType::yearEnd(year, numSpace);
207  }
208 
209  void computeSummary(unsigned int year, unsigned int numSpace)
210  {
211  // Next variable
212  NextType::computeSummary(year, numSpace);
213  }
214 
215  void hourBegin(unsigned int hourInTheYear)
216  {
217  // Next variable
218  NextType::hourBegin(hourInTheYear);
219  }
220 
221  void hourForEachArea(State& state, unsigned int numSpace)
222  {
223  // Next variable
224  NextType::hourForEachArea(state, numSpace);
225  }
226 
227  void localBuildAnnualSurveyReport(SurveyResults& results,
228  int fileLevel,
229  int precision,
230  unsigned int) 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.template buildAnnualSurveyReport<VCardType>(results,
241  fileLevel,
242  precision);
243  }
244  }
245 
246 private:
248  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
249 
250 }; // class RowBalance
251 
252 } // namespace Antares::Solver::Variable::Economy
253 
254 #endif // __SOLVER_VARIABLE_ECONOMY_RowBalance_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal RowBalance.
Definition: rowBalance.h:92
@ count
How many items have we got.
Definition: rowBalance.h:109
NextT NextType
Type of the next static variable.
Definition: rowBalance.h:95
VCardType::ResultsType ResultsType
List of expected results.
Definition: rowBalance.h:102
VCardRowBalance VCardType
VCard.
Definition: rowBalance.h:97
Variable::IVariable< RowBalance< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: rowBalance.h:99
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
Antares::Memory::Stored< Type >::Type hour
Values for each hour in the year.
Definition: intermediate.h:132
void computeStatisticsForTheCurrentYear()
Compute statistics for the current year.
Definition: intermediate.cpp:70
Definition: results.h:44
@ count
The count if item in the list.
Definition: results.h:52
Definition: cbuilder.h:120
Results< R::AllYears::Raw< > > ResultsType
The expecte results.
Definition: rowBalance.h:52
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: rowBalance.h:60
static std::string Description()
The short description of the variable.
Definition: rowBalance.h:44
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: rowBalance.h:66
static std::string Caption()
Caption.
Definition: rowBalance.h:32
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: rowBalance.h:70
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: rowBalance.h:76
static std::string Unit()
Unit.
Definition: rowBalance.h:38
static constexpr uint8_t precision
Precision (views)
Definition: rowBalance.h:64
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: rowBalance.h:72
VCardRowBalance VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: rowBalance.h:55
static constexpr uint8_t decimal
Decimal precision.
Definition: rowBalance.h:68
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: rowBalance.h:78
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: rowBalance.h:58