gjp_common.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
29 module gjp_common
30 use gjp_types, only: dp, gjp_sparse_matrix
31 implicit none
32 
33 contains
49 function jacobi_matrix(n, alpha, beta) result(jacmat)
50  integer, intent(in) :: n ! Size of the matrix, number of points
51  real(dp), intent(in) :: alpha, beta
52  type(gjp_sparse_matrix) :: jacmat
53  integer :: idx
54  real(dp) :: ab, abi, a2b2
55 
56  allocate (jacmat%diagonal(n))
57  allocate (jacmat%off_diagonal(n - 1))
58 
59  ab = alpha + beta
60  abi = 2.0_dp + ab
61  jacmat%diagonal(1) = (beta - alpha) / abi
62  jacmat%off_diagonal(1) = 4.0_dp * (1.0_dp + alpha) * (1.0_dp + beta) &
63  / ((abi + 1.0_dp) * abi * abi)
64  a2b2 = beta * beta - alpha * alpha
65  do idx = 2, n
66  abi = 2.0_dp * idx + ab
67  jacmat%diagonal(idx) = a2b2 / ((abi - 2.0_dp) * abi)
68  abi = abi**2
69  if (idx < n) then
70  jacmat%off_diagonal(idx) = 4.0_dp * idx * (idx + alpha) * (idx + beta) &
71  * (idx + ab) / ((abi - 1.0_dp) * abi)
72  end if
73  end do
74  jacmat%off_diagonal(1:n - 1) = sqrt(jacmat%off_diagonal(1:n - 1))
75 end function jacobi_matrix
76 
89 function jacobi_zeroeth_moment(alpha, beta) result(zmom)
90  real(dp), intent(in) :: alpha, beta
91  real(dp) :: zmom
92  real(dp) :: ab, abi
93 
94  ab = alpha + beta
95  abi = 2.0_dp + ab
96 
97  zmom = 2.0_dp**(alpha + beta + 1.0_dp) * exp(log_gamma(alpha + 1.0_dp) &
98  + log_gamma(beta + 1.0_dp) - log_gamma(abi))
99 
100  if (zmom <= 0.0_dp) then
101  error stop "Zeroth moment is not positive but should be"
102  end if
103 end function jacobi_zeroeth_moment
104 
105 end module gjp_common
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 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