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 REAL(kind=
dp) :: operator_parameter = 0.0_dp
58 INTEGER,
DIMENSION(3) :: periodicity = 0
59 REAL(kind=
dp) :: cutoff_radius = 0.0_dp
60 REAL(kind=
dp) :: eps_integral = 0.0_dp
61 TYPE(eri_gpw_type) :: eri_gpw = eri_gpw_type()
62 TYPE(dbcsr_csr_p_type), &
63 DIMENSION(:),
POINTER :: eri => null()
67 PROCEDURE :: eri_foreach => eri_type_eri_foreach
79 INTEGER :: nelec_active = 0
80 INTEGER :: nelec_inactive = 0
81 INTEGER :: nelec_total = 0
82 INTEGER,
POINTER,
DIMENSION(:, :) :: active_orbitals => null()
83 INTEGER,
POINTER,
DIMENSION(:, :) :: inactive_orbitals => null()
84 INTEGER :: nmo_active = 0
85 INTEGER :: nmo_inactive = 0
86 INTEGER :: multiplicity = 0
88 LOGICAL :: molecule = .false.
90 REAL(kind=
dp) :: energy_total = 0.0_dp
91 REAL(kind=
dp) :: energy_ref = 0.0_dp
92 REAL(kind=
dp) :: energy_inactive = 0.0_dp
93 REAL(kind=
dp) :: energy_active = 0.0_dp
94 LOGICAL :: do_scf_embedding = .false.
96 LOGICAL :: fcidump = .false.
97 CHARACTER(LEN=default_path_length) :: qcschema_filename =
''
99 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mos_active => null()
100 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mos_inactive => null()
101 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: p_active => null()
105 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fock_sub => null()
123 INTEGER,
INTENT(in) :: i, j, k, l
124 REAL(kind=
dp),
INTENT(in) :: val
139 IF (
ASSOCIATED(active_space_env))
THEN
143 ALLOCATE (active_space_env)
144 NULLIFY (active_space_env%active_orbitals, active_space_env%inactive_orbitals)
145 NULLIFY (active_space_env%mos_active, active_space_env%mos_inactive)
146 NULLIFY (active_space_env%ks_sub, active_space_env%p_active)
147 NULLIFY (active_space_env%vxc_sub, active_space_env%h_sub)
148 NULLIFY (active_space_env%fock_sub, active_space_env%pmat_inactive)
161 IF (
ASSOCIATED(active_space_env))
THEN
163 IF (
ASSOCIATED(active_space_env%active_orbitals))
THEN
164 DEALLOCATE (active_space_env%active_orbitals)
167 IF (
ASSOCIATED(active_space_env%inactive_orbitals))
THEN
168 DEALLOCATE (active_space_env%inactive_orbitals)
171 IF (
ASSOCIATED(active_space_env%mos_active))
THEN
172 DO imo = 1,
SIZE(active_space_env%mos_active)
175 DEALLOCATE (active_space_env%mos_active)
178 IF (
ASSOCIATED(active_space_env%mos_inactive))
THEN
179 DO imo = 1,
SIZE(active_space_env%mos_inactive)
182 DEALLOCATE (active_space_env%mos_inactive)
185 CALL release_eri_type(active_space_env%eri)
193 IF (
ASSOCIATED(active_space_env%pmat_inactive)) &
196 DEALLOCATE (active_space_env)
205 SUBROUTINE release_eri_type(eri_env)
210 IF (
ASSOCIATED(eri_env%eri))
THEN
212 DO i = 1,
SIZE(eri_env%eri)
213 CALL dbcsr_csr_destroy(eri_env%eri(i)%csr_mat)
214 DEALLOCATE (eri_env%eri(i)%csr_mat)
216 DEALLOCATE (eri_env%eri)
220 END SUBROUTINE release_eri_type
232 INTEGER,
INTENT(IN) :: i, j, n
238 ij = (i - 1)*n - ((i - 1)*(i - 2))/2 + (j - i + 1)
240 cpassert(ij <= (n*(n + 1))/2 .AND. 0 <= ij)
254 INTEGER,
INTENT(IN) :: ij, n
255 INTEGER,
INTENT(OUT) :: i, j
261 m0 = (i - 1)*n - ((i - 1)*(i - 2))/2
266 cpassert(i > 0 .AND. i <= n)
267 cpassert(j > 0 .AND. j <= n)
282 INTEGER,
INTENT(IN) :: nindex
285 INTEGER,
DIMENSION(2) :: irange
289 associate(numtask => mp_group%num_pe, taskid => mp_group%mepos)
291 IF (numtask == 1 .AND. taskid == 0)
THEN
294 ELSEIF (numtask >= nindex)
THEN
295 IF (taskid >= nindex)
THEN
299 irange(1) = taskid + 1
300 irange(2) = taskid + 1
303 rat = real(nindex, kind=
dp)/real(numtask, kind=
dp)
304 irange(1) = nint(rat*taskid) + 1
305 irange(2) = nint(rat*taskid + rat)
324 SUBROUTINE eri_type_eri_foreach(this, nspin, active_orbitals, fobj, spin1, spin2)
327 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: active_orbitals
328 INTEGER,
OPTIONAL :: spin1, spin2
329 INTEGER :: i1, i12, i12l, i2, i3, i34, i34l, i4, m1, m2, m3, m4, &
330 irange(2), irptr, nspin, nindex, nmo, proc, nonzero_elements_local
331 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: colind, offsets, nonzero_elements_global
332 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: erival
333 REAL(kind=dp) :: erint
334 TYPE(mp_comm_type) :: mp_group
336 IF (.NOT.
PRESENT(spin1))
THEN
339 IF (.NOT.
PRESENT(spin2))
THEN
343 associate(eri => this%eri(nspin)%csr_mat, norb => this%norb)
344 nindex = (norb*(norb + 1))/2
345 CALL mp_group%set_handle(eri%mp_group%get_handle())
346 nmo =
SIZE(active_orbitals, 1)
349 ALLOCATE (erival(nindex), colind(nindex))
351 IF (this%method == eri_method_gpw_ht)
THEN
352 ALLOCATE (offsets(0:mp_group%num_pe - 1), &
353 nonzero_elements_global(0:mp_group%num_pe - 1))
357 i1 = active_orbitals(m1, spin1)
359 i2 = active_orbitals(m2, spin1)
362 IF (this%method == eri_method_gpw_ht)
THEN
368 nonzero_elements_local = eri%nzerow_local(i12)
369 CALL mp_group%allgather(nonzero_elements_local, nonzero_elements_global)
373 DO proc = 1, mp_group%num_pe - 1
374 offsets(proc) = offsets(proc - 1) + nonzero_elements_global(proc - 1)
376 nindex = offsets(mp_group%num_pe - 1) + nonzero_elements_global(mp_group%num_pe - 1)
377 irptr = eri%rowptr_local(i12)
380 CALL mp_group%allgatherv(eri%colind_local(irptr:irptr + nonzero_elements_local - 1), &
381 colind(1:nindex), nonzero_elements_global, offsets)
382 CALL mp_group%allgatherv(eri%nzval_local%r_dp(irptr:irptr + nonzero_elements_local - 1), &
383 erival(1:nindex), nonzero_elements_global, offsets)
387 IF (i12 >= irange(1) .AND. i12 <= irange(2))
THEN
388 i12l = i12 - irange(1) + 1
389 irptr = eri%rowptr_local(i12l)
390 nindex = eri%nzerow_local(i12l)
391 colind(1:nindex) = eri%colind_local(irptr:irptr + nindex - 1)
392 erival(1:nindex) = eri%nzval_local%r_dp(irptr:irptr + nindex - 1)
400 CALL mp_group%sum(nindex)
401 CALL mp_group%sum(colind(1:nindex))
402 CALL mp_group%sum(erival(1:nindex))
411 IF (active_orbitals(m3, spin2) == i3)
THEN
417 IF (active_orbitals(m4, spin2) == i4)
THEN
423 IF (.NOT. fobj%func(m1, m2, m3, m4, erint))
RETURN
429 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.