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
168 NULLIFY (t_region%part_index)
172 i_rep_section=ireg, n_rep_val=nlist)
176 i_rep_val=il, i_vals=tmplist)
177 DO i = 1,
SIZE(tmplist)
184 i_rep_section=ireg, n_rep_val=nlist)
188 i_rep_val=il, c_vals=tmpstringlist)
189 DO i = 1,
SIZE(tmpstringlist)
190 DO ikind = 1,
SIZE(molecule_kind_set)
191 molecule_kind => molecule_kind_set(ikind)
192 IF (molecule_kind%name == tmpstringlist(i))
THEN
193 DO imol = 1,
SIZE(molecule_kind%molecule_list)
194 molecule => molecule_set(molecule_kind%molecule_list(imol))
195 CALL get_molecule(molecule, first_atom=first_atom, last_atom=last_atom)
196 DO ipart = first_atom, last_atom
210 i_rep_section=ireg, n_rep_val=nlist, explicit=explicit)
212 cpabort(
"QM_SUBSYS not yet implemented for thermal regions")
215 i_rep_section=ireg, n_rep_val=nlist, explicit=explicit)
217 cpabort(
"MM_SUBSYS not yet implemented for thermal regions")
223 DO ipart = 1, particles%n_els
224 IF (particles%els(ipart)%t_region_index == ireg) nnpart = nnpart + 1
226 ALLOCATE (t_region%part_index(nnpart))
227 DO ipart = 1, particles%n_els
228 IF (particles%els(ipart)%t_region_index == ireg)
THEN
229 t_region%npart = t_region%npart + 1
230 t_region%part_index(t_region%npart) = ipart
239 t_region%temperature_function, &
240 t_region%temperature_function_parameters, &
241 t_region%temperature_function_values, &
242 input_variables=[
"S",
"T"], i_rep_sec=1)
253 i_rep_section=ireg, explicit=use_t)
256 i_rep_section=ireg, r_val=temp)
258 IF (temp > 0.0_dp)
THEN
259 t_region%temp_expected = temp
263 CALL parsef(1, trim(t_region%temperature_function), &
264 t_region%temperature_function_parameters)
266 t_region%temperature_function_values(1) = itimes*1.0_dp
267 t_region%temperature_function_values(2) = 0.0_dp
272 IF (temp > 0.0_dp)
THEN
273 t_region%temp_expected = temp
275 temp = simpar%temp_ext
276 IF (temp > 0.0_dp)
THEN
277 t_region%temp_expected = temp
279 CALL cp_warn(__location__, &
280 "For thermal region "//trim(my_region)//
" , none of the "// &
281 "input values for the initial temperature, nor the result "// &
282 "of evaluating temperature function at STEP_START_VAL, is "// &
283 "positive in Kelvin. A value of zero will be used instead.")
284 t_region%temp_expected = 0.0_dp
296 i_rep_section=ireg, explicit=use_temp_tol)
297 IF (use_temp_tol)
THEN
299 i_rep_section=ireg, r_val=temp_tol)
301 IF (temp_tol > 0.0_dp)
THEN
302 t_region%temp_tol = temp_tol
304 temp_tol = simpar%temp_tol
305 IF (temp_tol > 0.0_dp)
THEN
306 t_region%temp_tol = temp_tol
308 t_region%temp_tol = 0.0_dp
320 l_val=do_langevin_default)
321 ALLOCATE (thermal_regions%do_langevin(particles%n_els))
322 thermal_regions%do_langevin = do_langevin_default
323 DO ireg = 1, nregions
325 t_region => thermal_regions%thermal_region(ireg)
328 i_rep_section=ireg, l_val=do_langevin)
329 DO ipart = 1, particles%n_els
330 IF (particles%els(ipart)%t_region_index == ireg)
THEN
331 thermal_regions%do_langevin(ipart) = do_langevin
334 CALL section_vals_val_get(region_sections,
"NOISY_GAMMA_REGION", i_rep_section=ireg, explicit=do_read_ngr)
335 IF (do_read_ngr)
THEN
337 r_val=t_region%noisy_gamma_region)
338 IF (.NOT. do_langevin)
THEN
339 CALL cp_warn(__location__, &
340 "You provided NOISY_GAMMA_REGION but atoms in thermal region "//trim(my_region)// &
341 " will not undergo Langevin MD. "// &
342 "NOISY_GAMMA_REGION will be ignored and its value discarded!")
345 t_region%noisy_gamma_region = simpar%noisy_gamma
353 IF (output_unit > 0)
THEN
354 WRITE (output_unit,
'(/,T2,A)') &
355 "THERMAL_REGION| Temperature value and function for each region [K]"
356 DO ireg = 1, nregions
358 t_region => thermal_regions%thermal_region(ireg)
359 WRITE (output_unit,
'(T2,A,T25,I3,T29,A,T34,I6,T41,A,T66,F15.6)') &
360 "THERMAL_REGION| Region", t_region%region_index, &
361 "with", t_region%npart, &
362 "particles initialized at", &
364 flen = len(trim(t_region%temperature_function))
367 WRITE (output_unit,
'(T2,A,T17,A64)') &
368 "THERMAL_REGION|", t_region%temperature_function(i:min(i + 64, flen))
371 WRITE (output_unit,
'(T2,A,T66,F15.6)') &
375 WRITE (output_unit,
'(/,T2,A)') &
376 "THERMAL_REGION| Mapping of thermal region indices to particles"
377 DO ipart = 1, particles%n_els, 16
378 WRITE (output_unit,
'(T2,A,T17,16(" ",I3))') &
379 "THERMAL_REGION|", particles%els(ipart:min(ipart + 15, particles%n_els))%t_region_index
384 DEALLOCATE (thermal_regions)
385 simpar%do_thermal_region = .false.
389 DEALLOCATE (thermal_regions)
390 simpar%do_thermal_region = .false.
406 INTEGER,
INTENT(IN) :: ipart, ireg
408 CHARACTER(LEN=default_string_length) :: my_part, my_reg, my_region
412 IF ((ipart > 0) .AND. (ipart <= particles%n_els))
THEN
414 iregion = particles%els(ipart)%t_region_index
415 IF ((iregion == 0) .OR. (iregion == ireg))
THEN
418 particles%els(ipart)%t_region_index = ireg
421 CALL cp_abort(__location__, &
422 "Atom "//trim(my_part)//
" has been "// &
423 "assigned to two different thermal "// &
424 "regions "//trim(my_region)//
" and "// &
425 trim(my_reg)//
" which is not allowed!")
428 IF (.NOT. ipart > 0)
THEN
429 CALL cp_abort(__location__, &
430 "Input atom index "//trim(my_part)//
" is non-positive!")
432 IF (.NOT. ipart <= particles%n_els)
THEN
433 CALL cp_abort(__location__, &
434 "Input atom index "//trim(my_part)//
" is out of bounds!")
456 INTEGER,
INTENT(IN) :: itimes
457 REAL(kind=
dp),
INTENT(IN) :: time
458 CHARACTER(LEN=default_string_length) :: pos, act
460 CHARACTER(LEN=default_string_length) :: fmd
461 INTEGER :: ireg, nregions, unit
463 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: temp, temp_tfunc
470 IF (
ASSOCIATED(thermal_regions))
THEN
474 extension=
".tregion", file_position=pos, &
475 file_action=act, is_new_file=new_file)
478 WRITE (unit,
'(A)')
"# Temperature per Region"
479 WRITE (unit,
'("#",3X,A,2X,A,13X,A)')
"Step Nr.",
"Time[fs]",
"Temp.[K] ...."
481 nregions = thermal_regions%nregions
482 ALLOCATE (temp(0:nregions))
483 ALLOCATE (temp_tfunc(1:nregions))
485 temp(0) = thermal_regions%temp_reg0
486 DO ireg = 1, nregions
488 temp(ireg) = thermal_regions%thermal_region(ireg)%temperature
489 temp_tfunc(ireg) =
cp_unit_from_cp2k(thermal_regions%thermal_region(ireg)%temp_expected,
"K")
491 fmd =
"(I10,F20.3,"//trim(adjustl(
cp_to_string(2*nregions + 1)))//
"F20.10)"
493 WRITE (unit=unit, fmt=fmd) itimes, time, temp(0), (temp_tfunc(ireg), temp(ireg), ireg=1, nregions)
495 DEALLOCATE (temp_tfunc)
517 CHARACTER(LEN=default_string_length) :: pos, act
519 INTEGER :: ipart, ipart_reg, ireg, natoms, &
521 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: region_id
523 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: noisy_gamma_region, temperature
530 IF (
ASSOCIATED(thermal_regions))
THEN
531 IF (
ASSOCIATED(thermal_regions%do_langevin))
THEN
533 "PRINT%LANGEVIN_REGIONS")
537 "PRINT%LANGEVIN_REGIONS", &
538 extension=
".lgv_regions", &
539 file_position=pos, file_action=act, &
540 is_new_file=new_file)
541 IF (print_unit > 0)
THEN
543 WRITE (print_unit,
'(A)')
"# Atoms Undergoing Langevin MD"
544 WRITE (print_unit,
'(A,3X,A,3X,A,3X,A,3X,A,3X,A)') &
545 "#",
"Atom_ID",
"Region_ID",
"Langevin(L)/NVE(N)",
"Expected_T[K]",
"[NoisyGamma]"
547 natoms =
SIZE(thermal_regions%do_langevin)
548 ALLOCATE (temperature(natoms))
549 ALLOCATE (region_id(natoms))
550 ALLOCATE (noisy_gamma_region(natoms))
551 temperature(:) = simpar%temp_ext
553 noisy_gamma_region(:) = simpar%noisy_gamma
554 DO ireg = 1, thermal_regions%nregions
555 DO ipart_reg = 1, thermal_regions%thermal_region(ireg)%npart
556 ipart = thermal_regions%thermal_region(ireg)%part_index(ipart_reg)
557 temperature(ipart) = thermal_regions%thermal_region(ireg)%temp_expected
558 region_id(ipart) = thermal_regions%thermal_region(ireg)%region_index
559 noisy_gamma_region(ipart) = thermal_regions%thermal_region(ireg)%noisy_gamma_region
563 WRITE (print_unit,
'(1X,I10,2X)', advance=
'no') ipart
564 WRITE (print_unit,
'(I10,3X)', advance=
'no') region_id(ipart)
565 IF (thermal_regions%do_langevin(ipart))
THEN
566 WRITE (print_unit,
'(A,3X)', advance=
'no')
"L"
567 IF (noisy_gamma_region(ipart) > 0._dp)
THEN
568 WRITE (print_unit,
'(10X,F20.3,3X,ES9.3)') temperature(ipart)*
kelvin, &
571 WRITE (print_unit,
'(10X,F20.3)') temperature(ipart)*
kelvin
574 WRITE (print_unit,
'(A,3X)', advance=
'no')
"N"
575 WRITE (print_unit,
'(18X,A)')
"--"
578 DEALLOCATE (region_id)
579 DEALLOCATE (temperature)
580 DEALLOCATE (noisy_gamma_region)
583 "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
subroutine, public get_generic_info(gen_section, func_name, xfunction, parameters, values, var_values, size_variables, i_rep_sec, input_variables)
Reads from the input structure all information for generic functions.
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.