LCOV - code coverage report
Current view: top level - src - post_scf_bandstructure_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 154 155 99.4 %
Date: 2024-11-21 06:45:46 Functions: 12 17 70.6 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief
      10             : !> \author Jan Wilhelm
      11             : !> \date 07.2023
      12             : ! **************************************************************************************************
      13             : MODULE post_scf_bandstructure_types
      14             :    USE basis_set_types,                 ONLY: gto_basis_set_p_type
      15             :    USE cp_cfm_types,                    ONLY: cp_cfm_release,&
      16             :                                               cp_cfm_type
      17             :    USE cp_dbcsr_api,                    ONLY: dbcsr_p_type,&
      18             :                                               dbcsr_release
      19             :    USE cp_dbcsr_operations,             ONLY: dbcsr_deallocate_matrix_set
      20             :    USE cp_fm_types,                     ONLY: cp_fm_release,&
      21             :                                               cp_fm_type
      22             :    USE dbt_api,                         ONLY: dbt_destroy,&
      23             :                                               dbt_type
      24             :    USE input_constants,                 ONLY: rtp_method_bse,&
      25             :                                               small_cell_full_kp
      26             :    USE kinds,                           ONLY: default_string_length,&
      27             :                                               dp
      28             :    USE kpoint_types,                    ONLY: kpoint_release,&
      29             :                                               kpoint_type
      30             :    USE libint_2c_3c,                    ONLY: libint_potential_type
      31             :    USE message_passing,                 ONLY: mp_para_env_release,&
      32             :                                               mp_para_env_type
      33             :    USE qs_tensors_types,                ONLY: neighbor_list_3c_type
      34             : #include "./base/base_uses.f90"
      35             : 
      36             :    IMPLICIT NONE
      37             : 
      38             :    PRIVATE
      39             : 
      40             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'post_scf_bandstructure_types'
      41             : 
      42             :    PUBLIC :: post_scf_bandstructure_type, band_edges_type, data_3_type, bs_env_release
      43             : 
      44             :    ! valence band maximum (VBM), conduction band minimum (CBM), direct band gap (DBG),
      45             :    ! indirect band gap (IDBG)
      46             :    TYPE band_edges_type
      47             :       REAL(KIND=dp)                                   :: VBM = -1.0_dp, &
      48             :                                                          CBM = -1.0_dp, &
      49             :                                                          DBG = -1.0_dp, &
      50             :                                                          IDBG = -1.0_dp
      51             :    END TYPE band_edges_type
      52             : 
      53             :    ! data type for storing 3-index quantities for small-cell, full-k-points GW code
      54             :    TYPE data_3_type
      55             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE :: data_3
      56             :    END TYPE data_3_type
      57             : 
      58             :    TYPE post_scf_bandstructure_type
      59             : 
      60             :       ! decide which calculations will be done
      61             :       LOGICAL                                         :: do_gw = .FALSE., &
      62             :                                                          do_soc = .FALSE., &
      63             :                                                          do_ldos = .FALSE.
      64             : 
      65             :       ! various eigenvalues computed in GW code, some depend on k-points
      66             :       ! and have therefore three dimensions (band index, k-point, spin)
      67             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE     :: eigenval_scf_Gamma
      68             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE  :: eigenval_scf, &
      69             :                                                          eigenval_G0W0, &
      70             :                                                          eigenval_HF, &
      71             :                                                          eigenval_scGW0
      72             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE     :: eigenval_scf_soc, &
      73             :                                                          eigenval_G0W0_soc
      74             :       TYPE(band_edges_type), DIMENSION(2)             :: band_edges_scf_Gamma = band_edges_type()
      75             :       TYPE(band_edges_type)                           :: band_edges_scf = band_edges_type(), &
      76             :                                                          band_edges_G0W0 = band_edges_type(), &
      77             :                                                          band_edges_HF = band_edges_type()
      78             : 
      79             :       ! parameters that influence the GW flavor
      80             :       LOGICAL                                         :: do_hedin_shift = .FALSE.
      81             : 
      82             :       ! general parameters on molecular orbitals and basis sets
      83             :       INTEGER                                      :: n_ao = -1, &
      84             :                                                       n_RI = -1, &
      85             :                                                       n_spin = -1, &
      86             :                                                       n_atom = -1, &
      87             :                                                       max_AO_bf_per_atom = -1
      88             :       INTEGER, DIMENSION(:), ALLOCATABLE           :: i_ao_start_from_atom, &
      89             :                                                       i_ao_end_from_atom, &
      90             :                                                       i_RI_start_from_atom, &
      91             :                                                       i_RI_end_from_atom
      92             :       INTEGER, DIMENSION(2)                        :: n_occ = -1, &
      93             :                                                       n_vir = -1
      94             :       REAL(KIND=dp)                                :: spin_degeneracy = -1.0_dp
      95             :       REAL(KIND=dp), DIMENSION(2)                  :: e_fermi = -1.0_dp
      96             : 
      97             :       ! kpoint mesh for chi, eps, W
      98             :       INTEGER, DIMENSION(:), POINTER               :: nkp_grid_DOS_input => NULL()
      99             :       INTEGER, DIMENSION(3)                        :: nkp_grid_chi_eps_W_orig = -1, &
     100             :                                                       nkp_grid_chi_eps_W_extra = -1
     101             :       INTEGER                                      :: nkp_chi_eps_W_orig = -1, &
     102             :                                                       nkp_chi_eps_W_extra = -1, &
     103             :                                                       nkp_chi_eps_W_orig_plus_extra = -1, &
     104             :                                                       nkp_chi_eps_W_batch = -1, &
     105             :                                                       num_chi_eps_W_batches = -1, &
     106             :                                                       size_lattice_sum_V = -1
     107             :       TYPE(kpoint_type), POINTER                   :: kpoints_chi_eps_W => NULL(), &
     108             :                                                       kpoints_DOS => NULL()
     109             :       LOGICAL                                      :: approx_kp_extrapol = .FALSE.
     110             : 
     111             :       REAL(KIND=dp)                                :: wkp_orig = -1.0_dp
     112             :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE     :: wkp_s_p, &
     113             :                                                       wkp_no_extra
     114             :       INTEGER, DIMENSION(:), ALLOCATABLE           :: l_RI
     115             :       INTEGER                                      :: input_kp_bs_npoints = -1, &
     116             :                                                       input_kp_bs_n_sp_pts = -1, &
     117             :                                                       nkp_bs_and_DOS = -1, &
     118             :                                                       nkp_only_bs = -1, &
     119             :                                                       nkp_only_DOS = -1
     120             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE  :: xkp_special
     121             : 
     122             :       ! parameters for GW band structure calculation of small unit cell (with multiple unit cell)
     123             :       INTEGER                                      :: small_cell_full_kp_or_large_cell_Gamma = -1, &
     124             :                                                       nimages_scf = -1
     125             :       INTEGER, DIMENSION(3)                        :: periodic = -1
     126             :       REAL(KIND=dp), DIMENSION(3, 3)               :: hmat = -1.0_dp
     127             : 
     128             :       ! imaginary time and frequency grids
     129             :       INTEGER                                         :: num_time_freq_points = -1, &
     130             :                                                          num_freq_points_fit = -1
     131             :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE        :: imag_time_points, &
     132             :                                                          imag_time_weights_freq_zero, &
     133             :                                                          imag_freq_points, &
     134             :                                                          imag_freq_points_fit
     135             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE     :: weights_cos_t_to_w, &
     136             :                                                          weights_cos_w_to_t, &
     137             :                                                          weights_sin_t_to_w
     138             :       INTEGER                                         :: nparam_pade = -1, &
     139             :                                                          num_points_per_magnitude = -1
     140             :       REAL(KIND=dp)                                   :: freq_max_fit = -1.0_dp, &
     141             :                                                          regularization_minimax = -1.0_dp, &
     142             :                                                          stabilize_exp = -1.0_dp
     143             : 
     144             :       ! filter threshold for matrix-tensor operations
     145             :       REAL(KIND=dp)                                :: eps_filter = -1.0_dp, &
     146             :                                                       eps_atom_grid_2d_mat = -1.0_dp
     147             : 
     148             :       ! threshold for inverting ao overlap matrix, RI cfm_1d
     149             :       REAL(KIND=dp)                                :: eps_eigval_mat_s = -1.0_dp, &
     150             :                                                       eps_eigval_mat_RI = -1.0_dp, &
     151             :                                                       input_regularization_RI = -1.0_dp, &
     152             :                                                       regularization_RI = -1.0_dp
     153             : 
     154             :       ! global full cfm_1d used in GW
     155             :       TYPE(cp_fm_type)                             :: fm_s_Gamma = cp_fm_type(), &
     156             :                                                       fm_Gocc = cp_fm_type(), &
     157             :                                                       fm_Gvir = cp_fm_type()
     158             :       TYPE(cp_fm_type), DIMENSION(2)               :: fm_ks_Gamma = cp_fm_type(), &
     159             :                                                       fm_V_xc_Gamma = cp_fm_type(), &
     160             :                                                       fm_mo_coeff_Gamma = cp_fm_type()
     161             :       TYPE(cp_fm_type), DIMENSION(4)               :: fm_work_mo = cp_fm_type()
     162             :       TYPE(cp_fm_type)                             :: fm_RI_RI = cp_fm_type(), &
     163             :                                                       fm_chi_Gamma_freq = cp_fm_type(), &
     164             :                                                       fm_W_MIC_freq = cp_fm_type(), &
     165             :                                                       fm_W_MIC_freq_1_extra = cp_fm_type(), &
     166             :                                                       fm_W_MIC_freq_1_no_extra = cp_fm_type(), &
     167             :                                                       fm_W_MIC_freq_zero = cp_fm_type(), &
     168             :                                                       fm_h_G0W0_Gamma = cp_fm_type()
     169             :       TYPE(cp_cfm_type)                            :: cfm_work_mo = cp_cfm_type(), &
     170             :                                                       cfm_work_mo_2 = cp_cfm_type()
     171             : 
     172             :       ! global dbcsr cfm_1d used in GW
     173             :       TYPE(dbcsr_p_type)                           :: mat_ao_ao = dbcsr_p_type(), &
     174             :                                                       mat_RI_RI = dbcsr_p_type()
     175             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER    :: mat_chi_Gamma_tau => NULL()
     176             : 
     177             :       ! local dbcsr cfm_1d used in GW (local in tensor group)
     178             :       TYPE(dbcsr_p_type)                           :: mat_ao_ao_tensor = dbcsr_p_type(), &
     179             :                                                       mat_RI_RI_tensor = dbcsr_p_type()
     180             : 
     181             :       ! tensors for sparse matrix-tensor operations
     182             : #if defined(FTN_NO_DEFAULT_INIT)
     183             :       TYPE(dbt_type)                               :: t_G, &
     184             :                                                       t_chi, &
     185             :                                                       t_W, &
     186             :                                                       t_RI_AO__AO, &
     187             :                                                       t_RI__AO_AO
     188             : #else
     189             :       TYPE(dbt_type)                               :: t_G = dbt_type(), &
     190             :                                                       t_chi = dbt_type(), &
     191             :                                                       t_W = dbt_type(), &
     192             :                                                       t_RI_AO__AO = dbt_type(), &
     193             :                                                       t_RI__AO_AO = dbt_type()
     194             : #endif
     195             : 
     196             :       ! parameters and data for parallelization
     197             :       INTEGER                                      :: group_size_tensor = -1, &
     198             :                                                       tensor_group_color = -1, &
     199             :                                                       num_tensor_groups = -1
     200             :       REAL(KIND=dp)                                :: input_memory_per_proc_GB = -1.0_dp
     201             :       TYPE(mp_para_env_type), POINTER              :: para_env => NULL(), &
     202             :                                                       para_env_tensor => NULL()
     203             :       REAL(KIND=dp)                                :: occupation_3c_int = -1.0_dp, &
     204             :                                                       max_dist_AO_atoms = -1.0_dp, &
     205             :                                                       safety_factor_memory = -1.0_dp
     206             : 
     207             :       ! parallelization: atom range i and atom range j for tensor group
     208             :       INTEGER, DIMENSION(2)                        :: atoms_i = -1, &
     209             :                                                       atoms_j = -1
     210             :       INTEGER                                      :: n_atom_i = -1, &
     211             :                                                       n_intervals_i = -1, &
     212             :                                                       n_atom_j = -1, &
     213             :                                                       n_intervals_j = -1, &
     214             :                                                       n_atom_per_interval_ij = -1, &
     215             :                                                       n_intervals_inner_loop_atoms = -1, &
     216             :                                                       n_atom_per_IL_interval = -1
     217             :       INTEGER, DIMENSION(:, :), ALLOCATABLE        :: i_atom_intervals, &
     218             :                                                       j_atom_intervals, &
     219             :                                                       inner_loop_atom_intervals, &
     220             :                                                       atoms_i_t_group, &
     221             :                                                       atoms_j_t_group
     222             :       LOGICAL, DIMENSION(:, :), ALLOCATABLE        :: skip_Sigma_occ, &
     223             :                                                       skip_Sigma_vir
     224             :       ! Marek : rtp_method
     225             :       INTEGER                                      :: rtp_method = rtp_method_bse
     226             : 
     227             :       ! check-arrays and names for restarting
     228             :       LOGICAL, DIMENSION(:), ALLOCATABLE           :: read_chi, &
     229             :                                                       calc_chi
     230             :       LOGICAL, DIMENSION(:, :), ALLOCATABLE        :: Sigma_c_exists
     231             :       LOGICAL                                      :: all_W_exist = .FALSE., &
     232             :                                                       Sigma_x_exists = .FALSE.
     233             :       CHARACTER(LEN=3)                             :: chi_name = "chi"
     234             :       CHARACTER(LEN=6)                             :: W_time_name = "W_time"
     235             :       CHARACTER(LEN=7)                             :: Sigma_x_name = "Sigma_x"
     236             :       CHARACTER(LEN=13)                            :: Sigma_p_name = "Sigma_pos_tau", &
     237             :                                                       Sigma_n_name = "Sigma_neg_tau"
     238             :       CHARACTER(LEN=default_string_length)         :: prefix = ""
     239             :       INTEGER                                      :: unit_nr = -1
     240             : 
     241             :       ! parameters and data for basis sets
     242             :       TYPE(gto_basis_set_p_type), &
     243             :          DIMENSION(:), ALLOCATABLE                 :: basis_set_AO, &
     244             :                                                       basis_set_RI
     245             :       INTEGER, DIMENSION(:), ALLOCATABLE           :: sizes_AO, &
     246             :                                                       sizes_RI
     247             :       TYPE(neighbor_list_3c_type)                  :: nl_3c = neighbor_list_3c_type()
     248             :       TYPE(libint_potential_type)                  :: ri_metric = libint_potential_type(), &
     249             :                                                       trunc_coulomb = libint_potential_type()
     250             : 
     251             :       ! parameters for SOC calculation
     252             :       REAL(KIND=dp)                                :: energy_window_soc = -1.0_dp
     253             :       ! sizes: mat_V_SOC_xyz: xyz, img
     254             :       TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_V_SOC_xyz => NULL()
     255             :       TYPE(cp_fm_type), DIMENSION(3)               :: fm_V_SOC_xyz_mo = cp_fm_type()
     256             :       ! small-cell GW: dimension = number of kpoints; large-cell GW: Gamma-point, dimension = 1
     257             :       TYPE(cp_cfm_type), DIMENSION(:), ALLOCATABLE :: cfm_SOC_spinor_ao
     258             :       TYPE(band_edges_type)                        :: band_edges_scf_SOC = band_edges_type(), &
     259             :                                                       band_edges_G0W0_SOC = band_edges_type()
     260             : 
     261             :       ! parameters for DOS and PDOS calculation
     262             :       REAL(KIND=dp)                                :: energy_window_DOS = -1.0_dp, &
     263             :                                                       energy_step_DOS = -1.0_dp, &
     264             :                                                       broadening_DOS = -1.0_dp
     265             : 
     266             :       ! parameters for LDOS calculation (LDOS: local density of states)
     267             :       INTEGER                                      :: int_ldos_xyz = -1
     268             :       INTEGER, DIMENSION(:), POINTER               :: bin_mesh => NULL()
     269             :       INTEGER                                      :: n_bins_max_for_printing = -1
     270             :       REAL(KIND=dp)                                :: unit_ldos_int_z_inv_Ang2_eV = -1.0_dp
     271             : 
     272             :       ! quantities only needed for small cells and k-point sampling in DFT (small_cell_full_kp)
     273             :       INTEGER                                      :: nkp_scf_desymm = -1, &
     274             :                                                       nimages_3c = -1, &
     275             :                                                       nimages_scf_desymm = -1, &
     276             :                                                       nimages_Delta_R = -1
     277             :       TYPE(kpoint_type), POINTER                   :: kpoints_scf_desymm => NULL(), &
     278             :                                                       kpoints_scf_desymm_2 => NULL()
     279             :       INTEGER, DIMENSION(3)                        :: cell_grid_scf_desymm = -1
     280             :       INTEGER, DIMENSION(:, :), ALLOCATABLE        :: index_to_cell_3c, &
     281             :                                                       index_to_cell_Delta_R
     282             :       INTEGER, DIMENSION(:, :, :), POINTER         :: cell_to_index_3c => NULL(), &
     283             :                                                       cell_to_index_Delta_R => NULL()
     284             :       REAL(KIND=dp)                                :: heuristic_filter_factor = -1.0_dp
     285             : 
     286             :       ! small_cell_full_kp parallelization
     287             :       INTEGER                                      :: n_tasks_Delta_R_local = -1
     288             :       INTEGER, DIMENSION(:), ALLOCATABLE           :: task_Delta_R
     289             :       INTEGER, DIMENSION(:, :), ALLOCATABLE        :: nblocks_3c
     290             : 
     291             :       ! cfm for k-dep overl mat S_µν(k), KS mat h_µν(k,spin) and mo coeff C_μn(k,spin) from SCF
     292             :       TYPE(cp_cfm_type), DIMENSION(:), ALLOCATABLE      :: cfm_s_kp
     293             :       TYPE(cp_cfm_type), DIMENSION(:, :), ALLOCATABLE   :: cfm_mo_coeff_kp, &
     294             :                                                            cfm_ks_kp
     295             :       TYPE(cp_fm_type), DIMENSION(:), ALLOCATABLE       :: fm_G_S, &
     296             :                                                            fm_Sigma_x_R
     297             :       TYPE(cp_fm_type), DIMENSION(:, :), ALLOCATABLE    :: fm_V_xc_R, &
     298             :                                                            fm_chi_R_t, &
     299             :                                                            fm_MWM_R_t
     300             :       TYPE(cp_fm_type), DIMENSION(:, :, :), ALLOCATABLE :: fm_Sigma_c_R_neg_tau, &
     301             :                                                            fm_Sigma_c_R_pos_tau
     302             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE    :: v_xc_n
     303             :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)      :: t_3c_int
     304             : 
     305             :    END TYPE post_scf_bandstructure_type
     306             : 
     307             : CONTAINS
     308             : 
     309             : ! **************************************************************************************************
     310             : !> \brief ...
     311             : !> \param bs_env ...
     312             : ! **************************************************************************************************
     313          34 :    SUBROUTINE bs_env_release(bs_env)
     314             :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     315             : 
     316             :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'bs_env_release'
     317             : 
     318             :       INTEGER                                            :: handle
     319             : 
     320          34 :       CALL timeset(routineN, handle)
     321             : 
     322          34 :       CPASSERT(ASSOCIATED(bs_env))
     323             : 
     324          34 :       CALL safe_kpoints_release(bs_env%kpoints_chi_eps_W)
     325          34 :       CALL safe_kpoints_release(bs_env%kpoints_DOS)
     326          34 :       CALL safe_kpoints_release(bs_env%kpoints_scf_desymm)
     327          34 :       CALL safe_kpoints_release(bs_env%kpoints_scf_desymm_2)
     328             : 
     329          34 :       IF (ALLOCATED(bs_env%wkp_s_p)) DEALLOCATE (bs_env%wkp_s_p)
     330          34 :       IF (ALLOCATED(bs_env%wkp_no_extra)) DEALLOCATE (bs_env%wkp_no_extra)
     331          34 :       IF (ALLOCATED(bs_env%l_RI)) DEALLOCATE (bs_env%l_RI)
     332          34 :       IF (ALLOCATED(bs_env%xkp_special)) DEALLOCATE (bs_env%xkp_special)
     333          34 :       IF (ALLOCATED(bs_env%imag_time_points)) DEALLOCATE (bs_env%imag_time_points)
     334          34 :       IF (ALLOCATED(bs_env%imag_time_weights_freq_zero)) DEALLOCATE (bs_env%imag_time_weights_freq_zero)
     335          34 :       IF (ALLOCATED(bs_env%imag_freq_points)) DEALLOCATE (bs_env%imag_freq_points)
     336          34 :       IF (ALLOCATED(bs_env%eigenval_scf_Gamma)) DEALLOCATE (bs_env%eigenval_scf_Gamma)
     337          34 :       IF (ALLOCATED(bs_env%eigenval_scf)) DEALLOCATE (bs_env%eigenval_scf)
     338          34 :       IF (ALLOCATED(bs_env%eigenval_G0W0)) DEALLOCATE (bs_env%eigenval_G0W0)
     339          34 :       IF (ALLOCATED(bs_env%eigenval_HF)) DEALLOCATE (bs_env%eigenval_HF)
     340          34 :       IF (ALLOCATED(bs_env%eigenval_scGW0)) DEALLOCATE (bs_env%eigenval_scGW0)
     341          34 :       IF (ALLOCATED(bs_env%eigenval_scf_soc)) DEALLOCATE (bs_env%eigenval_scf_soc)
     342          34 :       IF (ALLOCATED(bs_env%eigenval_G0W0_soc)) DEALLOCATE (bs_env%eigenval_G0W0_soc)
     343          34 :       IF (ALLOCATED(bs_env%i_ao_start_from_atom)) DEALLOCATE (bs_env%i_ao_start_from_atom)
     344          34 :       IF (ALLOCATED(bs_env%i_ao_end_from_atom)) DEALLOCATE (bs_env%i_ao_end_from_atom)
     345          34 :       IF (ALLOCATED(bs_env%i_RI_start_from_atom)) DEALLOCATE (bs_env%i_RI_start_from_atom)
     346          34 :       IF (ALLOCATED(bs_env%i_RI_end_from_atom)) DEALLOCATE (bs_env%i_RI_end_from_atom)
     347          34 :       IF (ALLOCATED(bs_env%i_atom_intervals)) DEALLOCATE (bs_env%i_atom_intervals)
     348          34 :       IF (ALLOCATED(bs_env%j_atom_intervals)) DEALLOCATE (bs_env%j_atom_intervals)
     349          34 :       IF (ALLOCATED(bs_env%atoms_i_t_group)) DEALLOCATE (bs_env%atoms_i_t_group)
     350          34 :       IF (ALLOCATED(bs_env%atoms_j_t_group)) DEALLOCATE (bs_env%atoms_j_t_group)
     351          34 :       IF (ALLOCATED(bs_env%skip_Sigma_occ)) DEALLOCATE (bs_env%skip_Sigma_occ)
     352          34 :       IF (ALLOCATED(bs_env%skip_Sigma_vir)) DEALLOCATE (bs_env%skip_Sigma_vir)
     353          34 :       IF (ALLOCATED(bs_env%read_chi)) DEALLOCATE (bs_env%read_chi)
     354          34 :       IF (ALLOCATED(bs_env%calc_chi)) DEALLOCATE (bs_env%calc_chi)
     355          34 :       IF (ALLOCATED(bs_env%Sigma_c_exists)) DEALLOCATE (bs_env%Sigma_c_exists)
     356          34 :       IF (ALLOCATED(bs_env%sizes_AO)) DEALLOCATE (bs_env%sizes_AO)
     357          34 :       IF (ALLOCATED(bs_env%sizes_RI)) DEALLOCATE (bs_env%sizes_RI)
     358          34 :       IF (ALLOCATED(bs_env%index_to_cell_3c)) DEALLOCATE (bs_env%index_to_cell_3c)
     359          34 :       IF (ALLOCATED(bs_env%index_to_cell_Delta_R)) DEALLOCATE (bs_env%index_to_cell_Delta_R)
     360          34 :       IF (ASSOCIATED(bs_env%cell_to_index_3c)) DEALLOCATE (bs_env%cell_to_index_3c)
     361          34 :       IF (ASSOCIATED(bs_env%cell_to_index_Delta_R)) DEALLOCATE (bs_env%cell_to_index_Delta_R)
     362          34 :       IF (ALLOCATED(bs_env%task_Delta_R)) DEALLOCATE (bs_env%task_Delta_R)
     363          34 :       IF (ALLOCATED(bs_env%nblocks_3c)) DEALLOCATE (bs_env%nblocks_3c)
     364             : 
     365          34 :       CALL cp_fm_release(bs_env%fm_s_Gamma)
     366          34 :       CALL cp_fm_release(bs_env%fm_ks_Gamma(1))
     367          34 :       CALL cp_fm_release(bs_env%fm_ks_Gamma(2))
     368          34 :       CALL cp_fm_release(bs_env%fm_V_xc_Gamma(1))
     369          34 :       CALL cp_fm_release(bs_env%fm_V_xc_Gamma(2))
     370          34 :       CALL cp_fm_release(bs_env%fm_mo_coeff_Gamma(1))
     371          34 :       CALL cp_fm_release(bs_env%fm_mo_coeff_Gamma(2))
     372          34 :       CALL cp_fm_release(bs_env%fm_Gocc)
     373          34 :       CALL cp_fm_release(bs_env%fm_Gvir)
     374          34 :       CALL cp_fm_release(bs_env%fm_work_mo(1))
     375          34 :       CALL cp_fm_release(bs_env%fm_work_mo(2))
     376          34 :       CALL cp_fm_release(bs_env%fm_work_mo(3))
     377          34 :       CALL cp_fm_release(bs_env%fm_work_mo(4))
     378          34 :       CALL cp_fm_release(bs_env%fm_RI_RI)
     379          34 :       CALL cp_fm_release(bs_env%fm_chi_Gamma_freq)
     380          34 :       CALL cp_fm_release(bs_env%fm_W_MIC_freq)
     381             :       ! TODO : Test whether IF (rtp_method == rtp_method_gw) is needed
     382          34 :       CALL cp_fm_release(bs_env%fm_W_MIC_freq_zero)
     383          34 :       CALL cp_fm_release(bs_env%fm_W_MIC_freq_1_extra)
     384          34 :       CALL cp_fm_release(bs_env%fm_W_MIC_freq_1_no_extra)
     385          34 :       CALL cp_cfm_release(bs_env%cfm_work_mo)
     386          34 :       CALL cp_cfm_release(bs_env%cfm_work_mo_2)
     387             : 
     388          34 :       CALL safe_fm_destroy_1d(bs_env%fm_G_S)
     389          34 :       CALL safe_fm_destroy_1d(bs_env%fm_Sigma_x_R)
     390          34 :       CALL safe_fm_destroy_2d(bs_env%fm_V_xc_R)
     391          34 :       CALL safe_fm_destroy_2d(bs_env%fm_chi_R_t)
     392          34 :       CALL safe_fm_destroy_2d(bs_env%fm_MWM_R_t)
     393          34 :       CALL safe_fm_destroy_3d(bs_env%fm_Sigma_c_R_neg_tau)
     394          34 :       CALL safe_fm_destroy_3d(bs_env%fm_Sigma_c_R_pos_tau)
     395             : 
     396          34 :       CALL t_destroy_2d(bs_env%t_3c_int)
     397             : 
     398          34 :       CALL release_dbcsr_p_type(bs_env%mat_ao_ao)
     399          34 :       CALL release_dbcsr_p_type(bs_env%mat_RI_RI)
     400          34 :       CALL safe_dbcsr_deallocate_matrix_set_1d(bs_env%mat_chi_Gamma_tau)
     401             : 
     402          34 :       CALL release_dbcsr_p_type(bs_env%mat_ao_ao_tensor)
     403          34 :       CALL release_dbcsr_p_type(bs_env%mat_RI_RI_tensor)
     404             : 
     405          34 :       CALL safe_cfm_destroy_1d(bs_env%cfm_s_kp)
     406          34 :       CALL safe_cfm_destroy_2d(bs_env%cfm_ks_kp)
     407          34 :       CALL safe_cfm_destroy_2d(bs_env%cfm_mo_coeff_kp)
     408             : 
     409          34 :       CALL mp_para_env_release(bs_env%para_env)
     410          34 :       IF (ASSOCIATED(bs_env%para_env_tensor)) CALL mp_para_env_release(bs_env%para_env_tensor)
     411             : 
     412          34 :       CALL safe_dbt_destroy(bs_env%t_G)
     413          34 :       CALL safe_dbt_destroy(bs_env%t_chi)
     414          34 :       CALL safe_dbt_destroy(bs_env%t_W)
     415          34 :       CALL safe_dbt_destroy(bs_env%t_RI_AO__AO)
     416          34 :       CALL safe_dbt_destroy(bs_env%t_RI__AO_AO)
     417             : 
     418          34 :       IF (ALLOCATED(bs_env%basis_set_AO)) DEALLOCATE (bs_env%basis_set_AO)
     419          34 :       IF (ALLOCATED(bs_env%basis_set_RI)) DEALLOCATE (bs_env%basis_set_RI)
     420             : 
     421             :       ! SOC cfm_1d and arrays
     422          34 :       CALL safe_dbcsr_deallocate_matrix_set_2d(bs_env%mat_V_SOC_xyz)
     423          34 :       CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(1))
     424          34 :       CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(2))
     425          34 :       CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(3))
     426          34 :       CALL safe_cfm_destroy_1d(bs_env%cfm_SOC_spinor_ao)
     427             : 
     428          34 :       DEALLOCATE (bs_env)
     429             : 
     430          34 :       CALL timestop(handle)
     431             : 
     432          34 :    END SUBROUTINE bs_env_release
     433             : 
     434             : ! **************************************************************************************************
     435             : !> \brief ...
     436             : !> \param kpoints ...
     437             : ! **************************************************************************************************
     438         136 :    SUBROUTINE safe_kpoints_release(kpoints)
     439             :       TYPE(kpoint_type), POINTER                         :: kpoints
     440             : 
     441         136 :       IF (ASSOCIATED(kpoints)) CALL kpoint_release(kpoints)
     442             : 
     443         136 :    END SUBROUTINE safe_kpoints_release
     444             : 
     445             : ! **************************************************************************************************
     446             : !> \brief ...
     447             : !> \param dbcsr_p_type_matrix ...
     448             : ! **************************************************************************************************
     449         136 :    SUBROUTINE release_dbcsr_p_type(dbcsr_p_type_matrix)
     450             :       TYPE(dbcsr_p_type)                                 :: dbcsr_p_type_matrix
     451             : 
     452         136 :       IF (ASSOCIATED(dbcsr_p_type_matrix%matrix)) THEN
     453         136 :          CALL dbcsr_release(dbcsr_p_type_matrix%matrix)
     454         136 :          DEALLOCATE (dbcsr_p_type_matrix%matrix)
     455             :       END IF
     456             : 
     457         136 :    END SUBROUTINE release_dbcsr_p_type
     458             : 
     459             : ! **************************************************************************************************
     460             : !> \brief ...
     461             : !> \param t ...
     462             : ! **************************************************************************************************
     463         170 :    SUBROUTINE safe_dbt_destroy(t)
     464             :       TYPE(dbt_type)                                     :: t
     465             : 
     466         170 :       IF (ASSOCIATED(t%matrix_rep)) CALL dbt_destroy(t)
     467             : 
     468         170 :    END SUBROUTINE safe_dbt_destroy
     469             : 
     470             : ! **************************************************************************************************
     471             : !> \brief ...
     472             : !> \param dbcsr_array ...
     473             : ! **************************************************************************************************
     474          34 :    SUBROUTINE safe_dbcsr_deallocate_matrix_set_1d(dbcsr_array)
     475             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: dbcsr_array
     476             : 
     477          34 :       IF (ASSOCIATED(dbcsr_array)) CALL dbcsr_deallocate_matrix_set(dbcsr_array)
     478             : 
     479          34 :    END SUBROUTINE safe_dbcsr_deallocate_matrix_set_1d
     480             : 
     481             : ! **************************************************************************************************
     482             : !> \brief ...
     483             : !> \param dbcsr_array ...
     484             : ! **************************************************************************************************
     485          34 :    SUBROUTINE safe_dbcsr_deallocate_matrix_set_2d(dbcsr_array)
     486             :       TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER       :: dbcsr_array
     487             : 
     488          34 :       IF (ASSOCIATED(dbcsr_array)) CALL dbcsr_deallocate_matrix_set(dbcsr_array)
     489             : 
     490          34 :    END SUBROUTINE safe_dbcsr_deallocate_matrix_set_2d
     491             : 
     492             : ! **************************************************************************************************
     493             : !> \brief ...
     494             : !> \param fm_1d ...
     495             : ! **************************************************************************************************
     496          68 :    SUBROUTINE safe_fm_destroy_1d(fm_1d)
     497             :       TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:)        :: fm_1d
     498             : 
     499             :       INTEGER                                            :: i
     500             : 
     501          68 :       IF (ALLOCATED(fm_1d)) THEN
     502         120 :          DO i = 1, SIZE(fm_1d, 1)
     503         120 :             CALL cp_fm_release(fm_1d(i))
     504             :          END DO
     505          12 :          DEALLOCATE (fm_1d)
     506             :       END IF
     507             : 
     508          68 :    END SUBROUTINE safe_fm_destroy_1d
     509             : 
     510             : ! **************************************************************************************************
     511             : !> \brief ...
     512             : !> \param fm_2d ...
     513             : ! **************************************************************************************************
     514         102 :    SUBROUTINE safe_fm_destroy_2d(fm_2d)
     515             :       TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :)     :: fm_2d
     516             : 
     517             :       INTEGER                                            :: i, j
     518             : 
     519         102 :       IF (ALLOCATED(fm_2d)) THEN
     520         272 :          DO i = 1, SIZE(fm_2d, 1)
     521        1354 :          DO j = 1, SIZE(fm_2d, 2)
     522        1336 :             CALL cp_fm_release(fm_2d(i, j))
     523             :          END DO
     524             :          END DO
     525          18 :          DEALLOCATE (fm_2d)
     526             :       END IF
     527             : 
     528         102 :    END SUBROUTINE safe_fm_destroy_2d
     529             : 
     530             : ! **************************************************************************************************
     531             : !> \brief ...
     532             : !> \param fm_3d ...
     533             : ! **************************************************************************************************
     534          68 :    SUBROUTINE safe_fm_destroy_3d(fm_3d)
     535             :       TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :, :)  :: fm_3d
     536             : 
     537             :       INTEGER                                            :: i, j, k
     538             : 
     539          68 :       IF (ALLOCATED(fm_3d)) THEN
     540         120 :          DO i = 1, SIZE(fm_3d, 1)
     541        1056 :          DO j = 1, SIZE(fm_3d, 2)
     542        1980 :          DO k = 1, SIZE(fm_3d, 3)
     543        1872 :             CALL cp_fm_release(fm_3d(i, j, k))
     544             :          END DO
     545             :          END DO
     546             :          END DO
     547          12 :          DEALLOCATE (fm_3d)
     548             :       END IF
     549             : 
     550          68 :    END SUBROUTINE safe_fm_destroy_3d
     551             : 
     552             : ! **************************************************************************************************
     553             : !> \brief ...
     554             : !> \param cfm_1d ...
     555             : ! **************************************************************************************************
     556          68 :    SUBROUTINE safe_cfm_destroy_1d(cfm_1d)
     557             :       TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:)       :: cfm_1d
     558             : 
     559             :       INTEGER                                            :: i
     560             : 
     561          68 :       IF (ALLOCATED(cfm_1d)) THEN
     562         476 :          DO i = 1, SIZE(cfm_1d, 1)
     563         476 :             CALL cp_cfm_release(cfm_1d(i))
     564             :          END DO
     565          24 :          DEALLOCATE (cfm_1d)
     566             :       END IF
     567             : 
     568          68 :    END SUBROUTINE safe_cfm_destroy_1d
     569             : 
     570             : ! **************************************************************************************************
     571             : !> \brief ...
     572             : !> \param cfm_2d ...
     573             : ! **************************************************************************************************
     574          68 :    SUBROUTINE safe_cfm_destroy_2d(cfm_2d)
     575             :       TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:, :)    :: cfm_2d
     576             : 
     577             :       INTEGER                                            :: i, j
     578             : 
     579          68 :       IF (ALLOCATED(cfm_2d)) THEN
     580         452 :          DO i = 1, SIZE(cfm_2d, 1)
     581         892 :          DO j = 1, SIZE(cfm_2d, 2)
     582         880 :             CALL cp_cfm_release(cfm_2d(i, j))
     583             :          END DO
     584             :          END DO
     585          12 :          DEALLOCATE (cfm_2d)
     586             :       END IF
     587             : 
     588          68 :    END SUBROUTINE safe_cfm_destroy_2d
     589             : 
     590             : ! **************************************************************************************************
     591             : !> \brief ...
     592             : !> \param t_2d ...
     593             : ! **************************************************************************************************
     594          34 :    SUBROUTINE t_destroy_2d(t_2d)
     595             :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_2d
     596             : 
     597             :       INTEGER                                            :: i, j
     598             : 
     599          34 :       IF (ALLOCATED(t_2d)) THEN
     600          50 :          DO i = 1, SIZE(t_2d, 1)
     601         438 :             DO j = 1, SIZE(t_2d, 2)
     602         432 :                CALL dbt_destroy(t_2d(i, j))
     603             :             END DO
     604             :          END DO
     605         394 :          DEALLOCATE (t_2d)
     606             :       END IF
     607             : 
     608          34 :    END SUBROUTINE t_destroy_2d
     609             : 
     610           0 : END MODULE post_scf_bandstructure_types

Generated by: LCOV version 1.15