Octopus
math.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22module math_oct_m
23 use debug_oct_m
25 use global_oct_m
26 use, intrinsic :: iso_c_binding, only: c_double
27 use, intrinsic :: iso_fortran_env
32
33 implicit none
34
35 private
36 public :: &
37 is_close, &
39 ylmr_cmplx, &
40 ylmr_real, &
42 real_gaunt, &
43 weights, &
44 factorial, &
45 hermite, &
50 ddelta, &
53 even, &
54 odd, &
58 pad, &
59 pad_pow2, &
60 log2, &
61 expm1, &
63 phi1, &
64 phi2, &
66 is_prime, &
78 cos_safe, &
80
81 interface is_close
82 module procedure dis_close_scalar, zis_close_scalar
83 end interface
84
85 interface diagonal_matrix
87 end interface diagonal_matrix
88
92
96
99 interface interpolate
102 end interface interpolate
103
104 interface symmetrize_matrix
105 module procedure dsymmetrize_matrix, zsymmetrize_matrix
106 end interface symmetrize_matrix
107
108 interface log2
109 module procedure dlog2, ilog2, llog2
110 end interface log2
111
112 interface pad
113 module procedure pad4, pad8, pad48, pad88
114 end interface pad
115
116 interface
117 real(c_double) function expm1(x) bind(c, name='expm1')
118 import c_double
119 real(c_double), intent(in), value :: x
120 end function expm1
121 end interface
122
123contains
124
143 elemental logical function dis_close_scalar(x, y, rtol, atol)
144 real(real64), intent(in) :: x, y
145 real(real64), optional, intent(in) :: rtol
146 real(real64), optional, intent(in) :: atol
147 real(real64) :: atol_, rtol_
148
149 atol_ = optional_default(atol, 1.e-8_real64)
150 rtol_ = optional_default(rtol, 1.e-5_real64)
151
152 dis_close_scalar = abs(x - y) <= (atol_ + rtol_ * abs(y))
153 end function dis_close_scalar
154
156 elemental logical function zis_close_scalar(x, y, rtol, atol)
157 complex(real64), intent(in) :: x, y
158 real(real64), optional, intent(in) :: rtol
159 real(real64), optional, intent(in) :: atol
160 real(real64) :: atol_, rtol_
162 atol_ = optional_default(atol, 1.e-8_real64)
163 rtol_ = optional_default(rtol, 1.e-5_real64)
164
165 zis_close_scalar = abs(x - y) <= (atol_ + rtol_ * abs(y))
166 end function zis_close_scalar
167
168
169 ! ---------------------------------------------------------
172 pure function idiagonal_matrix(dim, diag) result(matrix)
173 integer, intent(in) :: dim
174 integer, intent(in) :: diag
175 integer :: matrix(dim, dim)
177 integer :: ii
178
179 matrix = 0
180 do ii = 1, dim
181 matrix(ii, ii) = diag
182 end do
183
184 end function idiagonal_matrix
185
186 ! ---------------------------------------------------------
187 recursive function hermite(n, x) result (h)
188 integer, intent(in) :: n
189 real(real64), intent(in) :: x
190
191 real(real64) :: h
192
193 ! no push_sub, called too frequently
194
195 if (n <= 0) then
196 h = m_one
197 elseif (n == 1) then
198 h = m_two*x
199 else
200 h = m_two*x*hermite(n-1,x) - m_two*(n-1)*hermite(n-2,x)
201 end if
202
203 end function hermite
204
205
206 ! ---------------------------------------------------------
207 recursive function factorial (n) RESULT (fac)
208 integer, intent(in) :: n
209
210 integer :: fac
211
212 ! no push_sub for recursive function
213
214 if (n <= 1) then
215 fac = 1
216 else
217 fac = n * factorial(n-1)
218 end if
219 end function factorial
220
221 ! ---------------------------------------------------------
223 subroutine ylmr_cmplx(xx, li, mi, ylm)
224 real(real64), intent(in) :: xx(3)
225 integer, intent(in) :: li, mi
226 complex(real64), intent(out) :: ylm
227
228 integer :: i
229 real(real64) :: dx, dy, dz, r, plm, cosm, sinm, cosmm1, sinmm1, cosphi, sinphi
230 real(real64), parameter :: tiny = 1.e-15_real64
231
232 ! no push_sub: this routine is called too many times
233
234 ! if l=0, no calculations are required
235 if (li == 0) then
236 ylm = cmplx(sqrt(m_one/(m_four*m_pi)), m_zero, real64)
237 return
238 end if
239
240 r = sqrt(xx(1)**2 + xx(2)**2 + xx(3)**2)
241
242 ! if r=0, direction is undefined => make ylm=0 except for l=0
243 if (r <= tiny) then
244 ylm = m_z0
245 return
246 end if
247 dx = xx(1)/r
248 dy = xx(2)/r
249 dz = xx(3)/r
250
251 ! get the associated Legendre polynomial (including the normalization factor)
252 ! We need to avoid getting outside [-1:1] due to rounding errors
253 if(abs(dz) > m_one) dz = sign(m_one, dz)
254 plm = loct_legendre_sphplm(li, abs(mi), dz)
255
256 ! compute sin(|m|*phi) and cos(|m|*phi)
257 r = sqrt(dx*dx + dy*dy)
258 if(r > tiny) then
259 cosphi = dx/r
260 sinphi = dy/r
261 else ! In this case the values are ill defined so we choose \phi=0
262 cosphi = m_zero
263 sinphi = m_zero
264 end if
265
266 cosm = m_one
267 sinm = m_zero
268 do i = 1, abs(mi)
269 cosmm1 = cosm
270 sinmm1 = sinm
271 cosm = cosmm1*cosphi - sinmm1*sinphi
272 sinm = cosmm1*sinphi + sinmm1*cosphi
273 end do
274
275 !And now ylm
276 ylm = plm*cmplx(cosm, sinm, real64)
277
278 if (mi < 0) then
279 ylm = conjg(ylm)
280 do i = 1, abs(mi)
281 ylm = -ylm
282 end do
283 end if
284
285 end subroutine ylmr_cmplx
286
287
288 ! ---------------------------------------------------------
294 subroutine ylmr_real(xx, li, mi, ylm)
295 real(real64), intent(in) :: xx(3)
296 integer, intent(in) :: li, mi
297 real(real64), intent(out) :: ylm
298
299 integer, parameter :: lmaxd = 20
300 real(real64), parameter :: tiny = 1.e-15_real64
301 integer :: i, ilm0, l, m, mabs
302 integer, save :: lmax = -1
303
304 real(real64) :: cmi, cosm, cosmm1, cosphi, fac, &
305 fourpi, plgndr, phase, pll, pmm, pmmp1, sinm, &
306 sinmm1, sinphi, rsize, rx, ry, rz, xysize
307 real(real64), save :: c(0:(lmaxd+1)*(lmaxd+1))
308 ! The lazily-filled table is per thread, as this is called from OpenMP regions
309 !$omp threadprivate(lmax, c)
310
311 ! no push_sub: called too frequently
312
313 ! evaluate normalization constants once and for all
314 if (li > lmax) then
315 fourpi = m_four*m_pi
316 do l = 0, li
317 ilm0 = l*l + l
318 do m = 0, l
319 fac = (2*l+1)/fourpi
320 do i = l - m + 1, l + m
321 fac = fac/i
322 end do
323 c(ilm0 + m) = sqrt(fac)
324 ! next line because ylm are real combinations of m and -m
325 if (m /= 0) c(ilm0 + m) = c(ilm0 + m)*sqrt(m_two)
326 c(ilm0 - m) = c(ilm0 + m)
327 end do
328 end do
329 lmax = li
330 end if
331
332 ! if l=0, no calculations are required
333 if (li == 0) then
334 ylm = c(0)
335 return
336 end if
337
338 ! if r=0, direction is undefined => make ylm=0 except for l=0
339 rsize = sqrt(xx(1)**2 + xx(2)**2 + xx(3)**2)
340 if (rsize < tiny) then
341 ylm = m_zero
342 return
343 end if
344
345 rx = xx(1)/rsize
346 ry = xx(2)/rsize
347 rz = xx(3)/rsize
348
349 ! explicit formulas for l=1 and l=2
350 if (li == 1) then
351 select case (mi)
352 case (-1)
353 ylm = (-c(1))*ry
354 case (0)
355 ylm = c(2)*rz
356 case (1)
357 ylm = (-c(3))*rx
358 end select
359 return
360 end if
361
362 if (li == 2) then
363 select case (mi)
364 case (-2)
365 ylm = c(4)*6.0_real64*rx*ry
366 case (-1)
367 ylm = (-c(5))*m_three*ry*rz
368 case (0)
369 ylm = c(6)*m_half*(m_three*rz*rz - m_one)
370 case (1)
371 ylm = (-c(7))*m_three*rx*rz
372 case (2)
373 ylm = c(8)*m_three*(rx*rx - ry*ry)
374 end select
375 return
376 end if
377
378 ! general algorithm based on routine plgndr of numerical recipes
379 mabs = abs(mi)
380 xysize = sqrt(max(rx*rx + ry*ry, tiny))
381 cosphi = rx/xysize
382 sinphi = ry/xysize
383 cosm = m_one
384 sinm = m_zero
385 do m = 1, mabs
386 cosmm1 = cosm
387 sinmm1 = sinm
388 cosm = cosmm1*cosphi - sinmm1*sinphi
389 sinm = cosmm1*sinphi + sinmm1*cosphi
390 end do
391
392 if (mi < 0) then
393 phase = sinm
394 else
395 phase = cosm
396 end if
397
398 pmm = m_one
399 fac = m_one
400 if (mabs > m_zero) then
401 do i = 1, mabs
402 pmm = (-pmm)*fac*xysize
403 fac = fac + m_two
404 end do
405 end if
406
407 if (li == mabs) then
408 plgndr = pmm
409 else
410 pmmp1 = rz*(2*mabs + 1)*pmm
411 if (li == mabs + 1) then
412 plgndr = pmmp1
413 else
414 do l = mabs + 2, li
415 pll = (rz*(2*l - 1)*pmmp1 - (l + mabs - 1)*pmm)/(l - mabs)
416 pmm = pmmp1
417 pmmp1 = pll
418 end do
419 plgndr = pll
420 end if
421 end if
422
423 ilm0 = li*li + li
424 cmi = c(ilm0 + mi)
425 ylm = cmi*plgndr*phase
426
427 end subroutine ylmr_real
428
429 ! ---------------------------------------------------------
442 subroutine ylmr_real_with_grad(xx, li, mi, ylm, grad_theta, grad_phi_oversin)
443 real(real64), intent(in) :: xx(3)
444 integer, intent(in) :: li, mi
445 real(real64), intent(out) :: ylm
446 real(real64), intent(out) :: grad_theta
447 real(real64), intent(out) :: grad_phi_oversin
448
449 real(real64), parameter :: tiny = 1.e-15_real64
450 real(real64) :: rsize, costh, sinth, ylm_lm1, ylm_negm, gfac
451
452 ! no push_sub: low-level helper called on every angular node
453
454 call ylmr_real(xx, li, mi, ylm)
455
456 rsize = sqrt(xx(1)**2 + xx(2)**2 + xx(3)**2)
457 if (li == 0 .or. rsize < tiny) then
458 grad_theta = m_zero
459 grad_phi_oversin = m_zero
460 return
461 end if
462
463 costh = xx(3)/rsize
464 sinth = sqrt(max(m_one - costh**2, m_zero))
465 if (sinth < tiny) then
466 ! poles: this angular parametrization is singular
467 grad_theta = m_zero
468 grad_phi_oversin = m_zero
469 return
470 end if
471
472 ! theta component
473 if (li - 1 >= abs(mi)) then
474 call ylmr_real(xx, li-1, mi, ylm_lm1)
475 gfac = real(li + abs(mi), real64) * &
476 sqrt(real((2*li+1)*(li-abs(mi)), real64) / real((2*li-1)*(li+abs(mi)), real64))
477 grad_theta = (real(li, real64)*costh*ylm - gfac*ylm_lm1)/sinth
478 else
479 ! l = |m|: Y_{l-1,m} = 0
480 grad_theta = real(li, real64)*costh*ylm/sinth
481 end if
482
483 ! (1/sin theta) phi component: dY_lm/dphi = -m Y_{l,-m}
484 if (mi == 0) then
485 grad_phi_oversin = m_zero
486 else
487 call ylmr_real(xx, li, -mi, ylm_negm)
488 grad_phi_oversin = -real(mi, real64)*ylm_negm/sinth
489 end if
490
491 end subroutine ylmr_real_with_grad
492
493
494 ! ---------------------------------------------------------
503 real(real64) function real_gaunt(l1, m1, l2, m2, l3, m3) result(coeff)
504 integer, intent(in) :: l1, m1, l2, m2, l3, m3
505
506 integer, parameter :: lmax_cache = 6
507 integer, parameter :: ngauss = 16 ! exact for polynomial degree <= 31 >= 3*lmax_cache
508 integer, parameter :: nphi = 72
509 real(real64), save :: cache(0:lmax_cache, -lmax_cache:lmax_cache, &
510 0:lmax_cache, -lmax_cache:lmax_cache, 0:lmax_cache, -lmax_cache:lmax_cache)
511 logical, save :: initialized(0:lmax_cache, -lmax_cache:lmax_cache, &
512 0:lmax_cache, -lmax_cache:lmax_cache, 0:lmax_cache, -lmax_cache:lmax_cache) = .false.
513 real(real64), save :: gl_x(1:ngauss), gl_w(1:ngauss)
514 logical, save :: gl_initialized = .false.
515
516 integer :: ix, iphi
517 real(real64) :: phi, dphi, y1, y2, y3, xx(3), sintheta
518
519 ! no PUSH_SUB/POP_SUB: this is a low-level, frequently-called numerical helper
520
521 assert(l1 >= 0 .and. l1 <= lmax_cache)
522 assert(l2 >= 0 .and. l2 <= lmax_cache)
523 assert(l3 >= 0 .and. l3 <= lmax_cache)
524 assert(abs(m1) <= l1)
525 assert(abs(m2) <= l2)
526 assert(abs(m3) <= l3)
527
528 if (.not. gl_initialized) then
529 ! Gauss-Legendre nodes and weights on [-1, 1]
530 call gauss_legendre_newton(ngauss, gl_x, gl_w)
531 gl_initialized = .true.
532 end if
533
534 if (.not. initialized(l1, m1, l2, m2, l3, m3)) then
535 dphi = m_two*m_pi/real(nphi, real64)
536
537 coeff = m_zero
538 do ix = 1, ngauss
539 sintheta = sqrt(max(m_one - gl_x(ix)**2, m_zero))
540 do iphi = 1, nphi
541 phi = (real(iphi, real64) - m_half)*dphi
542 xx(1) = sintheta*cos(phi)
543 xx(2) = sintheta*sin(phi)
544 xx(3) = gl_x(ix)
545
546 call ylmr_real(xx, l1, m1, y1)
547 call ylmr_real(xx, l2, m2, y2)
548 call ylmr_real(xx, l3, m3, y3)
549
550 coeff = coeff + y1*y2*y3*gl_w(ix)*dphi
551 end do
552 end do
553
554 cache(l1, m1, l2, m2, l3, m3) = coeff
555 initialized(l1, m1, l2, m2, l3, m3) = .true.
556 end if
557
558 coeff = cache(l1, m1, l2, m2, l3, m3)
559 end function real_gaunt
560
561
562 ! ---------------------------------------------------------
572 subroutine weights(N, M, cc, side)
573 integer, intent(in) :: n, m
574 real(real64), intent(out) :: cc(0:,0:,0:)
575 integer, optional, intent(in) :: side
576
577 integer :: i, j, k, mn, side_
578 real(real64) :: c1, c2, c3, c4, c5, xi
579 real(real64), allocatable :: x(:)
580
581 push_sub(weights)
582
583 safe_allocate(x(0:m))
584
585 if (present(side)) then
586 side_ = side
587 else
588 side_ = 0
589 end if
590
591 select case (side_)
592 case (-1)
593 ! grid-points for left-side finite-difference formulas on an equi-spaced grid
594 mn = m
595 x(:) = (/(-i,i=0,mn)/)
596 case (+1)
597 ! grid-points for right-side finite-difference formulas on an equi-spaced grid
598 mn = m
599 x(:) = (/(i,i=0,mn)/)
600 case default
601 ! grid-points for centered finite-difference formulas on an equi-spaced grid
602 mn = m/2
603 x(:) = (/0,(-i,i,i=1,mn)/)
604 end select
605
606
607
608 xi = m_zero ! point at which the approx. are to be accurate
609
610 cc = m_zero
611 cc(0,0,0) = m_one
612
613 c1 = m_one
614 c4 = x(0) - xi
615
616 do j = 1, m
617 mn = min(j,n)
618 c2 = m_one
619 c5 = c4
620 c4 = x(j) - xi
621
622 do k = 0, j - 1
623 c3 = x(j) - x(k)
624 c2 = c2*c3
625
626 if (j <= n) cc(k, j - 1, j) = m_zero
627 cc(k, j, 0) = c4*cc(k, j - 1, 0)/c3
628
629 do i = 1, mn
630 cc(k, j, i) = (c4*cc(k, j - 1, i) - i*cc(k, j - 1, i - 1))/c3
631 end do
632
633 cc(j, j, 0) = -c1*c5*cc(j - 1, j - 1, 0) / c2
634 end do
635
636 do i = 1, mn
637 cc(j, j, i) = c1*(i*cc(j - 1, j - 1, i - 1) - c5*cc(j - 1, j - 1, i))/c2
638 end do
639
640 c1 = c2
641 end do
642
643 safe_deallocate_a(x)
644 pop_sub(weights)
645 end subroutine weights
646
647 ! ---------------------------------------------------------
648 real(real64) pure function ddelta(i, j)
649 integer, intent(in) :: i
650 integer, intent(in) :: j
651
652 ! no push_sub in pure function
653
654 if (i == j) then
655 ddelta = m_one
656 else
657 ddelta = m_zero
658 end if
659
660 end function ddelta
661
662 ! ---------------------------------------------------------
663 subroutine interpolation_coefficients(nn, xa, xx, cc)
664 integer, intent(in) :: nn
665 real(real64), intent(in) :: xa(:)
666 real(real64), intent(in) :: xx
667 real(real64), contiguous, intent(out) :: cc(:)
668
669 integer :: ii, kk
670
671 ! no push_sub, called too frequently
672
673 do ii = 1, nn
674 cc(ii) = m_one
675 do kk = 1, nn
676 if (kk == ii) cycle
677 cc(ii) = cc(ii)*(xx - xa(kk))/(xa(ii) - xa(kk))
678 end do
679 end do
680
681 end subroutine interpolation_coefficients
682
683
684 ! ---------------------------------------------------------
686 logical pure function even(n)
687 integer, intent(in) :: n
688
689 even = (mod(n, 2) == 0)
690
691 end function even
692
693
694 ! ---------------------------------------------------------
696 logical pure function odd(n)
697 integer, intent(in) :: n
698
699 odd = .not. even(n)
700
701 end function odd
702
703 ! ---------------------------------------------------------
706 subroutine cartesian2hyperspherical(x, u)
707 real(real64), contiguous, intent(in) :: x(:)
708 real(real64), contiguous, intent(out) :: u(:)
709
710 integer :: n, k, j
711 real(real64) :: sumx2
712 real(real64), allocatable :: xx(:)
713
715
716 n = size(x)
717 assert(n>1)
718 assert(size(u) == n-1)
719
720 ! These lines make the code less machine-dependent.
721 safe_allocate(xx(1:n))
722 do j = 1, n
723 if (abs(x(j))<1.0e-8_real64) then
724 xx(j) = m_zero
725 else
726 xx(j) = x(j)
727 end if
728 end do
729
730 u = m_zero
731 do k = 1, n-1
732 sumx2 = m_zero
733 do j = k+1, n
734 sumx2 = sumx2 + xx(j)**2
735 end do
736 if (abs(sumx2) <= m_epsilon .and. abs(xx(k)) <= m_epsilon) exit
737 if (k < n - 1) then
738 u(k) = atan2(sqrt(sumx2), xx(k))
739 else
740 u(n-1) = atan2(xx(n), xx(n-1))
741 end if
742 end do
743
744
746 end subroutine cartesian2hyperspherical
747 ! ---------------------------------------------------------
748
749
750 ! ---------------------------------------------------------
753 subroutine hyperspherical2cartesian(u, x)
754 real(real64), contiguous, intent(in) :: u(:)
755 real(real64), contiguous, intent(out) :: x(:)
756
757 integer :: n, j, k
760
761 n = size(x)
762 assert(n>1)
763 assert(size(u) == n-1)
764
765 if (n == 2) then
766 x(1) = cos(u(1))
767 x(2) = sin(u(1))
768 elseif (n == 3) then
769 x(1) = cos(u(1))
770 x(2) = sin(u(1))*cos(u(2))
771 x(3) = sin(u(1))*sin(u(2))
772 else
773 x(1) = cos(u(1))
774 x(2) = sin(u(1))*cos(u(2))
775 x(3) = sin(u(1))*sin(u(2))*cos(u(3))
776 do j = 4, n - 1
777 x(j) = m_one
778 do k = 1, j - 1
779 x(j) = x(j) * sin(u(k))
780 end do
781 x(j) = x(j) * cos(u(j))
782 end do
783 x(n) = m_one
784 do k = 1, n - 2
785 x(n) = x(n) * sin(u(k))
786 end do
787 x(n) = x(n) * sin(u(n-1))
788 end if
789
791 end subroutine hyperspherical2cartesian
792 ! ---------------------------------------------------------
793
794
795 ! ---------------------------------------------------------
799 subroutine hypersphere_grad_matrix(grad_matrix, r, x)
800 real(real64), contiguous, intent(out) :: grad_matrix(:,:)
801 real(real64), intent(in) :: r
802 real(real64), contiguous, intent(in) :: x(:)
803
804 integer :: n, l, m
805
807
808 n = size(x)+1 ! the dimension of the matrix is (n-1)x(n)
809
810 ! --- l=1 ---
811 grad_matrix = m_one
812 grad_matrix(1,1) = -r*sin(x(1))
813 do m = 2, n-1
814 grad_matrix(m,1) = m_zero
815 end do
816
817 ! --- l=2..(n-1) ---
818 do l=2, n-1
819 do m=1, n-1
820 if (m == l) then
821 grad_matrix(m,l) = -r*grad_matrix(m,l)*product(sin(x(1:l)))
822 elseif (m < l) then
823 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)))
824 else
825 grad_matrix(m,l) = m_zero
826 end if
827 end do
828 end do
829
830 ! --- l=n ---
831 do m=1, n-1
832 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)))
833 end do
834
836 end subroutine hypersphere_grad_matrix
837
838 ! ---------------------------------------------------------
839 integer(int64) pure function pad88(size, blk)
840 integer(int64), intent(in) :: size
841 integer(int64), intent(in) :: blk
842
843 integer(int64) :: mm
844
845 mm = mod(size, blk)
846 if (mm == 0) then
847 pad88 = size
848 else
849 pad88 = size + blk - mm
850 end if
851 end function pad88
852
853 ! ---------------------------------------------------------
854 integer(int64) pure function pad48(size, blk)
855 integer, intent(in) :: size
856 integer(int64), intent(in) :: blk
857
858 pad48 = pad88(int(size, int64), blk)
859 end function pad48
860
861 ! ---------------------------------------------------------
862 integer(int64) pure function pad8(size, blk)
863 integer(int64), intent(in) :: size
864 integer, intent(in) :: blk
865
866 pad8 = pad88(size, int(blk, int64))
867 end function pad8
868
869 ! ---------------------------------------------------------
870 integer pure function pad4(size, blk)
871 integer, intent(in) :: size
872 integer, intent(in) :: blk
873
874 pad4 = int(pad88(int(size, int64), int(blk, int64)), int32)
875 end function pad4
876
877 ! ---------------------------------------------------------
878
883 integer pure function pad_pow2(size)
884 integer, intent(in) :: size
885
886 integer :: mm, mm2
887
888 mm = size
889 pad_pow2 = 1
890
891 ! loop below never terminates otherwise! just pick 1 as value.
892 if (size == 0) return
893
894 ! first we divide by two all the times we can, so we catch exactly
895 ! the case when size is already a power of two
896 do
897 mm2 = mm/2
898 if (mm - 2*mm2 /= 0) exit
900 mm = mm2
901 end do
902
903 ! the rest is handled by log2
904 if (mm /= 1) then
905 pad_pow2 = pad_pow2*2**(ceiling(log(real(mm, real64) )/log(2.0_8)))
906 end if
907
908 end function pad_pow2
909
910 ! -------------------------------------------------------
912 real(real64) pure function dlog2(xx)
913 real(real64), intent(in) :: xx
914
915 dlog2 = log(xx)/log(m_two)
916 end function dlog2
917
918 ! -------------------------------------------------------
919
920 integer pure function ilog2(xx)
921 integer, intent(in) :: xx
922
923 ilog2 = nint(log2(real(xx, real64) ))
924 end function ilog2
925
926 ! -------------------------------------------------------
927
928 integer(int64) pure function llog2(xx)
929 integer(int64), intent(in) :: xx
930
931 llog2 = nint(log2(real(xx, real64) ), kind=int64)
932 end function llog2
933
934 ! -------------------------------------------------------
936 complex(real64) pure function exponential(z)
937 complex(real64), intent(in) :: z
938
939 exponential = exp(z)
940 end function exponential
941
942 ! -------------------------------------------------------
948 complex(real64) pure function phi1(z)
949 complex(real64), intent(in) :: z
950
951 real(real64), parameter :: cut = 0.002_real64
952
953 if (abs(z) < cut) then
954 phi1 = m_one + m_half*z*(m_one + z/m_three*(m_one + m_fourth*z*(m_one + z/m_five)))
955 else
956 phi1 = (exp(z) - m_z1)/z
957 end if
958 end function phi1
959
960 ! -------------------------------------------------------
967 complex(real64) pure function phi2(z)
968 complex(real64), intent(in) :: z
969
970 real(real64), parameter :: cut = 0.002_real64
971
972 if (abs(z) < cut) then
973 phi2 = m_half + z/6.0_real64*(m_one + m_fourth*z*(m_one + z/m_five*(m_one + z/6.0_real64)))
974 else
975 phi2 = (exp(z) - z - m_z1)/z**2
976 end if
977 end function phi2
978
979 ! -------------------------------------------------------
981 real(real64) pure function square_root(x)
982 real(real64), intent(in) :: x
983
985 end function square_root
986
987 ! -------------------------------------------------------
988
989 logical function is_prime(n)
990 integer, intent(in) :: n
991
992 integer :: i, root
993
994 push_sub(is_prime)
995
996 if (n < 1) then
997 message(1) = "Internal error: is_prime does not take negative numbers."
998 call messages_fatal(1)
999 end if
1000 if (n == 1) then
1001 is_prime = .false.
1002 pop_sub(is_prime)
1003 return
1004 end if
1005
1006 root = nint(sqrt(real(n, real64) ))
1007 do i = 2, root
1008 if (mod(n,i) == 0) then
1009 is_prime = .false.
1010 pop_sub(is_prime)
1011 return
1012 end if
1013 end do
1014
1015 is_prime = .true.
1016 pop_sub(is_prime)
1017 end function is_prime
1018
1019 ! ---------------------------------------------------------
1024 subroutine generate_rotation_matrix(R, ff, tt)
1025 real(real64), contiguous, intent(out) :: r(:,:)
1026 real(real64), intent(in) :: ff(:)
1027 real(real64), contiguous, intent(in) :: tt(:)
1028
1029 integer :: dim, i, j
1030 real(real64) :: th, uv, uu, vv, ft
1031 real(real64), allocatable :: axis(:), u(:), v(:), f(:), t(:), p(:)
1032
1033 push_sub(generate_rotation_matrix)
1034
1035 dim = size(ff,1)
1036
1037 assert((dim == 2) .or. (dim == 3))
1038 assert(size(tt,1) == dim)
1039 assert((size(r,1) == dim) .and. (size(r,2) == dim))
1040
1041 safe_allocate(u(1:dim))
1042 safe_allocate(v(1:dim))
1043 safe_allocate(f(1:dim))
1044 safe_allocate(t(1:dim))
1045
1046
1047 !normalize
1048 f = ff / norm2(ff)
1049 t = tt / norm2(tt)
1050
1051 ft = dot_product(f,t)
1052 ! Note : if ff and tt are antiparallel, we get ft = -1 and R = Identity.
1053 ! This is wrong.
1054
1055 if (abs(ft) < m_one) then
1056 select case (dim)
1057 case (2)
1058 th = acos(ft)
1059 r(1,1) = cos(th)
1060 r(1,2) = -sin(th)
1062 r(2,1) = sin(th)
1063 r(2,2) = cos(th)
1064
1065 case (3)
1066 if (.false.) then
1067 !Old implementation
1068 safe_allocate(axis(1:dim))
1069 th = acos(ft)
1070
1071 u = f / dot_product(f,f)
1072 v = t /dot_product(t,t)
1073
1074 axis = dcross_product(u,v)
1075 axis = axis / norm2(axis)
1076
1077 r(1,1) = cos(th) + axis(1)**2 * (1 - cos(th))
1078 r(1,2) = axis(1)*axis(2)*(1-cos(th)) + axis(3)*sin(th)
1079 r(1,3) = axis(1)*axis(3)*(1-cos(th)) - axis(2)*sin(th)
1080
1081 r(2,1) = axis(2)*axis(1)*(1-cos(th)) - axis(3)*sin(th)
1082 r(2,2) = cos(th) + axis(2)**2 * (1 - cos(th))
1083 r(2,3) = axis(2)*axis(3)*(1-cos(th)) + axis(1)*sin(th)
1084
1085 r(3,1) = axis(3)*axis(1)*(1-cos(th)) + axis(2)*sin(th)
1086 r(3,2) = axis(3)*axis(2)*(1-cos(th)) - axis(1)*sin(th)
1087 r(3,3) = cos(th) + axis(3)**2 * (1 - cos(th))
1088
1089 safe_deallocate_a(axis)
1090 end if
1091
1092 if (.true.) then
1093 !Naive implementation
1094 th = acos(ft)
1095 u = dcross_product(f,t)
1096 u = u / norm2(u)
1097
1098 r(1,1) = u(1)**2 + (1-u(1)**2)*cos(th)
1099 r(1,2) = u(1)*u(2)*(1-cos(th)) - u(3)*sin(th)
1100 r(1,3) = u(1)*u(3) + u(2)*sin(th)
1101
1102 r(2,1) = u(1)*u(2)*(1-cos(th)) + u(3)*sin(th)
1103 r(2,2) = u(2)**2 + (1-u(2)**2)*cos(th)
1104 r(2,3) = u(2)*u(3)*(1-cos(th)) - u(1)*sin(th)
1105
1106 r(3,1) = u(1)*u(3)*(1-cos(th)) - u(2)*sin(th)
1107 r(3,2) = u(2)*u(3)*(1-cos(th)) + u(1)*sin(th)
1108 r(3,3) = u(3)**2 + (1-u(3)**2)*cos(th)
1109 end if
1110
1111 if (.false.) then
1112 !Fast
1113 safe_allocate(p(1:dim))
1114
1115 if (abs(f(1)) <= abs(f(2)) .and. abs(f(1)) < abs(f(3))) then
1116 p = (/m_one, m_zero, m_zero/)
1117 else if (abs(f(2)) < abs(f(1)) .and. abs(f(2)) <= abs(f(3))) then
1118 p = (/m_zero, m_one, m_zero/)
1119 else if (abs(f(3)) <= abs(f(1)) .and. abs(f(3)) < abs(f(2))) then
1120 p = (/m_zero, m_zero, m_one/)
1121 end if
1122
1123 u = p - f
1124 v = p - t
1125
1126 uu = dot_product(u,u)
1127 vv = dot_product(v,v)
1128 uv = dot_product(u,v)
1129
1130 do i = 1,3
1131 do j = 1,3
1132
1133 r(i,j) = ddelta(i,j) - m_two * u(i)*u(j)/uu - m_two * v(i)*v(j)/vv &
1134 + 4_real64*uv * v(i)*u(j) /(uu*vv)
1135
1136 end do
1137 end do
1138
1139 safe_deallocate_a(p)
1140 end if
1141
1142
1143 end select
1144
1145 else
1146
1147 r = m_zero
1148 do i = 1,dim
1149 r(i,i) = m_one
1150 end do
1151
1152 end if
1153
1154
1155 safe_deallocate_a(u)
1156 safe_deallocate_a(v)
1157
1159 end subroutine generate_rotation_matrix
1160
1161 ! ---------------------------------------------------------
1170 subroutine numder_ridders(x, h, res, err, f)
1171 implicit none
1172 real(real64), intent(in) :: x, h
1173 real(real64), intent(out) :: res, err
1174 interface
1175 subroutine f(x, fx)
1176 use, intrinsic :: iso_fortran_env
1177 implicit none
1178 real(real64), intent(in) :: x
1179 real(real64), intent(inout) :: fx
1180 end subroutine f
1181 end interface
1182
1183 real(real64), parameter :: con = 1.4_real64, big = 1.0e30_real64, safe = m_two
1184 integer, parameter :: ntab = 20
1185 integer :: i, j
1186 real(real64) :: errt, fac, hh, fx1, fx2
1187 real(real64), allocatable :: a(:, :)
1188
1189 push_sub(numder_ridders)
1190
1191 if (abs(h) <= m_epsilon) then
1192 message(1) = "h must be nonzero in numder_ridders"
1193 call messages_fatal(1)
1194 end if
1195
1196 safe_allocate(a(1:ntab, 1:ntab))
1197
1198 hh = h
1199 call f(x+hh, fx1)
1200 call f(x-hh, fx2)
1201 a(1,1) = (fx1-fx2) / (m_two*hh)
1202 err = big
1203 do i = 2, ntab
1204 hh = hh / con
1205 call f(x+hh, fx1)
1206 call f(x-hh, fx2)
1207 a(1,i) = (fx1-fx2) / (m_two*hh)
1208 fac = con**2
1209 do j = 2, i
1210 a(j,i) = (a(j-1,i)*fac-a(j-1,i-1)) / (fac-m_one)
1211 fac = con**2*fac
1212 errt = max(abs(a(j,i)-a(j-1,i)),abs(a(j,i)-a(j-1,i-1)))
1213 if (errt .le. err) then
1214 err = errt
1215 res = a(j,i)
1216 end if
1217 end do
1218 if (abs(a(i,i)-a(i-1,i-1)) .ge. safe*err) then
1219 safe_deallocate_a(a)
1220 pop_sub(numder_ridders)
1221 return
1222 end if
1223 end do
1224
1225 safe_deallocate_a(a)
1226 pop_sub(numder_ridders)
1227 end subroutine numder_ridders
1228
1229 ! ---------------------------------------------------------
1230 pure function dzcross_product(a, b) result(c)
1231 real(real64), contiguous, intent(in) :: a(:)
1232 complex(real64), contiguous, intent(in) :: b(:)
1233
1234 complex(real64) :: c(1:3)
1235
1236 c(1) = a(2)*b(3) - a(3)*b(2)
1237 c(2) = a(3)*b(1) - a(1)*b(3)
1238 c(3) = a(1)*b(2) - a(2)*b(1)
1239
1240 end function dzcross_product
1241
1242 ! ---------------------------------------------------------
1243 pure function zdcross_product(a, b) result(c)
1244 complex(real64), contiguous, intent(in) :: a(:)
1245 real(real64), contiguous, intent(in) :: b(:)
1246
1247 complex(real64) :: c(1:3)
1248
1249 c(1) = a(2)*b(3) - a(3)*b(2)
1250 c(2) = a(3)*b(1) - a(1)*b(3)
1251 c(3) = a(1)*b(2) - a(2)*b(1)
1252
1253 end function zdcross_product
1254
1255
1256!*****************************************************************************80
1257!
1258!! LM_POLYNOMIAL evaluates Laguerre polynomials Lm(n,m,x).
1259!
1260! First terms:
1261!
1262! M = 0
1263!
1264! Lm(0,0,X) = 1
1265! Lm(1,0,X) = -X + 1
1266! Lm(2,0,X) = X^2 - 4 X + 2
1267! Lm(3,0,X) = -X^3 + 9 X^2 - 18 X + 6
1268! Lm(4,0,X) = X^4 - 16 X^3 + 72 X^2 - 96 X + 24
1269! Lm(5,0,X) = -X^5 + 25 X^4 - 200 X^3 + 600 X^2 - 600 x + 120
1270! Lm(6,0,X) = X^6 - 36 X^5 + 450 X^4 - 2400 X^3 + 5400 X^2 - 4320 X + 720
1271!
1272! M = 1
1273!
1274! Lm(0,1,X) = 0
1275! Lm(1,1,X) = -1,
1276! Lm(2,1,X) = 2 X - 4,
1277! Lm(3,1,X) = -3 X^2 + 18 X - 18,
1278! Lm(4,1,X) = 4 X^3 - 48 X^2 + 144 X - 96
1279!
1280! M = 2
1281!
1282! Lm(0,2,X) = 0
1283! Lm(1,2,X) = 0,
1284! Lm(2,2,X) = 2,
1285! Lm(3,2,X) = -6 X + 18,
1286! Lm(4,2,X) = 12 X^2 - 96 X + 144
1287!
1288! M = 3
1289!
1290! Lm(0,3,X) = 0
1291! Lm(1,3,X) = 0,
1292! Lm(2,3,X) = 0,
1293! Lm(3,3,X) = -6,
1294! Lm(4,3,X) = 24 X - 96
1295!
1296! M = 4
1297!
1298! Lm(0,4,X) = 0
1299! Lm(1,4,X) = 0
1300! Lm(2,4,X) = 0
1301! Lm(3,4,X) = 0
1302! Lm(4,4,X) = 24
1303!
1304! Recursion:
1305!
1306! Lm(0,M,X) = 1
1307! Lm(1,M,X) = (M+1-X)
1308!
1309! if 2 <= N:
1310!
1311! Lm(N,M,X) = ( (M+2*N-1-X) * Lm(N-1,M,X)
1312! + (1-M-N) * Lm(N-2,M,X) ) / N
1313!
1314! Special values:
1316! For M = 0, the associated Laguerre polynomials Lm(N,M,X) are equal
1317! to the Laguerre polynomials L(N,X).
1318!
1319! Licensing:
1320!
1321! This code is distributed under the GNU LGPL license.
1322!
1323! Modified:
1324!
1325! 08 February 2003
1326!
1327! Author:
1328!
1329! John Burkardt
1330!
1331! Reference:
1332!
1333! Milton Abramowitz, Irene Stegun,
1334! Handbook of Mathematical Functions,
1335! National Bureau of Standards, 1964,
1336! ISBN: 0-486-61272-4,
1337! LC: QA47.A34.
1338!
1339! Parameters:
1340!
1341! Input, integer ( kind = 4 ) MM, the number of evaluation points.
1342!
1343! Input, integer ( kind = 4 ) N, the highest order polynomial to compute.
1344! Note that polynomials 0 through N will be computed.
1345!
1346! Input, integer ( kind = 4 ) M, the parameter. M must be nonnegative.
1347!
1348! Input, real ( kind = rk ) X(MM), the evaluation points.
1349!
1350! Output, real ( kind = rk ) CX(MM,0:N), the associated Laguerre polynomials
1351! of degrees 0 through N evaluated at the evaluation points.
1352!
1353! Taken from
1354! https://people.sc.fsu.edu/~jburkardt/f_src/laguerre_polynomial/laguerre_polynomial.html
1355! and adapted to Octopus by N. Tancogne-Dejean
1356 subroutine generalized_laguerre_polynomial ( np, nn, mm, xx, cx )
1357 integer, intent(in) :: np
1358 integer, intent(in) :: nn, mm
1359 real(real64), intent(in) :: xx(np)
1360 real(real64), intent(out) :: cx(np)
1361
1362 integer ii, ip
1363 real(real64), allocatable :: cx_tmp(:,:)
1364
1365 assert(mm >= 0)
1366
1367 safe_allocate(cx_tmp(1:np, 0:nn))
1368
1369 if (nn < 0) then
1370 cx = m_zero
1371 return
1372 end if
1373
1374 if (nn == 0) then
1375 cx(1:np) = m_one
1376 return
1377 end if
1378
1379 cx_tmp(1:np,0) = m_one
1380 !$omp parallel private(ii, ip)
1381 !$omp do
1382 do ip = 1, np
1383 cx_tmp(ip,1) = real(mm + 1, real64) - xx(ip)
1384 end do
1385 !$omp end do
1386 do ii = 2, nn
1387 !$omp do
1388 do ip = 1, np
1389 cx_tmp(ip, ii) = &
1390 (( real(mm + 2*ii - 1, real64) - xx(ip)) * cx_tmp(ip,ii-1) &
1391 + real(-mm -ii + 1, real64) * cx_tmp(ip,ii-2)) / real(ii, real64)
1392 end do
1393 end do
1394 !$omp end parallel
1395
1396 cx(1:np) = cx_tmp(1:np, nn)
1397
1398 safe_deallocate_a(cx_tmp)
1399
1400 end subroutine generalized_laguerre_polynomial
1401
1402 subroutine dupper_triangular_to_hermitian(nn, aa)
1403 integer, intent(in) :: nn
1404 real(real64), contiguous, intent(inout) :: aa(:, :)
1405
1406 integer :: ii, jj
1407
1408 do jj = 1, nn
1409 do ii = 1, jj-1
1410 aa(jj, ii) = aa(ii, jj)
1411 end do
1412 end do
1413 end subroutine dupper_triangular_to_hermitian
1414
1415 subroutine zupper_triangular_to_hermitian(nn, aa)
1416 integer, intent(in) :: nn
1417 complex(real64), contiguous, intent(inout) :: aa(:, :)
1418
1419 integer :: ii, jj
1420
1421 do jj = 1, nn
1422 do ii = 1, jj-1
1423 aa(jj, ii) = conjg(aa(ii, jj))
1424 end do
1425 aa(jj, jj) = real(aa(jj, jj), real64)
1426 end do
1427 end subroutine zupper_triangular_to_hermitian
1429 subroutine dlower_triangular_to_hermitian(nn, aa)
1430 integer, intent(in) :: nn
1431 real(real64), contiguous, intent(inout) :: aa(:, :)
1432
1433 integer :: ii, jj
1434
1435 do jj = 1, nn
1436 do ii = 1, jj-1
1437 aa(ii, jj) = aa(jj, ii)
1438 end do
1439 end do
1440 end subroutine dlower_triangular_to_hermitian
1441
1442 subroutine zlower_triangular_to_hermitian(nn, aa)
1443 integer, intent(in) :: nn
1444 complex(real64), contiguous, intent(inout) :: aa(:, :)
1445
1446 integer :: ii, jj
1447
1448 do jj = 1, nn
1449 do ii = 1, jj-1
1450 aa(ii, jj) = conjg(aa(jj, ii))
1451 end do
1452 aa(jj, jj) = real(aa(jj, jj), real64)
1453 end do
1454 end subroutine zlower_triangular_to_hermitian
1455
1457 subroutine dsymmetrize_matrix(nn, aa)
1458 integer, intent(in) :: nn
1459 real(real64), contiguous, intent(inout) :: aa(:, :)
1460
1461 integer :: ii, jj
1462
1463 do ii = 1, nn
1464 do jj = ii+1, nn
1465 aa(ii, jj) = m_half * (aa(ii, jj) + aa(jj, ii))
1466 aa(jj, ii) = aa(ii, jj)
1467 end do
1468 end do
1469 end subroutine dsymmetrize_matrix
1470
1472 subroutine zsymmetrize_matrix(n, a)
1473 integer, intent(in) :: n
1474 complex(real64), contiguous, intent(inout) :: a(:, :)
1475
1476 integer :: i,j
1477
1478 do i = 1, n
1479 do j = i+1, n
1480 a(i, j) = m_half * (a(i, j) + conjg(a(j, i)))
1481 a(j, i) = conjg(a(i, j))
1482 end do
1483 end do
1484 end subroutine zsymmetrize_matrix
1485
1486
1488 real(real64), contiguous, intent(inout) :: aa(:, :)
1489 real(real64), intent(in) :: tol
1490
1491 where(abs(aa)<tol)
1492 aa = m_zero
1493 end where
1494 end subroutine dzero_small_elements_matrix
1495
1497 logical function is_symmetric(a, tol)
1498 real(real64), intent(in) :: a(:, :)
1499 real(real64), optional, intent(in) :: tol
1500
1501 real(real64) :: tolerance
1502
1503 push_sub(is_symmetric)
1504
1505 tolerance = optional_default(tol, 1.0e-8_real64)
1506 ! a must be square
1507 assert(size(a, 1) == size(a, 2))
1508
1509 is_symmetric = all(abs(a - transpose(a)) < tolerance)
1510
1511 pop_sub(is_symmetric)
1512
1513 end function is_symmetric
1516 logical pure function is_diagonal(dim, matrix, tol)
1517 integer, intent(in) :: dim
1518 real(real64), intent(in) :: matrix(:, :)
1519 real(real64), intent(in) :: tol
1520
1521 integer :: ii, jj
1522 real(real64) :: max_diag
1523
1524 max_diag = m_zero
1525 do ii = 1, dim
1526 max_diag = max(abs(matrix(ii, ii)), max_diag)
1527 end do
1528
1530 do ii = 1, dim
1531 do jj = 1, dim
1532 if (ii == jj) cycle
1533 if (abs(matrix(ii, jj)) > tol*max_diag) is_diagonal = .false.
1534 end do
1535 end do
1536
1537 end function is_diagonal
1538
1540 subroutine convert_to_base(num, base, converted)
1541 integer, intent(in) :: num
1542 integer, intent(in) :: base
1543 integer, contiguous, intent(out) :: converted(:)
1545 integer :: i, num_, length
1546
1547 ! no PUSH_SUB, called too often
1548
1549 converted = 0
1550 if (num > 0) then
1551 ! length of converted number
1552 length = floor(log(real(num, real64)) / log(real(base, real64))) + 1
1553 assert(size(converted) >= length)
1554
1555 num_ = num
1556 ! do conversion by repeated division
1557 do i = 1, size(converted)
1558 converted(i) = mod(num_, base)
1559 num_ = num_ / base
1560 end do
1561 end if
1562
1563 end subroutine convert_to_base
1564
1566 subroutine convert_from_base(converted, base, num)
1567 integer, intent(in) :: converted(:)
1568 integer, intent(in) :: base
1569 integer, intent(out) :: num
1570
1571 integer :: i
1572
1573 ! no PUSH_SUB, called too often
1574
1575 num = m_zero
1576 do i = 1, size(converted)
1577 num = num + converted(i) * base**(i-1)
1578 end do
1579
1580 end subroutine convert_from_base
1581
1585 pure real(real64) function cos_safe(deg)
1586 real(real64), intent(in) :: deg
1587
1588 if (abs(abs(deg) - 90.0_real64) < m_epsilon) then
1589 cos_safe = m_zero
1590 else if (abs(deg) < m_epsilon) then
1591 cos_safe = m_one
1592 else if (abs(abs(deg) - 180.0_real64) < m_epsilon) then
1593 cos_safe = -m_one
1594 else
1595 cos_safe = cos(m_pi*deg/180.0_real64)
1596 end if
1597 end function cos_safe
1598
1602 pure real(real64) function sin_safe(deg)
1603 real(real64), intent(in) :: deg
1604
1605 if (abs(deg - 90.0_real64) < m_epsilon) then
1606 sin_safe = m_one
1607 else if (abs(deg + 90.0_real64) < m_epsilon) then
1608 sin_safe = -m_one
1609 else if (abs(deg) < m_epsilon .or. abs(abs(deg) - 180.0_real64) < m_epsilon) then
1610 sin_safe = m_zero
1611 else
1612 sin_safe = sin(m_pi*deg/180.0_real64)
1613 end if
1614 end function sin_safe
1615
1616#include "undef.F90"
1617#include "complex.F90"
1618#include "math_inc.F90"
1619
1620#include "undef.F90"
1621#include "real.F90"
1622#include "math_inc.F90"
1623
1624end module math_oct_m
1625
1626!! Local Variables:
1627!! mode: f90
1628!! coding: utf-8
1629!! End:
This is the common interface to a simple-minded polynomical interpolation procedure (simple use of th...
Definition: math.F90:171
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__
double floor(double __x) __attribute__((__nothrow__
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
subroutine zsymmetrize_matrix(n, a)
make a complex matrix Hermitian
Definition: math.F90:1545
complex(real64) pure function, public phi2(z)
Compute phi2(z) = (phi1(z)-1)/z = (exp(z) - z - 1)/z^2.
Definition: math.F90:1040
integer pure function ilog2(xx)
Definition: math.F90:993
logical pure function, public even(n)
Returns if n is even.
Definition: math.F90:759
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...
Definition: math.F90:1950
subroutine, public generalized_laguerre_polynomial(np, nn, mm, xx, cx)
Definition: math.F90:1429
complex(real64) pure function, public exponential(z)
Wrapper for exponential.
Definition: math.F90:1009
subroutine dinterpolate_0(xa, ya, x, y)
Definition: math.F90:2028
subroutine, public ylmr_cmplx(xx, li, mi, ylm)
Computes spherical harmonics ylm at position (x, y, z)
Definition: math.F90:296
subroutine zinterpolate_0(xa, ya, x, y)
Definition: math.F90:1837
subroutine, public convert_to_base(num, base, converted)
convert an integer in base 10 to a different base
Definition: math.F90:1613
subroutine dinterpolate_1(xa, ya, x, y)
Definition: math.F90:2000
real(real64) pure function dlog2(xx)
Definition: math.F90:985
integer(int64) pure function pad88(size, blk)
Definition: math.F90:912
real(real64) pure function, public square_root(x)
Wrapper for sqrt.
Definition: math.F90:1054
integer pure function pad4(size, blk)
Definition: math.F90:943
subroutine dlower_triangular_to_hermitian(nn, aa)
Definition: math.F90:1502
pure complex(real64) function, dimension(1:3), public dzcross_product(a, b)
Definition: math.F90:1303
subroutine, public cartesian2hyperspherical(x, u)
Performs a transformation of an n-dimensional vector from Cartesian coordinates to hyperspherical coo...
Definition: math.F90:779
integer pure function, public pad_pow2(size)
create array size, which is padded to powers of 2
Definition: math.F90:956
pure real(real64) function, public cos_safe(deg)
Cosine of an angle in degrees, exact at multiples of 90 degrees.
Definition: math.F90:1658
subroutine, public dzero_small_elements_matrix(aa, tol)
Definition: math.F90:1560
subroutine zinterpolate_1(xa, ya, x, y)
Definition: math.F90:1809
pure real(real64) function, dimension(1:3), public dcross_product(a, b)
Definition: math.F90:2053
integer(int64) pure function pad48(size, blk)
Definition: math.F90:927
subroutine dsymmetrize_matrix(nn, aa)
symmetrize a real matrix
Definition: math.F90:1530
subroutine, public ylmr_real_with_grad(xx, li, mi, ylm, grad_theta, grad_phi_oversin)
Real spherical harmonic together with its angular gradient.
Definition: math.F90:515
subroutine, public ylmr_real(xx, li, mi, ylm)
This is a Numerical Recipes-based subroutine computes real spherical harmonics ylm at position (x,...
Definition: math.F90:367
subroutine dupper_triangular_to_hermitian(nn, aa)
Definition: math.F90:1475
subroutine, public interpolation_coefficients(nn, xa, xx, cc)
Definition: math.F90:736
logical function, public is_symmetric(a, tol)
Check if a 2D array is symmetric.
Definition: math.F90:1570
subroutine, public generate_rotation_matrix(R, ff, tt)
Generates a rotation matrix R to rotate a vector f to t.
Definition: math.F90:1097
elemental logical function zis_close_scalar(x, y, rtol, atol)
Same as dis_close_scalar for complex numbers.
Definition: math.F90:229
logical pure function, public odd(n)
Returns if n is odd.
Definition: math.F90:769
real(real64) pure function, public ddelta(i, j)
Definition: math.F90:721
pure real(real64) function, public sin_safe(deg)
Sine of an angle in degrees, exact at multiples of 90 degrees.
Definition: math.F90:1675
logical function, public is_prime(n)
Definition: math.F90:1062
complex(real64) pure function, public phi1(z)
Compute phi1(z) = (exp(z)-1)/z.
Definition: math.F90:1021
pure complex(real64) function, dimension(1:3), public zcross_product(a, b)
Definition: math.F90:1862
subroutine, public weights(N, M, cc, side)
Compute the weights for finite-difference calculations:
Definition: math.F90:645
subroutine zinterpolate_2(xa, ya, x, y)
Definition: math.F90:1774
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...
Definition: math.F90:1759
subroutine zlower_triangular_to_hermitian(nn, aa)
Definition: math.F90:1515
logical pure function, public is_diagonal(dim, matrix, tol)
Returns true is the matrix of size dim x dim is diagonal, given a relative tolerance.
Definition: math.F90:1589
subroutine zupper_triangular_to_hermitian(nn, aa)
Definition: math.F90:1488
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...
Definition: math.F90:245
integer(int64) pure function pad8(size, blk)
Definition: math.F90:935
subroutine dinterpolate_2(xa, ya, x, y)
Definition: math.F90:1965
subroutine, public numder_ridders(x, h, res, err, f)
Numerical derivative (Ridder`s algorithm).
Definition: math.F90:1243
integer(int64) pure function llog2(xx)
Definition: math.F90:1001
recursive real(real64) function, public hermite(n, x)
Definition: math.F90:260
elemental logical function dis_close_scalar(x, y, rtol, atol)
Are and equal within a tolerance.
Definition: math.F90:216
pure complex(real64) function, dimension(1:3), public zdcross_product(a, b)
Definition: math.F90:1316
subroutine, public convert_from_base(converted, base, num)
convert an integer to base 10 from a different base
Definition: math.F90:1639
real(real64) function, public real_gaunt(l1, m1, l2, m2, l3, m3)
Real Gaunt coefficient , by quadrature.
Definition: math.F90:576
subroutine, public hyperspherical2cartesian(u, x)
Performs the inverse transformation of cartesian2hyperspherical.
Definition: math.F90:826
subroutine, public hypersphere_grad_matrix(grad_matrix, r, x)
Gives the hyperspherical gradient matrix, which contains the derivatives of the Cartesian coordinates...
Definition: math.F90:872
recursive integer function, public factorial(n)
Definition: math.F90:280
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
static double f(double w, void *p)
int true(void)