gjp_gw.f90
Go to the documentation of this file.
1 ! BEGIN_HEADER
2 ! -----------------------------------------------------------------------------
3 ! Gauss-Jacobi Quadrature Implementation
4 ! Authors: Rohit Goswami <rgoswami[at]ieee.org>
5 ! Source: GaussJacobiQuad Library
6 ! License: MIT
7 ! GitHub Repository: https://github.com/HaoZeke/GaussJacobiQuad
8 ! Date: 2023-08-28
9 ! Commit: c442f77
10 ! -----------------------------------------------------------------------------
11 ! This code is part of the GaussJacobiQuad library, providing an efficient
12 ! implementation for Gauss-Jacobi quadrature nodes and weights computation.
13 ! -----------------------------------------------------------------------------
14 ! To cite this software:
15 ! Rohit Goswami (2023). HaoZeke/GaussJacobiQuad: v0.1.0.
16 ! Zenodo: https://doi.org/10.5281/ZENODO.8285112
17 ! ---------------------------------------------------------------------
18 ! END_HEADER
28 module gjp_gw
29 use gjp_types, only: dp, gjp_sparse_matrix
30 use gjp_lapack, only: dsteqr
32 implicit none
33 contains
34 
59 subroutine gauss_jacobi_gw(npts, alpha, beta, x, wts)
60  integer, intent(in) :: npts
61  real(dp), intent(in) :: alpha, beta
62  real(dp), intent(out) :: x(npts), wts(npts)
63  real(dp) :: zeroeth_moment
64  type(gjp_sparse_matrix) :: jacobi_mat
65  real(dp) :: diagonal_elements(npts), &
66  off_diagonal_elements(npts - 1), &
67  eigenvectors(npts, npts), &
68  workspace(2 * npts - 2)
69  integer :: computation_info, i
70 
71  jacobi_mat = jacobi_matrix(npts, alpha, beta)
72  zeroeth_moment = jacobi_zeroeth_moment(alpha, beta)
73 
74  ! Extract diagonal and off-diagonal elements
75  diagonal_elements = jacobi_mat%diagonal(1:npts)
76  off_diagonal_elements = jacobi_mat%off_diagonal(1:npts - 1)
77 
78  ! Initialize eigenvectors as identity matrix
79  eigenvectors = 0.0_dp
80  do i = 1, npts
81  eigenvectors(i, i) = 1.0_dp
82  end do
83 
84  ! Diagonalize the Jacobi matrix using DSTEQR.
85  call dsteqr('V', npts, diagonal_elements, off_diagonal_elements, &
86  eigenvectors, npts, workspace, computation_info)
87 
88  if (computation_info /= 0) then
89  write (*, *) 'Error in DSTEQR, info:', computation_info
90  error stop
91  end if
92 
93  ! The eigenvalues are the nodes
94  x = diagonal_elements
95  ! The weights are related to the squares of the first components of the
96  ! eigenvectors
97  wts = eigenvectors(1, :)**2 * zeroeth_moment
98 
99 end subroutine gauss_jacobi_gw
100 
101 end module gjp_gw
This module provides utility functions for computing Jacobi matrices and zeroth moments.
Definition: gjp_common.f90:29
type(gjp_sparse_matrix) function jacobi_matrix(n, alpha, beta)
Computes the Jacobi matrix for given parameters.
Definition: gjp_common.f90:50
real(dp) function jacobi_zeroeth_moment(alpha, beta)
Computes the zeroth moment for Jacobi polynomials.
Definition: gjp_common.f90:90
Module for computing Gauss-Jacobi quadrature nodes and weights using the Golub-Welsch (GW) method.
Definition: gjp_gw.f90:28
subroutine gauss_jacobi_gw(npts, alpha, beta, x, wts)
Computes the zeros and weights for Gauss-Jacobi quadrature.
Definition: gjp_gw.f90:60
LAPACK Interface for Gauss Jacobi Polynomials.
Definition: gjp_lapack.f90:21
Module for defining types and precision levels for Gauss-Jacobi Polynomial (GJP) calculations.
Definition: gjp_types.f90:33
integer, parameter, public dp
Define various kinds for real numbers.
Definition: gjp_types.f90:39
Sparse representation of a Jacobi matrix.
Definition: gjp_types.f90:49