(git:374b731)
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-2024 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)) .LE. tol) &
96 CALL cp_abort(__location__, "difference of boundaries for cutoff "// &
97 "(MAX - MIN) must be greater than cutoff precision.")
98
99 IF ((delta .GE. 1.0_dp) .OR. (delta .LE. 0.0_dp)) &
100 CALL cp_abort(__location__, &
101 "relative delta to modify initial cutoff interval (DELTA) must be in (0, 1)")
102
103 cutoff_lr(1) = cutoff_l
104 cutoff_lr(2) = cutoff_r
105
106 ALLOCATE (minimax_aw(2*n_minimax))
107
108 IF (do_print) THEN
109 WRITE (unit_nr, '(/T2, A)') "ERI_MME| Calibrating cutoff by bisecting error(minimax) - error(cutoff)"
110 WRITE (unit_nr, '(T2, A, T72, ES9.2)') "ERI_MME| Rel. cutoff precision", tol
111 WRITE (unit_nr, '(T2, A, T77, F4.1)') "ERI_MME| Rel. cutoff delta to modify initial interval", delta
112 END IF
113
114 ! 1) find valid initial values for bisection
115 DO iter1 = 1, max_iter + 1
116 IF (iter1 .GT. max_iter) &
117 CALL cp_abort(__location__, &
118 "Maximum number of iterations in bisection to determine initial "// &
119 "cutoff interval has been exceeded.")
120
121 cutoff_lr(1) = max(cutoff_lr(1), 0.5_dp*g_min**2)
122 ! approx.) is hit
123
124 DO i = 1, 2
125 CALL cutoff_minimax_error(cutoff_lr(i), hmat, h_inv, vol, g_min, zet_min, l_mm, zet_max, l_max_zet, &
126 n_minimax, minimax_aw, delta_mm(i), delta_c(i), c_mm, para_env)
127 END DO
128
129 valid_initial = .true.
130 IF ((delta_mm(1) - delta_c(1)) .GT. 0) THEN
131 cutoff_lr(1) = cutoff_lr(1)*(1.0_dp - abs(delta))
132 valid_initial = .false.
133 END IF
134 IF ((delta_mm(2) - delta_c(2)) .LT. 0) THEN
135 cutoff_lr(2) = cutoff_lr(2)*(1.0_dp + abs(delta))
136 valid_initial = .false.
137 END IF
138
139 IF (valid_initial) EXIT
140 END DO
141
142 ! 2) bisection to find cutoff s.t. err_minimax(cutoff) - err_cutoff(cutoff) = 0
143 IF (do_print) WRITE (unit_nr, '(/T2, A)') &
144 "ERI_MME| Step, cutoff (min, max, mid), err(minimax), err(cutoff), err diff"
145
146 DO iter2 = 1, max_iter + 1
147 IF (iter2 .GT. max_iter) &
148 CALL cp_abort(__location__, &
149 "Maximum number of iterations in bisection to determine cutoff has been exceeded")
150
151 cutoff_mid = 0.5_dp*(cutoff_lr(1) + cutoff_lr(2))
152 CALL cutoff_minimax_error(cutoff_mid, hmat, h_inv, vol, g_min, zet_min, l_mm, zet_max, l_max_zet, &
153 n_minimax, minimax_aw, delta_mm_mid, delta_c_mid, c_mm, para_env)
154 IF (do_print) WRITE (unit_nr, '(T11, I2, F11.1, F11.1, F11.1, 3X, ES9.2, 3X, ES9.2, 3X, ES9.2)') &
155 iter2, cutoff_lr(1), cutoff_lr(2), cutoff_mid, &
156 delta_mm_mid, delta_c_mid, delta_mm_mid - delta_c_mid
157
158 IF ((cutoff_lr(2) - cutoff_lr(1))/cutoff_mid .LT. tol) EXIT
159 IF (delta_mm_mid - delta_c_mid .GT. 0) THEN
160 cutoff_lr(2) = cutoff_mid
161 delta_mm(2) = delta_mm_mid
162 delta_c(2) = delta_c_mid
163 ELSE
164 cutoff_lr(1) = cutoff_mid
165 delta_mm(1) = delta_mm_mid
166 delta_c(1) = delta_c_mid
167 END IF
168 END DO
169 err_mm = delta_mm_mid
170 err_c = delta_c_mid
171 cutoff = cutoff_mid
172
173 IF (do_print) THEN
174 WRITE (unit_nr, '(/T2, A)') "ERI_MME| Cutoff calibration number of steps:"
175 WRITE (unit_nr, '(T2, A, T79, I2)') "ERI_MME| Steps for initial interval", iter1 - 1
176 WRITE (unit_nr, '(T2, A, T79, I2/)') "ERI_MME| Bisection iteration steps", iter2 - 1
177 END IF
178
179 END SUBROUTINE calibrate_cutoff
180
181! **************************************************************************************************
182!> \brief Compute upper bounds for the errors of 2-center ERI's (P|P) due
183!> to minimax approximation and due to finite cutoff, where P is a
184!> normalized Hermite Gaussian.
185!> \param cutoff ...
186!> \param hmat ...
187!> \param h_inv ...
188!> \param vol ...
189!> \param G_min ...
190!> \param zet_min Exponent of P to estimate minimax error
191!> \param l_mm total ang. mom. quantum number of P to estimate minimax error
192!> \param zet_max Max. exponents of P to estimate cutoff error
193!> \param l_max_zet Max. total ang. mom. quantum numbers of P to estimate cutoff error
194!> \param n_minimax Number of terms in minimax approximation
195!> \param minimax_aw Minimax coefficients
196!> \param err_mm Minimax error
197!> \param err_ctff Cutoff error
198!> \param C_mm Scaling constant to generalize AM-GM upper bound estimate to
199!> minimax approx.
200!> \param para_env ...
201! **************************************************************************************************
202 SUBROUTINE cutoff_minimax_error(cutoff, hmat, h_inv, vol, G_min, zet_min, l_mm, zet_max, l_max_zet, &
203 n_minimax, minimax_aw, err_mm, err_ctff, C_mm, para_env)
204 REAL(kind=dp), INTENT(IN) :: cutoff
205 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: hmat, h_inv
206 REAL(kind=dp), INTENT(IN) :: vol, g_min, zet_min
207 INTEGER, INTENT(IN) :: l_mm
208 REAL(kind=dp), INTENT(IN) :: zet_max
209 INTEGER, INTENT(IN) :: l_max_zet, n_minimax
210 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: minimax_aw
211 REAL(kind=dp), INTENT(OUT) :: err_mm, err_ctff, c_mm
212 TYPE(mp_para_env_type), INTENT(IN) :: para_env
213
214 REAL(kind=dp) :: delta_mm
215
216 CALL minimax_error(cutoff, hmat, vol, g_min, zet_min, l_mm, &
217 n_minimax, minimax_aw, err_mm, delta_mm)
218 CALL cutoff_error(cutoff, h_inv, g_min, zet_max, l_max_zet, &
219 n_minimax, minimax_aw, err_ctff, c_mm, para_env)
220
221 END SUBROUTINE cutoff_minimax_error
222
223! **************************************************************************************************
224!> \brief Minimax error, simple analytical formula
225!> Note minimax error may blow up for small exponents. This is also observed numerically,
226!> but in this case, error estimate is no upper bound.
227!> \param cutoff ...
228!> \param hmat ...
229!> \param vol ...
230!> \param G_min ...
231!> \param zet_min Exponent of P to estimate minimax error
232!> \param l_mm total ang. mom. quantum number of P to estimate minimax error
233!> \param n_minimax Number of terms in minimax approximation
234!> \param minimax_aw Minimax coefficients
235!> \param err_mm Minimax error
236!> \param delta_mm ...
237!> \param potential ...
238!> \param pot_par ...
239! **************************************************************************************************
240 SUBROUTINE minimax_error(cutoff, hmat, vol, G_min, zet_min, l_mm, &
241 n_minimax, minimax_aw, err_mm, delta_mm, potential, pot_par)
242 REAL(kind=dp), INTENT(IN) :: cutoff
243 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: hmat
244 REAL(kind=dp), INTENT(IN) :: vol, g_min, zet_min
245 INTEGER, INTENT(IN) :: l_mm, n_minimax
246 REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: minimax_aw
247 REAL(kind=dp), INTENT(OUT) :: err_mm, delta_mm
248 INTEGER, INTENT(IN), OPTIONAL :: potential
249 REAL(kind=dp), INTENT(IN), OPTIONAL :: pot_par
250
251 INTEGER :: i_xyz
252 REAL(kind=dp) :: prod_mm_k
253
254 CALL get_minimax_coeff_v_gspace(n_minimax, cutoff, g_min, minimax_aw(:), &
255 potential=potential, pot_par=pot_par, err_minimax=delta_mm)
256
257 prod_mm_k = 1.0_dp
258 DO i_xyz = 1, 3
259 prod_mm_k = prod_mm_k*(abs(hmat(i_xyz, i_xyz))/twopi + &
260 merge(sqrt(2.0_dp/(zet_min*pi))*exp(-1.0_dp), 0.0_dp, l_mm .GT. 0))
261 END DO
262 err_mm = 32*pi**4/vol*delta_mm*prod_mm_k
263
264 END SUBROUTINE
265
266! **************************************************************************************************
267!> \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
268!> upper bound for 1/G^2 (AM-GM inequality) and its minimax approximation (factor C).
269!>
270!> Note: usually, minimax approx. falls off faster than 1/G**2, so C should be approximately 1.
271!> The error is calculated for all l up to l_max and golden section search algorithm is
272!> applied to find the exponent that maximizes cutoff error.
273!> \param cutoff ...
274!> \param h_inv ...
275!> \param G_min ...
276!> \param zet_max Max. exponents of P to estimate cutoff error
277!> \param l_max_zet Max. total ang. mom. quantum numbers of P to estimate cutoff error
278!> \param n_minimax Number of terms in minimax approximation
279!> \param minimax_aw Minimax coefficients
280!> \param err_ctff Cutoff error
281!> \param C_mm Scaling constant to generalize AM-GM upper bound estimate to
282!> minimax approx.
283!> \param para_env ...
284! **************************************************************************************************
285 SUBROUTINE cutoff_error(cutoff, h_inv, G_min, zet_max, l_max_zet, &
286 n_minimax, minimax_aw, err_ctff, C_mm, para_env)
287 REAL(kind=dp), INTENT(IN) :: cutoff
288 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: h_inv
289 REAL(kind=dp), INTENT(IN) :: g_min, zet_max
290 INTEGER, INTENT(IN) :: l_max_zet, n_minimax
291 REAL(kind=dp), DIMENSION(:), INTENT(INOUT) :: minimax_aw
292 REAL(kind=dp), INTENT(OUT) :: err_ctff, c_mm
293 TYPE(mp_para_env_type), INTENT(IN) :: para_env
294
295 INTEGER :: i_aw, ig, iter, max_iter, ng
296 REAL(kind=dp) :: c, dg, eps_zet, err0, err1, err_c, err_ctff_curr, err_ctff_prev, err_d, g, &
297 g_1, g_c, gr, zet_a, zet_b, zet_c, zet_d, zet_div, zet_max_tmp
298
299 ! parameters for finding exponent maximizing cutoff error
300
301 eps_zet = 1.0e-05_dp ! tolerance for exponent
302 zet_div = 2.0_dp ! sampling constant for finding initial values of exponents
303 max_iter = 100 ! maximum number of iterations in golden section search
304 g_c = sqrt(2.0*cutoff)
305
306 zet_max_tmp = zet_max
307
308 ! 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
309 ! upper bound for 1/G^2 (AM-GM inequality) and its minimax approximation (factor C).
310 ! Note: usually, minimax approx. falls off faster than 1/G**2, so C should be approximately 1.
311 ! The error is calculated for all l up to l_max and golden section search algorithm is
312 ! applied to find the exponent that maximizes cutoff error.
313 g_1 = sqrt(1.0_dp/(3.0_dp*minval(minimax_aw(1:n_minimax))))
314
315 c_mm = 0.0_dp
316 IF (g_1 .GT. g_c) THEN
317 ng = 1000
318 dg = (g_1 - g_c)/ng
319 g = g_c
320 DO ig = 1, ng
321 g = min(g, g_c)
322 c = 0.0_dp
323 DO i_aw = 1, n_minimax
324 c = c + 3.0_dp*minimax_aw(n_minimax + i_aw)*exp(-3.0_dp*minimax_aw(i_aw)*g**2)*g**2
325 END DO
326 c_mm = max(c, c_mm)
327 g = g + dg
328 END DO
329 ELSE
330 DO i_aw = 1, n_minimax
331 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
332 END DO
333 END IF
334 c = max(1.0_dp, c_mm)
335
336 err_ctff_prev = 0.0_dp
337 gr = 0.5_dp*(sqrt(5.0_dp) - 1.0_dp) ! golden ratio
338 ! Find valid starting values for golden section search
339 DO iter = 1, max_iter + 1
340 IF (iter .GT. max_iter) &
341 CALL cp_abort(__location__, "Maximum number of iterations for finding "// &
342 "exponent maximizing cutoff error has been exceeded.")
343
344 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_max_tmp, c, err_ctff_curr, para_env)
345 IF (err_ctff_prev .GE. err_ctff_curr) THEN
346 zet_a = zet_max_tmp
347 zet_b = min(zet_max_tmp*zet_div**2, zet_max)
348 EXIT
349 ELSE
350 err_ctff_prev = err_ctff_curr
351 END IF
352 zet_max_tmp = zet_max_tmp/zet_div
353 END DO
354
355 ! Golden section search
356 zet_c = zet_b - gr*(zet_b - zet_a)
357 zet_d = zet_a + gr*(zet_b - zet_a)
358 DO iter = 1, max_iter + 1
359 IF (abs(zet_c - zet_d) .LT. eps_zet*(zet_a + zet_b)) THEN
360 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_a, c, err0, para_env)
361 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_b, c, err1, para_env)
362 err_ctff_curr = max(err0, err1)
363 EXIT
364 END IF
365 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_c, c, err_c, para_env)
366 CALL cutoff_error_fixed_exp(cutoff, h_inv, g_min, l_max_zet, zet_d, c, err_d, para_env)
367 IF (err_c .GT. err_d) THEN
368 zet_b = zet_d
369 zet_d = zet_c
370 zet_c = zet_b - gr*(zet_b - zet_a)
371 ELSE
372 zet_a = zet_c
373 zet_c = zet_d
374 zet_d = zet_a + gr*(zet_b - zet_a)
375 END IF
376 END DO
377 err_ctff = err_ctff_curr
378
379 END SUBROUTINE
380
381! **************************************************************************************************
382!> \brief Calculate cutoff error estimate by using C_mm/3 * 1/(Gx^2*Gy^2*Gz^2)^1/3
383!> as an upper bound for 1/G^2 (and its minimax approximation) for |G| > G_c.
384!> Error is referring to a basis function P with fixed exponent zet_max and
385!> max. angular momentum l_max_zet.
386!> \param cutoff ...
387!> \param h_inv ...
388!> \param G_min ...
389!> \param l_max_zet ...
390!> \param zet_max ...
391!> \param C_mm ...
392!> \param err_c ...
393!> \param para_env ...
394! **************************************************************************************************
395 SUBROUTINE cutoff_error_fixed_exp(cutoff, h_inv, G_min, l_max_zet, zet_max, C_mm, err_c, para_env)
396 REAL(kind=dp), INTENT(IN) :: cutoff
397 REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: h_inv
398 REAL(kind=dp), INTENT(IN) :: g_min
399 INTEGER, INTENT(IN) :: l_max_zet
400 REAL(kind=dp), INTENT(IN) :: zet_max, c_mm
401 REAL(kind=dp), INTENT(OUT) :: err_c
402 TYPE(mp_para_env_type), INTENT(IN) :: para_env
403
404 INTEGER :: ax, ay, az, g_l, g_u, gl_first, gl_last, &
405 gu_first, gu_last, i_xyz, l, my_p, &
406 n_gl, n_gl_left, n_gl_p, n_gu, &
407 n_gu_left, n_gu_p, n_p
408 REAL(kind=dp) :: alpha_g, eps_g, err_c_l, g_c, g_rad, &
409 g_res, inv_lgth, prefactor, sum_g_diff
410 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: s_g_l, s_g_u
411
412 g_c = sqrt(2.0_dp*cutoff)
413 eps_g = tiny(eps_g) ! sum up to machine precision
414 g_res = 0.5_dp*g_min ! resolution for screening
415
416 err_c = 0.0_dp
417 alpha_g = 1.0_dp/(2.0_dp*zet_max)
418 prefactor = 1.0_dp/zet_max
419
420 ALLOCATE (s_g_l(0:2*l_max_zet, 3))
421 ALLOCATE (s_g_u(0:2*l_max_zet, 3))
422
423 g_rad = exp_radius(2*l_max_zet, alpha_g, eps_g, prefactor, epsabs=g_res)
424
425 ! Parallelization of sum over G vectors
426 my_p = para_env%mepos ! mpi rank
427 n_p = para_env%num_pe ! total number of processes
428
429 DO i_xyz = 1, 3
430 inv_lgth = abs(h_inv(i_xyz, i_xyz))
431
432 g_l = floor(g_c/(inv_lgth*twopi))
433 g_u = floor(g_rad/(inv_lgth*twopi))
434
435 IF (g_u .LT. g_l) g_u = g_l
436
437 ! Serial code:
438 ! !Sum |G| <= G_c
439 ! CALL pgf_sum_2c_gspace_1d_deltal(S_G_l(:, i_xyz), alpha_G, inv_lgth, -G_l, G_l, &
440 ! 2.0_dp/3.0_dp, prefactor)
441 ! !Sum |G| > G_c
442 ! CALL pgf_sum_2c_gspace_1d_deltal(S_G_u(:, i_xyz), alpha_G, inv_lgth, G_l + 1, G_u, &
443 ! 2.0_dp/3.0_dp, prefactor)
444
445 ! Parallel code:
446 n_gu = max((g_u - g_l), 0)
447 n_gl = 2*g_l + 1
448 n_gu_p = n_gu/n_p
449 n_gl_p = n_gl/n_p
450 n_gu_left = mod(n_gu, n_p)
451 n_gl_left = mod(n_gl, n_p)
452
453 IF (my_p .LT. n_gu_left) THEN
454 gu_first = g_l + 1 + (n_gu_p + 1)*my_p
455 gu_last = g_l + 1 + (n_gu_p + 1)*(my_p + 1) - 1
456 ELSE
457 gu_first = g_l + 1 + n_gu_left + n_gu_p*my_p
458 gu_last = g_l + 1 + n_gu_left + n_gu_p*(my_p + 1) - 1
459 END IF
460
461 IF (my_p .LT. n_gl_left) THEN
462 gl_first = -g_l + (n_gl_p + 1)*my_p
463 gl_last = -g_l + (n_gl_p + 1)*(my_p + 1) - 1
464 ELSE
465 gl_first = -g_l + n_gl_left + n_gl_p*my_p
466 gl_last = -g_l + n_gl_left + n_gl_p*(my_p + 1) - 1
467 END IF
468
469 ! Sum |G| <= G_c
470 CALL pgf_sum_2c_gspace_1d_deltal(s_g_l(:, i_xyz), alpha_g, inv_lgth, gl_first, gl_last, &
471 2.0_dp/3.0_dp, prefactor)
472
473 ! Sum |G| > G_c
474 CALL pgf_sum_2c_gspace_1d_deltal(s_g_u(:, i_xyz), alpha_g, inv_lgth, gu_first, gu_last, &
475 2.0_dp/3.0_dp, prefactor)
476 END DO
477
478 CALL para_env%sum(s_g_l)
479 CALL para_env%sum(s_g_u)
480
481 s_g_u = s_g_u*2.0_dp ! to include negative values of G
482
483 DO l = 0, l_max_zet
484 DO ax = 0, l
485 DO ay = 0, l - ax
486 az = l - ax - ay
487
488 ! 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}
489 ! Note: term by term multiplication to avoid subtraction for numerical stability
490 sum_g_diff = s_g_u(2*ax, 1)*s_g_u(2*ay, 2)*s_g_u(2*az, 3) + &
491 s_g_u(2*ax, 1)*s_g_u(2*ay, 2)*s_g_l(2*az, 3) + &
492 s_g_u(2*ax, 1)*s_g_l(2*ay, 2)*s_g_u(2*az, 3) + &
493 s_g_l(2*ax, 1)*s_g_u(2*ay, 2)*s_g_u(2*az, 3) + &
494 s_g_u(2*ax, 1)*s_g_l(2*ay, 2)*s_g_l(2*az, 3) + &
495 s_g_l(2*ax, 1)*s_g_u(2*ay, 2)*s_g_l(2*az, 3) + &
496 s_g_l(2*ax, 1)*s_g_l(2*ay, 2)*s_g_u(2*az, 3)
497
498 err_c_l = 4.0_dp*pi**4*hermite_gauss_norm(zet_max, [ax, ay, az])**2* &
499 c_mm/3.0_dp*sum_g_diff
500
501 err_c = max(err_c, err_c_l)
502 END DO
503 END DO
504 END DO
505
506 DEALLOCATE (s_g_u, s_g_l)
507
508 END SUBROUTINE cutoff_error_fixed_exp
509
510END 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