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