Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Radial fundamentals for Gaussian two-electron integrals.
10 : !> Entry m+1 stores order m. Private kernels provide unnormalized coefficients;
11 : !> the dispatcher returns their common multiplicative normalization separately.
12 : !> Gaussian-product attenuation and geometry prefactors belong to the caller.
13 : ! **************************************************************************************************
14 : MODULE r12_fundamentals
15 : USE cp_files, ONLY: close_file,&
16 : discover_file,&
17 : open_file
18 : USE gamma, ONLY: deallocate_md_ftable,&
19 : fgamma => fgamma_0,&
20 : init_md_ftable
21 : USE input_constants, ONLY: do_potential_coulomb,&
22 : do_potential_gaussian,&
23 : do_potential_long,&
24 : do_potential_mix_cl,&
25 : do_potential_mix_cl_trunc,&
26 : do_potential_mix_lg,&
27 : do_potential_short,&
28 : do_potential_truncated
29 : USE integral_library_types, ONLY: coulomb_operator_type
30 : USE kinds, ONLY: default_path_length,&
31 : dp
32 : USE mathconstants, ONLY: pi
33 : USE message_passing, ONLY: mp_para_env_type
34 : USE t_c_g0, ONLY: free_truncated_table => free_C0,&
35 : get_lmax_init,&
36 : init_truncated_table => init,&
37 : t_c_g0_n
38 : #include "./base/base_uses.f90"
39 :
40 : IMPLICIT NONE
41 : PRIVATE
42 :
43 : PUBLIC :: compute_r12_fundamentals, r12_fundamentals_init, r12_fundamentals_cleanup
44 :
45 : CHARACTER(default_path_length), SAVE :: truncated_filename = ""
46 :
47 : CONTAINS
48 :
49 : ! **************************************************************************************************
50 : !> \brief Prepare shared radial evaluator tables before entering a threaded evaluation region.
51 : !> \param m_max maximum radial order including any derivative increment
52 : !> \param potential_parameter physical radial operator and table filename
53 : !> \param para_env communicator; table initialization is collective on this communicator
54 : !> \note Call outside OpenMP regions. Per-thread integral contexts borrow these read-only tables.
55 : ! **************************************************************************************************
56 65922 : SUBROUTINE r12_fundamentals_init(m_max, potential_parameter, para_env)
57 : INTEGER, INTENT(IN) :: m_max
58 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
59 : TYPE(mp_para_env_type), INTENT(IN) :: para_env
60 :
61 : INTEGER :: table_order, unit_id
62 :
63 65922 : CALL init_md_ftable(m_max)
64 91746 : SELECT CASE (potential_parameter%potential_type)
65 : CASE (do_potential_truncated, do_potential_mix_cl_trunc)
66 65922 : IF (m_max <= get_lmax_init() .AND. potential_parameter%filename == truncated_filename) RETURN
67 : CASE DEFAULT
68 65922 : RETURN
69 : END SELECT
70 :
71 276 : unit_id = -1
72 276 : IF (para_env%is_source()) THEN
73 138 : CALL open_file(unit_number=unit_id, file_name=discover_file(potential_parameter%filename))
74 : END IF
75 276 : table_order = MAX(m_max, get_lmax_init())
76 276 : CALL init_truncated_table(table_order, unit_id, para_env%mepos, para_env)
77 276 : truncated_filename = potential_parameter%filename
78 276 : IF (para_env%is_source()) CALL close_file(unit_id)
79 : END SUBROUTINE r12_fundamentals_init
80 :
81 : ! **************************************************************************************************
82 : !> \brief Release shared radial evaluator tables at process finalization, after their consumers.
83 : ! **************************************************************************************************
84 1492 : SUBROUTINE r12_fundamentals_cleanup()
85 1492 : CALL free_truncated_table()
86 1492 : CALL deallocate_md_ftable()
87 1492 : truncated_filename = ""
88 1492 : END SUBROUTINE r12_fundamentals_cleanup
89 :
90 : ! **************************************************************************************************
91 : !> \brief Compute the unnormalized Coulomb Boys coefficients.
92 : !> \param F coefficients of orders zero through m_max
93 : !> \param m_max maximum order, nonnegative
94 : !> \param T reduced squared distance between Gaussian product centers
95 : ! **************************************************************************************************
96 177095883 : SUBROUTINE compute_coulomb_fundamentals(F, m_max, T)
97 : INTEGER, INTENT(IN) :: m_max
98 : REAL(dp), INTENT(OUT) :: F(m_max + 1)
99 : REAL(dp), INTENT(IN) :: T
100 :
101 177095883 : CALL fgamma(m_max, T, F)
102 177095883 : END SUBROUTINE compute_coulomb_fundamentals
103 :
104 : ! **************************************************************************************************
105 : !> \brief Compute radial coefficients for erf(omega*r)/r.
106 : !> \param F coefficients of orders zero through m_max
107 : !> \param m_max maximum order, nonnegative
108 : !> \param rho reduced Gaussian exponent, positive
109 : !> \param T reduced squared distance between Gaussian product centers
110 : !> \param omega range-separation parameter in inverse length units
111 : ! **************************************************************************************************
112 31418011 : SUBROUTINE compute_long_range_fundamentals(F, m_max, rho, T, omega)
113 : INTEGER, INTENT(IN) :: m_max
114 : REAL(dp), INTENT(OUT) :: F(m_max + 1)
115 : REAL(dp), INTENT(IN) :: rho, T, omega
116 :
117 : INTEGER :: m
118 : REAL(dp) :: omega2, omega_corr2, scaled_T, weight
119 :
120 31418011 : omega2 = omega**2
121 31418011 : omega_corr2 = omega2/(omega2 + rho)
122 31418011 : scaled_T = T*omega_corr2
123 31418011 : CALL fgamma(m_max, scaled_T, F)
124 31418011 : weight = SQRT(omega_corr2)
125 132783352 : DO m = 1, m_max + 1
126 101365341 : F(m) = F(m)*weight
127 132783352 : weight = weight*omega_corr2
128 : END DO
129 31418011 : END SUBROUTINE compute_long_range_fundamentals
130 :
131 : ! **************************************************************************************************
132 : !> \brief Compute radial coefficients for erfc(omega*r)/r.
133 : !> \param F coefficients of orders zero through m_max
134 : !> \param m_max maximum order, nonnegative
135 : !> \param rho reduced Gaussian exponent, positive
136 : !> \param T reduced squared distance between Gaussian product centers
137 : !> \param omega range-separation parameter in inverse length units
138 : !> \param work scratch space for the long-range coefficients
139 : ! **************************************************************************************************
140 16556372 : SUBROUTINE compute_short_range_fundamentals(F, m_max, rho, T, omega, work)
141 : INTEGER, INTENT(IN) :: m_max
142 : REAL(dp), INTENT(OUT) :: F(m_max + 1)
143 : REAL(dp), INTENT(IN) :: rho, T, omega
144 : REAL(dp), INTENT(INOUT) :: work(m_max + 1)
145 :
146 16556372 : CALL compute_coulomb_fundamentals(F, m_max, T)
147 16556372 : CALL compute_long_range_fundamentals(work, m_max, rho, T, omega)
148 77434059 : F = F - work
149 16556372 : END SUBROUTINE compute_short_range_fundamentals
150 :
151 : ! **************************************************************************************************
152 : !> \brief Compute radial coefficients for Coulomb truncated at cutoff_radius.
153 : !> \param F coefficients of orders zero through m_max
154 : !> \param m_max maximum order, nonnegative
155 : !> \param rho reduced Gaussian exponent, positive
156 : !> \param T reduced squared distance between Gaussian product centers
157 : !> \param cutoff_radius truncation radius
158 : !> \note The truncated-Coulomb tables must be initialized before this call.
159 : ! **************************************************************************************************
160 256464349 : SUBROUTINE compute_truncated_fundamentals(F, m_max, rho, T, cutoff_radius)
161 : INTEGER, INTENT(IN) :: m_max
162 : REAL(dp), INTENT(OUT) :: F(m_max + 1)
163 : REAL(dp), INTENT(IN) :: rho, T, cutoff_radius
164 :
165 : LOGICAL :: use_gamma
166 : REAL(dp) :: R
167 :
168 256464349 : R = cutoff_radius*SQRT(rho)
169 256464349 : CALL t_c_g0_n(F, use_gamma, R, T, m_max)
170 256464349 : IF (use_gamma) CALL compute_coulomb_fundamentals(F, m_max, T)
171 256464349 : END SUBROUTINE compute_truncated_fundamentals
172 :
173 : ! **************************************************************************************************
174 : !> \brief Compute radial coefficients for exp(-alpha*r*r).
175 : !> \param F coefficients of orders zero through m_max
176 : !> \param m_max maximum order, nonnegative
177 : !> \param rho reduced Gaussian exponent, positive
178 : !> \param T reduced squared distance between Gaussian product centers
179 : !> \param alpha Gaussian operator exponent in inverse squared length units
180 : ! **************************************************************************************************
181 301982 : SUBROUTINE compute_gaussian_fundamentals(F, m_max, rho, T, alpha)
182 : INTEGER, INTENT(IN) :: m_max
183 : REAL(dp), INTENT(OUT) :: F(m_max + 1)
184 : REAL(dp), INTENT(IN) :: rho, T, alpha
185 :
186 : INTEGER :: m
187 : REAL(dp) :: scaled_T, weight
188 :
189 301982 : scaled_T = -alpha*T/(rho + alpha)
190 301982 : weight = 1.0_dp
191 1104172 : DO m = 1, m_max + 1
192 802190 : F(m) = EXP(scaled_T)*weight
193 1104172 : weight = weight*alpha/(rho + alpha)
194 : END DO
195 301982 : END SUBROUTINE compute_gaussian_fundamentals
196 :
197 : ! **************************************************************************************************
198 : !> \brief Compose radial kernels before applying their common normalization.
199 : !> \param F coefficients of orders zero through m_max, excluding normalization;
200 : !> MIX_LG includes its distinct component normalizations in F
201 : !> \param normalization common multiplicative normalization; one for MIX_LG
202 : !> \param m_max maximum order, nonnegative
203 : !> \param potential_type operator selector from input_constants
204 : !> \param rho reduced Gaussian exponent, positive
205 : !> \param T reduced squared distance between Gaussian product centers
206 : !> \param work reusable scratch space for composing radial kernels
207 : !> \param omega range-separation parameter; Gaussian operators use alpha=omega**2
208 : !> \param cutoff_radius cutoff parameter for truncated Coulomb
209 : !> \param scale_coulomb Coulomb coefficient in mixed operators
210 : !> \param scale_longrange long-range coefficient in mixed operators
211 : !> \param scale_gaussian Gaussian coefficient in mixed operators
212 : !> \note Spatial screening and table initialization belong to the caller.
213 : ! **************************************************************************************************
214 422047141 : SUBROUTINE compute_r12_fundamentals(F, normalization, m_max, potential_type, rho, T, work, &
215 : omega, cutoff_radius, scale_coulomb, scale_longrange, scale_gaussian)
216 : REAL(dp), INTENT(OUT) :: normalization
217 : INTEGER, INTENT(IN) :: m_max
218 : REAL(dp), INTENT(OUT) :: F(m_max + 1)
219 : INTEGER, INTENT(IN) :: potential_type
220 : REAL(dp), INTENT(IN) :: rho, T
221 : REAL(dp), INTENT(INOUT) :: work(m_max + 1)
222 : REAL(dp), INTENT(IN) :: omega, cutoff_radius, scale_coulomb, &
223 : scale_longrange, scale_gaussian
224 :
225 : REAL(dp) :: gaussian_normalization
226 :
227 422047141 : normalization = 2.0_dp*pi/rho
228 564581080 : SELECT CASE (potential_type)
229 : CASE (do_potential_coulomb)
230 142533939 : CALL compute_coulomb_fundamentals(F, m_max, T)
231 : CASE (do_potential_truncated)
232 248095191 : CALL compute_truncated_fundamentals(F, m_max, rho, T, cutoff_radius)
233 : CASE (do_potential_short)
234 16556372 : CALL compute_short_range_fundamentals(F, m_max, rho, T, omega, work)
235 : CASE (do_potential_long)
236 2077323 : CALL compute_long_range_fundamentals(F, m_max, rho, T, omega)
237 : CASE (do_potential_gaussian)
238 0 : CALL compute_gaussian_fundamentals(F, m_max, rho, T, omega**2)
239 0 : normalization = (pi/(rho + omega**2))**1.5_dp
240 : CASE (do_potential_mix_cl)
241 4113176 : CALL compute_coulomb_fundamentals(F, m_max, T)
242 4113176 : CALL compute_long_range_fundamentals(work, m_max, rho, T, omega)
243 14752877 : F = F*scale_coulomb + work*scale_longrange
244 : CASE (do_potential_mix_cl_trunc)
245 8369158 : CALL compute_truncated_fundamentals(F, m_max, rho, T, cutoff_radius)
246 8369158 : CALL compute_coulomb_fundamentals(work, m_max, T)
247 32066925 : F = F*(scale_coulomb + scale_longrange) - work*scale_longrange
248 8369158 : CALL compute_long_range_fundamentals(work, m_max, rho, T, omega)
249 32066925 : F = F + work*scale_longrange
250 : CASE (do_potential_mix_lg)
251 301982 : CALL compute_long_range_fundamentals(F, m_max, rho, T, omega)
252 301982 : CALL compute_gaussian_fundamentals(work, m_max, rho, T, omega**2)
253 301982 : gaussian_normalization = (pi/(rho + omega**2))**1.5_dp
254 1104172 : F = work*gaussian_normalization*scale_gaussian + F*normalization*scale_longrange
255 301982 : normalization = 1.0_dp
256 : CASE DEFAULT
257 422047141 : CPABORT("Unsupported operator for radial r12 fundamentals")
258 : END SELECT
259 422047141 : END SUBROUTINE compute_r12_fundamentals
260 :
261 : END MODULE r12_fundamentals
|