Thermal-FIST  1.3
Package for hadron resonance gas model applications
NumericalIntegration.cpp
Go to the documentation of this file.
1 /*
2  * Thermal-FIST package
3  *
4  * Copyright (c) 2014-2018 Volodymyr Vovchenko
5  *
6  * GNU General Public License (GPLv3 or later)
7  */
9 
10 namespace thermalfist {
11 
12  namespace NumericalIntegration {
13 
14  double Integrate2DLaguerre32Legendre32(double(*func)(double, double), double ay, double by)
15  {
16  // Integrate 2D function from 0 to infinity using Gauss-Laguerre integration
17  // with 32 points and from ay to by using Gauss-Legendre integration with 32 points
18  //
19 
20  const double *xleg = coefficients_xleg32;
21  const double *wleg = coefficients_wleg32;
22  double x[32];
23  double w[32];
24 
25 
26  const double *xlag = coefficients_xlag32;
27  const double *wlag = coefficients_wlag32;
28 
29  double sum = 0.;
30 
31  for (int i = 0; i < 32; i++) {
32  for (int j = 0; j < 32; j++) {
33  x[j] = (by - ay) / 2.*xleg[j] + (by + ay) / 2.;
34  w[j] = (by - ay) / 2.*wleg[j];
35 
36  sum += wlag[i] * w[j] * func(xlag[i], x[j]);
37  }
38  }
39  return sum;
40  }
41 
42  void GetCoefs2DLaguerre32Legendre32(double ay, double by,
43  std::vector<double> *xlagp, std::vector<double> *wlagp,
44  std::vector<double> *xlegp, std::vector<double> *wlegp) {
45  std::vector<double> &xlag = *xlagp;
46  std::vector<double> &wlag = *wlagp;
47  std::vector<double> &xleg = *xlegp;
48  std::vector<double> &wleg = *wlegp;
49 
50  xlag.resize(32);
51  wlag.resize(32);
52  xleg.resize(32);
53  wleg.resize(32);
54 
55  const double *xlego = coefficients_xleg32;
56  const double *wlego = coefficients_wleg32;
57  const double *xlago = coefficients_xlag32;
58  const double *wlago = coefficients_wlag32;
59 
60  for (int j = 0; j < 32; j++) {
61  xleg[j] = (by - ay) / 2.*xlego[j] + (by + ay) / 2.;
62  wleg[j] = (by - ay) / 2.*wlego[j];
63  xlag[j] = xlago[j];
64  wlag[j] = wlago[j];
65  }
66  }
67 
68  void GetCoefs2DLegendre32Legendre32(double ay, double by, double a2y, double b2y,
69  std::vector<double> *xlegp1, std::vector<double> *wlegp1,
70  std::vector<double> *xlegp2, std::vector<double> *wlegp2) {
71  std::vector<double> &xleg1 = *xlegp1;
72  std::vector<double> &wleg1 = *wlegp1;
73  std::vector<double> &xleg2 = *xlegp2;
74  std::vector<double> &wleg2 = *wlegp2;
75 
76  xleg1.resize(32);
77  wleg1.resize(32);
78  xleg2.resize(32);
79  wleg2.resize(32);
80 
81  const double *xlego = coefficients_xleg32;
82  const double *wlego = coefficients_wleg32;
83 
84  for (int j = 0; j < 32; j++) {
85  xleg1[j] = (by - ay) / 2.*xlego[j] + (by + ay) / 2.;
86  wleg1[j] = (by - ay) / 2.*wlego[j];
87  xleg2[j] = (b2y - a2y) / 2.*xlego[j] + (b2y + a2y) / 2.;
88  wleg2[j] = (b2y - a2y) / 2.*wlego[j];
89  }
90  }
91 
92  void GetCoefsIntegrateLegendre32(double a, double b, std::vector<double> *xp, std::vector<double> *wp)
93  {
94  // Integrate function from a to b using Legendre-Gaussian integration
95  // with 32 points.
96  //
97  std::vector<double> &x = *xp;
98  std::vector<double> &w = *wp;
99 
100  x.resize(32);
101  w.resize(32);
102 
103  const double *xlego = coefficients_xleg32;
104  const double *wlego = coefficients_wleg32;
105 
106 
107  for (int i = 0; i < 32; i++) {
108  w[i] = (b - a) / 2.*wlego[i];
109  x[i] = (b - a) / 2.*xlego[i] + (b + a) / 2.;
110  }
111  }
112 
113  void GetCoefsIntegrateLegendre10(double a, double b, std::vector<double> *xp, std::vector<double> *wp)
114  {
115  // Integrate function from a to b using Legendre-Gaussian integration
116  // with 32 points.
117  //
118  std::vector<double> &x = *xp;
119  std::vector<double> &w = *wp;
120 
121  x.resize(10);
122  w.resize(10);
123 
124  const double *xlego = coefficients_xleg10;
125  const double *wlego = coefficients_wleg10;
126 
127  for (int i = 0; i < 10; i++) {
128  w[i] = (b - a) / 2.*wlego[i];
129  x[i] = (b - a) / 2.*xlego[i] + (b + a) / 2.;
130  }
131  }
132 
133  void GetCoefsIntegrateLegendre5(double a, double b, std::vector<double> *xp, std::vector<double> *wp)
134  {
135  // Integrate function from a to b using Legendre-Gaussian integration
136  // with 32 points.
137  //
138  std::vector<double> &x = *xp;
139  std::vector<double> &w = *wp;
140 
141  x.resize(5);
142  w.resize(5);
143 
144  const double *xlego = coefficients_xleg5;
145  const double *wlego = coefficients_wleg5;
146 
147  for (int i = 0; i < 5; i++) {
148  w[i] = (b - a) / 2.*wlego[i];
149  x[i] = (b - a) / 2.*xlego[i] + (b + a) / 2.;
150  }
151  }
152 
153  void GetCoefsIntegrateLegendre40(double a, double b, std::vector<double> *xp, std::vector<double> *wp)
154  {
155  // Integrate function from a to b using Legendre-Gaussian integration
156  // with 40 points.
157  //
158  std::vector<double> &x = *xp;
159  std::vector<double> &w = *wp;
160 
161  x.resize(40);
162  w.resize(40);
163 
164 
165  const double *xlego = coefficients_xleg40;
166  const double *wlego = coefficients_wleg40;
167 
168  for (int i = 0; i < 40; i++) {
169  w[i] = (b - a) / 2.*wlego[i];
170  x[i] = (b - a) / 2.*xlego[i] + (b + a) / 2.;
171  }
172  }
173 
174  void GetCoefsIntegrateLaguerre32(std::vector<double> *xp, std::vector<double> *wp)
175  {
176  // Integrate function from 0 to infinity using Gauss-Laguerre integration
177  // with 32 points
178  //
179  std::vector<double> &x = *xp;
180  std::vector<double> &w = *wp;
181 
182  x.resize(32);
183  w.resize(32);
184 
185  const double *xlago = coefficients_xlag32;
186  const double *wlago = coefficients_wlag32;
187 
188  for (int i = 0; i < 32; i++) {
189  w[i] = wlago[i];
190  x[i] = xlago[i];
191  }
192  }
193 
194  } // namespace NumericalIntegration
195 
196 } // namespace thermalfist
void GetCoefsIntegrateLegendre5(double a, double b, std::vector< double > *x, std::vector< double > *w)
const double coefficients_wleg10[10]
Weights of the 10-point Gauss-Legendre quadrature.
const double coefficients_wlag32[32]
Weights of the 32-point Gauss-Laguerre quadrature.
const double coefficients_xlag32[32]
Nodes of the 32-point Gauss-Laguerre quadrature.
void GetCoefs2DLaguerre32Legendre32(double ay, double by, std::vector< double > *xlag, std::vector< double > *wlag, std::vector< double > *xleg, std::vector< double > *wleg)
void GetCoefsIntegrateLaguerre32(std::vector< double > *x, std::vector< double > *w)
const double coefficients_wleg40[40]
Weights of the 40-point Gauss-Legendre quadrature.
void GetCoefsIntegrateLegendre40(double a, double b, std::vector< double > *x, std::vector< double > *w)
const double coefficients_wleg32[32]
Weights of the 32-point Gauss-Legendre quadrature.
const double coefficients_xleg10[10]
Nodes of the 10-point Gauss-Legendre quadrature.
void GetCoefsIntegrateLegendre32(double a, double b, std::vector< double > *x, std::vector< double > *w)
const double coefficients_wleg5[5]
Weights of the 5-point Gauss-Legendre quadrature.
const double coefficients_xleg5[5]
Nodes of the 5-point Gauss-Legendre quadrature.
void GetCoefsIntegrateLegendre10(double a, double b, std::vector< double > *x, std::vector< double > *w)
void GetCoefs2DLegendre32Legendre32(double ax, double bx, double ay, double by, std::vector< double > *xleg1, std::vector< double > *wleg1, std::vector< double > *xleg2, std::vector< double > *wleg2)
double Integrate2DLaguerre32Legendre32(double(*func)(double, double), double ay, double by)
const double coefficients_xleg32[32]
Nodes of the 32-point Gauss-Legendre quadrature.
The main namespace where all classes and functions of the Thermal-FIST library reside.
const double coefficients_xleg40[40]
Nodes of the 40-point Gauss-Legendre quadrature.