31#include "./base/base_uses.f90"
36 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_active_space_types'
47 LOGICAL :: redo_poisson = .false.
48 LOGICAL :: store_wfn = .false.
49 REAL(KIND=
dp) :: cutoff = 0.0_dp
50 REAL(KIND=
dp) :: rel_cutoff = 0.0_dp
51 REAL(KIND=
dp) :: eps_grid = 0.0_dp
52 REAL(KIND=
dp) :: eps_filter = 0.0_dp
53 INTEGER :: print_level = 0
54 INTEGER :: group_size = 0
59 INTEGER :: operator = 0
60 LOGICAL :: enlarge_cell = .false.
61 REAL(kind=
dp) :: omega = 0.0_dp
62 INTEGER,
DIMENSION(3) :: periodicity = 0
63 REAL(kind=
dp),
DIMENSION(3) :: eri_cell = 0
64 REAL(kind=
dp),
DIMENSION(3) :: eri_cell_angles = 0
65 REAL(kind=
dp) :: cutoff_radius = 0.0_dp
66 REAL(kind=
dp) :: eps_integral = 0.0_dp
67 TYPE(eri_gpw_type) :: eri_gpw = eri_gpw_type()
68 TYPE(dbcsr_csr_p_type), &
69 DIMENSION(:),
POINTER :: eri => null()
74 PROCEDURE :: eri_foreach => eri_type_eri_foreach
86 INTEGER :: nelec_active = 0
87 INTEGER :: nelec_inactive = 0
88 INTEGER :: nelec_total = 0
89 INTEGER,
POINTER,
DIMENSION(:, :) :: active_orbitals => null()
90 INTEGER,
POINTER,
DIMENSION(:, :) :: inactive_orbitals => null()
91 INTEGER :: nmo_active = 0
92 INTEGER :: nmo_inactive = 0
93 INTEGER :: multiplicity = 0
95 LOGICAL :: molecule = .false.
97 REAL(kind=
dp) :: energy_total = 0.0_dp
98 REAL(kind=
dp) :: energy_ref = 0.0_dp
99 REAL(kind=
dp) :: energy_inactive = 0.0_dp
100 REAL(kind=
dp) :: energy_active = 0.0_dp
101 REAL(kind=
dp) :: alpha = 0.0_dp
102 LOGICAL :: do_scf_embedding = .false.
104 LOGICAL :: fcidump = .false.
105 CHARACTER(LEN=default_path_length) :: qcschema_filename =
''
108 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mos_inactive => null()
109 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: p_active => null()
113 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fock_sub => null()
133 INTEGER,
INTENT(in) :: i, j, k, l
134 REAL(kind=
dp),
INTENT(in) :: val
149 IF (
ASSOCIATED(active_space_env))
THEN
153 ALLOCATE (active_space_env)
154 NULLIFY (active_space_env%active_orbitals, active_space_env%inactive_orbitals)
155 NULLIFY (active_space_env%mos_active, active_space_env%mos_inactive)
156 NULLIFY (active_space_env%ks_sub, active_space_env%p_active)
157 NULLIFY (active_space_env%vxc_sub, active_space_env%h_sub)
158 NULLIFY (active_space_env%fock_sub, active_space_env%pmat_inactive)
171 IF (
ASSOCIATED(active_space_env))
THEN
173 IF (
ASSOCIATED(active_space_env%active_orbitals))
THEN
174 DEALLOCATE (active_space_env%active_orbitals)
177 IF (
ASSOCIATED(active_space_env%inactive_orbitals))
THEN
178 DEALLOCATE (active_space_env%inactive_orbitals)
181 IF (
ASSOCIATED(active_space_env%mos_active))
THEN
182 DO imo = 1,
SIZE(active_space_env%mos_active)
185 DEALLOCATE (active_space_env%mos_active)
188 IF (
ASSOCIATED(active_space_env%mos_inactive))
THEN
189 DO imo = 1,
SIZE(active_space_env%mos_inactive)
192 DEALLOCATE (active_space_env%mos_inactive)
195 CALL release_eri_type(active_space_env%eri)
204 IF (
ASSOCIATED(active_space_env%pmat_inactive)) &
207 DEALLOCATE (active_space_env)
216 SUBROUTINE release_eri_type(eri_env)
221 IF (
ASSOCIATED(eri_env%eri))
THEN
223 DO i = 1,
SIZE(eri_env%eri)
224 CALL dbcsr_csr_destroy(eri_env%eri(i)%csr_mat)
225 DEALLOCATE (eri_env%eri(i)%csr_mat)
228 CALL eri_env%comm_exchange%free()
229 DEALLOCATE (eri_env%eri)
233 END SUBROUTINE release_eri_type
245 INTEGER,
INTENT(IN) :: i, j, n
251 ij = (i - 1)*n - ((i - 1)*(i - 2))/2 + (j - i + 1)
253 cpassert(ij <= (n*(n + 1))/2 .AND. 0 <= ij)
267 INTEGER,
INTENT(IN) :: ij, n
268 INTEGER,
INTENT(OUT) :: i, j
274 m0 = (i - 1)*n - ((i - 1)*(i - 2))/2
279 cpassert(i > 0 .AND. i <= n)
280 cpassert(j > 0 .AND. j <= n)
295 INTEGER,
INTENT(IN) :: nindex
298 INTEGER,
DIMENSION(2) :: irange
302 associate(numtask => mp_group%num_pe, taskid => mp_group%mepos)
304 IF (numtask == 1 .AND. taskid == 0)
THEN
307 ELSEIF (numtask >= nindex)
THEN
308 IF (taskid >= nindex)
THEN
312 irange(1) = taskid + 1
313 irange(2) = taskid + 1
316 rat = real(nindex, kind=
dp)/real(numtask, kind=
dp)
317 irange(1) = nint(rat*taskid) + 1
318 irange(2) = nint(rat*taskid + rat)
337 SUBROUTINE eri_type_eri_foreach(this, nspin, active_orbitals, fobj, spin1, spin2)
340 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: active_orbitals
341 INTEGER,
OPTIONAL :: spin1, spin2
343 CHARACTER(LEN=*),
PARAMETER :: routinen =
"eri_type_eri_foreach"
345 INTEGER :: i1, i12, i12l, i2, i3, i34, i34l, i4, m1, m2, m3, m4, &
346 irange(2), irptr, nspin, nindex, nmo, proc, nonzero_elements_local, handle, dummy_int(1)
347 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: colind, offsets, nonzero_elements_global
348 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: erival
349 REAL(kind=dp) :: erint, dummy_real(1)
350 TYPE(mp_comm_type) :: mp_group
352 CALL timeset(routinen, handle)
354 IF (.NOT.
PRESENT(spin1))
THEN
357 IF (.NOT.
PRESENT(spin2))
THEN
364 associate(eri => this%eri(nspin)%csr_mat, norb => this%norb)
365 nindex = (norb*(norb + 1))/2
366 CALL mp_group%set_handle(eri%mp_group%get_handle())
367 nmo =
SIZE(active_orbitals, 1)
370 ALLOCATE (erival(nindex), colind(nindex))
371 ALLOCATE (offsets(0:mp_group%num_pe - 1), &
372 nonzero_elements_global(0:mp_group%num_pe - 1))
375 i1 = active_orbitals(m1, spin1)
377 i2 = active_orbitals(m2, spin1)
379 i12l = i12 - irange(1) + 1
386 nonzero_elements_local = 0
387 IF (i12 >= irange(1) .AND. i12 <= irange(2)) nonzero_elements_local = eri%nzerow_local(i12l)
388 CALL mp_group%allgather(nonzero_elements_local, nonzero_elements_global)
392 DO proc = 1, mp_group%num_pe - 1
393 offsets(proc) = offsets(proc - 1) + nonzero_elements_global(proc - 1)
395 nindex = offsets(mp_group%num_pe - 1) + nonzero_elements_global(mp_group%num_pe - 1)
397 IF (i12 >= irange(1) .AND. i12 <= irange(2))
THEN
398 irptr = eri%rowptr_local(i12l)
401 CALL mp_group%allgatherv(eri%colind_local(irptr:irptr + nonzero_elements_local - 1), &
402 colind(1:nindex), nonzero_elements_global, offsets)
403 CALL mp_group%allgatherv(eri%nzval_local%r_dp(irptr:irptr + nonzero_elements_local - 1), &
404 erival(1:nindex), nonzero_elements_global, offsets)
406 CALL mp_group%allgatherv(dummy_int(1:1), colind(1:nindex), nonzero_elements_global, offsets)
407 CALL mp_group%allgatherv(dummy_real(1:1), erival(1:nindex), nonzero_elements_global, offsets)
416 IF (active_orbitals(m3, spin2) == i3)
THEN
422 IF (active_orbitals(m4, spin2) == i4)
THEN
428 IF (.NOT. fobj%func(m1, m2, m3, m4, erint))
RETURN
435 CALL timestop(handle)
436 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.
type(mp_comm_type), parameter, public mp_comm_null
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
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.
stores all the informations relevant to an mpi environment
Abstract function object for the eri_type_eri_foreach method.