LCOV - code coverage report
Current view: top level - src - ipi_environment_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 0 77 0.0 %
Date: 2024-11-21 06:45:46 Functions: 0 6 0.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief The environment for the empirical interatomic potential methods.
      10             : !> \par History
      11             : !>      03.2024 initial create
      12             : !> \author Sebastian Seidenath (sebastian.seidenath@uni-jena.de)
      13             : ! **************************************************************************************************
      14             : MODULE ipi_environment_types
      15             :    USE atomic_kind_list_types,          ONLY: atomic_kind_list_create,&
      16             :                                               atomic_kind_list_release,&
      17             :                                               atomic_kind_list_type
      18             :    USE atomic_kind_types,               ONLY: atomic_kind_type
      19             :    USE cell_types,                      ONLY: cell_release,&
      20             :                                               cell_retain,&
      21             :                                               cell_type
      22             :    USE cp_subsys_types,                 ONLY: cp_subsys_get,&
      23             :                                               cp_subsys_release,&
      24             :                                               cp_subsys_set,&
      25             :                                               cp_subsys_type
      26             :    USE distribution_1d_types,           ONLY: distribution_1d_type
      27             :    USE input_section_types,             ONLY: section_vals_release,&
      28             :                                               section_vals_retain,&
      29             :                                               section_vals_type
      30             :    USE kinds,                           ONLY: dp
      31             :    USE molecule_kind_list_types,        ONLY: molecule_kind_list_create,&
      32             :                                               molecule_kind_list_release,&
      33             :                                               molecule_kind_list_type
      34             :    USE molecule_kind_types,             ONLY: molecule_kind_type
      35             :    USE molecule_list_types,             ONLY: molecule_list_create,&
      36             :                                               molecule_list_release,&
      37             :                                               molecule_list_type
      38             :    USE molecule_types,                  ONLY: molecule_type
      39             :    USE particle_list_types,             ONLY: particle_list_create,&
      40             :                                               particle_list_release,&
      41             :                                               particle_list_type
      42             :    USE particle_types,                  ONLY: particle_type
      43             :    USE virial_types,                    ONLY: virial_type
      44             : #include "./base/base_uses.f90"
      45             : 
      46             :    IMPLICIT NONE
      47             :    PRIVATE
      48             : 
      49             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ipi_environment_types'
      50             : 
      51             :    ! *** Public data types ***
      52             :    PUBLIC :: ipi_environment_type
      53             : 
      54             :    ! *** Public subroutines ***
      55             :    PUBLIC :: ipi_env_release, &
      56             :              ipi_env_set, &
      57             :              ipi_env_get, &
      58             :              ipi_env_create
      59             : 
      60             : ! **************************************************************************************************
      61             : !> \brief The i–PI environment
      62             : !> \param ipi_energy The total ipi energy
      63             : !> \param ipi_forces The final ipi forces [eV/A]
      64             : !> \param subsystem The particles, molecules,... of this environment
      65             : !> \param force_env_input Pointer to the force_env input section
      66             : !> \param cell_ref The reference simulation cell
      67             : !> \par History
      68             : !>      03.2024 initial create
      69             : !> \author Sebastian Seidenath (sebastian.seidenath@uni-jena.de)
      70             : ! **************************************************************************************************
      71             :    TYPE ipi_environment_type
      72             :       REAL(KIND=dp)                                    :: ipi_energy = 0.0_dp
      73             :       REAL(KIND=dp), DIMENSION(:, :), POINTER          :: ipi_forces => Null()
      74             :       TYPE(cp_subsys_type), POINTER                    :: subsys => Null()
      75             :       TYPE(section_vals_type), POINTER                 :: force_env_input => Null()
      76             :       TYPE(cell_type), POINTER                         :: cell_ref => Null()
      77             :       INTEGER                                          :: sockfd = -1
      78             :    END TYPE ipi_environment_type
      79             : 
      80             : CONTAINS
      81             : 
      82             : ! **************************************************************************************************
      83             : !> \brief Releases the given ipi environment (see doc/ReferenceCounting.html)
      84             : !> \param ipi_env The ipi environment to release
      85             : !> \par History
      86             : !>      03.2024 initial create
      87             : !> \author Sebastian Seidenath (sebastian.seidenath@uni-jena.de)
      88             : ! **************************************************************************************************
      89           0 :    SUBROUTINE ipi_env_release(ipi_env)
      90             :       TYPE(ipi_environment_type), INTENT(INOUT)          :: ipi_env
      91             : 
      92           0 :       IF (ASSOCIATED(ipi_env%ipi_forces)) THEN
      93           0 :          DEALLOCATE (ipi_env%ipi_forces)
      94             :       END IF
      95           0 :       IF (ASSOCIATED(ipi_env%subsys)) THEN
      96           0 :          CALL cp_subsys_release(ipi_env%subsys)
      97             :       END IF
      98           0 :       IF (ASSOCIATED(ipi_env%force_env_input)) THEN
      99           0 :          CALL section_vals_release(ipi_env%force_env_input)
     100             :       END IF
     101           0 :       IF (ASSOCIATED(ipi_env%cell_ref)) THEN
     102           0 :          CALL cell_release(ipi_env%cell_ref)
     103             :       END IF
     104           0 :    END SUBROUTINE ipi_env_release
     105             : 
     106             : ! **************************************************************************************************
     107             : !> \brief Returns various attributes of the ipi environment
     108             : !> \param ipi_env The enquired ipi environment
     109             : !> \param ipi_energy The total ipi energy
     110             : !> \param ipi_forces The final ipi forces [eV/A]
     111             : !> \param subsys the particles, molecules,... of this environment
     112             : !> \param atomic_kind_set The set of all atomic kinds involved
     113             : !> \param particle_set The set of all particles
     114             : !> \param local_particles All particles on this particular node
     115             : !> \param molecule_kind_set The set of all different molecule kinds involved
     116             : !> \param molecule_set The set of all molecules
     117             : !> \param local_molecules All molecules on this particular node
     118             : !> \param force_env_input Pointer to the force_env input section
     119             : !> \param cell The simulation cell
     120             : !> \param cell_ref The reference simulation cell
     121             : !> \param virial Dummy virial pointer
     122             : !> \param sockfd File descriptor of the communications socket
     123             : !> \par History
     124             : !>      03.2024 initial create
     125             : !> \author Sebastian Seidenath (sebastian.seidenath@uni-jena.de)
     126             : ! **************************************************************************************************
     127           0 :    SUBROUTINE ipi_env_get(ipi_env, ipi_energy, ipi_forces, subsys, &
     128             :                           atomic_kind_set, particle_set, local_particles, &
     129             :                           molecule_kind_set, molecule_set, local_molecules, &
     130             :                           force_env_input, cell, cell_ref, virial, sockfd)
     131             : 
     132             :       TYPE(ipi_environment_type), INTENT(IN)             :: ipi_env
     133             :       REAL(kind=dp), OPTIONAL                            :: ipi_energy
     134             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: ipi_forces
     135             :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: subsys
     136             :       TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
     137             :          POINTER                                         :: atomic_kind_set
     138             :       TYPE(particle_type), DIMENSION(:), OPTIONAL, &
     139             :          POINTER                                         :: particle_set
     140             :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_particles
     141             :       TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
     142             :          POINTER                                         :: molecule_kind_set
     143             :       TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
     144             :          POINTER                                         :: molecule_set
     145             :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_molecules
     146             :       TYPE(section_vals_type), OPTIONAL, POINTER         :: force_env_input
     147             :       TYPE(cell_type), OPTIONAL, POINTER                 :: cell, cell_ref
     148             :       TYPE(virial_type), OPTIONAL, POINTER               :: virial
     149             :       INTEGER, OPTIONAL                                  :: sockfd
     150             : 
     151             :       TYPE(atomic_kind_list_type), POINTER               :: atomic_kinds
     152             :       TYPE(molecule_kind_list_type), POINTER             :: molecule_kinds
     153             :       TYPE(molecule_list_type), POINTER                  :: molecules
     154             :       TYPE(particle_list_type), POINTER                  :: particles
     155             : 
     156           0 :       NULLIFY (atomic_kinds, particles, molecules, molecule_kinds)
     157             : 
     158           0 :       IF (PRESENT(ipi_energy)) ipi_energy = ipi_env%ipi_energy
     159           0 :       IF (PRESENT(ipi_forces)) ipi_forces = ipi_env%ipi_forces
     160           0 :       IF (PRESENT(subsys)) subsys => ipi_env%subsys
     161             :       CALL cp_subsys_get(ipi_env%subsys, &
     162             :                          atomic_kinds=atomic_kinds, &
     163             :                          particles=particles, &
     164             :                          molecule_kinds=molecule_kinds, &
     165             :                          molecules=molecules, &
     166             :                          local_molecules=local_molecules, &
     167             :                          local_particles=local_particles, &
     168             :                          virial=virial, &
     169           0 :                          cell=cell)
     170           0 :       IF (PRESENT(atomic_kind_set)) atomic_kind_set => atomic_kinds%els
     171           0 :       IF (PRESENT(particle_set)) particle_set => particles%els
     172           0 :       IF (PRESENT(molecule_kind_set)) molecule_kind_set => molecule_kinds%els
     173           0 :       IF (PRESENT(molecule_set)) molecule_set => molecules%els
     174             : 
     175           0 :       IF (PRESENT(force_env_input)) force_env_input => ipi_env%force_env_input
     176           0 :       IF (PRESENT(cell_ref)) cell_ref => ipi_env%cell_ref
     177           0 :       IF (PRESENT(sockfd)) sockfd = ipi_env%sockfd
     178             : 
     179           0 :    END SUBROUTINE ipi_env_get
     180             : 
     181             : ! **************************************************************************************************
     182             : !> \brief Sets various attributes of the ipi environment
     183             : !> \param ipi_env The enquired ipi environment
     184             : !> \param ipi_energy The total ipi energy
     185             : !> \param ipi_forces The final ipi forces [eV/A]
     186             : !> \param subsys the particles, molecules,... of this environment
     187             : !> \param atomic_kind_set The set of all atomic kinds involved
     188             : !> \param particle_set The set of all particles
     189             : !> \param local_particles All particles on this particular node
     190             : !> \param molecule_kind_set The set of all different molecule kinds involved
     191             : !> \param molecule_set The set of all molecules
     192             : !> \param local_molecules All molecules on this particular node
     193             : !> \param force_env_input Pointer to the force_env input section
     194             : !> \param cell_ref The reference simulation cell
     195             : !> \param sockfd File descriptor of the communications socket
     196             : !> \par History
     197             : !>      03.2024 initial create
     198             : !> \author Sebastian Seidenath (sebastian.seidenath@uni-jena.de)
     199             : ! **************************************************************************************************
     200           0 :    SUBROUTINE ipi_env_set(ipi_env, ipi_energy, ipi_forces, subsys, &
     201             :                           atomic_kind_set, particle_set, local_particles, &
     202             :                           molecule_kind_set, molecule_set, local_molecules, &
     203             :                           force_env_input, cell_ref, sockfd)
     204             : 
     205             :       TYPE(ipi_environment_type), INTENT(INOUT)          :: ipi_env
     206             :       REAL(KIND=dp), OPTIONAL                            :: ipi_energy
     207             :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: ipi_forces
     208             :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: subsys
     209             :       TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
     210             :          POINTER                                         :: atomic_kind_set
     211             :       TYPE(particle_type), DIMENSION(:), OPTIONAL, &
     212             :          POINTER                                         :: particle_set
     213             :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_particles
     214             :       TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
     215             :          POINTER                                         :: molecule_kind_set
     216             :       TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
     217             :          POINTER                                         :: molecule_set
     218             :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_molecules
     219             :       TYPE(section_vals_type), OPTIONAL, POINTER         :: force_env_input
     220             :       TYPE(cell_type), OPTIONAL, POINTER                 :: cell_ref
     221             :       INTEGER, OPTIONAL                                  :: sockfd
     222             : 
     223             :       TYPE(atomic_kind_list_type), POINTER               :: atomic_kinds
     224             :       TYPE(molecule_kind_list_type), POINTER             :: molecule_kinds
     225             :       TYPE(molecule_list_type), POINTER                  :: molecules
     226             :       TYPE(particle_list_type), POINTER                  :: particles
     227             : 
     228           0 :       IF (PRESENT(ipi_energy)) ipi_env%ipi_energy = ipi_energy
     229           0 :       IF (PRESENT(ipi_forces)) ipi_env%ipi_forces = ipi_forces
     230           0 :       IF (PRESENT(subsys)) THEN
     231           0 :          IF (ASSOCIATED(ipi_env%subsys)) THEN
     232           0 :             IF (.NOT. ASSOCIATED(ipi_env%subsys, subsys)) THEN
     233           0 :                CALL cp_subsys_release(ipi_env%subsys)
     234             :             END IF
     235             :          END IF
     236           0 :          ipi_env%subsys => subsys
     237             :       END IF
     238           0 :       IF (PRESENT(atomic_kind_set)) THEN
     239           0 :          CALL atomic_kind_list_create(atomic_kinds, els_ptr=atomic_kind_set)
     240           0 :          CALL cp_subsys_set(ipi_env%subsys, atomic_kinds=atomic_kinds)
     241           0 :          CALL atomic_kind_list_release(atomic_kinds)
     242             :       END IF
     243           0 :       IF (PRESENT(particle_set)) THEN
     244           0 :          CALL particle_list_create(particles, els_ptr=particle_set)
     245           0 :          CALL cp_subsys_set(ipi_env%subsys, particles=particles)
     246           0 :          CALL particle_list_release(particles)
     247             :       END IF
     248           0 :       IF (PRESENT(molecule_kind_set)) THEN
     249           0 :          CALL molecule_kind_list_create(molecule_kinds, els_ptr=molecule_kind_set)
     250           0 :          CALL cp_subsys_set(ipi_env%subsys, molecule_kinds=molecule_kinds)
     251           0 :          CALL molecule_kind_list_release(molecule_kinds)
     252             :       END IF
     253           0 :       IF (PRESENT(molecule_set)) THEN
     254           0 :          CALL molecule_list_create(molecules, els_ptr=molecule_set)
     255           0 :          CALL cp_subsys_set(ipi_env%subsys, molecules=molecules)
     256           0 :          CALL molecule_list_release(molecules)
     257             :       END IF
     258           0 :       IF (PRESENT(local_particles)) THEN
     259           0 :          CALL cp_subsys_set(ipi_env%subsys, local_particles=local_particles)
     260             :       END IF
     261           0 :       IF (PRESENT(local_molecules)) THEN
     262           0 :          CALL cp_subsys_set(ipi_env%subsys, local_molecules=local_molecules)
     263             :       END IF
     264             : 
     265           0 :       IF (PRESENT(force_env_input)) THEN
     266           0 :          CALL section_vals_retain(force_env_input)
     267           0 :          CALL section_vals_release(ipi_env%force_env_input)
     268           0 :          ipi_env%force_env_input => force_env_input
     269             :       END IF
     270           0 :       IF (PRESENT(cell_ref)) THEN
     271           0 :          CALL cell_retain(cell_ref)
     272           0 :          CALL cell_release(ipi_env%cell_ref)
     273           0 :          ipi_env%cell_ref => cell_ref
     274             :       END IF
     275           0 :       IF (PRESENT(sockfd)) ipi_env%sockfd = sockfd
     276           0 :    END SUBROUTINE ipi_env_set
     277             : 
     278             : ! **************************************************************************************************
     279             : !> \brief Reinitializes the ipi environment
     280             : !> \param ipi_env The ipi environment to be reinitialized
     281             : !> \par History
     282             : !>      03.2024 initial create
     283             : !> \author Sebastian Seidenath (sebastian.seidenath@uni-jena.de)
     284             : ! **************************************************************************************************
     285           0 :    SUBROUTINE ipi_env_clear(ipi_env)
     286             : 
     287             :       TYPE(ipi_environment_type), INTENT(INOUT)          :: ipi_env
     288             : 
     289           0 :       IF (ASSOCIATED(ipi_env%ipi_forces)) THEN
     290           0 :          ipi_env%ipi_forces(:, :) = 0.0_dp
     291             :       END IF
     292           0 :       IF (ASSOCIATED(ipi_env%subsys)) THEN
     293           0 :          CALL cp_subsys_release(ipi_env%subsys)
     294             :       END IF
     295           0 :       IF (ASSOCIATED(ipi_env%force_env_input)) THEN
     296           0 :          CALL section_vals_release(ipi_env%force_env_input)
     297             :       END IF
     298           0 :       IF (ASSOCIATED(ipi_env%cell_ref)) THEN
     299           0 :          CALL cell_release(ipi_env%cell_ref)
     300             :       END IF
     301           0 :    END SUBROUTINE ipi_env_clear
     302             : 
     303             : ! **************************************************************************************************
     304             : !> \brief Creates the ipi environment
     305             : !> \param ipi_env The ipi environment to be created
     306             : !> \par History
     307             : !>      03.2024 initial create
     308             : !> \author Sebastian Seidenath (sebastian.seidenath@uni-jena.de)
     309             : ! **************************************************************************************************
     310           0 :    SUBROUTINE ipi_env_create(ipi_env)
     311             : 
     312             :       TYPE(ipi_environment_type), INTENT(OUT)            :: ipi_env
     313             : 
     314             :       NULLIFY (ipi_env%ipi_forces)
     315             :       NULLIFY (ipi_env%subsys)
     316             :       NULLIFY (ipi_env%force_env_input)
     317             :       NULLIFY (ipi_env%cell_ref)
     318             : 
     319             :       ipi_env%ipi_energy = 0_dp
     320           0 :       ipi_env%sockfd = 0 ! stdinp
     321           0 :       CALL ipi_env_clear(ipi_env)
     322           0 :    END SUBROUTINE ipi_env_create
     323             : 
     324           0 : END MODULE ipi_environment_types

Generated by: LCOV version 1.15