Antares Simulator
Power System Simulator
economy_base.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 
22 #pragma once
23 
24 #include <antares/memory/memory.h>
25 #include <antares/solver/variable/categories.h>
26 #include <antares/solver/variable/container.h>
27 #include <antares/solver/variable/state.h>
28 #include <antares/solver/variable/storage/intermediate.h>
29 #include <antares/solver/variable/storage/results.h>
30 #include <antares/solver/variable/surveyresults.h>
31 #include <antares/solver/variable/variable.h>
32 #include <antares/study/area/area.h>
33 #include <antares/study/area/links.h>
34 #include <antares/study/study.h>
35 
36 namespace Antares::Solver::Variable::Economy
37 {
38 
39 template<class Traits>
40 struct VCard_Base
41 {
43  static std::string Caption()
44  {
45  return Traits::Caption();
46  }
47 
49  static std::string Unit()
50  {
51  return Traits::Unit();
52  }
53 
55  static std::string Description()
56  {
57  return Traits::Description();
58  }
59 
61  typedef typename Traits::ResultsType ResultsType;
62 
64 
65  static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
67  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
68  & (Category::FileLevel::id
69  | Category::FileLevel::va);
71  static constexpr uint8_t precision = Category::all;
73  static constexpr uint8_t nodeDepthForGUI = +0;
75  static constexpr uint8_t decimal = Traits::decimal;
77  static constexpr int columnCount = 1;
79  static constexpr uint8_t spatialAggregate = Traits::spatialAggregate;
80  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
81  static constexpr uint8_t spatialAggregatePostProcessing = 0;
83  static constexpr uint8_t hasIntermediateValues = 1;
85  static constexpr uint8_t isPossiblyNonApplicable = 0;
86 
88  typedef std::vector<IntermediateValues> IntermediateValuesType;
89 
90  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
91 
92 }; // class VCard
93 
97 template<class Traits, class NextT = Container::EndOfList>
99  : public Variable::IVariable<Economy_Base<Traits, NextT>, NextT, VCard_Base<Traits>>
100 {
101 public:
103  typedef NextT NextType;
108 
111 
113 
114  enum
115  {
117  count = 1 + NextT::count,
118  };
119 
120  template<int CDataLevel, int CFile>
121  struct Statistics
122  {
123  enum
124  {
125  count = ((VCardType::categoryDataLevel & CDataLevel
126  && VCardType::categoryFileLevel & CFile)
127  ? (NextType::template Statistics<CDataLevel, CFile>::count
128  + VCardType::columnCount * ResultsType::count)
129  : NextType::template Statistics<CDataLevel, CFile>::count),
130  };
131  };
132 
133 public:
134  void initializeFromStudy(Data::Study& study)
135  {
136  pNbYearsParallel = study.maxNbYearsInParallel;
137 
138  // Intermediate values
139  InitializeResultsFromStudy(AncestorType::pResults, study);
140 
141  pValuesForTheCurrentYear.resize(pNbYearsParallel);
142  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
143  {
144  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
145  }
146  // Next
147  NextType::initializeFromStudy(study);
148  }
149 
150  template<class R>
151  static void InitializeResultsFromStudy(R& results, Data::Study& study)
152  {
153  VariableAccessorType::InitializeAndReset(results, study);
154  }
155 
156  void initializeFromArea(Data::Study* study, Data::Area* area)
157  {
158  // Next
159  NextType::initializeFromArea(study, area);
160  }
161 
162  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
163  {
164  // Next
165  NextType::initializeFromAreaLink(study, link);
166  }
167 
168  void simulationBegin()
169  {
170  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
171  {
172  pValuesForTheCurrentYear[numSpace].reset();
173  }
174  // Next
175  NextType::simulationBegin();
176  }
177 
178  void simulationEnd()
179  {
180  NextType::simulationEnd();
181  }
182 
183  void yearBegin(unsigned int year, unsigned int numSpace)
184  {
185  // Reset the values for the current year
186  pValuesForTheCurrentYear[numSpace].reset();
187 
188  // Next variable
189  NextType::yearBegin(year, numSpace);
190  }
191 
192  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
193  {
194  // Next variable
195  NextType::yearEndBuild(state, year, numSpace);
196  }
197 
198  void yearEnd(unsigned int year, unsigned int numSpace)
199  {
200  // Compute all statistics for the current year (daily,weekly,monthly)
201  Traits::computeStats(pValuesForTheCurrentYear[numSpace]);
202 
203  // Next variable
204  NextType::yearEnd(year, numSpace);
205  }
206 
207  void computeSummary(unsigned int year, unsigned int numSpace)
208  {
209  // Merge all those values with the global results
210  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
211 
212  // Next variable
213  NextType::computeSummary(year, numSpace);
214  }
215 
216  void hourBegin(unsigned int hourInTheYear)
217  {
218  // Next variable
219  NextType::hourBegin(hourInTheYear);
220  }
221 
222  void hourForEachArea(State& state, unsigned int numSpace)
223  {
224  if (Traits::checkCondition(state))
225  {
226  pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = Traits::value();
227  }
228 
229  // Next variable
230  NextType::hourForEachArea(state, numSpace);
231  }
232 
233  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
234  unsigned int,
235  unsigned int numSpace) const
236  {
237  return pValuesForTheCurrentYear[numSpace].hour;
238  }
239 
240  void localBuildAnnualSurveyReport(SurveyResults& results,
241  int fileLevel,
242  int precision,
243  unsigned int numSpace) const
244  {
245  // Initializing external pointer on current variable non applicable status
246  results.isCurrentVarNA = AncestorType::isNonApplicable;
247 
248  if (AncestorType::isPrinted[0])
249  {
250  // Write the data for the current year
251  results.variableCaption = VCardType::Caption();
252  results.variableUnit = VCardType::Unit();
253  pValuesForTheCurrentYear[numSpace]
254  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
255  }
256  }
257 
258 private:
260  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
261  unsigned int pNbYearsParallel;
262 
263 }; // class Economy_Base
264 
265 } // namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Base class for economy variables like LOLP and LOLD.
Definition: economy_base.h:100
NextT NextType
Type of the next static variable.
Definition: economy_base.h:103
VCardType::ResultsType ResultsType
List of expected results.
Definition: economy_base.h:110
@ count
How many items have we got.
Definition: economy_base.h:117
Variable::IVariable< Economy_Base< Traits, NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: economy_base.h:107
VCard_Base< Traits > VCardType
VCard.
Definition: economy_base.h:105
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: cbuilder.h:120
static std::string Caption()
Caption.
Definition: economy_base.h:43
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: economy_base.h:77
static constexpr uint8_t decimal
Decimal precision.
Definition: economy_base.h:75
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: economy_base.h:73
static std::string Description()
The short description of the variable.
Definition: economy_base.h:55
Traits::ResultsType ResultsType
The expecte results.
Definition: economy_base.h:61
static std::string Unit()
Unit.
Definition: economy_base.h:49
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: economy_base.h:67
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: economy_base.h:83
static constexpr uint8_t precision
Precision (views)
Definition: economy_base.h:71
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: economy_base.h:79
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: economy_base.h:85