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
32 use global_oct_m
33 use grid_oct_m
38 use math_oct_m
39 use mesh_oct_m
43 use mpi_oct_m
47 use parser_oct_m
48 use phase_oct_m
53 use space_oct_m
61 use types_oct_m
62 use unit_oct_m
65 use xc_cam_oct_m
66
67 implicit none
68
69 private
70 public :: &
90
91 type ace_t
92 integer :: nst
93 real(real64), allocatable :: dchi(:,:,:,:)
94 complex(real64), allocatable :: zchi(:,:,:,:)
95 type(wfs_elec_t), allocatable :: chib(:)
96 ! one batch per k-point (kpt%start:kpt%end), used to
97 ! apply the operator with GEMMs while keeping the
98 ! wavefunctions resident on the GPU. dchi/zchi above
99 ! remain the reference host copy.
100 contains
101 procedure :: init => ace_init
102 procedure :: end => ace_end
103 procedure :: write_info => ace_write_info
104 end type ace_t
105
106
108 type(states_elec_t), public, pointer :: st => null()
109 type(xc_cam_t) :: cam
110 type(poisson_t) :: psolver
111 type(singularity_t) :: singul
112 logical :: useACE
113 logical :: with_isdf
114 type(ACE_t) :: ace
115 type(isdf_options_t) :: isdf
116 contains
117 procedure :: write_info => exchange_operator_write_info
118 end type exchange_operator_t
119
120
121 type(fourier_space_op_t) :: coulb
122 ! Saved as we avoid then to recompute it,
123 ! for instance in the case of CAM functionals in isolated systems
124
125 real(real64), parameter, private :: TOL_EXX_WEIGHT = 1.0e-3_real64
126
127contains
128
130 subroutine ace_init(this, namespace, st)
131 class(ACE_t), intent(inout) :: this
132 type(namespace_t), intent(in) :: namespace
133 type(states_elec_t), intent(in ) :: st
134
135 push_sub(ace_init)
136
137 !%Variable ACESize
138 !%Type integer
139 !%Default All states
140 !%Section Hamiltonian
141 !%Description
142 !% (Experimental) The number of ACE projection vectors (i.e. the size of the test-orbital set) and hence the dimension of the
143 !% subspace on which the low-rank ACE operator is (approximately) exact. By default, Octopus sets this to the
144 !% number of states requested for a calculation (all states), which is essential when the band gap is of interest.
145 !% For development purposes, if only occupied states are required, the user can set this value manually.
146 !% For more information, see Lin, J. Chem. Theory Comput. 2016, 12, 2242.
147 !%End
148 call parse_variable(namespace, 'ACESize', st%nst, this%nst)
149
150 if (this%nst > st%nst) then
151 call messages_input_error(namespace, 'ACESize', "Exceeds the total number of states available")
152 endif
153
154 if (this%nst < st%nst) then
155 call messages_experimental("Adaptively-compressed exchange defined with a subset of states", namespace=namespace)
156 endif
157
158 if (this%nst * st%smear%el_per_state < st%qtot) then
159 write(message(1),'(a)') "ACESize should at least equal the number of occupied states."
160 call messages_warning(1, namespace=namespace)
161 endif
162
163 ! dchi/zchi are allocated at their point of use.
164
165 pop_sub(ace_init)
166
167 end subroutine ace_init
168
170 subroutine ace_end(this)
171 class(ACE_t), intent(inout) :: this
172
173 integer :: ik
174
175 push_sub(ace_end)
176
177 this%nst = 0
178 safe_deallocate_a(this%dchi)
179 safe_deallocate_a(this%zchi)
180
181 if (allocated(this%chib)) then
182 do ik = lbound(this%chib, 1), ubound(this%chib, 1)
183 call this%chib(ik)%end()
184 end do
185 safe_deallocate_a(this%chib)
186 end if
188 pop_sub(ace_end)
190 end subroutine ace_end
191
192 subroutine ace_write_info(this, namespace)
193 class(ace_t), intent(in) :: this
194 type(namespace_t), intent(in) :: namespace
195
198 call messages_print_var_value("Dimension of the subspace in which the low-rank ACE operator is"// &
199 & " approximately exact (ACESize)", this%nst, namespace=namespace)
200
201 pop_sub(ace_write_info)
203 end subroutine ace_write_info
205 subroutine exchange_operator_init(this, namespace, space, st, der, mc, stencil, kpoints, cam)
206 type(exchange_operator_t), intent(inout) :: this
207 type(namespace_t), intent(in) :: namespace
208 class(space_t), intent(in) :: space
209 type(states_elec_t), intent(in) :: st
210 type(derivatives_t), intent(in) :: der
211 type(multicomm_t), intent(in) :: mc
212 type(stencil_t), intent(in) :: stencil
213 type(kpoints_t), intent(in) :: kpoints
214 type(xc_cam_t), intent(in) :: cam
215
217
218 !%Variable AdaptivelyCompressedExchange
219 !%Type logical
220 !%Default true
221 !%Section Hamiltonian
222 !%Description
223 !% If set to yes, Octopus will use the adaptively compressed exchange
224 !% operator (ACE) for HF and hybrid calculations, as defined in
225 !% Lin, J. Chem. Theory Comput. 2016, 12, 2242.
226 !%
227 !% This is currently ignored for TheoryLevel = rdmft
228 !%End
229 call parse_variable(namespace, 'AdaptivelyCompressedExchange', .true., this%useACE)
230 call messages_print_var_value('AdaptivelyCompressedExchange', this%useACE)
231
232 !%Variable ACEWithISDF
233 !%Type logical
234 !%Default no
235 !%Section ISDF
236 !%Description
237 !% If set to yes, Octopus will use interpolative separable density fitting (ISDF)
238 !% to accelerate the calculation of adaptively compressed exchange in hybrid
239 !% functionals. For more details, please refer to J.Chem.TheoryComput.2017, 13, 5420-5431.
240 !% ISDF is currently only implemented for spin-unpolarized, molecular systems.
241 !%End
242 call parse_variable(namespace, 'ACEWithISDF', .false., this%with_isdf)
243
244 if (this%with_isdf .and. .not. this%useACE) then
245 call messages_input_error(namespace, 'ACEWithISDF', &
246 '"ACEWithISDF = yes" must be used with "AdaptivelyCompressedExchange = yes"')
247 endif
248
249 ! Objs initialised by exchange constructor
250 if (this%useACE) then
251 call this%ace%init(namespace, st)
252 if (this%with_isdf) call this%isdf%init(namespace, space, der%mesh, this%ace%nst)
253 endif
254 call singularity_init(this%singul, namespace, space, st, kpoints)
255 call poisson_init(this%psolver, namespace, space, der, mc, stencil, st%qtot, &
256 force_serial = .true., verbose = .false., force_cmplx = .not. states_are_real(st))
257
258 ! Objs initialised by the caller
259 this%cam = cam
260
262 end subroutine exchange_operator_init
263
264 subroutine exchange_operator_reinit(this, cam, st)
265 type(exchange_operator_t), intent(inout) :: this
266 type(xc_cam_t), intent(in ) :: cam
267 type(states_elec_t), target, optional, intent(in ) :: st
268
270
271 if (present(st)) then
272 this%st => st
273 end if
274
275 this%cam = cam
276
278 end subroutine exchange_operator_reinit
279
280 subroutine exchange_operator_end(this)
281 type(exchange_operator_t), intent(inout) :: this
282
283 push_sub(exchange_operator_end)
284
285 if (associated(this%st) .and. .not. this%useACE) then
287 call states_elec_end(this%st)
288 safe_deallocate_p(this%st)
289 end if
290 nullify(this%st)
291
292 call this%ace%end()
293 call singularity_end(this%singul)
294 call fourier_space_op_end(coulb)
295 call poisson_end(this%psolver)
296 call this%isdf%end()
297
298 pop_sub(exchange_operator_end)
299 end subroutine exchange_operator_end
301 subroutine exchange_operator_rdmft_occ_apply(this, mesh, hpsib)
302 type(exchange_operator_t), intent(in) :: this
303 type(mesh_t), intent(in) :: mesh
304 class(wfs_elec_t), intent(inout) :: hpsib
305
307
308 ! multiply linear terms in hamiltonian with occupation number
309 ! nonlinear occupation number dependency occurs only in the exchange, which is treated there
310 call batch_scal(mesh%np, this%st%occ(:, hpsib%ik), hpsib)
311
314
315 subroutine exchange_operator_write_info(this, namespace)
316 class(exchange_operator_t), intent(in) :: this
317 type(namespace_t), intent(in) :: namespace
318
320
321 call messages_print_with_emphasis(msg='Exact Exchange', namespace=namespace)
322 call messages_print_var_value("Adaptively compressed exchange", this%useACE, namespace=namespace)
323 if (this%useACE) then
324 call this%ace%write_info(namespace)
325 if (this%with_isdf) then
326 call messages_print_var_value("Density Fitting in ACE with ISDF", this%with_isdf, namespace=namespace)
327 call this%isdf%write_info(namespace)
328 endif
329 endif
330
332
333 end subroutine exchange_operator_write_info
334
335
336#include "undef.F90"
337#include "real.F90"
338#include "exchange_operator_inc.F90"
339
340#include "undef.F90"
341#include "complex.F90"
342#include "exchange_operator_inc.F90"
343
345
346!! Local Variables:
347!! mode: f90
348!! coding: utf-8
349!! 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)
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: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)
Definition: poisson.F90:232
subroutine, public poisson_end(this)
Definition: poisson.F90:679
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
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)