(git:b6ef100)
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-2026 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) THEN
114 screen_function%array(1) = screen_function%array(1) + fourpi/(4.0e0_dp*alpha2)
115 END IF
116 CASE (mt2d)
117 iz = special_dimension ! iz is the direction with NO PBC
118 zlength = slab_size ! zlength is the thickness of the cell
119 DO ig = screen_function%pw_grid%first_gne0, screen_function%pw_grid%ngpts_cut_local
120 gz = screen_function%pw_grid%g(iz, ig)
121 g2 = screen_function%pw_grid%gsq(ig)
122 gxy = sqrt(abs(g2 - gz*gz))
123 g3d = fourpi/g2
124 screen_function%array(ig) = -g3d*cos(gz*zlength/2.0_dp)*exp(-gxy*zlength/2.0_dp)
125 END DO
126 IF (screen_function%pw_grid%have_g0) screen_function%array(1) = pi*zlength*zlength/2.0_dp
127 CASE (mt1d)
128 iz = special_dimension ! iz is the direction with PBC
129 CALL mt1din(screen_function)
130 cpabort("MT1D unimplemented")
131 END SELECT
132 CALL pw_pool_release(pw_pool_aux)
133 CALL timestop(handle)
134 END SUBROUTINE mtin_create_screen_fn
135
136! **************************************************************************************************
137!> \brief Calculates the Tuckerman Green's function in reciprocal space
138!> according the scheme published on:
139!> Martyna and Tuckerman, J. Chem. Phys. Vol. 110, No. 6, 2810-2821
140!> \param Vloc ...
141!> \param alpha ...
142!> \author Teodoro Laino (09.03.2005)
143! **************************************************************************************************
144 SUBROUTINE mt0din(Vloc, alpha)
145 TYPE(pw_r3d_rs_type), POINTER :: vloc
146 REAL(kind=dp), INTENT(in) :: alpha
147
148 CHARACTER(len=*), PARAMETER :: routinen = 'mt0din'
149
150 INTEGER :: handle, i, ii, j, jj, k, kk
151 INTEGER, DIMENSION(:), POINTER :: glb
152 INTEGER, DIMENSION(:, :), POINTER :: bo
153 REAL(kind=dp) :: dx, dy, dz, fact, omega, r, r2, x, y, &
154 y2, z, z2
155 REAL(kind=dp), DIMENSION(3) :: box, box2
156 TYPE(pw_grid_type), POINTER :: grid
157
158 CALL timeset(routinen, handle)
159
160 grid => vloc%pw_grid
161 bo => grid%bounds_local
162 glb => grid%bounds(1, :)
163 vloc%array = 0.0_dp
164 box = real(grid%npts, kind=dp)*grid%dr
165 box2 = box/2.0_dp
166 omega = product(box)
167 fact = omega
168 dx = grid%dr(1)
169 dy = grid%dr(2)
170 dz = grid%dr(3)
171 kk = bo(1, 3)
172 DO k = bo(1, 3), bo(2, 3)
173 z = real(k - glb(3), dp)*dz; IF (z > box2(3)) z = box(3) - z
174 z2 = z*z
175 jj = bo(1, 2)
176 DO j = bo(1, 2), bo(2, 2)
177 y = real(j - glb(2), dp)*dy; IF (y > box2(2)) y = box(2) - y
178 y2 = y*y
179 ii = bo(1, 1)
180 DO i = bo(1, 1), bo(2, 1)
181 x = real(i - glb(1), dp)*dx; IF (x > box2(1)) x = box(1) - x
182 r2 = x*x + y2 + z2
183 r = sqrt(r2)
184 IF (r > 1.0e-10_dp) THEN
185 vloc%array(ii, jj, kk) = erf(alpha*r)/r*fact
186 ELSE
187 vloc%array(ii, jj, kk) = 2.0_dp*alpha*oorootpi*fact
188 END IF
189 ii = ii + 1
190 END DO
191 jj = jj + 1
192 END DO
193 kk = kk + 1
194 END DO
195 CALL timestop(handle)
196 END SUBROUTINE mt0din
197
198! **************************************************************************************************
199!> \brief Calculates the Tuckerman Green's function in reciprocal space
200!> according the scheme published on:
201!> Martyna and Tuckerman, J. Chem. Phys. Vol. 121, No. 23, 11949
202!> \param screen_function ...
203!> \author Teodoro Laino (11.2005)
204! **************************************************************************************************
205 SUBROUTINE mt1din(screen_function)
206 TYPE(pw_c1d_gs_type), POINTER :: screen_function
207
208 CHARACTER(len=*), PARAMETER :: routinen = 'mt1din'
209
210 INTEGER :: handle
211 REAL(kind=dp) :: dx, dy, dz, omega
212 REAL(kind=dp), DIMENSION(3) :: box, box2
213 TYPE(pw_grid_type), POINTER :: grid
214
215 CALL timeset(routinen, handle)
216 grid => screen_function%pw_grid
217 box = real(grid%npts, kind=dp)*grid%dr
218 box2 = box/2.0_dp
219 omega = product(box)
220 dx = grid%dr(1)
221 dy = grid%dr(2)
222 dz = grid%dr(3)
223
224 CALL timestop(handle)
225 END SUBROUTINE mt1din
226
227END 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 ...