Antares Simulator
Power System Simulator
loopFlow.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_LoopFlow_H__
22 #define __SOLVER_VARIABLE_ECONOMY_LoopFlow_H__
23 
24 #include "../../variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "LOOP FLOW";
34  }
35 
37  static std::string Unit()
38  {
39  return "MWh";
40  }
41 
43  static std::string Description()
44  {
45  return "Loop flow";
46  }
47 
49  typedef Results<R::AllYears::Raw< // Raw values
50  >>
52 
54  static constexpr uint8_t categoryDataLevel = Category::DataLevel::link;
56  static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
57  & (Category::FileLevel::id
58  | Category::FileLevel::va);
60  static constexpr uint8_t precision = Category::all;
62  static constexpr uint8_t nodeDepthForGUI = +0;
64  static constexpr uint8_t decimal = 0;
66  static constexpr int columnCount = 1;
68  static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
69  static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
70  static constexpr uint8_t spatialAggregatePostProcessing = 0;
72  static constexpr uint8_t hasIntermediateValues = 1;
74  static constexpr uint8_t isPossiblyNonApplicable = 0;
75 
77 
78 }; // class VCard
79 
83 template<class NextT = Container::EndOfList>
84 class LoopFlow: public Variable::IVariable<LoopFlow<NextT>, NextT, VCardLoopFlow>
85 {
86 public:
88  typedef NextT NextType;
93 
96 
98 
99  enum
100  {
102  count = 1 + NextT::count,
103  };
104 
105  template<int CDataLevel, int CFile>
106  struct Statistics
107  {
108  enum
109  {
110  count = ((VCardType::categoryDataLevel & CDataLevel
111  && VCardType::categoryFileLevel & CFile)
112  ? (NextType::template Statistics<CDataLevel, CFile>::count
114  : NextType::template Statistics<CDataLevel, CFile>::count),
115  };
116  };
117 
118 public:
119  ~LoopFlow()
120  {
121  }
122 
123  void initializeFromStudy(Data::Study& study)
124  {
125  // Average on all years
126  InitializeResultsFromStudy(AncestorType::pResults, study);
127 
128  // Intermediate values
129  pValuesForTheCurrentYear.initializeFromStudy(study);
130 
131  // Next
132  NextType::initializeFromStudy(study);
133  }
134 
135  template<class R>
136  static void InitializeResultsFromStudy(R& results, Data::Study& study)
137  {
138  VariableAccessorType::InitializeAndReset(results, study);
139  }
140 
141  void initializeFromArea(Data::Study* study, Data::Area* area)
142  {
143  // Next
144  NextType::initializeFromArea(study, area);
145  }
146 
147  void initializeFromLink(Data::Study* study, Data::AreaLink* link)
148  {
149  // Next
150  NextType::initializeFromAreaLink(study, link);
151  }
152 
153  void initializeFromAreaLink(Data::Study* study, Data::AreaLink* link)
154  {
155  if (link->useLoopFlow)
156  {
157  // Flow assessed over all MC years (linear)
158  unsigned int height = link->parameters.height;
159  (void)::memcpy(pValuesForTheCurrentYear.hour,
160  link->parameters[Data::fhlLoopFlow],
161  sizeof(double) * height);
162  }
163 
164  // Next
165  NextType::initializeFromAreaLink(study, link);
166  }
167 
168  void simulationBegin()
169  {
170  // Next
171  NextType::simulationBegin();
172  }
173 
174  void simulationEnd()
175  {
176  // Compute all statistics for the current year (daily,weekly,monthly)
177  pValuesForTheCurrentYear.computeStatisticsForTheCurrentYear();
178  // Merge all those values with the global results
179  AncestorType::pResults.merge(0, pValuesForTheCurrentYear);
180 
181  // Next
182  NextType::simulationEnd();
183  }
184 
185  void yearBegin(uint year, unsigned int numSpace)
186  {
187  // Next variable
188  NextType::yearBegin(year, numSpace);
189  }
190 
191  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
192  {
193  // Next variable
194  NextType::yearEndBuild(state, year, numSpace);
195  }
196 
197  void yearEnd(uint year, unsigned int numSpace)
198  {
199  // Next variable
200  NextType::yearEnd(year, numSpace);
201  }
202 
203  void computeSummary(unsigned int year, unsigned int numSpace)
204  {
205  // Next variable
206  NextType::computeSummary(year, numSpace);
207  }
208 
209  void hourBegin(uint hourInTheYear)
210  {
211  // Next variable
212  NextType::hourBegin(hourInTheYear);
213  }
214 
215  void hourForEachArea(State& state, unsigned int numSpace)
216  {
217  // Next variable
218  NextType::hourForEachArea(state, numSpace);
219  }
220 
221  void hourForEachLink(State& state, unsigned int numSpace)
222  {
223  // Next item in the list
224  NextType::hourForEachLink(state, numSpace);
225  }
226 
227  void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
228  {
229  // Next
230  NextType::buildDigest(results, digestLevel, dataLevel);
231  }
232 
233  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
234  uint,
235  uint) const
236  {
237  return pValuesForTheCurrentYear.hour;
238  }
239 
240  void localBuildAnnualSurveyReport(SurveyResults& results,
241  int fileLevel,
242  int precision,
243  uint) 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.template buildAnnualSurveyReport<VCardType>(results,
254  fileLevel,
255  precision);
256  }
257  }
258 
259 private:
261  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
262 
263 }; // class LoopFlow
264 
265 } // namespace Antares::Solver::Variable::Economy
266 
267 #endif // __SOLVER_VARIABLE_ECONOMY_LoopFlow_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
LoopFlow.
Definition: loopFlow.h:85
Variable::IVariable< LoopFlow< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: loopFlow.h:92
NextT NextType
Type of the next static variable.
Definition: loopFlow.h:88
@ count
How many items have we got.
Definition: loopFlow.h:102
VCardType::ResultsType ResultsType
List of expected results.
Definition: loopFlow.h:95
VCardLoopFlow VCardType
VCard.
Definition: loopFlow.h:90
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
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
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: loopFlow.h:62
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: loopFlow.h:72
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: loopFlow.h:56
static std::string Unit()
Unit.
Definition: loopFlow.h:37
static std::string Caption()
Caption.
Definition: loopFlow.h:31
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: loopFlow.h:68
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: loopFlow.h:74
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: loopFlow.h:66
static std::string Description()
The short description of the variable.
Definition: loopFlow.h:43
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: loopFlow.h:54
static constexpr uint8_t precision
Precision (views)
Definition: loopFlow.h:60
Results< R::AllYears::Raw< > > ResultsType
The expecte results.
Definition: loopFlow.h:51
static constexpr uint8_t decimal
Decimal precision.
Definition: loopFlow.h:64