LCOV - code coverage report
Current view: top level - src - almo_scf_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:42dac4a) Lines: 95.8 % 72 69
Test Date: 2025-07-25 12:55:17 Functions: 22.2 % 9 2

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2025 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Types for all ALMO-based methods
      10              : !> \par History
      11              : !>       2011.05 created [Rustam Z Khaliullin]
      12              : !>       2018.09 smearing support [Ruben Staub]
      13              : !> \author Rustam Z Khaliullin
      14              : ! **************************************************************************************************
      15              : MODULE almo_scf_types
      16              :    USE cp_blacs_env,                    ONLY: cp_blacs_env_type
      17              :    USE cp_dbcsr_api,                    ONLY: dbcsr_release,&
      18              :                                               dbcsr_type
      19              :    USE domain_submatrix_types,          ONLY: domain_map_type,&
      20              :                                               domain_submatrix_type
      21              :    USE input_constants,                 ONLY: &
      22              :         cg_dai_yuan, cg_fletcher, cg_fletcher_reeves, cg_hager_zhang, cg_hestenes_stiefel, &
      23              :         cg_liu_storey, cg_polak_ribiere, cg_zero, optimizer_diis, optimizer_pcg, optimizer_trustr, &
      24              :         trustr_cauchy, trustr_dogleg, trustr_steihaug, xalmo_prec_domain, xalmo_prec_full, &
      25              :         xalmo_prec_zero
      26              :    USE kinds,                           ONLY: dp
      27              :    USE message_passing,                 ONLY: mp_para_env_type
      28              : #include "./base/base_uses.f90"
      29              : 
      30              :    IMPLICIT NONE
      31              : 
      32              :    PRIVATE
      33              : 
      34              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'almo_scf_types'
      35              : 
      36              :    INTEGER, PARAMETER, PUBLIC   :: almo_mat_dim_aobasis = 1, &
      37              :                                    almo_mat_dim_occ = 2, &
      38              :                                    almo_mat_dim_virt = 3, &
      39              :                                    almo_mat_dim_virt_full = 4, &
      40              :                                    almo_mat_dim_domains = 5, &
      41              :                                    almo_mat_dim_virt_disc = 6
      42              :    REAL(KIND=dp), PARAMETER, PUBLIC :: almo_max_cutoff_multiplier = 2.2_dp
      43              : 
      44              :    PUBLIC :: almo_scf_env_type, optimizer_options_type, &
      45              :              print_optimizer_options, almo_scf_env_release, &
      46              :              almo_scf_history_type
      47              : 
      48              :    ! methods that add penalty terms to the energy functional
      49              :    TYPE penalty_type
      50              : 
      51              :       REAL(KIND=dp)      :: final_determinant = 0.0_dp, penalty_strength = 0.0_dp, &
      52              :                             determinant_tolerance = 0.0_dp, penalty_strength_dec_factor = 0.0_dp, &
      53              :                             compactification_filter_start = 0.0_dp
      54              :       INTEGER            :: operator_type = 0
      55              :       LOGICAL            :: virtual_nlmos = .FALSE.
      56              : 
      57              :    END TYPE penalty_type
      58              : 
      59              :    ! almo-based electronic structure analysis
      60              :    TYPE almo_analysis_type
      61              : 
      62              :       ! switch analysis on/off
      63              :       LOGICAL :: do_analysis = .FALSE.
      64              : 
      65              :       INTEGER :: frozen_mo_energy_term = 0
      66              : 
      67              :    END TYPE almo_analysis_type
      68              : 
      69              :    TYPE optimizer_options_type
      70              : 
      71              :       REAL(KIND=dp)  :: eps_error = 0.0_dp, &
      72              :                         eps_error_early = 0.0_dp, &
      73              :                         lin_search_eps_error = 0.0_dp, &
      74              :                         lin_search_step_size_guess = 0.0_dp, &
      75              :                         rho_do_not_update = 0.0_dp, &
      76              :                         model_grad_norm_ratio = 0.0_dp, &
      77              :                         initial_trust_radius = 0.0_dp, &
      78              :                         max_trust_radius = 0.0_dp, &
      79              :                         neglect_threshold = 0.0_dp
      80              : 
      81              :       INTEGER        :: optimizer_type = 0 ! diis, pcg, etc.
      82              :       TYPE(penalty_type)  :: opt_penalty = penalty_type()
      83              : 
      84              :       INTEGER        :: preconditioner = 0, & ! preconditioner type
      85              :                         conjugator = 0, & ! conjugator type
      86              :                         max_iter = 0, &
      87              :                         max_iter_early = 0, &
      88              :                         max_iter_outer_loop = 0, &
      89              :                         trustr_algorithm = 0, &
      90              :                         ndiis = 0 ! diis history length
      91              : 
      92              :       LOGICAL        :: early_stopping_on = .FALSE.
      93              : 
      94              :    END TYPE optimizer_options_type
      95              : 
      96              :    TYPE almo_scf_history_type
      97              :       INTEGER :: istore = 0, nstore = 0
      98              :       TYPE(dbcsr_type), DIMENSION(:, :), ALLOCATABLE :: matrix_p_up_down
      99              :       !TYPE(dbcsr_type), DIMENSION(:, :), ALLOCATABLE :: matrix_x
     100              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_t
     101              :    END TYPE
     102              : 
     103              :    ! the structure contains general info about the system
     104              :    TYPE almo_scf_env_type
     105              : 
     106              :       TYPE(mp_para_env_type), POINTER  :: para_env => NULL()
     107              :       TYPE(cp_blacs_env_type), POINTER  :: blacs_env => NULL()
     108              : 
     109              :       INTEGER :: nspins = 0, nelectrons_total = 0, naos = 0
     110              :       INTEGER :: natoms = 0, nmolecules = 0
     111              :       INTEGER, DIMENSION(2) :: nelectrons_spin = 0
     112              : 
     113              :       ! Definitions:
     114              :       ! I.  Domain - a subset of basis functions (e.g. AOs),
     115              :       ! II. Group  - a subset of electrons delocalized within a domain.
     116              :       !
     117              :       ! The following variables specify the group-domain structure
     118              :       ! of the system. Several rules must be obeyed:
     119              :       ! 1. There should be no zero domains (i.e. domain contains at least one AO).
     120              :       ! 2. There should be no empty domains (i.e. all domains must be populated
     121              :       !     by at least one electron).
     122              :       ! 3. If two groups are localized within the same domain they are combined
     123              :       ! It follows that the number of domains is equal to the number of groups
     124              :       !
     125              :       ! Number of domains
     126              :       INTEGER :: ndomains = 0
     127              : 
     128              :       ! List of atoms, whose basis functions are included into the domain.
     129              :       ! It is assumed that:
     130              :       !   (a) basis functions are localized and atom-labeled,
     131              :       !   (b) basis functions are grouped into atomic sets (i.e. if a basis
     132              :       !       function on an atom is in domain A then all basis functions on
     133              :       !       this atom are in domain A)
     134              :       !TYPE(domain_list_type), DIMENSION(:), ALLOCATABLE   :: atom_list_of_domain
     135              :       ! List of basis functions included into the domain
     136              :       !TYPE(domain_list_type), DIMENSION(:), ALLOCATABLE   :: basis_list_of_domain
     137              : 
     138              :       ! Number of electrons of each spin for a given domain (second dim is spin).
     139              :       ! Note that some domains can be populated only with alpha or beta electrons.
     140              :       INTEGER, DIMENSION(:, :), ALLOCATABLE                :: nocc_of_domain
     141              :       ! Number of basis functions for a given domain
     142              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: nbasis_of_domain
     143              :       ! Define number of virtuals for a given domain: nvirt = nbasis - nocc
     144              :       INTEGER, DIMENSION(:, :), ALLOCATABLE                :: nvirt_full_of_domain
     145              :       ! Define the dimension of truncated virtual subspace for a given domain:
     146              :       INTEGER, DIMENSION(:, :), ALLOCATABLE                :: nvirt_of_domain
     147              :       ! Define the dimension of discarded virtual subspace for a given domain:
     148              :       INTEGER, DIMENSION(:, :), ALLOCATABLE                :: nvirt_disc_of_domain
     149              :       ! Each domain has its own mu - "fermi" level
     150              :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE          :: mu_of_domain
     151              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: first_atom_of_domain
     152              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: last_atom_of_domain
     153              :       ! The following arrays are useful only with non-overlapping domains
     154              :       ! RZK-warning generalization is required
     155              :       INTEGER, DIMENSION(:), ALLOCATABLE        :: domain_index_of_ao
     156              :       INTEGER, DIMENSION(:), ALLOCATABLE        :: domain_index_of_atom
     157              : 
     158              :       ! Charge of domains
     159              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: charge_of_domain
     160              :       ! Charge of domains
     161              :       INTEGER, DIMENSION(:), ALLOCATABLE                  :: multiplicity_of_domain
     162              : 
     163              :       ! The matrix contains information about the delocalization of
     164              :       ! alpha and beta electrons.
     165              :       ! Rows denote basis function, columns denote electrons.
     166              :       ! Non-zero (j,i) entry means that electron j can delocalize over
     167              :       ! basis function i. 0.0 means no delocalization
     168              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE   :: quench_t
     169              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE   :: quench_t_blk
     170              :       ! Local array for a compact description of quench_t
     171              :       TYPE(domain_map_type), DIMENSION(:), ALLOCATABLE :: domain_map
     172              : 
     173              :       ! Several special cases for the structure of the group-domain matrix:
     174              :       ! 1. The basis functions can be grouped into:
     175              :       !    a. molecular sets
     176              :       !    b. atomic sets
     177              :       ! 2. Electrons can be grouped into:
     178              :       !    a. molecular sets
     179              :       !    b. atomic sets
     180              :       INTEGER :: domain_layout_mos = 0, domain_layout_aos = 0
     181              :       ! ALMO  constraint type.
     182              :       INTEGER :: constraint_type = 0
     183              : 
     184              :       ! Desciptors of molecules
     185              :       !INTEGER, DIMENSION(:), ALLOCATABLE        :: molecule_index_of_atom
     186              :       !INTEGER, DIMENSION(:), ALLOCATABLE        :: first_atom_of_molecule
     187              :       !INTEGER, DIMENSION(:), ALLOCATABLE        :: nbasis_of_molecule
     188              :       !INTEGER, DIMENSION(:,:), ALLOCATABLE      :: nocc_of_molecule
     189              :       !INTEGER, DIMENSION(:,:), ALLOCATABLE      :: nvirt_of_molecule
     190              :       !REAL(KIND=dp),DIMENSION(:,:), ALLOCATABLE :: mu_of_molecule
     191              : 
     192              :       ! Descriptors of atoms
     193              :       !INTEGER, DIMENSION(:), ALLOCATABLE        :: nbasis_of_atom
     194              :       !INTEGER, DIMENSION(:,:), ALLOCATABLE      :: nocc_of_atom
     195              :       !INTEGER, DIMENSION(:,:), ALLOCATABLE      :: nvirt_of_atom
     196              :       !REAL(KIND=dp),DIMENSION(:,:), ALLOCATABLE :: mu_of_atom
     197              : 
     198              :       ! All AO and MO matrices are distributed for parallel computations.
     199              :       ! The following flags specify what constitues a block for a parallel
     200              :       ! distribution. Both AOs and MOs can be divided into atomic or
     201              :       ! molecular blocks. Domain blocks should be equal or larger than
     202              :       ! the distribution blocks (otherwise retain_sparsity does not work).
     203              :       ! Possible values: almo_mat_distr_atomic, almo_mat_distr_molecular
     204              :       INTEGER :: mat_distr_aos = 0, mat_distr_mos = 0
     205              :       ! Define mappping from a distribution block to a domain
     206              :       INTEGER, DIMENSION(:), ALLOCATABLE :: domain_index_of_ao_block
     207              :       INTEGER, DIMENSION(:), ALLOCATABLE :: domain_index_of_mo_block
     208              : 
     209              :       LOGICAL              :: need_previous_ks = .FALSE.
     210              :       LOGICAL              :: need_virtuals = .FALSE.
     211              :       LOGICAL              :: need_orbital_energies = .FALSE.
     212              :       LOGICAL              :: s_inv_done = .FALSE.
     213              :       LOGICAL              :: s_sqrt_done = .FALSE.
     214              :       REAL(KIND=dp)        :: almo_scf_energy = 0.0_dp
     215              :       LOGICAL              :: orthogonal_basis = .FALSE., fixed_mu = .FALSE.
     216              :       LOGICAL              :: return_orthogonalized_mos = .FALSE., construct_nlmos = .FALSE.
     217              : 
     218              :       !! Smearing control
     219              :       !! smear flag allow to retrieve eigenvalues in almo_scf with diag algorithm and create occupation-scaled ALMO orbitals
     220              :       LOGICAL               :: smear = .FALSE.
     221              :       !! store relevant smearing parameters
     222              :       REAL(KIND=dp)         :: smear_e_temp = 0.0_dp !! electronic temperature, required for Fermi-Dirac
     223              :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE    :: kTS !! electronic entropy contribution of each spin system
     224              :       !! mo_energies(imo, ispin) stores the eigenvalue corresponding to the orbital imo with spin ispin
     225              :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: mo_energies
     226              :       !! since S-ALMO creates partially occupied orbitals, there is a need to store the real number of electron-pairs
     227              :       !! of each spin and for each fragment
     228              :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: real_ne_of_domain
     229              : 
     230              :       ! Controls for the SCF procedure
     231              :       REAL(KIND=dp)         :: eps_filter = 0.0_dp
     232              :       INTEGER               :: xalmo_trial_wf = 0
     233              :       INTEGER               :: almo_scf_guess = 0
     234              :       REAL(KIND=dp)         :: eps_prev_guess = 0.0_dp
     235              :       INTEGER               :: order_lanczos = 0
     236              :       REAL(KIND=dp)         :: matrix_iter_eps_error_factor = 0.0_dp
     237              :       REAL(KIND=dp)         :: eps_lanczos = 0.0_dp
     238              :       INTEGER               :: max_iter_lanczos = 0
     239              :       REAL(KIND=dp)         :: mixing_fraction = 0.0_dp
     240              :       REAL(KIND=dp)         :: mu = 0.0_dp
     241              :       ! SCF procedure for the block-diagonal ALMOs
     242              :       INTEGER               :: almo_update_algorithm = 0
     243              :       ! SCF procedure for the quenched ALMOs (xALMOs)
     244              :       INTEGER               :: xalmo_update_algorithm = 0
     245              :       ! mo overlap inversion algorithm
     246              :       INTEGER               :: sigma_inv_algorithm = 0
     247              : 
     248              :       ! Determinant of the ALMO overlap matrix
     249              :       REAL(KIND=dp)         :: overlap_determinant = 0.0_dp
     250              : 
     251              :       ! ALMO SCF delocalization control
     252              :       LOGICAL               :: perturbative_delocalization = .FALSE.
     253              :       INTEGER               :: quencher_radius_type = 0
     254              :       REAL(KIND=dp)         :: quencher_r0_factor = 0.0_dp, &
     255              :                                quencher_r1_factor = 0.0_dp, &
     256              :                                !quencher_r0_shift,&
     257              :                                !quencher_r1_shift,&
     258              :                                quencher_s0 = 0.0_dp, &
     259              :                                quencher_s1 = 0.0_dp, &
     260              :                                envelope_amplitude = 0.0_dp
     261              : 
     262              :       ! guess options
     263              :       ! This prevents a bug in GCC 8/9
     264              :       TYPE(almo_scf_history_type) :: almo_history = almo_scf_history_type(matrix_p_up_down=null(), matrix_t=null())
     265              :       TYPE(almo_scf_history_type) :: xalmo_history = almo_scf_history_type(matrix_p_up_down=null(), matrix_t=null())
     266              :       INTEGER :: almo_extrapolation_order = 0
     267              :       INTEGER :: xalmo_extrapolation_order = 0
     268              : 
     269              :       ! forces
     270              :       LOGICAL :: calc_forces = .FALSE.
     271              : 
     272              :       !!!!!!!!!!!!!!!!!!!!!!!
     273              :       !!!!!! MATRICES !!!!!!!
     274              :       !!!!!!!!!!!!!!!!!!!!!!!
     275              : 
     276              :       ! AO overlap NxN
     277              :       TYPE(dbcsr_type), DIMENSION(1)   :: matrix_s
     278              :       TYPE(dbcsr_type), DIMENSION(1)   :: matrix_s_inv
     279              :       TYPE(dbcsr_type), DIMENSION(1)   :: matrix_s_sqrt
     280              :       TYPE(dbcsr_type), DIMENSION(1)   :: matrix_s_sqrt_inv
     281              :       ! block-diagonal AO overlap NxN
     282              :       TYPE(dbcsr_type), DIMENSION(1)   :: matrix_s_blk
     283              :       TYPE(dbcsr_type), DIMENSION(1)   :: matrix_s_blk_inv
     284              :       TYPE(dbcsr_type), DIMENSION(1)   :: matrix_s_blk_sqrt
     285              :       TYPE(dbcsr_type), DIMENSION(1)   :: matrix_s_blk_sqrt_inv
     286              : 
     287              :       ! occupied ALMO coeff NxOCC (alpha,beta - if necessary)
     288              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_t_blk
     289              :       ! occupied MO coeff NxOCC (alpha,beta - if necessary)
     290              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_t
     291              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_t_tr
     292              :       ! MO overlap OCCxOCC and its inverse (alpha, beta - if necessary)
     293              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_sigma, &
     294              :                                                      matrix_sigma_inv, &
     295              :                                                      matrix_sigma_sqrt, &
     296              :                                                      matrix_sigma_sqrt_inv, &
     297              :                                                      matrix_sigma_blk, &
     298              :                                                      matrix_sigma_inv_0deloc
     299              : 
     300              :       ! error vector (alpha,beta - if necessary)
     301              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_err_blk
     302              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_err_xx
     303              : 
     304              :       ! MO overlap VIRTxVIRT and its derivatives
     305              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_sigma_vv, &
     306              :                                                      matrix_sigma_vv_blk, &
     307              :                                                      matrix_sigma_vv_sqrt, &
     308              :                                                      matrix_sigma_vv_sqrt_inv
     309              : 
     310              :       ! template of various VIRT x VIR matrices
     311              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_vv_full_blk, &
     312              :                                                      matrix_vv_disc_blk, &
     313              :                                                      matrix_vv_disc
     314              : 
     315              :       ! VIRT-OCC MO overlap
     316              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_vo, matrix_ov
     317              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_ov_full, &
     318              :                                                      matrix_ov_disc
     319              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_x
     320              : 
     321              :       ! VIRT_DISC x VIRT_RETAINED
     322              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_k_blk
     323              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_k_tr
     324              :       ! matrix_k_blk_ones is blocked with all elements equal to 1.0
     325              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_k_blk_ones
     326              : 
     327              :       ! virtual ALMO coeff NxV
     328              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_v_blk, &
     329              :                                                      matrix_v, &
     330              :                                                      matrix_v_full_blk, &
     331              :                                                      matrix_v_disc, &
     332              :                                                      matrix_v_disc_blk
     333              : 
     334              :       ! kohn-sham matrix (alpha,beta - if necessary)
     335              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_ks
     336              :       ! the diff between ks_blk and ks_0deloc is that blk is a blocked matrix
     337              :       ! 0deloc stores the matrix that correponds to zero-delocalization state
     338              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_ks_blk
     339              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_ks_0deloc
     340              :       ! density NxN (alpha,beta - if necessary)
     341              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_p
     342              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_p_blk
     343              : 
     344              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_eoo
     345              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_evv_full
     346              : 
     347              :       ! preconditioner for k-optimization
     348              :       ! RZK-warning: do they have to be stored?
     349              :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: opt_k_t_rr, &
     350              :                                                      opt_k_t_dd, &
     351              :                                                      opt_k_denom
     352              : 
     353              :       ! second dimension is spin
     354              :       TYPE(domain_submatrix_type), DIMENSION(:, :), ALLOCATABLE :: domain_preconditioner
     355              :       TYPE(domain_submatrix_type), DIMENSION(:, :), ALLOCATABLE :: domain_s_inv
     356              :       TYPE(domain_submatrix_type), DIMENSION(:, :), ALLOCATABLE :: domain_s_sqrt
     357              :       TYPE(domain_submatrix_type), DIMENSION(:, :), ALLOCATABLE :: domain_s_sqrt_inv
     358              :       TYPE(domain_submatrix_type), DIMENSION(:, :), ALLOCATABLE :: domain_ks_xx
     359              :       TYPE(domain_submatrix_type), DIMENSION(:, :), ALLOCATABLE :: domain_t
     360              :       TYPE(domain_submatrix_type), DIMENSION(:, :), ALLOCATABLE :: domain_err
     361              :       TYPE(domain_submatrix_type), DIMENSION(:, :), ALLOCATABLE :: domain_r_down_up
     362              : 
     363              :       INTEGER, DIMENSION(:), ALLOCATABLE                       :: cpu_of_domain
     364              : 
     365              :       ! Options for various subsection options collected neatly
     366              :       TYPE(almo_analysis_type)                       :: almo_analysis = almo_analysis_type()
     367              : 
     368              :       ! Options for various optimizers collected neatly
     369              :       TYPE(optimizer_options_type)                   :: opt_block_diag_diis = optimizer_options_type()
     370              :       TYPE(optimizer_options_type)                   :: opt_block_diag_pcg = optimizer_options_type()
     371              :       TYPE(optimizer_options_type)                   :: opt_xalmo_diis = optimizer_options_type()
     372              :       TYPE(optimizer_options_type)                   :: opt_xalmo_pcg = optimizer_options_type()
     373              :       TYPE(optimizer_options_type)                   :: opt_xalmo_trustr = optimizer_options_type()
     374              :       TYPE(optimizer_options_type)                   :: opt_nlmo_pcg = optimizer_options_type()
     375              :       TYPE(optimizer_options_type)                   :: opt_block_diag_trustr = optimizer_options_type()
     376              :       TYPE(optimizer_options_type)                   :: opt_xalmo_newton_pcg_solver = optimizer_options_type()
     377              :       TYPE(optimizer_options_type)                   :: opt_k_pcg = optimizer_options_type()
     378              : 
     379              :       ! keywords that control electron delocalization treatment
     380              :       ! RZK-warning: many of these varibles should be collected
     381              :       !  into an optimizer_options_type variable
     382              :       INTEGER         :: deloc_method = 0
     383              :       LOGICAL         :: deloc_use_occ_orbs = .FALSE.
     384              :       LOGICAL         :: deloc_cayley_use_virt_orbs = .FALSE.
     385              :       INTEGER         :: deloc_cayley_tensor_type = 0
     386              :       LOGICAL         :: deloc_cayley_linear = .FALSE.
     387              :       INTEGER         :: deloc_cayley_conjugator = 0
     388              :       REAL(KIND=dp)   :: deloc_cayley_eps_convergence = 0.0_dp
     389              :       INTEGER         :: deloc_cayley_max_iter = 0
     390              :       INTEGER         :: deloc_truncate_virt = 0
     391              :       INTEGER         :: deloc_virt_per_domain = 0
     392              :       LOGICAL         :: deloc_cayley_occ_precond = .FALSE.
     393              :       LOGICAL         :: deloc_cayley_vir_precond = .FALSE.
     394              : 
     395              :       !! keywords that control optimization of retained orbitals
     396              :       INTEGER         :: opt_k_conjugator = 0 !-> conjugartor
     397              :       REAL(KIND=dp)   :: opt_k_eps_convergence = 0.0_dp !-> eps_error
     398              :       REAL(KIND=dp)   :: opt_k_trial_step_size = 0.0_dp !-> lin_search_step_size_guess
     399              :       INTEGER         :: opt_k_max_iter = 0 !-> max_iter
     400              :       INTEGER         :: opt_k_outer_max_iter = 0 !-> max_iter for a separate 'outer' optimizer
     401              :       REAL(KIND=dp)   :: opt_k_trial_step_size_multiplier = 0.0_dp !-> ?
     402              :       INTEGER         :: opt_k_conj_iter_start = 0 !-> ?
     403              :       INTEGER         :: opt_k_prec_iter_start = 0 !-> ?
     404              :       INTEGER         :: opt_k_conj_iter_freq = 0 !-> ?
     405              :       INTEGER         :: opt_k_prec_iter_freq = 0 !-> ?
     406              : 
     407              :       ! development keywords
     408              :       INTEGER         :: integer01 = 0
     409              :       INTEGER         :: integer02 = 0
     410              :       INTEGER         :: integer03 = 0
     411              :       INTEGER         :: integer04 = 0
     412              :       INTEGER         :: integer05 = 0
     413              :       REAL(KIND=dp)   :: real01 = 0.0_dp
     414              :       REAL(KIND=dp)   :: real02 = 0.0_dp
     415              :       REAL(KIND=dp)   :: real03 = 0.0_dp
     416              :       REAL(KIND=dp)   :: real04 = 0.0_dp
     417              :       REAL(KIND=dp)   :: real05 = 0.0_dp
     418              :       LOGICAL         :: logical01 = .FALSE.
     419              :       LOGICAL         :: logical02 = .FALSE.
     420              :       LOGICAL         :: logical03 = .FALSE.
     421              :       LOGICAL         :: logical04 = .FALSE.
     422              :       LOGICAL         :: logical05 = .FALSE.
     423              : 
     424              :    END TYPE almo_scf_env_type
     425              : 
     426              : CONTAINS
     427              : 
     428              : ! **************************************************************************************************
     429              : !> \brief Prints out the options of an optimizer
     430              : !> \param optimizer   options to print
     431              : !> \param unit_nr   output stream
     432              : !> \par History
     433              : !>       2014.10 created [Rustam Z Khaliullin]
     434              : !> \author Rustam Z Khaliullin
     435              : ! **************************************************************************************************
     436           83 :    SUBROUTINE print_optimizer_options(optimizer, unit_nr)
     437              : 
     438              :       TYPE(optimizer_options_type), INTENT(IN)           :: optimizer
     439              :       INTEGER, INTENT(IN)                                :: unit_nr
     440              : 
     441              :       CHARACTER(33)                                      :: conj_string, prec_string, type_string
     442              : 
     443           83 :       IF (unit_nr .GT. 0) THEN
     444              : 
     445          121 :          SELECT CASE (optimizer%optimizer_type)
     446              :          CASE (optimizer_diis)
     447           38 :             type_string = "DIIS"
     448              :          CASE (optimizer_pcg)
     449           36 :             type_string = "PCG"
     450              :          CASE (optimizer_trustr)
     451           83 :             type_string = "TRUST REGION"
     452              :          END SELECT
     453              : 
     454           83 :          WRITE (unit_nr, '(T4,A,T48,A33)') "optimizer type:", TRIM(type_string)
     455           83 :          WRITE (unit_nr, '(T4,A,T48,I33)') "maximum iterations:", optimizer%max_iter
     456           83 :          WRITE (unit_nr, '(T4,A,T48,E33.3)') "target error:", optimizer%eps_error
     457              : 
     458           83 :          IF (optimizer%optimizer_type .EQ. optimizer_diis) THEN
     459              : 
     460           38 :             WRITE (unit_nr, '(T4,A,T48,I33)') "maximum DIIS history:", optimizer%ndiis
     461              : 
     462              :          END IF
     463              : 
     464           83 :          IF (optimizer%optimizer_type .EQ. optimizer_trustr .OR. &
     465              :              optimizer%optimizer_type .EQ. optimizer_pcg) THEN
     466              : 
     467           45 :             WRITE (unit_nr, '(T4,A,T48,I33)') "maximum outer loop iterations:", &
     468           90 :                optimizer%max_iter_outer_loop
     469              : 
     470           45 :             SELECT CASE (optimizer%preconditioner)
     471              :             CASE (xalmo_prec_zero)
     472            0 :                prec_string = "NONE"
     473              :             CASE (xalmo_prec_domain)
     474           45 :                prec_string = "0.5 KS + 0.5 S, DOMAINS"
     475              :             CASE (xalmo_prec_full)
     476           45 :                prec_string = "0.5 KS + 0.5 S, FULL"
     477              :             END SELECT
     478           45 :             WRITE (unit_nr, '(T4,A,T48,A33)') "preconditioner:", TRIM(prec_string)
     479              : 
     480           45 :             SELECT CASE (optimizer%conjugator)
     481              :             CASE (cg_zero)
     482            0 :                conj_string = "Steepest descent"
     483              :             CASE (cg_polak_ribiere)
     484            3 :                conj_string = "Polak-Ribiere"
     485              :             CASE (cg_fletcher_reeves)
     486            8 :                conj_string = "Fletcher-Reeves"
     487              :             CASE (cg_hestenes_stiefel)
     488            4 :                conj_string = "Hestenes-Stiefel"
     489              :             CASE (cg_fletcher)
     490           15 :                conj_string = "Fletcher"
     491              :             CASE (cg_liu_storey)
     492            3 :                conj_string = "Liu-Storey"
     493              :             CASE (cg_dai_yuan)
     494            4 :                conj_string = "Dai-Yuan"
     495              :             CASE (cg_hager_zhang)
     496           45 :                conj_string = "Hager-Zhang"
     497              :             END SELECT
     498           45 :             WRITE (unit_nr, '(T4,A,T48,A33)') "conjugator:", TRIM(conj_string)
     499              : 
     500              :          END IF
     501              : 
     502           83 :          IF (optimizer%optimizer_type .EQ. optimizer_pcg) THEN
     503              : 
     504           36 :             WRITE (unit_nr, '(T4,A,T48,E33.3)') "line search step size guess:", &
     505           72 :                optimizer%lin_search_step_size_guess
     506           36 :             WRITE (unit_nr, '(T4,A,T48,E33.3)') "line search target error:", &
     507           72 :                optimizer%lin_search_eps_error
     508           36 :             IF (optimizer%neglect_threshold .GT. 0.0_dp) THEN
     509            7 :                WRITE (unit_nr, '(T4,A,T48,E33.3)') "low-curvature threshold:", &
     510           14 :                   optimizer%neglect_threshold
     511              :             END IF
     512              : 
     513              :          END IF
     514              : 
     515           83 :          IF (optimizer%optimizer_type .EQ. optimizer_trustr) THEN
     516              : 
     517           10 :             SELECT CASE (optimizer%trustr_algorithm)
     518              :             CASE (trustr_steihaug)
     519            1 :                conj_string = "Steihaug's CG"
     520              :             CASE (trustr_cauchy)
     521            6 :                conj_string = "Cauchy point"
     522              :             CASE (trustr_dogleg)
     523            9 :                conj_string = "Dogleg"
     524              :             END SELECT
     525            9 :             WRITE (unit_nr, '(T4,A,T48,A33)') "Subproblem algorithm:", TRIM(conj_string)
     526              : 
     527            9 :             WRITE (unit_nr, '(T4,A,T48,E33.3)') "gradient decrease accepted:", &
     528           18 :                optimizer%model_grad_norm_ratio
     529            9 :             WRITE (unit_nr, '(T4,A,T48,E33.3)') "initial trust radius:", &
     530           18 :                optimizer%initial_trust_radius
     531            9 :             WRITE (unit_nr, '(T4,A,T48,E33.3)') "max trust radius:", &
     532           18 :                optimizer%max_trust_radius
     533            9 :             WRITE (unit_nr, '(T4,A,T48,E33.3)') "rho of no update lies between .0 and .25:", &
     534           18 :                optimizer%rho_do_not_update
     535              : 
     536              :          END IF
     537              : 
     538              :       END IF
     539              : 
     540           83 :    END SUBROUTINE print_optimizer_options
     541              : 
     542              : ! **************************************************************************************************
     543              : !> \brief release the almo scf envirnoment
     544              : !> \param almo_scf_env ...
     545              : !> \par History
     546              : !>       2016.11 created [Rustam Z Khaliullin]
     547              : !> \author Rustam Z Khaliullin
     548              : ! **************************************************************************************************
     549           66 :    SUBROUTINE almo_scf_env_release(almo_scf_env)
     550              :       TYPE(almo_scf_env_type), POINTER                   :: almo_scf_env
     551              : 
     552              :       CHARACTER(len=*), PARAMETER :: routineN = 'almo_scf_env_release'
     553              : 
     554              :       INTEGER                                            :: handle, ispin, istore
     555              : 
     556           66 :       CALL timeset(routineN, handle)
     557              : 
     558              :       ! delete history
     559          132 :       DO ispin = 1, SIZE(almo_scf_env%almo_history%matrix_t)
     560          154 :          DO istore = 1, MIN(almo_scf_env%almo_history%istore, almo_scf_env%almo_history%nstore)
     561          154 :             CALL dbcsr_release(almo_scf_env%almo_history%matrix_p_up_down(ispin, istore))
     562              :          END DO
     563           66 :          IF (almo_scf_env%almo_history%istore .GT. 0) &
     564          130 :             CALL dbcsr_release(almo_scf_env%almo_history%matrix_t(ispin))
     565              :       END DO
     566           66 :       DEALLOCATE (almo_scf_env%almo_history%matrix_p_up_down)
     567           66 :       DEALLOCATE (almo_scf_env%almo_history%matrix_t)
     568              :       ! delete xalmo history
     569          132 :       DO ispin = 1, SIZE(almo_scf_env%xalmo_history%matrix_t)
     570           90 :          DO istore = 1, MIN(almo_scf_env%xalmo_history%istore, almo_scf_env%xalmo_history%nstore)
     571           90 :             CALL dbcsr_release(almo_scf_env%xalmo_history%matrix_p_up_down(ispin, istore))
     572              :             !CALL dbcsr_release(almo_scf_env%xalmo_history%matrix_x(ispin, istore))
     573              :          END DO
     574           66 :          IF (almo_scf_env%xalmo_history%istore .GT. 0) &
     575           76 :             CALL dbcsr_release(almo_scf_env%xalmo_history%matrix_t(ispin))
     576              :       END DO
     577           66 :       DEALLOCATE (almo_scf_env%xalmo_history%matrix_p_up_down)
     578              :       !DEALLOCATE (almo_scf_env%xalmo_history%matrix_x)
     579           66 :       DEALLOCATE (almo_scf_env%xalmo_history%matrix_t)
     580              : 
     581           66 :       DEALLOCATE (almo_scf_env)
     582              : 
     583           66 :       CALL timestop(handle)
     584              : 
     585           66 :    END SUBROUTINE almo_scf_env_release
     586              : 
     587            0 : END MODULE almo_scf_types
     588              : 
        

Generated by: LCOV version 2.0-1