(git:1f9fd2c)
Loading...
Searching...
No Matches
pint_pile.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! **************************************************************************************************
9!> \brief Methods to apply a simple Lagevin thermostat to PI runs.
10!> v_new = c1*vold + SQRT(kT/m)*c2*random
11!> \author Felix Uhl
12!> \par History
13!> 10.2014 created [Felix Uhl]
14! **************************************************************************************************
22 USE kinds, ONLY: dp
23 USE parallel_rng_types, ONLY: gaussian,&
30#include "../base/base_uses.f90"
31
32 IMPLICIT NONE
33
34 PRIVATE
35
36 PUBLIC :: pint_pile_step, &
40
41 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pint_pile'
42
43CONTAINS
44
45! ***************************************************************************
46!> \brief initializes the data for a pile run
47!> \param pile_therm ...
48!> \param pint_env ...
49!> \param normalmode_env ...
50!> \param section ...
51!> \author Felix Uhl
52! **************************************************************************************************
53 SUBROUTINE pint_pile_init(pile_therm, pint_env, normalmode_env, section)
54 TYPE(pile_therm_type), INTENT(OUT) :: pile_therm
55 TYPE(pint_env_type), INTENT(INOUT) :: pint_env
56 TYPE(normalmode_env_type), POINTER :: normalmode_env
57 TYPE(section_vals_type), POINTER :: section
58
59 CHARACTER(LEN=rng_record_length) :: rng_record
60 INTEGER :: i, i_propagator, j, p
61 LOGICAL :: explicit
62 REAL(kind=dp) :: dti2, ex
63 REAL(kind=dp), DIMENSION(3, 2) :: initial_seed
64 TYPE(section_vals_type), POINTER :: pint_section, rng_section
65
66 pint_env%e_pile = 0.0_dp
67 pile_therm%thermostat_energy = 0.0_dp
68 !Get input parameter
69 CALL section_vals_val_get(section, "TAU", r_val=pile_therm%tau)
70 CALL section_vals_val_get(section, "LAMBDA", r_val=pile_therm%lamb)
71 CALL section_vals_val_get(section, "THERMOSTAT_ENERGY", r_val=pile_therm%thermostat_energy)
72 pint_section => section_vals_get_subs_vals(pint_env%input, "MOTION%PINT")
73 CALL section_vals_val_get(pint_section, "PROPAGATOR", i_val=i_propagator)
74
75 IF (i_propagator == propagator_cmd .OR. i_propagator == propagator_bcmd) THEN
76 pile_therm%tau = 0.0_dp
77 END IF
78
79 p = pint_env%p
80 dti2 = 0.5_dp*pint_env%dt
81 ALLOCATE (pile_therm%c1(p))
82 ALLOCATE (pile_therm%c2(p))
83 ALLOCATE (pile_therm%g_fric(p))
84 ALLOCATE (pile_therm%massfact(p, pint_env%ndim))
85 !Initialize everything
86 ! If tau is negative or zero the thermostat does not act on the centroid
87 ! (TRPMD)
88 IF (pile_therm%tau <= 0.0_dp) THEN
89 pile_therm%g_fric(1) = 0.0_dp
90 ELSE
91 pile_therm%g_fric(1) = 1.0_dp/pile_therm%tau
92 END IF
93 IF (i_propagator == propagator_bcmd) THEN
94 pile_therm%c1(1) = exp(-dti2*pile_therm%g_fric(1))
95 ex = pile_therm%c1(1)*pile_therm%c1(1)
96 pile_therm%c2(1) = sqrt(1.0_dp - ex)
97 DO i = 2, p
98 pile_therm%c1(i) = 0.0_dp
99 pile_therm%c2(i) = 1.0_dp
100 END DO
101 ELSE
102 DO i = 2, p
103 pile_therm%g_fric(i) = 2.0_dp*pile_therm%lamb*sqrt(normalmode_env%lambda(i))
104 END DO
105 DO i = 1, p
106 ex = -dti2*pile_therm%g_fric(i)
107 pile_therm%c1(i) = exp(ex)
108 ex = pile_therm%c1(i)*pile_therm%c1(i)
109 pile_therm%c2(i) = sqrt(1.0_dp - ex)
110 END DO
111 END IF
112 DO j = 1, pint_env%ndim
113 DO i = 1, pint_env%p
114 pile_therm%massfact(i, j) = sqrt(pint_env%kT/pint_env%mass_fict(i, j))
115 END DO
116 END DO
117
118 !prepare Random number generator
119 NULLIFY (rng_section)
120 rng_section => section_vals_get_subs_vals(section, &
121 subsection_name="RNG_INIT")
122 CALL section_vals_get(rng_section, explicit=explicit)
123 IF (explicit) THEN
124 CALL section_vals_val_get(rng_section, "_DEFAULT_KEYWORD_", &
125 i_rep_val=1, c_val=rng_record)
126
127 pile_therm%gaussian_rng_stream = rng_stream_type_from_record(rng_record)
128 ELSE
129 initial_seed(:, :) = real(pint_env%thermostat_rng_seed, dp)
130 pile_therm%gaussian_rng_stream = rng_stream_type( &
131 name="pile_rng_gaussian", distribution_type=gaussian, &
132 extended_precision=.true., &
133 seed=initial_seed)
134 END IF
135
136 END SUBROUTINE pint_pile_init
137
138! **************************************************************************************************
139!> \brief ...
140!> \param vold ...
141!> \param vnew ...
142!> \param p ...
143!> \param ndim ...
144!> \param first_mode ...
145!> \param masses ...
146!> \param pile_therm ...
147! **************************************************************************************************
148 SUBROUTINE pint_pile_step(vold, vnew, p, ndim, first_mode, masses, pile_therm)
149 REAL(kind=dp), DIMENSION(:, :), POINTER :: vold, vnew
150 INTEGER, INTENT(IN) :: p, ndim, first_mode
151 REAL(kind=dp), DIMENSION(:, :), INTENT(IN) :: masses
152 TYPE(pile_therm_type), POINTER :: pile_therm
153
154 CHARACTER(len=*), PARAMETER :: routinen = 'pint_pile_step'
155
156 INTEGER :: handle, ibead, idim
157 REAL(kind=dp) :: delta_ekin
158
159 CALL timeset(routinen, handle)
160 delta_ekin = 0.0_dp
161 DO idim = 1, ndim
162 DO ibead = first_mode, p
163 vnew(ibead, idim) = pile_therm%c1(ibead)*vold(ibead, idim) + &
164 pile_therm%massfact(ibead, idim)*pile_therm%c2(ibead)* &
165 pile_therm%gaussian_rng_stream%next()
166 delta_ekin = delta_ekin + masses(ibead, idim)*( &
167 vnew(ibead, idim)*vnew(ibead, idim) - &
168 vold(ibead, idim)*vold(ibead, idim))
169 END DO
170 END DO
171 pile_therm%thermostat_energy = pile_therm%thermostat_energy - 0.5_dp*delta_ekin
172
173 CALL timestop(handle)
174 END SUBROUTINE pint_pile_step
175
176! ***************************************************************************
177!> \brief releases the pile environment
178!> \param pile_therm pile data to be released
179!> \author Felix Uhl
180! **************************************************************************************************
181 SUBROUTINE pint_pile_release(pile_therm)
182
183 TYPE(pile_therm_type), INTENT(INOUT) :: pile_therm
184
185 DEALLOCATE (pile_therm%c1)
186 DEALLOCATE (pile_therm%c2)
187 DEALLOCATE (pile_therm%g_fric)
188 DEALLOCATE (pile_therm%massfact)
189
190 END SUBROUTINE pint_pile_release
191
192! ***************************************************************************
193!> \brief returns the pile kinetic energy contribution
194!> \param pint_env ...
195!> \author Felix Uhl
196! **************************************************************************************************
197 SUBROUTINE pint_calc_pile_energy(pint_env)
198 TYPE(pint_env_type), INTENT(INOUT) :: pint_env
199
200 IF (ASSOCIATED(pint_env%pile_therm)) THEN
201 pint_env%e_pile = pint_env%pile_therm%thermostat_energy
202 END IF
203
204 END SUBROUTINE pint_calc_pile_energy
205END MODULE pint_pile
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public propagator_cmd
integer, parameter, public propagator_bcmd
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
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
Parallel (pseudo)random number generator (RNG) for multiple streams and substreams of random numbers.
type(rng_stream_type) function, public rng_stream_type_from_record(rng_record)
Create a RNG stream from a record given as an internal file (string).
integer, parameter, public rng_record_length
integer, parameter, public gaussian
Methods to apply a simple Lagevin thermostat to PI runs. v_new = c1*vold + SQRT(kT/m)*c2*random.
Definition pint_pile.F:15
subroutine, public pint_pile_step(vold, vnew, p, ndim, first_mode, masses, pile_therm)
...
Definition pint_pile.F:149
subroutine, public pint_pile_init(pile_therm, pint_env, normalmode_env, section)
initializes the data for a pile run
Definition pint_pile.F:54
subroutine, public pint_pile_release(pile_therm)
releases the pile environment
Definition pint_pile.F:182
subroutine, public pint_calc_pile_energy(pint_env)
returns the pile kinetic energy contribution
Definition pint_pile.F:198
data to perform the normalmode transformation
Definition pint_types.F:165
data to use the pile thermostat
Definition pint_types.F:202
environment for a path integral run
Definition pint_types.F:112