You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							39 lines
						
					
					
						
							1.2 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							39 lines
						
					
					
						
							1.2 KiB
						
					
					
				
								#pragma once
							 | 
						|
								
							 | 
						|
								#include "GL_integrator.hpp"
							 | 
						|
								#include "TS_integrator.hpp"
							 | 
						|
								
							 | 
						|
								// Gauss-Legendre quadrature for 1D integral over interval [a, b]
							 | 
						|
								template<typename Func>
							 | 
						|
								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 = a + length * GLIntegrator<double>::x(q, i);
							 | 
						|
								        double w = length * GLIntegrator<double>::w(q, i);
							 | 
						|
								        sum += w * func(x);
							 | 
						|
								    }
							 | 
						|
								    return sum;
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								// Tanh-sinh quadrature for 1D integral over [a, b]
							 | 
						|
								template<typename Func>
							 | 
						|
								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 = a + length * TSIntegrator<double>::x(q, i, a, b);
							 | 
						|
								        double w = length * TSIntegrator<double>::w(q, i, a, b);
							 | 
						|
								        result += w * func(x);
							 | 
						|
								    }
							 | 
						|
								    return result;
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								template<typename Func>
							 | 
						|
								double integrate_1D(double a, double b, Func&& func, int q, bool use_tanh_sinh = false) {
							 | 
						|
								    if (use_tanh_sinh) {
							 | 
						|
								        return tanh_sinh_integrate_1D(a, b, std::forward<Func>(func), q);
							 | 
						|
								    } else {
							 | 
						|
								        return gauss_integrate_1D(a, b, std::forward<Func>(func), q);       
							 | 
						|
								    }
							 | 
						|
								}
							 |