(git:374b731)
Loading...
Searching...
No Matches
thermal_region_utils.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 Setup of regions with different temperature
10!> \par History
11!> - Added support for Langevin regions (2014/01/08, LT)
12!> - Added print subroutine for langevin regions (2014/02/04, LT)
13!> - Changed print_thermal_regions to print_thermal_regions_temperature
14!> (2014/02/04, LT)
15!> \author MI
16! **************************************************************************************************
18
19 USE bibliography, ONLY: kantorovich2008,&
21 cite_reference
25 USE cp_output_handling, ONLY: cp_p_file,&
42 USE kinds, ONLY: default_string_length,&
43 dp
46 USE physcon, ONLY: femtoseconds,&
47 kelvin
48 USE simpar_types, ONLY: simpar_type
54#include "../base/base_uses.f90"
55
56 IMPLICIT NONE
57
58 PRIVATE
59 PUBLIC :: create_thermal_regions, &
62
63 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'thermal_region_utils'
64
65CONTAINS
66
67! **************************************************************************************************
68!> \brief create thermal_regions
69!> \param thermal_regions ...
70!> \param md_section ...
71!> \param simpar ...
72!> \param force_env ...
73!> \par History
74!> - Added support for Langevin regions (2014/01/08, LT)
75!> \author
76! **************************************************************************************************
77 SUBROUTINE create_thermal_regions(thermal_regions, md_section, simpar, force_env)
78 TYPE(thermal_regions_type), POINTER :: thermal_regions
79 TYPE(section_vals_type), POINTER :: md_section
80 TYPE(simpar_type), POINTER :: simpar
81 TYPE(force_env_type), POINTER :: force_env
82
83 CHARACTER(LEN=default_string_length) :: my_region
84 INTEGER :: i, il, ipart, ireg, nlist, nregions
85 INTEGER, DIMENSION(:), POINTER :: tmplist
86 LOGICAL :: apply_thermostat, do_langevin, &
87 do_langevin_default, do_read_ngr, &
88 explicit
89 REAL(kind=dp) :: temp, temp_tol
90 TYPE(cp_subsys_type), POINTER :: subsys
91 TYPE(particle_list_type), POINTER :: particles
92 TYPE(section_vals_type), POINTER :: region_sections, thermal_region_section
93 TYPE(thermal_region_type), POINTER :: t_region
94
95 NULLIFY (region_sections, t_region, thermal_region_section, particles, subsys, tmplist)
96 ALLOCATE (thermal_regions)
97 CALL allocate_thermal_regions(thermal_regions)
98 thermal_region_section => section_vals_get_subs_vals(md_section, "THERMAL_REGION")
99 CALL section_vals_get(thermal_region_section, explicit=explicit)
100 IF (explicit) THEN
101 apply_thermostat = (simpar%ensemble == nvt_ensemble) .OR. &
102 (simpar%ensemble == npt_f_ensemble) .OR. &
103 (simpar%ensemble == npt_ia_ensemble) .OR. &
104 (simpar%ensemble == npt_i_ensemble)
105 IF (apply_thermostat) THEN
106 CALL cp_warn(__location__, &
107 "With the chosen ensemble the temperature is "// &
108 "controlled by thermostats. The definition of different thermal "// &
109 "regions might result inconsistent with the presence of thermostats.")
110 END IF
111 IF (simpar%temp_tol > 0.0_dp) THEN
112 CALL cp_warn(__location__, &
113 "Control of the global temperature by rescaling of the velocity "// &
114 "is not consistent with the presence of different thermal regions. "// &
115 "The temperature of different regions is rescaled separatedly.")
116 END IF
117 CALL section_vals_val_get(thermal_region_section, "FORCE_RESCALING", &
118 l_val=thermal_regions%force_rescaling)
119 region_sections => section_vals_get_subs_vals(thermal_region_section, &
120 "DEFINE_REGION")
121 CALL section_vals_get(region_sections, n_repetition=nregions)
122 IF (nregions > 0) THEN
123 thermal_regions%nregions = nregions
124 thermal_regions%section => thermal_region_section
125 ALLOCATE (thermal_regions%thermal_region(nregions))
126 CALL force_env_get(force_env, subsys=subsys)
127 CALL cp_subsys_get(subsys, particles=particles)
128 IF (simpar%ensemble == langevin_ensemble) THEN
129 CALL cite_reference(kantorovich2008)
130 CALL cite_reference(kantorovich2008a)
131 CALL section_vals_val_get(thermal_region_section, "DO_LANGEVIN_DEFAULT", &
132 l_val=do_langevin_default)
133 ALLOCATE (thermal_regions%do_langevin(particles%n_els))
134 thermal_regions%do_langevin = do_langevin_default
135 END IF
136 DO ireg = 1, nregions
137 NULLIFY (t_region)
138 t_region => thermal_regions%thermal_region(ireg)
139 t_region%region_index = ireg
140 CALL section_vals_val_get(region_sections, "LIST", &
141 i_rep_section=ireg, n_rep_val=nlist)
142 NULLIFY (t_region%part_index)
143 t_region%npart = 0
144 IF (simpar%ensemble == langevin_ensemble) THEN
145 CALL section_vals_val_get(region_sections, "DO_LANGEVIN", &
146 i_rep_section=ireg, l_val=do_langevin)
147 END IF
148 DO il = 1, nlist
149 CALL section_vals_val_get(region_sections, "LIST", i_rep_section=ireg, &
150 i_rep_val=il, i_vals=tmplist)
151 CALL reallocate(t_region%part_index, 1, t_region%npart + SIZE(tmplist))
152 DO i = 1, SIZE(tmplist)
153 ipart = tmplist(i)
154 cpassert(((ipart > 0) .AND. (ipart <= particles%n_els)))
155 t_region%npart = t_region%npart + 1
156 t_region%part_index(t_region%npart) = ipart
157 particles%els(ipart)%t_region_index = ireg
158 IF (simpar%ensemble == langevin_ensemble) THEN
159 thermal_regions%do_langevin(ipart) = do_langevin
160 END IF
161 END DO
162 END DO
163 CALL section_vals_val_get(region_sections, "TEMPERATURE", i_rep_section=ireg, &
164 r_val=temp)
165 t_region%temp_expected = temp
166 CALL section_vals_val_get(region_sections, "TEMP_TOL", i_rep_section=ireg, &
167 r_val=temp_tol)
168 t_region%temp_tol = temp_tol
169 CALL section_vals_val_get(region_sections, "NOISY_GAMMA_REGION", i_rep_section=ireg, explicit=do_read_ngr)
170 IF (do_read_ngr) THEN
171 CALL section_vals_val_get(region_sections, "NOISY_GAMMA_REGION", i_rep_section=ireg, &
172 r_val=t_region%noisy_gamma_region)
173 IF (simpar%ensemble == langevin_ensemble) THEN
174 IF (.NOT. do_langevin) THEN
175 CALL integer_to_string(ireg, my_region)
176 CALL cp_warn(__location__, &
177 "You provided NOISY_GAMMA_REGION but atoms in thermal region "//trim(my_region)// &
178 " will not undergo Langevin MD. "// &
179 "NOISY_GAMMA_REGION will be ignored and its value discarded!")
180 END IF
181 ELSE
182 CALL cp_warn(__location__, &
183 "You provided NOISY_GAMMA_REGION but the Langevin Ensamble is not selected "// &
184 "NOISY_GAMMA_REGION will be ignored and its value discarded!")
185 END IF
186 ELSE
187 t_region%noisy_gamma_region = simpar%noisy_gamma
188 END IF
189 END DO
190 simpar%do_thermal_region = .true.
191 ELSE
192 CALL release_thermal_regions(thermal_regions)
193 DEALLOCATE (thermal_regions)
194 simpar%do_thermal_region = .false.
195 END IF
196 ELSE
197 CALL release_thermal_regions(thermal_regions)
198 DEALLOCATE (thermal_regions)
199 simpar%do_thermal_region = .false.
200 END IF
201
202 END SUBROUTINE create_thermal_regions
203
204! **************************************************************************************************
205!> \brief print_thermal_regions_temperature
206!> \param thermal_regions : thermal regions type contains information
207!> about the regions
208!> \param itimes : iteration number of the time step
209!> \param time : simulation time of the time step
210!> \param pos : file position
211!> \param act : file action
212!> \par History
213!> - added doxygen header and changed subroutine name from
214!> print_thermal_regions to print_thermal_regions_temperature
215!> (2014/02/04, LT)
216!> \author
217! **************************************************************************************************
218 SUBROUTINE print_thermal_regions_temperature(thermal_regions, itimes, time, pos, act)
219 TYPE(thermal_regions_type), POINTER :: thermal_regions
220 INTEGER, INTENT(IN) :: itimes
221 REAL(kind=dp), INTENT(IN) :: time
222 CHARACTER(LEN=default_string_length) :: pos, act
223
224 CHARACTER(LEN=default_string_length) :: fmd
225 INTEGER :: ireg, nregions, unit
226 LOGICAL :: new_file
227 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: temp
228 TYPE(cp_logger_type), POINTER :: logger
229 TYPE(section_vals_type), POINTER :: print_key
230
231 NULLIFY (logger)
232 logger => cp_get_default_logger()
233
234 IF (ASSOCIATED(thermal_regions)) THEN
235 print_key => section_vals_get_subs_vals(thermal_regions%section, "PRINT%TEMPERATURE")
236 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
237 unit = cp_print_key_unit_nr(logger, thermal_regions%section, "PRINT%TEMPERATURE", &
238 extension=".tregion", file_position=pos, &
239 file_action=act, is_new_file=new_file)
240 IF (unit > 0) THEN
241 IF (new_file) THEN
242 WRITE (unit, '(A)') "# Temperature per Region"
243 WRITE (unit, '("#",3X,A,2X,A,13X,A)') "Step Nr.", "Time[fs]", "Temp.[K] ...."
244 END IF
245 nregions = thermal_regions%nregions
246 ALLOCATE (temp(0:nregions))
247 temp = 0.0_dp
248 temp(0) = thermal_regions%temp_reg0
249 DO ireg = 1, nregions
250 temp(ireg) = thermal_regions%thermal_region(ireg)%temperature
251 END DO
252 fmd = "(I10,F20.3,"//trim(adjustl(cp_to_string(nregions + 1)))//"F20.6)"
253 fmd = trim(fmd)
254 WRITE (unit=unit, fmt=fmd) itimes, time, temp(0:nregions)
255 DEALLOCATE (temp)
256 END IF
257 CALL cp_print_key_finished_output(unit, logger, thermal_regions%section, "PRINT%TEMPERATURE")
258 END IF
259 END IF
261
262! **************************************************************************************************
263!> \brief print out information regarding to langevin regions defined in
264!> thermal_regions section
265!> \param thermal_regions : thermal regions type containing the relevant
266!> langevin regions information
267!> \param simpar : wrapper for simulation parameters
268!> \param pos : file position
269!> \param act : file action
270!> \par History
271!> - created (2014/02/02, LT)
272!> \author Lianheng Tong [LT] (tonglianheng@gmail.com)
273! **************************************************************************************************
274 SUBROUTINE print_thermal_regions_langevin(thermal_regions, simpar, pos, act)
275 TYPE(thermal_regions_type), POINTER :: thermal_regions
276 TYPE(simpar_type), POINTER :: simpar
277 CHARACTER(LEN=default_string_length) :: pos, act
278
279 INTEGER :: ipart, ipart_reg, ireg, natoms, &
280 print_unit
281 INTEGER, ALLOCATABLE, DIMENSION(:) :: region_id
282 LOGICAL :: new_file
283 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: noisy_gamma_region, temperature
284 TYPE(cp_logger_type), POINTER :: logger
285 TYPE(section_vals_type), POINTER :: print_key
286
287 NULLIFY (logger)
288 logger => cp_get_default_logger()
289
290 IF (ASSOCIATED(thermal_regions)) THEN
291 IF (ASSOCIATED(thermal_regions%do_langevin)) THEN
292 print_key => section_vals_get_subs_vals(thermal_regions%section, &
293 "PRINT%LANGEVIN_REGIONS")
294 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), &
295 cp_p_file)) THEN
296 print_unit = cp_print_key_unit_nr(logger, thermal_regions%section, &
297 "PRINT%LANGEVIN_REGIONS", &
298 extension=".lgv_regions", &
299 file_position=pos, file_action=act, &
300 is_new_file=new_file)
301 IF (print_unit > 0) THEN
302 IF (new_file) THEN
303 WRITE (print_unit, '(A)') "# Atoms Undergoing Langevin MD"
304 WRITE (print_unit, '(A,3X,A,3X,A,3X,A,3X,A,3X,A)') &
305 "#", "Atom_ID", "Region_ID", "Langevin(L)/NVE(N)", "Expected_T[K]", "[NoisyGamma]"
306 END IF
307 natoms = SIZE(thermal_regions%do_langevin)
308 ALLOCATE (temperature(natoms))
309 ALLOCATE (region_id(natoms))
310 ALLOCATE (noisy_gamma_region(natoms))
311 temperature(:) = simpar%temp_ext
312 region_id(:) = 0
313 noisy_gamma_region(:) = simpar%noisy_gamma
314 DO ireg = 1, thermal_regions%nregions
315 DO ipart_reg = 1, thermal_regions%thermal_region(ireg)%npart
316 ipart = thermal_regions%thermal_region(ireg)%part_index(ipart_reg)
317 temperature(ipart) = thermal_regions%thermal_region(ireg)%temp_expected
318 region_id(ipart) = thermal_regions%thermal_region(ireg)%region_index
319 noisy_gamma_region(ipart) = thermal_regions%thermal_region(ireg)%noisy_gamma_region
320 END DO
321 END DO
322 DO ipart = 1, natoms
323 WRITE (print_unit, '(1X,I10,2X)', advance='no') ipart
324 WRITE (print_unit, '(I10,3X)', advance='no') region_id(ipart)
325 IF (thermal_regions%do_langevin(ipart)) THEN
326 WRITE (print_unit, '(A,3X)', advance='no') "L"
327 IF (noisy_gamma_region(ipart) > 0._dp) THEN
328 WRITE (print_unit, '(10X,F20.3,3X,ES9.3)') temperature(ipart)*kelvin, &
329 noisy_gamma_region(ipart)/femtoseconds
330 ELSE
331 WRITE (print_unit, '(10X,F20.3)') temperature(ipart)*kelvin
332 END IF
333 ELSE
334 WRITE (print_unit, '(A,3X)', advance='no') "N"
335 WRITE (print_unit, '(18X,A)') "--"
336 END IF
337 END DO
338 DEALLOCATE (region_id)
339 DEALLOCATE (temperature)
340 DEALLOCATE (noisy_gamma_region)
341 END IF
342 CALL cp_print_key_finished_output(print_unit, logger, thermal_regions%section, &
343 "PRINT%LANGEVIN_REGIONS")
344 END IF
345 END IF
346 END IF
347 END SUBROUTINE print_thermal_regions_langevin
348
349END MODULE thermal_region_utils
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public kantorovich2008
integer, save, public kantorovich2008a
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell)
returns information about various attributes of the given subsys
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env)
returns various attributes about the force environment
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public npt_i_ensemble
integer, parameter, public langevin_ensemble
integer, parameter, public npt_ia_ensemble
integer, parameter, public npt_f_ensemble
integer, parameter, public nvt_ensemble
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
integer, parameter, public default_string_length
Definition kinds.F:57
Utility routines for the memory handling.
represent a simple array based list of the given type
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public femtoseconds
Definition physcon.F:153
real(kind=dp), parameter, public kelvin
Definition physcon.F:165
Type for storing MD parameters.
Utilities for string manipulations.
subroutine, public integer_to_string(inumber, string)
Converts an integer number to a string. The WRITE statement will return an error message,...
Thermal regions type: to initialize and control the temperature of different regions.
subroutine, public release_thermal_regions(thermal_regions)
release thermal_regions
subroutine, public allocate_thermal_regions(thermal_regions)
allocate thermal_regions
Setup of regions with different temperature.
subroutine, public print_thermal_regions_langevin(thermal_regions, simpar, pos, act)
print out information regarding to langevin regions defined in thermal_regions section
subroutine, public create_thermal_regions(thermal_regions, md_section, simpar, force_env)
create thermal_regions
subroutine, public print_thermal_regions_temperature(thermal_regions, itimes, time, pos, act)
print_thermal_regions_temperature
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
wrapper to abstract the force evaluation of the various methods
Simulation parameter type for molecular dynamics.