From 07fe15f8630700656cbaaca63fc54c0cdc1442d4 Mon Sep 17 00:00:00 2001 From: mckay Date: Sun, 5 Oct 2025 20:47:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(quadrature):=20optimize=20Gauss-Legendre=20?= =?UTF-8?q?and=20tanh-sinh=20integration=20calculations=EF=BC=8Csupport=20?= =?UTF-8?q?integral=20over=20[a,=20b]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- surface_integral/include/quadrature.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/surface_integral/include/quadrature.hpp b/surface_integral/include/quadrature.hpp index 243f815..ba69ae6 100644 --- a/surface_integral/include/quadrature.hpp +++ b/surface_integral/include/quadrature.hpp @@ -3,25 +3,27 @@ #include "GL_integrator.hpp" #include "TS_integrator.hpp" -// 高斯-勒让德一维积分:积分区间 [a, b] +// Gauss-Legendre quadrature for 1D integral over interval [a, b] template double gauss_integrate_1D(double a, double b, Func&& func, int q) { double sum = 0.0; + double length = b - a; for (int i = 0; i < q; ++i) { - double x = GLIntegrator::x(q, i, a, b); - double w = GLIntegrator::w(q, i, a, b); + double x = a + length * GLIntegrator::x(q, i); + double w = length * GLIntegrator::w(q, i); sum += w * func(x); } return sum; } -// tanh-sinh 一维积分:积分区间 [a, b] +// Tanh-sinh quadrature for 1D integral over [a, b] template double tanh_sinh_integrate_1D(double a, double b, Func&& func, int q) { double result = 0.0; + double length = b - a; for (int i = 0; i < q; ++i) { - double x = TSIntegrator::x(q, i, a, b); - double w = TSIntegrator::w(q, i, a, b); + double x = a + length * TSIntegrator::x(q, i, a, b); + double w = length * TSIntegrator::w(q, i, a, b); result += w * func(x); } return result;