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