-
Notifications
You must be signed in to change notification settings - Fork 191
legendre polynomials and gaussian quadrature #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
56822b5
- Added preliminary implementation for Legendre polynomials
hsnyder 1a914dd
Update src/stdlib_quadrature_gauss.f90
hsnyder 5937f90
Some changes in accorance with preliminary review comments
hsnyder 124a2c5
merge
hsnyder e0add1a
changed stdlib_functions to stdlib_specialfunctions
hsnyder 29ebe9c
added a comment regarding the initial guess for gauss-legendre quadra…
hsnyder 7f91f1d
changed newton iteration loop indexing (stdlib_quadrature_gauss.f90) …
hsnyder 6a1945f
Merge branch 'master' into master
hsnyder 56b9423
Fix build for GCC 10.2
awvwgk a4cc366
Resolve merge conflicts and fix parallel Makefile build
awvwgk ce62e1f
Merge branch 'fortran-lang:master' into master
hsnyder 551ec6d
added first tests for gaussian quadrature functions
hsnyder 6f06f69
test implementation for gaussian quadrature functions
hsnyder 274f542
added spec for gaussian quadrature functions
hsnyder f6ac41b
Added spec for special functions
hsnyder 4dbd769
Update doc/specs/stdlib_quadrature.md
hsnyder 259482a
Update doc/specs/stdlib_quadrature.md
hsnyder 7225987
Update doc/specs/stdlib_specialfunctions.md
hsnyder 6647e9b
Update doc/specs/stdlib_specialfunctions.md
hsnyder f3d43b3
made spec examples (guassian quadrature) standalone programs
hsnyder 6f9d7e4
Update doc/specs/stdlib_quadrature.md
hsnyder 5c53579
Update doc/specs/stdlib_quadrature.md
hsnyder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
title: specialfunctions | ||
--- | ||
|
||
# Special functions | ||
|
||
[TOC] | ||
|
||
## `legendre` - Calculate Legendre polynomials | ||
|
||
### Status | ||
|
||
Experimental | ||
|
||
### Description | ||
|
||
Computes the value of the n-th Legendre polynomial at a specified point. | ||
Currently only 64 bit floating point is supported. | ||
|
||
This is an `elemental` function. | ||
|
||
### Syntax | ||
|
||
`result = [[stdlib_specialfunctions(module):legendre(interface)]] (n, x)` | ||
|
||
### Arguments | ||
|
||
`n`: Shall be a scalar of type `real(real64)`. | ||
|
||
`x`: Shall be a scalar or array (this function is elemental) of type `real(real64)`. | ||
|
||
### Return value | ||
|
||
The function result will be the value of the `n`-th Legendre polynomial, evaluated at `x`. | ||
|
||
|
||
|
||
## `dlegendre` - Calculate first derivatives of Legendre polynomials | ||
|
||
### Status | ||
|
||
Experimental | ||
|
||
### Description | ||
|
||
Computes the value of the first derivative of the n-th Legendre polynomial at a specified point. | ||
Currently only 64 bit floating point is supported. | ||
|
||
This is an `elemental` function. | ||
|
||
### Syntax | ||
|
||
`result = [[stdlib_specialfunctions(module):dlegendre(interface)]] (n, x)` | ||
|
||
### Arguments | ||
|
||
`n`: Shall be a scalar of type `real(real64)`. | ||
|
||
`x`: Shall be a scalar or array (this function is elemental) of type `real(real64)`. | ||
|
||
### Return value | ||
|
||
The function result will be the value of the first derivative of the `n`-th Legendre polynomial, evaluated at `x`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
submodule (stdlib_quadrature) stdlib_quadrature_gauss | ||
use stdlib_specialfunctions, only: legendre, dlegendre | ||
implicit none | ||
|
||
real(dp), parameter :: pi = acos(-1._dp) | ||
real(dp), parameter :: tolerance = 4._dp * epsilon(1._dp) | ||
integer, parameter :: newton_iters = 100 | ||
|
||
contains | ||
|
||
pure module subroutine gauss_legendre_fp64 (x, w, interval) | ||
real(dp), intent(out) :: x(:), w(:) | ||
real(dp), intent(in), optional :: interval(2) | ||
|
||
associate (n => size(x)-1 ) | ||
select case (n) | ||
case (0) | ||
x = 0 | ||
w = 2 | ||
case (1) | ||
x(1) = -sqrt(1._dp/3._dp) | ||
x(2) = -x(1) | ||
w = 1 | ||
case default | ||
block | ||
integer :: i,j | ||
real(dp) :: leg, dleg, delta | ||
|
||
do i = 0, (n+1)/2 - 1 | ||
! use Gauss-Chebyshev points as an initial guess | ||
x(i+1) = -cos((2*i+1)/(2._dp*n+2._dp) * pi) | ||
do j = 1, newton_iters | ||
leg = legendre(n+1,x(i+1)) | ||
dleg = dlegendre(n+1,x(i+1)) | ||
delta = -leg/dleg | ||
x(i+1) = x(i+1) + delta | ||
if ( abs(delta) <= tolerance * abs(x(i+1)) ) exit | ||
end do | ||
x(n-i+1) = -x(i+1) | ||
|
||
dleg = dlegendre(n+1,x(i+1)) | ||
w(i+1) = 2._dp/((1-x(i+1)**2)*dleg**2) | ||
w(n-i+1) = w(i+1) | ||
end do | ||
|
||
if (mod(n,2) == 0) then | ||
x(n/2+1) = 0 | ||
|
||
dleg = dlegendre(n+1, 0.0_dp) | ||
w(n/2+1) = 2._dp/(dleg**2) | ||
end if | ||
end block | ||
end select | ||
end associate | ||
|
||
if (present(interval)) then | ||
associate ( a => interval(1) , b => interval(2) ) | ||
x = 0.5_dp*(b-a)*x+0.5_dp*(b+a) | ||
x(1) = interval(1) | ||
x(size(x)) = interval(2) | ||
w = 0.5_dp*(b-a)*w | ||
end associate | ||
end if | ||
end subroutine | ||
|
||
pure module subroutine gauss_legendre_lobatto_fp64 (x, w, interval) | ||
real(dp), intent(out) :: x(:), w(:) | ||
real(dp), intent(in), optional :: interval(2) | ||
|
||
associate (n => size(x)-1) | ||
select case (n) | ||
case (1) | ||
x(1) = -1 | ||
x(2) = 1 | ||
w = 1 | ||
case default | ||
block | ||
integer :: i,j | ||
real(dp) :: leg, dleg, delta | ||
|
||
x(1) = -1._dp | ||
x(n+1) = 1._dp | ||
w(1) = 2._dp/(n*(n+1._dp)) | ||
awvwgk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
w(n+1) = 2._dp/(n*(n+1._dp)) | ||
awvwgk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
do i = 1, (n+1)/2 - 1 | ||
! initial guess from an approximate form given by SV Parter (1999) | ||
x(i+1) = -cos( (i+0.25_dp)*pi/n - 3/(8*n*pi*(i+0.25_dp))) | ||
awvwgk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
do j = 1, newton_iters | ||
leg = legendre(n+1,x(i+1)) - legendre(n-1,x(i+1)) | ||
dleg = dlegendre(n+1,x(i+1)) - dlegendre(n-1,x(i+1)) | ||
delta = -leg/dleg | ||
x(i+1) = x(i+1) + delta | ||
if ( abs(delta) <= tolerance * abs(x(i+1)) ) exit | ||
end do | ||
x(n-i+1) = -x(i+1) | ||
|
||
leg = legendre(n, x(i+1)) | ||
w(i+1) = 2._dp/(n*(n+1._dp)*leg**2) | ||
awvwgk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
w(n-i+1) = w(i+1) | ||
end do | ||
|
||
if (mod(n,2) == 0) then | ||
x(n/2+1) = 0 | ||
|
||
leg = legendre(n, 0.0_dp) | ||
w(n/2+1) = 2._dp/(n*(n+1._dp)*leg**2) | ||
awvwgk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end if | ||
end block | ||
end select | ||
end associate | ||
|
||
if (present(interval)) then | ||
associate ( a => interval(1) , b => interval(2) ) | ||
x = 0.5_dp*(b-a)*x+0.5_dp*(b+a) | ||
x(1) = interval(1) | ||
x(size(x)) = interval(2) | ||
w = 0.5_dp*(b-a)*w | ||
end associate | ||
end if | ||
end subroutine | ||
end submodule |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.