LCOV - code coverage report
Current view: top level - src - bse_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:9ccafda) Lines: 95.0 % 20 19
Test Date: 2026-10-15 00:55:44 Functions: 33.3 % 3 1

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief The BSE environment: the settings of the &BSE section and the state a GW path prepares
      10              : !>        for the solver core (window, energies, window-sized RI slabs, inverse dielectric matrix)
      11              : !> \par History
      12              : !>      09.2026 created from the bse_type of mp2_types [Maximilian Graml]
      13              : ! **************************************************************************************************
      14              : MODULE bse_types
      15              :    USE cp_control_types,                ONLY: dft_control_type
      16              :    USE cp_dbcsr_api,                    ONLY: dbcsr_p_type
      17              :    USE cp_dbcsr_operations,             ONLY: dbcsr_deallocate_matrix_set
      18              :    USE cp_fm_types,                     ONLY: cp_fm_release,&
      19              :                                               cp_fm_type
      20              :    USE exstates_types,                  ONLY: excited_energy_type
      21              :    USE input_section_types,             ONLY: section_vals_type
      22              :    USE kinds,                           ONLY: dp
      23              :    USE message_passing,                 ONLY: mp_para_env_type
      24              :    USE pw_env_types,                    ONLY: pw_env_type
      25              :    USE qs_mo_types,                     ONLY: mo_set_type
      26              :    USE qs_subsys_types,                 ONLY: qs_subsys_type
      27              : #include "./base/base_uses.f90"
      28              : 
      29              :    IMPLICIT NONE
      30              : 
      31              :    PRIVATE
      32              : 
      33              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'bse_types'
      34              : 
      35              :    PUBLIC :: bse_env_type, bse_env_release
      36              : 
      37              : ! **************************************************************************************************
      38              : !> \brief Settings of the &BSE section (read_bse_section, re-read before every BSE run, normalised in
      39              : !>        place by adapt_BSE_input_params) and the state that the entry of the GW fills for bse_solve:
      40              : !>        prepare_bse_env_from_ri_rpa_gw for RI_RPA%GW, prepare_bse_env_from_bandstructure_gw for
      41              : !>        PROPERTIES%BANDSTRUCTURE%GW
      42              : ! **************************************************************************************************
      43              :    TYPE bse_env_type
      44              :       ! --- settings, one field per keyword of the &BSE section; the reader sets them ---
      45              :       INTEGER                                            :: bse_spin_config = 0, &
      46              :                                                             bse_diag_method = 0, &
      47              :                                                             flag_tda = 0, &
      48              :                                                             num_exc_en = 0, &
      49              :                                                             num_print_exc = 0, &
      50              :                                                             num_print_exc_descr = 0, &
      51              :                                                             screening_method = 0, &
      52              :                                                             num_buffer_states = 0, &
      53              :                                                             block_size = 0, &
      54              :                                                             num_guess_transitions = 0, &
      55              :                                                             max_subspace_factor = 0, &
      56              :                                                             matvec_block_columns = -1, &
      57              :                                                             max_iter = 0, &
      58              :                                                             convergence_criterion = 0, &
      59              :                                                             preconditioner = 0, &
      60              :                                                             abba_solver = 0
      61              :       REAL(KIND=dp)                                      :: eps_res = 0.0_dp, &
      62              :                                                             memory_per_proc_gb = -1.0_dp, &
      63              :                                                             eps_energy = 0.0_dp, &
      64              :                                                             eps_x = 0.0_dp, &
      65              :                                                             screening_factor = 0.0_dp, &
      66              :                                                             bse_cutoff_occ = 0.0_dp, &
      67              :                                                             bse_cutoff_empty = 0.0_dp
      68              :       REAL(KIND=dp)                                      :: wc_scaling = 1.0_dp
      69              :       LOGICAL                                            :: do_bse = .FALSE., &
      70              :                                                             bse_debug_print = .FALSE., &
      71              :                                                             print_directional_exc_descr = .FALSE., &
      72              :                                                             print_directional_crosscorrelation = .FALSE., &
      73              :                                                             use_ks_energies = .FALSE.
      74              :       !BSE optical spectrum
      75              :       REAL(KIND=dp)                                      :: bse_spectrum_freq_step_size = 0.0_dp, &
      76              :                                                             bse_spectrum_freq_start = 0.0_dp, &
      77              :                                                             bse_spectrum_freq_end = 0.0_dp
      78              :       LOGICAL                                            :: bse_print_spectrum = .FALSE.
      79              :       REAL(KIND=dp), DIMENSION(:), POINTER               :: bse_eta_spectrum_list => NULL()
      80              : 
      81              :       !BSE NTO prints
      82              :       LOGICAL                                            :: do_nto_analysis = .FALSE., &
      83              :                                                             explicit_nto_list = .FALSE.
      84              :       REAL(KIND=dp)                                      :: eps_nto_eigval = 0.0_dp, &
      85              :                                                             eps_nto_osc_str = 0.0_dp
      86              :       INTEGER                                            :: num_print_exc_ntos = 0
      87              :       INTEGER, DIMENSION(:), POINTER                     :: bse_nto_state_list => NULL()
      88              :       INTEGER, DIMENSION(:), ALLOCATABLE                 :: bse_nto_state_list_final
      89              :       TYPE(section_vals_type), POINTER                   :: bse_section => NULL()
      90              :       ! --- state, unset until the entry of the GW (prepare_bse_env_from_...) fills it ---
      91              :       LOGICAL                                            :: do_tda = .FALSE., &
      92              :                                                             do_abba = .FALSE., &
      93              :                                                             do_fulldiag = .FALSE., &
      94              :                                                             do_iterdiag = .FALSE.
      95              :       INTEGER                                            :: nspins = 0, &
      96              :                                                             dimen_RI = 0, &
      97              :                                                             dimen_RI_red = 0, &
      98              :                                                             n_ov_joint = 0, &
      99              :                                                             gw_corr_lev_occ = 0
     100              :       ! per spin: the window's occupied and virtual counts, the full occupied count (MO labels and
     101              :       ! N_e), the GW-corrected virtual count
     102              :       INTEGER, DIMENSION(:), ALLOCATABLE                 :: homo_red, virt_red, homo_full, &
     103              :                                                             gw_corr_lev_virt
     104              :       ! windowed energies (level, spin), DFT and quasiparticle; bse_solve picks one by USE_KS_ENERGIES
     105              :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE        :: eigenval_dft, eigenval_qp
     106              :       ! window-sized RI slabs per spin, [1+Q(0)]^-1, and the screened slabs bse_solve forms
     107              :       TYPE(cp_fm_type), DIMENSION(:), ALLOCATABLE        :: fm_S_ia, fm_S_ij, fm_S_ab, &
     108              :                                                             fm_S_bar_ia, fm_S_bar_ij
     109              :       TYPE(cp_fm_type)                                   :: fm_eps_inv = cp_fm_type()
     110              :       ! AO multipoles <φ_µ|(r - r_0)^k|φ_ν> from QS, dipoles always and quadrupoles for the exciton
     111              :       ! descriptors, about r_0; the solver transforms them into the window
     112              :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_dipole_ao => NULL(), &
     113              :                                                             matrix_quadpole_ao => NULL()
     114              :       REAL(KIND=dp), DIMENSION(3)                        :: multipole_ref_point = 0.0_dp
     115              :       ! periodic directions of the Poisson solver, read from the input: the grids may be released
     116              :       INTEGER                                            :: n_periodic_poisson = 0
     117              :       ! QS objects the solver reads, none owned
     118              :       TYPE(mp_para_env_type), POINTER                    :: para_env => NULL()
     119              :       TYPE(qs_subsys_type), POINTER                      :: subsys => NULL()
     120              :       TYPE(pw_env_type), POINTER                         :: pw_env => NULL()
     121              :       TYPE(dft_control_type), POINTER                    :: dft_control => NULL()
     122              :       TYPE(mo_set_type), DIMENSION(:), POINTER           :: mos => NULL()
     123              :       TYPE(excited_energy_type), POINTER                 :: exstate_env => NULL()
     124              :    END TYPE bse_env_type
     125              : 
     126              : CONTAINS
     127              : 
     128              : ! **************************************************************************************************
     129              : !> \brief Releases the state a GW path prepared and nullifies the QS pointers; the settings stay,
     130              : !>        including the section pointer and the two lists into the input tree, since
     131              : !>        prepare_bse_env_from_ri_rpa_gw re-reads them from the section when a later energy evaluation
     132              : !>        on the same environment runs the BSE again. Safe on an unprepared environment.
     133              : !> \param bse_env the environment whose prepared state is released
     134              : ! **************************************************************************************************
     135          574 :    SUBROUTINE bse_env_release(bse_env)
     136              :       TYPE(bse_env_type), INTENT(INOUT)                  :: bse_env
     137              : 
     138          574 :       CALL cp_fm_release(bse_env%fm_S_ia)
     139          574 :       CALL cp_fm_release(bse_env%fm_S_ij)
     140          574 :       CALL cp_fm_release(bse_env%fm_S_ab)
     141          574 :       CALL cp_fm_release(bse_env%fm_S_bar_ia)
     142          574 :       CALL cp_fm_release(bse_env%fm_S_bar_ij)
     143          574 :       CALL cp_fm_release(bse_env%fm_eps_inv)
     144          574 :       CALL dbcsr_deallocate_matrix_set(bse_env%matrix_dipole_ao)
     145          574 :       CALL dbcsr_deallocate_matrix_set(bse_env%matrix_quadpole_ao)
     146          574 :       IF (ALLOCATED(bse_env%homo_red)) DEALLOCATE (bse_env%homo_red)
     147          574 :       IF (ALLOCATED(bse_env%virt_red)) DEALLOCATE (bse_env%virt_red)
     148          574 :       IF (ALLOCATED(bse_env%homo_full)) DEALLOCATE (bse_env%homo_full)
     149          574 :       IF (ALLOCATED(bse_env%gw_corr_lev_virt)) DEALLOCATE (bse_env%gw_corr_lev_virt)
     150          574 :       IF (ALLOCATED(bse_env%eigenval_dft)) DEALLOCATE (bse_env%eigenval_dft)
     151          574 :       IF (ALLOCATED(bse_env%eigenval_qp)) DEALLOCATE (bse_env%eigenval_qp)
     152          574 :       IF (ALLOCATED(bse_env%bse_nto_state_list_final)) DEALLOCATE (bse_env%bse_nto_state_list_final)
     153          574 :       NULLIFY (bse_env%para_env, bse_env%subsys, bse_env%pw_env, bse_env%dft_control, bse_env%mos, &
     154          574 :                bse_env%exstate_env)
     155              : 
     156          574 :    END SUBROUTINE bse_env_release
     157              : 
     158            0 : END MODULE bse_types
        

Generated by: LCOV version 2.0-1