-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntegrationFunction.cpp
executable file
·68 lines (62 loc) · 1.94 KB
/
IntegrationFunction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "TF1.h"
#include "TF2.h"
#include "Math/Integrator.h"
#include "IntegrationFunction.h"
IntegrationFunction::IntegrationFunction(int npar, int nvar, bool integralFast)
{
n_param = npar;
n_var = nvar;
useIntegralFast = integralFast;
}
void generateGaussLegendreSamplingPoint(int n)
{
TF1 f{};
n_gaussLegendreSamplingPoints = n;
gaussLegendreWeights = new double[n];
gaussLegendreAbscissas = new double[n];
f.CalcGaussLegendreSamplingPoints(n,gaussLegendreAbscissas,gaussLegendreWeights);
gaussLegendreSamplingPointsGenerated = true;
}
void IntegrationFunction::setLimits(double a1, double b1, double a2, double b2)
{
integralLowerLimit1 = a1;
integralUpperLimit1 = b1;
integralLowerLimit2 = a2;
integralUpperLimit2 = b2;
}
void IntegrationFunction::setFunction(double (*f)(double*,double*))
{
function = f;
if (n_var == 1)
{
ROOT::Math::IntegratorOneDimOptions::SetDefaultIntegrator("Gauss");
function1D = {"1D_Integral", f, integralLowerLimit1, integralUpperLimit1, n_param};
functionInitialized = true;
}
else if (n_var == 2)
{
function2D = {"2D_Integral", f, integralLowerLimit1, integralUpperLimit1, integralLowerLimit2, integralUpperLimit2, n_param};
functionInitialized = true;
}
}
double IntegrationFunction::integrate(double *param){
if(!functionInitialized){
return 0;
}
if (n_var == 1)
{
function1D.SetParameters(param);
if(useIntegralFast)
{
if(!gaussLegendreSamplingPointsGenerated){ generateGaussLegendreSamplingPoint(); }
return function1D.IntegralFast(n_gaussLegendreSamplingPoints, gaussLegendreAbscissas, gaussLegendreWeights, integralLowerLimit1, integralUpperLimit1, param);
}
return function1D.Integral(integralLowerLimit1, integralUpperLimit1);
}
else if (n_var == 2)
{
function2D.SetParameters(param);
return function2D.Integral(integralLowerLimit1, integralUpperLimit1, integralLowerLimit2, integralUpperLimit2);
}
return 0;
}