Antares Simulator
Power System Simulator
psp.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_PSP_H__
22 #define __SOLVER_VARIABLE_ECONOMY_PSP_H__
23 
24 #include <antares/study/area/constants.h>
25 #include "antares/solver/variable/variable.h"
26 
27 namespace Antares::Solver::Variable::Economy
28 {
29 struct VCardPSP
30 {
32  static std::string Caption()
33  {
34  return "PSP";
35  }
36 
38  static std::string Unit()
39  {
40  return "MWh";
41  }
42 
44  static std::string Description()
45  {
46  return "PSP";
47  }
48 
50  typedef Results<R::AllYears::Average< // The average values throughout all years
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::spatialAggregateEachYear;
74  static constexpr uint8_t spatialAggregatePostProcessing = 0;
76  static constexpr uint8_t hasIntermediateValues = 1;
78  static constexpr uint8_t isPossiblyNonApplicable = 0;
79 
81  typedef std::vector<IntermediateValues> IntermediateValuesType;
82  using IntermediateValuesTypeForSpatialAg = std::unique_ptr<IntermediateValuesBaseType[]>;
83 
84 }; // class VCard
85 
89 template<class NextT = Container::EndOfList>
90 class PSP: public Variable::IVariable<PSP<NextT>, NextT, VCardPSP>
91 {
92 public:
94  typedef NextT NextType;
99 
102 
104 
105  enum
106  {
108  count = 1 + NextT::count,
109  };
110 
111  template<int CDataLevel, int CFile>
112  struct Statistics
113  {
114  enum
115  {
116  count = ((VCardType::categoryDataLevel & CDataLevel
117  && VCardType::categoryFileLevel & CFile)
118  ? (NextType::template Statistics<CDataLevel, CFile>::count
120  : NextType::template Statistics<CDataLevel, CFile>::count),
121  };
122  };
123 
124 public:
125  void initializeFromStudy(Data::Study& study)
126  {
127  pNbYearsParallel = study.maxNbYearsInParallel;
128 
129  // Average on all years
130  InitializeResultsFromStudy(AncestorType::pResults, study);
131 
132  // Intermediate values
133  pValuesForTheCurrentYear.resize(pNbYearsParallel);
134  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
135  {
136  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
137  }
138 
139  // Next
140  NextType::initializeFromStudy(study);
141  }
142 
143  void initializeFromArea(Data::Study* study, Data::Area* area)
144  {
145  // Copy raw values
146  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
147  {
148  (void)::memcpy(pValuesForTheCurrentYear[numSpace].hour,
149  area->miscGen.entry[Data::fhhPSP],
150  sizeof(double) * area->miscGen.height);
151  }
152 
153  // Next
154  NextType::initializeFromArea(study, area);
155  }
156 
157  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
158  {
159  // Next
160  NextType::initializeFromAreaLink(study, link);
161  }
162 
163  template<class R>
164  static void InitializeResultsFromStudy(R& results, Data::Study& study)
165  {
166  VariableAccessorType::InitializeAndReset(results, study);
167  }
168 
169  void simulationBegin()
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  // Next variable
183  NextType::yearBegin(year, numSpace);
184  }
185 
186  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
187  {
188  // Next variable
189  NextType::yearEndBuild(state, year, numSpace);
190  }
191 
192  void yearEnd(unsigned int year, unsigned int numSpace)
193  {
194  // Compute all statistics for the current year (daily,weekly,monthly)
195  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
196 
197  // Next variable
198  NextType::yearEnd(year, numSpace);
199  }
200 
201  void computeSummary(unsigned int year, unsigned int numSpace)
202  {
203  // Merge all those values with the global results
204  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
205 
206  // Next variable
207  NextType::computeSummary(year, numSpace);
208  }
209 
210  void hourBegin(unsigned int hourInTheYear)
211  {
212  // Next variable
213  NextType::hourBegin(hourInTheYear);
214  }
215 
216  void hourForEachArea(State& state, unsigned int numSpace)
217  {
218  // Next variable
219  NextType::hourForEachArea(state, numSpace);
220  }
221 
222  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
223  unsigned int,
224  unsigned int numSpace) const
225  {
226  return pValuesForTheCurrentYear[numSpace].hour;
227  }
228 
229  void localBuildAnnualSurveyReport(SurveyResults& results,
230  int fileLevel,
231  int precision,
232  unsigned int numSpace) const
233  {
234  // Initializing external pointer on current variable non applicable status
235  results.isCurrentVarNA = AncestorType::isNonApplicable;
236 
237  if (AncestorType::isPrinted[0])
238  {
239  // Write the data for the current year
240  results.variableCaption = VCardType::Caption();
241  results.variableUnit = VCardType::Unit();
242  pValuesForTheCurrentYear[numSpace]
243  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
244  }
245  }
246 
247 private:
249  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
250  unsigned int pNbYearsParallel;
251 
252 }; // class PSP
253 
254 } // namespace Antares::Solver::Variable::Economy
255 
256 #endif // __SOLVER_VARIABLE_ECONOMY_PSP_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal PSP.
Definition: psp.h:91
NextT NextType
Type of the next static variable.
Definition: psp.h:94
VCardType::ResultsType ResultsType
List of expected results.
Definition: psp.h:101
Variable::IVariable< PSP< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: psp.h:98
@ count
How many items have we got.
Definition: psp.h:108
VCardPSP VCardType
VCard.
Definition: psp.h:96
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 std::string Unit()
Unit.
Definition: psp.h:38
Results< R::AllYears::Average< > > ResultsType
The expecte results.
Definition: psp.h:52
static std::string Description()
The short description of the variable.
Definition: psp.h:44
static constexpr uint8_t precision
Precision (views)
Definition: psp.h:64
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: psp.h:78
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: psp.h:60
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: psp.h:72
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: psp.h:76
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: psp.h:66
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: psp.h:70
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: psp.h:58
VCardPSP VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: psp.h:55
static constexpr uint8_t decimal
Decimal precision.
Definition: psp.h:68
static std::string Caption()
Caption.
Definition: psp.h:32