LCOV - code coverage report
Current view: top level - src - csvr_system_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:936074a) Lines: 97.7 % 43 42
Test Date: 2025-12-04 06:27:48 Functions: 66.7 % 6 4

            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 the canonical sampling through velocity rescaling
      10              : !> \author Teodoro Laino - 09.2007 University of Zurich [tlaino]
      11              : ! **************************************************************************************************
      12              : MODULE csvr_system_types
      13              :    USE bibliography,                    ONLY: Bussi2007,&
      14              :                                               cite_reference
      15              :    USE extended_system_types,           ONLY: create_map_info_type,&
      16              :                                               map_info_type,&
      17              :                                               release_map_info_type
      18              :    USE input_section_types,             ONLY: section_vals_type,&
      19              :                                               section_vals_val_get
      20              :    USE kinds,                           ONLY: dp
      21              :    USE parallel_rng_types,              ONLY: GAUSSIAN,&
      22              :                                               next_rng_seed,&
      23              :                                               rng_stream_type
      24              :    USE simpar_types,                    ONLY: simpar_type
      25              :    USE string_utilities,                ONLY: compress
      26              : #include "./base/base_uses.f90"
      27              : 
      28              :    IMPLICIT NONE
      29              : 
      30              :    PRIVATE
      31              :    PUBLIC :: csvr_system_type, &
      32              :              csvr_init, &
      33              :              csvr_dealloc, &
      34              :              csvr_thermo_create
      35              : 
      36              : ! **************************************************************************************************
      37              :    TYPE csvr_thermo_type
      38              :       INTEGER                                 :: degrees_of_freedom = 0
      39              :       REAL(KIND=dp)                           :: nkt = 0.0_dp
      40              :       REAL(KIND=dp)                           :: thermostat_energy = 0.0_dp
      41              :       REAL(KIND=dp)                           :: region_kin_energy = 0.0_dp
      42              :       TYPE(rng_stream_type)                   :: gaussian_rng_stream = rng_stream_type()
      43              :    END TYPE csvr_thermo_type
      44              : 
      45              : ! **************************************************************************************************
      46              :    TYPE csvr_system_type
      47              :       INTEGER                                 :: region = 0, glob_num_csvr = 0, loc_num_csvr = 0
      48              :       REAL(KIND=dp)                           :: tau_csvr = 0.0_dp, dt_fact = 0.0_dp
      49              :       TYPE(csvr_thermo_type), POINTER         :: nvt(:) => NULL()
      50              :       TYPE(map_info_type), POINTER            :: map_info => NULL()
      51              :    END TYPE csvr_system_type
      52              : 
      53              : ! *** Global parameters ***
      54              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'csvr_system_types'
      55              : 
      56              : CONTAINS
      57              : 
      58              : ! **************************************************************************************************
      59              : !> \brief Initialize type for Canonical Sampling through Velocity Rescaling (CSVR)
      60              : !> \param csvr ...
      61              : !> \param simpar ...
      62              : !> \param section ...
      63              : !> \author Teodoro Laino [tlaino] 10.2007- University of Zurich
      64              : ! **************************************************************************************************
      65          162 :    SUBROUTINE csvr_init(csvr, simpar, section)
      66              :       TYPE(csvr_system_type), POINTER                    :: csvr
      67              :       TYPE(simpar_type), POINTER                         :: simpar
      68              :       TYPE(section_vals_type), POINTER                   :: section
      69              : 
      70          162 :       NULLIFY (csvr%nvt)
      71          162 :       NULLIFY (csvr%map_info)
      72          162 :       csvr%loc_num_csvr = 0
      73          162 :       csvr%glob_num_csvr = 0
      74          162 :       csvr%dt_fact = 1.0_dp
      75          162 :       CALL cite_reference(Bussi2007)
      76          162 :       CALL section_vals_val_get(section, "TIMECON", r_val=csvr%tau_csvr)
      77              :       ! The CSVR library expects the tau_csv to be in unit of integration timestep
      78              :       ! if applied once.. divided by two if the process is applied both to the first
      79              :       ! and the second verlet step
      80          162 :       csvr%tau_csvr = csvr%tau_csvr/(0.5_dp*simpar%dt)
      81          162 :       CALL create_map_info_type(csvr%map_info)
      82              : 
      83          162 :    END SUBROUTINE csvr_init
      84              : 
      85              : ! **************************************************************************************************
      86              : !> \brief Initialize NVT type for CSVR thermostat
      87              : !> \param csvr ...
      88              : !> \author Teodoro Laino [tlaino] 10.2007- University of Zurich
      89              : ! **************************************************************************************************
      90          162 :    SUBROUTINE csvr_thermo_create(csvr)
      91              :       TYPE(csvr_system_type), POINTER                    :: csvr
      92              : 
      93              :       CHARACTER(LEN=40)                                  :: name
      94              :       INTEGER                                            :: i, ithermo, my_index
      95          162 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: seed
      96              :       REAL(KIND=dp), DIMENSION(3, 2)                     :: initial_seed, my_seed
      97              : 
      98          162 :       CPASSERT(ASSOCIATED(csvr))
      99          162 :       CPASSERT(.NOT. ASSOCIATED(csvr%nvt))
     100              : 
     101         6706 :       ALLOCATE (csvr%nvt(csvr%loc_num_csvr))
     102         2170 :       DO i = 1, csvr%loc_num_csvr
     103         2170 :          csvr%nvt(i)%thermostat_energy = 0.0_dp
     104              :       END DO
     105              :       ! Initialize the gaussian stream random number
     106          486 :       ALLOCATE (seed(3, 2, csvr%glob_num_csvr))
     107          162 :       initial_seed = next_rng_seed()
     108              : 
     109         1458 :       seed(:, :, 1) = initial_seed
     110         3880 :       DO ithermo = 2, csvr%glob_num_csvr
     111         3880 :          seed(:, :, ithermo) = next_rng_seed(seed(:, :, ithermo - 1))
     112              :       END DO
     113              :       ! Update initial seed
     114          162 :       initial_seed = next_rng_seed(seed(:, :, csvr%glob_num_csvr))
     115         2170 :       DO ithermo = 1, csvr%loc_num_csvr
     116         2008 :          my_index = csvr%map_info%index(ithermo)
     117        18072 :          my_seed = seed(:, :, my_index)
     118         2008 :          WRITE (UNIT=name, FMT="(A,I8)") "Wiener process for Thermostat #", my_index
     119         2008 :          CALL compress(name)
     120              :          csvr%nvt(ithermo)%gaussian_rng_stream = rng_stream_type( &
     121         2170 :                                                  name=name, distribution_type=GAUSSIAN, extended_precision=.TRUE., seed=my_seed)
     122              :       END DO
     123          162 :       DEALLOCATE (seed)
     124              : 
     125          162 :    END SUBROUTINE csvr_thermo_create
     126              : 
     127              : ! **************************************************************************************************
     128              : !> \brief Deallocate type for CSVR thermostat
     129              : !> \param csvr ...
     130              : !> \author Teodoro Laino [tlaino] 10.2007- University of Zurich
     131              : ! **************************************************************************************************
     132          162 :    SUBROUTINE csvr_dealloc(csvr)
     133              :       TYPE(csvr_system_type), POINTER                    :: csvr
     134              : 
     135          162 :       IF (ASSOCIATED(csvr)) THEN
     136          162 :          CALL csvr_thermo_dealloc(csvr%nvt)
     137          162 :          CALL release_map_info_type(csvr%map_info)
     138          162 :          DEALLOCATE (csvr)
     139              :       END IF
     140              : 
     141          162 :    END SUBROUTINE csvr_dealloc
     142              : 
     143              : ! **************************************************************************************************
     144              : !> \brief Deallocate NVT type for CSVR thermostat
     145              : !> \param nvt ...
     146              : !> \author Teodoro Laino [tlaino] 10.2007- University of Zurich
     147              : ! **************************************************************************************************
     148          162 :    SUBROUTINE csvr_thermo_dealloc(nvt)
     149              :       TYPE(csvr_thermo_type), DIMENSION(:), POINTER      :: nvt
     150              : 
     151          162 :       IF (ASSOCIATED(nvt)) &
     152          162 :          DEALLOCATE (nvt)
     153          162 :    END SUBROUTINE csvr_thermo_dealloc
     154              : 
     155            0 : END MODULE csvr_system_types
     156              : 
        

Generated by: LCOV version 2.0-1