28#include "../base/base_uses.f90"
34 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'tmc_tree_search'
69 REAL(kind=
dp),
INTENT(OUT) :: prob
70 LOGICAL,
INTENT(INOUT) :: n_acc
71 LOGICAL,
OPTIONAL :: search_energy_node
73 CHARACTER(LEN=*),
PARAMETER :: routinen =
'most_prob_end'
76 LOGICAL :: check_accepted, check_rejected, keep_on, &
78 REAL(kind=
dp) :: prob_n_acc, prob_n_nacc
82 NULLIFY (st_elem, ptr_acc, ptr_nacc)
86 check_accepted = .false.
87 check_rejected = .false.
90 cpassert(
ASSOCIATED(global_tree_elem))
91 st_elem => global_tree_elem%conf(global_tree_elem%mv_conf)%elem
92 cpassert(
ASSOCIATED(st_elem))
95 CALL timeset(routinen, handle)
99 SELECT CASE (global_tree_elem%stat)
101 check_accepted = .true.
103 check_rejected = .true.
106 SELECT CASE (st_elem%stat)
109 IF (
PRESENT(search_energy_node))
THEN
114 check_accepted = .true.
115 check_rejected = .true.
122 IF (.NOT.
PRESENT(search_energy_node))
THEN
124 n_acc =
ASSOCIATED(global_tree_elem%parent%acc, global_tree_elem)
125 global_tree_elem => global_tree_elem%parent
133 check_accepted = .true.
134 check_rejected = .true.
138 IF (.NOT.
PRESENT(search_energy_node))
THEN
139 check_rejected = .true.
143 CALL cp_abort(__location__, &
144 "unknown sub tree element status "// &
153 IF (check_accepted)
THEN
155 IF (
ASSOCIATED(global_tree_elem%acc))
THEN
156 ptr_acc => global_tree_elem%acc
157 IF (
PRESENT(search_energy_node))
THEN
158 CALL most_prob_end(global_tree_elem=ptr_acc, prob=prob_n_acc, &
160 search_energy_node=search_energy_node)
162 CALL most_prob_end(global_tree_elem=ptr_acc, prob=prob_n_acc, &
167 prob_n_acc = prob_n_acc + log(global_tree_elem%prob_acc)
171 prob_n_acc = log(global_tree_elem%prob_acc)
172 IF (
PRESENT(search_energy_node)) prob_n_acc = -100000
173 ptr_acc => global_tree_elem
179 IF (check_rejected)
THEN
181 IF (
ASSOCIATED(global_tree_elem%nacc))
THEN
182 ptr_nacc => global_tree_elem%nacc
183 IF (
PRESENT(search_energy_node))
THEN
184 CALL most_prob_end(global_tree_elem=ptr_nacc, prob=prob_n_nacc, &
186 search_energy_node=search_energy_node)
188 CALL most_prob_end(global_tree_elem=ptr_nacc, prob=prob_n_nacc, &
193 prob_n_nacc = prob_n_nacc + log(1 - global_tree_elem%prob_acc)
197 prob_n_nacc = log(1 - global_tree_elem%prob_acc)
198 IF (
PRESENT(search_energy_node)) prob_n_nacc = -100000
199 ptr_nacc => global_tree_elem
206 IF (prob_n_acc >= prob_n_nacc)
THEN
208 global_tree_elem => ptr_acc
212 global_tree_elem => ptr_nacc
217 CALL timestop(handle)
230 INTEGER :: stat, react_count
232 CHARACTER(LEN=*),
PARAMETER :: routinen =
'search_next_energy_calc'
233 REAL(kind=
dp),
PARAMETER :: eps_exp_prob = 1.0e-10_dp
237 REAL(kind=
dp) :: prob
241 cpassert(
ASSOCIATED(gt_head))
244 CALL timeset(routinen, handle)
246 new_gt_elem => gt_head
248 CALL most_prob_end(global_tree_elem=new_gt_elem, prob=prob, n_acc=flag, &
249 search_energy_node=.true.)
254 IF (.NOT.
ASSOCIATED(new_gt_elem) .OR. (exp(prob) < eps_exp_prob))
THEN
258 IF (new_gt_elem%conf(new_gt_elem%mv_conf)%elem%stat == &
261 react_count = react_count + 1
265 IF (new_gt_elem%conf(new_gt_elem%mv_conf)%elem%stat /=
status_created)
THEN
270 CALL timestop(handle)
281 TYPE(
tree_type),
POINTER :: current, parent
283 CHARACTER(LEN=*),
PARAMETER :: routinen =
'search_parent_element'
287 cpassert(
ASSOCIATED(current))
290 CALL timeset(routinen, handle)
292 IF (
ASSOCIATED(current%parent))
THEN
294 parent => current%parent
295 IF (
ASSOCIATED(parent%nacc, current))
THEN
303 CALL timestop(handle)
304 cpassert(
ASSOCIATED(parent))
317 CHARACTER(LEN=*),
PARAMETER :: routinen =
'search_next_gt_element_to_check'
323 cpassert(
ASSOCIATED(ptr))
326 CALL timeset(routinen, handle)
330 SELECT CASE (ptr%stat)
332 IF (
ASSOCIATED(ptr%acc))
THEN
337 IF (
ASSOCIATED(ptr%nacc))
THEN
349 CALL cp_abort(__location__, &
354 CALL timestop(handle)
356 cpassert(
ASSOCIATED(ptr))
369 TYPE(
tree_type),
INTENT(OUT),
POINTER :: elem1, elem2
371 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_subtree_elements_to_check'
375 cpassert(
ASSOCIATED(gt_act_elem))
378 CALL timeset(routinen, handle)
380 IF (gt_act_elem%swaped)
THEN
384 IF (gt_act_elem%conf_n_acc(gt_act_elem%conf(gt_act_elem%mv_conf)%elem%sub_tree_nr))
THEN
385 elem1 => gt_act_elem%conf(gt_act_elem%mv_conf)%elem
390 IF (gt_act_elem%conf_n_acc(gt_act_elem%conf(gt_act_elem%mv_conf + 1)%elem%sub_tree_nr))
THEN
391 elem2 => gt_act_elem%conf(gt_act_elem%mv_conf + 1)%elem
396 elem1 => gt_act_elem%conf(gt_act_elem%mv_conf)%elem
401 CALL timestop(handle)
403 cpassert(
ASSOCIATED(gt_act_elem))
404 cpassert(
ASSOCIATED(elem1))
405 cpassert(
ASSOCIATED(elem2))
419 CHARACTER(LEN=*),
PARAMETER :: routinen =
'search_end_of_clean_g_tree'
423 cpassert(
ASSOCIATED(last_acc))
424 cpassert(
ASSOCIATED(tree_ptr))
427 CALL timeset(routinen, handle)
429 SELECT CASE (tree_ptr%stat)
431 IF (
ASSOCIATED(tree_ptr%acc) .AND. .NOT.
ASSOCIATED(tree_ptr%nacc))
THEN
433 tree_ptr => tree_ptr%acc
437 IF (
ASSOCIATED(tree_ptr%nacc) .AND. .NOT.
ASSOCIATED(tree_ptr%acc))
THEN
438 tree_ptr => tree_ptr%nacc
447 CALL cp_abort(__location__, &
448 "the global tree element "//
cp_to_string(tree_ptr%nr)// &
452 CALL timestop(handle)
453 cpassert(
ASSOCIATED(last_acc))
454 cpassert(
ASSOCIATED(tree_ptr))
469 TYPE(
tree_type),
INTENT(IN),
POINTER :: last_acc
471 CHARACTER(LEN=*),
PARAMETER :: routinen =
'search_end_of_clean_tree'
475 cpassert(
ASSOCIATED(tree_ptr))
476 cpassert(
ASSOCIATED(last_acc))
479 CALL timeset(routinen, handle)
481 IF (.NOT.
ASSOCIATED(last_acc, tree_ptr))
THEN
482 IF (
ASSOCIATED(tree_ptr%acc) .AND. .NOT.
ASSOCIATED(tree_ptr%nacc))
THEN
483 tree_ptr => tree_ptr%acc
485 ELSE IF (
ASSOCIATED(tree_ptr%nacc) .AND. .NOT.
ASSOCIATED(tree_ptr%acc))
THEN
486 tree_ptr => tree_ptr%nacc
491 CALL timestop(handle)
492 cpassert(
ASSOCIATED(tree_ptr))
493 cpassert(
ASSOCIATED(last_acc))
508 REAL(kind=
dp),
OPTIONAL :: prob
511 CHARACTER(LEN=*),
PARAMETER :: routinen =
'search_canceling_elements'
512 REAL(kind=
dp),
PARAMETER :: eps_prob = 1.0e-10_dp
518 NULLIFY (pt_elem, act_pt_ptr)
519 cpassert(
ASSOCIATED(pt_elem_in))
520 cpassert(
ASSOCIATED(tmc_env))
523 CALL timeset(routinen, handle)
527 IF (
PRESENT(prob))
THEN
528 IF (prob < eps_prob .AND.
ASSOCIATED(pt_elem_in%acc))
THEN
529 pt_elem => pt_elem_in%acc
530 ELSE IF (prob > (1.0_dp - eps_prob) .AND.
ASSOCIATED(pt_elem_in%nacc))
THEN
531 pt_elem => pt_elem_in%nacc
536 pt_elem => pt_elem_in
540 IF (
ASSOCIATED(pt_elem%conf(pt_elem%mv_conf)%elem))
THEN
541 SELECT CASE (pt_elem%conf(pt_elem%mv_conf)%elem%stat)
550 elem=pt_elem%conf(pt_elem%mv_conf)%elem, tmc_env=tmc_env)
553 CALL cp_abort(__location__, &
554 "unknown status of subtree element"// &
560 IF (
ASSOCIATED(pt_elem%acc))
THEN
561 act_pt_ptr => pt_elem%acc
564 IF (
ASSOCIATED(pt_elem%nacc))
THEN
565 act_pt_ptr => pt_elem%nacc
570 CALL timestop(handle)
571 cpassert(
ASSOCIATED(pt_elem_in))
582 INTEGER,
DIMENSION(:),
POINTER :: counters
584 CHARACTER(len=*),
PARAMETER :: routinen =
'count_prepared_nodes_in_trees'
591 cpassert(
ASSOCIATED(global_tree_ptr))
592 cpassert(
ASSOCIATED(counters))
593 cpassert(
SIZE(counters(1:)) ==
SIZE(global_tree_ptr%conf(:)))
596 CALL timeset(routinen, handle)
599 DO i = 1,
SIZE(global_tree_ptr%conf(:))
600 begin_ptr => global_tree_ptr%conf(i)%elem
601 CALL count_prepared_nodes_in_subtree(tree_ptr=begin_ptr, &
606 CALL timestop(handle)
616 RECURSIVE SUBROUTINE count_prepared_nodes_in_subtree(tree_ptr, counter)
624 cpassert(
ASSOCIATED(tree_ptr))
626 SELECT CASE (tree_ptr%stat)
628 IF (
ASSOCIATED(tree_ptr%acc))
THEN
629 tmp_ptr => tree_ptr%acc
630 CALL count_prepared_nodes_in_subtree(tmp_ptr, counter)
633 IF (
ASSOCIATED(tree_ptr%nacc))
THEN
634 tmp_ptr => tree_ptr%nacc
635 CALL count_prepared_nodes_in_subtree(tmp_ptr, counter)
640 IF (
ASSOCIATED(tree_ptr%acc))
THEN
641 tmp_ptr => tree_ptr%acc
642 CALL count_prepared_nodes_in_subtree(tmp_ptr, counter)
644 IF (
ASSOCIATED(tree_ptr%nacc))
THEN
645 tmp_ptr => tree_ptr%nacc
646 CALL count_prepared_nodes_in_subtree(tmp_ptr, counter)
652 CALL cp_abort(__location__, &
657 END SUBROUTINE count_prepared_nodes_in_subtree
669 counters, head_elements_nr)
672 INTEGER,
DIMENSION(:),
POINTER :: counters, head_elements_nr
674 CHARACTER(len=*),
PARAMETER :: routinen =
'count_nodes_in_trees'
680 NULLIFY (begin_gt_ptr, begin_ptr)
682 cpassert(
ASSOCIATED(global_tree_ptr))
683 cpassert(
ASSOCIATED(end_of_clean_trees))
684 cpassert(
ASSOCIATED(counters))
685 cpassert(
SIZE(counters(1:)) ==
SIZE(global_tree_ptr%conf(:)))
688 CALL timeset(routinen, handle)
690 begin_gt_ptr => global_tree_ptr
693 IF (.NOT.
ASSOCIATED(begin_gt_ptr%parent))
EXIT
694 begin_gt_ptr => begin_gt_ptr%parent
696 head_elements_nr(0) = begin_gt_ptr%nr
697 CALL count_nodes_in_global_tree(begin_gt_ptr, counters(0))
698 DO i = 1,
SIZE(end_of_clean_trees(:))
699 begin_ptr => end_of_clean_trees(i)%elem
701 IF (.NOT.
ASSOCIATED(begin_ptr%parent))
EXIT
702 begin_ptr => begin_ptr%parent
704 head_elements_nr(i) = begin_ptr%nr
705 CALL count_nodes_in_tree(begin_ptr, counters(i))
709 CALL timestop(handle)
718 RECURSIVE SUBROUTINE count_nodes_in_global_tree(ptr, counter)
720 INTEGER,
INTENT(INOUT) :: counter
722 cpassert(
ASSOCIATED(ptr))
724 counter = counter + 1
726 IF (
ASSOCIATED(ptr%acc))
THEN
727 CALL count_nodes_in_global_tree(ptr%acc, counter)
729 IF (
ASSOCIATED(ptr%nacc))
THEN
730 CALL count_nodes_in_global_tree(ptr%nacc, counter)
732 END SUBROUTINE count_nodes_in_global_tree
740 RECURSIVE SUBROUTINE count_nodes_in_tree(ptr, counter)
744 cpassert(
ASSOCIATED(ptr))
746 counter = counter + 1
748 IF (
ASSOCIATED(ptr%acc))
THEN
749 CALL count_nodes_in_tree(ptr%acc, counter)
751 IF (
ASSOCIATED(ptr%nacc))
THEN
752 CALL count_nodes_in_tree(ptr%nacc, counter)
754 END SUBROUTINE count_nodes_in_tree
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
tree nodes creation, searching, deallocation, references etc.
integer, parameter, public tmc_status_wait_for_new_task
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 search_next_energy_calc(gt_head, new_gt_elem, stat, react_count)
gt_head head of the global tree
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...
recursive subroutine, public search_canceling_elements(pt_elem_in, prob, tmc_env)
searches in all branches down below the entered global tree element for elements to cancel,...
subroutine, public get_subtree_elements_to_check(gt_act_elem, elem1, elem2)
get the changed element of the actual global tree element and its related last accepted parent
subroutine, public count_nodes_in_trees(global_tree_ptr, end_of_clean_trees, counters, head_elements_nr)
counts the number of existing nodes in global and subtrees
subroutine, public count_prepared_nodes_in_trees(global_tree_ptr, counters)
searches for created configurations in all subtrees
recursive subroutine, public search_next_gt_element_to_check(ptr, found)
search the next global element in the Markov Chain to check
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
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_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