forked from Infant83/VASPBAUM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_math.f90
73 lines (60 loc) · 2.45 KB
/
do_math.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "alias.inc"
module do_math
use parameters
use mykind
contains
elemental real(kind=dp) function fgauss(sigma, x)
implicit none
real(kind=dp), intent(in) :: sigma
real(kind=dp), intent(in) :: x
real(kind=dp) sigma2, xx
xx = x**2
sigma2 = sigma**2
fgauss = exp(-xx/(2d0*sigma2)) / (sigma*sqrt(pi2))
return
endfunction
elemental real(kind=dp) function florentz(sigma, x)
implicit none
real(kind=dp), intent(in) :: sigma
real(kind=dp), intent(in) :: x
real(kind=dp) sigma2, xx
! NOTE: Lorentzian (https://en.wikipedia.org/wiki/Spectral_line_shape)
! A Lorentzian line shape function can be represented as
! 1 p - p0
! L = ----------- , x = ----------
! 1 + x^2 w/2
! where L signifies a Lorentzian function standardized,
! for spectroscopic purpose, to a maximum value of 1;
! x is a subsidiary variable where p0 is the position of the
! maximum (corresponding to the transition energy E),
! p is a position, and w is the full width at half maximum (FWHM),
! the width of the curve when the intensity is half the maximum
! intensity (--> p = p0 + w/2).
! The unit of p0, p and w is typically wavenumber or frequency.
! The variable x is dimensionless and is zero at p = p0.
!
sigma2 = sigma**2
xx = x**2 / sigma2
florentz = 1d0/(1d0 + xx)/pi
return
endfunction
! Returns the inverse of a matrix calculated by finding the LU decomposition.
! http://fortranwiki.org/fortran/show/Matrix+inversion
function inv(A) result(Ainv)
implicit none
real*8, dimension(:,:), intent(in) :: A
real*8, dimension(size(A,1),size(A,2)) :: Ainv
real*8, dimension(size(A,1)) :: work ! work array for LAPACK
integer*4, dimension(size(A,1)) :: ipiv ! pipov indices
integer*4 :: n, info
external DGETRF, DGETRI ! External procedures defined in LAPACK
Ainv = A
n = size(A,1)
! DGETRF computes an LU factorization of a general M-by-N matrix A
! using partial pivoting with row interchanges.
call DGETRF(n, n, Ainv, n, ipiv, info)
! DGETRI computes the inverse of a matrix using the LU factorization
call DGETRI(n, Ainv, n, ipiv, work, n, info)
return
endfunction
endmodule