Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
math.hxx
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
22#include <cmath>
23
24#include <yuni/yuni.h>
25
26#include <antares/logs/logs.h>
27#include <antares/study/study.h>
28#include "antares/solver/ts-generator/xcast/xcast.h"
29
30#include "constants.h"
31
32using namespace Yuni;
33
34namespace Antares
35{
36namespace TSGenerator
37{
38namespace XCast
39{
40/*
41** This function is no longer used but remains for code clarity
42**
43float Minimum(float a,float b,float g,float d,int l)
44{
45 switch(l)
46 {
47 case 1: return 0;
48 case 2: return 0;
49 case 3: return 0;
50 case 4: return 0;
51 case 5: return 0;
52 }
53 return 0.f;
54}
55*/
56
57static float maximum(float a, float b, float g, float d, int l)
58{
60 {
64 {
65 return d - g;
66 }
68 {
69 // on regle la borne pour que le residu sur la fonction de repartition :
70 // y= 1-exp(-(x/b)^a) soit < NEGLI_WEIB
71 return (b * (float(pow(log(1. / NEGLI_WEIB), double(1. / a))))) - g;
72 }
74 {
75 // on regle la borne pour que la fonction de distribution :
76 // y = b*((bx)^a-1)*exp(-bx)/gamma_euler(a) soit < NEGLI_GAMM
77 // on regle la borne ou une valeur pessimiste en considerant que la
78 // fonction ne diminue pas plus rapidement qu'une exponentielle
79 // (alors qu'on impose a >= 1)
80 // Since 3.5, B' = 1/B
81 return ((float)(log(1. / NEGLI_GAMM) * a * b)) - g;
82 }
83
86 return 0.f;
87 }
88 return 0.f;
89}
90
96static float esperance(float a, float b, float g, float d, int l)
97{
98 // note : valeur exprimee en valeur relative par rapport au minimum
100 {
102 return (a * (d - g)) / (a + b);
103
105 return (d - g) / 2.f;
106
108 return 6.f * b;
109
111 return b * (float)XCast::GammaEuler(1. + 1. / double(a));
112
114 return a * b;
115
118 return 0.f;
119 }
120 return 0.f;
121}
122
124static float standard(float a, float b, float g, float d, int l)
125{
126 switch (Data::XCast::Distribution(l))
127 {
129 {
130 float s = a + b;
131 s = s * s * (s + 1.f);
132 s = a * b / s;
133 s = (float)sqrt(s);
134 s = (d - g) * s;
135 return s;
136 }
138 {
139 return (d - g) / (3.464101615f /* float(sqrt(12.)) */);
140 }
142 {
143 return b;
144 }
146 {
147 const float x = (float)(XCast::GammaEuler(1. + 2. / double(a))
148 - pow(XCast::GammaEuler(1. + 1. / double(a)), 2.));
149 if (x < 0.f)
150 {
151 logs.warning()
152 << "TS Generator: error when computing the standard deviation (Weibul Shape A)";
153 return 0.f;
154 }
155 return b * sqrt(x);
156 }
158 {
159 return (float)(sqrt(a) * b);
160 }
161
164 return 0.f;
165 }
166 return 0.f;
167}
168
170static float diffusion(float a, float b, float g, float d, int l, float t, float x)
171{
172 switch (Data::XCast::Distribution(l))
173 {
175 {
176 return (float)sqrt(2. * t * x * ((d - g) - x) / (a + b));
177 }
179 {
180 return (float)sqrt(t * x * ((d - g) - x));
181 }
183 {
184 return b * (float)sqrt(2. * t);
185 }
187 {
188 // Warning:
189 // On suppose ici que d a ete correctement initialise avec d=gamma_euler(1+1/a)
190 //
191 assert(b != 0 && "division by zero");
192 const double v = pow(x / b, a);
193 const double w = exp(v);
194
195 double y = (w - 1.) * double(d);
196 y -= w * XCast::GammaInc(double(1. + 1. / a), v);
197 y /= v;
198 y *= x * b * 2. * t / a;
199 if (y < 0.)
200 {
201 logs.info() << " square diff: " << y << " (Weibul Shape A)";
202 y = 1e-6;
203 }
204 return (float)sqrt(y);
205 }
207 {
208 return (float)sqrt(2. * t * x * b);
209 }
210
213 return 0.f;
214 }
215 return 0.f;
216}
217
218/*
219** \brief Verification de l'acceptabilite d'une factorisation LtL
220**
221**
222** Ce code verifie si LtL est proche de A, A symetrique reelle et L triangulaire
223** inferieure qui n'est pas necessairement definie positive.
224**
225** \param L estimation a priori de la racine carrée autoconjuguée de A
226** \param A matrice symétrique NxN
227** \param N Nombre de processus
228**
229** \return True si la factorisation est correcte a la tolerance pres
230*/
231/*static bool proma(float** L, float** A, uint N)
232{
233 float estim_aij;
234 uint i, j, k;
235
236 for (i = 0; i < N; i++)
237 {
238 for (j = 0; j <= i; ++j)
239 {
240 estim_aij = 0.f;
241 for (k = 0; k < N; ++k)
242 estim_aij += L[i][k] * L[j][k];
243
244 if (std::abs(estim_aij - A[i][j]) > EPSIMAX)
245 return false;
246 }
247 }
248 return true;
249}*/
250
251static bool verification(float a, float b, float g, float d, int l, float t)
252{
253 switch (Data::XCast::Distribution(l))
254 {
256 {
257 return !(d < g || g < INFININ / 2.f || d > INFINIP / 2.f || t < 0.f || a < 0.f || b < 0.f);
258 }
260 {
261 return !(d < g || g < INFININ / 2.f || d > INFINIP / 2.f || t < 0.f);
262 }
264 {
265 return !(d < g || g < INFININ / 2.f || d > INFINIP / 2.f || a < INFININ / 2.f
266 || a > INFINIP / 2.f || t < 0.f || b < 0.f);
267 }
269 {
270 return !(g < INFININ / 2.f || a < 1.f || a > 50.f || t < 0.f || b <= 0.f);
271 }
273 {
274 return !(g < INFININ / 2.f || a < 1.f || a > 50.f || t < 0.f || b <= 0.f);
275 }
276
279 return false;
280 }
281 return false;
282}
283
285static float maxiDiffusion(float a, float b, float g, float d, int l, float t)
286{
287 switch (Data::XCast::Distribution(l))
288 {
290 {
291 return (float)((d - g) * sqrt(t / (2. * (a + b))));
292 }
294 {
295 return (float)((d - g) * sqrt(t) / 2.);
296 }
298 {
299 return (float)(b * sqrt(2. * t));
300 }
302 {
303 // pour une loi de Weibull, on prend comme reference le max des diffusions obtenues pour :
304 // x= e= gamma_euler(1+1/a)
305 // x = Maximum
306 // quand a>1, x = b*(((a-1)/a)^(1/a))
307 // la valeur de la diffusion
308
309 // necessaire si d n'a pas ete initialise au prealable
310 d = float(XCast::GammaEuler(1. + 1. / double(a)));
311
312 float x = b * d;
313 float m = diffusion(a, b, g, d, l, t, x);
314 float y = diffusion(a, b, g, d, l, t, maximum(a, b, g, d, l));
315 if (y > m)
316 {
317 m = y;
318 }
319 if (a > 1.f)
320 {
321 x = (a - 1.f) / a;
322 x = (float)pow((double)x, (double)(1. / a));
323 x *= b;
324 y = diffusion(a, b, g, d, l, t, x);
325 if (y > m)
326 {
327 m = y;
328 }
329 }
330 return m;
331 }
333 {
334 return diffusion(a, b, g, d, l, t, maximum(a, b, g, d, l));
335 }
336
339 return 0.f;
340 }
341 return 0.f;
342}
343
344} // namespace XCast
345} // namespace TSGenerator
346} // namespace Antares
Distribution
All available probability distribution.
Definition xcast.h:61
@ dtGammaShapeA
The Gamma distribution, of shape A.
Definition xcast.h:73
@ dtNormal
The normal distribution.
Definition xcast.h:69
@ dtMax
The maximum number of distributions.
Definition xcast.h:75
@ dtWeibullShapeA
The Weibul distribution, of shape A.
Definition xcast.h:71
@ dtNone
None.
Definition xcast.h:63
@ dtBeta
The Beta distribution.
Definition xcast.h:67
@ dtUniform
The uniform distribution.
Definition xcast.h:65
static double GammaInc(double s, double z)
Calcul de la forme inférieure de la fonction gamma incomplete.
Definition gamma-inc.cpp:37
static double GammaEuler(double z)
Compute.
Definition gamma-euler.cpp:37