LCOV - code coverage report
Current view: top level - src - qs_period_efield_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:42dac4a) Lines: 96.2 % 26 25
Test Date: 2025-07-25 12:55:17 Functions: 75.0 % 4 3

            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 type for berry phase efield matrices. At the moment only used for
      10              : !>        cosmat and sinmat
      11              : !> \par History
      12              : !>      none
      13              : !> \author fschiff (06.2010)
      14              : ! **************************************************************************************************
      15              : 
      16              : MODULE qs_period_efield_types
      17              : 
      18              :    USE cp_dbcsr_api,                    ONLY: dbcsr_p_type
      19              :    USE cp_dbcsr_operations,             ONLY: dbcsr_deallocate_matrix_set
      20              :    USE kinds,                           ONLY: dp
      21              : #include "./base/base_uses.f90"
      22              : 
      23              :    IMPLICIT NONE
      24              : 
      25              :    PRIVATE
      26              : 
      27              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_period_efield_types'
      28              : 
      29              :    PUBLIC :: efield_berry_type, efield_berry_release, init_efield_matrices, &
      30              :              set_efield_matrices
      31              : 
      32              :    TYPE efield_berry_type
      33              :       REAL(KIND=dp)                                          :: field_energy = -1.0_dp
      34              :       REAL(KIND=dp), DIMENSION(3)                            :: polarisation = -1.0_dp
      35              :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER           :: cosmat => NULL()
      36              :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER           :: sinmat => NULL()
      37              :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER           :: dipmat => NULL()
      38              :    END TYPE efield_berry_type
      39              : 
      40              : CONTAINS
      41              : 
      42              : ! **************************************************************************************************
      43              : !> \brief ...
      44              : !> \param efield ...
      45              : ! **************************************************************************************************
      46         1382 :    SUBROUTINE init_efield_matrices(efield)
      47              :       TYPE(efield_berry_type), POINTER                   :: efield
      48              : 
      49              :       REAL(KIND=dp)                                      :: field_energy
      50              :       REAL(KIND=dp), DIMENSION(3)                        :: polarisation
      51              : 
      52              : ! retain possible values for energy and polarisation
      53              : 
      54         1382 :       IF (ASSOCIATED(efield)) THEN
      55         1128 :          field_energy = efield%field_energy
      56         4512 :          polarisation = efield%polarisation
      57         1128 :          CALL efield_berry_release(efield)
      58              :       ELSE
      59          254 :          field_energy = 0.0_dp
      60          254 :          polarisation = 0.0_dp
      61              :       END IF
      62              : 
      63         6910 :       ALLOCATE (efield)
      64              :       NULLIFY (efield%cosmat)
      65              :       NULLIFY (efield%sinmat)
      66              :       NULLIFY (efield%dipmat)
      67              : 
      68         1382 :       efield%field_energy = field_energy
      69         5528 :       efield%polarisation = polarisation
      70              : 
      71         1382 :    END SUBROUTINE init_efield_matrices
      72              : 
      73              : ! **************************************************************************************************
      74              : !> \brief ...
      75              : !> \param efield ...
      76              : !> \param sinmat ...
      77              : !> \param cosmat ...
      78              : !> \param dipmat ...
      79              : ! **************************************************************************************************
      80         1050 :    SUBROUTINE set_efield_matrices(efield, sinmat, cosmat, dipmat)
      81              : 
      82              :       TYPE(efield_berry_type), POINTER                   :: efield
      83              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
      84              :          POINTER                                         :: sinmat, cosmat, dipmat
      85              : 
      86         1050 :       IF (PRESENT(cosmat)) efield%cosmat => cosmat
      87         1050 :       IF (PRESENT(sinmat)) efield%sinmat => sinmat
      88         1050 :       IF (PRESENT(dipmat)) efield%dipmat => dipmat
      89              : 
      90         1050 :    END SUBROUTINE set_efield_matrices
      91              : 
      92              : ! **************************************************************************************************
      93              : !> \brief ...
      94              : !> \param efield ...
      95              : ! **************************************************************************************************
      96        15945 :    SUBROUTINE efield_berry_release(efield)
      97              :       TYPE(efield_berry_type), POINTER                   :: efield
      98              : 
      99        15945 :       IF (ASSOCIATED(efield)) THEN
     100         1382 :          IF (ASSOCIATED(efield%sinmat) .AND. ASSOCIATED(efield%cosmat)) THEN
     101          252 :             CALL dbcsr_deallocate_matrix_set(efield%cosmat)
     102          252 :             CALL dbcsr_deallocate_matrix_set(efield%sinmat)
     103              :          END IF
     104         1382 :          IF (ASSOCIATED(efield%dipmat)) THEN
     105          798 :             CALL dbcsr_deallocate_matrix_set(efield%dipmat)
     106              :          END IF
     107         1382 :          DEALLOCATE (efield)
     108              :       END IF
     109        15945 :    END SUBROUTINE efield_berry_release
     110              : 
     111            0 : END MODULE qs_period_efield_types
        

Generated by: LCOV version 2.0-1