33#include "./base/base_uses.f90"
38 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_active_space_types'
49 LOGICAL :: redo_poisson = .false.
50 LOGICAL :: store_wfn = .false.
51 REAL(KIND=
dp) :: cutoff = 0.0_dp
52 REAL(KIND=
dp) :: rel_cutoff = 0.0_dp
53 REAL(KIND=
dp) :: eps_grid = 0.0_dp
54 REAL(KIND=
dp) :: eps_filter = 0.0_dp
55 INTEGER :: print_level = 0
56 INTEGER :: group_size = 0
61 INTEGER :: operator = 0
62 LOGICAL :: enlarge_cell = .false.
63 REAL(kind=
dp) :: omega = 0.0_dp
64 INTEGER,
DIMENSION(3) :: periodicity = 0
65 REAL(kind=
dp),
DIMENSION(3) :: eri_cell = 0
66 REAL(kind=
dp),
DIMENSION(3) :: eri_cell_angles = 0
67 REAL(kind=
dp) :: cutoff_radius = 0.0_dp
68 REAL(kind=
dp) :: eps_integral = 0.0_dp
69 TYPE(eri_gpw_type) :: eri_gpw = eri_gpw_type()
70 TYPE(dbcsr_csr_p_type), &
71 DIMENSION(:),
POINTER :: eri => null()
76 PROCEDURE :: eri_foreach => eri_type_eri_foreach
88 INTEGER :: nelec_active = 0
89 INTEGER :: nelec_inactive = 0
90 INTEGER :: nelec_total = 0
91 INTEGER,
POINTER,
DIMENSION(:, :) :: active_orbitals => null()
92 INTEGER,
POINTER,
DIMENSION(:, :) :: inactive_orbitals => null()
93 INTEGER :: nmo_active = 0
94 INTEGER :: nmo_inactive = 0
95 INTEGER :: multiplicity = 0
97 LOGICAL :: restricted_orbitals = .false.
98 LOGICAL :: molecule = .false.
100 REAL(kind=
dp) :: energy_total = 0.0_dp
101 REAL(kind=
dp) :: energy_ref = 0.0_dp
102 REAL(kind=
dp) :: energy_inactive = 0.0_dp
103 REAL(kind=
dp) :: energy_active = 0.0_dp
104 REAL(kind=
dp) :: alpha = 0.0_dp
106 INTEGER :: as_mixing_iter = 0
107 INTEGER :: as_mixing_dim = 0
108 LOGICAL :: do_scf_embedding = .false.
110 LOGICAL :: fcidump = .false.
111 CHARACTER(LEN=default_path_length) :: qcschema_filename =
''
113 REAL(kind=
dp),
DIMENSION(:),
POINTER :: as_mix_r_old => null()
114 REAL(kind=
dp),
DIMENSION(:),
POINTER :: as_mix_weight => null()
115 REAL(kind=
dp),
DIMENSION(:),
POINTER :: as_mix_x_old => null()
116 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: as_mix_r_buffer => null()
117 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: as_mix_x_buffer => null()
120 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mos_inactive => null()
121 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: p_active => null()
125 TYPE(
cp_fm_type),
DIMENSION(:),
POINTER :: fock_sub => null()
145 INTEGER,
INTENT(in) :: i, j, k, l
146 REAL(kind=
dp),
INTENT(in) :: val
161 IF (
ASSOCIATED(active_space_env))
THEN
165 ALLOCATE (active_space_env)
166 NULLIFY (active_space_env%active_orbitals, active_space_env%inactive_orbitals)
167 NULLIFY (active_space_env%mos_active, active_space_env%mos_inactive)
168 NULLIFY (active_space_env%ks_sub, active_space_env%p_active)
169 NULLIFY (active_space_env%vxc_sub, active_space_env%h_sub)
170 NULLIFY (active_space_env%fock_sub, active_space_env%pmat_inactive)
171 NULLIFY (active_space_env%as_mixing_store)
172 NULLIFY (active_space_env%as_mix_r_old, active_space_env%as_mix_weight)
173 NULLIFY (active_space_env%as_mix_x_old)
174 NULLIFY (active_space_env%as_mix_r_buffer, active_space_env%as_mix_x_buffer)
187 IF (
ASSOCIATED(active_space_env))
THEN
189 IF (
ASSOCIATED(active_space_env%active_orbitals))
THEN
190 DEALLOCATE (active_space_env%active_orbitals)
193 IF (
ASSOCIATED(active_space_env%inactive_orbitals))
THEN
194 DEALLOCATE (active_space_env%inactive_orbitals)
197 IF (
ASSOCIATED(active_space_env%mos_active))
THEN
198 DO imo = 1,
SIZE(active_space_env%mos_active)
201 DEALLOCATE (active_space_env%mos_active)
204 IF (
ASSOCIATED(active_space_env%mos_inactive))
THEN
205 DO imo = 1,
SIZE(active_space_env%mos_inactive)
208 DEALLOCATE (active_space_env%mos_inactive)
211 CALL release_eri_type(active_space_env%eri)
220 IF (
ASSOCIATED(active_space_env%as_mixing_store))
THEN
222 DEALLOCATE (active_space_env%as_mixing_store)
224 IF (
ASSOCIATED(active_space_env%as_mix_r_old))
THEN
225 DEALLOCATE (active_space_env%as_mix_r_old)
227 IF (
ASSOCIATED(active_space_env%as_mix_weight))
THEN
228 DEALLOCATE (active_space_env%as_mix_weight)
230 IF (
ASSOCIATED(active_space_env%as_mix_x_old))
THEN
231 DEALLOCATE (active_space_env%as_mix_x_old)
233 IF (
ASSOCIATED(active_space_env%as_mix_r_buffer))
THEN
234 DEALLOCATE (active_space_env%as_mix_r_buffer)
236 IF (
ASSOCIATED(active_space_env%as_mix_x_buffer))
THEN
237 DEALLOCATE (active_space_env%as_mix_x_buffer)
240 IF (
ASSOCIATED(active_space_env%pmat_inactive)) &
243 DEALLOCATE (active_space_env)
252 SUBROUTINE release_eri_type(eri_env)
257 IF (
ASSOCIATED(eri_env%eri))
THEN
259 DO i = 1,
SIZE(eri_env%eri)
260 CALL dbcsr_csr_destroy(eri_env%eri(i)%csr_mat)
261 DEALLOCATE (eri_env%eri(i)%csr_mat)
264 CALL eri_env%comm_exchange%free()
265 DEALLOCATE (eri_env%eri)
269 END SUBROUTINE release_eri_type
281 INTEGER,
INTENT(IN) :: i, j, n
287 ij = (i - 1)*n - ((i - 1)*(i - 2))/2 + (j - i + 1)
289 cpassert(ij <= (n*(n + 1))/2 .AND. 0 <= ij)
303 INTEGER,
INTENT(IN) :: ij, n
304 INTEGER,
INTENT(OUT) :: i, j
310 m0 = (i - 1)*n - ((i - 1)*(i - 2))/2
315 cpassert(i > 0 .AND. i <= n)
316 cpassert(j > 0 .AND. j <= n)
334 SUBROUTINE eri_type_eri_foreach(this, nspin, active_orbitals, fobj, spin1, spin2)
337 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: active_orbitals
338 INTEGER,
OPTIONAL :: spin1, spin2
340 CHARACTER(LEN=*),
PARAMETER :: routinen =
"eri_type_eri_foreach"
342 INTEGER :: i1, i12, i12l, i2, i3, i34, i34l, i4, m1, m2, m3, m4, &
343 irptr, nspin, nindex, nmo, proc, nonzero_elements_local, handle, dummy_int(1)
344 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: colind, offsets, nonzero_elements_global
345 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: erival
346 REAL(kind=
dp) :: erint, dummy_real(1)
349 CALL timeset(routinen, handle)
351 IF (.NOT.
PRESENT(spin1))
THEN
354 IF (.NOT.
PRESENT(spin2))
THEN
361 associate(eri => this%eri(nspin)%csr_mat, norb => this%norb)
362 nindex = (norb*(norb + 1))/2
363 CALL mp_group%set_handle(eri%mp_group%get_handle())
364 nmo =
SIZE(active_orbitals, 1)
366 ALLOCATE (erival(nindex), colind(nindex))
367 ALLOCATE (offsets(0:mp_group%num_pe - 1), &
368 nonzero_elements_global(0:mp_group%num_pe - 1))
371 i1 = active_orbitals(m1, spin1)
373 i2 = active_orbitals(m2, spin1)
375 i12l = (i12 - 1)/this%comm_exchange%num_pe + 1
382 nonzero_elements_local = 0
383 IF (mod(i12 - 1, this%comm_exchange%num_pe) == this%comm_exchange%mepos) &
384 nonzero_elements_local = eri%nzerow_local(i12l)
385 CALL mp_group%allgather(nonzero_elements_local, nonzero_elements_global)
389 DO proc = 1, mp_group%num_pe - 1
390 offsets(proc) = offsets(proc - 1) + nonzero_elements_global(proc - 1)
392 nindex = offsets(mp_group%num_pe - 1) + nonzero_elements_global(mp_group%num_pe - 1)
394 IF (mod(i12 - 1, this%comm_exchange%num_pe) == this%comm_exchange%mepos)
THEN
395 irptr = eri%rowptr_local(i12l)
398 CALL mp_group%allgatherv(eri%colind_local(irptr:irptr + nonzero_elements_local - 1), &
399 colind(1:nindex), nonzero_elements_global, offsets)
400 CALL mp_group%allgatherv(eri%nzval_local%r_dp(irptr:irptr + nonzero_elements_local - 1), &
401 erival(1:nindex), nonzero_elements_global, offsets)
403 CALL mp_group%allgatherv(dummy_int(1:0), colind(1:nindex), nonzero_elements_global, offsets)
404 CALL mp_group%allgatherv(dummy_real(1:0), erival(1:nindex), nonzero_elements_global, offsets)
413 IF (active_orbitals(m3, spin2) == i3)
THEN
419 IF (active_orbitals(m4, spin2) == i4)
THEN
425 IF (.NOT. fobj%func(m1, m2, m3, m4, erint))
RETURN
432 CALL timestop(handle)
433 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)
subroutine, public create_active_space_type(active_space_env)
Creates an active space environment type, nullifying all quantities.
module that contains the definitions of the scf types
subroutine, public mixing_storage_release(mixing_store)
releases a mixing_storage
integer, parameter, public direct_mixing_nr
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.