Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
balance.h
1/*
2** Copyright 2007-2024, 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_BALANCE_H__
22#define __SOLVER_VARIABLE_ECONOMY_BALANCE_H__
23
24#include "antares/solver/variable/variable.h"
25
26namespace Antares
27{
28namespace Solver
29{
30namespace Variable
31{
32namespace Economy
33{
35{
37 static std::string Caption()
38 {
39 return "BALANCE";
40 }
41
43 static std::string Unit()
44 {
45 return "MWh";
46 }
47
49 static std::string Description()
50 {
51 return "Nodal energy balance, throughout all MC years";
52 }
53
55 typedef Results<R::AllYears::Average< // The average values throughout all years
56 R::AllYears::StdDeviation< // The standard deviation values throughout all years
57 R::AllYears::Min< // The minimum values throughout all years
58 R::AllYears::Max< // The maximum values throughout all years
59 >>>>>
61
64
66 static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
68 static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
69 & (Category::FileLevel::id
70 | Category::FileLevel::va);
72 static constexpr uint8_t precision = Category::all;
74 static constexpr uint8_t nodeDepthForGUI = +0;
76 static constexpr uint8_t decimal = 0;
78 static constexpr int columnCount = 1;
80 static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
81 static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
82 static constexpr uint8_t spatialAggregatePostProcessing = 0;
84 static constexpr uint8_t hasIntermediateValues = 1;
86 static constexpr uint8_t isPossiblyNonApplicable = 0;
87
89 typedef std::vector<IntermediateValues> IntermediateValuesType;
90
92
93}; // class VCard
94
98template<class NextT = Container::EndOfList>
99class Balance: public Variable::IVariable<Balance<NextT>, NextT, VCardBalance>
100{
101public:
103 typedef NextT NextType;
108
111
113
114 enum
115 {
117 count = 1 + NextT::count,
118 };
119
120 template<int CDataLevel, int CFile>
122 {
123 enum
124 {
125 count = ((VCardType::categoryDataLevel & CDataLevel
127 ? (NextType::template Statistics<CDataLevel, CFile>::count
129 : NextType::template Statistics<CDataLevel, CFile>::count),
130 };
131 };
132
133public:
134 ~Balance() = default;
135
136 void initializeFromStudy(Data::Study& study)
137 {
138 pNbYearsParallel = study.maxNbYearsInParallel;
139
140 InitializeResultsFromStudy(AncestorType::pResults, study);
141
142 pValuesForTheCurrentYear.resize(pNbYearsParallel);
143 for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
144 {
145 pValuesForTheCurrentYear[numSpace].initializeFromStudy(study);
146 }
147
148 // Next
149 NextType::initializeFromStudy(study);
150 }
151
152 template<class R>
153 static void InitializeResultsFromStudy(R& results, Data::Study& study)
154 {
155 VariableAccessorType::InitializeAndReset(results, study);
156 }
157
158 void initializeFromArea(Data::Study* study, Data::Area* area)
159 {
160 // Next
161 NextType::initializeFromArea(study, area);
162 }
163
164 void initializeFromLink(Data::Study* study, Data::AreaLink* link)
165 {
166 // Next
167 NextType::initializeFromAreaLink(study, link);
168 }
169
170 void simulationBegin()
171 {
172 // Next
173 NextType::simulationBegin();
174 }
175
176 void simulationEnd()
177 {
178 NextType::simulationEnd();
179 }
180
181 void yearBegin(unsigned int year, unsigned int numSpace)
182 {
183 // A single reset is enough
184 pValuesForTheCurrentYear[numSpace].reset();
185 // Next variable
186 NextType::yearBegin(year, numSpace);
187 }
188
189 void yearEndBuild(State& state, unsigned int year, unsigned int numSpace)
190 {
191 // Next variable
192 NextType::yearEndBuild(state, year, numSpace);
193 }
194
195 void yearEnd(unsigned int year, unsigned int numSpace)
196 {
197 // Compute all statistics for the current year (daily,weekly,monthly)
198 pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear();
199
200 // Next variable
201 NextType::yearEnd(year, numSpace);
202 }
203
204 void computeSummary(std::map<unsigned int, unsigned int>& numSpaceToYear,
205 unsigned int nbYearsForCurrentSummary)
206 {
207 for (unsigned int numSpace = 0; numSpace < nbYearsForCurrentSummary; ++numSpace)
208 {
209 // Merge all those values with the global results
210 AncestorType::pResults.merge(numSpaceToYear[numSpace] /*year*/,
211 pValuesForTheCurrentYear[numSpace]);
212 }
213
214 // Next variable
215 NextType::computeSummary(numSpaceToYear, nbYearsForCurrentSummary);
216 }
217
218 void hourBegin(unsigned int hourInTheYear)
219 {
220 // Next variable
221 NextType::hourBegin(hourInTheYear);
222 }
223
224 void hourForEachArea(State& state, unsigned int numSpace)
225 {
226 double bilanPays = 0.;
227 int Interco = state.problemeHebdo->IndexDebutIntercoOrigine[state.area->index];
228 while (Interco >= 0)
229 {
230 bilanPays += state.ntc.ValeurDuFlux[static_cast<std::size_t>(Interco)];
231 Interco = state.problemeHebdo
232 ->IndexSuivantIntercoOrigine[static_cast<std::size_t>(Interco)];
233 }
234 Interco = state.problemeHebdo->IndexDebutIntercoExtremite[state.area->index];
235 while (Interco >= 0)
236 {
237 bilanPays -= state.ntc.ValeurDuFlux[static_cast<std::size_t>(Interco)];
238 Interco = state.problemeHebdo
239 ->IndexSuivantIntercoExtremite[static_cast<std::size_t>(Interco)];
240 }
241
242 pValuesForTheCurrentYear[numSpace][state.hourInTheYear] = bilanPays;
243 // Next variable
244 NextType::hourForEachArea(state, numSpace);
245 }
246
247 Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
248 unsigned int,
249 unsigned int numSpace) const
250 {
251 return pValuesForTheCurrentYear[numSpace].hour;
252 }
253
254 void localBuildAnnualSurveyReport(SurveyResults& results,
255 int fileLevel,
256 int precision,
257 unsigned int numSpace) const
258 {
259 // Initializing external pointer on current variable non applicable status
260 results.isCurrentVarNA = AncestorType::isNonApplicable;
261
262 if (AncestorType::isPrinted[0])
263 {
264 // Write the data for the current year
265 results.variableCaption = VCardType::Caption();
266 results.variableUnit = VCardType::Unit();
267 pValuesForTheCurrentYear[numSpace]
268 .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
269 }
270 }
271
272private:
274 typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
275 unsigned int pNbYearsParallel;
276
277}; // class Balance
278
279} // namespace Economy
280} // namespace Variable
281} // namespace Solver
282} // namespace Antares
283
284#endif // __SOLVER_VARIABLE_ECONOMY_BALANCE_H__
Definition for a single area.
Definition area.h:52
Definition study.h:61
Marginal Balance.
Definition balance.h:100
VCardBalance VCardType
VCard.
Definition balance.h:105
@ count
How many items have we got.
Definition balance.h:117
VCardType::ResultsType ResultsType
List of expected results.
Definition balance.h:110
NextT NextType
Type of the next static variable.
Definition balance.h:103
Variable::IVariable< Balance< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition balance.h:107
Interface for any variable.
Definition variable.h:51
StoredResultType pResults
All the results about this variable.
Definition variable.h:327
Temporary buffer for allocating results for a single year.
Definition intermediate.h:46
Definition results.h:48
@ count
The count if item in the list.
Definition results.h:56
Definition cbuilder.h:120
Definition variable.h:25
static constexpr int columnCount
Number of columns used by the variable (One ResultsType per column)
Definition balance.h:78
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition balance.h:68
static std::string Description()
The short description of the variable.
Definition balance.h:49
static constexpr uint8_t categoryDataLevel
Data Level.
Definition balance.h:66
Results< R::AllYears::Average< R::AllYears::StdDeviation< R::AllYears::Min< R::AllYears::Max< > > > > > ResultsType
The expecte results.
Definition balance.h:60
static std::string Unit()
Unit.
Definition balance.h:43
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition balance.h:80
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition balance.h:74
static std::string Caption()
Caption.
Definition balance.h:37
static constexpr uint8_t decimal
Decimal precision.
Definition balance.h:76
static constexpr uint8_t precision
Precision (views)
Definition balance.h:72
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition balance.h:84
VCardBalance VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition balance.h:63
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition balance.h:86