Octopus
xc_interaction.F90
Go to the documentation of this file.
1!! Copyright (C) 2021 Nicolas Tancogne-Dejean
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use debug_oct_m
25 use global_oct_m
28 use, intrinsic :: iso_fortran_env
29 use mesh_oct_m
36 use space_oct_m
38 use xc_cam_oct_m
39 use xc_f03_lib_m
41
42 implicit none
43
44 private
45 public :: &
50
52 private
53
54 contains
55 procedure :: init => xc_interaction_init
56 procedure :: calculate => xc_interaction_calculate
57 procedure :: calculate_energy => xc_interaction_calculate_energy
58 procedure :: end => xc_interaction_end
60 end type xc_interaction_t
61
62 interface xc_interaction_t
63 module procedure xc_interaction_constructor
64 end interface xc_interaction_t
65
66 integer, public, parameter :: &
67 FUNC_X = 1, &
68 func_c = 2
69
70
71contains
72
73 ! ---------------------------------------------------------
74 function xc_interaction_constructor(partner) result(this)
75 class(interaction_partner_t), target, intent(inout) :: partner
76 class(xc_interaction_t), pointer :: this
77
79
80 allocate(this)
81
82 this%label = "exchange-correlation interaction"
83
84 this%partner => partner
85
88
89 ! ---------------------------------------------------------
90 subroutine xc_interaction_init(this)
91 class(xc_interaction_t), intent(inout) :: this
92
93 push_sub(xc_interaction_init)
94
95 pop_sub(xc_interaction_init)
96 end subroutine xc_interaction_init
97
98 ! ---------------------------------------------------------
99 subroutine xc_interaction_calculate(this)
100 class(xc_interaction_t), intent(inout) :: this
101
103
104 this%density = m_zero
105
107 end subroutine xc_interaction_calculate
108
109 ! ---------------------------------------------------------
110 subroutine xc_interaction_calculate_energy(this)
111 class(xc_interaction_t), intent(inout) :: this
112
114
115 this%energy = m_zero
119
120
121 ! ---------------------------------------------------------
122 subroutine xc_interaction_compute(this)
123 class(xc_interaction_t), intent(inout) :: this
124 push_sub(xc_interaction_compute)
125
126 this%density = m_zero
127
129 end subroutine xc_interaction_compute
130
131 ! ---------------------------------------------------------
132 subroutine xc_interaction_end(this)
133 class(xc_interaction_t), intent(inout) :: this
134
135 push_sub(xc_interaction_end)
136
137 safe_deallocate_a(this%density)
138
139 call interaction_end(this)
140
141 pop_sub(xc_interaction_end)
142 end subroutine xc_interaction_end
143
144
145 ! ---------------------------------------------------------
146 subroutine xc_interaction_finalize(this)
147 type(xc_interaction_t), intent(inout) :: this
148
155
156 ! -----------------------------------------------------
157 subroutine calc_tb09_c(mesh, space, functl, dens, gdens, ispin, rcell_volume)
158 class(mesh_t), intent(in) :: mesh
159 class(space_t), intent(in) :: space
160 type(xc_functional_t), intent(inout) :: functl(:)
161 real(real64), intent(in) :: dens(:,:)
162 real(real64), intent(in) :: gdens(:,:,:)
163 integer, intent(in) :: ispin
164 real(real64), intent(in) :: rcell_volume
165
166 real(real64), allocatable :: gnon(:)
167 real(real64) :: gn(space%dim), n, parameters(1)
168 integer :: ii
170 push_sub(calc_tb09_c)
171
172 safe_allocate(gnon(1:mesh%np))
173
174 do ii = 1, mesh%np
175 if (ispin == unpolarized) then
176 n = dens(ii, 1)
177 gn(1:space%dim) = gdens(ii, 1:space%dim, 1)
178 else
179 n = dens(ii, 1) + dens(ii, 2)
180 gn(1:space%dim) = gdens(ii, 1:space%dim, 1) + gdens(ii, 1:space%dim, 2)
181 end if
182
183 if (n <= 1e-7_real64) then
184 gnon(ii) = m_zero
185 else
186 gnon(ii) = sqrt(sum((gn(1:space%dim)/n)**2))
187 end if
188 end do
189
190 parameters(1) = -0.012_real64 + 1.023_real64*sqrt(dmf_integrate(mesh, gnon)/rcell_volume)
191
192 call xc_f03_func_set_ext_params(functl(1)%conf, parameters)
193
194 safe_deallocate_a(gnon)
195
196 pop_sub(calc_tb09_c)
197 end subroutine calc_tb09_c
198
199 ! ---------------------------------------------------------
200 subroutine calc_mvorb_alpha(mesh, namespace, space, functl, dens, gdens, ispin, rcell_volume, cam)
201 class(mesh_t), intent(in) :: mesh
202 type(namespace_t), intent(in) :: namespace
203 class(space_t), intent(in) :: space
204 type(xc_functional_t), intent(inout) :: functl(:)
205 real(real64), intent(in) :: dens(:,:)
206 real(real64), intent(in) :: gdens(:,:,:)
207 integer, intent(in) :: ispin
208 real(real64), intent(in) :: rcell_volume
209 type(xc_cam_t), intent(inout) :: cam
210
211 real(real64), allocatable :: gnon(:)
212 real(real64) :: tb09_c, alpha
213 real(real64) :: gn(space%dim), n
214 integer :: ii
215 real(real64) :: parameters(3)
216 real(real64), parameter :: tol_small_dens = 1e-11_real64
218 push_sub(calc_mvorb_alpha)
219
220 safe_allocate(gnon(1:mesh%np))
221
222 do ii = 1, mesh%np
223 if (ispin == unpolarized) then
224 n = dens(ii, 1)
225 gn(1:space%dim) = gdens(ii, 1:space%dim, 1)
226 else
227 n = dens(ii, 1) + dens(ii, 2)
228 gn(1:space%dim) = gdens(ii, 1:space%dim, 1) + gdens(ii, 1:space%dim, 2)
229 end if
230
231 if (n <= tol_small_dens) then
232 gnon(ii) = m_zero
233 else
234 gnon(ii) = sqrt(sum((gn(1:space%dim)/n)**2))
235 gnon(ii) = sqrt(gnon(ii))
236 end if
237 end do
238
239 tb09_c = dmf_integrate(mesh, gnon)/rcell_volume
240
241 safe_deallocate_a(gnon)
242
243 select case (functl(func_c)%id)
245 alpha = 0.121983_real64+0.130711_real64*tb09_c**4
246
247 if (alpha > 1) then
248 write(message(1), '(a,f6.3,a)') 'MVORB mixing parameter bigger than one (' , alpha ,').'
249 call messages_warning(1, namespace=namespace)
250 alpha = 0.25_real64
251 else
252 write(message(1), '(a,f6.3,a)') 'MVORB mixing parameter is (' , alpha ,').'
253 call messages_info(1, namespace=namespace, debug_only=.true.)
254 end if
255
256
257 parameters(1) = alpha
258 parameters(2) = cam%omega
259 parameters(3) = cam%omega
260 call xc_f03_func_set_ext_params(functl(func_c)%conf, parameters)
261 !The name is confusing. Here alpha is the beta of hybrids in functionals,
262 !but is called alpha in the original paper.
263 cam%beta = alpha
264
266 alpha = -1.00778_real64+1.10507_real64*tb09_c
267
268 if (alpha > 1) then
269 write(message(1), '(a,f6.3,a)') 'MVORB mixing parameter bigger than one (' , alpha ,').'
270 call messages_warning(1, namespace=namespace)
271 alpha = 0.25_real64
272 else if (alpha < 0) then
273 write(message(1), '(a,f6.3,a)') 'MVORB mixing parameter smaller than zero (' , alpha ,').'
274 call messages_warning(1, namespace=namespace)
275 alpha = 0.25_real64
276 else
277 write(message(1), '(a,f6.3,a)') 'MVORB mixing parameter is (' , alpha ,').'
278 call messages_info(1, namespace=namespace, debug_only=.true.)
279 end if
280
281 parameters(1) = alpha
282 call xc_f03_func_set_ext_params(functl(func_c)%conf, parameters)
283 cam%alpha = alpha
284 case default
285 call messages_not_implemented("MVORB density-based mixing for functionals other than PBE0 and HSE06", namespace=namespace)
286 end select
287
288 pop_sub(calc_mvorb_alpha)
289 end subroutine calc_mvorb_alpha
290
291
292end module xc_interaction_oct_m
293
294!! Local Variables:
295!! mode: f90
296!! coding: utf-8
297!! End:
double sqrt(double __x) __attribute__((__nothrow__
integer, parameter, public unpolarized
Parameters...
real(real64), parameter, public m_zero
Definition: global.F90:200
This module defines the abstract interaction_t class, and some auxiliary classes for interactions.
subroutine, public interaction_end(this)
This module defines classes and functions for interaction partners.
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
This module defines the quantity_t class and the IDs for quantities, which can be exposed by a system...
Definition: quantity.F90:140
This module handles spin dimensions of the states and the k-point distribution.
integer, parameter, public xc_hyb_gga_xc_mvorb_pbeh
Density-based mixing parameter of PBE0.
integer, parameter, public xc_hyb_gga_xc_mvorb_hse06
Density-based mixing parameter of HSE06.
subroutine xc_interaction_finalize(this)
class(xc_interaction_t) function, pointer xc_interaction_constructor(partner)
subroutine, public xc_interaction_compute(this)
subroutine xc_interaction_end(this)
subroutine, public calc_tb09_c(mesh, space, functl, dens, gdens, ispin, rcell_volume)
integer, parameter, public func_c
subroutine xc_interaction_init(this)
subroutine xc_interaction_calculate(this)
subroutine xc_interaction_calculate_energy(this)
subroutine, public calc_mvorb_alpha(mesh, namespace, space, functl, dens, gdens, ispin, rcell_volume, cam)
Describes mesh distribution to nodes.
Definition: mesh.F90:187
Coulomb-attenuating method parameters, used in the partitioning of the Coulomb potential into a short...
Definition: xc_cam.F90:141
int true(void)