(git:e7e05ae)
xc_derivative_desc.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 Module with functions to handle derivative descriptors.
10 !> derivative description are strings have the following form
11 !> "rhorhorhoa" which means that it is a forth order
12 !> derivative, twice with respect to rho, once with respect to rhoa
13 !> and once with respect to drhoa.
14 !> Possible derivatives are:
15 !> - rho: total density
16 !> - norm_drho: norm of the gradient of the total density
17 !> - rhoa, rhob: alpha and beta spin density (with LSD)
18 !> - norm_drhoa, norm_drhob: norm of the gradient of the alpha and beta
19 !> spin density
20 !> - tau: the local kinetic part
21 !> - taua, taub: the kinetic part of the different spins
22 !> \note
23 !> add drhox, drhoy, drhoz, drhoax,...?
24 !> \author thomas & fawzi
25 ! **************************************************************************************************
27 
28  USE util, ONLY: sort
29 #include "../base/base_uses.f90"
30 
31  IMPLICIT NONE
32 
33  PRIVATE
34 
35  INTEGER, PARAMETER, PUBLIC :: &
36  deriv_rho = 1, &
37  deriv_rhoa = 2, &
38  deriv_rhob = 3, &
39  deriv_norm_drho = 4, &
40  deriv_norm_drhoa = 5, &
41  deriv_norm_drhob = 6, &
42  deriv_tau = 7, &
43  deriv_tau_a = 8, &
44  deriv_tau_b = 9, &
45  deriv_laplace_rho = 10, &
46  deriv_laplace_rhoa = 11, &
48 
49  INTEGER, PARAMETER :: max_label_length = 12
50 
51  LOGICAL, PARAMETER :: debug_this_module = .false.
52 
53  CHARACTER(len=*), PARAMETER, PRIVATE :: modulen = 'xc_derivative_desc'
54 
56 
57 CONTAINS
58 
59 ! **************************************************************************************************
60 !> \brief ...
61 !> \param desc ...
62 !> \return ...
63 ! **************************************************************************************************
64  FUNCTION desc_to_id(desc) RESULT(id)
65  CHARACTER(LEN=*), INTENT(IN) :: desc
66  INTEGER :: id
67 
68  SELECT CASE (trim(desc))
69  CASE ("rho")
70  id = deriv_rho
71  CASE ("rhoa")
72  id = deriv_rhoa
73  CASE ("rhob")
74  id = deriv_rhob
75  CASE ("norm_drho")
76  id = deriv_norm_drho
77  CASE ("norm_drhoa")
78  id = deriv_norm_drhoa
79  CASE ("norm_drhob")
80  id = deriv_norm_drhob
81  CASE ("tau")
82  id = deriv_tau
83  CASE ("tau_a")
84  id = deriv_tau_a
85  CASE ("tau_b")
86  id = deriv_tau_b
87  CASE ("laplace_rho")
89  CASE ("laplace_rhoa")
91  CASE ("laplace_rhob")
93  CASE DEFAULT
94  cpabort("Unknown derivative variable: "//desc)
95  END SELECT
96 
97  END FUNCTION desc_to_id
98 
99 ! **************************************************************************************************
100 !> \brief ...
101 !> \param id ...
102 !> \return ...
103 ! **************************************************************************************************
104  FUNCTION id_to_desc(id) RESULT(desc)
105  INTEGER, INTENT(IN) :: id
106  CHARACTER(LEN=MAX_LABEL_LENGTH) :: desc
107 
108  SELECT CASE (id)
109  CASE (deriv_rho)
110  desc = "rho"
111  CASE (deriv_rhoa)
112  desc = "rhoa"
113  CASE (deriv_rhob)
114  desc = "rhob"
115  CASE (deriv_norm_drho)
116  desc = "norm_drho"
117  CASE (deriv_norm_drhoa)
118  desc = "norm_drhoa"
119  CASE (deriv_norm_drhob)
120  desc = "norm_drhob"
121  CASE (deriv_tau)
122  desc = "tau"
123  CASE (deriv_tau_a)
124  desc = "tau_a"
125  CASE (deriv_tau_b)
126  desc = "tau_b"
127  CASE (deriv_laplace_rho)
128  desc = "laplace_rho"
129  CASE (deriv_laplace_rhoa)
130  desc = "laplace_rhoa"
131  CASE (deriv_laplace_rhob)
132  desc = "laplace_rhob"
133  CASE DEFAULT
134  cpabort("Unknown derivative id!")
135  END SELECT
136 
137  END FUNCTION id_to_desc
138 
139 ! **************************************************************************************************
140 !> \brief ...
141 !> \param desc ...
142 !> \param split_desc ...
143 ! **************************************************************************************************
144  SUBROUTINE create_split_desc(desc, split_desc)
145  INTEGER, DIMENSION(:), INTENT(IN) :: desc
146  INTEGER, DIMENSION(:), POINTER :: split_desc
147 
148  INTEGER, ALLOCATABLE, DIMENSION(:) :: indices
149 
150  ALLOCATE (split_desc(SIZE(desc)))
151  IF (SIZE(desc) > 0) THEN
152  ALLOCATE (indices(SIZE(desc)))
153  split_desc = desc
154  CALL sort(split_desc, SIZE(desc), indices)
155  DEALLOCATE (indices)
156  END IF
157 
158  END SUBROUTINE create_split_desc
159 
160 ! **************************************************************************************************
161 !> \brief ...
162 !> \param desc ...
163 !> \param split_desc ...
164 ! **************************************************************************************************
165  SUBROUTINE standardize_desc(desc, split_desc)
166  INTEGER, DIMENSION(:), INTENT(IN) :: desc
167  INTEGER, ALLOCATABLE, DIMENSION(:), INTENT(OUT) :: split_desc
168 
169  INTEGER, ALLOCATABLE, DIMENSION(:) :: indices
170 
171  ALLOCATE (split_desc(SIZE(desc)))
172  IF (SIZE(desc) > 0) THEN
173  ALLOCATE (indices(SIZE(desc)))
174  split_desc(:) = desc
175  CALL sort(split_desc, SIZE(desc), indices)
176  DEALLOCATE (indices)
177  END IF
178 
179  END SUBROUTINE standardize_desc
180 
181 END MODULE xc_derivative_desc
All kind of helpful little routines.
Definition: util.F:14
Module with functions to handle derivative descriptors. derivative description are strings have the f...
integer, parameter, public deriv_norm_drho
integer, parameter, public deriv_laplace_rhob
integer, parameter, public deriv_norm_drhoa
integer, parameter, public deriv_rhob
integer, parameter, public deriv_rhoa
integer, parameter, public deriv_tau
integer, parameter, public deriv_tau_b
subroutine, public standardize_desc(desc, split_desc)
...
integer, parameter, public deriv_tau_a
integer, parameter, public deriv_laplace_rhoa
subroutine, public create_split_desc(desc, split_desc)
...
integer function, public desc_to_id(desc)
...
integer, parameter, public deriv_rho
integer, parameter, public deriv_norm_drhob
character(len=max_label_length) function, public id_to_desc(id)
...
integer, parameter, public deriv_laplace_rho