Octopus
exchange_operator.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2018 M. Marques, A. Castro, A. Rubio, G. Bertsch, N. 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 batch_oct_m
24 use comm_oct_m
25 use debug_oct_m
29 use global_oct_m
30 use grid_oct_m
35 use math_oct_m
36 use mesh_oct_m
40 use mpi_oct_m
44 use parser_oct_m
45 use phase_oct_m
50 use space_oct_m
58 use unit_oct_m
61 use xc_cam_oct_m
62
63 implicit none
64
65 private
66 public :: &
86
87 type ace_t
88 integer :: nst
89 real(real64), allocatable :: dchi(:,:,:,:)
90 complex(real64), allocatable :: zchi(:,:,:,:)
91 contains
92 procedure :: init => ace_init
93 procedure :: end => ace_end
94 procedure :: write_info => ace_write_info
95 end type ace_t
96
97
99 type(states_elec_t), public, pointer :: st => null()
100 type(xc_cam_t) :: cam
101 type(poisson_t) :: psolver
102 type(singularity_t) :: singul
103 logical :: useACE
104 logical :: with_isdf
105 type(ACE_t) :: ace
106 type(isdf_options_t) :: isdf
107 contains
108 procedure :: write_info => exchange_operator_write_info
109 end type exchange_operator_t
110
111
112 type(fourier_space_op_t) :: coulb
113 ! Saved as we avoid then to recompute it,
114 ! for instance in the case of CAM functionals in isolated systems
115
116 real(real64), parameter, private :: TOL_EXX_WEIGHT = 1.0e-3_real64
117
118contains
119
121 subroutine ace_init(this, namespace, st)
122 class(ACE_t), intent(inout) :: this
123 type(namespace_t), intent(in) :: namespace
124 type(states_elec_t), intent(in ) :: st
125
126 push_sub(ace_init)
127
128 !%Variable ACESize
129 !%Type integer
130 !%Default All states
131 !%Section Hamiltonian
132 !%Description
133 !% (Experimental) The number of ACE projection vectors (i.e. the size of the test-orbital set) and hence the dimension of the
134 !% subspace on which the low-rank ACE operator is (approximately) exact. By default, Octopus sets this to the
135 !% number of states requested for a calculation (all states), which is essential when the band gap is of interest.
136 !% For development purposes, if only occupied states are required, the user can set this value manually.
137 !% For more information, see Lin, J. Chem. Theory Comput. 2016, 12, 2242.
138 !%End
139 call parse_variable(namespace, 'ACESize', st%nst, this%nst)
140
141 if (this%nst > st%nst) then
142 call messages_input_error(namespace, 'ACESize', "Exceeds the total number of states available")
143 endif
144
145 if (this%nst < st%nst) then
146 call messages_experimental("Adaptively-compressed exchange defined with a subset of states", namespace=namespace)
147 endif
148
149 if (this%nst * st%smear%el_per_state < st%qtot) then
150 write(message(1),'(a)') "ACESize should at least equal the number of occupied states."
151 call messages_warning(1, namespace=namespace)
152 endif
153
154 ! dchi/zchi are allocated at their point of use.
155
156 pop_sub(ace_init)
157
158 end subroutine ace_init
159
161 subroutine ace_end(this)
162 class(ACE_t), intent(inout) :: this
163
164 push_sub(ace_end)
165
166 this%nst = 0
167 safe_deallocate_a(this%dchi)
168 safe_deallocate_a(this%zchi)
169
170 pop_sub(ace_end)
171
172 end subroutine ace_end
173
174 subroutine ace_write_info(this, namespace)
175 class(ACE_t), intent(in) :: this
176 type(namespace_t), intent(in) :: namespace
177
178 push_sub(ace_write_info)
179
180 call messages_print_var_value("Dimension of the subspace in which the low-rank ACE operator is"// &
181 & " approximately exact (ACESize)", this%nst, namespace=namespace)
185 end subroutine ace_write_info
186
187 subroutine exchange_operator_init(this, namespace, space, st, der, mc, stencil, kpoints, cam)
188 type(exchange_operator_t), intent(inout) :: this
189 type(namespace_t), intent(in) :: namespace
190 class(space_t), intent(in) :: space
191 type(states_elec_t), intent(in) :: st
192 type(derivatives_t), intent(in) :: der
193 type(multicomm_t), intent(in) :: mc
194 type(stencil_t), intent(in) :: stencil
195 type(kpoints_t), intent(in) :: kpoints
196 type(xc_cam_t), intent(in) :: cam
200 !%Variable AdaptivelyCompressedExchange
201 !%Type logical
202 !%Default true
203 !%Section Hamiltonian
204 !%Description
205 !% If set to yes, Octopus will use the adaptively compressed exchange
206 !% operator (ACE) for HF and hybrid calculations, as defined in
207 !% Lin, J. Chem. Theory Comput. 2016, 12, 2242.
208 !%
209 !% This is currently ignored for TheoryLevel = rdmft
210 !%End
211 call parse_variable(namespace, 'AdaptivelyCompressedExchange', .true., this%useACE)
212 call messages_print_var_value('AdaptivelyCompressedExchange', this%useACE)
213
214 !%Variable ACEWithISDF
215 !%Type logical
216 !%Default no
217 !%Section ISDF
218 !%Description
219 !% If set to yes, Octopus will use interpolative separable density fitting (ISDF)
220 !% to accelerate the calculation of adaptively compressed exchange in hybrid
221 !% functionals. For more details, please refer to J.Chem.TheoryComput.2017, 13, 5420-5431.
222 !% ISDF is currently only implemented for spin-unpolarized, molecular systems.
223 !%End
224 call parse_variable(namespace, 'ACEWithISDF', .false., this%with_isdf)
225
226 if (this%with_isdf .and. .not. this%useACE) then
227 call messages_input_error(namespace, 'ACEWithISDF', &
228 '"ACEWithISDF = yes" must be used with "AdaptivelyCompressedExchange = yes"')
229 endif
230
231 ! Objs initialised by exchange constructor
232 if (this%useACE) then
233 call this%ace%init(namespace, st)
234 if (this%with_isdf) call this%isdf%init(namespace, space, st, der%mesh, this%ace%nst)
235 endif
236 call singularity_init(this%singul, namespace, space, st, kpoints)
237 call poisson_init(this%psolver, namespace, space, der, mc, stencil, st%qtot, &
238 force_serial = .true., verbose = .false., force_cmplx = .not. states_are_real(st))
239
240 ! Objs initialised by the caller
241 this%cam = cam
242
244 end subroutine exchange_operator_init
245
246 subroutine exchange_operator_reinit(this, cam, st)
247 type(exchange_operator_t), intent(inout) :: this
248 type(xc_cam_t), intent(in ) :: cam
249 type(states_elec_t), target, optional, intent(in ) :: st
250
252
253 if (present(st)) then
254 this%st => st
255 end if
257 this%cam = cam
258
260 end subroutine exchange_operator_reinit
261
262 subroutine exchange_operator_end(this)
263 type(exchange_operator_t), intent(inout) :: this
264
265 push_sub(exchange_operator_end)
266
267 if (associated(this%st) .and. .not. this%useACE) then
269 call states_elec_end(this%st)
270 safe_deallocate_p(this%st)
271 end if
272 nullify(this%st)
273
274 call this%ace%end()
275 call singularity_end(this%singul)
276 call fourier_space_op_end(coulb)
277 call poisson_end(this%psolver)
278 call this%isdf%end()
279
280 pop_sub(exchange_operator_end)
281 end subroutine exchange_operator_end
283 subroutine exchange_operator_rdmft_occ_apply(this, mesh, hpsib)
284 type(exchange_operator_t), intent(in) :: this
285 type(mesh_t), intent(in) :: mesh
286 class(wfs_elec_t), intent(inout) :: hpsib
287
289
290 ! multiply linear terms in hamiltonian with occupation number
291 ! nonlinear occupation number dependency occurs only in the exchange, which is treated there
292 call batch_scal(mesh%np, this%st%occ(:, hpsib%ik), hpsib)
293
296
297 subroutine exchange_operator_write_info(this, namespace)
298 class(exchange_operator_t), intent(in) :: this
299 type(namespace_t), intent(in) :: namespace
300
302
303 call messages_print_with_emphasis(msg='Exact Exchange', namespace=namespace)
304 call messages_print_var_value("Adaptively compressed exchange", this%useACE, namespace=namespace)
305 if (this%useACE) then
306 call this%ace%write_info(namespace)
307 if (this%with_isdf) then
308 call messages_print_var_value("Density Fitting in ACE with ISDF", this%with_isdf, namespace=namespace)
309 call this%isdf%write_info(namespace)
310 endif
311 endif
312
314
315 end subroutine exchange_operator_write_info
316
317
318#include "undef.F90"
319#include "real.F90"
320#include "exchange_operator_inc.F90"
321
322#include "undef.F90"
323#include "complex.F90"
324#include "exchange_operator_inc.F90"
325
327
328!! Local Variables:
329!! mode: f90
330!! coding: utf-8
331!! End:
scale a batch by a constant or vector
Definition: batch_ops.F90:164
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:182
This module implements batches of mesh functions.
Definition: batch.F90:135
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:118
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dexchange_operator_hartree_apply(this, namespace, mesh, st_d, kpoints, exx_coef, psib, hpsib)
subroutine, public dexchange_operator_ace(this, namespace, mesh, st, xst, phase)
subroutine ace_write_info(this, namespace)
subroutine ace_init(this, namespace, st)
Initialize an instance of ACE_t.
subroutine, public zexchange_operator_compute_potentials(this, namespace, space, gr, st, xst, kpoints, F_out)
subroutine, public zexchange_operator_commute_r(this, namespace, mesh, st_d, ik, psi, gpsi)
subroutine, public exchange_operator_init(this, namespace, space, st, der, mc, stencil, kpoints, cam)
subroutine, public exchange_operator_reinit(this, cam, st)
subroutine exchange_operator_write_info(this, namespace)
subroutine, public dexchange_operator_compute_potentials(this, namespace, space, gr, st, xst, kpoints, F_out)
subroutine, public zexchange_operator_single(this, namespace, space, mesh, st_d, kpoints, phase, ist, ik, psi, hpsi, rdmft, force_noace)
subroutine, public dexchange_operator_single(this, namespace, space, mesh, st_d, kpoints, phase, ist, ik, psi, hpsi, rdmft, force_noace)
subroutine ace_end(this)
End an instance of ACE_t.
subroutine, public dexchange_operator_commute_r(this, namespace, mesh, st_d, ik, psi, gpsi)
subroutine, public zexchange_operator_hartree_apply(this, namespace, mesh, st_d, kpoints, exx_coef, psib, hpsib)
subroutine, public exchange_operator_end(this)
subroutine, public zexchange_operator_apply(this, namespace, space, mesh, st_d, kpoints, phase, psib, hpsib, rdmft, force_noace)
subroutine, public dexchange_operator_apply(this, namespace, space, mesh, st_d, kpoints, phase, psib, hpsib, rdmft, force_noace)
subroutine, public zexchange_operator_ace(this, namespace, mesh, st, xst, phase)
real(real64) function, public dexchange_operator_compute_ex(mesh, st, xst)
Compute the exact exchange energy.
subroutine, public exchange_operator_rdmft_occ_apply(this, mesh, hpsib)
real(real64) function, public zexchange_operator_compute_ex(mesh, st, xst)
Compute the exact exchange energy.
subroutine, public fourier_space_op_end(this)
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:118
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_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:904
character(len=512), private msg
Definition: messages.F90:167
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:531
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:697
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1069
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
Some general things and nomenclature:
Definition: par_vec.F90:173
subroutine, public poisson_init(this, namespace, space, der, mc, stencil, qtot, label, solver, verbose, force_serial, force_cmplx)
Definition: poisson.F90:236
subroutine, public poisson_end(this)
Definition: poisson.F90:688
This module is an helper to perform ring-pattern communications among all states.
subroutine, public singularity_end(this)
subroutine, public singularity_init(this, namespace, space, st, kpoints)
pure logical function, public states_are_real(st)
This module provides routines for communicating all batches in a ring-pattern scheme.
This module handles spin dimensions of the states and the k-point distribution.
subroutine, public states_elec_end(st)
finalize the states_elec_t object
This module provides routines for communicating states when using states parallelization.
subroutine, public states_elec_parallel_remote_access_stop(this)
stop remote memory access for states on other processors
This module defines stencils used in Octopus.
Definition: stencil.F90:137
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
This module defines the unit system, used for input and output.
class representing derivatives
Describes mesh distribution to nodes.
Definition: mesh.F90:187
The states_elec_t class contains all electronic wave functions.
The class representing the stencil, which is used for non-local mesh operations.
Definition: stencil.F90:165
batches of electronic states
Definition: wfs_elec.F90:141
Coulomb-attenuating method parameters, used in the partitioning of the Coulomb potential into a short...
Definition: xc_cam.F90:141
int true(void)