(git:374b731)
Loading...
Searching...
No Matches
pint_normalmode.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 Data type and methods dealing with PI calcs in normal mode coords
10!> \author fawzi
11!> \par History
12!> 2006-02 created
13!> 2006-11 modified so it might actually work [hforbert]
14!> 2009-04-07 moved from pint_types module to a separate file [lwalewski]
15!> 2015-10 added alternative normal mode transformation needed by RPMD
16!> [Felix Uhl
17! **************************************************************************************************
24 USE kinds, ONLY: dp
25 USE mathconstants, ONLY: pi,&
26 twopi
28#include "../base/base_uses.f90"
29
30 IMPLICIT NONE
31 PRIVATE
32
33 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
34 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pint_normalmode'
35
36 PUBLIC :: normalmode_env_create
37 PUBLIC :: normalmode_release
39 PUBLIC :: normalmode_x2u
40 PUBLIC :: normalmode_u2x
41 PUBLIC :: normalmode_f2uf
42 PUBLIC :: normalmode_calc_uf_h
43
44CONTAINS
45
46! ***************************************************************************
47!> \brief creates the data needed for a normal mode transformation
48!> \param normalmode_env ...
49!> \param normalmode_section ...
50!> \param p ...
51!> \param kT ...
52!> \param propagator ...
53!> \author Harald Forbert
54! **************************************************************************************************
55 SUBROUTINE normalmode_env_create(normalmode_env, normalmode_section, p, kT, propagator)
56 TYPE(normalmode_env_type), INTENT(OUT) :: normalmode_env
57 TYPE(section_vals_type), POINTER :: normalmode_section
58 INTEGER, INTENT(in) :: p
59 REAL(kind=dp), INTENT(in) :: kt
60 INTEGER, INTENT(in) :: propagator
61
62 INTEGER :: i, j, k, li
63 LOGICAL :: explicit_gamma, explicit_modefactor
64 REAL(kind=dp) :: gamma_parameter, invsqrtp, pip, sqrt2p, &
65 twopip
66
67 ALLOCATE (normalmode_env%x2u(p, p))
68 ALLOCATE (normalmode_env%u2x(p, p))
69 ALLOCATE (normalmode_env%lambda(p))
70
71 normalmode_env%p = p
72
73 CALL section_vals_val_get(normalmode_section, "Q_CENTROID", &
74 r_val=normalmode_env%Q_centroid)
75 CALL section_vals_val_get(normalmode_section, "Q_BEAD", &
76 r_val=normalmode_env%Q_bead)
77 CALL section_vals_val_get(normalmode_section, "MODEFACTOR", &
78 explicit=explicit_modefactor, &
79 r_val=normalmode_env%modefactor)
80 CALL section_vals_val_get(normalmode_section, "GAMMA", &
81 r_val=gamma_parameter, &
82 explicit=explicit_gamma)
83
84 IF (explicit_modefactor .AND. explicit_gamma) THEN
85 cpabort("Both GAMMA and MODEFACTOR have been declared. Please use only one.")
86 END IF
87 IF (explicit_gamma) THEN
88 normalmode_env%modefactor = 1.0_dp/gamma_parameter**2
89 END IF
90
91 IF (propagator == propagator_cmd) THEN
92 IF (.NOT. explicit_gamma) THEN
93 cpabort("GAMMA needs to be specified with CMD PROPAGATOR")
94 END IF
95 IF (gamma_parameter <= 1.0_dp) THEN
96 cpwarn("GAMMA should be larger than 1.0 for CMD PROPAGATOR")
97 END IF
98 END IF
99
100 IF (normalmode_env%Q_centroid < 0.0_dp) THEN
101 normalmode_env%Q_centroid = -normalmode_env%Q_centroid/(kt*p)
102 END IF
103 IF (normalmode_env%Q_bead < 0.0_dp) THEN
104 normalmode_env%Q_bead = -normalmode_env%Q_bead/(kt*p)
105 END IF
106
107 !Use different normal mode transformations depending on the propagator
108 IF (propagator == propagator_pimd .OR. propagator == propagator_cmd) THEN
109
110 IF (propagator == propagator_pimd) THEN
111 normalmode_env%harm = p*kt*kt/normalmode_env%modefactor
112 ELSE IF (propagator == propagator_cmd) THEN
113 normalmode_env%harm = p*kt*kt*gamma_parameter*gamma_parameter
114 normalmode_env%modefactor = 1.0_dp/(gamma_parameter*gamma_parameter)
115 END IF
116
117 ! set up the transformation matrices
118 DO i = 1, p
119 normalmode_env%lambda(i) = 2.0_dp*(1.0_dp - cos(pi*(i/2)*2.0_dp/p))
120 DO j = 1, p
121 k = ((i/2)*(j - 1))/p
122 k = (i/2)*(j - 1) - k*p
123 li = 2*(i - 2*(i/2))*p - p
124 normalmode_env%u2x(j, i) = sqrt(2.0_dp/p)*sin(twopi*(k + 0.125_dp*li)/p)
125 END DO
126 END DO
127 normalmode_env%lambda(1) = 1.0_dp/(p*normalmode_env%modefactor)
128 DO i = 1, p
129 DO j = 1, p
130 normalmode_env%x2u(i, j) = sqrt(normalmode_env%lambda(i)* &
131 normalmode_env%modefactor)* &
132 normalmode_env%u2x(j, i)
133 END DO
134 END DO
135 DO i = 1, p
136 DO j = 1, p
137 normalmode_env%u2x(i, j) = normalmode_env%u2x(i, j)/ &
138 sqrt(normalmode_env%lambda(j)* &
139 normalmode_env%modefactor)
140 END DO
141 END DO
142 normalmode_env%lambda(:) = normalmode_env%harm
143
144 ELSE IF (propagator == propagator_rpmd) THEN
145 normalmode_env%harm = kt/normalmode_env%modefactor
146 sqrt2p = sqrt(2.0_dp/real(p, dp))
147 twopip = twopi/real(p, dp)
148 pip = pi/real(p, dp)
149 invsqrtp = 1.0_dp/sqrt(real(p, dp))
150 normalmode_env%x2u(:, :) = 0.0_dp
151 normalmode_env%x2u(1, :) = invsqrtp
152 DO j = 1, p
153 DO i = 2, p/2 + 1
154 normalmode_env%x2u(i, j) = sqrt2p*cos(twopip*(i - 1)*(j - 1))
155 END DO
156 DO i = p/2 + 2, p
157 normalmode_env%x2u(i, j) = sqrt2p*sin(twopip*(i - 1)*(j - 1))
158 END DO
159 END DO
160 IF (mod(p, 2) == 0) THEN
161 DO i = 1, p - 1, 2
162 normalmode_env%x2u(p/2 + 1, i) = invsqrtp
163 normalmode_env%x2u(p/2 + 1, i + 1) = -1.0_dp*invsqrtp
164 END DO
165 END IF
166
167 normalmode_env%u2x = transpose(normalmode_env%x2u)
168
169 ! Setting up propagator frequencies for rpmd
170 normalmode_env%lambda(1) = 0.0_dp
171 DO i = 2, p
172 normalmode_env%lambda(i) = 2.0_dp*normalmode_env%harm*sin((i - 1)*pip)
173 normalmode_env%lambda(i) = normalmode_env%lambda(i)*normalmode_env%lambda(i)
174 END DO
175 normalmode_env%harm = kt*kt
176 ELSE
177 cpabort("UNKNOWN PROPAGATOR FOR PINT SELECTED")
178 END IF
179
180 END SUBROUTINE normalmode_env_create
181
182! ***************************************************************************
183!> \brief releases the normalmode environment
184!> \param normalmode_env the normalmode_env to release
185!> \author Harald Forbert
186! **************************************************************************************************
187 PURE SUBROUTINE normalmode_release(normalmode_env)
188
189 TYPE(normalmode_env_type), INTENT(INOUT) :: normalmode_env
190
191 DEALLOCATE (normalmode_env%x2u)
192 DEALLOCATE (normalmode_env%u2x)
193 DEALLOCATE (normalmode_env%lambda)
194
195 END SUBROUTINE normalmode_release
196
197! ***************************************************************************
198!> \brief initializes the masses and fictitious masses compatible with the
199!> normal mode information
200!> \param normalmode_env the definition of the normal mode transformation
201!> \param mass *input* the masses of the particles
202!> \param mass_beads masses of the beads
203!> \param mass_fict the fictitious masses
204!> \param Q masses of the nose thermostats
205!> \author Harald Forbert
206! **************************************************************************************************
207 PURE SUBROUTINE normalmode_init_masses(normalmode_env, mass, mass_beads, mass_fict, &
208 Q)
209
210 TYPE(normalmode_env_type), INTENT(IN) :: normalmode_env
211 REAL(kind=dp), DIMENSION(:), INTENT(in) :: mass
212 REAL(kind=dp), DIMENSION(:, :), INTENT(out), &
213 OPTIONAL :: mass_beads, mass_fict
214 REAL(kind=dp), DIMENSION(:), INTENT(out), OPTIONAL :: q
215
216 INTEGER :: iat, ib
217
218 IF (PRESENT(q)) THEN
219 q = normalmode_env%Q_bead
220 q(1) = normalmode_env%Q_centroid
221 END IF
222 IF (PRESENT(mass_beads) .OR. PRESENT(mass_fict)) THEN
223 IF (PRESENT(mass_beads)) THEN
224 DO iat = 1, SIZE(mass)
225 mass_beads(1, iat) = 0.0_dp
226 DO ib = 2, normalmode_env%p
227 mass_beads(ib, iat) = mass(iat)
228 END DO
229 END DO
230 END IF
231 IF (PRESENT(mass_fict)) THEN
232 DO iat = 1, SIZE(mass)
233 DO ib = 1, normalmode_env%p
234 mass_fict(ib, iat) = mass(iat)
235 END DO
236 END DO
237 END IF
238 END IF
239
240 END SUBROUTINE normalmode_init_masses
241
242! ***************************************************************************
243!> \brief Transforms from the x into the u variables using a normal mode
244!> transformation for the positions
245!> \param normalmode_env the environment for the normal mode transformation
246!> \param ux will contain the u variable
247!> \param x the positions to transform
248!> \author Harald Forbert
249! **************************************************************************************************
250 SUBROUTINE normalmode_x2u(normalmode_env, ux, x)
251 TYPE(normalmode_env_type), INTENT(INOUT) :: normalmode_env
252 REAL(kind=dp), DIMENSION(:, :), INTENT(out) :: ux
253 REAL(kind=dp), DIMENSION(:, :), INTENT(in) :: x
254
255 CALL dgemm('N', 'N', normalmode_env%p, SIZE(x, 2), normalmode_env%p, 1.0_dp, &
256 normalmode_env%x2u(1, 1), SIZE(normalmode_env%x2u, 1), x(1, 1), SIZE(x, 1), &
257 0.0_dp, ux, SIZE(ux, 1))
258 END SUBROUTINE normalmode_x2u
259
260! ***************************************************************************
261!> \brief transform from the u variable to the x (back normal mode
262!> transformation for the positions)
263!> \param normalmode_env the environment for the normal mode transformation
264!> \param ux the u variable (positions to be backtransformed)
265!> \param x will contain the positions
266!> \author Harald Forbert
267! **************************************************************************************************
268 SUBROUTINE normalmode_u2x(normalmode_env, ux, x)
269 TYPE(normalmode_env_type), INTENT(INOUT) :: normalmode_env
270 REAL(kind=dp), DIMENSION(:, :), INTENT(in) :: ux
271 REAL(kind=dp), DIMENSION(:, :), INTENT(out) :: x
272
273 CALL dgemm('N', 'N', normalmode_env%p, SIZE(ux, 2), normalmode_env%p, 1.0_dp, &
274 normalmode_env%u2x(1, 1), SIZE(normalmode_env%u2x, 1), ux(1, 1), SIZE(ux, 1), &
275 0.0_dp, x, SIZE(x, 1))
276 END SUBROUTINE normalmode_u2x
277
278! ***************************************************************************
279!> \brief normalmode transformation for the forces
280!> \param normalmode_env the environment for the normal mode transformation
281!> \param uf will contain the forces for the transformed variables afterwards
282!> \param f the forces to transform
283!> \author Harald Forbert
284! **************************************************************************************************
285 SUBROUTINE normalmode_f2uf(normalmode_env, uf, f)
286 TYPE(normalmode_env_type), INTENT(INOUT) :: normalmode_env
287 REAL(kind=dp), DIMENSION(:, :), INTENT(out) :: uf
288 REAL(kind=dp), DIMENSION(:, :), INTENT(in) :: f
289
290 CALL dgemm('T', 'N', normalmode_env%p, SIZE(f, 2), normalmode_env%p, 1.0_dp, &
291 normalmode_env%u2x(1, 1), SIZE(normalmode_env%u2x, 1), f(1, 1), SIZE(f, 1), &
292 0.0_dp, uf, SIZE(uf, 1))
293 END SUBROUTINE normalmode_f2uf
294
295! ***************************************************************************
296!> \brief calculates the harmonic force in the normal mode basis
297!> \param normalmode_env the normal mode environment
298!> \param mass_beads the masses of the beads
299!> \param ux the positions of the beads in the staging basis
300!> \param uf_h the harmonic forces (not accelerations)
301!> \param e_h ...
302!> \author Harald Forbert
303! **************************************************************************************************
304 PURE SUBROUTINE normalmode_calc_uf_h(normalmode_env, mass_beads, ux, uf_h, e_h)
305 TYPE(normalmode_env_type), INTENT(IN) :: normalmode_env
306 REAL(kind=dp), DIMENSION(:, :), POINTER :: mass_beads, ux, uf_h
307 REAL(kind=dp), INTENT(OUT) :: e_h
308
309 INTEGER :: ibead, idim
310 REAL(kind=dp) :: f
311
312 e_h = 0.0_dp
313 DO idim = 1, SIZE(mass_beads, 2)
314
315 ! starting at 2 since the centroid is at 1 and it's mass_beads
316 ! SHOULD be zero anyways:
317
318 uf_h(1, idim) = 0.0_dp
319 DO ibead = 2, normalmode_env%p
320 f = -mass_beads(ibead, idim)*normalmode_env%lambda(ibead)*ux(ibead, idim)
321 uf_h(ibead, idim) = f
322 ! - to cancel the - in the force f.
323 e_h = e_h - 0.5_dp*ux(ibead, idim)*f
324 END DO
325
326 END DO
327 END SUBROUTINE normalmode_calc_uf_h
328
329END MODULE pint_normalmode
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public propagator_cmd
integer, parameter, public propagator_rpmd
integer, parameter, public propagator_pimd
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
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 pi
real(kind=dp), parameter, public twopi
Data type and methods dealing with PI calcs in normal mode coords.
pure subroutine, public normalmode_calc_uf_h(normalmode_env, mass_beads, ux, uf_h, e_h)
calculates the harmonic force in the normal mode basis
subroutine, public normalmode_x2u(normalmode_env, ux, x)
Transforms from the x into the u variables using a normal mode transformation for the positions.
subroutine, public normalmode_u2x(normalmode_env, ux, x)
transform from the u variable to the x (back normal mode transformation for the positions)
pure subroutine, public normalmode_release(normalmode_env)
releases the normalmode environment
subroutine, public normalmode_f2uf(normalmode_env, uf, f)
normalmode transformation for the forces
subroutine, public normalmode_env_create(normalmode_env, normalmode_section, p, kt, propagator)
creates the data needed for a normal mode transformation
pure subroutine, public normalmode_init_masses(normalmode_env, mass, mass_beads, mass_fict, q)
initializes the masses and fictitious masses compatible with the normal mode information
data to perform the normalmode transformation
Definition pint_types.F:165