LCOV - code coverage report
Current view: top level - src/motion/thermostat - barostat_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 89.3 % 28 25
Test Date: 2026-11-24 01:22:08 Functions: 66.7 % 3 2

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Barostat structure: module containing barostat available for MD
      10              : !> \author teo [tlaino] - University of Zurich - 09.2007
      11              : ! **************************************************************************************************
      12              : MODULE barostat_types
      13              :    USE cell_types,                      ONLY: cell_type
      14              :    USE extended_system_init,            ONLY: initialize_npt
      15              :    USE extended_system_types,           ONLY: npt_info_type
      16              :    USE force_env_types,                 ONLY: force_env_get,&
      17              :                                               force_env_type
      18              :    USE global_types,                    ONLY: global_environment_type
      19              :    USE input_constants,                 ONLY: npe_f_ensemble,&
      20              :                                               npe_i_ensemble,&
      21              :                                               nph_uniaxial_damped_ensemble,&
      22              :                                               nph_uniaxial_ensemble,&
      23              :                                               npt_f_ensemble,&
      24              :                                               npt_i_ensemble,&
      25              :                                               npt_ia_ensemble
      26              :    USE input_section_types,             ONLY: section_vals_get,&
      27              :                                               section_vals_get_subs_vals,&
      28              :                                               section_vals_type,&
      29              :                                               section_vals_val_get
      30              :    USE kinds,                           ONLY: dp
      31              :    USE simpar_types,                    ONLY: simpar_type
      32              : #include "../../base/base_uses.f90"
      33              : 
      34              :    IMPLICIT NONE
      35              : 
      36              :    INTEGER, PARAMETER, PUBLIC               :: do_clv_geo_center = 0, &
      37              :                                                do_clv_fix_point = 1, &
      38              :                                                do_clv_xyz = 0, &
      39              :                                                do_clv_x = 1, &
      40              :                                                do_clv_y = 2, &
      41              :                                                do_clv_z = 3, &
      42              :                                                do_clv_xy = 4, &
      43              :                                                do_clv_xz = 5, &
      44              :                                                do_clv_yz = 6
      45              : 
      46              :    PRIVATE
      47              :    PUBLIC :: barostat_type, &
      48              :              create_barostat_type, &
      49              :              release_barostat_type
      50              : 
      51              : ! **************************************************************************************************
      52              :    TYPE barostat_type
      53              :       INTEGER                          :: virial_components = do_clv_geo_center
      54              :       REAL(KIND=dp)                    :: temp_ext = 0.0_dp
      55              :       TYPE(npt_info_type), POINTER  :: npt(:, :) => NULL()
      56              :       TYPE(section_vals_type), POINTER :: section => NULL()
      57              :    END TYPE barostat_type
      58              : 
      59              : ! *** Global parameters ***
      60              : 
      61              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'barostat_types'
      62              : 
      63              : CONTAINS
      64              : 
      65              : ! **************************************************************************************************
      66              : !> \brief ...
      67              : !> \param barostat ...
      68              : !> \param md_section ...
      69              : !> \param force_env ...
      70              : !> \param simpar ...
      71              : !> \param globenv ...
      72              : !> \par History
      73              : !>      09.2007 created [tlaino]
      74              : !> \author Teodoro Laino
      75              : ! **************************************************************************************************
      76         3586 :    SUBROUTINE create_barostat_type(barostat, md_section, force_env, simpar, &
      77              :                                    globenv)
      78              :       TYPE(barostat_type), POINTER                       :: barostat
      79              :       TYPE(section_vals_type), POINTER                   :: md_section
      80              :       TYPE(force_env_type), POINTER                      :: force_env
      81              :       TYPE(simpar_type), POINTER                         :: simpar
      82              :       TYPE(global_environment_type), POINTER             :: globenv
      83              : 
      84              :       LOGICAL                                            :: check, explicit
      85              :       TYPE(cell_type), POINTER                           :: cell
      86              :       TYPE(section_vals_type), POINTER                   :: barostat_section
      87              : 
      88         1793 :       check = .NOT. ASSOCIATED(barostat)
      89         1793 :       CPASSERT(check)
      90         1793 :       barostat_section => section_vals_get_subs_vals(md_section, "BAROSTAT")
      91         1793 :       CALL section_vals_get(barostat_section, explicit=explicit)
      92              :       IF (simpar%ensemble == npt_i_ensemble .OR. &
      93              :           simpar%ensemble == npt_ia_ensemble .OR. &
      94              :           simpar%ensemble == npt_f_ensemble .OR. &
      95              :           simpar%ensemble == npe_f_ensemble .OR. &
      96              :           simpar%ensemble == npe_i_ensemble .OR. &
      97         1793 :           simpar%ensemble == nph_uniaxial_ensemble .OR. &
      98              :           simpar%ensemble == nph_uniaxial_damped_ensemble) THEN
      99          178 :          ALLOCATE (barostat)
     100          178 :          barostat%section => barostat_section
     101              :          NULLIFY (barostat%npt)
     102          178 :          CALL force_env_get(force_env, cell=cell)
     103              : 
     104          178 :          barostat%temp_ext = simpar%temp_baro_ext
     105          178 :          CALL section_vals_val_get(barostat_section, "TEMP_TOL", r_val=simpar%temp_baro_tol)
     106              :          ! Initialize or possibly restart Barostat
     107              :          CALL initialize_npt(simpar, globenv, barostat%npt, &
     108          178 :                              cell, work_section=barostat_section)
     109              : 
     110              :          ! If none of the possible barostat has been allocated let's deallocate
     111              :          ! the full structure
     112          178 :          IF (.NOT. ASSOCIATED(barostat%npt)) THEN
     113            0 :             CALL release_barostat_type(barostat)
     114              :          END IF
     115              : 
     116              :          ! User defined virial screening
     117          178 :          CALL section_vals_val_get(barostat_section, "VIRIAL", i_val=barostat%virial_components)
     118          178 :          check = barostat%virial_components == do_clv_xyz .OR. simpar%ensemble == npt_f_ensemble
     119              :          IF (.NOT. check) THEN
     120              :             CALL cp_abort(__LOCATION__, "The screening of the components of "// &
     121            0 :                           "the virial is available only with the NPT_F ensemble!")
     122              :          END IF
     123              :       ELSE
     124         1615 :          IF (explicit) THEN
     125              :             CALL cp_warn(__LOCATION__, &
     126              :                          "A barostat has been defined with an MD ensemble which does not support barostat! "// &
     127            2 :                          "Its definition will be ignored!")
     128              :          END IF
     129              :       END IF
     130              : 
     131         1793 :    END SUBROUTINE create_barostat_type
     132              : 
     133              : ! **************************************************************************************************
     134              : !> \brief ...
     135              : !> \param barostat ...
     136              : !> \par History
     137              : !>      09.2007 created [tlaino]
     138              : !> \author Teodoro Laino
     139              : ! **************************************************************************************************
     140         1793 :    SUBROUTINE release_barostat_type(barostat)
     141              :       TYPE(barostat_type), POINTER                       :: barostat
     142              : 
     143         1793 :       IF (ASSOCIATED(barostat)) THEN
     144          178 :          IF (ASSOCIATED(barostat%npt)) THEN
     145          178 :             DEALLOCATE (barostat%npt)
     146              :          END IF
     147          178 :          NULLIFY (barostat%section)
     148          178 :          DEALLOCATE (barostat)
     149              :       END IF
     150              : 
     151         1793 :    END SUBROUTINE release_barostat_type
     152              : 
     153            0 : END MODULE barostat_types
        

Generated by: LCOV version 2.0-1