Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 0 additions & 142 deletions src/dynamics/se/dycore/quadrature_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ module quadrature_mod
public :: jacobi
public :: quad_norm

public :: trapezoid
private :: trapN
public :: simpsons
public :: gaussian_int

private :: gausslobatto_pts
Expand Down Expand Up @@ -782,145 +779,6 @@ function quad_norm(gquad,N) result(gamma)

end function quad_norm

! =======================
! TrapN:
! Numerical recipes
! =======================

subroutine trapN(f,a,b,N,it,s)
INTERFACE
FUNCTION f(x) RESULT(f_x) ! Function to be integrated
use shr_kind_mod, only: r8=>shr_kind_r8
real(kind=r8), INTENT(IN) :: x
real(kind=r8) :: f_x
END FUNCTION f
END INTERFACE

real(kind=r8),intent(in) :: a,b
integer, intent(in) :: N
integer, intent(inout) :: it
real(kind=r8), intent(inout) :: s

real(kind=r8) :: ssum
real(kind=r8) :: del
real(kind=r8) :: rtnm
real(kind=r8) :: x

integer :: j

if (N==1) then
s = 0.5_r8*(b-a)*(f(a) + f(b))
it =1
else
ssum = 0.0_r8
rtnm =1.0_r8/it
del = (b-a)*rtnm
x=a+0.5_r8*del
do j=1,it
ssum = ssum + f(x)
x=x+del
end do
s=0.5_r8*(s + del*ssum)
it=2*it
end if

end subroutine trapN

! ==========================================
! Trapezoid Rule for integrating functions
! from a to b with residual error eps
! ==========================================

function trapezoid(f,a,b,eps) result(Integral)

integer, parameter :: Nmax = 25 ! At most 2^Nmax + 1 points in integral

INTERFACE
FUNCTION f(x) RESULT(f_x) ! Function to be integrated
use shr_kind_mod, only: r8=>shr_kind_r8
real(kind=r8), INTENT(IN) :: x
real(kind=r8) :: f_x
END FUNCTION f
END INTERFACE

real(kind=r8), intent(in) :: a,b ! The integral bounds
real(kind=r8), intent(in) :: eps ! relative error bound for integral
real(kind=r8) :: Integral ! the integral result (within eps)
real(kind=r8) :: s ! Integral approximation
real(kind=r8) :: sold ! previous integral approx

integer :: N
integer :: it

! ==============================================================
! Calculate I here using trapezoid rule using f and a DO loop...
! ==============================================================

s = 1.0e30_r8
sold = 0.0_r8
N=1
it=0
do while(N<=Nmax .and. ABS(s-sold)>eps*ABS(sold))
sold=s
call trapN(f,a,b,N,it,s)
N=N+1
end do

Integral = s

end function trapezoid

! ==========================================
! Simpsons Rule for integrating functions
! from a to b with residual error eps
! ==========================================

function simpsons(f,a,b,eps) result(Integral)

integer, parameter :: Nmax = 25 ! At most 2^Nmax + 1 points in integral

INTERFACE
FUNCTION f(x) RESULT(f_x) ! Function to be integrated
use shr_kind_mod, only: r8=>shr_kind_r8
real(kind=r8), INTENT(IN) :: x
real(kind=r8) :: f_x
END FUNCTION f
END INTERFACE

real(kind=r8), intent(in) :: a,b ! The integral bounds
real(kind=r8), intent(in) :: eps ! relative error bound for integral
real(kind=r8) :: Integral ! the integral result (within eps)
real(kind=r8) :: s ! Integral approximation
real(kind=r8) :: os ! previous integral approx
real(kind=r8) :: st ! Integral approximation
real(kind=r8) :: ost ! previous integral approx

integer :: N
integer :: it

! ==============================================================
! Calculate I here using trapezoid rule using f and a DO loop...
! ==============================================================

ost= 0.0_r8
s = 1.0e30_r8
os = 0.0_r8

N=1
it=0
do while ((N<=Nmax .and. ABS(s-os)>eps*ABS(os) ) .or. N<=2)
os = s
call trapN(f,a,b,N,it,st)
s=(4.0_r8*st-ost)/3.0_r8
ost=st
N=N+1
end do

Integral = s

end function simpsons


! ==========================================
! gaussian_int:
!
Expand Down