(git:98357aa)
Loading...
Searching...
No Matches
eri_mme_error_control.F
Go to the documentation of this file.
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 Methods aiming for error estimate and automatic cutoff calibration.
10!> integrals.
11!> \par History
12!> 2015 09 created
13!> \author Patrick Seewald
14! **************************************************************************************************
15
17 USE ao_util, ONLY: exp_radius
21 USE kinds, ONLY: dp
22 USE mathconstants, ONLY: pi,&
23 twopi
25#include "../base/base_uses.f90"
26
27 IMPLICIT NONE
28
29 PRIVATE
30
31 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
32
33 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'eri_mme_error_control'
34
36CONTAINS
37
38! **************************************************************************************************
39!> \brief Find optimal cutoff minimizing errors due to minimax approximation and
40!> due to finite cutoff using bisection on the difference of the errors
41!> \param hmat ...
42!> \param h_inv ...
43!> \param G_min ...
44!> \param vol ...
45!> \param zet_min Minimum exponent
46!> \param l_mm Total ang. mom. quantum number
47!> \param zet_max Max. exponents to estimate cutoff error
48!> \param l_max_zet Max. total ang. mom. quantum numbers to estimate cutoff error
49!> \param n_minimax Number of terms in minimax approximation
50!> \param cutoff_l Initial guess of lower bound for cutoff
51!> \param cutoff_r Initial guess of upper bound for cutoff
52!> \param tol Tolerance (cutoff precision)
53!> \param delta to modify initial guess interval
54!> \param cutoff Best cutoff
55!> \param err_mm Minimax error
56!> \param err_c Cutoff error
57!> \param C_mm Scaling constant to generalize AM-GM upper bound estimate to
58!> minimax approx.
59!> \param para_env ...
60!> \param print_calib ...
61!> \param unit_nr ...
62! **************************************************************************************************
63 SUBROUTINE calibrate_cutoff(hmat, h_inv, G_min, vol, zet_min, l_mm, zet_max, l_max_zet, &
64 n_minimax, cutoff_l, cutoff_r, tol, delta, &
65 cutoff, err_mm, err_c, C_mm, para_env, print_calib, unit_nr)
66 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: hmat, h_inv
67 REAL(kind=dp), INTENT(IN) :: g_min
68 REAL(kind=dp) :: vol
69 REAL(kind=dp), INTENT(IN) :: zet_min
70 INTEGER, INTENT(IN) :: l_mm
71 REAL(kind=dp), INTENT(IN) :: zet_max
72 INTEGER, INTENT(IN) :: l_max_zet, n_minimax
73 REAL(kind=dp), INTENT(IN) :: cutoff_l, cutoff_r, tol, delta
74 REAL(kind=dp), INTENT(OUT) :: cutoff, err_mm, err_c, c_mm
75 TYPE(mp_para_env_type), INTENT(IN) :: para_env
76 LOGICAL, INTENT(IN) :: print_calib
77 INTEGER, INTENT(IN) :: unit_nr
78
79 INTEGER :: i, iter1, iter2, max_iter
80 LOGICAL :: do_print, valid_initial
81 REAL(kind=dp) :: cutoff_mid, delta_c_mid, delta_mm_mid
82 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: minimax_aw
83 REAL(kind=dp), DIMENSION(2) :: cutoff_lr, delta_c, delta_mm
84
85 do_print = unit_nr > 0 .AND. print_calib
86 IF (do_print) THEN
87 WRITE (unit_nr, '(/T2, A)') "ERI_MME| Basis set parameters for estimating minimax error"
88 WRITE (unit_nr, '(T2, A, T67, ES12.2, 1X, I1)') "ERI_MME| exp, l:", zet_min, l_mm
89 WRITE (unit_nr, '(T2, A)') "ERI_MME| Basis set parameters for estimating cutoff error"
90 WRITE (unit_nr, '(T2, A, T67, ES12.2, 1X, I1)') "ERI_MME| exp, l:", zet_max, l_max_zet
91 END IF
92
93 max_iter = 100
94
95 IF ((cutoff_r - cutoff_l)/(0.5_dp*(cutoff_r + cutoff_l)) <= tol) THEN
96 CALL cp_abort(__location__, "difference of boundaries for cutoff "// &
97 "(MAX - MIN) must be greater than cutoff precision.")
98 END IF
99
100 IF ((delta >= 1.0_dp) .OR. (delta <= 0.0_dp)) THEN
101 CALL cp_abort(__location__, &
102 "relative delta to modify initial cutoff interval (DELTA) must be in (0, 1)")
103 END IF
104
105 cutoff_lr(1) = cutoff_l
106 cutoff_lr(2) = cutoff_r
107
108 ALLOCATE (minimax_aw(2*n_minimax))
109
110 IF (do_print) THEN
111 WRITE (unit_nr, '(/T2, A)') "ERI_MME| Calibrating cutoff by bisecting error(minimax) - error(cutoff)"
112 WRITE (unit_nr, '(T2, A, T72, ES9.2)') "ERI_MME| Rel. cutoff precision", tol
113 WRITE (unit_nr, '(T2, A, T77, F4.1)') "ERI_MME| Rel. cutoff delta to modify initial interval", delta
114 END IF
115
116 ! 1) find valid initial values for bisection
117 DO iter1 = 1, max_iter + 1
118 IF (iter1 > max_iter) THEN
119 CALL cp_abort(__location__, &
120 "Maximum number of iterations in bisection to determine initial "// &
121 "cutoff interval has been exceeded.")
122 END IF
123
124 cutoff_lr(1) = max(cutoff_lr(1), 0.5_dp*g_min**2)
125 ! approx.) is hit
126
127 DO i = 1, 2
128 CALL cutoff_minimax_error(cutoff_lr(i), hmat, h_inv, vol, g_min, zet_min, l_mm, zet_max, l_max_zet, &
129 n_minimax, minimax_aw, delta_mm(i), delta_c(i), c_mm, para_env)
130 END DO
131
132 valid_initial = .true.
133 IF ((delta_mm(1) - delta_c(1)) > 0) THEN
134 cutoff_lr(1) = cutoff_lr(1)*(1.0_dp - abs(delta))
135 valid_initial = .false.
136 END IF
137 IF ((delta_mm(2) - delta_c(2)) < 0) THEN
138 cutoff_lr(2) = cutoff_lr(2)*(1.0_dp + abs(delta))
139 valid_initial = .false.
140 END IF
141
142 IF (valid_initial) EXIT
143 END DO
144
145 ! 2) bisection to find cutoff s.t. err_minimax(cutoff) - err_cutoff(cutoff) = 0
146 IF (do_print) WRITE (unit_nr, '(/T2, A)') &
147 "ERI_MME| Step, cutoff (min, max, mid), err(minimax), err(cutoff), err diff"
148
149 DO iter2 = 1, max_iter + 1
150 IF (iter2 > max_iter) THEN
151 CALL cp_abort(__location__, &
152 "Maximum number of iterations in bisection to determine cutoff has been exceeded")
153 END IF
154
155 cutoff_mid = 0.5_dp*(cutoff_lr(1) + cutoff_lr(2))
156 CALL cutoff_minimax_error(cutoff_mid, hmat, h_inv, vol, g_min, zet_min, l_mm, zet_max, l_max_zet, &
157 n_minimax, minimax_aw, delta_mm_mid, delta_c_mid, c_mm, para_env)
158 IF (do_print) WRITE (unit_nr, '(T11, I2, F11.1, F11.1, F11.1, 3X, ES9.2, 3X, ES9.2, 3X, ES9.2)') &
159 iter2, cutoff_lr(1), cutoff_lr(2), cutoff_mid, &
160 delta_mm_mid, delta_c_mid, delta_mm_mid - delta_c_mid
161
162 IF ((cutoff_lr(2) - cutoff_lr(1))/cutoff_mid < tol) EXIT
163 IF (delta_mm_mid - delta_c_mid > 0) THEN
164 cutoff_lr(2) = cutoff_mid
165 delta_mm(2) = delta_mm_mid
166 delta_c(2) = delta_c_mid
167 ELSE
168 cutoff_lr(1) = cutoff_mid
169 delta_mm(1) = delta_mm_mid
170 delta_c(1) = delta_c_mid
171 END IF
172 END DO
173 err_mm = delta_mm_mid
174 err_c = delta_c_mid
175 cutoff = cutoff_mid
176
177 IF (do_print) THEN
178 WRITE (unit_nr, '(/T2, A)') "ERI_MME| Cutoff calibration number of steps:"
179 WRITE (unit_nr, '(T2, A, T79, I2)') "ERI_MME| Steps for initial interval", iter1 - 1
180 WRITE (unit_nr, '(T2, A, T79, I2/)') "ERI_MME| Bisection iteration steps", iter2 - 1
181 END IF
182
183 END SUBROUTINE calibrate_cutoff
184
185! **************************************************************************************************
186!> \brief Compute upper bounds for the errors of 2-center ERI's (P|P) due
187!> to minimax approximation and due to finite cutoff, where P is a
188!> normalized Hermite Gaussian.
189!> \param cutoff ...
190!> \param hmat ...
191!> \param h_inv ...
192!> \param vol ...
193!> \param G_min ...
194!> \param zet_min Exponent of P to estimate minimax error
195!> \param l_mm total ang. mom. quantum number of P to estimate minimax error
196!> \param zet_max Max. exponents of P to estimate cutoff error
197!> \param l_max_zet Max. total ang. mom. quantum numbers of P to estimate cutoff error
198!> \param n_minimax Number of terms in minimax approximation
199!> \param minimax_aw Minimax coefficients
200!> \param err_mm Minimax error
201!> \param err_ctff Cutoff error
202!> \param C_mm Scaling constant to generalize AM-GM upper bound estimate to
203!> minimax approx.
204!> \param para_env ...
205! **************************************************************************************************
206 SUBROUTINE cutoff_minimax_error(cutoff, hmat, h_inv, vol, G_min, zet_min, l_mm, zet_max, l_max_zet, &
207 n_minimax, minimax_aw, err_mm, err_ctff, C_mm, para_env)
208 REAL(kind=dp), INTENT(IN) :: cutoff
209 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: hmat, h_inv
210 REAL(kind=dp), INTENT(IN) :: vol, g_min, zet_min
211 INTEGER, INTENT(IN) :: l_mm
212 REAL(kind=dp), INTENT(IN) :: zet_max
213 INTEGER, INTENT(IN) :: l_max_zet, n_minimax
214 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: minimax_aw
215 REAL(kind=dp), INTENT(OUT) :: err_mm, err_ctff, c_mm
216 TYPE(mp_para_env_type), INTENT(IN) :: para_env
217
218 REAL(kind=dp) :: delta_mm
219
220 CALL minimax_error(cutoff, hmat, vol, g_min, zet_min, l_mm, &
221 n_minimax, minimax_aw, err_mm, delta_mm)
222 CALL cutoff_error(cutoff, h_inv, g_min, zet_max, l_max_zet, &
223 n_minimax, minimax_aw, err_ctff, c_mm, para_env)
224
225 END SUBROUTINE cutoff_minimax_error
226
227! **************************************************************************************************
228!> \brief Minimax error, simple analytical formula
229!> Note minimax error may blow up for small exponents. This is also observed numerically,
230!> but in this case, error estimate is no upper bound.
231!> \param cutoff ...
232!> \param hmat ...
233!> \param vol ...
234!> \param G_min ...
235!> \param zet_min Exponent of P to estimate minimax error
236!> \param l_mm total ang. mom. quantum number of P to estimate minimax error
237!> \param n_minimax Number of terms in minimax approximation
238!> \param minimax_aw Minimax coefficients
239!> \param err_mm Minimax error
240!> \param delta_mm ...
241!> \param potential ...
242!> \param pot_par ...
243! **************************************************************************************************
244 SUBROUTINE minimax_error(cutoff, hmat, vol, G_min, zet_min, l_mm, &
245 n_minimax, minimax_aw, err_mm, delta_mm, potential, pot_par)
246 REAL(kind=dp), INTENT(IN) :: cutoff
247 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: hmat
248 REAL(kind=dp), INTENT(IN) :: vol, g_min, zet_min
249 INTEGER, INTENT(IN) :: l_mm, n_minimax
250 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: minimax_aw
251 REAL(kind=dp), INTENT(OUT) :: err_mm, delta_mm
252 INTEGER, INTENT(IN), OPTIONAL :: potential
253 REAL(kind=dp), INTENT(IN), OPTIONAL :: pot_par
254
255 INTEGER :: i_xyz
256 REAL(kind=dp) :: prod_mm_k
257
258 CALL get_minimax_coeff_v_gspace(n_minimax, cutoff, g_min, minimax_aw(:), &
259 potential=potential, pot_par=pot_par, err_minimax=delta_mm)
260
261 prod_mm_k = 1.0_dp
262 DO i_xyz = 1, 3
263 prod_mm_k = prod_mm_k*(abs(hmat(i_xyz, i_xyz))/twopi + &
264 merge(sqrt(2.0_dp/(zet_min*pi))*exp(-1.0_dp), 0.0_dp, l_mm > 0))
265 END DO
266 err_mm = 32*pi**4/vol*delta_mm*prod_mm_k
267
268 END SUBROUTINE minimax_error
269
270! **************************************************************************************************
271!> \brief Cutoff error, estimating G > G_c part of Ewald sum by using C/3 * 1/(Gx^2*Gy^2*Gz^2)^1/3 as an
272!> upper bound for 1/G^2 (AM-GM inequality) and its minimax approximation (factor C).
273!>
274!> Note: usually, minimax approx. falls off faster than 1/G**2, so C should be approximately 1.
275!> The error is calculated for all l up to l_max and golden section search algorithm is
276!> applied to find the exponent that maximizes cutoff error.
277!> \param cutoff ...
278!> \param h_inv ...
279!> \param G_min ...
280!> \param zet_max Max. exponents of P to estimate cutoff error
281!> \param l_max_zet Max. total ang. mom. quantum numbers of P to estimate cutoff error
282!> \param n_minimax Number of terms in minimax approximation
283!> \param minimax_aw Minimax coefficients
284!> \param err_ctff Cutoff error
285!> \param C_mm Scaling constant to generalize AM-GM upper bound estimate to
286!> minimax approx.
287!> \param para_env ...
288! **************************************************************************************************
289 SUBROUTINE cutoff_error(cutoff, h_inv, G_min, zet_max, l_max_zet, &
290 n_minimax, minimax_aw, err_ctff, C_mm, para_env)
291 REAL(kind=dp), INTENT(IN) :: cutoff
292 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: h_inv
293 REAL(kind=dp), INTENT(IN) :: g_min, zet_max
294 INTEGER, INTENT(IN) :: l_max_zet, n_minimax
295 REAL(kind=dp), DIMENSION(:), INTENT(INOUT) :: minimax_aw
296 REAL(kind=dp), INTENT(OUT) :: err_ctff, c_mm
297 TYPE(mp_para_env_type), INTENT(IN) :: para_env
298
299 INTEGER :: i_aw, ig, iter, max_iter, ng
300 REAL(kind=dp) :: c, dg, eps_zet, err0, err1, err_c, err_ctff_curr, err_ctff_prev, err_d, g, &
301 g_1, g_c, gr, zet_a, zet_b, zet_c, zet_d, zet_div, zet_max_tmp
302
303 ! parameters for finding exponent maximizing cutoff error
304
305 eps_zet = 1.0e-05_dp ! tolerance for exponent
306 zet_div = 2.0_dp ! sampling constant for finding initial values of exponents
307 max_iter = 100 ! maximum number of iterations in golden section search
308 g_c = sqrt(2.0*cutoff)
309
310 zet_max_tmp = zet_max
311
312 ! 2) Cutoff error, estimating G > G_c part of Ewald sum by using C/3 * 1/(Gx^2*Gy^2*Gz^2)^1/3 as an
313 ! upper bound for 1/G^2 (AM-GM inequality) and its minimax approximation (factor C).
314 ! Note: usually, minimax approx. falls off faster than 1/G**2, so C should be approximately 1.
315 ! The error is calculated for all l up to l_max and golden section search algorithm is
316 ! applied to find the exponent that maximizes cutoff error.
317 g_1 = sqrt(1.0_dp/(3.0_dp*minval(minimax_aw(1:n_minimax))))
318
319 c_mm = 0.0_dp
320 IF (g_1 > g_c) THEN
321 ng = 1000
322 dg = (g_1 - g_c)/ng
323 g = g_c
324 DO ig = 1, ng
325 g = min(g, g_c)
326 c = 0.0_dp
327 DO i_aw = 1, n_minimax
328 c = c + 3.0_dp*minimax_aw(n_minimax + i_aw)*exp(-3.0_dp*minimax_aw(i_aw)*g**2)*g**2
329 END DO
330 c_mm = max(c, c_mm)
331 g = g + dg
332 END DO
333 ELSE
334 DO i_aw = 1, n_minimax
335 c_mm = c_mm + 3.0_dp*minimax_aw(n_minimax + i_aw)*exp(-3.0_dp*minimax_aw(i_aw)*g_c**2)*g_c**2
336 END DO
337 END IF
338 c = max(1.0_dp, c_mm)
339
340 err_ctff_prev = 0.0_dp
341 gr = 0.5_dp*(sqrt(5.0_dp) - 1.0_dp) ! golden ratio
342 ! Find valid starting values for golden section search
343 DO iter = 1, max_iter + 1
344 IF (iter > max_iter) THEN
345 CALL cp_abort(__location__, "Maximum number of iterations for finding "// &
346 "exponent maximizing cutoff error has been exceeded.")
347 END IF
348
349 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_max_tmp, c, err_ctff_curr, para_env)
350 IF (err_ctff_prev >= err_ctff_curr) THEN
351 zet_a = zet_max_tmp
352 zet_b = min(zet_max_tmp*zet_div**2, zet_max)
353 EXIT
354 ELSE
355 err_ctff_prev = err_ctff_curr
356 END IF
357 zet_max_tmp = zet_max_tmp/zet_div
358 END DO
359
360 ! Golden section search
361 zet_c = zet_b - gr*(zet_b - zet_a)
362 zet_d = zet_a + gr*(zet_b - zet_a)
363 DO iter = 1, max_iter + 1
364 IF (abs(zet_c - zet_d) < eps_zet*(zet_a + zet_b)) THEN
365 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_a, c, err0, para_env)
366 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_b, c, err1, para_env)
367 err_ctff_curr = max(err0, err1)
368 EXIT
369 END IF
370 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_c, c, err_c, para_env)
371 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_d, c, err_d, para_env)
372 IF (err_c > err_d) THEN
373 zet_b = zet_d
374 zet_d = zet_c
375 zet_c = zet_b - gr*(zet_b - zet_a)
376 ELSE
377 zet_a = zet_c
378 zet_c = zet_d
379 zet_d = zet_a + gr*(zet_b - zet_a)
380 END IF
381 END DO
382 err_ctff = err_ctff_curr
383
384 END SUBROUTINE cutoff_error
385
386! **************************************************************************************************
387!> \brief Calculate cutoff error estimate by using C_mm/3 * 1/(Gx^2*Gy^2*Gz^2)^1/3
388!> as an upper bound for 1/G^2 (and its minimax approximation) for |G| > G_c.
389!> Error is referring to a basis function P with fixed exponent zet_max and
390!> max. angular momentum l_max_zet.
391!> \param cutoff ...
392!> \param h_inv ...
393!> \param G_min ...
394!> \param l_max_zet ...
395!> \param zet_max ...
396!> \param C_mm ...
397!> \param err_c ...
398!> \param para_env ...
399! **************************************************************************************************
400 SUBROUTINE cutoff_error_fixed_exp(cutoff, h_inv, G_min, l_max_zet, zet_max, C_mm, err_c, para_env)
401 REAL(kind=dp), INTENT(IN) :: cutoff
402 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: h_inv
403 REAL(kind=dp), INTENT(IN) :: g_min
404 INTEGER, INTENT(IN) :: l_max_zet
405 REAL(kind=dp), INTENT(IN) :: zet_max, c_mm
406 REAL(kind=dp), INTENT(OUT) :: err_c
407 TYPE(mp_para_env_type), INTENT(IN) :: para_env
408
409 INTEGER :: ax, ay, az, g_l, g_u, gl_first, gl_last, &
410 gu_first, gu_last, i_xyz, l, my_p, &
411 n_gl, n_gl_left, n_gl_p, n_gu, &
412 n_gu_left, n_gu_p, n_p
413 REAL(kind=dp) :: alpha_g, eps_g, err_c_l, g_c, g_rad, &
414 g_res, inv_lgth, prefactor, sum_g_diff
415 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: s_g_l, s_g_u
416
417 g_c = sqrt(2.0_dp*cutoff)
418 eps_g = tiny(eps_g) ! sum up to machine precision
419 g_res = 0.5_dp*g_min ! resolution for screening
420
421 err_c = 0.0_dp
422 alpha_g = 1.0_dp/(2.0_dp*zet_max)
423 prefactor = 1.0_dp/zet_max
424
425 ALLOCATE (s_g_l(0:2*l_max_zet, 3))
426 ALLOCATE (s_g_u(0:2*l_max_zet, 3))
427
428 g_rad = exp_radius(2*l_max_zet, alpha_g, eps_g, prefactor, epsabs=g_res)
429
430 ! Parallelization of sum over G vectors
431 my_p = para_env%mepos ! mpi rank
432 n_p = para_env%num_pe ! total number of processes
433
434 DO i_xyz = 1, 3
435 inv_lgth = abs(h_inv(i_xyz, i_xyz))
436
437 g_l = floor(g_c/(inv_lgth*twopi))
438 g_u = floor(g_rad/(inv_lgth*twopi))
439
440 IF (g_u < g_l) g_u = g_l
441
442 ! Serial code:
443 ! !Sum |G| <= G_c
444 ! CALL pgf_sum_2c_gspace_1d_deltal(S_G_l(:, i_xyz), alpha_G, inv_lgth, -G_l, G_l, &
445 ! 2.0_dp/3.0_dp, prefactor)
446 ! !Sum |G| > G_c
447 ! CALL pgf_sum_2c_gspace_1d_deltal(S_G_u(:, i_xyz), alpha_G, inv_lgth, G_l + 1, G_u, &
448 ! 2.0_dp/3.0_dp, prefactor)
449
450 ! Parallel code:
451 n_gu = max((g_u - g_l), 0)
452 n_gl = 2*g_l + 1
453 n_gu_p = n_gu/n_p
454 n_gl_p = n_gl/n_p
455 n_gu_left = mod(n_gu, n_p)
456 n_gl_left = mod(n_gl, n_p)
457
458 IF (my_p < n_gu_left) THEN
459 gu_first = g_l + 1 + (n_gu_p + 1)*my_p
460 gu_last = g_l + 1 + (n_gu_p + 1)*(my_p + 1) - 1
461 ELSE
462 gu_first = g_l + 1 + n_gu_left + n_gu_p*my_p
463 gu_last = g_l + 1 + n_gu_left + n_gu_p*(my_p + 1) - 1
464 END IF
465
466 IF (my_p < n_gl_left) THEN
467 gl_first = -g_l + (n_gl_p + 1)*my_p
468 gl_last = -g_l + (n_gl_p + 1)*(my_p + 1) - 1
469 ELSE
470 gl_first = -g_l + n_gl_left + n_gl_p*my_p
471 gl_last = -g_l + n_gl_left + n_gl_p*(my_p + 1) - 1
472 END IF
473
474 ! Sum |G| <= G_c
475 CALL pgf_sum_2c_gspace_1d_deltal(s_g_l(:, i_xyz), alpha_g, inv_lgth, gl_first, gl_last, &
476 2.0_dp/3.0_dp, prefactor)
477
478 ! Sum |G| > G_c
479 CALL pgf_sum_2c_gspace_1d_deltal(s_g_u(:, i_xyz), alpha_g, inv_lgth, gu_first, gu_last, &
480 2.0_dp/3.0_dp, prefactor)
481 END DO
482
483 CALL para_env%sum(s_g_l)
484 CALL para_env%sum(s_g_u)
485
486 s_g_u = s_g_u*2.0_dp ! to include negative values of G
487
488 DO l = 0, l_max_zet
489 DO ax = 0, l
490 DO ay = 0, l - ax
491 az = l - ax - ay
492
493 ! Compute prod_k (S_G_l(l_k,k) + S_G_u(l_k,k)) - prod_k (S_G_l(l_k,k)) with k in {x, y, z}
494 ! Note: term by term multiplication to avoid subtraction for numerical stability
495 sum_g_diff = s_g_u(2*ax, 1)*s_g_u(2*ay, 2)*s_g_u(2*az, 3) + &
496 s_g_u(2*ax, 1)*s_g_u(2*ay, 2)*s_g_l(2*az, 3) + &
497 s_g_u(2*ax, 1)*s_g_l(2*ay, 2)*s_g_u(2*az, 3) + &
498 s_g_l(2*ax, 1)*s_g_u(2*ay, 2)*s_g_u(2*az, 3) + &
499 s_g_u(2*ax, 1)*s_g_l(2*ay, 2)*s_g_l(2*az, 3) + &
500 s_g_l(2*ax, 1)*s_g_u(2*ay, 2)*s_g_l(2*az, 3) + &
501 s_g_l(2*ax, 1)*s_g_l(2*ay, 2)*s_g_u(2*az, 3)
502
503 err_c_l = 4.0_dp*pi**4*hermite_gauss_norm(zet_max, [ax, ay, az])**2* &
504 c_mm/3.0_dp*sum_g_diff
505
506 err_c = max(err_c, err_c_l)
507 END DO
508 END DO
509 END DO
510
511 DEALLOCATE (s_g_u, s_g_l)
512
513 END SUBROUTINE cutoff_error_fixed_exp
514
515END MODULE eri_mme_error_control
All kind of helpful little routines.
Definition ao_util.F:14
real(kind=dp) function, public exp_radius(l, alpha, threshold, prefactor, epsabs, epsrel, rlow)
The radius of a primitive Gaussian function for a given threshold is calculated. g(r) = prefactor*r**...
Definition ao_util.F:96
Methods aiming for error estimate and automatic cutoff calibration. integrals.
subroutine, public cutoff_error(cutoff, h_inv, g_min, zet_max, l_max_zet, n_minimax, minimax_aw, err_ctff, c_mm, para_env)
Cutoff error, estimating G > G_c part of Ewald sum by using C/3 * 1/(Gx^2*Gy^2*Gz^2)^1/3 as an upper ...
subroutine, public cutoff_minimax_error(cutoff, hmat, h_inv, vol, g_min, zet_min, l_mm, zet_max, l_max_zet, n_minimax, minimax_aw, err_mm, err_ctff, c_mm, para_env)
Compute upper bounds for the errors of 2-center ERI's (P|P) due to minimax approximation and due to f...
subroutine, public calibrate_cutoff(hmat, h_inv, g_min, vol, zet_min, l_mm, zet_max, l_max_zet, n_minimax, cutoff_l, cutoff_r, tol, delta, cutoff, err_mm, err_c, c_mm, para_env, print_calib, unit_nr)
Find optimal cutoff minimizing errors due to minimax approximation and due to finite cutoff using bis...
subroutine, public minimax_error(cutoff, hmat, vol, g_min, zet_min, l_mm, n_minimax, minimax_aw, err_mm, delta_mm, potential, pot_par)
Minimax error, simple analytical formula Note minimax error may blow up for small exponents....
Methods related to properties of Hermite and Cartesian Gaussian functions.
pure real(kind=dp) function, public hermite_gauss_norm(zet, l)
Norm of 1d Hermite-Gauss functions.
subroutine, public get_minimax_coeff_v_gspace(n_minimax, cutoff, g_min, minimax_aw, potential, pot_par, err_minimax)
Get minimax coefficient a_i and w_i for approximating 1/G^2 by sum_i w_i exp(-a_i G^2)
Ewald sums to represent integrals in direct and reciprocal lattice.
pure subroutine, public pgf_sum_2c_gspace_1d_deltal(s_g, alpha, inv_lgth, g_min, g_c, delta_l, prefactor)
Compute 1d sum S_G(l, alpha) = inv_lgth*sum_G( C(l, alpha, delta_l, G) ) with C(l,...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), parameter, public twopi
Interface to the message passing library MPI.
stores all the informations relevant to an mpi environment