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 accel_oct_m
24 use batch_oct_m
26 use blas_oct_m
27 use comm_oct_m
28 use debug_oct_m
31 use fft_oct_m, only: fftlib_accel
33 use global_oct_m
34 use grid_oct_m
39 use math_oct_m
40 use mesh_oct_m
44 use mpi_oct_m
48 use parser_oct_m
49 use phase_oct_m
54 use space_oct_m
63 use types_oct_m
64 use unit_oct_m
67 use xc_cam_oct_m
68
69 implicit none
70
71 private
72 public :: &
92
93 type ace_t
94 integer :: nst
95 real(real64), allocatable :: dchi(:,:,:,:)
96 complex(real64), allocatable :: zchi(:,:,:,:)
97 type(wfs_elec_t), allocatable :: chib(:)
98 ! one batch per k-point (kpt%start:kpt%end), used to
99 ! apply the operator with GEMMs while keeping the
100 ! wavefunctions resident on the GPU. dchi/zchi above
101 ! remain the reference host copy.
102 contains
103 procedure :: init => ace_init
104 procedure :: end => ace_end
105 procedure :: write_info => ace_write_info
106 end type ace_t
107
108
110 type(states_elec_t), public, pointer :: st => null()
111 type(xc_cam_t) :: cam
112 type(poisson_t) :: psolver
113 type(singularity_t) :: singul
114 logical :: useACE
115 logical :: with_isdf
116 type(ACE_t) :: ace
117 type(isdf_options_t) :: isdf
118 contains
119 procedure :: write_info => exchange_operator_write_info
120 end type exchange_operator_t
121
122
123 type(fourier_space_op_t) :: coulb
124 ! Saved as we avoid then to recompute it,
125 ! for instance in the case of CAM functionals in isolated systems
126
127 real(real64), parameter, private :: TOL_EXX_WEIGHT = 1.0e-3_real64
128
129contains
130
132 subroutine ace_init(this, namespace, st)
133 class(ACE_t), intent(inout) :: this
134 type(namespace_t), intent(in) :: namespace
135 type(states_elec_t), intent(in ) :: st
136
137 push_sub(ace_init)
138
139 !%Variable ACESize
140 !%Type integer
141 !%Default All states
142 !%Section Hamiltonian
143 !%Description
144 !% (Experimental) The number of ACE projection vectors (i.e. the size of the test-orbital set) and hence the dimension of the
145 !% subspace on which the low-rank ACE operator is (approximately) exact. By default, Octopus sets this to the
146 !% number of states requested for a calculation (all states), which is essential when the band gap is of interest.
147 !% For development purposes, if only occupied states are required, the user can set this value manually.
148 !% For more information, see Lin, J. Chem. Theory Comput. 2016, 12, 2242.
149 !%End
150 call parse_variable(namespace, 'ACESize', st%nst, this%nst)
151
152 if (this%nst > st%nst) then
153 call messages_input_error(namespace, 'ACESize', "Exceeds the total number of states available")
154 endif
155
156 if (this%nst < st%nst) then
157 call messages_experimental("Adaptively-compressed exchange defined with a subset of states", namespace=namespace)
158 endif
159
160 if (this%nst * st%smear%el_per_state < st%qtot) then
161 write(message(1),'(a)') "ACESize should at least equal the number of occupied states."
162 call messages_warning(1, namespace=namespace)
163 endif
164
165 ! dchi/zchi are allocated at their point of use because at this point there is
166 ! nothing to indicate whether one needs dchi or zchi
167
168 pop_sub(ace_init)
169
170 end subroutine ace_init
171
173 subroutine ace_end(this)
174 class(ACE_t), intent(inout) :: this
175
176 integer :: ik
177
178 push_sub(ace_end)
179
180 this%nst = 0
181 safe_deallocate_a(this%dchi)
182 safe_deallocate_a(this%zchi)
183
184 if (allocated(this%chib)) then
185 do ik = lbound(this%chib, 1), ubound(this%chib, 1)
186 call this%chib(ik)%end()
187 end do
188 safe_deallocate_a(this%chib)
189 end if
191 pop_sub(ace_end)
193 end subroutine ace_end
194
195 subroutine ace_write_info(this, namespace)
196 class(ace_t), intent(in) :: this
197 type(namespace_t), intent(in) :: namespace
201 call messages_print_var_value("Dimension of the subspace in which the low-rank ACE operator is"// &
202 & " approximately exact (ACESize)", this%nst, namespace=namespace)
203
206 end subroutine ace_write_info
208 subroutine exchange_operator_init(this, namespace, space, st, der, mc, stencil, kpoints, cam)
209 type(exchange_operator_t), intent(inout) :: this
210 type(namespace_t), intent(in) :: namespace
211 class(space_t), intent(in) :: space
212 type(states_elec_t), intent(in) :: st
213 type(derivatives_t), intent(in) :: der
214 type(multicomm_t), intent(in) :: mc
215 type(stencil_t), intent(in) :: stencil
216 type(kpoints_t), intent(in) :: kpoints
217 type(xc_cam_t), intent(in) :: cam
219 push_sub(exchange_operator_init)
220
221 !%Variable AdaptivelyCompressedExchange
222 !%Type logical
223 !%Default true
224 !%Section Hamiltonian
225 !%Description
226 !% If set to yes, Octopus will use the adaptively compressed exchange
227 !% operator (ACE) for HF and hybrid calculations, as defined in
228 !% Lin, J. Chem. Theory Comput. 2016, 12, 2242.
229 !%
230 !% This is currently ignored for TheoryLevel = rdmft
231 !%End
232 call parse_variable(namespace, 'AdaptivelyCompressedExchange', .true., this%useACE)
233 call messages_print_var_value('AdaptivelyCompressedExchange', this%useACE)
234
235 !%Variable ACEWithISDF
236 !%Type logical
237 !%Default no
238 !%Section ISDF
239 !%Description
240 !% If set to yes, Octopus will use interpolative separable density fitting (ISDF)
241 !% to accelerate the calculation of adaptively compressed exchange in hybrid
242 !% functionals. For more details, please refer to J.Chem.TheoryComput.2017, 13, 5420-5431.
243 !% ISDF is currently only implemented for spin-unpolarized, molecular systems.
244 !%End
245 call parse_variable(namespace, 'ACEWithISDF', .false., this%with_isdf)
246
247 if (this%with_isdf .and. .not. this%useACE) then
248 call messages_input_error(namespace, 'ACEWithISDF', &
249 '"ACEWithISDF = yes" must be used with "AdaptivelyCompressedExchange = yes"')
250 endif
251
252 ! Objs initialised by exchange constructor
253 if (this%useACE) then
254 call this%ace%init(namespace, st)
255 if (this%with_isdf) call this%isdf%init(namespace, space, der%mesh, this%ace%nst)
256 endif
257 call singularity_init(this%singul, namespace, space, st, kpoints)
258 ! exchange_operator_compute_potentials solves the codensities of a whole state block in one
259 ! batched call, so size the cube to hold one block. The active count per call (psib%nst) may be
260 ! smaller than the capacity (the last/partial block), and solvers that cannot batch fall back to
261 ! a per-function loop; both are handled inside X(poisson_solve_batch).
262 call poisson_init(this%psolver, namespace, space, der, mc, stencil, st%qtot, &
263 force_serial = .true., verbose = .false., force_cmplx = .not. states_are_real(st), &
264 fft_batch_size = st%block_size)
265
266 ! Objs initialised by the caller
267 this%cam = cam
270 end subroutine exchange_operator_init
271
272 subroutine exchange_operator_reinit(this, cam, st)
273 type(exchange_operator_t), intent(inout) :: this
274 type(xc_cam_t), intent(in ) :: cam
275 type(states_elec_t), target, optional, intent(in ) :: st
276
278
279 if (present(st)) then
280 this%st => st
281 end if
282
283 this%cam = cam
284
286 end subroutine exchange_operator_reinit
287
288 subroutine exchange_operator_end(this)
289 type(exchange_operator_t), intent(inout) :: this
291 push_sub(exchange_operator_end)
292
293 if (associated(this%st) .and. .not. this%useACE) then
295 call states_elec_end(this%st)
296 safe_deallocate_p(this%st)
297 end if
298 nullify(this%st)
299
300 call this%ace%end()
301 call singularity_end(this%singul)
302 call fourier_space_op_end(coulb)
303 call poisson_end(this%psolver)
304 call this%isdf%end()
305
306 pop_sub(exchange_operator_end)
307 end subroutine exchange_operator_end
308
309 subroutine exchange_operator_rdmft_occ_apply(this, mesh, hpsib)
310 type(exchange_operator_t), intent(in) :: this
311 type(mesh_t), intent(in) :: mesh
312 class(wfs_elec_t), intent(inout) :: hpsib
313
315
316 ! multiply linear terms in hamiltonian with occupation number
317 ! nonlinear occupation number dependency occurs only in the exchange, which is treated there
318 call batch_scal(mesh%np, this%st%occ(:, hpsib%ik), hpsib)
319
322
323 subroutine exchange_operator_write_info(this, namespace)
324 class(exchange_operator_t), intent(in) :: this
325 type(namespace_t), intent(in) :: namespace
326
328
329 call messages_print_with_emphasis(msg='Exact Exchange', namespace=namespace)
330 call messages_print_var_value("Adaptively compressed exchange", this%useACE, namespace=namespace)
331 if (this%useACE) then
332 call this%ace%write_info(namespace)
333 if (this%with_isdf) then
334 call messages_print_var_value("Density Fitting in ACE with ISDF", this%with_isdf, namespace=namespace)
335 call this%isdf%write_info(namespace)
336 endif
337 endif
338
340
341 end subroutine exchange_operator_write_info
342
343
344#include "undef.F90"
345#include "real.F90"
346#include "exchange_operator_inc.F90"
347
348#include "undef.F90"
349#include "complex.F90"
350#include "exchange_operator_inc.F90"
351
353
354!! Local Variables:
355!! mode: f90
356!! coding: utf-8
357!! End:
scale a batch by a constant or vector
Definition: batch_ops.F90:167
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 contains interfaces for BLAS routines You should not use these routines directly....
Definition: blas.F90:120
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)
Construct the ACE vectors.
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)
Construct the ACE vectors.
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.
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:120
integer, parameter, public fftlib_accel
Definition: fft.F90:179
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:898
character(len=512), private msg
Definition: messages.F90:167
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_input_error(namespace, var, details, row, column)
Definition: messages.F90:691
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
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, fft_batch_size)
Definition: poisson.F90:236
subroutine, public poisson_end(this)
Definition: poisson.F90:692
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
subroutine, public dsymmetrizer_apply_batch(this, mesh, iop, src, dst)
Symmetrize a whole batch, returning another batch with the same layout.
subroutine, public zsymmetrizer_apply_batch(this, mesh, iop, src, dst)
Symmetrize a whole batch, returning another batch with the same layout.
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
Stores all communicators and groups.
Definition: multicomm.F90:208
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)