Included integration over v distribution of thermal population

Included integration over v distribution of thermal population
This commit is contained in:
Christian
2019-11-20 11:06:53 +01:00
parent 978b641315
commit 90a68dc47c
19 changed files with 194 additions and 69 deletions
+49
View File
@@ -65,5 +65,54 @@ public:
}
};
template<typename F, typename Double>
double double_simpson_integrate(F f, Double xmin, Double xmax, Double ymin, Double ymax, int nx, int ny) {
// Adapted from https://www.geeksforgeeks.org/program-to-calculate-double-integration/
// and http://www.physics.usyd.edu.au/teach_res/mp/doc/math_integration_2D.pdf
// and http://mathfaculty.fullerton.edu/mathews/n2003/SimpsonsRule2DMod.html
// Make number of steps even
if (nx % 2 != 0) {
nx += 1;
}
if (ny % 2 != 0) {
ny += 1;
}
// Calculating the step sizes
Double xsteps = (xmax - xmin)/(nx-1);
Double ysteps = (ymax - ymin)/(ny-1);
// Lambda for calculating function value in respect to x and y bins
auto f_bin = [&](int ix, int iy) {
return f(xmin + ix * xsteps, ymin + iy * ysteps);
};
// Lambda for calculating the integral over y for a ix bin
auto x_integral = [&](int ix) {
Double res = 0;
for (int iy = 0; iy < ny; iy++) {
if (iy == 0 || iy == ny - 1)
res += f_bin(ix, iy);
else if (iy % 2 == 0)
res += 2 * f_bin(ix, iy);
else
res += 4 * f_bin(ix, iy);
}
res *= (ysteps / 3);
return res;
};
// Calculating the final integral value over x
Double res = 0;
for (int ix = 0; ix < nx; ix++) {
if (ix == 0 || ix == nx - 1)
res += x_integral(ix);
else if (ix % 2 == 0)
res += 2 * x_integral(ix);
else
res += 4 * x_integral(ix);
}
res *= (xsteps / 3);
return res;
}
#endif /* integrater_h */