LCOV - code coverage report
Current view: top level - src/pw_env - pw_env_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:d0bd076) Lines: 55 59 93.2 %
Date: 2021-09-15 13:52:28 Functions: 3 4 75.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2021 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief container for various plainwaves related things
      10             : !> \par History
      11             : !>      10.2002 created [fawzi]
      12             : !> \author Fawzi Mohamed
      13             : ! **************************************************************************************************
      14             : MODULE pw_env_types
      15             :    USE cube_utils,                      ONLY: cube_info_type,&
      16             :                                               destroy_cube_info
      17             :    USE gaussian_gridlevels,             ONLY: destroy_gaussian_gridlevel,&
      18             :                                               gridlevel_info_type
      19             :    USE input_section_types,             ONLY: section_vals_release,&
      20             :                                               section_vals_type
      21             :    USE kinds,                           ONLY: dp
      22             :    USE pw_poisson_types,                ONLY: pw_poisson_release,&
      23             :                                               pw_poisson_type
      24             :    USE pw_pool_types,                   ONLY: pw_pool_p_type,&
      25             :                                               pw_pool_release,&
      26             :                                               pw_pool_type,&
      27             :                                               pw_pools_dealloc
      28             :    USE realspace_grid_types,            ONLY: realspace_grid_desc_p_type,&
      29             :                                               realspace_grid_desc_type,&
      30             :                                               realspace_grid_p_type,&
      31             :                                               realspace_grid_type,&
      32             :                                               rs_grid_release,&
      33             :                                               rs_grid_release_descriptor
      34             : #include "../base/base_uses.f90"
      35             : 
      36             :    IMPLICIT NONE
      37             :    PRIVATE
      38             : 
      39             :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      40             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pw_env_types'
      41             : 
      42             :    PUBLIC :: pw_env_type
      43             :    PUBLIC :: pw_env_retain, pw_env_release, pw_env_get
      44             : 
      45             : !***
      46             : 
      47             : ! **************************************************************************************************
      48             : !> \brief contained for different pw related things
      49             : !> \param pw_pools pools for multigrids
      50             : !> \param rs_descs descriptors for the realspace grids
      51             : !> \param rs_grids the realspace grids
      52             : !> \param xc_pw_pool the pool used for xc calculation on grid (might be the
      53             : !>        same as the finest, or finer still).
      54             : !> \param vdw_pw_pool the pool used for vdw-nl calculation on grid (might be the
      55             : !>        same or a grid with a new cutoff
      56             : !> \param gridlevel_info gaussian gridlevel info
      57             : !> \param cube_info info on cube and max sphere size for multigrids
      58             : !> \param aux_bas which multigrid is the auxiliar basis
      59             : !>
      60             : !>      readonly attributes
      61             : !> \param auxbas_pw_pool a pool that allocates grids in the auxiliary basis
      62             : !> \param auxbas_rs_desc real space grid in the auxiliary basis, be careful
      63             : !>        in parallel nsmax is chosen with multigrid in mind!
      64             : !> \note
      65             : !>      be careful in parallel nsmax for the rs_grids is chosen with
      66             : !>      multigrid in mind! (well not as of this writing but...)
      67             : !> \par History
      68             : !>      10.2002 created [fawzi]
      69             : !>      04.2003 added rs grid pools [fawzi]
      70             : !> \author Fawzi Mohamed
      71             : ! **************************************************************************************************
      72             :    TYPE pw_env_type
      73             :       INTEGER                                     :: ref_count
      74             :       INTEGER                                     :: auxbas_grid
      75             :       TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
      76             :       TYPE(pw_pool_type), POINTER                 :: xc_pw_pool
      77             :       TYPE(pw_pool_type), POINTER                 :: vdw_pw_pool
      78             :       TYPE(realspace_grid_desc_p_type), &
      79             :          DIMENSION(:), POINTER                    :: rs_descs
      80             :       TYPE(realspace_grid_p_type), &
      81             :          DIMENSION(:), POINTER                    :: rs_grids
      82             :       TYPE(gridlevel_info_type), POINTER          :: gridlevel_info
      83             :       TYPE(cube_info_type), DIMENSION(:), POINTER :: cube_info
      84             :       TYPE(pw_poisson_type), POINTER              :: poisson_env
      85             :       TYPE(section_vals_type), POINTER            :: interp_section
      86             :       ! store current cell, used to rebuild lazily.
      87             :       REAL(KIND=dp), DIMENSION(3, 3)          :: cell_hmat = -1.0_dp
      88             :    END TYPE pw_env_type
      89             : 
      90             : CONTAINS
      91             : 
      92             : ! **************************************************************************************************
      93             : !> \brief returns the various attributes of the pw env
      94             : !> \param pw_env the einvironment you want info about
      95             : !> \param pw_pools ...
      96             : !> \param cube_info ...
      97             : !> \param gridlevel_info ...
      98             : !> \param auxbas_pw_pool ...
      99             : !> \param auxbas_grid ...
     100             : !> \param auxbas_rs_desc ...
     101             : !> \param auxbas_rs_grid ...
     102             : !> \param rs_descs ...
     103             : !> \param rs_grids ...
     104             : !> \param xc_pw_pool ...
     105             : !> \param vdw_pw_pool ...
     106             : !> \param poisson_env ...
     107             : !> \param interp_section ...
     108             : !> \par History
     109             : !>      10.2002 created [fawzi]
     110             : !> \author Fawzi Mohamed
     111             : ! **************************************************************************************************
     112      722041 :    SUBROUTINE pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, &
     113             :                          auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, &
     114             :                          xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
     115             :       TYPE(pw_env_type), POINTER                         :: pw_env
     116             :       TYPE(pw_pool_p_type), DIMENSION(:), OPTIONAL, &
     117             :          POINTER                                         :: pw_pools
     118             :       TYPE(cube_info_type), DIMENSION(:), OPTIONAL, &
     119             :          POINTER                                         :: cube_info
     120             :       TYPE(gridlevel_info_type), OPTIONAL, POINTER       :: gridlevel_info
     121             :       TYPE(pw_pool_type), OPTIONAL, POINTER              :: auxbas_pw_pool
     122             :       INTEGER, INTENT(out), OPTIONAL                     :: auxbas_grid
     123             :       TYPE(realspace_grid_desc_type), OPTIONAL, POINTER  :: auxbas_rs_desc
     124             :       TYPE(realspace_grid_type), OPTIONAL, POINTER       :: auxbas_rs_grid
     125             :       TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
     126             :          OPTIONAL, POINTER                               :: rs_descs
     127             :       TYPE(realspace_grid_p_type), DIMENSION(:), &
     128             :          OPTIONAL, POINTER                               :: rs_grids
     129             :       TYPE(pw_pool_type), OPTIONAL, POINTER              :: xc_pw_pool, vdw_pw_pool
     130             :       TYPE(pw_poisson_type), OPTIONAL, POINTER           :: poisson_env
     131             :       TYPE(section_vals_type), OPTIONAL, POINTER         :: interp_section
     132             : 
     133      722041 :       CPASSERT(ASSOCIATED(pw_env))
     134      722041 :       CPASSERT(pw_env%ref_count > 0)
     135      722041 :       IF (PRESENT(pw_pools)) pw_pools => pw_env%pw_pools
     136      722041 :       IF (PRESENT(rs_descs)) rs_descs => pw_env%rs_descs
     137      722041 :       IF (PRESENT(rs_grids)) rs_grids => pw_env%rs_grids
     138      722041 :       IF (PRESENT(cube_info)) cube_info => pw_env%cube_info
     139      722041 :       IF (PRESENT(gridlevel_info)) gridlevel_info => pw_env%gridlevel_info
     140      722041 :       IF (PRESENT(auxbas_pw_pool)) THEN
     141      285388 :          auxbas_pw_pool => pw_env%pw_pools(pw_env%auxbas_grid)%pool
     142             :       END IF
     143      722041 :       IF (PRESENT(auxbas_rs_desc)) THEN
     144        9272 :          auxbas_rs_desc => pw_env%rs_descs(pw_env%auxbas_grid)%rs_desc
     145             :       END IF
     146      722041 :       IF (PRESENT(auxbas_rs_grid)) THEN
     147       20431 :          auxbas_rs_grid => pw_env%rs_grids(pw_env%auxbas_grid)%rs_grid
     148             :       END IF
     149      722041 :       IF (PRESENT(auxbas_grid)) auxbas_grid = pw_env%auxbas_grid
     150      722041 :       IF (PRESENT(xc_pw_pool)) xc_pw_pool => pw_env%xc_pw_pool
     151      722041 :       IF (PRESENT(vdw_pw_pool)) vdw_pw_pool => pw_env%vdw_pw_pool
     152      722041 :       IF (PRESENT(poisson_env)) poisson_env => pw_env%poisson_env
     153      722041 :       IF (PRESENT(interp_section)) interp_section => pw_env%interp_section
     154      722041 :    END SUBROUTINE pw_env_get
     155             : 
     156             : ! **************************************************************************************************
     157             : !> \brief retains the pw_env (see doc/ReferenceCounting.html)
     158             : !> \param pw_env the pw_env to retain
     159             : !> \par History
     160             : !>      10.2002 created [fawzi]
     161             : !> \author Fawzi Mohamed
     162             : ! **************************************************************************************************
     163        5570 :    SUBROUTINE pw_env_retain(pw_env)
     164             :       TYPE(pw_env_type), POINTER                         :: pw_env
     165             : 
     166        5570 :       CPASSERT(ASSOCIATED(pw_env))
     167        5570 :       CPASSERT(pw_env%ref_count > 0)
     168        5570 :       pw_env%ref_count = pw_env%ref_count + 1
     169        5570 :    END SUBROUTINE pw_env_retain
     170             : 
     171             : ! **************************************************************************************************
     172             : !> \brief releases the given pw_env (see doc/ReferenceCounting.html)
     173             : !> \param pw_env the pw_env to release
     174             : !> \param kg ...
     175             : !> \par History
     176             : !>      10.2002 created [fawzi]
     177             : !> \author Fawzi Mohamed
     178             : ! **************************************************************************************************
     179       16294 :    SUBROUTINE pw_env_release(pw_env, kg)
     180             :       TYPE(pw_env_type), POINTER                         :: pw_env
     181             :       LOGICAL, OPTIONAL                                  :: kg
     182             : 
     183             :       INTEGER                                            :: i, igrid_level
     184             :       LOGICAL                                            :: my_kg
     185             : 
     186       16294 :       my_kg = .FALSE.
     187       16294 :       IF (PRESENT(kg)) my_kg = kg
     188       16294 :       IF (ASSOCIATED(pw_env)) THEN
     189       11064 :          CPASSERT(pw_env%ref_count > 0)
     190       11064 :          pw_env%ref_count = pw_env%ref_count - 1
     191       11064 :          IF (pw_env%ref_count < 1) THEN
     192        5494 :             CALL pw_poisson_release(pw_env%poisson_env)
     193        5494 :             CALL pw_pools_dealloc(pw_env%pw_pools)
     194        5494 :             IF (ASSOCIATED(pw_env%gridlevel_info)) THEN
     195        5494 :                IF (my_kg) THEN
     196           0 :                   DEALLOCATE (pw_env%gridlevel_info%cutoff)
     197           0 :                   CALL section_vals_release(pw_env%gridlevel_info%print_section)
     198           0 :                   DEALLOCATE (pw_env%gridlevel_info%count)
     199             :                ELSE
     200        5494 :                   CALL destroy_gaussian_gridlevel(pw_env%gridlevel_info)
     201             :                END IF
     202        5494 :                DEALLOCATE (pw_env%gridlevel_info)
     203             :             END IF
     204        5494 :             IF (ASSOCIATED(pw_env%cube_info)) THEN
     205       23070 :                DO igrid_level = 1, SIZE(pw_env%cube_info)
     206       23070 :                   CALL destroy_cube_info(pw_env%cube_info(igrid_level))
     207             :                END DO
     208        5494 :                DEALLOCATE (pw_env%cube_info)
     209             :             END IF
     210        5494 :             CALL pw_pool_release(pw_env%xc_pw_pool)
     211        5494 :             CALL pw_pool_release(pw_env%vdw_pw_pool)
     212        5494 :             IF (ASSOCIATED(pw_env%rs_descs)) THEN
     213       23070 :                DO i = 1, SIZE(pw_env%rs_descs)
     214       23070 :                   CALL rs_grid_release_descriptor(pw_env%rs_descs(i)%rs_desc)
     215             :                END DO
     216        5494 :                DEALLOCATE (pw_env%rs_descs)
     217             :             END IF
     218        5494 :             IF (ASSOCIATED(pw_env%rs_grids)) THEN
     219       23070 :                DO i = 1, SIZE(pw_env%rs_grids)
     220       23070 :                   CALL rs_grid_release(pw_env%rs_grids(i)%rs_grid)
     221             :                END DO
     222        5494 :                DEALLOCATE (pw_env%rs_grids)
     223             :             END IF
     224        5494 :             DEALLOCATE (pw_env)
     225             :          END IF
     226             :       END IF
     227       16294 :       NULLIFY (pw_env)
     228       16294 :    END SUBROUTINE pw_env_release
     229             : 
     230           0 : END MODULE pw_env_types

Generated by: LCOV version 1.15