73#include "../base/base_uses.f90"
79 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'tmc_tree_build'
98 SUBROUTINE allocate_new_global_tree_node(next_el, nr_temp)
99 TYPE(global_tree_type),
POINTER :: next_el
102 CHARACTER(LEN=*),
PARAMETER :: routineN =
'allocate_new_global_tree_node'
104 INTEGER :: handle, itmp
106 cpassert(.NOT.
ASSOCIATED(next_el))
109 CALL timeset(routinen, handle)
113 ALLOCATE (next_el%conf(nr_temp))
114 ALLOCATE (next_el%conf_n_acc(nr_temp))
115 next_el%rnd_nr = -1.0_dp
118 NULLIFY (next_el%conf(itmp)%elem)
119 next_el%conf_n_acc(itmp) = .false.
122 next_el%swaped = .false.
124 CALL timestop(handle)
125 END SUBROUTINE allocate_new_global_tree_node
132 SUBROUTINE deallocate_global_tree_node(gt_elem)
133 TYPE(global_tree_type),
POINTER :: gt_elem
135 CHARACTER(LEN=*),
PARAMETER :: routineN =
'deallocate_global_tree_node'
139 cpassert(
ASSOCIATED(gt_elem))
142 CALL timeset(routinen, handle)
145 DEALLOCATE (gt_elem%conf_n_acc)
146 DEALLOCATE (gt_elem%conf)
149 CALL timestop(handle)
150 END SUBROUTINE deallocate_global_tree_node
164 CHARACTER(LEN=*),
PARAMETER :: routinen =
'allocate_new_sub_tree_node'
168 cpassert(.NOT.
ASSOCIATED(next_el))
171 CALL timeset(routinen, handle)
174 NULLIFY (next_el%subbox_center, next_el%pos, next_el%mol, next_el%vel, &
175 next_el%frc, next_el%dipole, next_el%elem_stat, &
176 next_el%gt_nodes_references)
178 next_el%scf_energies(:) = huge(next_el%scf_energies)
179 next_el%scf_energies_count = 0
180 ALLOCATE (next_el%pos(nr_dim))
181 ALLOCATE (next_el%mol(nr_dim/tmc_params%dim_per_elem))
182 ALLOCATE (next_el%vel(nr_dim))
183 IF (tmc_params%print_dipole)
ALLOCATE (next_el%dipole(tmc_params%dim_per_elem))
184 ALLOCATE (next_el%elem_stat(nr_dim))
186 ALLOCATE (next_el%subbox_center(tmc_params%dim_per_elem))
189 ALLOCATE (next_el%frc(nr_dim*nr_dim))
191 ALLOCATE (next_el%frc(nr_dim))
195 ALLOCATE (next_el%box_scale(3))
196 next_el%pos(:) = -1.0_dp
198 next_el%box_scale(:) = 1.0_dp
199 next_el%scf_energies(:) = 0.0_dp
200 next_el%e_pot_approx = 0.0_dp
201 next_el%potential = 76543.0_dp
203 next_el%ekin = 0.0_dp
204 next_el%ekin_before_md = 0.0_dp
205 next_el%sub_tree_nr = 0
207 next_el%rng_seed(:, :, :) = -1.0_dp
211 CALL timestop(handle)
222 CHARACTER(LEN=*),
PARAMETER :: routinen =
'deallocate_sub_tree_node'
226 cpassert(
ASSOCIATED(tree_elem))
229 CALL timeset(routinen, handle)
236 IF (
ASSOCIATED(tree_elem%box_scale))
DEALLOCATE (tree_elem%box_scale)
237 IF (
ASSOCIATED(tree_elem%frc))
DEALLOCATE (tree_elem%frc)
238 IF (
ASSOCIATED(tree_elem%subbox_center))
DEALLOCATE (tree_elem%subbox_center)
239 IF (
ASSOCIATED(tree_elem%elem_stat))
DEALLOCATE (tree_elem%elem_stat)
240 IF (
ASSOCIATED(tree_elem%dipole))
DEALLOCATE (tree_elem%dipole)
241 IF (
ASSOCIATED(tree_elem%vel))
DEALLOCATE (tree_elem%vel)
242 IF (
ASSOCIATED(tree_elem%mol))
DEALLOCATE (tree_elem%mol)
243 IF (
ASSOCIATED(tree_elem%pos))
DEALLOCATE (tree_elem%pos)
245 DEALLOCATE (tree_elem)
247 CALL timestop(handle)
265 INTEGER,
DIMENSION(:) :: job_counts
266 REAL(kind=
dp),
DIMENSION(4) :: worker_timings
268 CHARACTER(LEN=*),
PARAMETER :: routinen =
'init_tree_mod'
273 NULLIFY (global_tree)
275 cpassert(
ASSOCIATED(start_elem))
276 cpassert(
ASSOCIATED(tmc_env))
277 cpassert(
ASSOCIATED(tmc_env%m_env))
280 CALL timeset(routinen, handle)
283 CALL allocate_new_global_tree_node(next_el=tmc_env%m_env%gt_act, &
284 nr_temp=tmc_env%params%nr_temp)
287 CALL tmc_env%rng_stream%get( &
288 bg=tmc_env%m_env%gt_act%rng_seed(:, :, 1), &
289 cg=tmc_env%m_env%gt_act%rng_seed(:, :, 2), &
290 ig=tmc_env%m_env%gt_act%rng_seed(:, :, 3))
292 global_tree => tmc_env%m_env%gt_act
293 tmc_env%m_env%gt_head => tmc_env%m_env%gt_act
296 CALL tmc_env%rng_stream%set(bg=global_tree%rng_seed(:, :, 1), &
297 cg=global_tree%rng_seed(:, :, 2), &
298 ig=global_tree%rng_seed(:, :, 3))
299 global_tree%rnd_nr = tmc_env%rng_stream%next()
302 DO i = 1,
SIZE(global_tree%conf)
304 nr_dim=
SIZE(start_elem%pos))
305 global_tree%conf(i)%elem%move_type = 0
306 global_tree%conf(i)%elem%next_elem_nr => tmc_env%m_env%tree_node_count(i)
307 global_tree%conf(i)%elem%parent => null()
308 global_tree%conf(i)%elem%nr = global_tree%conf(i)%elem%next_elem_nr
309 global_tree%conf(i)%elem%sub_tree_nr = i
310 global_tree%conf(i)%elem%elem_stat =
status_ok
311 global_tree%conf(i)%elem%pos = start_elem%pos
312 global_tree%conf(i)%elem%mol = start_elem%mol
313 global_tree%conf(i)%elem%e_pot_approx = start_elem%e_pot_approx
314 global_tree%conf(i)%elem%temp_created = i
318 global_tree%conf(i)%elem%vel(:) = start_elem%vel(:)
319 global_tree%conf(i)%elem%frc(:) = start_elem%frc(:)
320 global_tree%conf(i)%elem%potential = start_elem%potential
321 global_tree%conf(i)%elem%ekin = start_elem%ekin
322 global_tree%conf(i)%elem%ekin_before_md = start_elem%ekin_before_md
326 CALL tmc_env%rng_stream%reset_to_next_substream()
327 CALL tmc_env%rng_stream%get(bg=global_tree%conf(i)%elem%rng_seed(:, :, 1), &
328 cg=global_tree%conf(i)%elem%rng_seed(:, :, 2), &
329 ig=global_tree%conf(i)%elem%rng_seed(:, :, 3))
334 IF (tmc_env%params%move_types%mv_weight(
mv_type_md) > 0.0_dp)
THEN
335 CALL init_vel(vel=global_tree%conf(i)%elem%vel, atoms=tmc_env%params%atoms, &
336 temerature=tmc_env%params%Temp(i), &
337 rng_stream=tmc_env%rng_stream, &
338 rnd_seed=global_tree%conf(i)%elem%rng_seed)
339 global_tree%conf(i)%elem%ekin =
calc_e_kin(vel=global_tree%conf(i)%elem%vel, &
340 atoms=tmc_env%params%atoms)
346 tmc_env%m_env%st_heads(i)%elem => global_tree%conf(i)%elem
347 tmc_env%m_env%st_clean_ends(i)%elem => global_tree%conf(i)%elem
349 tmc_env%m_env%result_list(i)%elem => global_tree%conf(i)%elem
351 tmc_env%m_env%tree_node_count(:) = 0
354 tmc_env%m_env%gt_head => global_tree
355 tmc_env%m_env%gt_clean_end => global_tree
357 global_tree%swaped = .false.
358 global_tree%mv_conf = 1
359 global_tree%mv_next_conf =
modulo(global_tree%mv_conf,
SIZE(global_tree%conf)) + 1
360 global_tree%conf_n_acc = .true.
363 global_tree%prob_acc = 1.0_dp
366 global_tree%Temp = tmc_env%params%Temp(1)
367 IF (tmc_env%params%nr_temp /= 1 .AND. tmc_env%m_env%temp_decrease /= 1.0_dp)
THEN
368 CALL cp_abort(__location__, &
369 "there is no parallel tempering implementation for simulated annealing implemented "// &
370 "(just one Temp per global tree element.")
374 IF (tmc_env%m_env%restart_in_file_name /=
"")
THEN
377 file_name=tmc_env%m_env%restart_in_file_name)
379 tmc_env%m_env%tree_node_count(0) = global_tree%nr
381 DO i = 1,
SIZE(tmc_env%m_env%result_list(:))
382 tmc_env%m_env%tree_node_count(i) = tmc_env%m_env%result_list(i)%elem%nr
385 global_tree%prob_acc = 1.0_dp
386 WRITE (tmc_env%m_env%io_unit, *)
"TMC| restarting at Markov Chain element(s): ", &
387 tmc_env%m_env%result_count
394 ELSE IF (tmc_env%params%NMC_inp_file /=
"")
THEN
404 IF (tmc_env%params%DRAW_TREE)
THEN
406 tmc_params=tmc_env%params)
408 tmc_params=tmc_env%params)
412 CALL timestop(handle)
427 CHARACTER(LEN=*),
PARAMETER :: routinen =
'finalize_init'
431 cpassert(
ASSOCIATED(gt_tree_ptr))
432 cpassert(.NOT.
ASSOCIATED(gt_tree_ptr%parent))
433 cpassert(
ASSOCIATED(tmc_env))
434 cpassert(
ASSOCIATED(tmc_env%m_env))
435 cpassert(
ASSOCIATED(tmc_env%params))
438 CALL timeset(routinen, handle)
442 DO i = 1,
SIZE(gt_tree_ptr%conf)
444 IF (
ASSOCIATED(gt_tree_ptr%conf(1)%elem%dipole))
THEN
445 gt_tree_ptr%conf(i)%elem%dipole = gt_tree_ptr%conf(1)%elem%dipole
447 IF (tmc_env%m_env%restart_in_file_name ==
"")
THEN
448 gt_tree_ptr%conf(i)%elem%potential = gt_tree_ptr%conf(1)%elem%potential
452 IF (tmc_env%m_env%restart_in_file_name ==
"")
THEN
453 tmc_env%m_env%result_count(:) = tmc_env%m_env%result_count(:) + 1
454 tmc_env%m_env%result_list(:) = gt_tree_ptr%conf(:)
456 DO i = 1,
SIZE(tmc_env%m_env%result_list)
458 result_count=tmc_env%m_env%result_count, &
459 conf_updated=i, accepted=.true., &
460 tmc_params=tmc_env%params)
462 IF (tmc_env%tmc_comp_set%para_env_m_ana%num_pe > 1)
THEN
463 CALL add_to_list(elem=tmc_env%m_env%result_list(i)%elem, &
464 list=tmc_env%m_env%analysis_list, &
465 nr=tmc_env%m_env%result_count(i), &
475 CALL timestop(handle)
490 reactivation_cc_count)
492 INTEGER,
INTENT(OUT) :: stat
494 INTEGER :: reactivation_cc_count
496 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_new_gt_tree_node'
497 REAL(kind=
dp),
PARAMETER :: eps_exp_prob = 1.0e-10_dp
499 INTEGER :: handle, swap_conf
500 LOGICAL :: keep_on, n_acc
501 REAL(kind=
dp) :: prob, rnd, rnd2
505 NULLIFY (tmp_elem, tree_elem, new_elem)
507 cpassert(
ASSOCIATED(tmc_env))
508 cpassert(
ASSOCIATED(tmc_env%params))
509 cpassert(
ASSOCIATED(tmc_env%m_env))
510 cpassert(
ASSOCIATED(tmc_env%m_env%gt_act))
513 CALL timeset(routinen, handle)
517 tmp_elem => tmc_env%m_env%gt_act
521 CALL most_prob_end(global_tree_elem=tmp_elem, prob=prob, n_acc=n_acc)
524 IF (
ASSOCIATED(tmp_elem) .AND. (exp(prob) < eps_exp_prob))
THEN
531 ELSE IF (.NOT.
ASSOCIATED(tmp_elem))
THEN
541 IF ((n_acc .AND.
ASSOCIATED(tmp_elem%acc)) .OR. &
542 ((.NOT. n_acc) .AND.
ASSOCIATED(tmp_elem%nacc)))
THEN
546 new_elem => tmp_elem%acc
548 IF (.NOT. n_acc)
THEN
549 new_elem => tmp_elem%nacc
553 cpassert(
ASSOCIATED(new_elem%conf(new_elem%mv_conf)%elem))
554 SELECT CASE (new_elem%conf(new_elem%mv_conf)%elem%stat)
560 reactivation_cc_count = reactivation_cc_count + 1
562 CALL cp_abort(__location__, &
563 "global tree node creation using existing sub tree element, "// &
564 "but is not a canceled one, gt elem "// &
566 cp_to_string(new_elem%conf(new_elem%mv_conf)%elem%nr)// &
568 cp_to_string(new_elem%conf(new_elem%mv_conf)%elem%stat))
575 SELECT CASE (new_elem%conf(new_elem%mv_conf)%elem%move_type)
580 CALL cp_warn(__location__, &
581 "reactivating tree element with wrong status"// &
582 cp_to_string(new_elem%conf(new_elem%mv_conf)%elem%stat))
591 CALL cp_abort(__location__, &
592 "reactivated st element has no NMC or MD move type, "// &
593 "but seems to be canceled. Move type"// &
594 cp_to_string(new_elem%conf(new_elem%mv_conf)%elem%move_type))
596 cpabort(
"Unknown move type while reactivating subtree element.")
601 CALL allocate_new_global_tree_node(next_el=new_elem, &
602 nr_temp=tmc_env%params%nr_temp)
603 tmc_env%m_env%tree_node_count(0) = tmc_env%m_env%tree_node_count(0) + 1
604 new_elem%nr = tmc_env%m_env%tree_node_count(0)
609 IF (
ASSOCIATED(tmp_elem%acc))
THEN
610 cpabort(
"creating new subtree element on an occupied acc branch")
612 tmp_elem%acc => new_elem
614 IF (
ASSOCIATED(tmp_elem%nacc))
THEN
615 cpabort(
"creating new subtree element on an occupied nacc branch")
617 tmp_elem%nacc => new_elem
619 new_elem%parent => tmp_elem
622 new_elem%conf_n_acc(:) = new_elem%parent%conf_n_acc
625 IF (.NOT. new_elem%parent%swaped)
THEN
628 new_elem%conf_n_acc(new_elem%parent%conf( &
629 new_elem%parent%mv_conf)%elem%sub_tree_nr) = n_acc
634 IF (.NOT. n_acc)
THEN
636 IF (.NOT.
ASSOCIATED(tmp_elem%parent))
EXIT
637 IF (
ASSOCIATED(tmp_elem%parent%acc, tmp_elem))
THEN
638 tmp_elem => tmp_elem%parent
641 tmp_elem => tmp_elem%parent
642 IF (.NOT. tmp_elem%swaped)
EXIT
648 new_elem%conf(:) = tmp_elem%conf(:)
651 CALL tmc_env%rng_stream%set( &
652 bg=new_elem%parent%rng_seed(:, :, 1), &
653 cg=new_elem%parent%rng_seed(:, :, 2), &
654 ig=new_elem%parent%rng_seed(:, :, 3))
655 CALL tmc_env%rng_stream%reset_to_next_substream()
657 new_elem%rnd_nr = tmc_env%rng_stream%next()
663 new_elem%mv_conf = new_elem%parent%mv_next_conf
664 new_elem%mv_next_conf =
modulo(new_elem%mv_conf,
SIZE(new_elem%conf)) + 1
667 new_elem%Temp = tmp_elem%Temp
668 IF (n_acc) new_elem%Temp = tmp_elem%Temp*(1 - tmc_env%m_env%temp_decrease)
671 rnd = tmc_env%rng_stream%next()
672 rnd2 = tmc_env%rng_stream%next()
673 CALL tmc_env%rng_stream%get(bg=new_elem%rng_seed(:, :, 1), &
674 cg=new_elem%rng_seed(:, :, 2), &
675 ig=new_elem%rng_seed(:, :, 3))
683 new_elem%mv_next_conf = new_elem%mv_conf
685 swap_conf = 1 + int((tmc_env%params%nr_temp - 1)*rnd2)
686 new_elem%mv_conf = swap_conf
689 tree_elem => new_elem%conf(new_elem%mv_conf)%elem
690 new_elem%conf(new_elem%mv_conf)%elem => &
691 new_elem%conf(new_elem%mv_conf + 1)%elem
692 new_elem%conf(new_elem%mv_conf + 1)%elem => tree_elem
695 new_elem%swaped = .true.
696 new_elem%prob_acc = tmc_env%params%move_types%acc_prob( &
699 IF (tmc_env%params%DRAW_TREE)
THEN
701 tmc_params=tmc_env%params)
713 IF (new_elem%conf_n_acc(new_elem%conf(new_elem%mv_conf)%elem%sub_tree_nr))
THEN
715 IF (
ASSOCIATED(new_elem%conf(new_elem%mv_conf)%elem%acc))
THEN
716 new_elem%conf(new_elem%mv_conf)%elem => &
717 new_elem%conf(new_elem%mv_conf)%elem%acc
721 CALL create_new_subtree_node(act_gt_el=new_elem, &
723 IF (tmc_env%params%DRAW_TREE)
THEN
724 CALL create_dot(new_element=new_elem%conf(new_elem%mv_conf)%elem, &
725 conf=new_elem%conf(new_elem%mv_conf)%elem%sub_tree_nr, &
726 tmc_params=tmc_env%params)
731 IF (
ASSOCIATED(new_elem%conf(new_elem%mv_conf)%elem%nacc))
THEN
732 new_elem%conf(new_elem%mv_conf)%elem => &
733 new_elem%conf(new_elem%mv_conf)%elem%nacc
737 CALL create_new_subtree_node(act_gt_el=new_elem, &
739 IF (tmc_env%params%DRAW_TREE)
THEN
740 CALL create_dot(new_element=new_elem%conf(new_elem%mv_conf)%elem, &
741 conf=new_elem%conf(new_elem%mv_conf)%elem%sub_tree_nr, &
742 tmc_params=tmc_env%params)
749 new_elem%prob_acc = tmc_env%params%move_types%acc_prob( &
750 new_elem%conf(new_elem%mv_conf)%elem%move_type, new_elem%mv_conf)
753 IF (tmc_env%params%DRAW_TREE)
THEN
755 tmc_params=tmc_env%params)
766 cpabort(
"selected existing RESULT gt node")
769 SELECT CASE (new_elem%conf(new_elem%mv_conf)%elem%stat)
774 stat = new_elem%conf(new_elem%mv_conf)%elem%stat
775 IF (tmc_env%params%DRAW_TREE)
THEN
777 tmc_params=tmc_env%params)
780 new_elem%stat = new_elem%conf(new_elem%mv_conf)%elem%stat
782 stat = new_elem%conf(new_elem%mv_conf)%elem%stat
783 IF (tmc_env%params%DRAW_TREE)
THEN
785 tmc_params=tmc_env%params)
791 new_elem%stat = new_elem%conf(new_elem%mv_conf)%elem%stat
793 stat = new_elem%conf(new_elem%mv_conf)%elem%stat
794 IF (tmc_env%params%DRAW_TREE)
THEN
796 tmc_params=tmc_env%params)
807 IF (tmc_env%params%DRAW_TREE)
THEN
809 tmc_params=tmc_env%params)
813 new_elem%conf(new_elem%mv_conf)%elem%stat = &
816 stat = new_elem%conf(new_elem%mv_conf)%elem%stat
817 reactivation_cc_count = reactivation_cc_count + 1
818 IF (tmc_env%params%DRAW_TREE)
THEN
820 tmc_params=tmc_env%params)
823 CALL cp_abort(__location__, &
825 cp_to_string(new_elem%conf(new_elem%mv_conf)%elem%stat)// &
826 "of subtree element "// &
827 "for creating new gt element")
836 CALL timestop(handle)
846 SUBROUTINE create_new_subtree_node(act_gt_el, tmc_env)
850 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_new_subtree_node'
852 INTEGER :: conf, handle, itmp
853 LOGICAL :: mv_rejected, new_subbox
855 TYPE(
tree_type),
POINTER :: new_elem, parent_elem
857 NULLIFY (new_elem, parent_elem)
859 cpassert(
ASSOCIATED(act_gt_el))
860 cpassert(
ASSOCIATED(act_gt_el%conf(act_gt_el%mv_conf)%elem))
861 cpassert(
ASSOCIATED(tmc_env))
862 cpassert(
ASSOCIATED(tmc_env%params))
865 CALL timeset(routinen, handle)
867 conf = act_gt_el%mv_conf
869 next_el=new_elem, nr_dim=
SIZE(act_gt_el%parent%conf(conf)%elem%pos))
872 parent_elem => act_gt_el%conf(conf)%elem
873 new_elem%parent => parent_elem
876 parent_elem%next_elem_nr = parent_elem%next_elem_nr + 1
877 new_elem%nr = parent_elem%next_elem_nr
878 new_elem%rng_seed = parent_elem%rng_seed
881 IF (act_gt_el%conf_n_acc(act_gt_el%conf(act_gt_el%mv_conf)%elem%sub_tree_nr))
THEN
882 parent_elem%acc => new_elem
884 parent_elem%nacc => new_elem
890 new_elem%pos(:) = parent_elem%pos(:)
891 new_elem%mol(:) = parent_elem%mol(:)
892 new_elem%vel(:) = parent_elem%vel(:)
893 new_elem%ekin = parent_elem%ekin
894 new_elem%e_pot_approx = parent_elem%e_pot_approx
895 new_elem%next_elem_nr => parent_elem%next_elem_nr
896 new_elem%sub_tree_nr = parent_elem%sub_tree_nr
897 new_elem%box_scale = parent_elem%box_scale
899 new_elem%frc(:) = parent_elem%frc(:)
900 new_elem%potential = parent_elem%potential
901 new_elem%ekin_before_md = parent_elem%ekin_before_md
903 new_elem%potential = 97589.0_dp
907 CALL tmc_env%rng_stream%set( &
908 bg=new_elem%rng_seed(:, :, 1), &
909 cg=new_elem%rng_seed(:, :, 2), &
910 ig=new_elem%rng_seed(:, :, 3))
911 CALL tmc_env%rng_stream%reset_to_next_substream()
914 rnd = tmc_env%rng_stream%next()
915 IF (tmc_env%params%NMC_inp_file /=
"")
THEN
916 new_elem%temp_created = int(tmc_env%params%nr_temp*rnd) + 1
918 new_elem%temp_created = act_gt_el%mv_conf
922 rnd = tmc_env%rng_stream%next()
925 move_types=tmc_env%params%move_types, &
927 CALL tmc_env%rng_stream%get( &
928 bg=new_elem%rng_seed(:, :, 1), &
929 cg=new_elem%rng_seed(:, :, 2), &
930 ig=new_elem%rng_seed(:, :, 3))
936 SELECT CASE (new_elem%move_type)
942 new_elem%temp_created = act_gt_el%mv_conf
945 rng_stream=tmc_env%rng_stream, elem=new_elem, &
946 nr_of_sub_box_elements=itmp)
952 rng_stream=tmc_env%rng_stream, elem=new_elem, &
953 nr_of_sub_box_elements=itmp)
965 move_types=tmc_env%params%move_types, &
966 rng_stream=tmc_env%rng_stream, elem=new_elem, &
967 mv_conf=conf, new_subbox=new_subbox, &
968 move_rejected=mv_rejected)
969 IF (mv_rejected)
THEN
970 new_elem%potential = huge(new_elem%potential)
971 new_elem%e_pot_approx = huge(new_elem%e_pot_approx)
975 IF (tmc_env%params%NMC_inp_file /=
"")
THEN
982 CALL cp_abort(__location__, &
983 "unknown move type ("//
cp_to_string(new_elem%move_type)// &
984 "), while creating subtree element.")
986 act_gt_el%conf(act_gt_el%mv_conf)%elem => new_elem
989 CALL timestop(handle)
990 cpassert(
ASSOCIATED(act_gt_el%conf(act_gt_el%mv_conf)%elem))
991 END SUBROUTINE create_new_subtree_node
1004 SUBROUTINE remove_gt_elem(gt_ptr, draw, tmc_env)
1006 LOGICAL,
OPTIONAL :: draw
1009 CHARACTER(LEN=*),
PARAMETER :: routinen =
'remove_gt_elem'
1013 cpassert(
ASSOCIATED(gt_ptr))
1014 cpassert(
ASSOCIATED(tmc_env))
1017 CALL timeset(routinen, handle)
1027 IF (tmc_env%params%DRAW_TREE .AND.
PRESENT(draw))
THEN
1032 IF (
ASSOCIATED(gt_ptr%parent))
THEN
1033 IF (
ASSOCIATED(gt_ptr%parent%acc, gt_ptr))
THEN
1034 gt_ptr%parent%acc => null()
1036 IF (
ASSOCIATED(gt_ptr%parent%nacc, gt_ptr))
THEN
1037 gt_ptr%parent%nacc => null()
1042 IF (
ASSOCIATED(gt_ptr%acc))
THEN
1043 gt_ptr%acc%parent => null()
1046 IF (
ASSOCIATED(gt_ptr%nacc))
THEN
1047 gt_ptr%nacc%parent => null()
1050 CALL deallocate_global_tree_node(gt_elem=gt_ptr)
1052 CALL timestop(handle)
1054 cpassert(.NOT.
ASSOCIATED(gt_ptr))
1055 END SUBROUTINE remove_gt_elem
1065 SUBROUTINE remove_st_elem(ptr, draw, tmc_env)
1067 LOGICAL,
OPTIONAL :: draw
1070 CHARACTER(LEN=*),
PARAMETER :: routinen =
'remove_st_elem'
1076 cpassert(
ASSOCIATED(ptr))
1077 cpassert(
ASSOCIATED(tmc_env))
1080 CALL timeset(routinen, handle)
1083 IF (
ASSOCIATED(ptr%gt_nodes_references))
THEN
1084 IF (
ASSOCIATED(ptr%parent))
THEN
1085 CALL cp_warn(__location__, &
1086 "try to deallocate subtree element"// &
1088 " still with global tree element references e.g."// &
1091 cpassert(
ASSOCIATED(ptr%gt_nodes_references%gt_elem))
1093 SELECT CASE (ptr%stat)
1099 cpassert(tmc_env%params%SPECULATIVE_CANCELING)
1102 IF (
PRESENT(draw)) ready = .false.
1107 IF (
ASSOCIATED(ptr%parent) .AND. &
1108 (
ASSOCIATED(ptr%acc) .OR.
ASSOCIATED(ptr%nacc)))
THEN
1109 cpabort(
"Invalid association state of parent element")
1120 IF (tmc_env%params%DRAW_TREE .AND.
PRESENT(draw))
THEN
1125 IF (
ASSOCIATED(ptr%parent))
THEN
1126 IF (
ASSOCIATED(ptr%parent%acc, ptr)) ptr%parent%acc => null()
1127 IF (
ASSOCIATED(ptr%parent%nacc, ptr)) ptr%parent%nacc => null()
1131 IF (
ASSOCIATED(ptr%acc)) ptr%acc%parent => null()
1132 IF (
ASSOCIATED(ptr%nacc)) ptr%nacc%parent => null()
1139 CALL timestop(handle)
1140 END SUBROUTINE remove_st_elem
1156 CHARACTER(LEN=*),
PARAMETER :: routinen =
'remove_unused_g_tree'
1159 LOGICAL :: acc_removed, nacc_removed
1162 NULLIFY (acc_ptr, nacc_ptr, tmp_ptr)
1164 cpassert(
ASSOCIATED(begin_ptr))
1165 cpassert(
ASSOCIATED(end_ptr))
1166 cpassert(
ASSOCIATED(tmc_env))
1169 CALL timeset(routinen, handle)
1172 acc_removed = .false.
1173 nacc_removed = .false.
1175 IF (.NOT.
ASSOCIATED(begin_ptr, end_ptr))
THEN
1178 IF (
ASSOCIATED(begin_ptr%acc))
THEN
1179 acc_ptr => begin_ptr%acc
1182 acc_removed = .true.
1184 IF (
ASSOCIATED(begin_ptr%nacc))
THEN
1185 nacc_ptr => begin_ptr%nacc
1188 nacc_removed = .true.
1192 IF (acc_removed .AND. nacc_removed)
THEN
1193 SELECT CASE (begin_ptr%stat)
1198 tmp_ptr => begin_ptr
1200 CALL remove_gt_elem(gt_ptr=tmp_ptr, draw=.true., tmc_env=tmc_env)
1201 IF (.NOT.
ASSOCIATED(tmp_ptr)) removed = .true.
1204 CALL cp_abort(__location__, &
1205 "try to dealloc unused tree element with status of begin element" &
1211 CALL timestop(handle)
1212 cpassert(
ASSOCIATED(end_ptr))
1225 RECURSIVE SUBROUTINE remove_unused_s_tree(begin_ptr, end_ptr, working_elem_list, &
1228 TYPE(
tree_type),
INTENT(IN),
POINTER :: end_ptr
1233 CHARACTER(LEN=*),
PARAMETER :: routinen =
'remove_unused_s_tree'
1235 INTEGER :: handle, i
1236 LOGICAL :: acc_removed, nacc_removed, remove_this
1237 TYPE(
tree_type),
POINTER :: acc_ptr, nacc_ptr, tmp_ptr
1239 NULLIFY (acc_ptr, nacc_ptr, tmp_ptr)
1240 remove_this = .false.
1242 acc_removed = .false.
1243 nacc_removed = .false.
1246 CALL timeset(routinen, handle)
1248 cpassert(
ASSOCIATED(begin_ptr))
1249 cpassert(
ASSOCIATED(end_ptr))
1250 cpassert(
ASSOCIATED(working_elem_list))
1251 cpassert(
ASSOCIATED(tmc_env))
1254 IF (.NOT.
ASSOCIATED(begin_ptr, end_ptr))
THEN
1257 IF (
ASSOCIATED(begin_ptr%acc))
THEN
1258 acc_ptr => begin_ptr%acc
1259 CALL remove_unused_s_tree(acc_ptr, end_ptr, working_elem_list, &
1260 acc_removed, tmc_env)
1262 acc_removed = .true.
1264 IF (
ASSOCIATED(begin_ptr%nacc))
THEN
1265 nacc_ptr => begin_ptr%nacc
1266 CALL remove_unused_s_tree(nacc_ptr, end_ptr, working_elem_list, &
1267 nacc_removed, tmc_env)
1269 nacc_removed = .true.
1277 IF (acc_removed .AND. nacc_removed)
THEN
1278 SELECT CASE (begin_ptr%stat)
1280 remove_this = .true.
1283 remove_this = .true.
1288 remove_this = .false.
1292 CALL cp_abort(__location__, &
1294 "of sub tree element "// &
1300 IF (remove_this)
THEN
1302 IF (.NOT.
ASSOCIATED(begin_ptr%parent))
THEN
1303 CALL cp_abort(__location__, &
1304 "try to remove unused subtree element "// &
1307 " but parent does not exist")
1309 tmp_ptr => begin_ptr
1312 DO i = 1,
SIZE(working_elem_list(:))
1313 IF (
ASSOCIATED(working_elem_list(i)%elem))
THEN
1314 IF (
ASSOCIATED(working_elem_list(i)%elem, tmp_ptr))
THEN
1322 CALL remove_st_elem(ptr=tmp_ptr, draw=.true., tmc_env=tmc_env)
1323 IF (.NOT.
ASSOCIATED(tmp_ptr))
THEN
1333 CALL timestop(handle)
1334 END SUBROUTINE remove_unused_s_tree
1344 RECURSIVE SUBROUTINE remove_result_g_tree(end_of_clean_tree, actual_ptr, &
1349 CHARACTER(LEN=*),
PARAMETER :: routinen =
'remove_result_g_tree'
1354 cpassert(
ASSOCIATED(end_of_clean_tree))
1355 cpassert(
ASSOCIATED(actual_ptr))
1358 CALL timeset(routinen, handle)
1361 IF (
ASSOCIATED(actual_ptr%parent))
THEN
1362 CALL remove_result_g_tree(end_of_clean_tree=end_of_clean_tree, &
1363 actual_ptr=actual_ptr%parent, &
1367 IF (.NOT.
ASSOCIATED(actual_ptr, end_of_clean_tree))
THEN
1370 tmp_ptr => actual_ptr
1371 CALL remove_gt_elem(gt_ptr=tmp_ptr, draw=.true., tmc_env=tmc_env)
1372 actual_ptr => tmp_ptr
1375 CALL timestop(handle)
1376 END SUBROUTINE remove_result_g_tree
1387 RECURSIVE SUBROUTINE remove_result_s_tree(end_of_clean_tree, actual_ptr, &
1389 TYPE(
tree_type),
POINTER :: end_of_clean_tree, actual_ptr
1392 CHARACTER(LEN=*),
PARAMETER :: routinen =
'remove_result_s_tree'
1397 cpassert(
ASSOCIATED(end_of_clean_tree))
1398 cpassert(
ASSOCIATED(actual_ptr))
1399 cpassert(
ASSOCIATED(tmc_env))
1402 CALL timeset(routinen, handle)
1405 IF (
ASSOCIATED(actual_ptr%parent))
THEN
1406 CALL remove_result_s_tree(end_of_clean_tree, actual_ptr%parent, &
1411 IF (.NOT.
ASSOCIATED(actual_ptr, end_of_clean_tree))
THEN
1413 cpassert(.NOT. (
ASSOCIATED(actual_ptr%acc) .AND.
ASSOCIATED(actual_ptr%nacc)))
1416 IF (.NOT.
ASSOCIATED(actual_ptr%parent))
THEN
1418 tmp_ptr => actual_ptr
1419 CALL remove_st_elem(ptr=tmp_ptr, draw=.true., tmc_env=tmc_env)
1420 actual_ptr => tmp_ptr
1424 CALL timestop(handle)
1425 END SUBROUTINE remove_result_s_tree
1439 CHARACTER(LEN=*),
PARAMETER :: routinen =
'remove_all_trees'
1441 INTEGER :: handle, i, tree
1442 LOGICAL :: change_trajec, flag
1444 TYPE(
tree_type),
POINTER :: last_acc_st_elem, tmp_ptr
1446 NULLIFY (last_acc_st_elem, tmp_ptr, tmp_gt_ptr)
1448 cpassert(
ASSOCIATED(working_elem_list))
1449 cpassert(
ASSOCIATED(tmc_env))
1450 cpassert(
ASSOCIATED(tmc_env%m_env))
1451 cpassert(
ASSOCIATED(tmc_env%m_env%gt_act))
1452 cpassert(
ASSOCIATED(tmc_env%m_env%gt_clean_end))
1453 cpassert(
ASSOCIATED(tmc_env%m_env%result_list))
1454 cpassert(
ASSOCIATED(tmc_env%m_env%st_clean_ends))
1457 change_trajec = .false.
1460 CALL timeset(routinen, handle)
1464 end_ptr=tmc_env%m_env%gt_act, removed=flag, &
1466 tmp_gt_ptr => tmc_env%m_env%gt_clean_end
1468 tree_ptr=tmp_gt_ptr)
1470 IF (tmc_env%params%USE_REDUCED_TREE)
THEN
1471 tmp_gt_ptr => tmc_env%m_env%gt_clean_end
1472 CALL remove_result_g_tree(end_of_clean_tree=tmc_env%m_env%gt_clean_end, &
1473 actual_ptr=tmp_gt_ptr, tmc_env=tmc_env)
1476 IF (.NOT.
ASSOCIATED(tmc_env%m_env%gt_head, tmc_env%m_env%gt_clean_end))
THEN
1477 change_trajec = .true.
1479 tmc_env%m_env%gt_head => tmc_env%m_env%gt_clean_end
1480 cpassert(.NOT.
ASSOCIATED(tmc_env%m_env%gt_head%parent))
1486 DO tree = 1, tmc_env%params%nr_temp
1488 conf_loop:
DO i = 1,
SIZE(tmc_env%m_env%result_list)
1489 last_acc_st_elem => tmc_env%m_env%result_list(i)%elem
1490 IF (last_acc_st_elem%sub_tree_nr == tree)
THEN
1494 cpassert(last_acc_st_elem%sub_tree_nr == tree)
1495 CALL remove_unused_s_tree(begin_ptr=tmc_env%m_env%st_clean_ends(tree)%elem, &
1496 end_ptr=last_acc_st_elem, working_elem_list=working_elem_list, &
1497 removed=flag, tmc_env=tmc_env)
1499 last_acc=last_acc_st_elem)
1502 IF (tmc_env%params%USE_REDUCED_TREE .AND. change_trajec)
THEN
1503 DO tree = 1, tmc_env%params%nr_temp
1504 tmp_ptr => tmc_env%m_env%st_clean_ends(tree)%elem
1505 cpassert(tmp_ptr%sub_tree_nr == tree)
1506 CALL remove_result_s_tree(end_of_clean_tree=tmc_env%m_env%st_clean_ends(tree)%elem, &
1507 actual_ptr=tmp_ptr, tmc_env=tmc_env)
1508 tmc_env%m_env%st_heads(tree)%elem => tmc_env%m_env%st_clean_ends(tree)%elem
1516 CALL timestop(handle)
1517 cpassert(
ASSOCIATED(tmc_env%m_env%gt_act))
1518 cpassert(
ASSOCIATED(tmc_env%m_env%gt_clean_end))
1528 RECURSIVE SUBROUTINE dealloc_whole_g_tree(begin_ptr, removed, tmc_env)
1533 LOGICAL :: acc_removed, nacc_removed
1536 cpassert(
ASSOCIATED(begin_ptr))
1537 cpassert(
ASSOCIATED(tmc_env))
1539 IF (
ASSOCIATED(begin_ptr%acc))
THEN
1540 acc_ptr => begin_ptr%acc
1541 CALL dealloc_whole_g_tree(acc_ptr, acc_removed, tmc_env)
1543 acc_removed = .true.
1545 IF (
ASSOCIATED(begin_ptr%nacc))
THEN
1546 nacc_ptr => begin_ptr%nacc
1547 CALL dealloc_whole_g_tree(nacc_ptr, nacc_removed, tmc_env)
1549 nacc_removed = .true.
1553 IF (acc_removed .AND. nacc_removed)
THEN
1555 elem=begin_ptr%conf(begin_ptr%mv_conf)%elem, tmc_env=tmc_env)
1556 tmp_ptr => begin_ptr
1557 CALL remove_gt_elem(gt_ptr=tmp_ptr, draw=.false., tmc_env=tmc_env)
1561 END SUBROUTINE dealloc_whole_g_tree
1569 RECURSIVE SUBROUTINE dealloc_whole_subtree(begin_ptr, removed, tmc_params)
1574 LOGICAL :: acc_removed, nacc_removed
1575 TYPE(
tree_type),
POINTER :: acc_ptr, nacc_ptr, tmp_ptr
1577 cpassert(
ASSOCIATED(begin_ptr))
1578 cpassert(
ASSOCIATED(tmc_params))
1580 IF (
ASSOCIATED(begin_ptr%acc))
THEN
1581 acc_ptr => begin_ptr%acc
1582 CALL dealloc_whole_subtree(acc_ptr, acc_removed, tmc_params)
1584 acc_removed = .true.
1586 IF (
ASSOCIATED(begin_ptr%nacc))
THEN
1587 nacc_ptr => begin_ptr%nacc
1588 CALL dealloc_whole_subtree(nacc_ptr, nacc_removed, tmc_params)
1590 nacc_removed = .true.
1594 IF (acc_removed .AND. nacc_removed)
THEN
1595 tmp_ptr => begin_ptr
1599 END SUBROUTINE dealloc_whole_subtree
1616 cpassert(
ASSOCIATED(tmc_env))
1617 cpassert(
ASSOCIATED(tmc_env%m_env))
1619 global_tree => tmc_env%m_env%gt_act
1622 DO WHILE (
ASSOCIATED(global_tree%parent))
1623 global_tree => global_tree%parent
1625 CALL dealloc_whole_g_tree(begin_ptr=global_tree, removed=flag, &
1629 trees_loop:
DO i = 1,
SIZE(tmc_env%m_env%st_clean_ends(:))
1630 DO WHILE (
ASSOCIATED(tmc_env%m_env%st_clean_ends(i)%elem%parent))
1631 tmc_env%m_env%st_clean_ends(i)%elem => &
1632 tmc_env%m_env%st_clean_ends(i)%elem%parent
1634 CALL dealloc_whole_subtree(begin_ptr=tmc_env%m_env%st_clean_ends(i)%elem, &
1635 removed=flag, tmc_params=tmc_env%params)
1637 DEALLOCATE (tmc_env%params%atoms)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
various routines to log and control the output. The idea is that decisions about where to log should ...
Defines the basic variable types.
integer, parameter, public dp
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Timing routines for accounting.
calculation section for TreeMonteCarlo
subroutine, public init_vel(vel, atoms, temerature, rng_stream, rnd_seed)
routine sets initial velocity, using the Box-Muller Method for Normal (Gaussian) Deviates
real(kind=dp) function, public calc_e_kin(vel, atoms)
routine calculates the kinetic energy, using the velocities and atom mass, both in atomic units
module for printing tree structures in GraphViz dot files for visualizing the trees
subroutine, public create_dot(new_element, conf, tmc_params)
interfaces the creating of a branch for subtree elements
subroutine, public create_global_tree_dot_color(gt_tree_element, tmc_params)
interfaces the change of color for global tree node on the basis of the element status
subroutine, public create_global_tree_dot(new_element, tmc_params)
creates new dot and arrow from element one level up (for subtree) additional handling of nodes with s...
subroutine, public create_dot_color(tree_element, tmc_params)
interfaces the change of color for subtree elements on the basis of the element status
writing and printing the files, trajectory (pos, cell, dipoles) as well as restart files
subroutine, public write_result_list_element(result_list, result_count, conf_updated, accepted, tmc_params)
select the correct configuration to print out the (coordinates, forces, cell ...)
subroutine, public read_restart_file(tmc_env, job_counts, timings, file_name)
reads the TMC restart file with all last configurations and counters etc.
acceptance ratio handling of the different Monte Carlo Moves types For each move type and each temper...
integer function, public select_random_move_type(move_types, rnd)
selects a move type related to the weighings and the entered rnd nr
tree nodes creation, searching, deallocation, references etc.
integer, parameter, public mv_type_mol_rot
integer, parameter, public mv_type_volume_move
integer, parameter, public mv_type_proton_reorder
integer, parameter, public mv_type_swap_conf
integer, parameter, public mv_type_md
integer, parameter, public mv_type_mol_trans
integer, parameter, public mv_type_atom_swap
integer, parameter, public mv_type_gausian_adapt
integer, parameter, public mv_type_atom_trans
integer, parameter, public mv_type_nmc_moves
integer, parameter, public mv_type_none
different move types are applied
subroutine, public elements_in_new_subbox(tmc_params, rng_stream, elem, nr_of_sub_box_elements)
set a new random sub box center and counte the number of atoms in it
subroutine, public change_pos(tmc_params, move_types, rng_stream, elem, mv_conf, new_subbox, move_rejected)
applying the preselected move type
tree nodes creation, searching, deallocation, references etc.
integer, parameter, public tmc_status_failed
integer, parameter, public task_type_gaussian_adaptation
integer, parameter, public tmc_status_wait_for_new_task
integer, parameter, public task_type_mc
tree nodes creation, deallocation, references etc.
subroutine, public init_tree_mod(start_elem, tmc_env, job_counts, worker_timings)
routine initiate the global and subtrees with the first elements
subroutine, public deallocate_sub_tree_node(tree_elem)
deallocates an elements of the subtree element structure
subroutine, public create_new_gt_tree_node(tmc_env, stat, new_elem, reactivation_cc_count)
creates new global tree element and if needed new subtree element
subroutine, public finalize_init(gt_tree_ptr, tmc_env)
distributes the initial energy to all subtree (if no restart) and call analysis for this element (wri...
recursive subroutine, public remove_unused_g_tree(begin_ptr, end_ptr, removed, tmc_env)
deletes the no more used global tree nodes beside the result nodes from begin_ptr to end_ptr
subroutine, public remove_all_trees(working_elem_list, tmc_env)
deallocates the no more used tree nodes beside the result nodes from begin_ptr to end_ptr in global a...
subroutine, public finalize_trees(tmc_env)
deallocating every tree node of every trees (clean up)
subroutine, public allocate_new_sub_tree_node(tmc_params, next_el, nr_dim)
allocates an elements of the subtree element structure
subroutine, public search_and_remove_reference_in_list(gt_ptr, elem, tmc_env)
removes the global tree references of this actual global tree element from all related sub tree eleme...
subroutine, public add_to_references(gt_elem)
adds global tree reference to the modified sub tree element(s)
subroutine, public remove_subtree_element_of_all_references(ptr)
removes the pointers to a certain subtree element from every related global tree element
subroutine, public remove_gt_references(gt_ptr, tmc_env)
removes the global tree references of this actual global tree element from all related sub tree eleme...
recursive subroutine, public search_end_of_clean_g_tree(last_acc, tree_ptr)
searches last element on trajectory, until where the sides of the tree are deleted (of global tree) a...
recursive type(tree_type) function, pointer, public search_parent_element(current)
searching the parent element (last accepted configuration before)
recursive subroutine, public most_prob_end(global_tree_elem, prob, n_acc, search_energy_node)
search most probable end in global tree to create a new tree node using the acceptance probabilities ...
recursive subroutine, public search_end_of_clean_tree(tree_ptr, last_acc)
searches last element on trajectory, until where the sides of the tree are deleted (in sub tree) also...
module handles definition of the tree nodes for the global and
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
integer, parameter, public status_canceled_ener
integer, parameter, public status_calculated
integer, parameter, public status_cancel_ener
integer, parameter, public status_cancel_nmc
integer, parameter, public status_canceled_nmc
integer, parameter, public status_calc_approx_ener
integer, parameter, public status_ok
integer, parameter, public status_rejected
integer, parameter, public status_calculate_nmc_steps
integer, parameter, public status_accepted_result
integer, parameter, public status_deleted_result
integer, parameter, public status_created
integer, parameter, public status_rejected_result
module handles definition of the tree nodes for the global and