68#include "../base/base_uses.f90"
78 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'thermal_region_utils'
98 CHARACTER(LEN=default_string_length) :: my_region
99 CHARACTER(LEN=default_string_length), &
100 DIMENSION(:),
POINTER :: tmpstringlist
101 INTEGER :: first_atom, flen, i, ikind, il, imol, &
102 ipart, ireg, itimes, last_atom, nlist, &
103 nnpart, nregions, output_unit, region
104 INTEGER,
DIMENSION(:),
POINTER :: tmplist
105 LOGICAL :: apply_thermostat, do_langevin, &
106 do_langevin_default, do_read_ngr, &
107 explicit, use_t, use_temp_tol, &
109 REAL(kind=
dp) :: temp, temp_tol
119 thermal_region_section
122 NULLIFY (logger, molecule, molecule_kind, molecule_kind_set, molecule_kinds, &
123 region_sections, t_region, tfunc_section, &
124 thermal_region_section, particles, subsys, tmplist)
127 ALLOCATE (thermal_regions)
132 apply_thermostat = (simpar%ensemble ==
nvt_ensemble) .OR. &
136 IF (apply_thermostat)
THEN
139 CALL cp_warn(__location__, &
140 "An ensemble has been chosen where one or more thermostats are "// &
141 "used to control temperature, and one or more thermal regions "// &
142 "are also defined. To ensure consistency between thermostat "// &
143 "regions and thermal regions, set THERMOSTAT/REGION to THERMAL.")
147 l_val=thermal_regions%force_rescaling)
151 IF (nregions > 0)
THEN
152 thermal_regions%nregions = nregions
153 thermal_regions%section => thermal_region_section
154 ALLOCATE (thermal_regions%thermal_region(nregions))
155 simpar%do_thermal_region = .true.
158 molecule_kinds=molecule_kinds, &
160 molecule_kind_set => molecule_kinds%els
161 molecule_set => molecules%els
163 DO ireg = 1, nregions
166 t_region => thermal_regions%thermal_region(ireg)
167 t_region%region_index = ireg
171 i_rep_section=ireg, n_rep_val=nlist)
175 i_rep_val=il, i_vals=tmplist)
176 DO i = 1,
SIZE(tmplist)
183 i_rep_section=ireg, n_rep_val=nlist)
187 i_rep_val=il, c_vals=tmpstringlist)
188 DO i = 1,
SIZE(tmpstringlist)
189 DO ikind = 1,
SIZE(molecule_kind_set)
190 molecule_kind => molecule_kind_set(ikind)
191 IF (molecule_kind%name == tmpstringlist(i))
THEN
192 DO imol = 1,
SIZE(molecule_kind%molecule_list)
193 molecule => molecule_set(molecule_kind%molecule_list(imol))
194 CALL get_molecule(molecule, first_atom=first_atom, last_atom=last_atom)
195 DO ipart = first_atom, last_atom
209 i_rep_section=ireg, n_rep_val=nlist, explicit=explicit)
211 cpabort(
"QM_SUBSYS not yet implemented for thermal regions")
214 i_rep_section=ireg, n_rep_val=nlist, explicit=explicit)
216 cpabort(
"MM_SUBSYS not yet implemented for thermal regions")
222 DO ipart = 1, particles%n_els
223 IF (particles%els(ipart)%t_region_index == ireg) nnpart = nnpart + 1
225 ALLOCATE (t_region%part_index(nnpart))
226 DO ipart = 1, particles%n_els
227 IF (particles%els(ipart)%t_region_index == ireg)
THEN
228 t_region%npart = t_region%npart + 1
229 t_region%part_index(t_region%npart) = ipart
238 t_region%temperature_function, &
239 t_region%temperature_function_parameters, &
240 t_region%temperature_function_values, &
241 input_variables=[
"S",
"T"], i_rep_sec=1)
252 i_rep_section=ireg, explicit=use_t)
255 i_rep_section=ireg, r_val=temp)
257 IF (temp > 0.0_dp)
THEN
258 t_region%temp_expected = temp
262 CALL parsef(1, trim(t_region%temperature_function), &
263 t_region%temperature_function_parameters)
265 t_region%temperature_function_values(1) = real(itimes, kind=
dp)
266 t_region%temperature_function_values(2) = 0.0_dp
271 IF (temp > 0.0_dp)
THEN
272 t_region%temp_expected = temp
274 temp = simpar%temp_ext
275 IF (temp > 0.0_dp)
THEN
276 t_region%temp_expected = temp
278 CALL cp_warn(__location__, &
279 "For thermal region "//trim(my_region)//
" , none of the "// &
280 "input values for the initial temperature, nor the result "// &
281 "of evaluating temperature function at STEP_START_VAL, is "// &
282 "positive in Kelvin. A value of zero will be used instead.")
283 t_region%temp_expected = 0.0_dp
295 i_rep_section=ireg, explicit=use_temp_tol)
296 IF (use_temp_tol)
THEN
298 i_rep_section=ireg, r_val=temp_tol)
300 IF (temp_tol > 0.0_dp)
THEN
301 t_region%temp_tol = temp_tol
303 temp_tol = simpar%temp_tol
304 IF (temp_tol > 0.0_dp)
THEN
305 t_region%temp_tol = temp_tol
307 t_region%temp_tol = 0.0_dp
319 l_val=do_langevin_default)
320 ALLOCATE (thermal_regions%do_langevin(particles%n_els))
321 thermal_regions%do_langevin = do_langevin_default
322 DO ireg = 1, nregions
324 t_region => thermal_regions%thermal_region(ireg)
327 i_rep_section=ireg, l_val=do_langevin)
328 DO ipart = 1, particles%n_els
329 IF (particles%els(ipart)%t_region_index == ireg)
THEN
330 thermal_regions%do_langevin(ipart) = do_langevin
333 CALL section_vals_val_get(region_sections,
"NOISY_GAMMA_REGION", i_rep_section=ireg, explicit=do_read_ngr)
334 IF (do_read_ngr)
THEN
336 r_val=t_region%noisy_gamma_region)
337 IF (.NOT. do_langevin)
THEN
338 CALL cp_warn(__location__, &
339 "You provided NOISY_GAMMA_REGION but atoms in thermal region "//trim(my_region)// &
340 " will not undergo Langevin MD. "// &
341 "NOISY_GAMMA_REGION will be ignored and its value discarded!")
344 t_region%noisy_gamma_region = simpar%noisy_gamma
352 IF (output_unit > 0)
THEN
353 WRITE (output_unit,
'(/,T2,A)') &
354 "THERMAL_REGION| Temperature value and function for each region [K]"
355 DO ireg = 1, nregions
357 t_region => thermal_regions%thermal_region(ireg)
358 WRITE (output_unit,
'(T2,A,T25,I3,T29,A,T34,I6,T41,A,T66,F15.6)') &
359 "THERMAL_REGION| Region", t_region%region_index, &
360 "with", t_region%npart, &
361 "particles initialized at", &
363 flen = len(trim(t_region%temperature_function))
366 WRITE (output_unit,
'(T2,A,T17,A64)') &
367 "THERMAL_REGION|", t_region%temperature_function(i:min(i + 64, flen))
370 WRITE (output_unit,
'(T2,A,T66,F15.6)') &
374 WRITE (output_unit,
'(/,T2,A)') &
375 "THERMAL_REGION| Mapping of thermal region indices to particles"
376 DO ipart = 1, particles%n_els, 16
377 WRITE (output_unit,
'(T2,A,T17,16(" ",I3))') &
378 "THERMAL_REGION|", particles%els(ipart:min(ipart + 15, particles%n_els))%t_region_index
383 DEALLOCATE (thermal_regions)
384 simpar%do_thermal_region = .false.
388 DEALLOCATE (thermal_regions)
389 simpar%do_thermal_region = .false.
405 INTEGER,
INTENT(IN) :: ipart, ireg
407 CHARACTER(LEN=default_string_length) :: my_part, my_reg, my_region
411 IF ((ipart > 0) .AND. (ipart <= particles%n_els))
THEN
413 iregion = particles%els(ipart)%t_region_index
414 IF ((iregion == 0) .OR. (iregion == ireg))
THEN
417 particles%els(ipart)%t_region_index = ireg
420 CALL cp_abort(__location__, &
421 "Atom "//trim(my_part)//
" has been "// &
422 "assigned to two different thermal "// &
423 "regions "//trim(my_region)//
" and "// &
424 trim(my_reg)//
" which is not allowed!")
427 IF (.NOT. ipart > 0)
THEN
428 CALL cp_abort(__location__, &
429 "Input atom index "//trim(my_part)//
" is non-positive!")
431 IF (.NOT. ipart <= particles%n_els)
THEN
432 CALL cp_abort(__location__, &
433 "Input atom index "//trim(my_part)//
" is out of bounds!")
455 INTEGER,
INTENT(IN) :: itimes
456 REAL(kind=
dp),
INTENT(IN) :: time
457 CHARACTER(LEN=default_string_length) :: pos, act
459 CHARACTER(LEN=default_string_length) :: fmd
460 INTEGER :: ireg, nregions, unit
462 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: temp, temp_tfunc
469 IF (
ASSOCIATED(thermal_regions))
THEN
473 extension=
".tregion", file_position=pos, &
474 file_action=act, is_new_file=new_file)
477 WRITE (unit,
'(A)')
"# Temperature per Region"
478 WRITE (unit,
'("#",3X,A,2X,A,13X,A)')
"Step Nr.",
"Time[fs]",
"Temp.[K] ...."
480 nregions = thermal_regions%nregions
481 ALLOCATE (temp(0:nregions))
482 ALLOCATE (temp_tfunc(1:nregions))
484 temp(0) = thermal_regions%temp_reg0
485 DO ireg = 1, nregions
487 temp(ireg) = thermal_regions%thermal_region(ireg)%temperature
488 temp_tfunc(ireg) =
cp_unit_from_cp2k(thermal_regions%thermal_region(ireg)%temp_expected,
"K")
490 fmd =
"(I10,F20.3,"//trim(adjustl(
cp_to_string(2*nregions + 1)))//
"F20.10)"
492 WRITE (unit=unit, fmt=fmd) itimes, time, temp(0), (temp_tfunc(ireg), temp(ireg), ireg=1, nregions)
494 DEALLOCATE (temp_tfunc)
516 CHARACTER(LEN=default_string_length) :: pos, act
518 INTEGER :: ipart, ipart_reg, ireg, natoms, &
520 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: region_id
522 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: noisy_gamma_region, temperature
529 IF (
ASSOCIATED(thermal_regions))
THEN
530 IF (
ASSOCIATED(thermal_regions%do_langevin))
THEN
532 "PRINT%LANGEVIN_REGIONS")
536 "PRINT%LANGEVIN_REGIONS", &
537 extension=
".lgv_regions", &
538 file_position=pos, file_action=act, &
539 is_new_file=new_file)
540 IF (print_unit > 0)
THEN
542 WRITE (print_unit,
'(A)')
"# Atoms Undergoing Langevin MD"
543 WRITE (print_unit,
'(A,3X,A,3X,A,3X,A,3X,A,3X,A)') &
544 "#",
"Atom_ID",
"Region_ID",
"Langevin(L)/NVE(N)",
"Expected_T[K]",
"[NoisyGamma]"
546 natoms =
SIZE(thermal_regions%do_langevin)
547 ALLOCATE (temperature(natoms))
548 ALLOCATE (region_id(natoms))
549 ALLOCATE (noisy_gamma_region(natoms))
550 temperature(:) = simpar%temp_ext
552 noisy_gamma_region(:) = simpar%noisy_gamma
553 DO ireg = 1, thermal_regions%nregions
554 DO ipart_reg = 1, thermal_regions%thermal_region(ireg)%npart
555 ipart = thermal_regions%thermal_region(ireg)%part_index(ipart_reg)
556 temperature(ipart) = thermal_regions%thermal_region(ireg)%temp_expected
557 region_id(ipart) = thermal_regions%thermal_region(ireg)%region_index
558 noisy_gamma_region(ipart) = thermal_regions%thermal_region(ireg)%noisy_gamma_region
562 WRITE (print_unit,
'(1X,I10,2X)', advance=
'no') ipart
563 WRITE (print_unit,
'(I10,3X)', advance=
'no') region_id(ipart)
564 IF (thermal_regions%do_langevin(ipart))
THEN
565 WRITE (print_unit,
'(A,3X)', advance=
'no')
"L"
566 IF (noisy_gamma_region(ipart) > 0._dp)
THEN
567 WRITE (print_unit,
'(10X,F20.3,3X,ES9.3)') temperature(ipart)*
kelvin, &
570 WRITE (print_unit,
'(10X,F20.3)') temperature(ipart)*
kelvin
573 WRITE (print_unit,
'(A,3X)', advance=
'no')
"N"
574 WRITE (print_unit,
'(18X,A)')
"--"
577 DEALLOCATE (region_id)
578 DEALLOCATE (temperature)
579 DEALLOCATE (noisy_gamma_region)
582 "PRINT%LANGEVIN_REGIONS")
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 ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
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, cell_ref, use_ref_cell)
returns information about various attributes of the given subsys
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
real(kind=dp) function, public cp_unit_to_cp2k(value, unit_str, defaults, power)
converts to the internal cp2k units to the given unit
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, ipi_env)
returns various attributes about the force environment
This public domain function parser module is intended for applications where a set of mathematical ex...
subroutine, public parsef(i, funcstr, var)
Parse ith function string FuncStr and compile it into bytecode.
real(rn) function, public evalf(i, val)
...
integer, public evalerrtype
subroutine, public finalizef()
...
subroutine, public initf(n)
...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
represent a simple array based list of the given type
Define the molecule kind structure types and the corresponding functionality.
represent a simple array based list of the given type
Define the data structure for the molecule information.
subroutine, public get_molecule(molecule, molecule_kind, lmi, lci, lg3x3, lg4x6, lcolv, first_atom, last_atom, first_shell, last_shell)
Get components from a molecule data set.
represent a simple array based list of the given type
Definition of physical constants:
real(kind=dp), parameter, public femtoseconds
real(kind=dp), parameter, public kelvin
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 set_t_region_index(particles, ipart, ireg)
set particlesels(ipart)t_region_index to ireg
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
represent a list of objects
represent a list of objects
represent a list of objects
Simulation parameter type for molecular dynamics.