(git:d3d49ac)
Loading...
Searching...
No Matches
tmc_types.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 module handles definition of the tree nodes for the global and
10!> the subtrees binary tree
11!> parent element
12!> / \
13!> accepted (acc) / \ not accepted (nacc)
14!> / \
15!> child child
16!> / \ / \
17!>
18!> tree creation assuming acceptance (acc) AND rejectance (nacc)
19!> of configuration
20!> if configuration is accepted: new configuration (child on acc) on basis
21!> of last configuration (one level up)
22!> if configuration is rejected: child on nacc on basis of last accepted
23!> element (last element which is on acc brach of its parent element)
24!> The global tree handles all configurations of different subtrees.
25!> The structure element "conf" is an array related to the temperature
26!> (sorted) and points to the subtree elements.
27!> \par History
28!> 11.2012 created [Mandes Schoenherr]
29!> \author Mandes
30! **************************************************************************************************
31
33 USE cell_types, ONLY: cell_type
34 USE kinds, ONLY: default_path_length,&
36 dp
41 USE tmc_stati, ONLY: task_type_mc
42 USE tmc_tree_types, ONLY: clean_list,&
46#include "../base/base_uses.f90"
47
48 IMPLICIT NONE
49
50 PRIVATE
51
52 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tmc_types'
53
58 PUBLIC :: tmc_atom_type
60
61 ! global environment
63 TYPE(tmc_comp_set_type), POINTER :: tmc_comp_set => null()
64 TYPE(tmc_param_type), POINTER :: params => null()
65 TYPE(rng_stream_type), ALLOCATABLE :: rng_stream
66 TYPE(master_env_type), POINTER :: m_env => null()
67 TYPE(worker_env_type), POINTER :: w_env => null()
68 END TYPE tmc_env_type
69
70 ! structure for remembering the main values used for reordering MPI communicators
71 ! \param group_nr: the first group_ener_nr groups are for energy calculation,
72 ! then the Configurational Change groups,
73 ! the global master has group 0 and unused cores have negative group numbering
75 INTEGER :: group_ener_size = 0
76 INTEGER :: group_ener_nr = 0
77 INTEGER :: group_cc_size = 0
78 INTEGER :: group_cc_nr = 0
79 INTEGER :: group_nr = 0
80 INTEGER :: ana_on_the_fly = -1
81 ! the communicators (para_env)
82 TYPE(mp_para_env_type), POINTER :: para_env_m_w => null()
83 TYPE(mp_para_env_type), POINTER :: para_env_sub_group => null()
84 TYPE(mp_para_env_type), POINTER :: para_env_m_first_w => null()
85 TYPE(mp_para_env_type), POINTER :: para_env_m_ana => null()
86 TYPE(mp_para_env_type), POINTER :: para_env_m_only => null()
87 END TYPE tmc_comp_set_type
88
89 ! struct for TMC global variables
91 INTEGER :: task_type = task_type_mc
92 INTEGER :: dim_per_elem = 3
93 INTEGER :: nr_temp = -1
94 REAL(kind=dp), DIMENSION(:), POINTER :: temp => null()
95 TYPE(cell_type), POINTER :: cell => null()
96 REAL(kind=dp), DIMENSION(:), POINTER :: sub_box_size => null()
97 TYPE(tmc_atom_type), DIMENSION(:), POINTER :: atoms => null()
98
99 INTEGER :: nr_elem_mv = -1
100 TYPE(tmc_move_type), POINTER :: move_types => null()
101 TYPE(tmc_move_type), POINTER :: nmc_move_types => null()
102 REAL(kind=dp) :: pressure = 0.0_dp
103 LOGICAL :: v_isotropic = .false.
104 LOGICAL :: mv_cen_of_mass = .false.
105 LOGICAL :: esimate_acc_prob = .false.
106 LOGICAL :: speculative_canceling = .false.
107 LOGICAL :: use_scf_energy_info = .false.
108 LOGICAL :: use_reduced_tree = .false.
109 CHARACTER(LEN=default_path_length) :: energy_inp_file = ""
110 CHARACTER(LEN=default_path_length) :: nmc_inp_file = ""
111 LOGICAL :: draw_tree = .false.
112 CHARACTER(LEN=default_path_length) :: dot_file_name = ""
113 CHARACTER(LEN=default_path_length) :: all_conf_file_name = ""
114 LOGICAL :: print_only_diff_conf = .false.
115 LOGICAL :: print_trajectory = .false.
116 LOGICAL :: print_dipole = .false.
117 LOGICAL :: print_forces = .false.
118 LOGICAL :: print_cell = .false.
119 LOGICAL :: print_energies = .false.
120 TYPE(prior_estimate_acceptance_type), POINTER :: prior_nmc_acc => null()
121 LOGICAL :: print_test_output = .false.
122 END TYPE tmc_param_type
123
125 CHARACTER(LEN=default_string_length) :: name = ""
126 REAL(kind=dp) :: mass = 0.0_dp
127 END TYPE tmc_atom_type
128
129 ! to estimate the prior acceptance
130 TYPE prior_estimate_acceptance_type
131 INTEGER :: counter = 0
132 REAL(kind=dp) :: aver = 0.0_dp, aver_2 = 0.0_dp
133 END TYPE prior_estimate_acceptance_type
134
135 ! environments for the master
136 TYPE master_env_type
137 INTEGER :: num_mc_elem = 0! the specified number of Markov Chain elements, to be reached
138 CHARACTER(LEN=default_path_length) :: restart_in_file_name = ""
139 CHARACTER(LEN=default_path_length) :: restart_out_file_name = ""
140 INTEGER :: restart_out_step = 0
141 INTEGER :: io_unit = -1
142 INTEGER :: info_out_step_size = 0
143 REAL(kind=dp) :: walltime = 0.0_dp
144 INTEGER :: rnd_init = 0
145 REAL(kind=dp) :: temp_decrease = 0.0_dp ! for simulated annealing
146 TYPE(elem_list_type), POINTER :: cancelation_list => null()
147 INTEGER :: count_cancel_ener = 0
148 INTEGER :: count_cancel_nmc = 0
149 ! masters tree stuff
150 TYPE(global_tree_type), POINTER :: gt_head => null(), gt_act => null()
151 INTEGER, DIMENSION(:), POINTER :: tree_node_count => null()
152 INTEGER, DIMENSION(:), POINTER :: result_count => null()
153 TYPE(elem_array_type), DIMENSION(:), &
154 POINTER :: result_list => null(), &
155 st_heads => null(), &
156 st_clean_ends => null()
157 TYPE(global_tree_type), POINTER :: gt_clean_end => null()
158 INTEGER, DIMENSION(4) :: estim_corr_wrong = 0
159 TYPE(elem_list_type), POINTER :: analysis_list => null()
160 END TYPE master_env_type
161
162 ! environment for the worker
163 TYPE worker_env_type
164 INTEGER :: env_id_ener = -1, env_id_approx = -1
165 INTEGER :: io_unit = -1
166 REAL(kind=dp) :: act_temp = 0.0_dp
167 END TYPE worker_env_type
168
169CONTAINS
170
171! **************************************************************************************************
172!> \brief creates a new structure environment for TMC
173!> \param tmc_env structure with parameters for TMC
174!> \author Mandes 11.2012
175! **************************************************************************************************
176 SUBROUTINE tmc_env_create(tmc_env)
177 TYPE(tmc_env_type), POINTER :: tmc_env
178
179 CHARACTER(LEN=*), PARAMETER :: routinen = 'tmc_env_create'
180
181 INTEGER :: handle
182
183 CALL timeset(routinen, handle)
184
185 cpassert(.NOT. ASSOCIATED(tmc_env))
186
187 ALLOCATE (tmc_env)
188
189 ALLOCATE (tmc_env%tmc_comp_set)
190
191 ! initialize the parameter section
192 ALLOCATE (tmc_env%params)
193
194 ALLOCATE (tmc_env%params%sub_box_size(tmc_env%params%dim_per_elem))
195 tmc_env%params%sub_box_size(:) = -1.0_dp
196
197 CALL timestop(handle)
198
199 END SUBROUTINE tmc_env_create
200
201! **************************************************************************************************
202!> \brief releases the structure environment for TMC
203!> \param tmc_env structure with parameters for TMC
204!> \author Mandes 11.2012
205! **************************************************************************************************
206 SUBROUTINE tmc_env_release(tmc_env)
207 TYPE(tmc_env_type), POINTER :: tmc_env
208
209 CHARACTER(LEN=*), PARAMETER :: routinen = 'tmc_env_release'
210
211 INTEGER :: handle
212
213 CALL timeset(routinen, handle)
214
215 cpassert(ASSOCIATED(tmc_env))
216 cpassert(ASSOCIATED(tmc_env%params))
217
218 DEALLOCATE (tmc_env%params%sub_box_size)
219 IF (ASSOCIATED(tmc_env%params%Temp)) THEN
220 DEALLOCATE (tmc_env%params%Temp)
221 END IF
222 IF (ASSOCIATED(tmc_env%params%cell)) THEN
223 DEALLOCATE (tmc_env%params%cell)
224 END IF
225 IF (ASSOCIATED(tmc_env%params%atoms)) THEN
226 CALL deallocate_tmc_atom_type(tmc_env%params%atoms)
227 END IF
228 DEALLOCATE (tmc_env%params)
229
230 CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_sub_group)
231 CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_m_w)
232 IF (ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_first_w)) THEN
233 CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_m_first_w)
234 END IF
235 IF (ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_ana)) THEN
236 CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_m_ana)
237 END IF
238 IF (ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_only)) THEN
239 CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_m_only)
240 END IF
241
242 DEALLOCATE (tmc_env%tmc_comp_set)
243
244 DEALLOCATE (tmc_env)
245
246 CALL timestop(handle)
247
248 END SUBROUTINE tmc_env_release
249
250! **************************************************************************************************
251!> \brief creates a new structure environment for TMC master
252!> \param tmc_env structure with parameters for TMC
253!> \author Mandes 11.2012
254! **************************************************************************************************
255 SUBROUTINE tmc_master_env_create(tmc_env)
256 TYPE(tmc_env_type), POINTER :: tmc_env
257
258 CHARACTER(LEN=*), PARAMETER :: routinen = 'tmc_master_env_create'
259
260 INTEGER :: handle, i
261
262 CALL timeset(routinen, handle)
263
264 cpassert(ASSOCIATED(tmc_env))
265 cpassert(ASSOCIATED(tmc_env%params))
266 cpassert(tmc_env%params%nr_temp > 0)
267
268 cpassert(.NOT. ASSOCIATED(tmc_env%m_env))
269
270 ALLOCATE (tmc_env%m_env)
271 NULLIFY (tmc_env%m_env%gt_head, tmc_env%m_env%gt_act, tmc_env%m_env%tree_node_count, &
272 tmc_env%m_env%result_count, tmc_env%m_env%result_list, &
273 tmc_env%m_env%st_heads, tmc_env%m_env%st_clean_ends, &
274 tmc_env%m_env%gt_clean_end, tmc_env%m_env%cancelation_list, tmc_env%m_env%analysis_list)
275
276 tmc_env%m_env%restart_in_file_name = ""
277 tmc_env%m_env%restart_out_file_name = ""
278 ALLOCATE (tmc_env%m_env%tree_node_count(0:tmc_env%params%nr_temp))
279 tmc_env%m_env%tree_node_count(:) = 0
280 ALLOCATE (tmc_env%m_env%result_count(0:tmc_env%params%nr_temp))
281 tmc_env%m_env%result_count(:) = 0
282 ALLOCATE (tmc_env%m_env%st_heads(tmc_env%params%nr_temp))
283 ALLOCATE (tmc_env%m_env%st_clean_ends(tmc_env%params%nr_temp))
284
285 IF (tmc_env%params%USE_REDUCED_TREE) ALLOCATE (tmc_env%m_env%result_list(tmc_env%params%nr_temp))
286
287 DO i = 1, tmc_env%params%nr_temp
288 tmc_env%m_env%st_heads(i)%elem => null()
289 tmc_env%m_env%st_clean_ends(i)%elem => null()
290 IF (tmc_env%params%USE_REDUCED_TREE) THEN
291 tmc_env%m_env%result_list(i)%elem => null()
292 END IF
293 END DO
294 tmc_env%m_env%gt_head => null()
295 tmc_env%m_env%gt_clean_end => null()
296 tmc_env%m_env%temp_decrease = 1.0_dp
297 tmc_env%m_env%count_cancel_ener = 0
298 tmc_env%m_env%count_cancel_NMC = 0
299 tmc_env%m_env%estim_corr_wrong(:) = 0
300
301 ALLOCATE (tmc_env%params%prior_NMC_acc)
302 tmc_env%params%prior_NMC_acc%counter = 0
303 tmc_env%params%prior_NMC_acc%aver = 0.0_dp
304 tmc_env%params%prior_NMC_acc%aver_2 = 0.0_dp
305
306 CALL timestop(handle)
307
308 END SUBROUTINE tmc_master_env_create
309
310! **************************************************************************************************
311!> \brief releases the structure environment for TMC master
312!> \param tmc_env structure with parameters for TMC
313!> \author Mandes 11.2012
314! **************************************************************************************************
315 SUBROUTINE tmc_master_env_release(tmc_env)
316 TYPE(tmc_env_type), POINTER :: tmc_env
317
318 CHARACTER(LEN=*), PARAMETER :: routinen = 'tmc_master_env_release'
319
320 INTEGER :: handle
321
322 CALL timeset(routinen, handle)
323
324 cpassert(ASSOCIATED(tmc_env))
325 cpassert(ASSOCIATED(tmc_env%m_env))
326
327 CALL clean_list(tmc_env%m_env%analysis_list)
328 CALL clean_list(tmc_env%m_env%cancelation_list)
329
330 DEALLOCATE (tmc_env%m_env%tree_node_count)
331 DEALLOCATE (tmc_env%m_env%result_count)
332 DEALLOCATE (tmc_env%m_env%st_heads)
333 DEALLOCATE (tmc_env%m_env%st_clean_ends)
334 IF (tmc_env%params%USE_REDUCED_TREE) DEALLOCATE (tmc_env%m_env%result_list)
335 DEALLOCATE (tmc_env%params%prior_NMC_acc)
336
337 DEALLOCATE (tmc_env%m_env)
338
339 CALL timestop(handle)
340
341 END SUBROUTINE tmc_master_env_release
342
343! **************************************************************************************************
344!> \brief creates a new structure environment for TMC master
345!> \param tmc_env structure with parameters for TMC
346!> \author Mandes 11.2012
347! **************************************************************************************************
348 SUBROUTINE tmc_worker_env_create(tmc_env)
349 TYPE(tmc_env_type), POINTER :: tmc_env
350
351 CHARACTER(LEN=*), PARAMETER :: routinen = 'tmc_worker_env_create'
352
353 INTEGER :: handle
354
355 CALL timeset(routinen, handle)
356
357 cpassert(ASSOCIATED(tmc_env))
358 cpassert(.NOT. ASSOCIATED(tmc_env%w_env))
359
360 ALLOCATE (tmc_env%w_env)
361
362 tmc_env%w_env%env_id_ener = -1
363 tmc_env%w_env%env_id_approx = -1
364 tmc_env%w_env%io_unit = -1
365 tmc_env%w_env%act_temp = -1.0_dp
366
367 CALL timestop(handle)
368
369 END SUBROUTINE tmc_worker_env_create
370
371! **************************************************************************************************
372!> \brief releases the structure environment for TMC master
373!> \param tmc_env structure with parameters for TMC
374!> \author Mandes 11.2012
375! **************************************************************************************************
376 SUBROUTINE tmc_worker_env_release(tmc_env)
377 TYPE(tmc_env_type), POINTER :: tmc_env
378
379 CHARACTER(LEN=*), PARAMETER :: routinen = 'tmc_worker_env_release'
380
381 INTEGER :: handle
382
383 CALL timeset(routinen, handle)
384
385 cpassert(ASSOCIATED(tmc_env))
386 cpassert(ASSOCIATED(tmc_env%w_env))
387
388 DEALLOCATE (tmc_env%w_env)
389
390 CALL timestop(handle)
391
392 END SUBROUTINE tmc_worker_env_release
393
394! **************************************************************************************************
395!> \brief creates a structure for storing the atom informations
396!> \param atoms pointer to a list of tmc_atoms_type
397!> \param nr_atoms the amount of atoms
398!> \author Mandes 01.2013
399! **************************************************************************************************
400 SUBROUTINE allocate_tmc_atom_type(atoms, nr_atoms)
401 TYPE(tmc_atom_type), DIMENSION(:), POINTER :: atoms
402 INTEGER, INTENT(IN) :: nr_atoms
403
404 cpassert(.NOT. ASSOCIATED(atoms))
405 cpassert(nr_atoms > 0)
406
407 ALLOCATE (atoms(nr_atoms))
408
409 cpassert(ASSOCIATED(atoms))
410
411 END SUBROUTINE allocate_tmc_atom_type
412
413! **************************************************************************************************
414!> \brief releases the structure for storing the atom informations
415!> \param atoms pointer to a list of tmc_atoms_type
416!> \author Mandes 01.2013
417! **************************************************************************************************
418 SUBROUTINE deallocate_tmc_atom_type(atoms)
419 TYPE(tmc_atom_type), DIMENSION(:), POINTER :: atoms
420
421 cpassert(ASSOCIATED(atoms))
422
423 DEALLOCATE (atoms)
424
425 cpassert(.NOT. ASSOCIATED(atoms))
426 END SUBROUTINE deallocate_tmc_atom_type
427
428END MODULE tmc_types
Handles all functions related to the CELL.
Definition cell_types.F:15
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
integer, parameter, public default_path_length
Definition kinds.F:58
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
Parallel (pseudo)random number generator (RNG) for multiple streams and substreams of random numbers.
tree nodes creation, searching, deallocation, references etc.
tree nodes creation, searching, deallocation, references etc.
Definition tmc_stati.F:15
integer, parameter, public task_type_mc
Definition tmc_stati.F:44
module handles definition of the tree nodes for the global and the subtrees binary tree parent elemen...
subroutine, public clean_list(list)
clean a certain element element list
module handles definition of the tree nodes for the global and the subtrees binary tree parent elemen...
Definition tmc_types.F:32
subroutine, public allocate_tmc_atom_type(atoms, nr_atoms)
creates a structure for storing the atom informations
Definition tmc_types.F:401
subroutine, public tmc_env_release(tmc_env)
releases the structure environment for TMC
Definition tmc_types.F:207
subroutine, public tmc_worker_env_create(tmc_env)
creates a new structure environment for TMC master
Definition tmc_types.F:349
subroutine, public tmc_master_env_create(tmc_env)
creates a new structure environment for TMC master
Definition tmc_types.F:256
subroutine, public tmc_master_env_release(tmc_env)
releases the structure environment for TMC master
Definition tmc_types.F:316
subroutine, public tmc_worker_env_release(tmc_env)
releases the structure environment for TMC master
Definition tmc_types.F:377
subroutine, public tmc_env_create(tmc_env)
creates a new structure environment for TMC
Definition tmc_types.F:177
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
stores all the informations relevant to an mpi environment