LCOV - code coverage report
Current view: top level - src - preconditioner_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:e5fdd81) Lines: 45 49 91.8 %
Date: 2024-04-16 07:24:02 Functions: 3 5 60.0 %

          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 of  preconditioners
      10             : !> \par History
      11             : !>      Separate types from construction and application
      12             : !> \author Joost VandeVondele (09.2002)
      13             : ! **************************************************************************************************
      14             : MODULE preconditioner_types
      15             :    USE cp_blacs_env,                    ONLY: cp_blacs_env_release,&
      16             :                                               cp_blacs_env_type
      17             :    USE cp_fm_types,                     ONLY: cp_fm_release,&
      18             :                                               cp_fm_type
      19             :    USE dbcsr_api,                       ONLY: dbcsr_deallocate_matrix,&
      20             :                                               dbcsr_p_type,&
      21             :                                               dbcsr_release_p,&
      22             :                                               dbcsr_type
      23             :    USE input_constants,                 ONLY: cholesky_reduce,&
      24             :                                               ot_precond_solver_default
      25             :    USE kinds,                           ONLY: dp
      26             :    USE message_passing,                 ONLY: mp_para_env_release,&
      27             :                                               mp_para_env_type
      28             : #include "./base/base_uses.f90"
      29             : 
      30             :    IMPLICIT NONE
      31             : 
      32             :    PRIVATE
      33             : 
      34             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'preconditioner_types'
      35             : 
      36             :    PUBLIC  :: preconditioner_type, preconditioner_p_type
      37             :    PUBLIC  :: init_preconditioner
      38             :    PUBLIC  :: preconditioner_in_use
      39             :    PUBLIC  :: destroy_preconditioner
      40             : 
      41             : ! **************************************************************************************************
      42             :    TYPE preconditioner_type
      43             : !    PRIVATE
      44             :       TYPE(dbcsr_type), POINTER :: sparse_matrix
      45             :       TYPE(cp_fm_type), POINTER :: fm
      46             :       TYPE(dbcsr_type), POINTER           :: dbcsr_matrix
      47             :       TYPE(dbcsr_type), POINTER           :: max_ev_vector
      48             :       TYPE(dbcsr_type), POINTER           :: min_ev_vector
      49             :       TYPE(dbcsr_p_type), POINTER, DIMENSION(:) :: inverse_history
      50             :       TYPE(mp_para_env_type), POINTER   :: para_env
      51             :       TYPE(cp_blacs_env_type), POINTER   :: ctxt
      52             :       INTEGER :: in_use, solver, ihistory, cholesky_use
      53             :       REAL(KIND=dp), DIMENSION(:), POINTER :: occ_evals, full_evals
      54             :       REAL(KIND=dp) :: energy_gap
      55             :       REAL(KIND=dp) :: condition_num
      56             :    END TYPE preconditioner_type
      57             : 
      58             : ! **************************************************************************************************
      59             :    TYPE preconditioner_p_type
      60             :       TYPE(preconditioner_type), POINTER :: preconditioner
      61             :    END TYPE preconditioner_p_type
      62             : 
      63             : CONTAINS
      64             : 
      65             : ! **************************************************************************************************
      66             : 
      67             : ! **************************************************************************************************
      68             : !> \brief ...
      69             : !> \param preconditioner ...
      70             : !> \return ...
      71             : ! **************************************************************************************************
      72         294 :    FUNCTION preconditioner_in_use(preconditioner)
      73             :       TYPE(preconditioner_type)                          :: preconditioner
      74             :       LOGICAL                                            :: preconditioner_in_use
      75             : 
      76         294 :       preconditioner_in_use = .NOT. (preconditioner%in_use .EQ. 0)
      77         294 :    END FUNCTION
      78             : 
      79             : ! **************************************************************************************************
      80             : !> \brief ...
      81             : !> \param preconditioner_env ...
      82             : !> \param para_env ...
      83             : !> \param blacs_env ...
      84             : ! **************************************************************************************************
      85        5936 :    SUBROUTINE init_preconditioner(preconditioner_env, para_env, blacs_env)
      86             : 
      87             :       TYPE(preconditioner_type)                          :: preconditioner_env
      88             :       TYPE(mp_para_env_type), POINTER                    :: para_env
      89             :       TYPE(cp_blacs_env_type), POINTER                   :: blacs_env
      90             : 
      91        5936 :       NULLIFY (preconditioner_env%sparse_matrix)
      92        5936 :       NULLIFY (preconditioner_env%fm)
      93        5936 :       NULLIFY (preconditioner_env%dbcsr_matrix)
      94        5936 :       NULLIFY (preconditioner_env%occ_evals)
      95        5936 :       NULLIFY (preconditioner_env%full_evals)
      96        5936 :       NULLIFY (preconditioner_env%inverse_history)
      97        5936 :       NULLIFY (preconditioner_env%max_ev_vector)
      98        5936 :       NULLIFY (preconditioner_env%min_ev_vector)
      99        5936 :       preconditioner_env%solver = ot_precond_solver_default
     100        5936 :       preconditioner_env%para_env => para_env
     101        5936 :       preconditioner_env%ctxt => blacs_env
     102             :       !inverse is used for filtering in update set it to something huge to
     103             :       ! avoid filtering if the information is not available
     104        5936 :       preconditioner_env%condition_num = -1.0_dp
     105        5936 :       preconditioner_env%ihistory = 0
     106             : 
     107        5936 :       CALL preconditioner_env%para_env%retain()
     108        5936 :       CALL preconditioner_env%ctxt%retain()
     109             : 
     110        5936 :    END SUBROUTINE init_preconditioner
     111             : 
     112             : ! **************************************************************************************************
     113             : !> \brief ...
     114             : !> \param preconditioner_env ...
     115             : ! **************************************************************************************************
     116        5936 :    SUBROUTINE destroy_preconditioner(preconditioner_env)
     117             : 
     118             :       TYPE(preconditioner_type)                          :: preconditioner_env
     119             : 
     120             :       CHARACTER(len=*), PARAMETER :: routineN = 'destroy_preconditioner'
     121             : 
     122             :       INTEGER                                            :: handle, i
     123             : 
     124        5936 :       CALL timeset(routineN, handle)
     125             : 
     126        5936 :       IF (ASSOCIATED(preconditioner_env%sparse_matrix)) THEN
     127           2 :          CALL dbcsr_deallocate_matrix(preconditioner_env%sparse_matrix)
     128           2 :          NULLIFY (preconditioner_env%sparse_matrix)
     129             :       END IF
     130             : 
     131        5936 :       IF (ASSOCIATED(preconditioner_env%fm)) THEN
     132        1420 :          CALL cp_fm_release(preconditioner_env%fm)
     133        1420 :          DEALLOCATE (preconditioner_env%fm)
     134             :          NULLIFY (preconditioner_env%fm)
     135             :       END IF
     136        5936 :       IF (ASSOCIATED(preconditioner_env%dbcsr_matrix)) THEN
     137        3960 :          CALL dbcsr_release_p(preconditioner_env%dbcsr_matrix)
     138             :       END IF
     139        5936 :       IF (ASSOCIATED(preconditioner_env%max_ev_vector)) THEN
     140        1683 :          CALL dbcsr_release_p(preconditioner_env%max_ev_vector)
     141             :       END IF
     142        5936 :       IF (ASSOCIATED(preconditioner_env%min_ev_vector)) THEN
     143        1683 :          CALL dbcsr_release_p(preconditioner_env%min_ev_vector)
     144             :       END IF
     145        5936 :       IF (ASSOCIATED(preconditioner_env%occ_evals)) THEN
     146        3008 :          DEALLOCATE (preconditioner_env%occ_evals)
     147             :       END IF
     148        5936 :       IF (ASSOCIATED(preconditioner_env%full_evals)) THEN
     149        3008 :          DEALLOCATE (preconditioner_env%full_evals)
     150             :       END IF
     151        5936 :       IF (ASSOCIATED(preconditioner_env%inverse_history)) THEN
     152           0 :          DO i = 1, SIZE(preconditioner_env%inverse_history)
     153           0 :             CALL dbcsr_release_p(preconditioner_env%inverse_history(i)%matrix)
     154             :          END DO
     155           0 :          DEALLOCATE (preconditioner_env%inverse_history)
     156             :       END IF
     157        5936 :       CALL mp_para_env_release(preconditioner_env%para_env)
     158        5936 :       CALL cp_blacs_env_release(preconditioner_env%ctxt)
     159             : 
     160        5936 :       preconditioner_env%in_use = 0
     161        5936 :       preconditioner_env%cholesky_use = cholesky_reduce
     162             : 
     163        5936 :       CALL timestop(handle)
     164             : 
     165        5936 :    END SUBROUTINE destroy_preconditioner
     166             : 
     167           0 : END MODULE preconditioner_types
     168             : 

Generated by: LCOV version 1.15