|
|
@ -3,25 +3,27 @@ |
|
|
#include "GL_integrator.hpp" |
|
|
#include "GL_integrator.hpp" |
|
|
#include "TS_integrator.hpp" |
|
|
#include "TS_integrator.hpp" |
|
|
|
|
|
|
|
|
// 高斯-勒让德一维积分:积分区间 [a, b]
|
|
|
// Gauss-Legendre quadrature for 1D integral over interval [a, b]
|
|
|
template<typename Func> |
|
|
template<typename Func> |
|
|
double gauss_integrate_1D(double a, double b, Func&& func, int q) { |
|
|
double gauss_integrate_1D(double a, double b, Func&& func, int q) { |
|
|
double sum = 0.0; |
|
|
double sum = 0.0; |
|
|
|
|
|
double length = b - a; |
|
|
for (int i = 0; i < q; ++i) { |
|
|
for (int i = 0; i < q; ++i) { |
|
|
double x = GLIntegrator<double>::x(q, i, a, b); |
|
|
double x = a + length * GLIntegrator<double>::x(q, i); |
|
|
double w = GLIntegrator<double>::w(q, i, a, b); |
|
|
double w = length * GLIntegrator<double>::w(q, i); |
|
|
sum += w * func(x); |
|
|
sum += w * func(x); |
|
|
} |
|
|
} |
|
|
return sum; |
|
|
return sum; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// tanh-sinh 一维积分:积分区间 [a, b]
|
|
|
// Tanh-sinh quadrature for 1D integral over [a, b]
|
|
|
template<typename Func> |
|
|
template<typename Func> |
|
|
double tanh_sinh_integrate_1D(double a, double b, Func&& func, int q) { |
|
|
double tanh_sinh_integrate_1D(double a, double b, Func&& func, int q) { |
|
|
double result = 0.0; |
|
|
double result = 0.0; |
|
|
|
|
|
double length = b - a; |
|
|
for (int i = 0; i < q; ++i) { |
|
|
for (int i = 0; i < q; ++i) { |
|
|
double x = TSIntegrator<double>::x(q, i, a, b); |
|
|
double x = a + length * TSIntegrator<double>::x(q, i, a, b); |
|
|
double w = TSIntegrator<double>::w(q, i, a, b); |
|
|
double w = length * TSIntegrator<double>::w(q, i, a, b); |
|
|
result += w * func(x); |
|
|
result += w * func(x); |
|
|
} |
|
|
} |
|
|
return result; |
|
|
return result; |
|
|
|