Antares Simulator
Power System Simulator
flowQuad.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_FlowQuad_H__
22 #define __SOLVER_VARIABLE_ECONOMY_FlowQuad_H__
23 
24 #include "../../variable.h"
25 
26 namespace Antares::Solver::Variable::Economy
27 {
29 {
31  static std::string Caption()
32  {
33  return "FLOW QUAD.";
34  }
35 
37  static std::string Unit()
38  {
39  return "MWh";
40  }
41 
43  static std::string Description()
44  {
45  return "Flow (quad.)";
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 FlowQuad: public Variable::IVariable<FlowQuad<NextT>, NextT, VCardFlowQuad>
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  ~FlowQuad()
120  {
121  }
122 
123  void initializeFromStudy(Data::Study& study)
124  {
125  // Average on all years
126  pNbHours = study.runtime.rangeLimits.hour[Data::rangeEnd] + 1;
127  transitMoyenInterco_ = &study.runtime.transitMoyenInterconnexionsRecalculQuadratique;
128  AncestorType::pResults.initializeFromStudy(study);
129  AncestorType::pResults.reset();
130 
131  // Intermediate values
132  pValuesForTheCurrentYear.initializeFromStudy(study);
133 
134  // Next
135  NextType::initializeFromStudy(study);
136  }
137 
138  void initializeFromArea(Data::Study* study, Data::Area* area)
139  {
140  // Next
141  NextType::initializeFromArea(study, area);
142  }
143 
144  void initializeFromAreaLink(Data::Study* study, Data::AreaLink* link)
145  {
146  assert(link && "invalid interconnection");
147  pLinkGlobalIndex = link->index;
148  // Next
149  NextType::initializeFromAreaLink(study, link);
150  }
151 
152  void simulationBegin()
153  {
154  pValuesForTheCurrentYear.reset();
155 
156  // Next
157  NextType::simulationBegin();
158  }
159 
160  void simulationEnd()
161  {
162  // Flow assessed over all MC years (linear)
163  (void)::memcpy(pValuesForTheCurrentYear.hour,
164  (*transitMoyenInterco_)[pLinkGlobalIndex].data(),
165  sizeof(double) * pNbHours);
166 
167  // Compute all statistics for the current year (daily,weekly,monthly)
168  pValuesForTheCurrentYear.computeStatisticsForTheCurrentYear();
169  // Merge all those values with the global results
170  AncestorType::pResults.merge(0, pValuesForTheCurrentYear);
171 
172  // Next
173  NextType::simulationEnd();
174  }
175 
176  void yearBegin(uint year, unsigned int numSpace)
177  {
178  // Next variable
179  NextType::yearBegin(year, numSpace);
180  }
181 
182  void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
183  {
184  // Next variable
185  NextType::yearEndBuild(state, year, numSpace);
186  }
187 
188  void yearEnd(uint year, unsigned int numSpace)
189  {
190  // Next variable
191  NextType::yearEnd(year, numSpace);
192  }
193 
194  void computeSummary(unsigned int year, unsigned int numSpace)
195  {
196  // Next variable
197  NextType::computeSummary(year, numSpace);
198  }
199 
200  void hourBegin(uint hourInTheYear)
201  {
202  // Next variable
203  NextType::hourBegin(hourInTheYear);
204  }
205 
206  void hourForEachArea(State& state, unsigned int numSpace)
207  {
208  // Next variable
209  NextType::hourForEachArea(state, numSpace);
210  }
211 
212  void hourForEachLink(State& state, unsigned int numSpace)
213  {
214  // Next item in the list
215  NextType::hourForEachLink(state, numSpace);
216  }
217 
218  void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
219  {
220  if (dataLevel & Category::DataLevel::link)
221  {
222  if (digestLevel & Category::digestFlowQuad)
223  {
224  results.data.matrix
225  .entry[results.data.link->from->index][results.data.link->with->index]
226  = AncestorType::pResults.rawdata.allYears;
227  results.data.matrix
228  .entry[results.data.link->with->index][results.data.link->from->index]
229  = -AncestorType::pResults.rawdata.allYears;
230  }
231  }
232  // Next
233  NextType::buildDigest(results, digestLevel, dataLevel);
234  }
235 
236  Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
237  uint,
238  uint) const
239  {
240  return pValuesForTheCurrentYear.hour;
241  }
242 
243  void localBuildAnnualSurveyReport(SurveyResults& results,
244  int fileLevel,
245  int precision,
246  uint) 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.template buildAnnualSurveyReport<VCardType>(results,
257  fileLevel,
258  precision);
259  }
260  }
261 
262 private:
263  uint pLinkGlobalIndex;
264  uint pNbHours;
265  std::vector<std::vector<double>>* transitMoyenInterco_;
266 
268  typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
269 
270 }; // class FlowQuad
271 
272 } // namespace Antares::Solver::Variable::Economy
273 
274 #endif // __SOLVER_VARIABLE_ECONOMY_FlowQuad_H__
Definition for a single area.
Definition: area.h:51
Definition: study.h:57
Marginal FlowQuad.
Definition: flowQuad.h:85
Variable::IVariable< FlowQuad< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition: flowQuad.h:92
@ count
How many items have we got.
Definition: flowQuad.h:102
VCardFlowQuad VCardType
VCard.
Definition: flowQuad.h:90
NextT NextType
Type of the next static variable.
Definition: flowQuad.h:88
VCardType::ResultsType ResultsType
List of expected results.
Definition: flowQuad.h:95
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
void reset()
Reset all values.
Definition: intermediate.hxx:33
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 std::string Unit()
Unit.
Definition: flowQuad.h:37
Results< R::AllYears::Raw< > > ResultsType
The expecte results.
Definition: flowQuad.h:51
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition: flowQuad.h:74
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition: flowQuad.h:66
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition: flowQuad.h:72
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition: flowQuad.h:68
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition: flowQuad.h:62
static std::string Description()
The short description of the variable.
Definition: flowQuad.h:43
static std::string Caption()
Caption.
Definition: flowQuad.h:31
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition: flowQuad.h:56
static constexpr uint8_t decimal
Decimal precision.
Definition: flowQuad.h:64
static constexpr uint8_t categoryDataLevel
Data Level.
Definition: flowQuad.h:54
static constexpr uint8_t precision
Precision (views)
Definition: flowQuad.h:60