Antares Simulator
Power System Simulator
miscGenMinusRowPSP.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_MiscGenMinusRowPSP_H__
22 #define __SOLVER_VARIABLE_ECONOMY_MiscGenMinusRowPSP_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 "MISC. NDG";
35  }
36 
38  static std::string Unit()
39  {
40  return "MWh";
41  }
42 
44  static std::string Description()
45  {
46  return "Non-dispatchable generation (not including wind and run-of-the-river)";
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>
91  : public Variable::IVariable<MiscGenMinusRowPSP<NextT>, NextT, VCardMiscGenMinusRowPSP>
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  void initializeFromStudy(Data::Study& study)
127  {
128  pNbYearsParallel = study.maxNbYearsInParallel;
129 
130  // Average on all years
131  InitializeResultsFromStudy(AncestorType::pResults, study);
132 
133  // Intermediate values
134  pValuesForTheCurrentYear.resize(pNbYearsParallel);
135  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
136  {
137  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
138  }
139 
140  // Next
141  NextType::initializeFromStudy(study);
142  }
143 
144  void initializeFromArea(Data::Study* study, Data::Area* area)
145  {
146  // Copy raw values
147  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
148  {
149  // Memcpy for the first value
150  (void)::memcpy(pValuesForTheCurrentYear[numSpace].hour,
151  area->miscGen.entry[0],
152  sizeof(double) * area->miscGen.height);
153 
154  {
155  // We must not include the CHP and the Solar. So we have to start from `2`
156  for (unsigned int x = 1; x != (unsigned int)Data::fhhPSP; ++x)
157  {
158  const Matrix<>::ColumnType& col = area->miscGen.entry[x];
159  for (unsigned int y = 0; y != area->miscGen.height; ++y)
160  {
161  pValuesForTheCurrentYear[numSpace].hour[y] += col[y];
162  }
163  }
164  }
165  }
166 
167  // Next
168  NextType::initializeFromArea(study, area);
169  }
170 
171  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
172  {
173  // Next
174  NextType::initializeFromAreaLink(study, link);
175  }
176 
177  template<class R>
178  static void InitializeResultsFromStudy(R& results, Data::Study& study)
179  {
180  VariableAccessorType::InitializeAndReset(results, study);
181  }
182 
183  void simulationBegin()
184  {
185  // Next
186  NextType::simulationBegin();
187  }
188 
189  void simulationEnd()
190  {
191  NextType::simulationEnd();
192  }
193 
194  void yearBegin(unsigned int year, unsigned int numSpace)
195  {
196  // Next variable
197  NextType::yearBegin(year, numSpace);
198  }
199 
200  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
201  {
202  // Next variable
203  NextType::yearEndBuild(state, year, numSpace);
204  }
205 
206  void yearEnd(unsigned int year, unsigned int numSpace)
207  {
208  // Compute all statistics for the current year (daily,weekly,monthly)
209  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
210 
211  // Next variable
212  NextType::yearEnd(year, numSpace);
213  }
214 
215  void computeSummary(unsigned int year, unsigned int numSpace)
216  {
217  // Merge all those values with the global results
218  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
219 
220  // Next variable
221  NextType::computeSummary(year, numSpace);
222  }
223 
224  void hourBegin(unsigned int hourInTheYear)
225  {
226  // Next variable
227  NextType::hourBegin(hourInTheYear);
228  }
229 
230  void hourForEachArea(State& state, unsigned int numSpace)
231  {
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 MiscGenMinusRowPSP
267 
268 } // namespace Antares::Solver::Variable::Economy
269 
270 #endif // __SOLVER_VARIABLE_ECONOMY_MiscGenMinusRowPSP_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
typename Antares::Memory::Stored< T >::Type ColumnType
Column type.
Definition: matrix.h:62
Marginal MiscGenMinusRowPSP.
Definition: miscGenMinusRowPSP.h:92
NextT NextType
Type of the next static variable.
Definition: miscGenMinusRowPSP.h:95
VCardMiscGenMinusRowPSP VCardType
VCard.
Definition: miscGenMinusRowPSP.h:97
Variable::IVariable< MiscGenMinusRowPSP< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: miscGenMinusRowPSP.h:99
VCardType::ResultsType ResultsType
List of expected results.
Definition: miscGenMinusRowPSP.h:102
@ count
How many items have we got.
Definition: miscGenMinusRowPSP.h:109
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: miscGenMinusRowPSP.h:44
static constexpr uint8_t decimal
Decimal precision.
Definition: miscGenMinusRowPSP.h:68
static constexpr uint8_t precision
Precision (views)
Definition: miscGenMinusRowPSP.h:64
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: miscGenMinusRowPSP.h:58
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: miscGenMinusRowPSP.h:72
static std::string Caption()
Caption.
Definition: miscGenMinusRowPSP.h:32
Results< R::AllYears::Average< > > ResultsType
The expecte results.
Definition: miscGenMinusRowPSP.h:52
static std::string Unit()
Unit.
Definition: miscGenMinusRowPSP.h:38
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: miscGenMinusRowPSP.h:70
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: miscGenMinusRowPSP.h:76
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: miscGenMinusRowPSP.h:60
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: miscGenMinusRowPSP.h:78
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: miscGenMinusRowPSP.h:66
VCardMiscGenMinusRowPSP VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition: miscGenMinusRowPSP.h:55