LCOV - code coverage report
Current view: top level - src/motion - cell_opt_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:cb5d5fc) Lines: 88.9 % 45 40
Test Date: 2026-04-24 07:01:27 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 Contains type used for a Simulation Cell Optimization
      10              : !> \par History
      11              : !>      none
      12              : !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
      13              : ! **************************************************************************************************
      14              : MODULE cell_opt_types
      15              : 
      16              :    USE cell_methods,                    ONLY: cell_create
      17              :    USE cell_opt_utils,                  ONLY: read_external_press_tensor
      18              :    USE cell_types,                      ONLY: cell_clone,&
      19              :                                               cell_release,&
      20              :                                               cell_type
      21              :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      22              :                                               cp_logger_type
      23              :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      24              :                                               cp_print_key_unit_nr
      25              :    USE cp_subsys_types,                 ONLY: cp_subsys_get,&
      26              :                                               cp_subsys_type
      27              :    USE cp_units,                        ONLY: cp_unit_from_cp2k
      28              :    USE force_env_types,                 ONLY: force_env_get,&
      29              :                                               force_env_type
      30              :    USE input_constants,                 ONLY: fix_none,&
      31              :                                               fix_x,&
      32              :                                               fix_xy,&
      33              :                                               fix_xz,&
      34              :                                               fix_y,&
      35              :                                               fix_yz,&
      36              :                                               fix_z
      37              :    USE input_section_types,             ONLY: section_vals_type,&
      38              :                                               section_vals_val_get
      39              :    USE kinds,                           ONLY: dp
      40              :    USE particle_list_types,             ONLY: particle_list_type
      41              : #include "../base/base_uses.f90"
      42              : 
      43              :    IMPLICIT NONE
      44              :    PRIVATE
      45              : 
      46              :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .FALSE.
      47              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cell_opt_types'
      48              : 
      49              :    PUBLIC :: cell_opt_env_type, &
      50              :              cell_opt_env_create, &
      51              :              cell_opt_env_release
      52              : 
      53              : ! **************************************************************************************************
      54              : !> \brief Type containing all informations abour the simulation cell optimization
      55              : !> \par History
      56              : !>      none
      57              : !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
      58              : ! **************************************************************************************************
      59              :    TYPE cell_opt_env_type
      60              :       ! Simulation cell optimization parameters
      61              :       INTEGER                                    :: constraint_id = fix_none
      62              :       LOGICAL                                    :: keep_angles = .FALSE., &
      63              :                                                     keep_symmetry = .FALSE., &
      64              :                                                     keep_volume = .FALSE.
      65              :       REAL(KIND=dp)                              :: pres_ext = 0.0_dp, pres_int = 0.0_dp, pres_tol = 0.0_dp, pres_constr = 0.0_dp
      66              :       REAL(KIND=dp), DIMENSION(3, 3)             :: mtrx = 0.0_dp
      67              :       REAL(KIND=dp), DIMENSION(3, 3)             :: rot_matrix = 0.0_dp
      68              :       TYPE(cell_type), POINTER                   :: ref_cell => NULL()
      69              :    END TYPE cell_opt_env_type
      70              : 
      71              : CONTAINS
      72              : 
      73              : ! **************************************************************************************************
      74              : !> \brief ...
      75              : !> \param cell_env ...
      76              : !> \param force_env ...
      77              : !> \param geo_section ...
      78              : !> \par History
      79              : !>      none
      80              : !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
      81              : ! **************************************************************************************************
      82         5824 :    SUBROUTINE cell_opt_env_create(cell_env, force_env, geo_section)
      83              :       TYPE(cell_opt_env_type), INTENT(OUT)               :: cell_env
      84              :       TYPE(force_env_type), POINTER                      :: force_env
      85              :       TYPE(section_vals_type), POINTER                   :: geo_section
      86              : 
      87              :       CHARACTER(LEN=4)                                   :: label
      88              :       INTEGER                                            :: ip, output_unit
      89              :       REAL(KIND=dp), DIMENSION(3)                        :: r
      90              :       TYPE(cell_type), POINTER                           :: cell
      91              :       TYPE(cp_logger_type), POINTER                      :: logger
      92              :       TYPE(cp_subsys_type), POINTER                      :: subsys
      93              :       TYPE(particle_list_type), POINTER                  :: particles
      94              : 
      95          224 :       NULLIFY (cell_env%ref_cell, cell, subsys, particles)
      96          224 :       CALL force_env_get(force_env, cell=cell, subsys=subsys)
      97          224 :       CALL cell_create(cell_env%ref_cell)
      98          224 :       CALL cell_clone(cell, cell_env%ref_cell, tag="REF_CELL_OPT")
      99          224 :       CALL section_vals_val_get(geo_section, "KEEP_VOLUME", l_val=cell_env%keep_volume)
     100          224 :       CALL section_vals_val_get(geo_section, "KEEP_ANGLES", l_val=cell_env%keep_angles)
     101          224 :       CALL section_vals_val_get(geo_section, "KEEP_SYMMETRY", l_val=cell_env%keep_symmetry)
     102          224 :       CALL section_vals_val_get(geo_section, "PRESSURE_TOLERANCE", r_val=cell_env%pres_tol)
     103          224 :       CALL section_vals_val_get(geo_section, "CONSTRAINT", i_val=cell_env%constraint_id)
     104              : 
     105              :       ! Compute the rotation matrix that give the cell vectors in the "canonical" orientation
     106        11872 :       cell_env%rot_matrix = MATMUL(cell_env%ref_cell%hmat, cell%h_inv)
     107              : 
     108              :       ! Get the external pressure
     109              :       CALL read_external_press_tensor(geo_section, cell, cell_env%pres_ext, cell_env%mtrx, &
     110          224 :                                       cell_env%rot_matrix)
     111              : 
     112              :       ! Rotate particles accordingly
     113          224 :       CALL cp_subsys_get(subsys, particles=particles)
     114        18372 :       DO ip = 1, particles%n_els
     115        18148 :          r = MATMUL(TRANSPOSE(cell_env%rot_matrix), particles%els(ip)%r)
     116        72816 :          particles%els(ip)%r = r
     117              :       END DO
     118              : 
     119              :       ! Print cell optimisation setup
     120          224 :       NULLIFY (logger)
     121          224 :       logger => cp_get_default_logger()
     122          224 :       output_unit = cp_print_key_unit_nr(logger, geo_section, "PRINT%CELL", extension=".Log")
     123          224 :       IF (output_unit > 0) THEN
     124              :          WRITE (UNIT=output_unit, FMT="(/,T2,A,T61,F20.1)") &
     125          112 :             "CELL_OPT| Pressure tolerance [bar]: ", cp_unit_from_cp2k(cell_env%pres_tol, "bar")
     126          112 :          IF (cell_env%keep_volume) THEN
     127              :             WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
     128            3 :                "CELL_OPT| Keep volume of cell: ", "YES"
     129              :          ELSE
     130              :             WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
     131          109 :                "CELL_OPT| Keep volume of cell: ", " NO"
     132              :          END IF
     133          112 :          IF (cell_env%keep_angles) THEN
     134              :             WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
     135           15 :                "CELL_OPT| Keep angles between the cell vectors: ", "YES"
     136              :          ELSE
     137              :             WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
     138           97 :                "CELL_OPT| Keep angles between the cell vectors: ", " NO"
     139              :          END IF
     140          112 :          IF (cell_env%keep_symmetry) THEN
     141              :             WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
     142           21 :                "CELL_OPT| Keep cell symmetry: ", "YES"
     143              :          ELSE
     144              :             WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
     145           91 :                "CELL_OPT| Keep cell symmetry: ", " NO"
     146              :          END IF
     147          112 :          SELECT CASE (cell_env%constraint_id)
     148              :          CASE (fix_x)
     149            0 :             label = "   X"
     150              :          CASE (fix_y)
     151            0 :             label = "   Y"
     152              :          CASE (fix_z)
     153            1 :             label = "   Z"
     154              :          CASE (fix_xy)
     155            1 :             label = "  XY"
     156              :          CASE (fix_xz)
     157            0 :             label = "  XZ"
     158              :          CASE (fix_yz)
     159            0 :             label = "  YZ"
     160              :          CASE (fix_none)
     161          112 :             label = "NONE"
     162              :          END SELECT
     163              :          WRITE (UNIT=output_unit, FMT="(T2,A,T77,A4)") &
     164          112 :             "CELL_OPT| Constraint: ", label
     165              :       END IF
     166          224 :       CALL cp_print_key_finished_output(output_unit, logger, geo_section, "PRINT%CELL")
     167              : 
     168          224 :    END SUBROUTINE cell_opt_env_create
     169              : 
     170              : ! **************************************************************************************************
     171              : !> \brief ...
     172              : !> \param cell_env ...
     173              : !> \par History
     174              : !>      none
     175              : !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
     176              : ! **************************************************************************************************
     177          224 :    SUBROUTINE cell_opt_env_release(cell_env)
     178              :       TYPE(cell_opt_env_type), INTENT(INOUT)             :: cell_env
     179              : 
     180          224 :       CALL cell_release(cell_env%ref_cell)
     181              : 
     182          224 :    END SUBROUTINE cell_opt_env_release
     183              : 
     184            0 : END MODULE cell_opt_types
        

Generated by: LCOV version 2.0-1