(git:b195825)
eri_mme_util.F
Go to the documentation of this file.
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 Some utility methods used in different contexts.
10 !> \par History
11 !> 2015 09 created
12 !> \author Patrick Seewald
13 ! **************************************************************************************************
14 
16 
17  USE kinds, ONLY: dp
18  USE mathconstants, ONLY: twopi
19 #include "../base/base_uses.f90"
20 
21  IMPLICIT NONE
22 
23  PRIVATE
24 
25  PUBLIC :: g_abs_min, r_abs_min
26 CONTAINS
27 ! **************************************************************************************************
28 !> \brief Find minimum length of R vectors, for a general (not necessarily
29 !> orthorhombic) cell.
30 !> \param hmat ...
31 !> \return ...
32 ! **************************************************************************************************
33  FUNCTION r_abs_min(hmat) RESULT(R_m)
34  REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: hmat
35  REAL(kind=dp) :: r_m
36 
37  INTEGER :: sx, sy, sz
38  INTEGER, DIMENSION(3) :: sxyz
39  REAL(kind=dp) :: r_sq
40  REAL(kind=dp), DIMENSION(3) :: r
41 
42  r_m = 0.0_dp
43 
44  DO sx = -1, 1
45  DO sy = -1, 1
46  DO sz = -1, 1
47  IF (.NOT. (sx == 0 .AND. sy == 0 .AND. sz == 0)) THEN
48  sxyz = [sx, sy, sz]
49  r = matmul(hmat, sxyz)
50  r_sq = r(1)**2 + r(2)**2 + r(3)**2
51  IF (r_sq < r_m .OR. r_m < epsilon(r_m)) r_m = r_sq
52  END IF
53  END DO
54  END DO
55  END DO
56  r_m = sqrt(r_m)
57 
58  END FUNCTION r_abs_min
59 
60 ! **************************************************************************************************
61 !> \brief Find minimum length of G vectors, for a general (not necessarily
62 !> orthorhombic) cell.
63 !> \param h_inv ...
64 !> \return ...
65 ! **************************************************************************************************
66  FUNCTION g_abs_min(h_inv) RESULT(G_m)
67  REAL(kind=dp), DIMENSION(3, 3), INTENT(IN) :: h_inv
68  REAL(kind=dp) :: g_m
69 
70  INTEGER :: gx, gy, gz
71  INTEGER, DIMENSION(3) :: gxyz
72  REAL(kind=dp) :: g_sq
73  REAL(kind=dp), DIMENSION(3) :: g
74  REAL(kind=dp), DIMENSION(3, 3) :: h
75 
76  h = twopi*transpose(h_inv)
77  g_m = 0.0_dp
78 
79  DO gx = -1, 1
80  DO gy = -1, 1
81  DO gz = -1, 1
82  IF (.NOT. (gx == 0 .AND. gy == 0 .AND. gz == 0)) THEN
83  gxyz = [gx, gy, gz]
84  g = matmul(h, gxyz)
85  g_sq = g(1)**2 + g(2)**2 + g(3)**2
86  IF (g_sq < g_m .OR. g_m < epsilon(g_m)) g_m = g_sq
87  END IF
88  END DO
89  END DO
90  END DO
91  g_m = sqrt(g_m)
92 
93  END FUNCTION g_abs_min
94 
95 END MODULE eri_mme_util
Some utility methods used in different contexts.
Definition: eri_mme_util.F:15
real(kind=dp) function, public g_abs_min(h_inv)
Find minimum length of G vectors, for a general (not necessarily orthorhombic) cell.
Definition: eri_mme_util.F:67
real(kind=dp) function, public r_abs_min(hmat)
Find minimum length of R vectors, for a general (not necessarily orthorhombic) cell.
Definition: eri_mme_util.F:34
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Definition of mathematical constants and functions.
Definition: mathconstants.F:16
real(kind=dp), parameter, public twopi