(git:374b731)
Loading...
Searching...
No Matches
mt_util.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! **************************************************************************************************
9MODULE mt_util
10 USE bibliography, ONLY: martyna1999,&
11 cite_reference
12 USE kinds, ONLY: dp
13 USE mathconstants, ONLY: fourpi,&
14 oorootpi,&
15 pi
17 USE pw_methods, ONLY: pw_axpy,&
20 USE pw_pool_types, ONLY: pw_pool_create,&
23 USE pw_types, ONLY: pw_c1d_gs_type,&
25#include "../base/base_uses.f90"
26
27 IMPLICIT NONE
28
29 PRIVATE
30 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
31 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mt_util'
32
33 INTEGER, PARAMETER, PUBLIC :: mt2d = 1101, &
34 mt1d = 1102, &
35 mt0d = 1103
36
37 PUBLIC :: mtin_create_screen_fn
38CONTAINS
39
40! **************************************************************************************************
41!> \brief Initialize the Martyna && Tuckerman Poisson Solver
42!> \param screen_function ...
43!> \param pw_pool ...
44!> \param method ...
45!> \param alpha ...
46!> \param special_dimension ...
47!> \param slab_size ...
48!> \param super_ref_pw_grid ...
49!> \author Teodoro Laino (16.06.2004)
50! **************************************************************************************************
51 SUBROUTINE mtin_create_screen_fn(screen_function, pw_pool, method, alpha, &
52 special_dimension, slab_size, super_ref_pw_grid)
53 TYPE(pw_c1d_gs_type), POINTER :: screen_function
54 TYPE(pw_pool_type), POINTER :: pw_pool
55 INTEGER, INTENT(IN) :: method
56 REAL(kind=dp), INTENT(in) :: alpha
57 INTEGER, INTENT(IN) :: special_dimension
58 REAL(kind=dp), INTENT(in) :: slab_size
59 TYPE(pw_grid_type), POINTER :: super_ref_pw_grid
60
61 CHARACTER(len=*), PARAMETER :: routinen = 'MTin_create_screen_fn'
62
63 INTEGER :: handle, ig, iz
64 REAL(kind=dp) :: alpha2, g2, g3d, gxy, gz, zlength
65 TYPE(pw_c1d_gs_type), POINTER :: vlocg
66 TYPE(pw_pool_type), POINTER :: pw_pool_aux
67 TYPE(pw_r3d_rs_type), POINTER :: vloc
68
69 CALL timeset(routinen, handle)
70 NULLIFY (vloc, vlocg, pw_pool_aux)
71 !
72 ! For Martyna-Tuckerman we set up an auxiliary pw_pool at an higher cutoff
73 !
74 CALL cite_reference(martyna1999)
75 IF (ASSOCIATED(super_ref_pw_grid)) THEN
76 CALL pw_pool_create(pw_pool_aux, pw_grid=super_ref_pw_grid)
77 END IF
78 NULLIFY (screen_function)
79 ALLOCATE (screen_function)
80 CALL pw_pool%create_pw(screen_function)
81 CALL pw_zero(screen_function)
82 SELECT CASE (method)
83 CASE (mt0d)
84 NULLIFY (vloc, vlocg)
85 ALLOCATE (vloc, vlocg)
86 IF (ASSOCIATED(pw_pool_aux)) THEN
87 CALL pw_pool_aux%create_pw(vloc)
88 CALL pw_pool_aux%create_pw(vlocg)
89 ELSE
90 CALL pw_pool%create_pw(vloc)
91 CALL pw_pool%create_pw(vlocg)
92 END IF
93 CALL mt0din(vloc, alpha)
94 CALL pw_transfer(vloc, vlocg)
95 CALL pw_axpy(vlocg, screen_function)
96 IF (ASSOCIATED(pw_pool_aux)) THEN
97 CALL pw_pool_aux%give_back_pw(vloc)
98 CALL pw_pool_aux%give_back_pw(vlocg)
99 ELSE
100 CALL pw_pool%give_back_pw(vloc)
101 CALL pw_pool%give_back_pw(vlocg)
102 END IF
103 DEALLOCATE (vloc, vlocg)
104 !
105 ! Get rid of the analytical FT of the erf(a*r)/r
106 !
107 alpha2 = alpha*alpha
108 DO ig = screen_function%pw_grid%first_gne0, screen_function%pw_grid%ngpts_cut_local
109 g2 = screen_function%pw_grid%gsq(ig)
110 g3d = fourpi/g2
111 screen_function%array(ig) = screen_function%array(ig) - g3d*exp(-g2/(4.0e0_dp*alpha2))
112 END DO
113 IF (screen_function%pw_grid%have_g0) &
114 screen_function%array(1) = screen_function%array(1) + fourpi/(4.0e0_dp*alpha2)
115 CASE (mt2d)
116 iz = special_dimension ! iz is the direction with NO PBC
117 zlength = slab_size ! zlength is the thickness of the cell
118 DO ig = screen_function%pw_grid%first_gne0, screen_function%pw_grid%ngpts_cut_local
119 gz = screen_function%pw_grid%g(iz, ig)
120 g2 = screen_function%pw_grid%gsq(ig)
121 gxy = sqrt(abs(g2 - gz*gz))
122 g3d = fourpi/g2
123 screen_function%array(ig) = -g3d*cos(gz*zlength/2.0_dp)*exp(-gxy*zlength/2.0_dp)
124 END DO
125 IF (screen_function%pw_grid%have_g0) screen_function%array(1) = pi*zlength*zlength/2.0_dp
126 CASE (mt1d)
127 iz = special_dimension ! iz is the direction with PBC
128 CALL mt1din(screen_function)
129 cpabort("MT1D unimplemented")
130 END SELECT
131 CALL pw_pool_release(pw_pool_aux)
132 CALL timestop(handle)
133 END SUBROUTINE mtin_create_screen_fn
134
135! **************************************************************************************************
136!> \brief Calculates the Tuckerman Green's function in reciprocal space
137!> according the scheme published on:
138!> Martyna and Tuckerman, J. Chem. Phys. Vol. 110, No. 6, 2810-2821
139!> \param Vloc ...
140!> \param alpha ...
141!> \author Teodoro Laino (09.03.2005)
142! **************************************************************************************************
143 SUBROUTINE mt0din(Vloc, alpha)
144 TYPE(pw_r3d_rs_type), POINTER :: vloc
145 REAL(kind=dp), INTENT(in) :: alpha
146
147 CHARACTER(len=*), PARAMETER :: routinen = 'mt0din'
148
149 INTEGER :: handle, i, ii, j, jj, k, kk
150 INTEGER, DIMENSION(:), POINTER :: glb
151 INTEGER, DIMENSION(:, :), POINTER :: bo
152 REAL(kind=dp) :: dx, dy, dz, fact, omega, r, r2, x, y, &
153 y2, z, z2
154 REAL(kind=dp), DIMENSION(3) :: box, box2
155 TYPE(pw_grid_type), POINTER :: grid
156
157 CALL timeset(routinen, handle)
158
159 grid => vloc%pw_grid
160 bo => grid%bounds_local
161 glb => grid%bounds(1, :)
162 vloc%array = 0.0_dp
163 box = real(grid%npts, kind=dp)*grid%dr
164 box2 = box/2.0_dp
165 omega = product(box)
166 fact = omega
167 dx = grid%dr(1)
168 dy = grid%dr(2)
169 dz = grid%dr(3)
170 kk = bo(1, 3)
171 DO k = bo(1, 3), bo(2, 3)
172 z = real(k - glb(3), dp)*dz; IF (z .GT. box2(3)) z = box(3) - z
173 z2 = z*z
174 jj = bo(1, 2)
175 DO j = bo(1, 2), bo(2, 2)
176 y = real(j - glb(2), dp)*dy; IF (y .GT. box2(2)) y = box(2) - y
177 y2 = y*y
178 ii = bo(1, 1)
179 DO i = bo(1, 1), bo(2, 1)
180 x = real(i - glb(1), dp)*dx; IF (x .GT. box2(1)) x = box(1) - x
181 r2 = x*x + y2 + z2
182 r = sqrt(r2)
183 IF (r .GT. 1.0e-10_dp) THEN
184 vloc%array(ii, jj, kk) = erf(alpha*r)/r*fact
185 ELSE
186 vloc%array(ii, jj, kk) = 2.0_dp*alpha*oorootpi*fact
187 END IF
188 ii = ii + 1
189 END DO
190 jj = jj + 1
191 END DO
192 kk = kk + 1
193 END DO
194 CALL timestop(handle)
195 END SUBROUTINE mt0din
196
197! **************************************************************************************************
198!> \brief Calculates the Tuckerman Green's function in reciprocal space
199!> according the scheme published on:
200!> Martyna and Tuckerman, J. Chem. Phys. Vol. 121, No. 23, 11949
201!> \param screen_function ...
202!> \author Teodoro Laino (11.2005)
203! **************************************************************************************************
204 SUBROUTINE mt1din(screen_function)
205 TYPE(pw_c1d_gs_type), POINTER :: screen_function
206
207 CHARACTER(len=*), PARAMETER :: routinen = 'mt1din'
208
209 INTEGER :: handle
210 REAL(kind=dp) :: dx, dy, dz, omega
211 REAL(kind=dp), DIMENSION(3) :: box, box2
212 TYPE(pw_grid_type), POINTER :: grid
213
214 CALL timeset(routinen, handle)
215 grid => screen_function%pw_grid
216 box = real(grid%npts, kind=dp)*grid%dr
217 box2 = box/2.0_dp
218 omega = product(box)
219 dx = grid%dr(1)
220 dy = grid%dr(2)
221 dz = grid%dr(3)
222
223 CALL timestop(handle)
224 END SUBROUTINE mt1din
225
226END MODULE mt_util
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public martyna1999
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
real(kind=dp), parameter, public oorootpi
real(kind=dp), parameter, public pi
real(kind=dp), parameter, public fourpi
integer, parameter, public mt0d
Definition mt_util.F:33
integer, parameter, public mt2d
Definition mt_util.F:33
subroutine, public mtin_create_screen_fn(screen_function, pw_pool, method, alpha, special_dimension, slab_size, super_ref_pw_grid)
Initialize the Martyna && Tuckerman Poisson Solver.
Definition mt_util.F:53
integer, parameter, public mt1d
Definition mt_util.F:33
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
subroutine, public pw_pool_release(pool)
releases the given pool (see cp2k/doc/ReferenceCounting.html)
subroutine, public pw_pool_create(pool, pw_grid, max_cache)
creates a pool for pw
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...