25 use,
intrinsic :: iso_fortran_env
128 real(real64),
intent(in) :: x, y
129 real(real64),
optional,
intent(in) :: rtol
130 real(real64),
optional,
intent(in) :: atol
131 real(real64) :: atol_, rtol_
141 complex(real64),
intent(in) :: x, y
142 real(real64),
optional,
intent(in) :: rtol
143 real(real64),
optional,
intent(in) :: atol
144 real(real64) :: atol_, rtol_
157 integer,
intent(in) :: dim
158 integer,
intent(in) :: diag
159 integer :: matrix(dim, dim)
165 matrix(ii, ii) = diag
171 recursive function hermite(n, x)
result (h)
172 integer,
intent(in) :: n
173 real(real64),
intent(in) :: x
191 recursive function factorial (n)
RESULT (fac)
192 integer,
intent(in) :: n
208 real(real64),
intent(in) :: xx(3)
209 integer,
intent(in) :: li, mi
210 complex(real64),
intent(out) :: ylm
213 real(real64) :: dx, dy, dz, r, plm, cosm, sinm, cosmm1, sinmm1, cosphi, sinphi
214 real(real64),
parameter :: tiny = 1.e-15_real64
224 r =
sqrt(xx(1)**2 + xx(2)**2 + xx(3)**2)
241 r =
sqrt(dx*dx + dy*dy)
255 cosm = cosmm1*cosphi - sinmm1*sinphi
256 sinm = cosmm1*sinphi + sinmm1*cosphi
260 ylm = plm*cmplx(cosm, sinm, real64)
279 real(real64),
intent(in) :: xx(3)
280 integer,
intent(in) :: li, mi
281 real(real64),
intent(out) :: ylm
283 integer,
parameter :: lmaxd = 20
284 real(real64),
parameter :: tiny = 1.e-15_real64
285 integer :: i, ilm0, l, m, mabs
286 integer,
save :: lmax = -1
288 real(real64) :: cmi, cosm, cosmm1, cosphi, dphase, dplg, fac, &
289 fourpi, plgndr, phase, pll, pmm, pmmp1, sinm, &
290 sinmm1, sinphi, rsize, rx, ry, rz, xysize
291 real(real64),
save :: c(0:(lmaxd+1)*(lmaxd+1))
302 do i = l - m + 1, l + m
305 c(ilm0 + m) =
sqrt(fac)
307 if (m /= 0) c(ilm0 + m) = c(ilm0 + m)*
sqrt(
m_two)
308 c(ilm0 - m) = c(ilm0 + m)
321 rsize =
sqrt(xx(1)**2 + xx(2)**2 + xx(3)**2)
322 if (rsize < tiny)
then
347 ylm = c(4)*6.0_real64*rx*ry
355 ylm = c(8)*
m_three*(rx*rx - ry*ry)
362 xysize =
sqrt(max(rx*rx + ry*ry, tiny))
370 cosm = cosmm1*cosphi - sinmm1*sinphi
371 sinm = cosmm1*sinphi + sinmm1*cosphi
379 dphase = (-mabs)*sinm
387 pmm = (-pmm)*fac*xysize
394 dplg = (-li)*rz*pmm/(xysize**2)
396 pmmp1 = rz*(2*mabs + 1)*pmm
397 if (li == mabs + 1)
then
399 dplg = -((li*rz*pmmp1 - (mabs + li)*pmm)/(xysize**2))
402 pll = (rz*(2*l - 1)*pmmp1 - (l + mabs - 1)*pmm)/(l - mabs)
407 dplg = -((li*rz*pll - (l + mabs - 1)*pmm)/(xysize**2))
413 ylm = cmi*plgndr*phase
428 subroutine weights(N, M, cc, side)
429 integer,
intent(in) :: n, m
430 real(real64),
intent(out) :: cc(0:,0:,0:)
431 integer,
optional,
intent(in) :: side
433 integer :: i, j, k, mn, side_
434 real(real64) :: c1, c2, c3, c4, c5, xi
435 real(real64),
allocatable :: x(:)
439 safe_allocate(x(0:m))
441 if (
present(side))
then
451 x(:) = (/(-i,i=0,mn)/)
455 x(:) = (/(i,i=0,mn)/)
459 x(:) = (/0,(-i,i,i=1,mn)/)
482 if (j <= n) cc(k, j - 1, j) =
m_zero
483 cc(k, j, 0) = c4*cc(k, j - 1, 0)/c3
486 cc(k, j, i) = (c4*cc(k, j - 1, i) - i*cc(k, j - 1, i - 1))/c3
489 cc(j, j, 0) = -c1*c5*cc(j - 1, j - 1, 0) / c2
493 cc(j, j, i) = c1*(i*cc(j - 1, j - 1, i - 1) - c5*cc(j - 1, j - 1, i))/c2
504 real(real64)
pure function
ddelta(i, j)
505 integer,
intent(in) :: i
506 integer,
intent(in) :: j
523 integer,
intent(in) :: n
524 integer,
allocatable,
intent(out) :: out(:)
525 integer,
intent(out) :: length
526 integer,
optional,
intent(in) :: in(:)
532 if (
present(in))
then
533 length = ubound(in, 1)
534 safe_allocate(out(1:length))
538 safe_allocate(out(1:length))
551 logical function member(n, a)
552 integer,
intent(in) :: n
553 integer,
intent(in) :: a(:)
561 do i = 1, ubound(a, 1)
573 integer,
intent(in) :: nn
574 real(real64),
intent(in) :: xa(:)
575 real(real64),
intent(in) :: xx
576 real(real64),
intent(out) :: cc(:)
586 cc(ii) = cc(ii)*(xx - xa(kk))/(xa(ii) - xa(kk))
595 logical pure function
even(n)
596 integer,
intent(in) :: n
598 even = (mod(n, 2) == 0)
605 logical pure function
odd(n)
606 integer,
intent(in) :: n
616 real(real64),
intent(in) :: x(:)
617 real(real64),
intent(out) :: u(:)
620 real(real64) :: sumx2
621 real(real64),
allocatable :: xx(:)
627 assert(
size(u) == n-1)
630 safe_allocate(xx(1:n))
632 if (abs(x(j))<1.0e-8_real64)
then
643 sumx2 = sumx2 + xx(j)**2
645 if (abs(sumx2) <= m_epsilon .and. abs(xx(k)) <= m_epsilon)
exit
649 u(n-1) =
atan2(xx(n), xx(n-1))
663 real(real64),
intent(in) :: u(:)
664 real(real64),
intent(out) :: x(:)
672 assert(
size(u) == n-1)
679 x(2) =
sin(u(1))*
cos(u(2))
680 x(3) =
sin(u(1))*
sin(u(2))
683 x(2) =
sin(u(1))*
cos(u(2))
690 x(j) = x(j) *
cos(u(j))
694 x(n) = x(n) *
sin(u(k))
696 x(n) = x(n) *
sin(u(n-1))
709 real(real64),
intent(out) :: grad_matrix(:,:)
710 real(real64),
intent(in) :: r
711 real(real64),
intent(in) :: x(:)
721 grad_matrix(1,1) = -r*
sin(x(1))
723 grad_matrix(m,1) = m_zero
730 grad_matrix(m,l) = -r*grad_matrix(m,l)*product(
sin(x(1:l)))
732 grad_matrix(m,l) = grad_matrix(m,l)*r*
cos(x(m))*
cos(x(l))*product(
sin(x(1:m-1)))*product(
sin(x(m+1:l-1)))
734 grad_matrix(m,l) = m_zero
741 grad_matrix(m,n) = r*
cos(x(m))*grad_matrix(m,n)*product(
sin(x(1:m-1)))*product(
sin(x(m+1:n-1)))
748 integer(int64) pure function
pad88(size, blk)
749 integer(int64),
intent(in) :: size
750 integer(int64),
intent(in) :: blk
758 pad88 =
size + blk - mm
763 integer(int64) pure function
pad48(size, blk)
764 integer,
intent(in) :: size
765 integer(int64),
intent(in) :: blk
771 integer(int64) pure function
pad8(size, blk)
772 integer(int64),
intent(in) :: size
773 integer,
intent(in) :: blk
779 integer pure function
pad4(size, blk)
780 integer,
intent(in) :: size
781 integer,
intent(in) :: blk
783 pad4 = int(
pad88(int(
size, int64), int(blk, int64)), int32)
792 integer pure function
pad_pow2(size)
793 integer,
intent(in) :: size
801 if (
size == 0)
return
807 if (mm - 2*mm2 /= 0)
exit
821 real(real64)
pure function
dlog2(xx)
822 real(real64),
intent(in) :: xx
829 integer pure function
ilog2(xx)
830 integer,
intent(in) :: xx
837 integer(int64) pure function
llog2(xx)
838 integer(int64),
intent(in) :: xx
840 llog2 = nint(
log2(real(xx, real64) ), kind=int64)
846 complex(real64),
intent(in) :: z
857 complex(real64) pure function
phi1(z)
858 complex(real64),
intent(in) :: z
860 real(real64),
parameter :: cut = 0.002_real64
862 if (abs(z) < cut)
then
863 phi1 = m_one + m_half*z*(m_one + z/m_three*(m_one + m_fourth*z*(m_one + z/m_five)))
876 complex(real64) pure function
phi2(z)
877 complex(real64),
intent(in) :: z
879 real(real64),
parameter :: cut = 0.002_real64
881 if (abs(z) < cut)
then
882 phi2 = m_half + z/6.0_real64*(m_one + m_fourth*z*(m_one + z/m_five*(m_one + z/6.0_real64)))
884 phi2 = (
exp(z) - z - m_z1)/z**2
891 real(real64),
intent(in) :: x
899 integer,
intent(in) :: n
906 message(1) =
"Internal error: is_prime does not take negative numbers."
907 call messages_fatal(1)
915 root = nint(
sqrt(real(n, real64) ))
917 if (mod(n,i) == 0)
then
934 real(real64),
intent(out) :: r(:,:)
935 real(real64),
intent(in) :: ff(:)
936 real(real64),
intent(in) :: tt(:)
939 real(real64) :: th, uv, uu, vv, ft
940 real(real64),
allocatable :: axis(:), u(:), v(:), f(:), t(:), p(:)
946 assert((dim < 3) .or. (dim > 2))
947 assert(
size(tt,1) == dim)
948 assert((
size(r,1) == dim) .and. (
size(r,2) == dim))
950 safe_allocate(u(1:dim))
951 safe_allocate(v(1:dim))
952 safe_allocate(f(1:dim))
953 safe_allocate(t(1:dim))
960 ft = dot_product(f,t)
962 if (abs(ft) < m_one)
then
975 safe_allocate(axis(1:dim))
978 u = f / dot_product(f,f)
979 v = t /dot_product(t,t)
982 axis = axis / norm2(axis)
984 r(1,1) =
cos(th) + axis(1)**2 * (1 -
cos(th))
985 r(1,2) = axis(1)*axis(2)*(1-
cos(th)) + axis(3)*
sin(th)
986 r(1,3) = axis(1)*axis(3)*(1-
cos(th)) - axis(2)*
sin(th)
988 r(2,1) = axis(2)*axis(1)*(1-
cos(th)) - axis(3)*
sin(th)
989 r(2,2) =
cos(th) + axis(2)**2 * (1 -
cos(th))
990 r(2,3) = axis(2)*axis(3)*(1-
cos(th)) + axis(1)*
sin(th)
992 r(3,1) = axis(3)*axis(1)*(1-
cos(th)) + axis(2)*
sin(th)
993 r(3,2) = axis(3)*axis(2)*(1-
cos(th)) - axis(1)*
sin(th)
994 r(3,3) =
cos(th) + axis(3)**2 * (1 -
cos(th))
996 safe_deallocate_a(axis)
1005 r(1,1) = u(1)**2 + (1-u(1)**2)*
cos(th)
1006 r(1,2) = u(1)*u(2)*(1-
cos(th)) - u(3)*
sin(th)
1007 r(1,3) = u(1)*u(3) + u(2)*
sin(th)
1009 r(2,1) = u(1)*u(2)*(1-
cos(th)) + u(3)*
sin(th)
1010 r(2,2) = u(2)**2 + (1-u(2)**2)*
cos(th)
1011 r(2,3) = u(2)*u(3)*(1-
cos(th)) - u(1)*
sin(th)
1013 r(3,1) = u(1)*u(3)*(1-
cos(th)) - u(2)*
sin(th)
1014 r(3,2) = u(2)*u(3)*(1-
cos(th)) + u(1)*
sin(th)
1015 r(3,3) = u(3)**2 + (1-u(3)**2)*
cos(th)
1020 safe_allocate(p(1:dim))
1022 if (abs(f(1)) <= abs(f(2)) .and. abs(f(1)) < abs(f(3)))
then
1023 p = (/m_one, m_zero, m_zero/)
1024 else if (abs(f(2)) < abs(f(1)) .and. abs(f(2)) <= abs(f(3)))
then
1025 p = (/m_zero, m_one, m_zero/)
1026 else if (abs(f(3)) <= abs(f(1)) .and. abs(f(3)) < abs(f(2)))
then
1027 p = (/m_zero, m_zero, m_one/)
1033 uu = dot_product(u,u)
1034 vv = dot_product(v,v)
1035 uv = dot_product(u,v)
1040 r(i,j) =
ddelta(i,j) - m_two * u(i)*u(j)/uu - m_two * v(i)*v(j)/vv &
1041 + 4_real64*uv * v(i)*u(j) /(uu*vv)
1046 safe_deallocate_a(p)
1062 safe_deallocate_a(u)
1063 safe_deallocate_a(v)
1079 real(real64),
intent(in) :: x, h
1080 real(real64),
intent(out) :: res, err
1083 use,
intrinsic :: iso_fortran_env
1085 real(real64),
intent(in) :: x
1086 real(real64),
intent(inout) :: fx
1090 real(real64) :: con = 1.4_real64, big = 1.0e30_real64, safe = m_two
1091 integer :: ntab = 20, i, j
1092 real(real64) :: errt, fac, hh, fx1, fx2
1093 real(real64),
allocatable :: a(:, :)
1097 if (abs(h) <= m_epsilon)
then
1098 message(1) =
"h must be nonzero in numder_ridders"
1099 call messages_fatal(1)
1102 safe_allocate(a(1:ntab, 1:ntab))
1107 a(1,1) = (fx1-fx2) / (m_two*hh)
1113 a(1,i) = (fx1-fx2) / (m_two*hh)
1116 a(j,i) = (a(j-1,i)*fac-a(j-1,i-1)) / (fac-m_one)
1118 errt = max(abs(a(j,i)-a(j-1,i)),abs(a(j,i)-a(j-1,i-1)))
1119 if (errt .le. err)
then
1124 if (abs(a(i,i)-a(i-1,i-1)) .ge. safe*err)
return
1127 safe_deallocate_a(a)
1133 real(real64),
intent(in) :: a(:)
1134 complex(real64),
intent(in) :: b(:)
1136 complex(real64) :: c(1:3)
1138 c(1) = a(2)*b(3) - a(3)*b(2)
1139 c(2) = a(3)*b(1) - a(1)*b(3)
1140 c(3) = a(1)*b(2) - a(2)*b(1)
1146 complex(real64),
intent(in) :: a(:)
1147 real(real64),
intent(in) :: b(:)
1149 complex(real64) :: c(1:3)
1151 c(1) = a(2)*b(3) - a(3)*b(2)
1152 c(2) = a(3)*b(1) - a(1)*b(3)
1153 c(3) = a(1)*b(2) - a(2)*b(1)
1259 integer,
intent(in) :: np
1260 integer,
intent(in) :: nn, mm
1261 real(real64),
intent(in) :: xx(np)
1262 real(real64),
intent(out) :: cx(np)
1265 real(real64),
allocatable :: cx_tmp(:,:)
1269 safe_allocate(cx_tmp(1:np, 0:nn))
1281 cx_tmp(1:np,0) = m_one
1282 cx_tmp(1:np,1) = real(mm + 1, real64) - xx(1:np)
1285 cx_tmp(1:np, ii) = &
1286 (( real(mm + 2*ii - 1, real64) - xx(1:np)) * cx_tmp(1:np,ii-1) &
1287 + real(-mm -ii + 1, real64) * cx_tmp(1:np,ii-2)) / real(ii, real64)
1290 cx(1:np) = cx_tmp(1:np, nn)
1292 safe_deallocate_a(cx_tmp)
1297 integer,
intent(in) :: nn
1298 real(real64),
intent(inout) :: aa(:, :)
1304 aa(jj, ii) = aa(ii, jj)
1310 integer,
intent(in) :: nn
1311 complex(real64),
intent(inout) :: aa(:, :)
1317 aa(jj, ii) = conjg(aa(ii, jj))
1319 aa(jj, jj) = real(aa(jj, jj), real64)
1324 integer,
intent(in) :: nn
1325 real(real64),
intent(inout) :: aa(:, :)
1331 aa(ii, jj) = aa(jj, ii)
1337 integer,
intent(in) :: nn
1338 complex(real64),
intent(inout) :: aa(:, :)
1344 aa(ii, jj) = conjg(aa(jj, ii))
1346 aa(jj, jj) = real(aa(jj, jj), real64)
1352 integer,
intent(in) :: nn
1353 real(real64),
intent(inout) :: aa(:, :)
1359 aa(ii, jj) = m_half * (aa(ii, jj) + aa(jj, ii))
1360 aa(jj, ii) = aa(ii, jj)
1366 integer,
intent(in) :: nn
1367 real(real64),
intent(inout) :: aa(:, :)
1376#include "complex.F90"
1377#include "math_inc.F90"
1381#include "math_inc.F90"
This is the common interface to a simple-minded polynomical interpolation procedure (simple use of th...
double acos(double __x) __attribute__((__nothrow__
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
double atan2(double __y, double __x) __attribute__((__nothrow__
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_four
real(real64), parameter, public m_pi
some mathematical constants
complex(real64), parameter, public m_z0
real(real64), parameter, public m_half
real(real64), parameter, public m_one
real(real64), parameter, public m_three
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public dsymmetrize_matrix(nn, aa)
complex(real64) pure function, public phi2(z)
Compute phi2(z) = (phi1(z)-1)/z = (exp(z) - z - 1)/z^2.
integer pure function ilog2(xx)
logical pure function, public even(n)
Returns if n is even.
pure real(real64) function, dimension(dim, dim) ddiagonal_matrix(dim, diag)
Currently only returns a matrix whose diagonal elements are all the same. Note that the integer versi...
subroutine, public generalized_laguerre_polynomial(np, nn, mm, xx, cx)
complex(real64) pure function, public exponential(z)
Wrapper for exponential.
subroutine dinterpolate_0(xa, ya, x, y)
subroutine, public ylmr_cmplx(xx, li, mi, ylm)
Computes spherical harmonics ylm at position (x, y, z)
subroutine zinterpolate_0(xa, ya, x, y)
subroutine dinterpolate_1(xa, ya, x, y)
real(real64) pure function dlog2(xx)
integer(int64) pure function pad88(size, blk)
real(real64) pure function, public square_root(x)
Wrapper for sqrt.
logical function, public member(n, a)
Considers a(1:ubound(a, 1)) as an integer set and checks if n is a member of it.
integer pure function pad4(size, blk)
subroutine dlower_triangular_to_hermitian(nn, aa)
pure complex(real64) function, dimension(1:3), public dzcross_product(a, b)
subroutine, public cartesian2hyperspherical(x, u)
Performs a transformation of an n-dimensional vector from Cartesian coordinates to hyperspherical coo...
integer pure function, public pad_pow2(size)
create array size, which is padded to powers of 2
subroutine zinterpolate_1(xa, ya, x, y)
pure real(real64) function, dimension(1:3), public dcross_product(a, b)
integer(int64) pure function pad48(size, blk)
subroutine, public ylmr_real(xx, li, mi, ylm)
This is a Numerical Recipes-based subroutine computes real spherical harmonics ylm at position (x,...
subroutine dupper_triangular_to_hermitian(nn, aa)
subroutine, public interpolation_coefficients(nn, xa, xx, cc)
subroutine, public generate_rotation_matrix(R, ff, tt)
Generates a rotation matrix R to rotate a vector f to t.
elemental logical function zis_close_scalar(x, y, rtol, atol)
Same as dis_close_scalar for complex numbers.
logical pure function, public odd(n)
Returns if n is odd.
real(real64) pure function, public ddelta(i, j)
subroutine, public make_idx_set(n, out, length, in)
Construct out(1:length) = (/1, ..., n/) if in is not present, out(1:length) = in otherwise.
logical function, public is_prime(n)
complex(real64) pure function, public phi1(z)
Compute phi1(z) = (exp(z)-1)/z.
pure complex(real64) function, dimension(1:3), public zcross_product(a, b)
subroutine, public weights(N, M, cc, side)
Compute the weights for finite-difference calculations:
subroutine zinterpolate_2(xa, ya, x, y)
pure complex(real64) function, dimension(dim, dim) zdiagonal_matrix(dim, diag)
Currently only returns a matrix whose diagonal elements are all the same. Note that the integer versi...
subroutine zlower_triangular_to_hermitian(nn, aa)
subroutine zupper_triangular_to_hermitian(nn, aa)
pure integer function, dimension(dim, dim) idiagonal_matrix(dim, diag)
Currently only returns a matrix whose diagonal elements are all the same. Note that the real and comp...
integer(int64) pure function pad8(size, blk)
subroutine dinterpolate_2(xa, ya, x, y)
subroutine, public numder_ridders(x, h, res, err, f)
Numerical derivative (Ridder`s algorithm).
integer(int64) pure function llog2(xx)
recursive real(real64) function, public hermite(n, x)
elemental logical function dis_close_scalar(x, y, rtol, atol)
Are and equal within a tolerance.
pure complex(real64) function, dimension(1:3), public zdcross_product(a, b)
subroutine, public hyperspherical2cartesian(u, x)
Performs the inverse transformation of cartesian2hyperspherical.
subroutine, public dzero_small_elements_matrix(nn, aa, tol)
subroutine, public hypersphere_grad_matrix(grad_matrix, r, x)
Gives the hyperspherical gradient matrix, which contains the derivatives of the Cartesian coordinates...
recursive integer function, public factorial(n)