Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
average.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_STORAGE_AVERAGE_H__
22#define __SOLVER_VARIABLE_STORAGE_AVERAGE_H__
23
24#include "averagedata.h"
25
26namespace Antares
27{
28namespace Solver
29{
30namespace Variable
31{
32namespace R
33{
34namespace AllYears
35{
36template<class NextT = Empty, int FileFilter = Variable::Category::FileLevel::allFile>
37struct Average: public NextT
38{
39public:
41 typedef NextT NextType;
42
43 enum
44 {
46 count = 1 + NextT::count,
47
48 categoryFile = NextT::categoryFile | Variable::Category::FileLevel::allFile,
49 };
50
51 struct Data
52 {
53 double value;
54 uint32_t indice;
55 };
56
58 static const char* Name()
59 {
60 return "average";
61 }
62
63public:
64 Average()
65 {
66 }
67
68protected:
69 void initializeFromStudy(Antares::Data::Study& study)
70 {
71 avgdata.initializeFromStudy(study);
72 // Next
73 NextType::initializeFromStudy(study);
74 }
75
76 void reset()
77 {
78 // Reset
79 avgdata.reset();
80 // Next
81 NextType::reset();
82 }
83
84 void merge(uint year, const IntermediateValues& rhs)
85 {
86 avgdata.merge(year, rhs);
87 // Next
88 NextType::merge(year, rhs);
89 }
90
91 template<class S, class VCardT>
92 void buildSurveyReport(SurveyResults& report,
93 const S& results,
94 int dataLevel,
95 int fileLevel,
96 int precision) const
97 {
98 if (!(fileLevel & Category::FileLevel::id))
99 {
100 switch (precision)
101 {
102 case Category::hourly:
103 InternalExportValues<HOURS_PER_YEAR, VCardT, Category::hourly>(report,
104 Memory::RawPointer(
105 avgdata.hourly));
106 break;
107 case Category::daily:
108 InternalExportValues<DAYS_PER_YEAR, VCardT, Category::daily>(report, avgdata.daily);
109 break;
110 case Category::weekly:
111 InternalExportValues<WEEKS_PER_YEAR, VCardT, Category::weekly>(report,
112 avgdata.weekly);
113 break;
114 case Category::monthly:
115 InternalExportValues<MONTHS_PER_YEAR, VCardT, Category::monthly>(report,
116 avgdata.monthly);
117 break;
118 case Category::annual:
119 InternalExportValues<1, VCardT, Category::annual>(report, avgdata.year.data());
120 break;
121 }
122 }
123 // Next
124 NextType::template buildSurveyReport<S, VCardT>(report,
125 results,
126 dataLevel,
127 fileLevel,
128 precision);
129 }
130
131 template<class VCardT>
132 void buildDigest(SurveyResults& report, int digestLevel, int dataLevel) const
133 {
134 const bool isCluster = (VCardT::categoryFileLevel & Category::FileLevel::de)
135 || (VCardT::categoryFileLevel & Category::FileLevel::de_res);
136 const bool isBindingConstraint = VCardT::categoryFileLevel & Category::FileLevel::bc;
137 const bool isDigest = digestLevel & Category::digestAllYears;
138 if ((dataLevel & Category::DataLevel::area || dataLevel & Category::DataLevel::setOfAreas)
139 && isDigest && !isCluster && !isBindingConstraint)
140 {
141 assert(report.data.columnIndex < report.maxVariables && "Column index out of bounds");
142
143 report.captions[0][report.data.columnIndex] = report.variableCaption;
144 report.captions[1][report.data.columnIndex] = report.variableUnit;
145 report.captions[2][report.data.columnIndex] = (report.variableCaption == "LOLP")
146 ? "values"
147 : "EXP";
148
149 // Precision
150 report.precision[report.data.columnIndex] = PrecisionToPrintfFormat<
151 VCardT::decimal>::Value();
152 // Value
153 report.values[report.data.columnIndex][report.data.rowIndex] = avgdata.allYears;
154 // Non applicability
155 report.digestNonApplicableStatus[report.data.rowIndex][report.data.columnIndex]
156 = *report.isCurrentVarNA;
157
158 ++(report.data.columnIndex);
159 }
160 // Next
161 NextType::template buildDigest<VCardT>(report, digestLevel, dataLevel);
162 }
163
164 template<template<class, int> class DecoratorT>
165 Antares::Memory::Stored<double>::ConstReturnType hourlyValuesForSpatialAggregate() const
166 {
167 if (Yuni::Static::Type::StrictlyEqual<DecoratorT<Empty, 0>, Average<Empty, 0>>::Yes)
168 {
169 return avgdata.hourly;
170 }
171 return NextType::template hourlyValuesForSpatialAggregate<DecoratorT>();
172 }
173
174public:
175 AverageData avgdata;
176
177private:
178 template<uint Size, class VCardT, int PrecisionT>
179 void InternalExportValues(SurveyResults& report, const double* array) const
180 {
181 assert(array);
182 assert(report.data.columnIndex < report.maxVariables && "Column index out of bounds");
183
184 // Caption
185 report.captions[0][report.data.columnIndex] = report.variableCaption;
186 report.captions[1][report.data.columnIndex] = report.variableUnit;
187 report.captions[2][report.data.columnIndex] = (report.variableCaption == "LOLP") ? "values"
188 : "EXP";
189 // Precision
190 report.precision[report.data.columnIndex] = PrecisionToPrintfFormat<
191 VCardT::decimal>::Value();
192 // Non applicability
193 report.nonApplicableStatus[report.data.columnIndex] = *report.isCurrentVarNA;
194
195 // Values
196 switch (PrecisionT)
197 {
198 case Category::annual:
199 {
200 double& target = *(report.values[report.data.columnIndex]);
201 target = 0;
202 for (uint i = 0; i != avgdata.nbYearsCapacity; ++i)
203 {
204 target += array[i];
205 }
206 avgdata.allYears = target;
207 break;
208 }
209 default:
210 (void)::memcpy(report.values[report.data.columnIndex], array, sizeof(double) * Size);
211 break;
212 }
213
214 // Next column index
215 ++report.data.columnIndex;
216 }
217
218}; // class Average
219
220} // namespace AllYears
221} // namespace R
222} // namespace Variable
223} // namespace Solver
224} // namespace Antares
225
226#endif // __SOLVER_VARIABLE_STORAGE_AVERAGE_H__
Definition study.h:61
Definition variable.h:25
static const char * Name()
Name of the filter.
Definition average.h:58
NextT NextType
Type of the net item in the list.
Definition average.h:41
@ count
The count if item in the list.
Definition average.h:46