Line data Source code
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 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 :
32 : MODULE tmc_types
33 : USE cell_types, ONLY: cell_type
34 : USE kinds, ONLY: default_path_length,&
35 : default_string_length,&
36 : dp
37 : USE message_passing, ONLY: mp_para_env_release,&
38 : mp_para_env_type
39 : USE parallel_rng_types, ONLY: rng_stream_type
40 : USE tmc_move_types, ONLY: tmc_move_type
41 : USE tmc_stati, ONLY: task_type_MC
42 : USE tmc_tree_types, ONLY: clean_list,&
43 : elem_array_type,&
44 : elem_list_type,&
45 : global_tree_type
46 : #include "../base/base_uses.f90"
47 :
48 : IMPLICIT NONE
49 :
50 : PRIVATE
51 :
52 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tmc_types'
53 :
54 : PUBLIC :: tmc_env_type, tmc_comp_set_type, tmc_param_type
55 : PUBLIC :: tmc_env_create, tmc_env_release, &
56 : tmc_master_env_create, tmc_master_env_release, &
57 : tmc_worker_env_create, tmc_worker_env_release
58 : PUBLIC :: tmc_atom_type
59 : PUBLIC :: allocate_tmc_atom_type
60 :
61 : ! global environment
62 : TYPE tmc_env_type
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
74 : TYPE tmc_comp_set_type
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
90 : TYPE tmc_param_type
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 :
124 : TYPE tmc_atom_type
125 : CHARACTER(LEN=default_string_length) :: name = ""
126 : REAL(KIND=dp) :: mass = 0.0_dp
127 : END 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 :
169 : CONTAINS
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 40 : 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 40 : CALL timeset(routineN, handle)
184 :
185 40 : CPASSERT(.NOT. ASSOCIATED(tmc_env))
186 :
187 40 : ALLOCATE (tmc_env)
188 :
189 40 : ALLOCATE (tmc_env%tmc_comp_set)
190 :
191 : ! initialize the parameter section
192 40 : ALLOCATE (tmc_env%params)
193 :
194 40 : ALLOCATE (tmc_env%params%sub_box_size(tmc_env%params%dim_per_elem))
195 160 : tmc_env%params%sub_box_size(:) = -1.0_dp
196 :
197 40 : CALL timestop(handle)
198 :
199 40 : 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 40 : 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 40 : CALL timeset(routineN, handle)
214 :
215 40 : CPASSERT(ASSOCIATED(tmc_env))
216 40 : CPASSERT(ASSOCIATED(tmc_env%params))
217 :
218 40 : DEALLOCATE (tmc_env%params%sub_box_size)
219 40 : IF (ASSOCIATED(tmc_env%params%Temp)) &
220 28 : DEALLOCATE (tmc_env%params%Temp)
221 40 : IF (ASSOCIATED(tmc_env%params%cell)) &
222 34 : DEALLOCATE (tmc_env%params%cell)
223 40 : IF (ASSOCIATED(tmc_env%params%atoms)) &
224 20 : CALL deallocate_tmc_atom_type(tmc_env%params%atoms)
225 40 : DEALLOCATE (tmc_env%params)
226 :
227 40 : CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_sub_group)
228 40 : CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_m_w)
229 40 : IF (ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_first_w)) &
230 28 : CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_m_first_w)
231 40 : IF (ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_ana)) &
232 26 : CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_m_ana)
233 40 : IF (ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_only)) &
234 14 : CALL mp_para_env_release(tmc_env%tmc_comp_set%para_env_m_only)
235 :
236 40 : DEALLOCATE (tmc_env%tmc_comp_set)
237 :
238 40 : DEALLOCATE (tmc_env)
239 :
240 40 : CALL timestop(handle)
241 :
242 40 : END SUBROUTINE tmc_env_release
243 :
244 : ! **************************************************************************************************
245 : !> \brief creates a new structure environment for TMC master
246 : !> \param tmc_env structure with parameters for TMC
247 : !> \author Mandes 11.2012
248 : ! **************************************************************************************************
249 14 : SUBROUTINE tmc_master_env_create(tmc_env)
250 : TYPE(tmc_env_type), POINTER :: tmc_env
251 :
252 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tmc_master_env_create'
253 :
254 : INTEGER :: handle, i
255 :
256 14 : CALL timeset(routineN, handle)
257 :
258 14 : CPASSERT(ASSOCIATED(tmc_env))
259 14 : CPASSERT(ASSOCIATED(tmc_env%params))
260 14 : CPASSERT(tmc_env%params%nr_temp .GT. 0)
261 :
262 14 : CPASSERT(.NOT. ASSOCIATED(tmc_env%m_env))
263 :
264 70 : ALLOCATE (tmc_env%m_env)
265 14 : NULLIFY (tmc_env%m_env%gt_head, tmc_env%m_env%gt_act, tmc_env%m_env%tree_node_count, &
266 14 : tmc_env%m_env%result_count, tmc_env%m_env%result_list, &
267 14 : tmc_env%m_env%st_heads, tmc_env%m_env%st_clean_ends, &
268 14 : tmc_env%m_env%gt_clean_end, tmc_env%m_env%cancelation_list, tmc_env%m_env%analysis_list)
269 :
270 14 : tmc_env%m_env%restart_in_file_name = ""
271 14 : tmc_env%m_env%restart_out_file_name = ""
272 42 : ALLOCATE (tmc_env%m_env%tree_node_count(0:tmc_env%params%nr_temp))
273 54 : tmc_env%m_env%tree_node_count(:) = 0
274 42 : ALLOCATE (tmc_env%m_env%result_count(0:tmc_env%params%nr_temp))
275 54 : tmc_env%m_env%result_count(:) = 0
276 68 : ALLOCATE (tmc_env%m_env%st_heads(tmc_env%params%nr_temp))
277 68 : ALLOCATE (tmc_env%m_env%st_clean_ends(tmc_env%params%nr_temp))
278 :
279 68 : IF (tmc_env%params%USE_REDUCED_TREE) ALLOCATE (tmc_env%m_env%result_list(tmc_env%params%nr_temp))
280 :
281 40 : DO i = 1, tmc_env%params%nr_temp
282 26 : tmc_env%m_env%st_heads(i)%elem => NULL()
283 26 : tmc_env%m_env%st_clean_ends(i)%elem => NULL()
284 26 : IF (tmc_env%params%USE_REDUCED_TREE) &
285 40 : tmc_env%m_env%result_list(i)%elem => NULL()
286 : END DO
287 14 : tmc_env%m_env%gt_head => NULL()
288 14 : tmc_env%m_env%gt_clean_end => NULL()
289 14 : tmc_env%m_env%temp_decrease = 1.0_dp
290 14 : tmc_env%m_env%count_cancel_ener = 0
291 14 : tmc_env%m_env%count_cancel_NMC = 0
292 70 : tmc_env%m_env%estim_corr_wrong(:) = 0
293 :
294 14 : ALLOCATE (tmc_env%params%prior_NMC_acc)
295 14 : tmc_env%params%prior_NMC_acc%counter = 0
296 14 : tmc_env%params%prior_NMC_acc%aver = 0.0_dp
297 14 : tmc_env%params%prior_NMC_acc%aver_2 = 0.0_dp
298 :
299 14 : CALL timestop(handle)
300 :
301 14 : END SUBROUTINE tmc_master_env_create
302 :
303 : ! **************************************************************************************************
304 : !> \brief releases the structure environment for TMC master
305 : !> \param tmc_env structure with parameters for TMC
306 : !> \author Mandes 11.2012
307 : ! **************************************************************************************************
308 14 : SUBROUTINE tmc_master_env_release(tmc_env)
309 : TYPE(tmc_env_type), POINTER :: tmc_env
310 :
311 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tmc_master_env_release'
312 :
313 : INTEGER :: handle
314 :
315 14 : CALL timeset(routineN, handle)
316 :
317 14 : CPASSERT(ASSOCIATED(tmc_env))
318 14 : CPASSERT(ASSOCIATED(tmc_env%m_env))
319 :
320 14 : CALL clean_list(tmc_env%m_env%analysis_list)
321 14 : CALL clean_list(tmc_env%m_env%cancelation_list)
322 :
323 14 : DEALLOCATE (tmc_env%m_env%tree_node_count)
324 14 : DEALLOCATE (tmc_env%m_env%result_count)
325 14 : DEALLOCATE (tmc_env%m_env%st_heads)
326 14 : DEALLOCATE (tmc_env%m_env%st_clean_ends)
327 14 : IF (tmc_env%params%USE_REDUCED_TREE) DEALLOCATE (tmc_env%m_env%result_list)
328 14 : DEALLOCATE (tmc_env%params%prior_NMC_acc)
329 :
330 14 : DEALLOCATE (tmc_env%m_env)
331 :
332 14 : CALL timestop(handle)
333 :
334 14 : END SUBROUTINE tmc_master_env_release
335 :
336 : ! **************************************************************************************************
337 : !> \brief creates a new structure environment for TMC master
338 : !> \param tmc_env structure with parameters for TMC
339 : !> \author Mandes 11.2012
340 : ! **************************************************************************************************
341 14 : SUBROUTINE tmc_worker_env_create(tmc_env)
342 : TYPE(tmc_env_type), POINTER :: tmc_env
343 :
344 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tmc_worker_env_create'
345 :
346 : INTEGER :: handle
347 :
348 14 : CALL timeset(routineN, handle)
349 :
350 14 : CPASSERT(ASSOCIATED(tmc_env))
351 14 : CPASSERT(.NOT. ASSOCIATED(tmc_env%w_env))
352 :
353 14 : ALLOCATE (tmc_env%w_env)
354 :
355 14 : tmc_env%w_env%env_id_ener = -1
356 14 : tmc_env%w_env%env_id_approx = -1
357 14 : tmc_env%w_env%io_unit = -1
358 14 : tmc_env%w_env%act_temp = -1.0_dp
359 :
360 14 : CALL timestop(handle)
361 :
362 14 : END SUBROUTINE tmc_worker_env_create
363 :
364 : ! **************************************************************************************************
365 : !> \brief releases the structure environment for TMC master
366 : !> \param tmc_env structure with parameters for TMC
367 : !> \author Mandes 11.2012
368 : ! **************************************************************************************************
369 14 : SUBROUTINE tmc_worker_env_release(tmc_env)
370 : TYPE(tmc_env_type), POINTER :: tmc_env
371 :
372 : CHARACTER(LEN=*), PARAMETER :: routineN = 'tmc_worker_env_release'
373 :
374 : INTEGER :: handle
375 :
376 14 : CALL timeset(routineN, handle)
377 :
378 14 : CPASSERT(ASSOCIATED(tmc_env))
379 14 : CPASSERT(ASSOCIATED(tmc_env%w_env))
380 :
381 14 : DEALLOCATE (tmc_env%w_env)
382 :
383 14 : CALL timestop(handle)
384 :
385 14 : END SUBROUTINE tmc_worker_env_release
386 :
387 : ! **************************************************************************************************
388 : !> \brief creates a structure for storing the atom informations
389 : !> \param atoms pointer to a list of tmc_atoms_type
390 : !> \param nr_atoms the amount of atoms
391 : !> \author Mandes 01.2013
392 : ! **************************************************************************************************
393 34 : SUBROUTINE allocate_tmc_atom_type(atoms, nr_atoms)
394 : TYPE(tmc_atom_type), DIMENSION(:), POINTER :: atoms
395 : INTEGER, INTENT(IN) :: nr_atoms
396 :
397 34 : CPASSERT(.NOT. ASSOCIATED(atoms))
398 34 : CPASSERT(nr_atoms .GT. 0)
399 :
400 3988 : ALLOCATE (atoms(nr_atoms))
401 :
402 34 : CPASSERT(ASSOCIATED(atoms))
403 :
404 34 : END SUBROUTINE allocate_tmc_atom_type
405 :
406 : ! **************************************************************************************************
407 : !> \brief releases the structure for storing the atom informations
408 : !> \param atoms pointer to a list of tmc_atoms_type
409 : !> \author Mandes 01.2013
410 : ! **************************************************************************************************
411 20 : SUBROUTINE deallocate_tmc_atom_type(atoms)
412 : TYPE(tmc_atom_type), DIMENSION(:), POINTER :: atoms
413 :
414 20 : CPASSERT(ASSOCIATED(atoms))
415 :
416 20 : DEALLOCATE (atoms)
417 :
418 : CPASSERT(.NOT. ASSOCIATED(atoms))
419 20 : END SUBROUTINE deallocate_tmc_atom_type
420 :
421 0 : END MODULE tmc_types
|