(git:374b731)
Loading...
Searching...
No Matches
tmc_tree_types.F
Go to the documentation of this file.
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
33 USE kinds, ONLY: dp
34#include "../base/base_uses.f90"
35
36 IMPLICIT NONE
37
38 PRIVATE
39
40 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tmc_tree_types'
41
44 PUBLIC :: add_to_list, clean_list
46
47 !-- tree element status
48 INTEGER, PARAMETER, PUBLIC :: status_created = 100
49 INTEGER, PARAMETER, PUBLIC :: status_calculate_energy = 101
50 INTEGER, PARAMETER, PUBLIC :: status_calc_approx_ener = 102
51
52 INTEGER, PARAMETER, PUBLIC :: status_calculate_nmc_steps = 111
53 INTEGER, PARAMETER, PUBLIC :: status_calculate_md = 112
54 INTEGER, PARAMETER, PUBLIC :: status_calculated = 113
55
56 INTEGER, PARAMETER, PUBLIC :: status_accepted_result = 123
57 INTEGER, PARAMETER, PUBLIC :: status_accepted = 122
58 INTEGER, PARAMETER, PUBLIC :: status_rejected = 121
59 INTEGER, PARAMETER, PUBLIC :: status_rejected_result = 120
60
61 INTEGER, PARAMETER, PUBLIC :: status_cancel_nmc = 133
62 INTEGER, PARAMETER, PUBLIC :: status_cancel_ener = 132
63 INTEGER, PARAMETER, PUBLIC :: status_canceled_nmc = 131
64 INTEGER, PARAMETER, PUBLIC :: status_canceled_ener = 130
65
66 INTEGER, PARAMETER, PUBLIC :: status_deleted = 140
67 INTEGER, PARAMETER, PUBLIC :: status_deleted_result = 141
68
69 !-- dimension status (for e.g. dividing atoms in sub box)
70 INTEGER, PARAMETER, PUBLIC :: status_ok = 42
71 INTEGER, PARAMETER, PUBLIC :: status_frozen = -1
72 INTEGER, PARAMETER, PUBLIC :: status_proton_disorder = 1
73
74 !-- subtree element
76 TYPE(tree_type), POINTER :: parent => null() ! points to element one level up
77 !-- acc..accepted goes to next level (next step),
78 ! nacc..not accepted takes an alternative configutation
79 TYPE(tree_type), POINTER :: acc => null(), nacc => null()
80 !-- type of MC move (swap is handled only in global tree)
81 INTEGER :: move_type = -1
82 !-- status (e.g. calculated, MD calculation, accepted...)
83 INTEGER :: stat = status_created
84 REAL(kind=dp), DIMENSION(:), POINTER :: subbox_center => null()
85 REAL(kind=dp), DIMENSION(:), POINTER :: pos => null() ! position array
86 INTEGER, DIMENSION(:), POINTER :: mol => null() ! specifies the molecules the atoms participate
87 REAL(kind=dp), DIMENSION(:), POINTER :: vel => null() ! velocity array
88 REAL(kind=dp), DIMENSION(:), POINTER :: frc => null() ! force array
89 REAL(kind=dp), DIMENSION(:), POINTER :: dipole => null() ! dipole moments array
90 INTEGER, DIMENSION(:), POINTER :: elem_stat => null() ! status for every dimension
91 INTEGER :: nr = -1 ! tree node number
92 REAL(kind=dp), DIMENSION(3, 2, 3) :: rng_seed = 0 ! random seed for childs
93 !-- remembers which subtree number element is from
94 INTEGER :: sub_tree_nr = -1
95 !-- remembers the temperature the configurational change (NMC) is done with
96 INTEGER :: temp_created = 0
97 !-- pointer to counter of next subtree element number
98 INTEGER, POINTER :: next_elem_nr => null()
99 !-- for calculating the NPT ensamble, variable box sizes are necessary.
100 REAL(kind=dp), DIMENSION(:), POINTER :: box_scale => null()
101 REAL(kind=dp) :: potential = 0.0_dp ! potential energy
102 !-- potential energy calculated using (MD potential) cp2k input file
103 REAL(kind=dp) :: e_pot_approx = 0.0_dp
104 !-- kinetic energy (espacially for HMC, where the velocities are respected)
105 REAL(kind=dp) :: ekin = 0.0_dp
106 !-- kinetic energy before md steps (after gaussian velocity change)
107 REAL(kind=dp) :: ekin_before_md = 0.0_dp
108 !-- estimated energies are stored in loop order in this array
109 REAL(kind=dp), DIMENSION(4) :: scf_energies = 0.0_dp
110 !-- counter to get last position in the array loop
111 INTEGER :: scf_energies_count = 0
112 !-- list of global tree elements referint to that node (reference back to global tree)
113 ! if no reference exist anymore, global tree element can be deleted
114 TYPE(gt_elem_list_type), POINTER :: gt_nodes_references => null()
115 END TYPE tree_type
116
117 ! type for global tree element list in tree elements
119 TYPE(global_tree_type), POINTER :: gt_elem => null()
120 TYPE(gt_elem_list_type), POINTER :: next => null()
121 END TYPE gt_elem_list_type
122
124 TYPE(tree_type), POINTER :: elem => null()
125 TYPE(elem_list_type), POINTER :: next => null()
126 INTEGER :: temp_ind = 0
127 INTEGER :: nr = -1
128 END TYPE elem_list_type
129
130 !-- array with subtree elements
132 TYPE(tree_type), POINTER :: elem => null()
133 LOGICAL :: busy = .false.
134 LOGICAL :: canceled = .false.
135 REAL(kind=dp) :: start_time = 0.0_dp
136 END TYPE elem_array_type
137
138 !-- global tree element
140 TYPE(global_tree_type), POINTER :: parent => null() ! points to element one level up
141 !-- acc..accepted goes to next level (next step),
142 ! nacc..not accepted takes an alternative configutation
143 TYPE(global_tree_type), POINTER :: acc => null(), nacc => null()
144 !-- status (e.g. calculated, MD calculation, accepted...)
145 INTEGER :: stat = -99
146 !-- remember if configuration in node are swaped
147 LOGICAL :: swaped = .false.
148 !-- stores the index of the configuration (temperature)
149 ! which is changed
150 INTEGER :: mv_conf = -54321
151 !-- stores the index of the configuration (temp.) which should change next
152 INTEGER :: mv_next_conf = -2345
153 !-- list of pointes to subtree elements (Temp sorting)
154 TYPE(elem_array_type), DIMENSION(:), ALLOCATABLE :: conf
155 !-- remembers if last configuration is assumed to be accepted or rejected (next branc in tree);
156 ! In case of swaping, it shows if the configuration of a certain temperature is assumed
157 ! to be acc/rej (which branch is followed at the last modification of the conf of this temp.
158 !TODO store conf_n_acc in a bitshifted array to decrease the size (1Logical = 1Byte)
159 LOGICAL, DIMENSION(:), ALLOCATABLE :: conf_n_acc
160 INTEGER :: nr = 0 ! tree node number
161 REAL(kind=dp), DIMENSION(3, 2, 3) :: rng_seed = 0.0_dp ! random seed for childs
162 !-- random number for acceptance check
163 REAL(kind=dp) :: rnd_nr = 0.0_dp
164 !-- approximate probability of acceptance will be adapted while calculating the exact energy
165 REAL(kind=dp) :: prob_acc = 0.0_dp ! estimated acceptance probability
166 REAL(kind=dp) :: temp = 0.0_dp ! temperature for simulated annealing
167 END TYPE global_tree_type
168
169CONTAINS
170
171! **************************************************************************************************
172!> \brief add a certain element to the specified element list at the beginning
173!> \param elem the sub tree element, to be added
174!> \param list ...
175!> \param temp_ind ...
176!> \param nr ...
177!> \author Mandes 11.2012
178! **************************************************************************************************
179 SUBROUTINE add_to_list(elem, list, temp_ind, nr)
180 TYPE(tree_type), POINTER :: elem
181 TYPE(elem_list_type), POINTER :: list
182 INTEGER, OPTIONAL :: temp_ind, nr
183
184 TYPE(elem_list_type), POINTER :: last, list_elem_tmp
185
186 NULLIFY (list_elem_tmp, last)
187
188 cpassert(ASSOCIATED(elem))
189
190 ALLOCATE (list_elem_tmp)
191 list_elem_tmp%elem => elem
192 list_elem_tmp%next => null()
193 IF (PRESENT(temp_ind)) THEN
194 list_elem_tmp%temp_ind = temp_ind
195 ELSE
196 list_elem_tmp%temp_ind = -1
197 END IF
198
199 IF (PRESENT(nr)) THEN
200 list_elem_tmp%nr = nr
201 ELSE
202 list_elem_tmp%nr = -1
203 END IF
204
205 IF (ASSOCIATED(list) .EQV. .false.) THEN
206 list => list_elem_tmp
207 ELSE
208 last => list
209 DO WHILE (ASSOCIATED(last%next))
210 last => last%next
211 END DO
212 last%next => list_elem_tmp
213 END IF
214
215 END SUBROUTINE add_to_list
216
217! **************************************************************************************************
218!> \brief clean a certain element element list
219!> \param list ...
220!> \author Mandes 11.2012
221! **************************************************************************************************
222 SUBROUTINE clean_list(list)
223 TYPE(elem_list_type), POINTER :: list
224
225 TYPE(elem_list_type), POINTER :: list_elem_tmp
226
227 NULLIFY (list_elem_tmp)
228
229 DO WHILE (ASSOCIATED(list))
230 list_elem_tmp => list%next
231 DEALLOCATE (list)
232 list => list_elem_tmp
233 END DO
234 END SUBROUTINE clean_list
235
236! **************************************************************************************************
237!> \brief prints out the TMC sub tree structure element unformated in file
238!> \param elem ...
239!> \param io_unit ...
240!> \param
241!> \author Mandes 11.2012
242! **************************************************************************************************
243 SUBROUTINE write_subtree_elem_unformated(elem, io_unit)
244 TYPE(tree_type), POINTER :: elem
245 INTEGER :: io_unit
246
247 cpassert(ASSOCIATED(elem))
248 cpassert(io_unit .GT. 0)
249 WRITE (io_unit) elem%nr, &
250 elem%sub_tree_nr, &
251 elem%stat, &
252 elem%rng_seed, &
253 elem%move_type, &
254 elem%temp_created, &
255 elem%potential, &
256 elem%e_pot_approx, &
257 elem%ekin, &
258 elem%ekin_before_md
259 CALL write_subtree_elem_darray(elem%pos, io_unit)
260 CALL write_subtree_elem_darray(elem%vel, io_unit)
261 CALL write_subtree_elem_darray(elem%frc, io_unit)
262 CALL write_subtree_elem_darray(elem%box_scale, io_unit)
263 CALL write_subtree_elem_darray(elem%dipole, io_unit)
264 END SUBROUTINE write_subtree_elem_unformated
265
266! **************************************************************************************************
267!> \brief reads the TMC sub tree structure element unformated in file
268!> \param elem ...
269!> \param io_unit ...
270!> \param
271!> \author Mandes 11.2012
272! **************************************************************************************************
273 SUBROUTINE read_subtree_elem_unformated(elem, io_unit)
274 TYPE(tree_type), POINTER :: elem
275 INTEGER :: io_unit
276
277 cpassert(ASSOCIATED(elem))
278 cpassert(io_unit .GT. 0)
279
280 READ (io_unit) elem%nr, &
281 elem%sub_tree_nr, &
282 elem%stat, &
283 elem%rng_seed, &
284 elem%move_type, &
285 elem%temp_created, &
286 elem%potential, &
287 elem%e_pot_approx, &
288 elem%ekin, &
289 elem%ekin_before_md
290 CALL read_subtree_elem_darray(elem%pos, io_unit)
291 CALL read_subtree_elem_darray(elem%vel, io_unit)
292 CALL read_subtree_elem_darray(elem%frc, io_unit)
293 CALL read_subtree_elem_darray(elem%box_scale, io_unit)
294 CALL read_subtree_elem_darray(elem%dipole, io_unit)
295 END SUBROUTINE read_subtree_elem_unformated
296
297! **************************************************************************************************
298!> \brief ...
299!> \param array ...
300!> \param io_unit ...
301! **************************************************************************************************
302 SUBROUTINE write_subtree_elem_darray(array, io_unit)
303 REAL(kind=dp), DIMENSION(:), POINTER :: array
304 INTEGER :: io_unit
305
306 WRITE (io_unit) ASSOCIATED(array)
307 IF (ASSOCIATED(array)) THEN
308 WRITE (io_unit) SIZE(array)
309 WRITE (io_unit) array
310 END IF
311 END SUBROUTINE write_subtree_elem_darray
312
313! **************************************************************************************************
314!> \brief ...
315!> \param array ...
316!> \param io_unit ...
317! **************************************************************************************************
318 SUBROUTINE read_subtree_elem_darray(array, io_unit)
319 REAL(kind=dp), DIMENSION(:), POINTER :: array
320 INTEGER :: io_unit
321
322 INTEGER :: i_tmp
323 LOGICAL :: l_tmp
324
325 READ (io_unit) l_tmp
326 IF (l_tmp) THEN
327 READ (io_unit) i_tmp
328 IF (ASSOCIATED(array)) THEN
329 cpassert(SIZE(array) .EQ. i_tmp)
330 ELSE
331 ALLOCATE (array(i_tmp))
332 END IF
333 READ (io_unit) array
334 END IF
335 END SUBROUTINE read_subtree_elem_darray
336
337END MODULE tmc_tree_types
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Definition list.F:24
module handles definition of the tree nodes for the global and the subtrees binary tree parent elemen...
integer, parameter, public status_deleted
integer, parameter, public status_accepted
integer, parameter, public status_calculate_energy
integer, parameter, public status_calculate_md
subroutine, public add_to_list(elem, list, temp_ind, nr)
add a certain element to the specified element list at the beginning
subroutine, public read_subtree_elem_unformated(elem, io_unit)
reads the TMC sub tree structure element unformated in file
integer, parameter, public status_canceled_ener
integer, parameter, public status_proton_disorder
integer, parameter, public status_calculated
integer, parameter, public status_cancel_ener
integer, parameter, public status_cancel_nmc
integer, parameter, public status_canceled_nmc
subroutine, public clean_list(list)
clean a certain element element list
integer, parameter, public status_calc_approx_ener
integer, parameter, public status_ok
integer, parameter, public status_rejected
integer, parameter, public status_frozen
integer, parameter, public status_calculate_nmc_steps
subroutine, public write_subtree_elem_unformated(elem, io_unit)
prints out the TMC sub tree structure element unformated in file
integer, parameter, public status_accepted_result
integer, parameter, public status_deleted_result
integer, parameter, public status_created
integer, parameter, public status_rejected_result