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 : !> \par History
10 : !> Code to return a gridlevel associated with a given gaussian exponent
11 : !> \author Joost VandeVondele (27.02.02)
12 : ! **************************************************************************************************
13 : MODULE gaussian_gridlevels
14 : USE cp_log_handling, ONLY: cp_get_default_logger,&
15 : cp_logger_type
16 : USE cp_output_handling, ONLY: cp_print_key_finished_output,&
17 : cp_print_key_unit_nr
18 : USE input_section_types, ONLY: section_vals_release,&
19 : section_vals_retain,&
20 : section_vals_type
21 : USE kinds, ONLY: dp,&
22 : int_8
23 : USE message_passing, ONLY: mp_comm_type,&
24 : mp_para_env_type
25 : #include "../base/base_uses.f90"
26 :
27 : IMPLICIT NONE
28 :
29 : PRIVATE
30 :
31 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gaussian_gridlevels'
32 :
33 : ! **************************************************************************************************
34 : TYPE gridlevel_info_type
35 : INTEGER :: ngrid_levels = 0
36 : REAL(KIND=dp), POINTER, DIMENSION(:) :: cutoff => NULL()
37 : INTEGER(KIND=int_8), POINTER, DIMENSION(:) :: count => NULL()
38 : INTEGER(KIND=int_8) :: total_count = 0_int_8
39 : REAL(KIND=dp) :: rel_cutoff = 0.0_dp
40 : TYPE(section_vals_type), POINTER :: print_section => NULL()
41 : END TYPE gridlevel_info_type
42 :
43 : PUBLIC :: gridlevel_info_type
44 : PUBLIC :: gaussian_gridlevel
45 : PUBLIC :: init_gaussian_gridlevel
46 : PUBLIC :: destroy_gaussian_gridlevel
47 :
48 : CONTAINS
49 :
50 : ! **************************************************************************************************
51 : !> \brief ...
52 : !> \param gridlevel_info ...
53 : !> \param ngrid_levels ...
54 : !> \param cutoff ...
55 : !> \param rel_cutoff ...
56 : !> \param print_section ...
57 : ! **************************************************************************************************
58 8564 : SUBROUTINE init_gaussian_gridlevel(gridlevel_info, ngrid_levels, cutoff, rel_cutoff, print_section)
59 : TYPE(gridlevel_info_type), INTENT(OUT) :: gridlevel_info
60 : INTEGER, INTENT(IN) :: ngrid_levels
61 : REAL(KIND=dp), DIMENSION(ngrid_levels), INTENT(IN) :: cutoff
62 : REAL(KIND=dp), INTENT(IN) :: rel_cutoff
63 : TYPE(section_vals_type), INTENT(IN), TARGET :: print_section
64 :
65 : INTEGER :: i
66 :
67 25692 : ALLOCATE (gridlevel_info%cutoff(ngrid_levels))
68 25692 : ALLOCATE (gridlevel_info%count(ngrid_levels))
69 8564 : gridlevel_info%ngrid_levels = ngrid_levels
70 8564 : gridlevel_info%rel_cutoff = rel_cutoff
71 36620 : DO i = 1, ngrid_levels
72 28056 : gridlevel_info%cutoff(i) = cutoff(i)
73 36620 : gridlevel_info%count(i) = 0
74 : END DO
75 8564 : gridlevel_info%print_section => print_section
76 8564 : CALL section_vals_retain(gridlevel_info%print_section)
77 8564 : END SUBROUTINE init_gaussian_gridlevel
78 :
79 : ! **************************************************************************************************
80 : !> \brief ...
81 : !> \param gridlevel_info ...
82 : !> \param para_env ...
83 : ! **************************************************************************************************
84 8564 : SUBROUTINE destroy_gaussian_gridlevel(gridlevel_info, para_env)
85 : TYPE(gridlevel_info_type), INTENT(INOUT) :: gridlevel_info
86 : TYPE(mp_para_env_type), INTENT(IN), OPTIONAL :: para_env
87 :
88 : INTEGER :: i, output_unit
89 : LOGICAL :: do_io
90 : TYPE(cp_logger_type), POINTER :: logger
91 : TYPE(mp_comm_type) :: group
92 :
93 8564 : NULLIFY (logger)
94 17128 : logger => cp_get_default_logger()
95 8564 : IF (PRESENT(para_env)) THEN
96 989 : group = para_env
97 : do_io = .FALSE. !subgroups completely mess up the output file
98 : ELSE
99 7575 : group = logger%para_env
100 : do_io = .TRUE.
101 : END IF
102 :
103 : IF (do_io) THEN
104 :
105 7575 : CALL group%sum(gridlevel_info%total_count)
106 55775 : CALL group%sum(gridlevel_info%count)
107 :
108 : output_unit = cp_print_key_unit_nr(logger, gridlevel_info%print_section, &
109 7575 : "", extension=".Log")
110 :
111 7575 : IF (output_unit > 0) THEN
112 1821 : WRITE (output_unit, '(/,T2,A,A)') "----------------------------------------", &
113 3642 : "---------------------------------------"
114 1821 : WRITE (output_unit, '(T2,A,T35,A,T77,A)') "----", "MULTIGRID INFO", "----"
115 1821 : WRITE (output_unit, '(T2,A,A)') "----------------------------------------", &
116 3642 : "---------------------------------------"
117 1821 : IF (gridlevel_info%ngrid_levels > 1) THEN
118 6334 : DO i = 1, gridlevel_info%ngrid_levels
119 5100 : WRITE (output_unit, '(T2,A,I4,A,I14,9x,A,F12.2)') "count for grid ", i, ": ", &
120 11434 : gridlevel_info%count(i), " cutoff [a.u.] ", gridlevel_info%cutoff(i)
121 : END DO
122 1234 : WRITE (output_unit, '(T2,A,I14)') "total gridlevel count : ", &
123 2468 : gridlevel_info%total_count
124 : ELSE
125 587 : WRITE (output_unit, '(T2,A,I14,T51,A,F12.2)') "total grid count :", &
126 1174 : gridlevel_info%count(1), " cutoff [a.u.] ", gridlevel_info%cutoff(1)
127 : END IF
128 : END IF
129 :
130 7575 : CALL cp_print_key_finished_output(output_unit, logger, gridlevel_info%print_section, "")
131 : END IF
132 :
133 8564 : DEALLOCATE (gridlevel_info%cutoff)
134 :
135 8564 : CALL section_vals_release(gridlevel_info%print_section)
136 :
137 8564 : DEALLOCATE (gridlevel_info%count)
138 :
139 8564 : END SUBROUTINE destroy_gaussian_gridlevel
140 :
141 : ! **************************************************************************************************
142 : !> \brief ...
143 : !> \param gridlevel_info ...
144 : !> \param exponent ...
145 : !> \return ...
146 : ! **************************************************************************************************
147 38264809 : FUNCTION gaussian_gridlevel(gridlevel_info, exponent) RESULT(gridlevel)
148 : TYPE(gridlevel_info_type), INTENT(INOUT) :: gridlevel_info
149 : REAL(KIND=dp), INTENT(IN) :: exponent
150 : INTEGER :: gridlevel
151 :
152 : INTEGER :: i
153 : REAL(KIND=dp) :: needed_cutoff
154 :
155 38264809 : gridlevel = 1
156 38264809 : needed_cutoff = ABS(exponent)*gridlevel_info%rel_cutoff
157 177715903 : DO i = 1, gridlevel_info%ngrid_levels
158 177715903 : IF ((gridlevel_info%cutoff(i) + 1E-6_dp) .GE. needed_cutoff) THEN
159 37374127 : gridlevel = i
160 : END IF
161 : END DO
162 38264809 : !$OMP ATOMIC
163 : gridlevel_info%total_count = gridlevel_info%total_count + 1
164 38264809 : !$OMP ATOMIC
165 : gridlevel_info%count(gridlevel) = gridlevel_info%count(gridlevel) + 1
166 :
167 38264809 : END FUNCTION gaussian_gridlevel
168 :
169 0 : END MODULE gaussian_gridlevels
|