LCOV - code coverage report
Current view: top level - src - admm_dm_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:2fce0f8) Lines: 25 26 96.2 %
Date: 2024-12-21 06:28:57 Functions: 2 6 33.3 %

          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 Types and set/get functions for auxiliary density matrix methods
      10             : !> \par History
      11             : !>      11.2014 created [Ole Schuett]
      12             : !> \author Ole Schuett
      13             : ! **************************************************************************************************
      14             : MODULE admm_dm_types
      15             :    USE cp_control_types,                ONLY: admm_control_type
      16             :    USE cp_dbcsr_api,                    ONLY: dbcsr_release,&
      17             :                                               dbcsr_type
      18             :    USE input_constants,                 ONLY: do_admm_basis_projection,&
      19             :                                               do_admm_purify_mcweeny
      20             :    USE kinds,                           ONLY: dp
      21             : #include "./base/base_uses.f90"
      22             : 
      23             :    IMPLICIT NONE
      24             :    PRIVATE
      25             : 
      26             :    PUBLIC :: admm_dm_type, mcweeny_history_type
      27             :    PUBLIC :: admm_dm_create, admm_dm_release
      28             : 
      29             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'admm_dm_types'
      30             : 
      31             :    TYPE mcweeny_history_type
      32             :       TYPE(dbcsr_type)                        :: m
      33             :       INTEGER                                    :: count = -1
      34             :       TYPE(mcweeny_history_type), POINTER        :: next => Null()
      35             :    END TYPE mcweeny_history_type
      36             : 
      37             :    TYPE mcweeny_history_p_type
      38             :       TYPE(mcweeny_history_type), POINTER        :: p => Null()
      39             :    END TYPE mcweeny_history_p_type
      40             : 
      41             :    TYPE admm_dm_type
      42             :       LOGICAL                                  :: purify = .FALSE.
      43             :       INTEGER                                  :: method = -1
      44             :       TYPE(dbcsr_type), POINTER             :: matrix_a => Null()
      45             :       REAL(KIND=dp)                            :: eps_filter = 1e-20_dp
      46             :       INTEGER                                  :: mcweeny_max_steps = 100
      47             :       INTEGER, DIMENSION(:, :), POINTER         :: block_map => Null()
      48             :       TYPE(mcweeny_history_p_type), &
      49             :          DIMENSION(:), POINTER                  :: mcweeny_history => Null()
      50             :    END TYPE
      51             : 
      52             : CONTAINS
      53             : 
      54             : ! **************************************************************************************************
      55             : !> \brief Create a new admm_dm type
      56             : !> \param admm_dm ...
      57             : !> \param admm_control ...
      58             : !> \param nspins ...
      59             : !> \param natoms ...
      60             : !> \author Ole Schuett
      61             : ! **************************************************************************************************
      62          14 :    SUBROUTINE admm_dm_create(admm_dm, admm_control, nspins, natoms)
      63             :       TYPE(admm_dm_type), POINTER                        :: admm_dm
      64             :       TYPE(admm_control_type), POINTER                   :: admm_control
      65             :       INTEGER, INTENT(IN)                                :: nspins, natoms
      66             : 
      67             :       INTEGER                                            :: i, iatom, iblock, j, jatom
      68             : 
      69          14 :       ALLOCATE (admm_dm)
      70             :       ! copy settings from admm_control
      71          14 :       admm_dm%purify = (admm_control%purification_method == do_admm_purify_mcweeny)
      72          14 :       admm_dm%method = admm_control%method
      73          14 :       admm_dm%eps_filter = admm_control%eps_filter
      74             : 
      75          64 :       ALLOCATE (admm_dm%mcweeny_history(nspins))
      76             : 
      77          14 :       IF (admm_dm%method /= do_admm_basis_projection) THEN
      78             :          ! create block map
      79          16 :          ALLOCATE (admm_dm%block_map(natoms, natoms))
      80         100 :          admm_dm%block_map(:, :) = 0
      81          12 :          DO iblock = 1, SIZE(admm_control%blocks)
      82          28 :             DO i = 1, SIZE(admm_control%blocks(iblock)%list)
      83          16 :                iatom = admm_control%blocks(iblock)%list(i)
      84          64 :                DO j = 1, SIZE(admm_control%blocks(iblock)%list)
      85          40 :                   jatom = admm_control%blocks(iblock)%list(j)
      86          56 :                   admm_dm%block_map(iatom, jatom) = 1
      87             :                END DO
      88             :             END DO
      89             :          END DO
      90             :       END IF
      91          14 :    END SUBROUTINE admm_dm_create
      92             : 
      93             : ! **************************************************************************************************
      94             : !> \brief Release a admm_dm type
      95             : !> \param admm_dm ...
      96             : !> \author Ole Schuett
      97             : ! **************************************************************************************************
      98          14 :    SUBROUTINE admm_dm_release(admm_dm)
      99             :       TYPE(admm_dm_type), POINTER                        :: admm_dm
     100             : 
     101          14 :       IF (.NOT. ASSOCIATED(admm_dm)) RETURN
     102             : 
     103          14 :       IF (ASSOCIATED(admm_dm%matrix_a)) THEN
     104          10 :          CALL dbcsr_release(admm_dm%matrix_a)
     105          10 :          DEALLOCATE (admm_dm%matrix_a)
     106             :       END IF
     107             : 
     108          14 :       IF (ASSOCIATED(admm_dm%block_map)) &
     109           4 :          DEALLOCATE (admm_dm%block_map)
     110             : 
     111          14 :       DEALLOCATE (admm_dm%mcweeny_history)
     112          14 :       DEALLOCATE (admm_dm)
     113             : 
     114             :    END SUBROUTINE admm_dm_release
     115             : 
     116           0 : END MODULE admm_dm_types
     117             : 

Generated by: LCOV version 1.15