28#include "./base/base_uses.f90"
33 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_active_space_types'
44 LOGICAL :: redo_poisson = .false.
45 LOGICAL :: store_wfn = .false.
46 REAL(KIND=
dp) :: cutoff = 0.0_dp
47 REAL(KIND=
dp) :: rel_cutoff = 0.0_dp
48 REAL(KIND=
dp) :: eps_grid = 0.0_dp
49 REAL(KIND=
dp) :: eps_filter = 0.0_dp
50 INTEGER :: print_level = 0
51 INTEGER :: group_size = 0
56 INTEGER :: operator = 0
57 LOGICAL :: enlarge_cell = .false.
58 REAL(kind=
dp) :: omega = 0.0_dp
59 INTEGER,
DIMENSION(3) :: periodicity = 0
60 REAL(kind=
dp),
DIMENSION(3) :: eri_cell = 0
61 REAL(kind=
dp),
DIMENSION(3) :: eri_cell_angles = 0
62 REAL(kind=
dp) :: cutoff_radius = 0.0_dp
63 REAL(kind=
dp) :: eps_integral = 0.0_dp
64 TYPE(eri_gpw_type) :: eri_gpw = eri_gpw_type()
65 TYPE(dbcsr_csr_p_type), &
66 DIMENSION(:),
POINTER :: eri => null()
70 PROCEDURE :: eri_foreach => eri_type_eri_foreach
82 INTEGER :: nelec_active = 0
83 INTEGER :: nelec_inactive = 0
84 INTEGER :: nelec_total = 0
85 INTEGER,
POINTER,
DIMENSION(:, :) :: active_orbitals => null()
86 INTEGER,
POINTER,
DIMENSION(:, :) :: inactive_orbitals => null()
87 INTEGER :: nmo_active = 0
88 INTEGER :: nmo_inactive = 0
89 INTEGER :: multiplicity = 0
91 LOGICAL :: molecule = .false.
93 REAL(kind=
dp) :: energy_total = 0.0_dp
94 REAL(kind=
dp) :: energy_ref = 0.0_dp
95 REAL(kind=
dp) :: energy_inactive = 0.0_dp
96 REAL(kind=
dp) :: energy_active = 0.0_dp
97 REAL(kind=
dp) :: alpha = 0.0_dp
98 LOGICAL :: do_scf_embedding = .false.
100 LOGICAL :: fcidump = .false.
101 CHARACTER(LEN=default_path_length) :: qcschema_filename =
''
104 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mos_inactive => null()
105 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: p_active => null()
109 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fock_sub => null()
128 INTEGER,
INTENT(in) :: i, j, k, l
129 REAL(kind=
dp),
INTENT(in) :: val
144 IF (
ASSOCIATED(active_space_env))
THEN
148 ALLOCATE (active_space_env)
149 NULLIFY (active_space_env%active_orbitals, active_space_env%inactive_orbitals)
150 NULLIFY (active_space_env%mos_active, active_space_env%mos_inactive)
151 NULLIFY (active_space_env%ks_sub, active_space_env%p_active)
152 NULLIFY (active_space_env%vxc_sub, active_space_env%h_sub)
153 NULLIFY (active_space_env%fock_sub, active_space_env%pmat_inactive)
166 IF (
ASSOCIATED(active_space_env))
THEN
168 IF (
ASSOCIATED(active_space_env%active_orbitals))
THEN
169 DEALLOCATE (active_space_env%active_orbitals)
172 IF (
ASSOCIATED(active_space_env%inactive_orbitals))
THEN
173 DEALLOCATE (active_space_env%inactive_orbitals)
176 IF (
ASSOCIATED(active_space_env%mos_active))
THEN
177 DO imo = 1,
SIZE(active_space_env%mos_active)
180 DEALLOCATE (active_space_env%mos_active)
183 IF (
ASSOCIATED(active_space_env%mos_inactive))
THEN
184 DO imo = 1,
SIZE(active_space_env%mos_inactive)
187 DEALLOCATE (active_space_env%mos_inactive)
190 CALL release_eri_type(active_space_env%eri)
199 IF (
ASSOCIATED(active_space_env%pmat_inactive)) &
202 DEALLOCATE (active_space_env)
211 SUBROUTINE release_eri_type(eri_env)
216 IF (
ASSOCIATED(eri_env%eri))
THEN
218 DO i = 1,
SIZE(eri_env%eri)
219 CALL dbcsr_csr_destroy(eri_env%eri(i)%csr_mat)
220 DEALLOCATE (eri_env%eri(i)%csr_mat)
222 DEALLOCATE (eri_env%eri)
226 END SUBROUTINE release_eri_type
238 INTEGER,
INTENT(IN) :: i, j, n
244 ij = (i - 1)*n - ((i - 1)*(i - 2))/2 + (j - i + 1)
246 cpassert(ij <= (n*(n + 1))/2 .AND. 0 <= ij)
260 INTEGER,
INTENT(IN) :: ij, n
261 INTEGER,
INTENT(OUT) :: i, j
267 m0 = (i - 1)*n - ((i - 1)*(i - 2))/2
272 cpassert(i > 0 .AND. i <= n)
273 cpassert(j > 0 .AND. j <= n)
288 INTEGER,
INTENT(IN) :: nindex
291 INTEGER,
DIMENSION(2) :: irange
295 associate(numtask => mp_group%num_pe, taskid => mp_group%mepos)
297 IF (numtask == 1 .AND. taskid == 0)
THEN
300 ELSEIF (numtask >= nindex)
THEN
301 IF (taskid >= nindex)
THEN
305 irange(1) = taskid + 1
306 irange(2) = taskid + 1
309 rat = real(nindex, kind=
dp)/real(numtask, kind=
dp)
310 irange(1) = nint(rat*taskid) + 1
311 irange(2) = nint(rat*taskid + rat)
330 SUBROUTINE eri_type_eri_foreach(this, nspin, active_orbitals, fobj, spin1, spin2)
333 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: active_orbitals
334 INTEGER,
OPTIONAL :: spin1, spin2
335 INTEGER :: i1, i12, i12l, i2, i3, i34, i34l, i4, m1, m2, m3, m4, &
336 irange(2), irptr, nspin, nindex, nmo, proc, nonzero_elements_local
337 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: colind, offsets, nonzero_elements_global
338 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: erival
339 REAL(kind=dp) :: erint
340 TYPE(mp_comm_type) :: mp_group
342 IF (.NOT.
PRESENT(spin1))
THEN
345 IF (.NOT.
PRESENT(spin2))
THEN
349 associate(eri => this%eri(nspin)%csr_mat, norb => this%norb)
350 nindex = (norb*(norb + 1))/2
351 CALL mp_group%set_handle(eri%mp_group%get_handle())
352 nmo =
SIZE(active_orbitals, 1)
355 ALLOCATE (erival(nindex), colind(nindex))
357 IF (this%method == eri_method_gpw_ht)
THEN
358 ALLOCATE (offsets(0:mp_group%num_pe - 1), &
359 nonzero_elements_global(0:mp_group%num_pe - 1))
363 i1 = active_orbitals(m1, spin1)
365 i2 = active_orbitals(m2, spin1)
368 IF (this%method == eri_method_gpw_ht)
THEN
374 nonzero_elements_local = eri%nzerow_local(i12)
375 CALL mp_group%allgather(nonzero_elements_local, nonzero_elements_global)
379 DO proc = 1, mp_group%num_pe - 1
380 offsets(proc) = offsets(proc - 1) + nonzero_elements_global(proc - 1)
382 nindex = offsets(mp_group%num_pe - 1) + nonzero_elements_global(mp_group%num_pe - 1)
383 irptr = eri%rowptr_local(i12)
386 CALL mp_group%allgatherv(eri%colind_local(irptr:irptr + nonzero_elements_local - 1), &
387 colind(1:nindex), nonzero_elements_global, offsets)
388 CALL mp_group%allgatherv(eri%nzval_local%r_dp(irptr:irptr + nonzero_elements_local - 1), &
389 erival(1:nindex), nonzero_elements_global, offsets)
393 IF (i12 >= irange(1) .AND. i12 <= irange(2))
THEN
394 i12l = i12 - irange(1) + 1
395 irptr = eri%rowptr_local(i12l)
396 nindex = eri%nzerow_local(i12l)
397 colind(1:nindex) = eri%colind_local(irptr:irptr + nindex - 1)
398 erival(1:nindex) = eri%nzval_local%r_dp(irptr:irptr + nindex - 1)
406 CALL mp_group%sum(nindex)
407 CALL mp_group%sum(colind(1:nindex))
408 CALL mp_group%sum(erival(1:nindex))
417 IF (active_orbitals(m3, spin2) == i3)
THEN
423 IF (active_orbitals(m4, spin2) == i4)
THEN
429 IF (.NOT. fobj%func(m1, m2, m3, m4, erint))
RETURN
435 END SUBROUTINE eri_type_eri_foreach
The function signature to be implemented by a child of eri_type_eri_element_func
DBCSR operations in CP2K.
represent a full matrix distributed on many processors
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_path_length
Interface to the message passing library MPI.
The module to read/write QCSchema HDF5 files for interfacing CP2K with other programs.
The types needed for the calculation of active space Hamiltonians.
subroutine, public release_active_space_type(active_space_env)
Releases all quantities in the active space environment.
subroutine, public csr_idx_from_combined(ij, n, i, j)
extracts indices i and j from combined index ij
integer function, public csr_idx_to_combined(i, j, n)
calculates combined index (ij)
integer function, dimension(2), public get_irange_csr(nindex, mp_group)
calculates index range for processor in group mp_group
subroutine, public create_active_space_type(active_space_env)
Creates an active space environment type, nullifying all quantities.
Definition and initialisation of the mo data type.
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
Abstract function object for the eri_type_eri_foreach method.