Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
STStorageCashFlowByCluster.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#pragma once
22
23#include "antares/solver/variable/variable.h"
24
25namespace Antares::Solver::Variable::Economy
26{
28{
30 static std::string Caption()
31 {
32 return "STS Cashflow By Cluster";
33 }
34
36 static std::string Unit()
37 {
38 return "CashFlow - Euro";
39 }
40
42 static std::string Description()
43 {
44 return "Cash Flow by short term storage";
45 }
46
48 typedef Results<R::AllYears::Average< // The average values throughout all years
49 >>
51
54
56 static constexpr uint8_t categoryDataLevel = Category::DataLevel::area;
58 static constexpr uint8_t categoryFileLevel = ResultsType::categoryFile
59 & Category::FileLevel::de_sts;
61 static constexpr uint8_t precision = Category::all;
63 static constexpr uint8_t nodeDepthForGUI = +0;
65 static constexpr uint8_t decimal = 0;
67 static constexpr int columnCount = Category::dynamicColumns;
69 static constexpr uint8_t spatialAggregate = Category::spatialAggregateSum;
70 static constexpr uint8_t spatialAggregateMode = Category::spatialAggregateEachYear;
71 static constexpr uint8_t spatialAggregatePostProcessing = 0;
73 static constexpr uint8_t hasIntermediateValues = 1;
75 static constexpr uint8_t isPossiblyNonApplicable = 0;
76
78 typedef std::vector<IntermediateValues> IntermediateValuesBaseType;
79 typedef std::vector<IntermediateValuesBaseType> IntermediateValuesType;
80
81}; // class VCard
82
86template<class NextT = Container::EndOfList>
87class STstorageCashFlowByCluster: public Variable::IVariable<STstorageCashFlowByCluster<NextT>,
88 NextT,
89 VCardSTstorageCashFlowByCluster>
90{
91public:
93 typedef NextT NextType;
98
101
103
104 static constexpr int count = 1 + NextT::count;
105
106 template<int CDataLevel, int CFile>
108 {
109 enum
110 {
111 count = ((VCardType::categoryDataLevel & CDataLevel
113 ? (NextType::template Statistics<CDataLevel, CFile>::count
115 : NextType::template Statistics<CDataLevel, CFile>::count),
116 };
117 };
118
119public:
120 STstorageCashFlowByCluster() = default;
121
122 void initializeFromArea(Data::Study* study, Data::Area* area)
123 {
124 // Get the number of years in parallel
125 pNbYearsParallel = study->maxNbYearsInParallel;
126 pValuesForTheCurrentYear.resize(pNbYearsParallel);
127
128 // Get the area
129 nbClusters_ = area->shortTermStorage.count();
130 if (nbClusters_)
131 {
132 AncestorType::pResults.resize(nbClusters_);
133
134 for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
135 {
136 pValuesForTheCurrentYear[numSpace].resize(nbClusters_);
137 }
138
139 for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++)
140 {
141 for (unsigned int i = 0; i != nbClusters_; ++i)
142 {
143 pValuesForTheCurrentYear[numSpace][i].initializeFromStudy(*study);
144 }
145 }
146
147 for (unsigned int i = 0; i != nbClusters_; ++i)
148 {
149 AncestorType::pResults[i].initializeFromStudy(*study);
150 AncestorType::pResults[i].reset();
151 }
152 }
153 else
154 {
156 }
157 // Next
158 NextType::initializeFromArea(study, area);
159 }
160
161 size_t getMaxNumberColumns() const
162 {
163 return nbClusters_ * ResultsType::count;
164 }
165
166 void yearBegin(unsigned int year, unsigned int numSpace)
167 {
168 // Reset the values for the current year
169 for (unsigned int clusterIndex = 0; clusterIndex != nbClusters_; ++clusterIndex)
170 {
171 pValuesForTheCurrentYear[numSpace][clusterIndex].reset();
172 }
173 // Next variable
174 NextType::yearBegin(year, numSpace);
175 }
176
177 void yearEnd(unsigned int year, unsigned int numSpace)
178 {
179 for (unsigned int clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
180 {
181 // Compute all statistics from hourly results for the current year (daily, weekly,
182 // monthly, ...)
183 pValuesForTheCurrentYear[numSpace][clusterIndex].computeStatisticsForTheCurrentYear();
184 }
185 // Next variable
186 NextType::yearEnd(year, numSpace);
187 }
188
189 void computeSummary(std::map<unsigned int, unsigned int>& numSpaceToYear,
190 unsigned int nbYearsForCurrentSummary)
191 {
192 for (unsigned int numSpace = 0; numSpace < nbYearsForCurrentSummary; ++numSpace)
193 {
194 for (unsigned int clusterIndex = 0; clusterIndex < nbClusters_; ++clusterIndex)
195 {
196 // Merge all those values with the global results
197 AncestorType::pResults[clusterIndex].merge(
198 numSpaceToYear[numSpace],
199 pValuesForTheCurrentYear[numSpace][clusterIndex]);
200 }
201 }
202
203 // Next variable
204 NextType::computeSummary(numSpaceToYear, nbYearsForCurrentSummary);
205 }
206
207 void hourBegin(unsigned int hourInTheYear)
208 {
209 // Next variable
210 NextType::hourBegin(hourInTheYear);
211 }
212
213 void hourForEachArea(State& state, unsigned int numSpace)
214 {
215 unsigned int hourInYear = state.hourInTheYear;
216 for (uint clusterIndex = 0; clusterIndex != state.area->shortTermStorage.count();
217 ++clusterIndex)
218 {
219 const auto& stsHourlyResults = state.hourlyResults
220 ->ShortTermStorage[state.hourInTheWeek];
221 // ST storage injection for the current cluster and this hour
222 // CashFlow[h] = (withdrawal - injection) * MRG. PRICE
223 pValuesForTheCurrentYear[numSpace][clusterIndex].hour[hourInYear]
224 = (stsHourlyResults.withdrawal[clusterIndex]
225 - stsHourlyResults.injection[clusterIndex])
226 * (-state.hourlyResults->CoutsMarginauxHoraires[state.hourInTheWeek]);
227 // Note: The marginal price provided by the solver is negative (naming convention).
228 }
229
230 // Next variable
231 NextType::hourForEachArea(state, numSpace);
232 }
233
234 inline void buildDigest(SurveyResults& results, int digestLevel, int dataLevel) const
235 {
236 // Ask to build the digest to the next variable
237 NextType::buildDigest(results, digestLevel, dataLevel);
238 }
239
240 Antares::Memory::Stored<double>::ConstReturnType retrieveRawHourlyValuesForCurrentYear(
241 unsigned int column,
242 unsigned int numSpace) const
243 {
244 return pValuesForTheCurrentYear[numSpace][column].hour;
245 }
246
247 void localBuildAnnualSurveyReport(SurveyResults& results,
248 int fileLevel,
249 int precision,
250 unsigned int numSpace) const
251 {
252 // Initializing external pointer on current variable non applicable status
253 results.isCurrentVarNA = AncestorType::isNonApplicable;
254
255 if (AncestorType::isPrinted[0])
256 {
257 assert(NULL != results.data.area);
258 const auto& shortTermStorage = results.data.area->shortTermStorage;
259
260 // Write the data for the current year
261 uint clusterIndex = 0;
262 for (const auto& cluster: shortTermStorage.storagesByIndex)
263 {
264 // Write the data for the current year
265 results.variableCaption = cluster.properties.name;
266 results.variableUnit = VCardType::Unit();
267 pValuesForTheCurrentYear[numSpace][clusterIndex]
268 .template buildAnnualSurveyReport<VCardType>(results, fileLevel, precision);
269
270 clusterIndex++;
271 }
272 }
273 }
274
275private:
277 typename VCardType::IntermediateValuesType pValuesForTheCurrentYear;
278 size_t nbClusters_ = 0;
279 unsigned int pNbYearsParallel = 0;
280
281}; // class STstorageCashFlowByCluster
282
283} // End namespace Antares::Solver::Variable::Economy
Definition for a single area.
Definition area.h:52
Definition study.h:61
Energy generated by short term storage clusters.
Definition STStorageCashFlowByCluster.h:90
NextT NextType
Type of the next static variable.
Definition STStorageCashFlowByCluster.h:93
Variable::IVariable< STstorageCashFlowByCluster< NextT >, NextT, VCardType > AncestorType
Ancestor.
Definition STStorageCashFlowByCluster.h:97
VCardSTstorageCashFlowByCluster VCardType
VCard.
Definition STStorageCashFlowByCluster.h:95
VCardType::ResultsType ResultsType
List of expected results.
Definition STStorageCashFlowByCluster.h:100
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
static constexpr int columnCount
Number of columns used by the variable.
Definition STStorageCashFlowByCluster.h:67
static constexpr uint8_t spatialAggregate
The Spatial aggregation.
Definition STStorageCashFlowByCluster.h:69
static constexpr uint8_t hasIntermediateValues
Intermediate values.
Definition STStorageCashFlowByCluster.h:73
Results< R::AllYears::Average< > > ResultsType
The expecte results.
Definition STStorageCashFlowByCluster.h:50
static constexpr uint8_t decimal
Decimal precision.
Definition STStorageCashFlowByCluster.h:65
static constexpr uint8_t categoryDataLevel
Data Level.
Definition STStorageCashFlowByCluster.h:56
static constexpr uint8_t isPossiblyNonApplicable
Can this variable be non applicable (0 : no, 1 : yes)
Definition STStorageCashFlowByCluster.h:75
VCardSTstorageCashFlowByCluster VCardForSpatialAggregate
The VCard to look for for calculating spatial aggregates.
Definition STStorageCashFlowByCluster.h:53
static std::string Unit()
Unit.
Definition STStorageCashFlowByCluster.h:36
static std::string Caption()
Caption.
Definition STStorageCashFlowByCluster.h:30
static std::string Description()
The short description of the variable.
Definition STStorageCashFlowByCluster.h:42
static constexpr uint8_t precision
Precision (views)
Definition STStorageCashFlowByCluster.h:61
static constexpr uint8_t nodeDepthForGUI
Indentation (GUI)
Definition STStorageCashFlowByCluster.h:63
static constexpr uint8_t categoryFileLevel
File level (provided by the type of the results)
Definition STStorageCashFlowByCluster.h:58