(git:b279b6b)
mathconstants.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Definition of mathematical constants and functions.
10 !> \par History
11 !> Adapted for use in CP2K (JGH)
12 !> JGH (16-06-2002) : Added Gamma functions
13 !> JGH (10-08-2004) : Added Euler constant (gamma)
14 !> \author Matthias Krack
15 ! **************************************************************************************************
17 
18  USE kinds, ONLY: dp
19 
20  IMPLICIT NONE
21 
22  PRIVATE
23 
24  PUBLIC :: maxfac, pi, twopi, fourpi, rootpi, oorootpi, zero, one, &
28 
29  ! Factorial function fac
30  ! Inverse Factorial function ifac
31  ! Double factorial function dfac
32  ! Gamma functions
33  ! gamma(n) = gamma0(n) = (n - 1)!
34  ! gamma(n + 1/2) = gamma1(n) = SQRT(pi)/2^n (2n - 1)!!
35 
36  INTEGER, PARAMETER :: maxfac = 30
37  REAL(kind=dp), PARAMETER, DIMENSION(0:maxfac) :: fac = (/ &
38  0.10000000000000000000e+01_dp, 0.10000000000000000000e+01_dp, 0.20000000000000000000e+01_dp, &
39  0.60000000000000000000e+01_dp, 0.24000000000000000000e+02_dp, 0.12000000000000000000e+03_dp, &
40  0.72000000000000000000e+03_dp, 0.50400000000000000000e+04_dp, 0.40320000000000000000e+05_dp, &
41  0.36288000000000000000e+06_dp, 0.36288000000000000000e+07_dp, 0.39916800000000000000e+08_dp, &
42  0.47900160000000000000e+09_dp, 0.62270208000000000000e+10_dp, 0.87178291200000000000e+11_dp, &
43  0.13076743680000000000e+13_dp, 0.20922789888000000000e+14_dp, 0.35568742809600000000e+15_dp, &
44  0.64023737057280000000e+16_dp, 0.12164510040883200000e+18_dp, 0.24329020081766400000e+19_dp, &
45  0.51090942171709440000e+20_dp, 0.11240007277776076800e+22_dp, 0.25852016738884976640e+23_dp, &
46  0.62044840173323943936e+24_dp, 0.15511210043330985984e+26_dp, 0.40329146112660563558e+27_dp, &
47  0.10888869450418352161e+29_dp, 0.30488834461171386050e+30_dp, 0.88417619937397019545e+31_dp, &
48  0.26525285981219105864e+33_dp/)
49  REAL(kind=dp), PARAMETER, DIMENSION(0:maxfac) :: ifac = (/ &
50  0.10000000000000000000e+01_dp, 0.10000000000000000000e+01_dp, 0.50000000000000000000e+00_dp, &
51  0.16666666666666666667e+00_dp, 0.41666666666666666667e-01_dp, 0.83333333333333333333e-02_dp, &
52  0.13888888888888888889e-02_dp, 0.19841269841269841270e-03_dp, 0.24801587301587301587e-04_dp, &
53  0.27557319223985890653e-05_dp, 0.27557319223985890653e-06_dp, 0.25052108385441718775e-07_dp, &
54  0.20876756987868098979e-08_dp, 0.16059043836821614599e-09_dp, 0.11470745597729724714e-10_dp, &
55  0.76471637318198164759e-12_dp, 0.47794773323873852974e-13_dp, 0.28114572543455207632e-14_dp, &
56  0.15619206968586226462e-15_dp, 0.82206352466243297170e-17_dp, 0.41103176233121648585e-18_dp, &
57  0.19572941063391261231e-19_dp, 0.88967913924505732867e-21_dp, 0.38681701706306840377e-22_dp, &
58  0.16117375710961183490e-23_dp, 0.64469502843844733962e-25_dp, 0.24795962632247974601e-26_dp, &
59  0.91836898637955461484e-28_dp, 0.32798892370698379102e-29_dp, 0.11309962886447716932e-30_dp, &
60  0.37699876288159056439e-32_dp/)
61  REAL(kind=dp), PARAMETER, DIMENSION(-1:2*maxfac + 1) :: dfac = (/ &
62  0.10000000000000000000e+01_dp, 0.10000000000000000000e+01_dp, 0.10000000000000000000e+01_dp, &
63  0.20000000000000000000e+01_dp, 0.30000000000000000000e+01_dp, 0.80000000000000000000e+01_dp, &
64  0.15000000000000000000e+02_dp, 0.48000000000000000000e+02_dp, 0.10500000000000000000e+03_dp, &
65  0.38400000000000000000e+03_dp, 0.94500000000000000000e+03_dp, 0.38400000000000000000e+04_dp, &
66  0.10395000000000000000e+05_dp, 0.46080000000000000000e+05_dp, 0.13513500000000000000e+06_dp, &
67  0.64512000000000000000e+06_dp, 0.20270250000000000000e+07_dp, 0.10321920000000000000e+08_dp, &
68  0.34459425000000000000e+08_dp, 0.18579456000000000000e+09_dp, 0.65472907500000000000e+09_dp, &
69  0.37158912000000000000e+10_dp, 0.13749310575000000000e+11_dp, 0.81749606400000000000e+11_dp, &
70  0.31623414322500000000e+12_dp, 0.19619905536000000000e+13_dp, 0.79058535806250000000e+13_dp, &
71  0.51011754393600000000e+14_dp, 0.21345804667687500000e+15_dp, 0.14283291230208000000e+16_dp, &
72  0.61902833536293750000e+16_dp, 0.42849873690624000000e+17_dp, 0.19189878396251062500e+18_dp, &
73  0.13711959580999680000e+19_dp, 0.63326598707628506250e+19_dp, 0.46620662575398912000e+20_dp, &
74  0.22164309547669977187e+21_dp, 0.16783438527143608320e+22_dp, 0.82007945326378915594e+22_dp, &
75  0.63777066403145711616e+23_dp, 0.31983098677287777082e+24_dp, 0.25510826561258284646e+25_dp, &
76  0.13113070457687988603e+26_dp, 0.10714547155728479551e+27_dp, 0.56386202968058350995e+27_dp, &
77  0.47144007485205310027e+28_dp, 0.25373791335626257948e+29_dp, 0.21686243443194442612e+30_dp, &
78  0.11925681927744341235e+31_dp, 0.10409396852733332454e+32_dp, 0.58435841445947272053e+32_dp, &
79  0.52046984263666662269e+33_dp, 0.29802279137433108747e+34_dp, 0.27064431817106664380e+35_dp, &
80  0.15795207942839547636e+36_dp, 0.14614793181237598765e+37_dp, 0.86873643685617511998e+37_dp, &
81  0.81842841814930553085e+38_dp, 0.49517976900801981839e+39_dp, 0.47468848252659720789e+40_dp, &
82  0.29215606371473169285e+41_dp, 0.28481308951595832474e+42_dp, 0.17821519886598633264e+43_dp/)
83  REAL(kind=dp), PARAMETER, DIMENSION(0:maxfac) :: gamma0 = (/ &
84  0.00000000000000000000e+00_dp, 0.10000000000000000000e+01_dp, 0.10000000000000000000e+01_dp, &
85  0.20000000000000000000e+01_dp, 0.60000000000000000000e+01_dp, 0.24000000000000000000e+02_dp, &
86  0.12000000000000000000e+03_dp, 0.72000000000000000000e+03_dp, 0.50400000000000000000e+04_dp, &
87  0.40320000000000000000e+05_dp, 0.36288000000000000000e+06_dp, 0.36288000000000000000e+07_dp, &
88  0.39916800000000000000e+08_dp, 0.47900160000000000000e+09_dp, 0.62270208000000000000e+10_dp, &
89  0.87178291200000000000e+11_dp, 0.13076743680000000000e+13_dp, 0.20922789888000000000e+14_dp, &
90  0.35568742809600000000e+15_dp, 0.64023737057280000000e+16_dp, 0.12164510040883200000e+18_dp, &
91  0.24329020081766400000e+19_dp, 0.51090942171709440000e+20_dp, 0.11240007277776076800e+22_dp, &
92  0.25852016738884976640e+23_dp, 0.62044840173323943936e+24_dp, 0.15511210043330985984e+26_dp, &
93  0.40329146112660563558e+27_dp, 0.10888869450418352161e+29_dp, 0.30488834461171386050e+30_dp, &
94  0.88417619937397019545e+31_dp/)
95  REAL(kind=dp), PARAMETER, DIMENSION(0:maxfac) :: gamma1 = (/ &
96  0.17724538509055160273e+01_dp, 0.88622692545275801365e+00_dp, 0.13293403881791370205e+01_dp, &
97  0.33233509704478425512e+01_dp, 0.11631728396567448929e+02_dp, 0.52342777784553520181e+02_dp, &
98  0.28788527781504436100e+03_dp, 0.18712543057977883465e+04_dp, 0.14034407293483412599e+05_dp, &
99  0.11929246199460900709e+06_dp, 0.11332783889487855673e+07_dp, 0.11899423083962248457e+08_dp, &
100  0.13684336546556585726e+09_dp, 0.17105420683195732157e+10_dp, 0.23092317922314238412e+11_dp, &
101  0.33483860987355645697e+12_dp, 0.51899984530401250831e+13_dp, 0.85634974475162063871e+14_dp, &
102  0.14986120533153361177e+16_dp, 0.27724322986333718178e+17_dp, 0.54062429823350750447e+18_dp, &
103  0.11082798113786903842e+20_dp, 0.23828015944641843260e+21_dp, 0.53613035875444147334e+22_dp, &
104  0.12599063430729374624e+24_dp, 0.30867705405286967828e+25_dp, 0.78712648783481767961e+26_dp, &
105  0.20858851927622668510e+28_dp, 0.57361842800962338401e+29_dp, 0.16348125198274266444e+31_dp, &
106  0.48226969334909086011e+32_dp/)
107 
108  ! Constants related to Pi
109 
110  REAL(kind=dp), PARAMETER :: pi = 3.14159265358979323846264338_dp ! Pi
111  REAL(kind=dp), PARAMETER :: pio2 = 1.57079632679489661923132169_dp ! Pi/2
112  REAL(kind=dp), PARAMETER :: twopi = 6.28318530717958647692528677_dp ! 2*Pi
113  REAL(kind=dp), PARAMETER :: fourpi = 12.56637061435917295385057353_dp ! 4*Pi
114  REAL(kind=dp), PARAMETER :: rootpi = 1.77245385090551602729816748_dp ! SQRT(Pi)
115  REAL(kind=dp), PARAMETER :: oorootpi = 0.56418958354775628694807945_dp ! 1/SQRT(Pi)
116 
117  ! Euler's constant (Euler-Mascheroni constant)
118 
119  REAL(kind=dp), PARAMETER :: euler = 0.57721566490153286060651209_dp
120 
121  ! Trivial constants
122 
123  REAL(kind=dp), PARAMETER :: zero = 0.0_dp, &
124  half = 0.5_dp, &
125  one = 1.0_dp
126 
127  REAL(kind=dp), PARAMETER :: sqrthalf = 0.70710678118654752440084436_dp, & ! SQRT(1/2)
128  sqrt2 = 1.41421356237309504880168872_dp, & ! SQRT(2)
129  sqrt3 = 1.73205080756887729352744634_dp, & ! SQRT(3)
130  sqrt5 = 2.23606797749978969640917367_dp, & ! SQRT(5)
131  sqrt7 = 2.64575131106459059050161575_dp, & ! SQRT(7)
132  sqrt15 = 3.87298334620741688517926540_dp, & ! SQRT(15)
133  sqrt21 = 4.58257569495584000658804719_dp, & ! SQRT(21)
134  sqrt35 = 5.91607978309961604256732829_dp, & ! SQRT(35)
135  sqrt105 = 10.24695076595959838322103868_dp ! SQRT(105)
136 
137  ! Conversion factors
138 
139  REAL(kind=dp), PARAMETER :: degree = 180.0_dp/pi, & ! radians -> degree
140  radians = one/degree ! degree -> radians
141 
142  COMPLEX(KIND=dp), PARAMETER :: gaussi = (0.0_dp, 1.0_dp) ! i = SQRT(-1)
143  COMPLEX(KIND=dp), PARAMETER :: z_mone = (-1.0_dp, 0.0_dp), &
144  z_one = (1.0_dp, 0.0_dp), &
145  z_zero = (0.0_dp, 0.0_dp)
146 
147 END MODULE mathconstants
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Definition of mathematical constants and functions.
Definition: mathconstants.F:16
real(kind=dp), dimension(0:maxfac), parameter, public gamma1
Definition: mathconstants.F:95
real(kind=dp), parameter, public oorootpi
real(kind=dp), parameter, public sqrt105
complex(kind=dp), parameter, public z_mone
real(kind=dp), parameter, public sqrt5
real(kind=dp), parameter, public pi
complex(kind=dp), parameter, public z_one
real(kind=dp), parameter, public one
real(kind=dp), parameter, public degree
real(kind=dp), parameter, public euler
real(kind=dp), parameter, public radians
real(kind=dp), parameter, public sqrt7
real(kind=dp), parameter, public sqrthalf
real(kind=dp), parameter, public sqrt3
complex(kind=dp), parameter, public gaussi
real(kind=dp), dimension(-1:2 *maxfac+1), parameter, public dfac
Definition: mathconstants.F:61
real(kind=dp), parameter, public rootpi
real(kind=dp), dimension(0:maxfac), parameter, public ifac
Definition: mathconstants.F:49
real(kind=dp), parameter, public sqrt15
real(kind=dp), parameter, public sqrt35
real(kind=dp), parameter, public fourpi
real(kind=dp), parameter, public sqrt2
real(kind=dp), dimension(0:maxfac), parameter, public gamma0
Definition: mathconstants.F:83
real(kind=dp), parameter, public twopi
integer, parameter, public maxfac
Definition: mathconstants.F:36
real(kind=dp), parameter, public sqrt21
real(kind=dp), parameter, public zero
real(kind=dp), dimension(0:maxfac), parameter, public fac
Definition: mathconstants.F:37
complex(kind=dp), parameter, public z_zero