Antares Simulator
Power System Simulator
flowLinear.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_FlowLinear_H__
22 #define __SOLVER_VARIABLE_ECONOMY_FlowLinear_H__
23 
24 #include "../../variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "FLOW LIN.";
34  }
35 
37  static std::string Unit()
38  {
39  return "MWh";
40  }
41 
43  static std::string Description()
44  {
45  return "Flow assessed, over all MC years, through linear optimization";
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 
57  static constexpr uint8_t categoryDataLevel = Category::DataLevel::link;
59  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
60  & (Category::FileLevel::id
61  | Category::FileLevel::va);
63  static constexpr uint8_t precision = Category::all;
65  static constexpr uint8_t nodeDepthForGUI = +0;
67  static constexpr uint8_t decimal = 0;
69  static constexpr int columnCount = 1;
71  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
72  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
73  static constexpr uint8_t spatialAggregatePostProcessing = 0;
75  static constexpr uint8_t hasIntermediateValues = 1;
77  static constexpr uint8_t isPossiblyNonApplicable = 0;
78 
80  typedef std::vector<IntermediateValues> IntermediateValuesType;
81 
82 }; // class VCard
83 
87 template<class NextT = Container::EndOfList>
88 class FlowLinear: public Variable::IVariable<FlowLinear<NextT>, NextT, VCardFlowLinear>
89 {
90 public:
92  typedef NextT NextType;
97 
100 
102 
103  enum
104  {
106  count = 1 + NextT::count,
107  };
108 
109  template<int CDataLevel, int CFile>
110  struct Statistics
111  {
112  enum
113  {
114  count = ((VCardType::categoryDataLevel & CDataLevel
115  && VCardType::categoryFileLevel & CFile)
116  ? (NextType::template Statistics<CDataLevel, CFile>::count
118  : NextType::template Statistics<CDataLevel, CFile>::count),
119  };
120  };
121 
122 public:
123  void initializeFromStudy(Data::Study& study)
124  {
125  pNbYearsParallel = study.maxNbYearsInParallel;
126 
127  // Average on all years
128  AncestorType::pResults.initializeFromStudy(study);
129  AncestorType::pResults.reset();
130 
131  // Intermediate values
132  pValuesForTheCurrentYear.resize(pNbYearsParallel);
133  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
134  {
135  pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
136  }
137 
138  // Next
139  NextType::initializeFromStudy(study);
140  }
141 
142  void initializeFromArea(Data::Study* study, Data::Area* area)
143  {
144  // Next
145  NextType::initializeFromArea(study, area);
146  }
147 
148  void initializeFromAreaLink(Data::Study* study, Data::AreaLink* link)
149  {
150  // Next
151  NextType::initializeFromAreaLink(study, link);
152  }
153 
154  void simulationBegin()
155  {
156  for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
157  {
158  pValuesForTheCurrentYear[numSpace].reset();
159  }
160  // Next
161  NextType::simulationBegin();
162  }
163 
164  void simulationEnd()
165  {
166  NextType::simulationEnd();
167  }
168 
169  void yearBegin(uint year, unsigned int numSpace)
170  {
171  // Reset
172  pValuesForTheCurrentYear[numSpace].reset();
173  // Next variable
174  NextType::yearBegin(year, numSpace);
175  }
176 
177  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
178  {
179  // Next variable
180  NextType::yearEndBuild(state, year, numSpace);
181  }
182 
183  void yearEnd(unsigned int year, unsigned int numSpace)
184  {
185  // Compute all statistics for the current year (daily,weekly,monthly)
186  pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
187 
188  // Next variable
189  NextType::yearEnd(year, numSpace);
190  }
191 
192  void computeSummary(unsigned int year, unsigned int numSpace)
193  {
194  // Merge all those values with the global results
195  AncestorType::pResults.merge(year, pValuesForTheCurrentYear[numSpace]);
196 
197  // Next variable
198  NextType::computeSummary(year, numSpace);
199  }
200 
201  void hourBegin(uint hourInTheYear)
202  {
203  // Next variable
204  NextType::hourBegin(hourInTheYear);
205  }
206 
207  void hourForEachArea(State& state, unsigned int numSpace)
208  {
209  // Next variable
210  NextType::hourForEachArea(state, numSpace);
211  }
212 
213  void hourForEachLink(State& state, unsigned int numSpace)
214  {
215  // Flow assessed over all MC years (linear)
216  pValuesForTheCurrentYear[numSpace].hour[state.hourInTheYear] += state.ntc.ValeurDuFlux
217  [state.link->index];
218  // Next item in the list
219  NextType::hourForEachLink(state, numSpace);
220  }
221 
222  void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
223  {
224  if (dataLevel & Category::DataLevel::link)
225  {
226  if (digestLevel & Category::digestFlowLinear)
227  {
228  results.data.matrix
229  .entry[results.data.link->from->index][results.data.link->with->index]
230  = AncestorType::pResults.avgdata.allYears;
231  results.data.matrix
232  .entry[results.data.link->with->index][results.data.link->from->index]
233  = -AncestorType::pResults.avgdata.allYears;
234  }
235  }
236 
237  // Next
238  NextType::buildDigest(results, digestLevel, dataLevel);
239  }
240 
241  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
242  uint,
243  uint numSpace) const
244  {
245  return pValuesForTheCurrentYear[numSpace].hour;
246  }
247 
248  void localBuildAnnualSurveyReport(SurveyResults& results,
249  int fileLevel,
250  int precision,
251  uint numSpace) const
252  {
253  // Initializing external pointer on current variable non applicable status
254  results.isCurrentVarNA = AncestorType::isNonApplicable;
255 
256  if (AncestorType::isPrinted[0])
257  {
258  // Write the data for the current year
259  results.variableCaption = VCardType::Caption();
260  results.variableUnit = VCardType::Unit();
261  pValuesForTheCurrentYear[numSpace]
262  .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
263  }
264  }
265 
266 private:
268  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
269  unsigned int pNbYearsParallel;
270 
271 }; // class FlowLinear
272 
273 } // namespace Antares::Solver::Variable::Economy
274 
275 #endif // __SOLVER_VARIABLE_ECONOMY_FlowLinear_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal FlowLinear.
Definition: flowLinear.h:89
VCardFlowLinear VCardType
VCard.
Definition: flowLinear.h:94
Variable::IVariable< FlowLinear< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: flowLinear.h:96
NextT NextType
Type of the next static variable.
Definition: flowLinear.h:92
VCardType::ResultsType ResultsType
List of expected results.
Definition: flowLinear.h:99
@ count
How many items have we got.
Definition: flowLinear.h:106
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 constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: flowLinear.h:59
static std::string Unit()
Unit.
Definition: flowLinear.h:37
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition: flowLinear.h:54
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: flowLinear.h:65
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: flowLinear.h:77
static constexpr uint8_t precision
Precision (views)
Definition: flowLinear.h:63
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: flowLinear.h:75
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: flowLinear.h:69
static std::string Caption()
Caption.
Definition: flowLinear.h:31
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: flowLinear.h:71
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: flowLinear.h:57
static std::string Description()
The short description of the variable.
Definition: flowLinear.h:43
static constexpr uint8_t decimal
Decimal precision.
Definition: flowLinear.h:67