16 USE ieee_arithmetic,
ONLY: ieee_is_finite
30 USE omp_lib,
ONLY: omp_get_max_threads,&
44#include "./base/base_uses.f90"
49 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'ri_rs_kp_integrals'
53 REAL(dp),
PARAMETER :: spacing_prefactor = 0.4_dp*sqrt(2.693604_dp*log(1.0e8_dp)), &
54 padding_safety = 1.1_dp
56 REAL(dp),
PARAMETER :: eps_mesh_phase = 1.0e-8_dp
58 REAL(dp),
PARAMETER :: eps_integer = 1.0e-10_dp
60 REAL(dp),
PARAMETER :: short_bound_spacing = 0.125_dp
61 INTEGER,
PARAMETER :: n_short_bounds = 1024
63 INTEGER,
PARAMETER :: quadrature_block_edge = 8, quadrature_block_size = quadrature_block_edge**3
65 REAL(dp),
PARAMETER :: eps_bound_roundoff = 1.0e-10_dp
68 REAL(dp),
PARAMETER :: short_grid_spacing = 0.02_dp, short_grid_switch = 2.0_dp, &
69 short_grid_ratio = 1.01_dp, short_grid_xmax = 512.0_dp
70 INTEGER,
PARAMETER :: n_short_uniform = nint(short_grid_switch/short_grid_spacing)
72 REAL(dp),
PARAMETER :: recurrence_b_max = 0.9_dp
74 REAL(dp),
PARAMETER :: mesh_table_radius = 40.0_dp
76 REAL(dp),
PARAMETER :: real_bytes = real(
dp_size, dp), bytes_per_mib = 1024.0_dp**2, &
77 bytes_per_gb = 1.0e9_dp
79 REAL(dp),
PARAMETER :: library_workspace_bytes = 96.0_dp*bytes_per_mib, &
80 thread_workspace_bytes = 128.0_dp*bytes_per_mib, &
81 message_batch_bytes = 32.0_dp*bytes_per_mib, &
82 radial_table_budget = 256.0_dp*bytes_per_mib
85 REAL(dp),
PARAMETER :: workspace_safety = 1.3_dp, ri_cache_share = 0.4_dp, ao_cache_share = 0.1_dp
106 REAL(dp),
INTENT(IN) :: grid_points(:, :)
107 INTEGER,
INTENT(IN) :: cells_r_d_lp(:, :)
108 REAL(dp),
ALLOCATABLE,
INTENT(OUT) :: d_lp_r(:, :, :)
109 REAL(dp),
INTENT(IN) :: qpoints(:, :)
110 COMPLEX(dp),
ALLOCATABLE,
INTENT(OUT) :: charge_lq(:, :)
112 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_d_lP_R'
114 INTEGER :: first_l, handle, last_l
117 IF (bs_env%unit_nr > 0)
THEN
118 WRITE (bs_env%unit_nr,
'(T2,A,T72,A9)')
'd_lP method',
'NUMERICAL'
121 bs_env%para_env%mepos, first_l, last_l)
122 ALLOCATE (d_lp_r(last_l - first_l + 1, bs_env%n_RI,
SIZE(cells_r_d_lp, 2)))
124 CALL timeset(routinen, handle)
126 CALL prepare_d_lp_integration_grid(bs_env, grid_points, settings)
127 ALLOCATE (charge_lq(bs_env%ri_rs%n_grid_points,
SIZE(qpoints, 2)))
128 CALL integrate_d_lp_r(bs_env, grid_points, cells_r_d_lp, settings, d_lp_r, first_l, &
131 IF (.NOT. all(ieee_is_finite(d_lp_r))) cpabort(
"Nonfinite DLP cell value")
133 CALL timestop(handle)
150 REAL(dp),
ALLOCATABLE,
INTENT(OUT) :: cutoffs(:)
152 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_d_lP_cutoffs'
154 INTEGER :: handle, iatom, ikind
155 REAL(dp) :: accuracy, ao_max, ao_min, ri_max, ri_min
159 CALL timeset(routinen, handle)
161 particles => bs_env%ri_rs%particle_set
162 accuracy = d_lp_integration_accuracy(bs_env)
163 ALLOCATE (cutoffs(bs_env%n_atom))
164 DO iatom = 1, bs_env%n_atom
165 ikind = particles(iatom)%atomic_kind%kind_number
166 basis => bs_env%basis_set_AO(ikind)%gto_basis_set
167 CALL basis_exponent_range(basis, ao_min, ao_max)
168 basis => bs_env%basis_set_RI(ikind)%gto_basis_set
169 CALL basis_exponent_range(basis, ri_min, ri_max)
170 cutoffs(iatom) = max(0.0_dp, bs_env%ri_metric%cutoff_radius) + &
171 sqrt(log(1.0_dp/accuracy)*(1.0_dp/ao_min + 2.0_dp/ri_min))
174 CALL timestop(handle)
187 INTEGER,
INTENT(IN) :: n_grid, n_ranks, i_rank
188 INTEGER,
INTENT(OUT) :: first_l, last_l
190 cpassert(i_rank >= 0 .AND. i_rank < n_ranks)
191 first_l = int(int(n_grid,
int_8)*int(i_rank,
int_8)/int(n_ranks,
int_8)) + 1
192 last_l = int(int(n_grid,
int_8)*int(i_rank + 1,
int_8)/int(n_ranks,
int_8))
207 INTEGER,
INTENT(IN) :: unit_nr
208 CHARACTER(LEN=*),
INTENT(IN) :: phase
209 INTEGER(KIND=int_8),
INTENT(IN) :: n_done, n_total
210 INTEGER,
INTENT(INOUT) :: next_progress
211 REAL(kind=dp),
INTENT(IN) :: phase_start
213 REAL(kind=dp),
PARAMETER :: milestones(9) = [0.1_dp, 0.3_dp, 1.0_dp, 3.0_dp, 10.0_dp, 30.0_dp&
214 , 60.0_dp, 90.0_dp, 100.0_dp]
216 CHARACTER(LEN=100) :: progress_line
217 CHARACTER(LEN=20) :: count_text
218 CHARACTER(LEN=32) :: phase_text
219 CHARACTER(LEN=64) :: progress_format
220 CHARACTER(LEN=8) :: time_text
221 INTEGER :: count_width, previous_progress
222 REAL(kind=dp) :: percent_done, phase_time
224 IF (unit_nr <= 0 .OR. n_total <= 0)
RETURN
225 percent_done = 100.0_dp*real(n_done, dp)/real(n_total, dp)
226 previous_progress = next_progress
227 DO WHILE (next_progress <=
SIZE(milestones))
228 IF (percent_done < milestones(next_progress))
EXIT
229 next_progress = next_progress + 1
231 IF (next_progress == previous_progress)
RETURN
232 cpassert(len_trim(phase) <= 32)
233 WRITE (count_text,
'(I0)') n_total
234 count_width = len_trim(count_text)
235 WRITE (progress_format,
'(A,I0,A,I0,A)') &
236 '(A32,1X,I', count_width,
',A,I', count_width,
',1X,F5.1,A)'
238 WRITE (progress_line, progress_format) &
239 phase_text, n_done,
' / ', n_total, percent_done,
' %'
241 WRITE (time_text,
'(F8.1)') phase_time
242 IF (index(time_text,
'*') > 0)
WRITE (time_text,
'(ES8.1E3)') phase_time
243 IF (len_trim(progress_line) > 56)
THEN
244 WRITE (unit_nr,
'(T2,A)') trim(phase)
245 WRITE (unit_nr,
'(T2,A)') trim(adjustl(progress_line(34:)))
248 WRITE (unit_nr,
'(T2,A,T60,A,T71,A,A)') trim(progress_line),
'Total time:', time_text,
' s'
271 SUBROUTINE prepare_d_lp_mpi_groups(para_env, nl, bs_env, nt, nresult, integration_comm, field_comm, ngroups)
273 INTEGER,
INTENT(IN) :: nl
275 INTEGER,
INTENT(IN) :: nt
276 INTEGER(int_8),
INTENT(IN) :: nresult
277 TYPE(
mp_comm_type),
INTENT(OUT) :: integration_comm, field_comm
278 INTEGER,
INTENT(OUT) :: ngroups
280 INTEGER :: igroup, integration_rank, maxnp, &
282 REAL(dp) :: available_gb, cell_bytes, contraction_bytes, cyclic_bytes, local_bytes, &
283 reduction_bytes, required_bytes, result_bytes, selection_bytes, workspace_bytes
287 result_bytes = real_bytes*real(nresult, dp)
288 CALL para_env%max(result_bytes)
289 cell_bytes = real_bytes*real(nl, dp)*real(np, dp)
290 cyclic_bytes = cell_bytes*real((nt + para_env%num_pe - 1)/para_env%num_pe, dp)
291 maxnp = maxval(bs_env%i_RI_end_from_atom - bs_env%i_RI_start_from_atom + 1)
292 contraction_bytes = real_bytes*(real(nl, dp)*real(maxnp + quadrature_block_size, dp) + &
293 REAL(quadrature_block_size, dp)*
REAL(maxnp, dp))
294 workspace_bytes = library_workspace_bytes + &
295 5.0_dp*real_bytes*real(nl + 3, dp)*real(quadrature_block_size, dp) + &
296 max(thread_workspace_bytes, contraction_bytes)
297 DO ngroups = 1, para_env%num_pe
298 IF (
modulo(para_env%num_pe, ngroups) /= 0) cycle
299 nlocal_t = (nt + ngroups - 1)/ngroups
302 local_bytes = cell_bytes*real(nlocal_t, dp)
303 selection_bytes = 2.0_dp*real(storage_size(.true.)/8, dp)* &
304 REAL(nl, dp)*
REAL(bs_env%n_atom, dp)*
REAL(nlocal_t, dp)
305 selection_bytes = selection_bytes + 3.0_dp*real(
int_size, dp)*real(nlocal_t, dp)
306 reduction_bytes = max(message_batch_bytes, cell_bytes)
307 required_bytes = workspace_safety*(selection_bytes + &
308 max(local_bytes + workspace_bytes, &
309 local_bytes + cyclic_bytes + reduction_bytes, &
310 2.0_dp*cyclic_bytes + result_bytes + reduction_bytes))
311 IF (required_bytes <= available_gb*bytes_per_gb)
EXIT
313 IF (ngroups > para_env%num_pe)
THEN
314 ngroups = para_env%num_pe
315 cpwarn(
'd_lP workspaces exceed memory with all MPI ranks')
317 igroup =
modulo(para_env%mepos, ngroups)
318 integration_rank = para_env%mepos/ngroups
319 CALL integration_comm%from_split(para_env, igroup, key=integration_rank)
320 CALL field_comm%from_split(para_env, integration_rank, key=igroup)
321 IF (bs_env%unit_nr > 0)
THEN
322 WRITE (bs_env%unit_nr,
'(T2,A,T66,F12.1,A)')
'd_lP PSS-aware rank headroom:', available_gb,
' GB'
323 WRITE (bs_env%unit_nr,
'(T2,A,T61,I20)')
'd_lP memory group size:', ngroups
324 WRITE (bs_env%unit_nr,
'(T2,A,T61,I20)')
'd_lP independent integration groups:', integration_comm%num_pe
325 WRITE (bs_env%unit_nr,
'(T2,A,T66,F12.1,A)')
'd_lP existing output storage:', result_bytes*1.0e-9_dp,
' GB'
326 WRITE (bs_env%unit_nr,
'(T2,A,T66,F12.1,A)')
'd_lP additional memory budget:', required_bytes*1.0e-9_dp,
' GB'
327 FLUSH (bs_env%unit_nr)
330 END SUBROUTINE prepare_d_lp_mpi_groups
340 SUBROUTINE sum_d_lp_r_over_mpi_ranks(comm, partial, cells)
342 REAL(dp),
CONTIGUOUS,
INTENT(IN),
TARGET :: partial(:, :, :)
343 REAL(dp),
ALLOCATABLE,
INTENT(OUT),
TARGET :: cells(:, :, :)
345 CHARACTER(LEN=*),
PARAMETER :: routinen =
'sum_d_lP_R_over_mpi_ranks'
347 INTEGER :: block_cells, first_rank, first_t, handle, icycle, last_rank, last_t, nl, nlocal, &
348 np, nranks, nt, rank, round_first, round_last
349 INTEGER(int_8) :: iround, plane_count
350 REAL(dp),
CONTIGUOUS,
POINTER :: receive_block(:), send_block(:, :)
351 REAL(dp),
TARGET :: empty(0)
352 INTEGER :: recv_counts(comm%num_pe)
354 CALL timeset(routinen, handle)
356 nl =
SIZE(partial, 1)
357 np =
SIZE(partial, 2)
358 nt =
SIZE(partial, 3)
362 IF (nt > rank) nlocal = 1 + (nt - 1 - rank)/nranks
363 ALLOCATE (cells(nl, np, nlocal))
364 IF (nl == 0 .OR. np == 0 .OR. nt == 0)
THEN
365 CALL timestop(handle)
368 IF (nranks == 1)
THEN
369 cells(:, :, :) = partial(:, :, :)
370 CALL timestop(handle)
374 IF (plane_count > huge(0))
THEN
375 cpabort(
'DLP integration block exceeds the MPI count range')
377 block_cells = int(max(1_int_8, int(message_batch_bytes/real_bytes,
int_8)/plane_count))
378 block_cells = min(block_cells, int(int(huge(0),
int_8)/plane_count))
380 DO iround = 1_int_8, int(nt,
int_8), int(nranks,
int_8)
382 round_first = int(iround)
383 round_last = int(min(int(nt,
int_8), iround + int(nranks,
int_8) - 1_int_8))
384 first_t = round_first
385 DO WHILE (first_t <= round_last)
386 last_t = int(min(int(round_last,
int_8), int(first_t,
int_8) + int(block_cells,
int_8) - 1_int_8))
387 first_rank = first_t - round_first
388 last_rank = last_t - round_first
390 recv_counts(first_rank + 1:last_rank + 1) = int(plane_count)
391 send_block(1:int(plane_count), 1:last_t - first_t + 1) => partial(:, :, first_t:last_t)
392 receive_block => empty
393 IF (rank >= first_rank .AND. rank <= last_rank)
THEN
394 receive_block(1:int(plane_count)) => cells(:, :, icycle)
396 CALL comm%sum_scatter(send_block, receive_block, recv_counts)
397 IF (last_t == round_last)
EXIT
402 CALL timestop(handle)
404 END SUBROUTINE sum_d_lp_r_over_mpi_ranks
415 SUBROUTINE distribute_d_lp_r_by_l(para_env, cell_values, first_l, d_lP_R)
417 REAL(dp),
INTENT(IN) :: cell_values(:, :, :)
418 INTEGER,
INTENT(IN) :: first_l
419 REAL(dp),
INTENT(OUT) :: d_lp_r(:, :, :)
421 CHARACTER(LEN=*),
PARAMETER :: routinen =
'distribute_d_lP_R_by_l'
423 INTEGER :: handle, il, ip, irank, it, local_it, &
424 nlocal_l, nlocal_t, np, nranks, &
426 INTEGER(int_8) :: count_wide
427 INTEGER,
ALLOCATABLE :: cell_counts(:), first_rows(:), recv_counts(:), recv_offsets(:), &
428 row_counts(:), send_counts(:), send_offsets(:)
429 REAL(dp),
ALLOCATABLE :: receive_values(:), send_values(:)
431 CALL timeset(routinen, handle)
433 nranks = para_env%num_pe
435 nlocal_l =
SIZE(d_lp_r, 1)
436 nlocal_t =
SIZE(cell_values, 3)
437 ALLOCATE (first_rows(nranks), row_counts(nranks), cell_counts(nranks), &
438 send_counts(nranks), send_offsets(nranks), recv_counts(nranks), recv_offsets(nranks))
439 CALL para_env%allgather(first_l, first_rows)
440 CALL para_env%allgather(nlocal_l, row_counts)
441 CALL para_env%allgather(nlocal_t, cell_counts)
443 count_wide = int(np,
int_8)*int(row_counts(irank),
int_8)*int(nlocal_t,
int_8)
444 cpassert(count_wide <= huge(0))
445 count_wide = int(np,
int_8)*int(nlocal_l,
int_8)*int(cell_counts(irank),
int_8)
446 cpassert(count_wide <= huge(0))
447 send_counts(irank) = np*row_counts(irank)*nlocal_t
448 recv_counts(irank) = np*nlocal_l*cell_counts(irank)
450 cpassert(sum(int(send_counts,
int_8)) <= huge(0))
451 cpassert(sum(int(recv_counts,
int_8)) <= huge(0))
454 send_offsets(irank) = position
455 position = position + send_counts(irank)
457 ALLOCATE (send_values(position))
460 recv_offsets(irank) = position
461 position = position + recv_counts(irank)
463 ALLOCATE (receive_values(position))
465 position = send_offsets(irank)
466 DO local_it = 1, nlocal_t
468 DO il = first_rows(irank), first_rows(irank) + row_counts(irank) - 1
469 position = position + 1
470 send_values(position) = cell_values(il, ip, local_it)
475 CALL para_env%alltoall(send_values, send_counts, send_offsets, &
476 receive_values, recv_counts, recv_offsets)
478 position = recv_offsets(irank)
479 DO local_it = 1, cell_counts(irank)
480 it = irank + (local_it - 1)*nranks
483 position = position + 1
484 d_lp_r(il, ip, it) = receive_values(position)
490 CALL timestop(handle)
492 END SUBROUTINE distribute_d_lp_r_by_l
505 SUBROUTINE accumulate_fourier_charge(points, field, q_cart, weight, charge_lq)
506 REAL(dp),
INTENT(IN) :: points(:, :)
507 REAL(dp),
CONTIGUOUS,
INTENT(IN) :: field(:, :)
508 REAL(dp),
INTENT(IN) :: q_cart(:, :), weight
509 COMPLEX(dp),
INTENT(INOUT) :: charge_lq(:, :)
511 CHARACTER(LEN=*),
PARAMETER :: routinen =
'accumulate_fourier_charge'
512 INTEGER,
PARAMETER :: row_block = 64
515 INTEGER :: first_l, handle, ig, il, iq, nblock, ng, &
517 REAL(dp),
ALLOCATABLE :: charge_parts(:, :), phase_parts(:, :)
519 CALL timeset(routinen, handle)
524 IF (ng == 0 .OR. nl == 0 .OR. nq == 0)
THEN
525 CALL timestop(handle)
528 ALLOCATE (phase_parts(ng, 2*nq))
531 phase = exp(cmplx(0.0_dp, sum(q_cart(:, iq)*points(:, ig)), dp))
532 phase_parts(ig, iq) = real(phase, dp)
533 phase_parts(ig, nq + iq) = aimag(phase)
539 ALLOCATE (charge_parts(row_block, 2*nq))
541 DO first_l = 1, nl, row_block
542 nblock = min(row_block, nl - first_l + 1)
543 CALL dgemm(
'T',
'N', nblock, 2*nq, ng, weight, &
544 field(:, first_l:first_l + nblock - 1),
SIZE(field, 1), &
545 phase_parts, ng, 0.0_dp, charge_parts, row_block)
548 charge_lq(first_l + il - 1, iq) = charge_lq(first_l + il - 1, iq) + &
549 cmplx(charge_parts(il, iq), charge_parts(il, nq + iq), dp)
554 DEALLOCATE (charge_parts)
556 DEALLOCATE (phase_parts)
558 CALL timestop(handle)
560 END SUBROUTINE accumulate_fourier_charge
568 SUBROUTINE prepare_d_lp_integration_grid(bs_env, grid_points, settings)
570 REAL(dp),
INTENT(IN) :: grid_points(:, :)
573 INTEGER(int_8) :: npoints
574 REAL(dp) :: exponent_max, exponent_min
576 settings%accuracy = d_lp_integration_accuracy(bs_env)
579 .NOT. (bs_env%ri_metric%omega > 0.0_dp))
THEN
580 cpabort(
'Uniform DLP requires the short-range erfc RI metric with positive omega')
582 IF (all(bs_env%ri_rs%cell%perd == 0)) cpabort(
'Uniform DLP requires a periodic cell')
583 CALL ao_exponent_range(bs_env, exponent_min, exponent_max)
584 settings%l_block_edge = 1.0_dp/
angstrom
585 settings%spacing = spacing_prefactor/ &
586 sqrt(exponent_max*log(1.0_dp/settings%accuracy))
587 settings%padding = padding_safety*sqrt(log(1.0_dp/settings%accuracy)/exponent_min)
588 CALL build_d_lp_integration_grid(bs_env, grid_points, settings)
589 npoints = product(int(settings%counts,
int_8))
590 IF (bs_env%unit_nr > 0)
THEN
591 WRITE (bs_env%unit_nr,
'(T2,A,T72,ES9.1E2)')
'd_lP uniform quadrature points', real(npoints, dp)
592 WRITE (bs_env%unit_nr,
'(T2,A,T72,ES9.1)')
'd_lP integration threshold', settings%accuracy
593 WRITE (bs_env%unit_nr,
'(T2,A,T69,F12.3)')
'd_lP largest AO exponent [bohr^-2]', exponent_max
594 WRITE (bs_env%unit_nr,
'(T2,A,T69,F12.3)')
'd_lP uniform spacing [bohr]', settings%spacing
597 END SUBROUTINE prepare_d_lp_integration_grid
606 SUBROUTINE build_d_lp_integration_grid(bs_env, grid_points, settings)
608 REAL(dp),
INTENT(IN) :: grid_points(:, :)
611 INTEGER :: idir, subdivisions(3)
612 REAL(dp) :: box_center(3), box_extent(3), &
613 eigenvalues(3), inverse_step(3, 3), &
614 metric(3, 3), scale, upper(3)
618 cell => bs_env%ri_rs%cell
619 particles => bs_env%ri_rs%particle_set
620 settings%origin =
pbc(particles(1)%r, cell)
622 subdivisions(idir) = max(1, ceiling(norm2(cell%hmat(:, idir))/settings%spacing))
623 settings%step(:, idir) = cell%hmat(:, idir)/real(subdivisions(idir), dp)
625 metric = matmul(transpose(settings%step), settings%step)
626 CALL diamat_all(metric, eigenvalues, dac=.true.)
627 scale = max(1.0_dp, sqrt(maxval(eigenvalues))/settings%spacing)
628 subdivisions = ceiling(scale*real(subdivisions, dp))
629 settings%subdivisions = subdivisions
631 settings%step(:, idir) = cell%hmat(:, idir)/real(subdivisions(idir), dp)
632 inverse_step(idir, :) = real(subdivisions(idir), dp)*cell%h_inv(idir, :)
634 settings%weight = abs(cell%deth)/product(real(subdivisions, dp))
635 box_center = 0.5_dp*(minval(grid_points, dim=2) + maxval(grid_points, dim=2)) - settings%origin
636 box_extent = 0.5_dp*(maxval(grid_points, dim=2) - minval(grid_points, dim=2)) + settings%padding
637 settings%lower = real(ceiling(matmul(inverse_step, box_center) - &
638 matmul(abs(inverse_step), box_extent)), dp)
639 upper = real(floor(matmul(inverse_step, box_center) + &
640 matmul(abs(inverse_step), box_extent)), dp)
641 settings%counts = int(upper - settings%lower) + 1
642 cpassert(all(settings%counts > 0))
644 END SUBROUTINE build_d_lp_integration_grid
652 SUBROUTINE group_points_l_by_position(grid_points, edge, blocks)
653 REAL(dp),
INTENT(IN) :: grid_points(:, :), edge
656 INTEGER :: cube(3), iblock, idir, il, insert
657 INTEGER,
ALLOCATABLE :: block_of_l(:), counts(:), cubes(:, :), &
659 REAL(dp) :: origin(3)
661 origin = minval(grid_points, dim=2)
662 ALLOCATE (block_of_l(
SIZE(grid_points, 2)), cubes(3,
SIZE(grid_points, 2)))
664 DO il = 1,
SIZE(grid_points, 2)
665 cube = floor((grid_points(:, il) - origin)/edge)
667 DO insert = 1, blocks%nblocks
668 IF (all(cubes(:, insert) == cube))
THEN
673 IF (iblock == 0)
THEN
674 blocks%nblocks = blocks%nblocks + 1
675 iblock = blocks%nblocks
676 cubes(:, iblock) = cube
678 block_of_l(il) = iblock
680 ALLOCATE (counts(blocks%nblocks), next(blocks%nblocks), &
681 blocks%first(blocks%nblocks + 1), blocks%indices(
SIZE(grid_points, 2)), &
682 blocks%lower(3, blocks%nblocks), blocks%upper(3, blocks%nblocks))
684 DO il = 1,
SIZE(grid_points, 2)
685 counts(block_of_l(il)) = counts(block_of_l(il)) + 1
688 DO iblock = 1, blocks%nblocks
689 blocks%first(iblock + 1) = blocks%first(iblock) + counts(iblock)
691 next(:) = blocks%first(1:blocks%nblocks)
692 blocks%lower = huge(1.0_dp)
693 blocks%upper = -huge(1.0_dp)
694 DO il = 1,
SIZE(grid_points, 2)
695 iblock = block_of_l(il)
696 blocks%indices(next(iblock)) = il
697 next(iblock) = next(iblock) + 1
699 blocks%lower(idir, iblock) = min(blocks%lower(idir, iblock), grid_points(idir, il))
700 blocks%upper(idir, iblock) = max(blocks%upper(idir, iblock), grid_points(idir, il))
704 END SUBROUTINE group_points_l_by_position
712 SUBROUTINE ao_exponent_range(bs_env, exponent_min, exponent_max)
714 REAL(dp),
INTENT(OUT) :: exponent_min, exponent_max
716 INTEGER :: ikind, ipgf, iset
720 exponent_min = huge(1.0_dp)
721 exponent_max = 0.0_dp
722 DO ikind = 1,
SIZE(bs_env%basis_set_AO)
723 basis => bs_env%basis_set_AO(ikind)%gto_basis_set
724 IF (.NOT.
ASSOCIATED(basis)) cycle
725 DO iset = 1, basis%nset
726 DO ipgf = 1, basis%npgf(iset)
727 exponent = basis%zet(ipgf, iset)
728 IF (exponent <= 0.0_dp) cycle
729 exponent_min = min(exponent_min, exponent)
730 exponent_max = max(exponent_max, exponent)
734 IF (exponent_max <= 0.0_dp .OR. exponent_min == huge(1.0_dp))
THEN
735 cpabort(
'Uniform DLP found no positive AO primitive exponent')
738 END SUBROUTINE ao_exponent_range
745 FUNCTION d_lp_integration_accuracy(bs_env)
RESULT(accuracy)
749 IF (.NOT. ieee_is_finite(bs_env%eps_filter) .OR. &
750 bs_env%eps_filter <= 0.0_dp .OR. bs_env%eps_filter >= 1.0_dp)
THEN
751 cpabort(
'EPS_FILTER must be between zero and one for periodic RI-RS DLP')
753 accuracy = bs_env%eps_filter
754 END FUNCTION d_lp_integration_accuracy
762 SUBROUTINE basis_exponent_range(basis, exponent_min, exponent_max)
764 REAL(dp),
INTENT(OUT) :: exponent_min, exponent_max
766 INTEGER :: ipgf, iset
769 cpassert(
ASSOCIATED(basis))
770 exponent_min = huge(1.0_dp)
771 exponent_max = 0.0_dp
772 DO iset = 1, basis%nset
773 DO ipgf = 1, basis%npgf(iset)
774 exponent = basis%zet(ipgf, iset)
775 IF (exponent <= 0.0_dp) cycle
776 exponent_min = min(exponent_min, exponent)
777 exponent_max = max(exponent_max, exponent)
780 IF (exponent_max <= 0.0_dp .OR. exponent_min == huge(1.0_dp))
THEN
781 cpabort(
'Automatic DLP cutoff found no positive primitive exponent')
784 END SUBROUTINE basis_exponent_range
817 SUBROUTINE integrate_d_lp_r(bs_env, grid_points, cells_R_d_lP, settings, d_lP_R, first_l, &
820 REAL(dp),
INTENT(IN) :: grid_points(:, :)
821 INTEGER,
INTENT(IN) :: cells_r_d_lp(:, :)
823 REAL(dp),
INTENT(OUT) :: d_lp_r(:, :, :)
824 INTEGER,
INTENT(IN) :: first_l
825 REAL(dp),
INTENT(IN) :: qpoints(:, :)
826 COMPLEX(dp),
INTENT(OUT) :: charge_lq(:, :)
828 CHARACTER(LEN=*),
PARAMETER :: routinen =
'integrate_d_lP_R'
830 INTEGER :: block_class, block_point(3), copy(3), counts(3), first_block(3), handle, iatom, &
831 ibatch, iblock, ig, igroup, il, indices(quadrature_block_size), irank, it, last_rank, &
832 n_blocks(3), n_class(3), next_progress, ngroups, nkeep, nl, np, npoints, nranks, &
833 nreceived, point_index(quadrature_block_size), position, quadrature_block_first(3), &
834 quadrature_block_points(3), rank, ranks_per_batch
835 INTEGER(int_8) :: contraction_products, iround, item, n_completed_quadrature_blocks, &
836 n_items, n_local_quadrature_blocks, nrounds, ntotal, potential_points
837 INTEGER(int_8),
ALLOCATABLE :: chunk_first(:)
838 INTEGER,
ALLOCATABLE :: chunk_class(:), chunk_part(:), chunk_parts(:), kept_per_rank(:), &
839 local_cells(:, :), recv_counts(:), recv_offsets(:)
840 LOGICAL,
ALLOCATABLE :: include_l_blocks_p_r(:, :, :), &
841 include_lp_r(:, :, :)
842 REAL(dp) :: available_gb, bound, elapsed, field_bound(quadrature_block_size), lower(3), &
843 mesh_index(3), points(3, quadrature_block_size), prep_start, ri_center_r(3), threshold, &
845 REAL(dp),
ALLOCATABLE :: cutoffs_lp(:), cyclic_d_lp_r(:, :, :), envelopes(:, :), &
846 field(:, :), local_d_lp_r(:, :, :), q_cart(:, :), receive_fields(:), send_fields(:)
855 CALL timeset(routinen, handle)
857 nl = bs_env%ri_rs%n_grid_points
858 cell => bs_env%ri_rs%cell
859 particles => bs_env%ri_rs%particle_set
860 ALLOCATE (field(quadrature_block_size, nl), q_cart(3,
SIZE(qpoints, 2)))
861 q_cart(:, :) = matmul(
twopi*transpose(cell%h_inv), qpoints)
862 charge_lq = cmplx(0.0_dp, 0.0_dp, dp)
865 IF (bs_env%unit_nr > 0)
THEN
866 WRITE (bs_env%unit_nr,
'(T2,A)')
'd_lP quadrature: evaluating AO image values'
867 FLUSH (bs_env%unit_nr)
869 CALL prepare_ao_images(bs_env, grid_points, images)
870 IF (bs_env%unit_nr > 0)
THEN
871 WRITE (bs_env%unit_nr,
'(T2,A,T67,F12.1,A)') &
872 'd_lP AO image values, rank 0 time:',
m_walltime() - prep_start,
' s'
873 FLUSH (bs_env%unit_nr)
875 CALL prepare_aux_potentials(bs_env, settings, aux_potentials)
876 CALL auxiliary_potential_bound(bs_env, aux_potentials, envelopes)
877 CALL group_points_l_by_position(grid_points, settings%l_block_edge, blocks)
878 bound = maxval(envelopes(1, :))
880 CALL prepare_d_lp_mpi_groups(bs_env%para_env, nl, bs_env,
SIZE(cells_r_d_lp, 2),
SIZE(d_lp_r, kind=
int_8), &
881 integration_comm, field_comm, ngroups)
882 igroup = field_comm%mepos
883 nranks = field_comm%num_pe
884 rank = field_comm%mepos
886 ALLOCATE (local_cells(3,
SIZE(cells_r_d_lp(:, igroup + 1::ngroups), 2)))
887 local_cells(:, :) = cells_r_d_lp(:, igroup + 1::ngroups)
890 ALLOCATE (include_lp_r(nl, bs_env%n_atom,
SIZE(local_cells, 2)))
891 ALLOCATE (include_l_blocks_p_r(blocks%nblocks, bs_env%n_atom,
SIZE(local_cells, 2)), source=.false.)
892 DO it = 1,
SIZE(local_cells, 2)
893 DO iatom = 1, bs_env%n_atom
894 ri_center_r =
pbc(particles(iatom)%r, cell) + matmul(bs_env%hmat, real(local_cells(:, it), dp))
896 include_lp_r(il, iatom, it) = sum((grid_points(:, il) - ri_center_r)**2) <= cutoffs_lp(iatom)**2
898 DO iblock = 1, blocks%nblocks
899 IF (distance_to_box_squared(ri_center_r, blocks%lower(:, iblock), &
900 blocks%upper(:, iblock)) > cutoffs_lp(iatom)**2) cycle
901 include_l_blocks_p_r(iblock, iatom, it) = &
902 any(include_lp_r(blocks%indices(blocks%first(iblock):blocks%first(iblock + 1) - 1), iatom, it))
906 DEALLOCATE (cutoffs_lp)
907 IF (bs_env%unit_nr > 0)
THEN
908 FLUSH (bs_env%unit_nr)
911 ALLOCATE (local_d_lp_r(nl, np,
SIZE(local_cells, 2)), source=0.0_dp)
912 ALLOCATE (kept_per_rank(nranks), recv_counts(nranks), recv_offsets(nranks))
914 ranks_per_batch = max(1, int(message_batch_bytes/ &
915 (real_bytes*real(nl + 4, dp)*real(quadrature_block_size, dp))))
916 ranks_per_batch = min(nranks, ranks_per_batch)
917 ALLOCATE (send_fields((nl + 4)*quadrature_block_size), &
918 receive_fields((nl + 4)*quadrature_block_size*ranks_per_batch))
919 contraction_products = 0_int_8
920 potential_points = 0_int_8
921 weight = settings%weight
922 lower = settings%lower
923 counts = settings%counts
924 ntotal = product(int(counts,
int_8))
927 CALL plan_quadrature_blocks(settings, cell%perd, integration_comm%num_pe, integration_comm%mepos, &
928 n_class, first_block, n_blocks, chunk_class, chunk_part, chunk_parts, &
930 n_items = chunk_first(
SIZE(chunk_class))
931 nrounds = (n_items + int(nranks,
int_8) - 1_int_8)/int(nranks,
int_8)
933 CALL prepare_block_class_cache(cache, local_cells, bs_env%n_atom, quadrature_block_size, &
934 maxval(bs_env%i_RI_end_from_atom - bs_env%i_RI_start_from_atom + 1), &
935 n_class, first_block, n_blocks, ri_cache_share*bytes_per_gb*available_gb, .true.)
936 CALL prepare_block_class_cache(ao_cache, bs_env%index_to_cell_3c, bs_env%n_atom, quadrature_block_size, &
937 maxval(bs_env%i_ao_end_from_atom - bs_env%i_ao_start_from_atom + 1), &
938 n_class, first_block, n_blocks, ao_cache_share*bytes_per_gb*available_gb, .false.)
940 n_local_quadrature_blocks = nrounds
941 threshold = 0.5_dp*settings%accuracy/(real(ntotal, dp)*weight)
942 DO iround = 0_int_8, nrounds - 1_int_8
943 item = iround*int(nranks,
int_8) + int(rank,
int_8)
945 IF (item < n_items)
THEN
946 CALL locate_quadrature_block(item, settings, cell%perd, n_class, first_block, n_blocks, &
947 chunk_class, chunk_part, chunk_parts, chunk_first, block_class, &
948 copy, quadrature_block_first, quadrature_block_points)
951 DO ig = 1, quadrature_block_size
952 block_point(1) =
modulo(ig - 1, quadrature_block_edge)
953 block_point(2) =
modulo((ig - 1)/quadrature_block_edge, quadrature_block_edge)
954 block_point(3) = (ig - 1)/quadrature_block_edge**2
955 IF (any(block_point >= quadrature_block_points)) cycle
956 IF (any(quadrature_block_first + block_point < 0 .OR. &
957 quadrature_block_first + block_point >= counts)) cycle
958 npoints = npoints + 1
959 point_index(npoints) = ig
960 mesh_index = lower + real(quadrature_block_first + block_point, dp)
961 points(:, npoints) = settings%origin + matmul(settings%step, mesh_index)
963 IF (block_class /= ao_cache%block_class)
CALL reset_block_class_cache(ao_cache, block_class)
964 CALL evaluate_rho_l_squared(images, points(:, 1:npoints), point_index(1:npoints), copy, ao_cache, &
965 field(1:npoints, :), &
966 settings%accuracy/(8.0_dp*weight*real(ntotal, dp)*max(1.0_dp, bound)))
967 CALL accumulate_fourier_charge(points(:, 1:npoints), field, q_cart, weight, charge_lq)
969 field_bound(1:npoints) = 0.0_dp
973 field_bound(ig) = max(field_bound(ig), abs(field(ig, il)))
977 IF (field_bound(ig)*bound > threshold)
THEN
983 send_fields(4*ig - 3:4*ig - 1) = points(:, indices(ig))
984 send_fields(4*ig) = real(point_index(indices(ig)), dp)
988 send_fields(4*nkeep + (il - 1)*nkeep + ig) = field(indices(ig), il)
992 CALL field_comm%allgather(nkeep, kept_per_rank)
993 DO ibatch = 1, nranks, ranks_per_batch
994 last_rank = min(nranks, ibatch + ranks_per_batch - 1)
996 recv_counts(ibatch:last_rank) = (nl + 4)*kept_per_rank(ibatch:last_rank)
999 recv_offsets(irank) = nreceived
1000 nreceived = nreceived + recv_counts(irank)
1002 IF (nreceived == 0) cycle
1003 cpassert(nreceived <=
SIZE(receive_fields))
1004 CALL field_comm%allgatherv(send_fields(1:recv_counts(rank + 1)), &
1005 receive_fields(1:nreceived), recv_counts, recv_offsets)
1006 DO irank = ibatch, last_rank
1007 nkeep = kept_per_rank(irank)
1008 IF (nkeep == 0 .OR.
SIZE(local_cells, 2) == 0) cycle
1009 position = recv_offsets(irank)
1011 points(:, ig) = receive_fields(position + 4*ig - 3:position + 4*ig - 1)
1012 point_index(ig) = nint(receive_fields(position + 4*ig))
1016 field(ig, il) = receive_fields(position + 4*nkeep + (il - 1)*nkeep + ig)
1019 CALL locate_quadrature_block(iround*int(nranks,
int_8) + int(irank - 1,
int_8), settings, &
1020 cell%perd, n_class, first_block, n_blocks, chunk_class, &
1021 chunk_part, chunk_parts, chunk_first, block_class, copy, &
1022 quadrature_block_first, quadrature_block_points)
1023 IF (block_class /= cache%block_class)
CALL reset_block_class_cache(cache, block_class)
1024 CALL integrate_potentials(bs_env, local_cells, include_lp_r, include_l_blocks_p_r, &
1025 points(:, 1:nkeep), point_index(1:nkeep), field(1:nkeep, :), &
1026 weight, envelopes, blocks, threshold, copy, cache, potential_points, &
1027 contraction_products, local_d_lp_r, aux_potentials)
1030 n_completed_quadrature_blocks = iround + 1_int_8
1032 n_completed_quadrature_blocks, n_local_quadrature_blocks, next_progress, elapsed)
1035 DEALLOCATE (field, send_fields, receive_fields, kept_per_rank, recv_counts, recv_offsets, &
1036 chunk_class, chunk_part, chunk_parts, chunk_first)
1037 CALL sum_d_lp_r_over_mpi_ranks(integration_comm, local_d_lp_r, cyclic_d_lp_r)
1038 DEALLOCATE (local_d_lp_r, local_cells)
1039 CALL distribute_d_lp_r_by_l(bs_env%para_env, cyclic_d_lp_r, first_l, d_lp_r)
1040 DEALLOCATE (cyclic_d_lp_r)
1041 CALL integration_comm%free()
1042 CALL field_comm%free()
1043 CALL bs_env%para_env%sum(charge_lq)
1044 CALL bs_env%para_env%sum(potential_points)
1045 CALL bs_env%para_env%sum(contraction_products)
1047 IF (bs_env%unit_nr > 0)
THEN
1048 WRITE (bs_env%unit_nr,
'(T2,A,T72,ES9.1E2)') &
1049 'Potential evaluations V_P^R(r_g) (point, atom image):', real(potential_points, dp)
1050 WRITE (bs_env%unit_nr,
'(T2,A,T72,ES9.1E2)') &
1051 'd_lP products f_l(r_g)^2 V_P^R(r_g):', real(contraction_products, dp)
1052 WRITE (bs_env%unit_nr,
'(T2,A)') &
1053 'f_l(r) = SUM_(μ,R) ϕ_μ^R(r_l) ϕ_μ^R(r)'
1054 WRITE (bs_env%unit_nr,
'(T2,A)') &
1055 'd_lP^R = SUM_g w_g f_l(r_g)^2 V_P^R(r_g)'
1058 CALL bs_env%para_env%max(elapsed)
1059 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(T2,A,T69,F10.1,A)') &
1060 'd_lP completed numerical integration, Exec. time:', elapsed,
' s'
1061 IF (bs_env%unit_nr > 0)
FLUSH (bs_env%unit_nr)
1063 CALL timestop(handle)
1065 END SUBROUTINE integrate_d_lp_r
1086 SUBROUTINE plan_quadrature_blocks(settings, perd, n_groups, my_group, n_class, first_block, &
1087 n_blocks, chunk_class, chunk_part, chunk_parts, chunk_first)
1089 INTEGER,
INTENT(IN) :: perd(3), n_groups, my_group
1090 INTEGER,
INTENT(OUT) :: n_class(3), first_block(3), n_blocks(3)
1091 INTEGER,
ALLOCATABLE,
INTENT(OUT) :: chunk_class(:), chunk_part(:), &
1093 INTEGER(int_8),
ALLOCATABLE,
INTENT(OUT) :: chunk_first(:)
1095 INTEGER :: block_class, copy_lower(3), group, ichunk, idir, ipart, last_point, n_chunks, &
1096 n_copies(3), n_mine, n_parts, period, position(3)
1097 INTEGER(int_8) :: class_blocks, part_length
1098 INTEGER(int_8),
ALLOCATABLE :: load(:), part_blocks(:)
1099 INTEGER,
ALLOCATABLE :: owner(:), part_class(:), part_count(:), &
1103 IF (perd(idir) == 1)
THEN
1104 n_class(idir) = (settings%subdivisions(idir) + quadrature_block_edge - 1)/quadrature_block_edge
1105 period = floor(settings%lower(idir)/real(settings%subdivisions(idir), dp))
1106 first_block(idir) = n_class(idir)*period + &
1107 (nint(settings%lower(idir)) - settings%subdivisions(idir)*period)/quadrature_block_edge
1108 last_point = nint(settings%lower(idir)) + settings%counts(idir) - 1
1109 period = floor(real(last_point, dp)/real(settings%subdivisions(idir), dp))
1110 n_blocks(idir) = n_class(idir)*period + &
1111 (last_point - settings%subdivisions(idir)*period)/quadrature_block_edge - &
1112 first_block(idir) + 1
1114 n_blocks(idir) = (settings%counts(idir) + quadrature_block_edge - 1)/quadrature_block_edge
1115 n_class(idir) = n_blocks(idir)
1116 first_block(idir) = 0
1120 part_length = max(1_int_8, product(int(n_blocks,
int_8))/(64_int_8*int(n_groups,
int_8)))
1122 DO block_class = 0, product(n_class) - 1
1123 CALL class_copy_range(block_class, n_class, first_block, n_blocks, position, copy_lower, n_copies)
1124 class_blocks = product(int(n_copies,
int_8))
1125 n_chunks = n_chunks + int((class_blocks + part_length - 1_int_8)/part_length)
1127 ALLOCATE (part_class(n_chunks), part_index(n_chunks), part_count(n_chunks), &
1128 part_blocks(n_chunks), owner(n_chunks), load(0:n_groups - 1))
1131 DO block_class = 0, product(n_class) - 1
1132 CALL class_copy_range(block_class, n_class, first_block, n_blocks, position, copy_lower, n_copies)
1133 class_blocks = product(int(n_copies,
int_8))
1134 n_parts = int((class_blocks + part_length - 1_int_8)/part_length)
1135 DO ipart = 0, n_parts - 1
1137 part_class(ichunk) = block_class
1138 part_index(ichunk) = ipart
1139 part_count(ichunk) = n_parts
1140 part_blocks(ichunk) = (class_blocks - int(ipart,
int_8) + int(n_parts - 1,
int_8))/int(n_parts,
int_8)
1141 group = minloc(load, 1) - 1
1142 owner(ichunk) = group
1143 load(group) = load(group) + part_blocks(ichunk)
1146 n_mine = count(owner == my_group)
1147 ALLOCATE (chunk_class(n_mine), chunk_part(n_mine), chunk_parts(n_mine), chunk_first(0:n_mine))
1148 chunk_first(0) = 0_int_8
1150 DO ichunk = 1, n_chunks
1151 IF (owner(ichunk) /= my_group) cycle
1153 chunk_class(n_mine) = part_class(ichunk)
1154 chunk_part(n_mine) = part_index(ichunk)
1155 chunk_parts(n_mine) = part_count(ichunk)
1156 chunk_first(n_mine) = chunk_first(n_mine - 1) + part_blocks(ichunk)
1158 DEALLOCATE (part_class, part_index, part_count, part_blocks, owner, load)
1160 END SUBROUTINE plan_quadrature_blocks
1172 PURE SUBROUTINE class_copy_range(block_class, n_class, first_block, n_blocks, position, &
1173 copy_lower, n_copies)
1174 INTEGER,
INTENT(IN) :: block_class, n_class(3), first_block(3), &
1176 INTEGER,
INTENT(OUT) :: position(3), copy_lower(3), n_copies(3)
1180 position(1) =
modulo(block_class, n_class(1))
1181 position(2) =
modulo(block_class/n_class(1), n_class(2))
1182 position(3) = block_class/(n_class(1)*n_class(2))
1184 copy_lower(idir) = ceiling(real(first_block(idir) - position(idir), dp)/real(n_class(idir), dp))
1185 n_copies(idir) = max(0, floor(real(first_block(idir) + n_blocks(idir) - 1 - position(idir), dp)/ &
1186 REAL(n_class(idir), dp)) - copy_lower(idir) + 1)
1189 END SUBROUTINE class_copy_range
1208 SUBROUTINE locate_quadrature_block(item, settings, perd, n_class, first_block, n_blocks, &
1209 chunk_class, chunk_part, chunk_parts, chunk_first, &
1210 block_class, copy, block_first, block_points)
1211 INTEGER(int_8),
INTENT(IN) :: item
1213 INTEGER,
INTENT(IN) :: perd(3), n_class(3), first_block(3), &
1214 n_blocks(3), chunk_class(:), &
1215 chunk_part(:), chunk_parts(:)
1216 INTEGER(int_8),
INTENT(IN) :: chunk_first(0:)
1217 INTEGER,
INTENT(OUT) :: block_class, copy(3), block_first(3), &
1220 INTEGER :: copy_lower(3), ichunk, idir, &
1221 lower_chunk, n_copies(3), position(3), &
1226 upper_chunk =
SIZE(chunk_class)
1227 DO WHILE (lower_chunk < upper_chunk)
1228 ichunk = (lower_chunk + upper_chunk)/2
1229 IF (chunk_first(ichunk) <= item)
THEN
1230 lower_chunk = ichunk + 1
1232 upper_chunk = ichunk
1235 ichunk = lower_chunk
1236 block_class = chunk_class(ichunk)
1237 CALL class_copy_range(block_class, n_class, first_block, n_blocks, position, copy_lower, n_copies)
1238 k = int(chunk_part(ichunk),
int_8) + int(chunk_parts(ichunk),
int_8)*(item - chunk_first(ichunk - 1))
1239 copy(1) = copy_lower(1) + int(
modulo(k, int(n_copies(1),
int_8)))
1240 copy(2) = copy_lower(2) + int(
modulo(k/int(n_copies(1),
int_8), int(n_copies(2),
int_8)))
1241 copy(3) = copy_lower(3) + int(k/int(n_copies(1)*n_copies(2),
int_8))
1243 IF (perd(idir) == 1)
THEN
1244 block_first(idir) = settings%subdivisions(idir)*copy(idir) + &
1245 quadrature_block_edge*position(idir) - nint(settings%lower(idir))
1246 block_points(idir) = min(quadrature_block_edge, &
1247 settings%subdivisions(idir) - quadrature_block_edge*position(idir))
1249 block_first(idir) = quadrature_block_edge*position(idir)
1250 block_points(idir) = quadrature_block_edge
1254 END SUBROUTINE locate_quadrature_block
1269 SUBROUTINE prepare_block_class_cache(cache, cells, n_atom, n_points, maxnp, n_class, first_block, &
1270 n_blocks, budget, point_bounds)
1272 INTEGER,
INTENT(IN) :: cells(:, :), n_atom, n_points, maxnp, &
1273 n_class(3), first_block(3), n_blocks(3)
1274 REAL(dp),
INTENT(IN) :: budget
1275 LOGICAL,
INTENT(IN) :: point_bounds
1277 INTEGER :: copy_lower(3), copy_upper(3), idir, &
1278 u_lower(3), u_upper(3)
1280 copy_lower = floor(real(first_block, dp)/real(n_class, dp))
1281 copy_upper = floor(real(first_block + n_blocks - 1, dp)/real(n_class, dp))
1284 IF (
SIZE(cells, 2) > 0)
THEN
1286 u_lower(idir) = minval(cells(idir, :)) - copy_upper(idir)
1287 u_upper(idir) = maxval(cells(idir, :)) - copy_lower(idir)
1290 ALLOCATE (cache%slot(u_lower(1):u_upper(1), u_lower(2):u_upper(2), u_lower(3):u_upper(3), n_atom), &
1293 cache%n_slots = int(min(real(
SIZE(cache%slot), dp), &
1294 budget/(real_bytes*real(n_points, dp)*real(maxnp + 2, dp))))
1295 ALLOCATE (cache%keys(4, cache%n_slots), cache%evaluated(n_points, cache%n_slots), &
1296 cache%values(maxnp, n_points, cache%n_slots))
1297 IF (point_bounds)
ALLOCATE (cache%point_bound(n_points, cache%n_slots))
1299 END SUBROUTINE prepare_block_class_cache
1306 SUBROUTINE reset_block_class_cache(cache, block_class)
1308 INTEGER,
INTENT(IN) :: block_class
1312 DO islot = 1, cache%n_used
1313 cache%slot(cache%keys(1, islot), cache%keys(2, islot), cache%keys(3, islot), cache%keys(4, islot)) = 0
1316 cache%block_class = block_class
1318 END SUBROUTINE reset_block_class_cache
1327 SUBROUTINE prepare_aux_potentials(bs_env, settings, aux_potentials)
1331 INTENT(OUT) :: aux_potentials(:)
1333 CHARACTER(LEN=12) :: spacing_text
1334 INTEGER :: first_u, iatom, ikind, ip, nmesh, np, &
1336 REAL(dp) :: mesh_bytes, mesh_displacement(3), &
1338 REAL(dp),
ALLOCATABLE :: u_pp(:, :)
1343 particles => bs_env%ri_rs%particle_set
1344 cell => bs_env%ri_rs%cell
1345 ALLOCATE (aux_potentials(bs_env%n_atom))
1348 mesh_spacing = 0.0_dp
1349 DO iatom = 1, bs_env%n_atom
1350 ikind = particles(iatom)%atomic_kind%kind_number
1351 basis => bs_env%basis_set_RI(ikind)%gto_basis_set
1352 IF (bs_env%auto_ri%enabled)
THEN
1353 nref = bs_env%auto_ri%sizes_ref_RI(iatom)
1354 np = bs_env%auto_ri%sizes_opt_RI(iatom)
1355 first_u = bs_env%auto_ri%U_Pp_atom_offset(iatom)
1356 ALLOCATE (u_pp(nref, np))
1357 u_pp(:, :) = reshape(bs_env%auto_ri%U_Pp_atom(first_u:first_u + nref*np - 1), [nref, np])
1359 ALLOCATE (u_pp(basis%nsgf, basis%nsgf), source=0.0_dp)
1360 DO ip = 1, basis%nsgf
1361 u_pp(ip, ip) = 1.0_dp
1364 mesh_displacement = settings%origin -
pbc(particles(iatom)%r, cell)
1365 CALL prepare_contracted_potential(basis, u_pp, aux_potentials(iatom), &
1366 max(0.0_dp, bs_env%ri_metric%omega), &
1367 radial_table_bytes=radial_table_budget/real(max(1, bs_env%n_atom), dp), &
1368 mesh_step=settings%step, &
1369 mesh_displacement=mesh_displacement)
1370 IF (
ALLOCATED(aux_potentials(iatom)%mesh_moments))
THEN
1372 mesh_bytes = mesh_bytes + real_bytes*real(
SIZE(aux_potentials(iatom)%mesh_moments, kind=
int_8), dp)
1373 mesh_spacing = aux_potentials(iatom)%mesh_spacing
1377 IF (bs_env%unit_nr > 0)
THEN
1379 WRITE (bs_env%unit_nr,
'(T2,A,T69,F12.1)')
'd_lP radial mesh storage [MiB/rank]', mesh_bytes/bytes_per_mib
1380 WRITE (spacing_text,
'(ES12.1E1)') mesh_spacing
1381 IF (index(spacing_text,
'*') > 0)
WRITE (spacing_text,
'(ES12.1E2)') mesh_spacing
1382 IF (index(spacing_text,
'*') > 0)
WRITE (spacing_text,
'(ES12.1E3)') mesh_spacing
1383 WRITE (bs_env%unit_nr,
'(T2,A,T69,A12)')
'd_lP radial mesh squared spacing [bohr^2]', spacing_text
1387 END SUBROUTINE prepare_aux_potentials
1395 SUBROUTINE prepare_ao_images(bs_env, grid_points, images)
1397 REAL(dp),
INTENT(IN) :: grid_points(:, :)
1400 INTEGER :: iatom, icell, iimage, ikind, maxao, nao
1401 REAL(dp) :: center(3), cutoff2
1402 REAL(dp),
ALLOCATABLE :: primary(:, :)
1407 cell => bs_env%ri_rs%cell
1408 particles => bs_env%ri_rs%particle_set
1409 maxao = maxval(bs_env%i_ao_end_from_atom - bs_env%i_ao_start_from_atom + 1)
1410 ALLOCATE (primary(bs_env%ri_rs%n_grid_points, maxao))
1411 ALLOCATE (images(bs_env%n_atom*
SIZE(bs_env%index_to_cell_3c, 2)))
1413 DO icell = 1,
SIZE(bs_env%index_to_cell_3c, 2)
1414 DO iatom = 1, bs_env%n_atom
1415 ikind = particles(iatom)%atomic_kind%kind_number
1416 basis => bs_env%basis_set_AO(ikind)%gto_basis_set
1417 nao = bs_env%i_ao_end_from_atom(iatom) - bs_env%i_ao_start_from_atom(iatom) + 1
1418 center =
pbc(particles(iatom)%r, cell) + matmul(bs_env%hmat, real(bs_env%index_to_cell_3c(:, icell), dp))
1419 cutoff2 = bs_env%ri_rs%radius_ao_per_atom(iatom)**2
1420 IF (bs_env%ri_rs%cutoff_radius_ri_ao > 0.0_dp) cutoff2 = bs_env%ri_rs%cutoff_radius_ri_ao**2
1423 cutoff_squared=cutoff2, minimum_image=.false.)
1424 IF (.NOT. any(primary(:, 1:nao) /= 0.0_dp)) cycle
1426 images(iimage)%basis => basis
1427 images(iimage)%atom = iatom
1428 images(iimage)%cell = bs_env%index_to_cell_3c(:, icell)
1429 images(iimage)%center = center
1430 ALLOCATE (images(iimage)%primary(bs_env%ri_rs%n_grid_points, nao))
1431 images(iimage)%primary(:, :) = primary(:, 1:nao)
1432 CALL pack_nonzero_ao_rows(images(iimage))
1433 CALL bound_ao_image(images(iimage))
1437 END SUBROUTINE prepare_ao_images
1444 SUBROUTINE pack_nonzero_ao_rows(image)
1447 INTEGER :: il, ipacked, nkeep, nl
1448 LOGICAL,
ALLOCATABLE :: nonzero(:)
1449 REAL(dp),
ALLOCATABLE :: primary(:, :)
1451 nl =
SIZE(image%primary, 1)
1452 ALLOCATE (nonzero(nl))
1454 nonzero(il) = any(abs(image%primary(il, :)) > 0.0_dp)
1456 nkeep = count(nonzero)
1457 IF (nkeep == 0 .OR. nkeep > nl/2)
RETURN
1458 ALLOCATE (primary(nkeep,
SIZE(image%primary, 2)), image%primary_l(nkeep))
1461 IF (.NOT. nonzero(il)) cycle
1462 ipacked = ipacked + 1
1463 primary(ipacked, :) = image%primary(il, :)
1464 image%primary_l(ipacked) = il
1466 CALL move_alloc(primary, image%primary)
1468 END SUBROUTINE pack_nonzero_ao_rows
1475 SUBROUTINE bound_ao_image(image)
1478 INTEGER :: ico, idir, il, ipgf, irow, iset, isgf, &
1480 REAL(dp) :: amplitude, exponent, factor
1481 REAL(dp),
ALLOCATABLE :: ao_bound(:)
1484 basis => image%basis
1485 image%decay = huge(0.0_dp)
1486 ALLOCATE (ao_bound(
SIZE(image%primary, 2)), source=0.0_dp)
1487 DO iset = 1, basis%nset
1488 ncart =
ncoset(basis%lmax(iset))
1489 DO ipgf = 1, basis%npgf(iset)
1490 exponent = basis%zet(ipgf, iset)
1491 cpassert(exponent > 0.0_dp)
1492 image%decay = min(image%decay, 0.5_dp*exponent)
1496 power =
indco(idir, ico)
1497 IF (power > 0) factor = factor*(real(power, dp)/(exponent*exp(1.0_dp)))** &
1498 (0.5_dp*real(power, dp))
1500 irow = (ipgf - 1)*ncart + ico
1501 DO isgf = basis%first_sgf(1, iset), basis%last_sgf(basis%nshell(iset), iset)
1502 ao_bound(isgf) = ao_bound(isgf) + abs(basis%sphi(irow, isgf))*factor
1507 image%bound = 0.0_dp
1508 DO il = 1,
SIZE(image%primary, 1)
1510 DO isgf = 1,
SIZE(ao_bound)
1511 amplitude = amplitude + abs(image%primary(il, isgf))*ao_bound(isgf)
1513 image%bound = max(image%bound, amplitude)
1515 CALL prepare_ao_radial_envelope(image)
1517 END SUBROUTINE bound_ao_image
1525 SUBROUTINE prepare_ao_radial_envelope(image)
1528 INTEGER :: ico, idegree, idir, iexponent, il, ipgf, &
1529 irow, iset, isgf, ncart, power
1530 REAL(dp) :: amplitude, angular_factor
1531 REAL(dp),
ALLOCATABLE :: ao_weight(:)
1534 basis => image%basis
1535 ALLOCATE (image%envelope_exponents(sum(basis%npgf(:basis%nset))), &
1536 image%radial_envelope(0:maxval(basis%lmax(:basis%nset)), sum(basis%npgf(:basis%nset))), &
1537 ao_weight(
SIZE(image%primary, 2)))
1539 DO isgf = 1,
SIZE(ao_weight)
1540 DO il = 1,
SIZE(image%primary, 1)
1541 ao_weight(isgf) = max(ao_weight(isgf), abs(image%primary(il, isgf)))
1544 image%radial_envelope = 0.0_dp
1546 DO iset = 1, basis%nset
1547 ncart =
ncoset(basis%lmax(iset))
1548 DO ipgf = 1, basis%npgf(iset)
1549 iexponent = iexponent + 1
1550 image%envelope_exponents(iexponent) = basis%zet(ipgf, iset)
1552 idegree = sum(
indco(:, ico))
1553 angular_factor = 1.0_dp
1555 power =
indco(idir, ico)
1556 IF (power > 0) angular_factor = angular_factor* &
1557 (real(power, dp)/real(idegree, dp))**(0.5_dp*real(power, dp))
1559 irow = (ipgf - 1)*ncart + ico
1561 DO isgf = basis%first_sgf(1, iset), basis%last_sgf(basis%nshell(iset), iset)
1562 amplitude = amplitude + ao_weight(isgf)*abs(basis%sphi(irow, isgf))
1564 image%radial_envelope(idegree, iexponent) = &
1565 image%radial_envelope(idegree, iexponent) + angular_factor*amplitude
1569 image%radial_envelope(:, :) = image%radial_envelope* &
1570 (1.0_dp + epsilon(1.0_dp)* &
1571 (64.0_dp + 4.0_dp*real(
SIZE(image%radial_envelope), dp)* &
1572 REAL(size(ao_weight), dp)))
1574 END SUBROUTINE prepare_ao_radial_envelope
1583 PURE FUNCTION bound_ao_image_distance(image, distance_squared)
RESULT(bound)
1588 INTEGER :: idegree, iexponent, lmax
1589 REAL(dp) :: exponent, polynomial, radius, &
1593 lmax = ubound(image%radial_envelope, 1)
1595 DO iexponent = 1,
SIZE(image%envelope_exponents)
1596 exponent = image%envelope_exponents(iexponent)
1598 polynomial = image%radial_envelope(lmax, iexponent)
1599 DO idegree = lmax - 1, 0, -1
1600 polynomial = image%radial_envelope(idegree, iexponent) + radius*polynomial
1604 DO idegree = 0, lmax
1606 bound = bound + image%radial_envelope(idegree, iexponent)* &
1607 radius_squared**(0.5_dp*real(idegree, dp))*exp(-exponent*radius_squared)
1611 END FUNCTION bound_ao_image_distance
1626 SUBROUTINE evaluate_rho_l_squared(images, points, point_index, copy, cache, field_squared, tolerance)
1628 REAL(dp),
INTENT(IN) :: points(:, :)
1629 INTEGER,
INTENT(IN) :: point_index(:), copy(3)
1631 REAL(dp),
INTENT(OUT) :: field_squared(:, :)
1632 REAL(dp),
INTENT(IN) :: tolerance
1634 CHARACTER(LEN=*),
PARAMETER :: routinen =
'evaluate_rho_l_squared'
1636 INTEGER :: first, handle, ig, iimage, islot, last, &
1637 nao, ng, nimages, nmissing, nslice, &
1639 INTEGER,
ALLOCATABLE :: missing_indices(:)
1640 REAL(dp),
ALLOCATABLE :: values(:, :)
1641 LOGICAL :: image_needed(size(images))
1642 INTEGER :: image_slot(size(images))
1644 CALL timeset(routinen, handle)
1646 ng =
SIZE(points, 2)
1648 DO iimage = 1,
SIZE(images)
1649 IF (.NOT.
ALLOCATED(images(iimage)%primary))
EXIT
1650 nimages = nimages + 1
1652 CALL screen_ao_images(images(1:nimages), points, tolerance, image_needed(1:nimages))
1653 IF (.NOT. any(image_needed(1:nimages)))
THEN
1654 field_squared = 0.0_dp
1655 CALL timestop(handle)
1662 ALLOCATE (missing_indices(ng))
1664 DO iimage = 1, nimages
1665 IF (.NOT. image_needed(iimage)) cycle
1666 u = images(iimage)%cell - copy
1668 islot = cache%slot(u(1), u(2), u(3), images(iimage)%atom)
1669 IF (islot == 0)
THEN
1671 IF (cache%n_used < cache%n_slots)
THEN
1672 cache%n_used = cache%n_used + 1
1673 islot = cache%n_used
1674 cache%keys(:, islot) = [u, images(iimage)%atom]
1677 IF (islot == 0) cycle
1678 cache%slot(u(1), u(2), u(3), images(iimage)%atom) = islot
1679 cache%evaluated(:, islot) = .false.
1681 image_slot(iimage) = islot
1684 IF (.NOT. cache%evaluated(point_index(ig), islot))
THEN
1685 nmissing = nmissing + 1
1686 missing_indices(nmissing) = ig
1689 IF (nmissing == 0) cycle
1690 nao =
SIZE(images(iimage)%primary, 2)
1691 ALLOCATE (values(nmissing, nao))
1692 CALL evaluate_mu_r_values(values, points(:, missing_indices(1:nmissing)), &
1693 images(iimage)%basis, images(iimage)%center)
1694 DO row = 1, nmissing
1695 cache%values(1:nao, point_index(missing_indices(row)), islot) = values(row, :)
1696 cache%evaluated(point_index(missing_indices(row)), islot) = .true.
1701 DEALLOCATE (missing_indices)
1705 nslice = max(1, (ng + nthreads - 1)/nthreads)
1709 DO first = 1, ng, nslice
1710 last = min(ng, first + nslice - 1)
1711 CALL evaluate_rho_l_squared_slice(images(1:nimages), points(:, first:last), point_index(first:last), &
1712 image_slot(1:nimages), cache, field_squared(first:last, :), tolerance)
1716 CALL timestop(handle)
1718 END SUBROUTINE evaluate_rho_l_squared
1730 SUBROUTINE screen_ao_images(images, points, tolerance, image_needed)
1732 REAL(dp),
INTENT(IN) :: points(:, :), tolerance
1733 LOGICAL,
INTENT(OUT) :: image_needed(:)
1735 INTEGER :: iimage, nimages
1736 REAL(dp) :: amplitude, delta, lower(3), &
1737 root_tolerance, upper(3), &
1738 image_bounds(size(images))
1740 image_needed = .true.
1741 IF (tolerance <= 0.0_dp)
RETURN
1742 nimages =
SIZE(images)
1743 lower = minval(points, dim=2)
1744 upper = maxval(points, dim=2)
1745 DO iimage = 1, nimages
1746 image_bounds(iimage) = images(iimage)%bound* &
1747 exp(-images(iimage)%decay*distance_to_box_squared(images(iimage)%center, lower, upper))
1749 amplitude = sum(image_bounds)*(1.0_dp + real(nimages, dp)*epsilon(1.0_dp))
1750 root_tolerance = sqrt(tolerance)
1751 IF (amplitude <= root_tolerance)
THEN
1752 image_needed = .false.
1755 delta = (tolerance/amplitude)/(sqrt(1.0_dp + (root_tolerance/amplitude)**2) + 1.0_dp)
1756 delta = delta/real(max(1, nimages), dp)
1757 DO iimage = 1, nimages
1758 IF (image_bounds(iimage) <= delta)
THEN
1759 image_needed(iimage) = .false.
1761 image_needed(iimage) = bound_ao_image_distance( &
1762 images(iimage), distance_to_box_squared(images(iimage)%center, lower, upper)) &
1767 END SUBROUTINE screen_ao_images
1780 SUBROUTINE evaluate_rho_l_squared_slice(images, points, point_index, image_slot, cache, field_squared, &
1783 REAL(dp),
INTENT(IN) :: points(:, :)
1784 INTEGER,
INTENT(IN) :: point_index(:), image_slot(:)
1786 REAL(dp),
INTENT(OUT) :: field_squared(:, :)
1787 REAL(dp),
INTENT(IN) :: tolerance
1789 INTEGER :: ig, iimage, il, nao, ng, nl, nprimary
1790 REAL(dp),
ALLOCATABLE :: field(:, :), image_field(:, :), &
1792 LOGICAL :: image_needed(size(images))
1794 ng =
SIZE(points, 2)
1795 nl =
SIZE(field_squared, 2)
1796 CALL screen_ao_images(images, points, tolerance, image_needed)
1797 ALLOCATE (field(ng, nl), source=0.0_dp)
1798 DO iimage = 1,
SIZE(images)
1799 IF (.NOT. image_needed(iimage)) cycle
1800 nao =
SIZE(images(iimage)%primary, 2)
1801 ALLOCATE (values(ng, nao))
1802 IF (image_slot(iimage) > 0)
THEN
1804 values(ig, :) = cache%values(1:nao, point_index(ig), image_slot(iimage))
1807 CALL evaluate_mu_r_values(values, points, images(iimage)%basis, images(iimage)%center)
1809 nprimary =
SIZE(images(iimage)%primary, 1)
1810 IF (
ALLOCATED(images(iimage)%primary_l))
THEN
1811 IF (.NOT.
ALLOCATED(image_field))
ALLOCATE (image_field(ng, nl))
1812 CALL dgemm(
'N',
'T', ng, nprimary, nao, 1.0_dp, values, ng, &
1813 images(iimage)%primary, nprimary, 0.0_dp, image_field, ng)
1815 field(:, images(iimage)%primary_l(il)) = &
1816 field(:, images(iimage)%primary_l(il)) + image_field(:, il)
1819 CALL dgemm(
'N',
'T', ng, nl, nao, 1.0_dp, values, ng, &
1820 images(iimage)%primary, nl, 1.0_dp, field, ng)
1824 field_squared = field**2
1826 END SUBROUTINE evaluate_rho_l_squared_slice
1837 SUBROUTINE evaluate_mu_r_values(values, points, basis, center)
1838 REAL(dp),
INTENT(OUT) :: values(:, :)
1839 REAL(dp),
INTENT(IN) :: points(:, :)
1841 REAL(dp),
INTENT(IN) :: center(3)
1843 INTEGER :: first_sgf, ico, ig, ipgf, ipower, iset, &
1844 last_sgf, ncart, ng, nprimitive
1845 INTEGER,
ALLOCATABLE :: offsets(:)
1846 LOGICAL :: parallel_points
1847 REAL(dp) :: relative(3)
1848 REAL(dp),
ALLOCATABLE :: coordinate_power(:, :), exponential(:), &
1849 monomial(:, :), primitive(:, :), &
1852 ng =
SIZE(points, 2)
1854 ALLOCATE (offsets(basis%nset), monomial(ng,
ncoset(maxval(basis%lmax))), &
1855 coordinate_power(3, 0:maxval(basis%lmax)), radius2(ng), exponential(ng))
1857 DO iset = 1, basis%nset
1858 offsets(iset) = nprimitive
1859 nprimitive = nprimitive + basis%npgf(iset)*
ncoset(basis%lmax(iset))
1861 ALLOCATE (primitive(ng, nprimitive))
1862 parallel_points = .true.
1869 relative = points(:, ig) - center
1870 radius2(ig) = dot_product(relative, relative)
1871 coordinate_power(:, 0) = 1.0_dp
1872 DO ipower = 1, ubound(coordinate_power, 2)
1873 coordinate_power(:, ipower) = coordinate_power(:, ipower - 1)*relative
1875 DO ico = 1,
SIZE(monomial, 2)
1876 monomial(ig, ico) = coordinate_power(1,
indco(1, ico))* &
1877 coordinate_power(2,
indco(2, ico))*coordinate_power(3,
indco(3, ico))
1882 DO iset = 1, basis%nset
1883 ncart =
ncoset(basis%lmax(iset))
1885 DO ipgf = 1, basis%npgf(iset)
1888 exponential(ig) = exp(-basis%zet(ipgf, iset)*radius2(ig))
1893 primitive(ig, offsets(iset) + (ipgf - 1)*ncart + ico) = monomial(ig, ico)*exponential(ig)
1901 DO iset = 1, basis%nset
1902 nprimitive = basis%npgf(iset)*
ncoset(basis%lmax(iset))
1903 first_sgf = basis%first_sgf(1, iset)
1904 last_sgf = basis%last_sgf(basis%nshell(iset), iset)
1905 CALL dgemm(
'N',
'N', ng, last_sgf - first_sgf + 1, nprimitive, &
1906 1.0_dp, primitive(:, offsets(iset) + 1:), ng, &
1907 basis%sphi(:, first_sgf:last_sgf),
SIZE(basis%sphi, 1), &
1908 1.0_dp, values(:, first_sgf:last_sgf), ng)
1911 END SUBROUTINE evaluate_mu_r_values
1922 SUBROUTINE auxiliary_potential_bound(bs_env, aux_potentials, envelopes)
1925 INTENT(IN) :: aux_potentials(:)
1926 REAL(dp),
ALLOCATABLE,
INTENT(OUT) :: envelopes(:, :)
1928 INTEGER :: iatom, ico, idir, ikind, ipgf, &
1929 irow_packed, iset, ishell, l, power
1930 LOGICAL,
ALLOCATABLE :: angular_used(:)
1931 REAL(dp) :: exponent, factor
1932 REAL(dp),
ALLOCATABLE :: bounds(:)
1936 particles => bs_env%ri_rs%particle_set
1937 ALLOCATE (envelopes(3, bs_env%n_atom))
1939 DO iatom = 1, bs_env%n_atom
1940 ikind = particles(iatom)%atomic_kind%kind_number
1941 basis => bs_env%basis_set_RI(ikind)%gto_basis_set
1942 cpassert(
ASSOCIATED(basis))
1943 ALLOCATE (bounds(
SIZE(aux_potentials(iatom)%coefficients, 2)))
1944 ALLOCATE (angular_used(0:maxval(basis%lmax)))
1947 envelopes(2, iatom) = huge(1.0_dp)
1948 DO iset = 1, basis%nset
1949 angular_used = .false.
1950 DO ishell = 1, basis%nshell(iset)
1951 angular_used(basis%l(ishell, iset)) = .true.
1953 DO ipgf = 1, basis%npgf(iset)
1954 exponent = basis%zet(ipgf, iset)
1955 envelopes(2, iatom) = min(envelopes(2, iatom), exponent)
1956 envelopes(3, iatom) = max(envelopes(3, iatom), exponent)
1957 DO l = 0, basis%lmax(iset)
1958 IF (.NOT. angular_used(l)) cycle
1960 irow_packed = irow_packed + 1
1961 factor = 4.0_dp*
pi/exponent
1963 power =
indco(idir, ico)
1964 IF (power > 0) factor = factor*(real(power, dp)/(exponent*exp(1.0_dp)))** &
1965 (0.5_dp*real(power, dp))
1967 bounds(:) = bounds(:) + abs(aux_potentials(iatom)%coefficients(irow_packed, :))*factor
1972 envelopes(1, iatom) = maxval(bounds)
1973 DEALLOCATE (bounds, angular_used)
1976 END SUBROUTINE auxiliary_potential_bound
2005 SUBROUTINE integrate_potentials(bs_env, cells_R_d_lP, include_lP_R, include_l_blocks_P_R, &
2006 points, point_index, field_squared, weight, envelopes, blocks, &
2007 threshold, copy, cache, potential_points, contraction_products, &
2008 d_lP_R, aux_potentials)
2010 INTEGER,
INTENT(IN) :: cells_r_d_lp(:, :)
2011 LOGICAL,
INTENT(IN) :: include_lp_r(:, :, :), &
2012 include_l_blocks_p_r(:, :, :)
2013 REAL(dp),
INTENT(IN) :: points(:, :)
2014 INTEGER,
INTENT(IN) :: point_index(:)
2015 REAL(dp),
INTENT(IN) :: field_squared(:, :), weight, &
2018 REAL(dp),
INTENT(IN) :: threshold
2019 INTEGER,
INTENT(IN) :: copy(3)
2021 INTEGER(int_8),
INTENT(INOUT) :: potential_points, contraction_products
2022 REAL(dp),
INTENT(INOUT) :: d_lp_r(:, :, :)
2024 INTENT(IN) :: aux_potentials(:)
2026 CHARACTER(LEN=*),
PARAMETER :: routinen =
'integrate_potentials'
2028 INTEGER :: firstp, handle, iatom, iblock, ig, ikind, ilocal, iradial, islot, it, lastp, &
2029 maxnp, nactive, nmissing, np, nthreads, nunion, row, u(3)
2030 REAL(dp) :: center(3), decay, field_max, &
2031 points_lower(3), points_upper(3)
2032 REAL(dp),
ALLOCATABLE :: block_field_bound(:, :), block_ri(:, :), field_work(:, :), &
2033 maximum_field(:), point_bound(:), potential(:, :), potential_t(:, :)
2034 LOGICAL :: point_needed(size(points, 2))
2035 INTEGER :: union_indices(size(points, 2)), missing_indices(size(points, 2))
2038 LOGICAL :: block_needed(blocks%nblocks)
2039 INTEGER :: block_active_last(blocks%nblocks), block_active_first(blocks%nblocks)
2041 INTEGER :: active_l(bs_env%ri_rs%n_grid_points)
2043 CALL timeset(routinen, handle)
2045 cell => bs_env%ri_rs%cell
2046 particles => bs_env%ri_rs%particle_set
2047 maxnp = maxval(bs_env%i_RI_end_from_atom - bs_env%i_RI_start_from_atom + 1)
2049 ALLOCATE (block_field_bound(
SIZE(points, 2), blocks%nblocks))
2051 DO iblock = 1, blocks%nblocks
2052 block_field_bound(:, iblock) = 0.0_dp
2053 DO ilocal = blocks%first(iblock), blocks%first(iblock + 1) - 1
2054 DO ig = 1,
SIZE(points, 2)
2055 block_field_bound(ig, iblock) = max(block_field_bound(ig, iblock), &
2056 abs(field_squared(ig, blocks%indices(ilocal))))
2061 field_max = maxval(block_field_bound)
2062 points_lower = minval(points, dim=2)
2063 points_upper = maxval(points, dim=2)
2069 nthreads = min(nthreads, max(1, int(thread_workspace_bytes/ &
2070 (real_bytes*(real(bs_env%ri_rs%n_grid_points, dp)*(maxnp +
SIZE(points, 2)) + &
2071 2.0_dp*real(
SIZE(points, 2), dp)*maxnp)))))
2086 ALLOCATE (block_ri(bs_env%ri_rs%n_grid_points, maxnp), &
2087 field_work(
SIZE(points, 2), bs_env%ri_rs%n_grid_points), point_bound(
SIZE(points, 2)), &
2088 maximum_field(
SIZE(points, 2)), potential(
SIZE(points, 2), maxnp), &
2089 potential_t(maxnp,
SIZE(points, 2)))
2092 DO it = 1,
SIZE(cells_r_d_lp, 2)
2093 DO iatom = 1, bs_env%n_atom
2094 ikind = particles(iatom)%atomic_kind%kind_number
2095 basis => bs_env%basis_set_RI(ikind)%gto_basis_set
2096 firstp = bs_env%i_RI_start_from_atom(iatom)
2097 lastp = bs_env%i_RI_end_from_atom(iatom)
2098 np = lastp - firstp + 1
2099 center =
pbc(particles(iatom)%r, cell) + matmul(bs_env%hmat, real(cells_r_d_lp(:, it), dp))
2100 IF (.NOT. any(include_l_blocks_p_r(:, iatom, it))) cycle
2102 u = cells_r_d_lp(:, it) - copy
2103 islot = cache%slot(u(1), u(2), u(3), iatom)
2104 decay = envelopes(2, iatom)*bs_env%ri_metric%omega**2/ &
2105 (envelopes(2, iatom) + 2.0_dp*bs_env%ri_metric%omega**2)
2107 IF (field_max*envelopes(1, iatom)* &
2108 exp(-decay*distance_to_box_squared(center, points_lower, points_upper)) <= threshold)
THEN
2111 DO ig = 1,
SIZE(points, 2)
2113 IF (cache%point_bound(point_index(ig), islot) >= 0.0_dp)
THEN
2114 point_bound(ig) = cache%point_bound(point_index(ig), islot)
2118 point_bound(ig) = envelopes(1, iatom)
2119 IF (decay > 0.0_dp) point_bound(ig) = point_bound(ig)* &
2120 exp(-decay*sum((points(:, ig) - center)**2))
2121 IF (
ALLOCATED(aux_potentials(iatom)%short_bounds))
THEN
2122 iradial = int(norm2(points(:, ig) - center)/short_bound_spacing)
2123 IF (iradial < n_short_bounds)
THEN
2124 point_bound(ig) = min(point_bound(ig), aux_potentials(iatom)%short_bounds(iradial))
2127 IF (islot > 0) cache%point_bound(point_index(ig), islot) = point_bound(ig)
2130 block_needed = .false.
2131 maximum_field = 0.0_dp
2132 DO iblock = 1, blocks%nblocks
2133 IF (.NOT. include_l_blocks_p_r(iblock, iatom, it)) cycle
2134 block_needed(iblock) = any(block_field_bound(:, iblock)*point_bound > threshold)
2135 IF (block_needed(iblock)) maximum_field(:) = max(maximum_field, block_field_bound(:, iblock))
2137 point_needed = maximum_field*point_bound > threshold
2139 DO ig = 1,
SIZE(points, 2)
2140 IF (point_needed(ig))
THEN
2142 union_indices(nunion) = ig
2145 IF (nunion == 0) cycle
2146 IF (islot == 0)
THEN
2148 IF (cache%n_used < cache%n_slots)
THEN
2149 cache%n_used = cache%n_used + 1
2150 islot = cache%n_used
2151 cache%keys(:, islot) = [u, iatom]
2152 cache%slot(u(1), u(2), u(3), iatom) = islot
2156 cache%evaluated(:, islot) = .false.
2157 cache%point_bound(:, islot) = -1.0_dp
2158 cache%point_bound(point_index, islot) = point_bound(1:
SIZE(points, 2))
2165 IF (.NOT. cache%evaluated(point_index(union_indices(row)), islot))
THEN
2166 nmissing = nmissing + 1
2167 missing_indices(nmissing) = union_indices(row)
2170 IF (nmissing > 0)
THEN
2171 CALL contract_selected_potentials(potential(:, 1:np), &
2172 points(:, missing_indices(1:nmissing)), &
2173 basis, center, aux_potentials(iatom))
2174 DO row = 1, nmissing
2175 cache%values(1:np, point_index(missing_indices(row)), islot) = potential(row, 1:np)
2176 cache%evaluated(point_index(missing_indices(row)), islot) = .true.
2180 potential_t(1:np, row) = cache%values(1:np, point_index(union_indices(row)), islot)
2182 potential_points = potential_points + int(nmissing,
int_8)
2184 CALL contract_selected_potentials(potential(:, 1:np), &
2185 points(:, union_indices(1:nunion)), &
2186 basis, center, aux_potentials(iatom))
2187 potential_t(1:np, 1:nunion) = transpose(potential(1:nunion, 1:np))
2188 potential_points = potential_points + int(nunion,
int_8)
2191 block_active_first = 0
2192 block_active_last = -1
2193 DO iblock = 1, blocks%nblocks
2194 IF (.NOT. block_needed(iblock)) cycle
2195 block_active_first(iblock) = nactive + 1
2196 DO ilocal = blocks%first(iblock), blocks%first(iblock + 1) - 1
2197 IF (include_lp_r(blocks%indices(ilocal), iatom, it))
THEN
2198 nactive = nactive + 1
2199 active_l(nactive) = blocks%indices(ilocal)
2202 block_active_last(iblock) = nactive
2204 DO iblock = 1, blocks%nblocks
2205 IF (.NOT. block_needed(iblock)) cycle
2207 ig = union_indices(row)
2208 point_needed(row) = block_field_bound(ig, iblock)*point_bound(ig) > threshold
2210 DO ilocal = block_active_first(iblock), block_active_last(iblock)
2212 field_work(row, ilocal) = merge(field_squared(union_indices(row), active_l(ilocal)), &
2213 0.0_dp, point_needed(row))
2217 CALL dgemm(
'T',
'T', nactive, np, nunion, weight, field_work,
SIZE(field_work, 1), &
2218 potential_t,
SIZE(potential_t, 1), 0.0_dp, block_ri,
SIZE(block_ri, 1))
2219 DO ilocal = 1, nactive
2220 d_lp_r(active_l(ilocal), firstp:lastp, it) = &
2221 d_lp_r(active_l(ilocal), firstp:lastp, it) + block_ri(ilocal, 1:np)
2223 contraction_products = contraction_products + &
2231 DEALLOCATE (block_ri, field_work, maximum_field, point_bound, potential, potential_t)
2235 CALL timestop(handle)
2237 END SUBROUTINE integrate_potentials
2246 PURE FUNCTION distance_to_box_squared(point, lower, upper)
RESULT(distance_squared)
2247 REAL(dp),
INTENT(IN) :: point(3), lower(3), upper(3)
2255 delta = max(lower(idir) - point(idir), point(idir) - upper(idir), 0.0_dp)
2258 END FUNCTION distance_to_box_squared
2270 SUBROUTINE prepare_contracted_potential(basis, U_Pp, contracted, attenuation, radial_table_bytes, &
2271 mesh_step, mesh_displacement)
2273 REAL(dp),
INTENT(IN) :: u_pp(:, :)
2275 REAL(dp),
INTENT(IN) :: attenuation, radial_table_bytes, &
2276 mesh_step(3, 3), mesh_displacement(3)
2278 INTEGER :: ico, iopt, ipgf, irow, irow_packed, &
2279 iset, isgf, ishell, l, ncart, &
2280 ninterval, np, nrows
2281 LOGICAL,
ALLOCATABLE :: angular_used(:)
2282 REAL(dp) :: bytes_per_node, table_bytes
2283 REAL(dp),
ALLOCATABLE :: full_abscissae(:), moments(:, :)
2285 ALLOCATE (angular_used(0:maxval(basis%lmax)))
2286 cpassert(
SIZE(u_pp, 1) == basis%nsgf)
2289 DO iset = 1, basis%nset
2290 angular_used = .false.
2291 DO ishell = 1, basis%nshell(iset)
2292 angular_used(basis%l(ishell, iset)) = .true.
2294 DO l = 0, basis%lmax(iset)
2295 IF (angular_used(l)) nrows = nrows + basis%npgf(iset)*(
ncoset(l) -
ncoset(l - 1))
2300 ALLOCATE (contracted%coefficients(nrows, np), source=0.0_dp)
2302 DO iset = 1, basis%nset
2303 ncart =
ncoset(basis%lmax(iset))
2304 angular_used = .false.
2305 DO ishell = 1, basis%nshell(iset)
2306 angular_used(basis%l(ishell, iset)) = .true.
2308 DO ipgf = 1, basis%npgf(iset)
2309 DO l = 0, basis%lmax(iset)
2310 IF (.NOT. angular_used(l)) cycle
2312 irow = (ipgf - 1)*ncart + ico
2313 irow_packed = irow_packed + 1
2314 DO ishell = 1, basis%nshell(iset)
2315 IF (basis%l(ishell, iset) /= l) cycle
2316 DO isgf = basis%first_sgf(ishell, iset), basis%last_sgf(ishell, iset)
2318 contracted%coefficients(irow_packed, iopt) = &
2319 contracted%coefficients(irow_packed, iopt) + basis%sphi(irow, isgf)*u_pp(isgf, iopt)
2327 DEALLOCATE (angular_used)
2328 IF (basis%nsgf < nrows)
CALL prepare_spherical_potential_factorization(basis, u_pp, contracted)
2329 contracted%attenuation = max(0.0_dp, attenuation)
2330 IF (contracted%attenuation > 0.0_dp)
THEN
2331 CALL prepare_short_potential_bounds(basis, contracted%coefficients, contracted%attenuation, &
2332 contracted%short_bounds)
2334 CALL prepare_radial_series(basis, contracted%attenuation, contracted%series, contracted%short_series)
2335 table_bytes = max(0.0_dp, radial_table_bytes)
2337 bytes_per_node = real_bytes*real(maxval(basis%lmax) + 7, dp)* &
2338 REAL(maxval(basis%npgf)*basis%nset + 1, dp)
2339 CALL prepare_short_radial_grid(short_grid_xmax, contracted%short_abscissae)
2340 table_bytes = max(0.0_dp, table_bytes - real_bytes*real(
SIZE(contracted%short_abscissae), dp))
2341 ninterval = int(min(real(
SIZE(contracted%short_abscissae), dp), &
2342 table_bytes/bytes_per_node)) - 1
2343 IF (ninterval < 1)
THEN
2344 DEALLOCATE (contracted%short_abscissae)
2347 IF (ninterval < ubound(contracted%short_abscissae, 1))
THEN
2348 CALL move_alloc(contracted%short_abscissae, full_abscissae)
2349 ALLOCATE (contracted%short_abscissae(0:ninterval))
2350 contracted%short_abscissae(:) = full_abscissae(0:ninterval)
2351 DEALLOCATE (full_abscissae)
2353 ALLOCATE (contracted%short_moments(0:maxval(basis%lmax) + 6, &
2354 0:ninterval, maxval(basis%npgf), basis%nset))
2355 DO iset = 1, basis%nset
2356 DO ipgf = 1, basis%npgf(iset)
2357 CALL prepare_short_radial_table(basis%zet(ipgf, iset), contracted%attenuation, &
2358 maxval(basis%lmax), moments, ninterval, abscissae=contracted%short_abscissae)
2359 contracted%short_moments(:, :, ipgf, iset) = moments
2360 DEALLOCATE (moments)
2364 table_bytes = max(0.0_dp, table_bytes - real_bytes*real(
SIZE(contracted%short_moments, kind=
int_8), dp))
2365 CALL prepare_mesh_radial_moments(basis, contracted, mesh_step, mesh_displacement, table_bytes)
2367 END SUBROUTINE prepare_contracted_potential
2382 SUBROUTINE prepare_short_potential_bounds(basis, coefficients, omega, radial_bounds)
2384 REAL(dp),
INTENT(IN) :: coefficients(:, :), omega
2385 REAL(dp),
ALLOCATABLE,
INTENT(OUT) :: radial_bounds(:)
2387 INTEGER,
PARAMETER :: n_rectangles = 32
2389 INTEGER :: ico, idir, ifactor, il, ipgf, ipower, &
2390 iq, ir, irow, iset, ishell, istart
2391 REAL(dp) :: a, angular, factor, integral, lower, &
2394 REAL(dp),
DIMENSION(SIZE(coefficients, 2)) :: bounds, cscale, sumsq, triangle
2395 LOGICAL :: angular_used(0:maxval(basis%lmax))
2397 ALLOCATE (radial_bounds(0:n_short_bounds - 1))
2398 DO ir = 0, n_short_bounds - 1
2399 rlo = real(ir, dp)*short_bound_spacing
2400 rhi = real(ir + 1, dp)*short_bound_spacing
2403 DO iset = 1, basis%nset
2404 angular_used = .false.
2405 DO ishell = 1, basis%nshell(iset)
2406 angular_used(basis%l(ishell, iset)) = .true.
2408 DO ipgf = 1, basis%npgf(iset)
2409 a = basis%zet(ipgf, iset)
2410 lower = sqrt(omega**2/(a + omega**2))
2411 width = 1.0_dp - lower
2413 DO il = 0, basis%lmax(iset)
2414 IF (.NOT. angular_used(il)) cycle
2416 DO iq = 0, n_rectangles - 1
2417 tlo = lower + width*real(iq, dp)/real(n_rectangles, dp)
2418 thi = lower + width*real(iq + 1, dp)/real(n_rectangles, dp)
2420 IF (x > 0.0_dp) peak = max(tlo, min(thi, sqrt(real(il, dp)/x)))
2421 integral = integral + width/real(n_rectangles, dp)*peak**(2*il)*exp(-x*peak**2)
2423 factor = 2.0_dp*
pi/a*integral*rhi**il
2427 cscale = max(cscale, abs(coefficients(istart + ico, :)))
2438 ipower =
indco(idir, ico)
2439 IF (ipower > 0) angular = angular*(real(ipower, dp)/real(il, dp))**(0.5_dp*real(ipower, dp))
2440 DO ifactor = 2, ipower
2445 triangle = triangle + abs(coefficients(irow, :))*angular
2446 sumsq = sumsq + (coefficients(irow, :)/max(tiny(1.0_dp), cscale))**2/
multinomial
2448 WHERE (cscale >= tiny(1.0_dp)) triangle = min(triangle, cscale*sqrt(sumsq))
2449 bounds = bounds + triangle*max(tiny(1.0_dp), factor)
2453 cpassert(irow ==
SIZE(coefficients, 1))
2455 radial_bounds(ir) = max(tiny(1.0_dp), maxval(bounds)*(1.0_dp + eps_bound_roundoff))
2458 END SUBROUTINE prepare_short_potential_bounds
2468 SUBROUTINE prepare_spherical_potential_factorization(basis, U_Pp, contracted)
2470 REAL(dp),
INTENT(IN) :: u_pp(:, :)
2473 INTEGER :: c, first, ico, ipgf, iset, ishell, l, &
2474 lmax, m, ncart, ref_c, ref_m, ref_p, &
2476 LOGICAL,
ALLOCATABLE :: used(:)
2477 REAL(dp) :: actual, expected, ref_abs, ref_value, &
2479 REAL(dp),
ALLOCATABLE :: angular_coeff(:, :, :, :), &
2480 primitive_scale(:, :, :)
2482 IF (
SIZE(u_pp, 1) /= basis%nsgf)
RETURN
2483 ALLOCATE (used(basis%nsgf), source=.false.)
2484 ALLOCATE (angular_coeff(maxval(
ncoset(0:maxval(basis%lmax)) - &
2485 ncoset(-1:maxval(basis%lmax) - 1)), &
2486 maxval(
nso(0:maxval(basis%lmax))), &
2487 0:maxval(basis%lmax), basis%nset), source=0.0_dp)
2488 ALLOCATE (primitive_scale(maxval(basis%npgf), maxval(basis%nshell), basis%nset), &
2490 DO iset = 1, basis%nset
2491 DO ishell = 1, basis%nshell(iset)
2492 l = basis%l(ishell, iset)
2493 first = basis%first_sgf(ishell, iset)
2494 IF (first < 1 .OR. basis%last_sgf(ishell, iset) /= first +
nso(l) - 1)
RETURN
2495 IF (basis%last_sgf(ishell, iset) > basis%nsgf)
RETURN
2496 IF (any(used(first:first +
nso(l) - 1)))
RETURN
2497 used(first:first +
nso(l) - 1) = .true.
2500 IF (.NOT. all(used))
RETURN
2501 DO iset = 1, basis%nset
2502 lmax = basis%lmax(iset)
2507 DO ishell = 1, basis%nshell(iset)
2508 IF (basis%l(ishell, iset) /= l) cycle
2509 first = basis%first_sgf(ishell, iset)
2510 DO ipgf = 1, basis%npgf(iset)
2514 row = (ipgf - 1)*
ncoset(lmax) + ico
2515 actual = basis%sphi(row, first + m - 1)
2516 IF (abs(actual) > ref_abs)
THEN
2517 ref_abs = abs(actual)
2528 IF (ref_shell == 0) cycle
2529 first = basis%first_sgf(ref_shell, iset)
2533 row = (ref_p - 1)*
ncoset(lmax) + ico
2534 angular_coeff(c, m, l, iset) = basis%sphi(row, first + m - 1)
2537 DO ishell = 1, basis%nshell(iset)
2538 IF (basis%l(ishell, iset) /= l) cycle
2539 first = basis%first_sgf(ishell, iset)
2540 DO ipgf = 1, basis%npgf(iset)
2542 scale = basis%sphi(row, first + ref_m - 1)/ref_value
2543 primitive_scale(ipgf, ishell, iset) = scale
2547 row = (ipgf - 1)*
ncoset(lmax) + ico
2548 actual = basis%sphi(row, first + m - 1)
2549 expected = scale*angular_coeff(c, m, l, iset)
2550 IF (abs(actual - expected) > 64.0_dp*epsilon(1.0_dp)* &
2551 max(ref_abs, abs(actual), abs(expected)))
RETURN
2558 CALL move_alloc(angular_coeff, contracted%spherical_angular)
2559 CALL move_alloc(primitive_scale, contracted%spherical_primitive)
2560 ALLOCATE (contracted%spherical_selection(
SIZE(u_pp, 1),
SIZE(u_pp, 2)))
2561 contracted%spherical_selection(:, :) = u_pp
2562 contracted%spherical_factorized = .true.
2564 END SUBROUTINE prepare_spherical_potential_factorization
2574 SUBROUTINE prepare_radial_series(basis, omega, series, short_series)
2576 REAL(dp),
INTENT(IN) :: omega
2577 REAL(dp),
ALLOCATABLE,
INTENT(OUT) :: series(:, :, :), short_series(:, :, :)
2579 INTEGER :: in, ipgf, iset, lmax
2580 REAL(dp) :: beta_ratio, exponent
2582 lmax = maxval(basis%lmax)
2583 ALLOCATE (series(0:lmax + 24, maxval(basis%npgf), basis%nset), &
2584 short_series(0:lmax + 24, maxval(basis%npgf), basis%nset))
2585 DO iset = 1, basis%nset
2586 DO ipgf = 1, basis%npgf(iset)
2587 exponent = basis%zet(ipgf, iset)
2588 CALL origin_series(series(:, ipgf, iset))
2589 beta_ratio = omega**2/(exponent + omega**2)
2590 DO in = 0, ubound(series, 1)
2591 short_series(in, ipgf, iset) = series(in, ipgf, iset)* &
2592 (1.0_dp - beta_ratio**(real(in, dp) + 0.5_dp))
2597 END SUBROUTINE prepare_radial_series
2614 SUBROUTINE contract_selected_potentials(values, points, basis, center, contracted)
2615 REAL(dp),
CONTIGUOUS,
INTENT(OUT) :: values(:, :)
2616 REAL(dp),
INTENT(IN) :: points(:, :)
2618 REAL(dp),
INTENT(IN) :: center(3)
2620 TARGET :: contracted
2622 INTEGER :: iangular, ico, ig, imesh, ipgf, irow, &
2623 iset, isgf, ishell, l, lmax, m, &
2624 nchannels, ng, np, nrows, nwork
2625 INTEGER,
ALLOCATABLE :: angular_count(:, :, :), &
2627 angular_term(:, :, :, :), &
2628 mesh_channel(:), minimum_l(:)
2629 LOGICAL :: factorized, in_table, parallel_points, &
2631 LOGICAL,
ALLOCATABLE :: angular_used(:, :)
2632 REAL(dp) :: mesh_delta, mesh_position, omega, &
2633 radial_sum, radius, radius2, &
2634 relative(3), spherical_value, x
2635 REAL(dp),
ALLOCATABLE :: angular_values(:, :, :), coordinate_power(:, :), long_radial(:), &
2636 monomial(:), radial(:), radial_channels(:, :, :), radial_mesh(:), work(:, :)
2637 REAL(dp),
CONTIGUOUS,
POINTER :: coefficient_matrix(:, :)
2638 REAL(dp),
POINTER :: series(:, :, :), short_series(:, :, :)
2640 ng =
SIZE(points, 2)
2641 np =
SIZE(values, 2)
2642 lmax = maxval(basis%lmax)
2643 nrows =
SIZE(contracted%coefficients, 1)
2644 factorized = contracted%spherical_factorized
2646 IF (factorized) nwork = basis%nsgf
2647 ALLOCATE (angular_used(0:lmax, basis%nset), source=.false.)
2648 ALLOCATE (minimum_l(basis%nset))
2649 DO iset = 1, basis%nset
2650 minimum_l(iset) = minval(basis%l(1:basis%nshell(iset), iset))
2651 DO ishell = 1, basis%nshell(iset)
2652 angular_used(basis%l(ishell, iset), iset) = .true.
2655 omega = contracted%attenuation
2656 ALLOCATE (work(nwork, ng))
2657 series => contracted%series
2658 short_series => contracted%short_series
2662 ALLOCATE (mesh_channel(nrows), angular_index(nrows))
2663 IF (
ALLOCATED(contracted%mesh_moments))
THEN
2664 nchannels =
SIZE(contracted%mesh_moments, 2)
2666 DO iset = 1, basis%nset
2667 DO ipgf = 1, basis%npgf(iset)
2668 DO l = 0, basis%lmax(iset)
2669 IF (.NOT. angular_used(l, iset)) cycle
2672 mesh_channel(irow) = contracted%mesh_first(ipgf, iset) + l - minimum_l(iset)
2673 angular_index(irow) = ico
2680 IF (factorized)
THEN
2681 ALLOCATE (angular_count(maxval(
nso(0:lmax)), 0:lmax, basis%nset), source=0)
2682 ALLOCATE (angular_term(
SIZE(contracted%spherical_angular, 1), maxval(
nso(0:lmax)), 0:lmax, basis%nset))
2683 DO iset = 1, basis%nset
2684 DO l = 0, basis%lmax(iset)
2685 IF (.NOT. angular_used(l, iset)) cycle
2688 IF (abs(contracted%spherical_angular(ico -
ncoset(l - 1), m, l, iset)) <= 0.0_dp) cycle
2689 angular_count(m, l, iset) = angular_count(m, l, iset) + 1
2690 angular_term(angular_count(m, l, iset), m, l, iset) = ico
2696 tabulated =
ALLOCATED(contracted%short_moments)
2698 parallel_points = .true.
2707 ALLOCATE (radial(0:lmax), long_radial(0:lmax))
2708 ALLOCATE (monomial(
ncoset(lmax)), coordinate_power(3, 0:lmax), radial_mesh(nchannels))
2709 IF (factorized)
ALLOCATE (radial_channels(0:lmax, maxval(basis%npgf), basis%nset), &
2710 angular_values(maxval(
nso(0:lmax)), 0:lmax, basis%nset))
2713 relative = points(:, ig) - center
2714 radius2 = sum(relative**2)
2715 coordinate_power(:, 0) = 1.0_dp
2717 coordinate_power(:, l) = coordinate_power(:, l - 1)*relative
2719 DO ico = 1,
SIZE(monomial)
2720 monomial(ico) = coordinate_power(1,
indco(1, ico))* &
2721 coordinate_power(2,
indco(2, ico))*coordinate_power(3,
indco(3, ico))
2726 IF (
ALLOCATED(contracted%mesh_moments))
THEN
2727 mesh_position = radius2/contracted%mesh_spacing - contracted%mesh_offset
2728 IF (mesh_position >= -0.5_dp .AND. mesh_position <= real(ubound(contracted%mesh_moments, 3), dp) + 0.5_dp)
THEN
2729 imesh = nint(mesh_position)
2730 IF (imesh >= 0 .AND. imesh <= ubound(contracted%mesh_moments, 3))
THEN
2731 mesh_delta = radius2 - contracted%mesh_spacing*(real(imesh, dp) + contracted%mesh_offset)
2732 use_mesh = abs(mesh_delta) <= 64.0_dp*epsilon(1.0_dp)*max(1.0_dp, radius2)
2733 use_mesh = use_mesh .AND. contracted%mesh_exponent*abs(mesh_delta) <= eps_mesh_phase
2738 IF (factorized .AND.
ALLOCATED(contracted%spherical_mesh_first))
THEN
2741 radial_mesh(:) = contracted%mesh_moments(1, :, imesh) + &
2742 mesh_delta*contracted%mesh_moments(2, :, imesh)
2744 IF (factorized .AND. .NOT.
ALLOCATED(contracted%spherical_mesh_first))
THEN
2745 DO iset = 1, basis%nset
2746 DO ipgf = 1, basis%npgf(iset)
2747 DO l = 0, basis%lmax(iset)
2748 IF (.NOT. angular_used(l, iset)) cycle
2749 radial_channels(l, ipgf, iset) = &
2750 radial_mesh(contracted%mesh_first(ipgf, iset) + l - minimum_l(iset))
2754 ELSE IF (.NOT. factorized)
THEN
2756 work(irow, ig) = monomial(angular_index(irow))*radial_mesh(mesh_channel(irow))
2761 radius = sqrt(radius2)
2763 DO iset = 1, basis%nset
2764 DO ipgf = 1, basis%npgf(iset)
2765 x = basis%zet(ipgf, iset)*radius2
2767 IF (tabulated) in_table = x <= contracted%short_abscissae(ubound(contracted%short_abscissae, 1))
2769 CALL evaluate_short_radial_table(x, contracted%short_abscissae, &
2770 contracted%short_moments(minimum_l(iset):, :, ipgf, iset), &
2771 radial(minimum_l(iset):basis%lmax(iset)))
2773 CALL radial_potential_short(radius, basis%zet(ipgf, iset), omega, &
2774 series(:, ipgf, iset), short_series(:, ipgf, iset), &
2775 radial(0:basis%lmax(iset)), long_radial)
2777 IF (factorized)
THEN
2778 DO l = 0, basis%lmax(iset)
2779 IF (angular_used(l, iset)) radial_channels(l, ipgf, iset) = radial(l)
2782 DO l = 0, basis%lmax(iset)
2783 IF (.NOT. angular_used(l, iset)) cycle
2786 work(irow, ig) = monomial(ico)*radial(l)
2793 IF (factorized)
THEN
2794 work(:, ig) = 0.0_dp
2795 DO iset = 1, basis%nset
2796 DO l = 0, basis%lmax(iset)
2797 IF (.NOT. angular_used(l, iset)) cycle
2799 spherical_value = 0.0_dp
2800 DO iangular = 1, angular_count(m, l, iset)
2801 ico = angular_term(iangular, m, l, iset)
2802 spherical_value = spherical_value + monomial(ico)* &
2803 contracted%spherical_angular(ico -
ncoset(l - 1), m, l, iset)
2805 angular_values(m, l, iset) = spherical_value
2808 DO ishell = 1, basis%nshell(iset)
2809 l = basis%l(ishell, iset)
2810 IF (use_mesh .AND.
ALLOCATED(contracted%spherical_mesh_first))
THEN
2811 irow = contracted%spherical_mesh_first(ishell, iset)
2812 radial_sum = contracted%mesh_moments(1, irow, imesh) + &
2813 mesh_delta*contracted%mesh_moments(2, irow, imesh)
2815 radial_sum = sum(radial_channels(l, 1:basis%npgf(iset), iset)* &
2816 contracted%spherical_primitive(1:basis%npgf(iset), ishell, iset))
2819 isgf = basis%first_sgf(ishell, iset) + m - 1
2820 work(isgf, ig) = radial_sum*angular_values(m, l, iset)
2827 DEALLOCATE (radial, long_radial)
2828 DEALLOCATE (monomial, coordinate_power, radial_mesh)
2829 IF (factorized)
DEALLOCATE (radial_channels, angular_values)
2833 IF (factorized)
THEN
2834 coefficient_matrix => contracted%spherical_selection
2836 coefficient_matrix => contracted%coefficients
2838 CALL dgemm(
'T',
'N', ng, np, nwork, 1.0_dp, work, nwork, &
2839 coefficient_matrix, nwork, 0.0_dp, values,
SIZE(values, 1))
2840 IF (factorized)
DEALLOCATE (angular_count, angular_term)
2841 DEALLOCATE (angular_used, minimum_l, mesh_channel, angular_index)
2843 END SUBROUTINE contract_selected_potentials
2858 SUBROUTINE radial_potential_short(radius, exponent, omega, coefficients, short_coefficients, radial, long_radial)
2859 REAL(dp),
INTENT(IN) :: radius, exponent, omega, &
2861 short_coefficients(0:)
2862 REAL(dp),
INTENT(OUT) :: radial(0:)
2863 REAL(dp),
INTENT(INOUT) :: long_radial(0:)
2866 REAL(dp) :: beta, beta_ratio, factor, lower_exp, &
2867 ratio_power, root_x, upper_exp, x
2869 IF (exponent*radius**2 < 0.5_dp)
THEN
2870 CALL radial_potential(radius, exponent, short_coefficients, radial)
2873 beta_ratio = omega**2/(exponent + omega**2)
2874 beta = exponent*beta_ratio
2875 x = exponent*radius**2
2876 IF (x >= real(2*ubound(radial, 1) + 8, dp))
THEN
2880 factor = 2.0_dp*
pi/exponent
2881 radial(0) = factor*sqrt(
pi)/(2.0_dp*root_x)* &
2882 (erfc(sqrt(beta_ratio)*root_x) - erfc(root_x))
2884 lower_exp = exp(-beta_ratio*x)
2885 ratio_power = sqrt(beta_ratio)
2886 DO il = 1, ubound(radial, 1)
2887 radial(il) = (real(2*il - 1, dp)*radial(il - 1) + &
2888 factor*(ratio_power*lower_exp - upper_exp))/(2.0_dp*x)
2889 ratio_power = ratio_power*beta_ratio
2893 CALL radial_potential(radius, exponent, coefficients, radial)
2894 CALL radial_potential(radius, beta, coefficients, long_radial(0:ubound(radial, 1)))
2895 DO il = 0, ubound(radial, 1)
2896 radial(il) = radial(il) - beta_ratio**(real(il, dp) + 1.5_dp)*long_radial(il)
2899 END SUBROUTINE radial_potential_short
2906 SUBROUTINE origin_series(coefficients)
2907 REAL(dp),
INTENT(OUT) :: coefficients(0:)
2910 REAL(dp) :: factorial, weight, terms(0:ubound(coefficients, 1))
2913 DO ik = 0, ubound(terms, 1)
2915 weight = weight*2.0_dp/real(2*ik + 3, dp)
2917 DO in = 0, ubound(coefficients, 1)
2918 coefficients(in) = 0.0_dp
2921 coefficients(in) = coefficients(in) + factorial*terms(ik)
2922 factorial = -factorial/real(in - ik + 1, dp)
2926 END SUBROUTINE origin_series
2936 SUBROUTINE radial_potential(radius, exponent, coefficients, radial)
2937 REAL(dp),
INTENT(IN) :: radius, exponent, coefficients(0:)
2938 REAL(dp),
INTENT(OUT) :: radial(0:)
2940 INTEGER :: ij, il, in, lmax
2941 REAL(dp) :: factor, power, prefactor,
value, x, jet(0:ubound(radial, 1)), &
2942 gaussian(0:ubound(radial, 1)), derivative(0:ubound(radial, 1)), &
2943 bracket(0:ubound(radial, 1))
2945 lmax = ubound(radial, 1)
2946 x = exponent*radius**2
2947 IF (x < 0.5_dp)
THEN
2951 DO in = il, ubound(coefficients, 1)
2953 DO ij = in - il + 1, in
2954 factor = factor*real(ij, dp)
2956 value =
value + coefficients(in)*factor*power
2959 radial(il) = 2.0_dp*
pi/exponent*(-1.0_dp)**il*
value
2963 bracket(0:lmax) = 0.0_dp
2964 gaussian(0) = exp(-exponent*radius**2)
2971 bracket(in) = bracket(in) + &
2972 4.0_dp*sqrt(exponent/
pi)*
gaussian(in - 1)/real(in, dp)
2974 bracket(0) = 2.0_dp*erf(sqrt(exponent)*radius)
2975 prefactor =
pi**1.5_dp/(2.0_dp*exponent**1.5_dp)
2976 jet(0) = bracket(0)/radius
2978 jet(in) = (bracket(in) - jet(in - 1))/radius
2980 radial(0) = prefactor*jet(0)
2982 derivative(0:lmax) = 0.0_dp
2983 derivative(0) = jet(1)/(2.0_dp*radius)
2984 DO in = 1, lmax - il
2985 derivative(in) = (real(in + 1, dp)*jet(in + 1)/2.0_dp - derivative(in - 1))/radius
2987 jet(0:lmax) = derivative(0:lmax)
2988 radial(il) = prefactor*(-1.0_dp/exponent)**il*jet(0)
2991 END SUBROUTINE radial_potential
3003 SUBROUTINE prepare_short_radial_grid(xmax, abscissae)
3004 REAL(dp),
INTENT(IN) :: xmax
3005 REAL(dp),
ALLOCATABLE,
INTENT(OUT) :: abscissae(:)
3009 cpassert(xmax > 0.0_dp)
3010 IF (xmax <= short_grid_switch)
THEN
3011 last = ceiling(xmax/short_grid_spacing)
3013 last = n_short_uniform + ceiling(log(xmax/short_grid_switch)/log(short_grid_ratio))
3015 ALLOCATE (abscissae(0:last))
3017 IF (ix <= n_short_uniform)
THEN
3018 abscissae(ix) = short_grid_spacing*real(ix, dp)
3020 abscissae(ix) = short_grid_switch*exp(real(ix - n_short_uniform, dp)*log(short_grid_ratio))
3023 abscissae(last) = xmax
3025 END SUBROUTINE prepare_short_radial_grid
3043 SUBROUTINE prepare_short_radial_table(a, omega, lmax, table, ninterval, point_spacing, point_offset, &
3044 last_moment, abscissae)
3045 REAL(dp),
INTENT(IN) :: a, omega
3046 INTEGER,
INTENT(IN) :: lmax
3047 REAL(dp),
ALLOCATABLE,
INTENT(OUT) :: table(:, :)
3048 INTEGER,
INTENT(IN) :: ninterval
3049 REAL(dp),
INTENT(IN),
OPTIONAL :: point_spacing, point_offset
3050 INTEGER,
INTENT(IN),
OPTIONAL :: last_moment
3051 REAL(dp),
INTENT(IN),
OPTIONAL :: abscissae(0:)
3053 INTEGER,
PARAMETER :: n_legendre = 64
3055 INTEGER :: ig, il, ix, last, order, quadrature_last
3056 REAL(dp) :: b, factor, legendre_nodes(n_legendre), legendre_weights(n_legendre), lower, &
3057 lower_exp, offset, ratio_power, root_x, spacing, t, t2, term, upper_exp, width, x
3059 cpassert(
PRESENT(point_spacing) .OR.
PRESENT(abscissae))
3064 IF (
PRESENT(point_spacing)) spacing = point_spacing
3065 IF (
PRESENT(point_offset)) offset = point_offset
3066 IF (
PRESENT(last_moment)) order = last_moment
3067 ALLOCATE (table(0:order, 0:last), source=0.0_dp)
3068 b = omega**2/(a + omega**2)
3070 width = (a/(a + omega**2))/(1.0_dp + lower)
3071 quadrature_last = last
3072 IF (b < recurrence_b_max)
THEN
3073 IF (
PRESENT(abscissae))
THEN
3074 quadrature_last = count(abscissae <= real(2*order + 8, dp)) - 1
3076 quadrature_last = int(min(real(last, dp), max(0.0_dp, real(2*order + 8, dp)/spacing - offset)))
3079 CALL gauss_legendre(n_legendre, legendre_nodes, legendre_weights)
3080 DO ig = 1, n_legendre
3081 t = lower + 0.5_dp*width*(1.0_dp + legendre_nodes(ig))
3083 DO ix = 0, quadrature_last
3084 x = spacing*(real(ix, dp) + offset)
3085 IF (
PRESENT(abscissae)) x = abscissae(ix)
3086 term = 0.5_dp*width*legendre_weights(ig)*exp(-x*t2)*2.0_dp*
pi/a
3087 DO il = 0, ubound(table, 1)
3088 table(il, ix) = table(il, ix) + term
3093 factor = 2.0_dp*
pi/a
3094 DO ix = quadrature_last + 1, last
3095 x = spacing*(real(ix, dp) + offset)
3096 IF (
PRESENT(abscissae)) x = abscissae(ix)
3098 table(0, ix) = factor*sqrt(
pi)/(2.0_dp*root_x)*(erfc(lower*root_x) - erfc(root_x))
3099 lower_exp = exp(-b*x)
3102 DO il = 1, ubound(table, 1)
3103 table(il, ix) = (real(2*il - 1, dp)*table(il - 1, ix) + &
3104 factor*(ratio_power*lower_exp - upper_exp))/(2.0_dp*x)
3105 ratio_power = ratio_power*b
3109 END SUBROUTINE prepare_short_radial_table
3120 SUBROUTINE evaluate_short_radial_table(x, abscissae, table, radial)
3121 REAL(dp),
INTENT(IN) :: x, abscissae(0:), table(0:, 0:)
3122 REAL(dp),
INTENT(OUT) :: radial(0:)
3124 REAL(dp),
PARAMETER :: &
3125 inverse(6) = [1.0_dp, 0.5_dp, 1.0_dp/3.0_dp, 0.25_dp, 0.2_dp, 1.0_dp/6.0_dp]
3127 INTEGER :: ik, il, ileft, imiddle, iright, ix
3128 REAL(dp) :: delta, value
3131 iright = ubound(abscissae, 1)
3132 DO WHILE (iright - ileft > 1)
3133 imiddle = (ileft + iright)/2
3134 IF (x < abscissae(imiddle))
THEN
3141 IF (abscissae(iright) - x < x - abscissae(ileft)) ix = iright
3142 delta = abscissae(ix) - x
3143 DO il = 0, ubound(radial, 1)
3144 value = table(il + 6, ix)
3146 value = table(il + ik, ix) + delta*
value*inverse(ik + 1)
3151 END SUBROUTINE evaluate_short_radial_table
3166 SUBROUTINE prepare_mesh_radial_moments(basis, contracted, step, displacement, table_bytes)
3169 REAL(dp),
INTENT(IN) :: step(3, 3), displacement(3)
3170 REAL(dp),
INTENT(INOUT) :: table_bytes
3172 INTEGER :: idir, ifirst, il, ipgf, iset, ishell, jdir, last, max_l, max_primitive, &
3173 minimum_l, nchannels, nshell_total, nstored, shell_index
3174 LOGICAL :: direct_shells
3175 REAL(dp) :: bytes_per_node, index_bytes, linear(3), &
3176 metric(3, 3), offset, ratio, &
3177 required_bytes, spacing
3178 REAL(dp),
ALLOCATABLE :: moments(:, :)
3180 IF (basis%nset < 1)
RETURN
3181 IF (any(basis%nshell(1:basis%nset) < 1))
RETURN
3182 IF (any(basis%npgf(1:basis%nset) < 1))
RETURN
3183 IF (contracted%attenuation <= 0.0_dp .OR. table_bytes <= 0.0_dp)
RETURN
3184 metric = matmul(transpose(step), step)
3185 spacing = min(metric(1, 1), metric(2, 2), metric(3, 3))
3186 IF (spacing <= tiny(1.0_dp))
RETURN
3189 ratio = metric(idir, jdir)/spacing
3190 IF (idir /= jdir) ratio = 2.0_dp*ratio
3191 IF (abs(ratio - anint(ratio)) > eps_integer)
RETURN
3194 linear = 2.0_dp*matmul(transpose(step), displacement)/spacing
3195 IF (any(abs(linear - anint(linear)) > eps_integer))
RETURN
3196 offset =
modulo(sum(displacement**2)/spacing, 1.0_dp)
3197 IF (mesh_table_radius**2/spacing > real(huge(last) - 1, dp))
RETURN
3198 last = ceiling(mesh_table_radius**2/spacing)
3199 IF (last < 1)
RETURN
3201 DO iset = 1, basis%nset
3202 minimum_l = minval(basis%l(1:basis%nshell(iset), iset))
3203 nchannels = nchannels + basis%npgf(iset)*(basis%lmax(iset) - minimum_l + 1)
3205 nshell_total = sum(basis%nshell(1:basis%nset))
3206 max_l = maxval(basis%lmax(1:basis%nset))
3207 max_primitive = maxval(basis%npgf(1:basis%nset))
3208 direct_shells = contracted%spherical_factorized .AND. nshell_total <= nchannels
3210 IF (direct_shells) nstored = nshell_total
3211 bytes_per_node = real_bytes*(2.0_dp*real(nstored, dp) + real(max_l + 2, dp))
3212 index_bytes = real(
int_size, dp)*real(max_primitive, dp)*real(basis%nset, dp)
3213 IF (direct_shells)
THEN
3214 index_bytes = index_bytes + &
3215 REAL(
int_size, dp)*
REAL(maxval(basis%nshell)*basis%nset, dp)
3218 last = min(last, int(min(real(huge(last), dp), &
3219 max(0.0_dp, (table_bytes - index_bytes)/bytes_per_node))) - 1)
3220 IF (last < 1)
RETURN
3221 required_bytes = bytes_per_node*real(last + 1, dp) + index_bytes
3222 IF (required_bytes > table_bytes)
RETURN
3223 ALLOCATE (contracted%mesh_moments(2, nstored, 0:last))
3224 ALLOCATE (contracted%mesh_first(max_primitive, basis%nset), source=0)
3225 contracted%mesh_spacing = spacing
3226 contracted%mesh_offset = offset
3227 IF (direct_shells)
THEN
3228 ALLOCATE (contracted%spherical_mesh_first(maxval(basis%nshell), basis%nset), source=0)
3230 DO iset = 1, basis%nset
3231 DO ishell = 1, basis%nshell(iset)
3232 shell_index = shell_index + 1
3233 contracted%spherical_mesh_first(ishell, iset) = shell_index
3236 contracted%mesh_moments = 0.0_dp
3239 DO iset = 1, basis%nset
3240 minimum_l = minval(basis%l(1:basis%nshell(iset), iset))
3241 DO ipgf = 1, basis%npgf(iset)
3242 contracted%mesh_exponent = max(contracted%mesh_exponent, basis%zet(ipgf, iset))
3243 contracted%mesh_first(ipgf, iset) = ifirst
3244 CALL prepare_short_radial_table(basis%zet(ipgf, iset), contracted%attenuation, &
3245 basis%lmax(iset), moments, last, &
3246 basis%zet(ipgf, iset)*spacing, offset, basis%lmax(iset) + 1)
3247 IF (direct_shells)
THEN
3250 DO ishell = 1, basis%nshell(iset)
3251 il = basis%l(ishell, iset)
3252 shell_index = contracted%spherical_mesh_first(ishell, iset)
3253 contracted%mesh_moments(1, shell_index, :) = &
3254 contracted%mesh_moments(1, shell_index, :) + &
3255 contracted%spherical_primitive(ipgf, ishell, iset)*moments(il, :)
3256 contracted%mesh_moments(2, shell_index, :) = &
3257 contracted%mesh_moments(2, shell_index, :) + &
3258 contracted%spherical_primitive(ipgf, ishell, iset)*(-basis%zet(ipgf, iset)*moments(il + 1, :))
3260 ifirst = ifirst + basis%lmax(iset) - minimum_l + 1
3262 DO il = minimum_l, basis%lmax(iset)
3263 contracted%mesh_moments(1, ifirst, :) = moments(il, :)
3264 contracted%mesh_moments(2, ifirst, :) = -basis%zet(ipgf, iset)*moments(il + 1, :)
3268 DEALLOCATE (moments)
3271 table_bytes = table_bytes - required_bytes
3273 END SUBROUTINE prepare_mesh_radial_moments
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
double distance_squared(double *A, double *B)
Handles all functions related to the CELL.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp_size
integer, parameter, public dp
integer, parameter, public int_size
Machine interface based on Fortran 2003 and POSIX.
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), parameter, public twopi
Collection of simple mathematical functions and subroutines.
subroutine, public diamat_all(a, eigval, dac)
Diagonalize the symmetric n by n matrix a using the LAPACK library. Only the upper triangle of matrix...
subroutine, public gauss_legendre(n, nodes, weights)
Gauss-Legendre nodes and weights on [-1,1], with nodes in ascending order. The Legendre roots are ref...
pure real(kind=dp) function, public multinomial(n, k)
Calculates the multinomial coefficients.
Interface to the message passing library MPI.
subroutine, public mp_mem_avail_per_rank_gb(comm, mem_avail_gb)
Memory that is currently free on the node, per MPI rank of that node, in GB.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
integer, dimension(:, :), allocatable, public indco
integer, dimension(:), allocatable, public nso
Define the data structure for the particle information.
Definition of physical constants:
real(kind=dp), parameter, public angstrom
Numerical integrals d_lP(R) for periodic RI-RS fitting.
subroutine, public compute_d_lp_r(bs_env, grid_points, cells_r_d_lp, d_lp_r, qpoints, charge_lq)
Allocate d_lP(R), prepare its integration grid, and evaluate the integrals.
subroutine, public get_local_l_range(n_grid, n_ranks, i_rank, first_l, last_l)
Distribute individual l rows evenly across MPI ranks; empty ranges are valid.
subroutine, public compute_d_lp_cutoffs(bs_env, cutoffs)
Automatic l/P cutoff from the overlap of the diffuse AO-field square and RI potential.
subroutine, public write_ri_rs_progress(unit_nr, phase, n_done, n_total, next_progress, phase_start)
Print one rank-local RI-RS work milestone without synchronizing MPI ranks. Percentages count complete...
Integration grid, AO images and radial tables for the periodic RI-RS integrals d_lP(R).
Geometry and AO evaluation for real-space resolution of the identity.
subroutine, public evaluate_ao_basis_on_points(phi, grid_points, basis, source_position, cell, dphi, cutoff_squared, periodic_images, minimum_image)
Evaluate one explicitly supplied contracted Gaussian basis on Cartesian points.
Type defining parameters related to the simulation cell.
stores all the informations relevant to an mpi environment