Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
atsp.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 __PREPROCESSOR_ATSP_H__
22#define __PREPROCESSOR_ATSP_H__
23
24#include <memory>
25
26#include <yuni/yuni.h>
27#include <yuni/core/string.h>
28
29#include <antares/study/study.h>
30#include <antares/study/xcast/xcast.h>
31
32namespace Antares
33{
34class ATSP final
35{
36public:
38 using Ptr = std::shared_ptr<ATSP>;
39
40public:
42
43
46 ATSP();
48 ~ATSP();
50
54 bool loadFromINIFile(const Yuni::String& filename);
55
59 void printSummary() const;
60
61 bool preflight();
62
63 bool computeMonthlyCorrelations();
64
65private:
66 class AreaInfo final
67 {
68 public:
70 using Vector = std::vector<AreaInfo>;
71
72 public:
73 bool enabled;
74 Data::AreaName name;
75 Yuni::String filename;
76 bool rawData;
77 Data::XCast::Distribution distribution;
78 };
79
80 struct MomentCentrSingle
81 {
82 double data[12][4];
83 };
84
85 using MomentCentr = std::vector<MomentCentrSingle>;
86
87 struct HiddenHoursSingle
88 {
89 int data[12][24];
90 };
91
92 using HiddenHours = std::vector<HiddenHoursSingle>;
93
94private:
95 // range dans les nblig première lignes et nbcol premières colonnes de OUT
96 // le bloc d'élements de MTRX de taille nblig x nbcol commençant aux indices indlig et indcol
97 static void Extrait_bloc(Matrix<>& out,
98 uint indlig,
99 uint indcol,
100 const Matrix<>& MTRX,
101 uint nblig,
102 uint nbcol);
103
104 // range dans OUT la moyenne des colonnes de MTRX
105 static void Colonne_moyenne(double* out, const Matrix<>& MTRX, uint nblig, uint nbcol);
106
107 // retourne le maximum ou le minimum de MTRX selon le code
108 static void Mtrx_bound(double& rmin,
109 double& rmax,
110 const Matrix<>& MTRX,
111 uint nblig,
112 uint nbcol);
113
114 // met dans OUT la valeur absolue de MTRX
115 static void Mtrx_abs(Matrix<>& out, const Matrix<>& MTRX, uint nblig, uint nbcol);
116
117 // retourne la moyenne des elements de A
118 static double Moyenne_generale(double* A, uint nblig);
119
120 // retranche de MTRX le vecteur A
121 static void Retranche_mtrx(Matrix<>& MTRX, const double* A, uint nblig, uint nbcol);
122
123 // range dans OUT les nblig première lignes de la colonne de MTRX d'indice indcol
124 static void Extrait_col(double* out, const Matrix<>& MTRX, uint nblig, uint indcol);
125
126 // met dans A le carre de B
127 static void Square(double* A, const double* B, uint nblig);
128
129 // met (B- le scalaire x) dans A
130 static void Retranche_scalaire(Matrix<>& A,
131 const Matrix<>& B,
132 double x,
133 uint nblig,
134 uint nbcol);
135
136 // met (B /scalaire x) dans A
137 static void Divise_scalaire(Matrix<>& A, const Matrix<>& B, double x, uint nblig, uint nbcol);
138
139 // met dans A le cube de B
140 static void Cube(double* A, const double* B, uint nblig);
141
142 // met dans A B^4
143 static void Dsquare(double* A, const double* B, uint nblig);
144
145 // range dans OUT nblig elements de MTRX pris a partir de l'indice indlig
146 static void Extrait_seg(double* out, const double* src, uint nblig, uint indlig);
147
148 // retourne le coefficient de corrélation entre A et B (retourne 999 si paramètre "code"
149 // aberrant)
150 // si code = 0 : les espérances et écarts-types des variables représentées par A et B sont à
151 // calculer si code = 1 : des estimations des espérances et écarts-types sont fournis dans
152 // EA,EB,SA,SB
153 static double Correlation(double* A,
154 double* B,
155 uint nblig,
156 double EA,
157 double EB,
158 double SA,
159 double SB,
160 int code);
161
162 static double GammaEuler(double z);
163
164 static double Ecart(double T1, double P1, double T2, double P2, int M, double T);
165
166 static double autocorr_average(int H, int M, double R);
167
168 static double Standard_shrinkage(int M, double R);
169
170private:
172 bool checkStudyVersion() const;
173
174 bool preflight(const uint areaIndex);
175
176 void Analyse_auto(double* A,
177 int nblig,
178 double auc,
179 double aum,
180 double hor,
181 double& theta,
182 double& mu);
183
184 // ajustement de la densité de probabilité en fonction des bornes L, U, de l'espérance E
185 // et de l'écart-type S
186 // selon une loi "type" : calcule alpha=A, beta = B, gamma = C, delta = D
187 // retourne 0 si le calage est possible et 1 sinon
188 bool Probab_density_funct(double L,
189 double U,
190 double E,
191 double S,
193 double& A,
194 double& B,
195 double& C,
196 double& D);
197
198 void roundMatrixValues(Matrix<>& m);
199
200 bool writeMoments() const;
201
202 void cacheCreate();
203 void cacheClear();
204 bool cacheFetch(uint index, Matrix<>& out) const;
205
206 bool cachePreload(uint index,
207 const AnyString& filename,
208 uint height,
209 Matrix<>::BufferType& buffer);
210
211private:
212 AreaInfo::Vector pArea;
213 YString pStudyFolder;
214 YString pTemp;
215 uint pTimeseriesCount;
216 uint pMHeight;
217 uint pTimeseries;
218 double pMediumTermAutoCorrAdjustment;
219 double pShortTermAutoCorrAdjustment;
220 double pRoundOff;
221 double pUpperBound;
222 double pUpperBound80percent;
223 double pLowerBound;
224 bool pUseUpperBound;
225 bool pUseLowerBound;
226 uint64_t pRoundingCount;
227 uint64_t pRounding80percentCount;
228 uint64_t pRoundingCountTotal;
229 Yuni::ShortString16 tsName;
230
231 uint pEnabledAreaCount;
232
234 uint NBZ;
236 uint NBS;
237
239 char TDS;
241 char code;
242
243 double RTZ;
245 double AUC;
247 double AUM;
248
258 const double HOR; // 0.92 by default
259
260 enum
261 {
263 PRA = 120,
264 };
265
266 MomentCentr moments_centr_net;
267 MomentCentr moments_centr_raw;
268
269 HiddenHours hidden_hours;
270
271 Matrix<> SERIE_N;
272 Matrix<> SERIE_P;
273 Matrix<> SERIE_Q;
274
275 double buffer_n[744];
276 double buffer_p[744];
277 double buffer_q[744];
278
279 static const uint lonmois[12];
280 static const uint durmois[12];
281 static const uint posmois[12];
282
283 enum
284 {
285 durjour = 24
286 };
287
288 uint64_t pLimitMemory;
289 uint64_t pCacheMemoryUsed;
290 uint pCacheLastValidIndex;
291 std::vector<Matrix<>> pCacheMatrix;
292
293 Yuni::String::Vector folderPerArea;
295 Yuni::CString<512> pStr;
296
297 bool pAutoClean;
298
299}; // class ATSP
300
301} // namespace Antares
302
303#include "atsp.hxx"
304
305#endif // __PREPROCESSOR_ATSP_H__
Definition atsp.h:35
ATSP()
Default constructor.
Definition atsp.cpp:35
~ATSP()
Destructor.
Definition atsp.cpp:46
void printSummary() const
Print a summary.
Definition atsp.cpp:72
std::shared_ptr< ATSP > Ptr
The most suitable smart pointer for the class.
Definition atsp.h:38
bool loadFromINIFile(const Yuni::String &filename)
Load settings from an INI file.
Definition load.cpp:32
Distribution
All available probability distribution.
Definition xcast.h:61
A n-by-n matrix.
Definition jit.h:30
Yuni::Clob BufferType
A buffer, for large amount of data.
Definition matrix.h:65