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
34 use math_oct_m
35 use mesh_oct_m
39 use mpi_oct_m
43 use parser_oct_m
44 use phase_oct_m
49 use space_oct_m
57 use unit_oct_m
60 use xc_cam_oct_m
61
62 implicit none
63
64 private
65 public :: &
85
86 type ace_t
87 integer :: nst
88 real(real64), allocatable :: dchi(:,:,:,:)
89 complex(real64), allocatable :: zchi(:,:,:,:)
90 contains
91 procedure :: init => ace_init
92 procedure :: end => ace_end
93 end type ace_t
94
96 type(states_elec_t), public, pointer :: st => null()
97 type(xc_cam_t) :: cam
98 type(poisson_t) :: psolver
99 type(singularity_t) :: singul
100 logical :: useACE = .false.
101 type(ACE_t) :: ace
102 end type exchange_operator_t
103
104 type(fourier_space_op_t) :: coulb
105 ! Saved as we avoid then to recompute it,
106 ! for instance in the case of CAM functionals in isolated systems
107
108 real(real64), parameter, private :: TOL_EXX_WEIGHT = 1.0e-3_real64
109
110contains
111
113 subroutine ace_init(this, namespace, st)
114 class(ACE_t), intent(inout) :: this
115 type(namespace_t), intent(in) :: namespace
116 type(states_elec_t), intent(in ) :: st
117
118 push_sub(ace_init)
119
120 !%Variable ACESize
121 !%Type integer
122 !%Default All states
123 !%Section Hamiltonian
124 !%Description
125 !% (Experimental) The number of ACE projection vectors (i.e. the size of the test-orbital set) and hence the dimension of the
126 !% subspace on which the low-rank ACE operator is (approximately) exact. By default, Octopus sets this to the
127 !% number of states requested for a calculation (all states), which is essential when the band gap is of interest.
128 !% For development purposes, if only occupied states are required, the user can set this value manually.
129 !% For more information, see Lin, J. Chem. Theory Comput. 2016, 12, 2242.
130 !%End
131 call parse_variable(namespace, 'ACESize', st%nst, this%nst)
132
133 if (this%nst > st%nst) then
134 call messages_input_error(namespace, 'ACESize', "Exceeds the total number of states available")
135 endif
136
137 if (this%nst < st%nst) then
138 call messages_experimental("Adaptively-compressed exchange defined with a subset of states", namespace=namespace)
139 endif
140
141 if (this%nst * st%smear%el_per_state < st%qtot) then
142 write(message(1),'(a)') "ACESize should at least equal the number of occupied states."
143 call messages_warning(1, namespace=namespace)
144 endif
145
146 ! dchi/zchi are allocated at their point of use.
147
148 pop_sub(ace_init)
149
150 end subroutine ace_init
151
153 subroutine ace_end(this)
154 class(ACE_t), intent(inout) :: this
155
156 push_sub(ace_end)
157
158 this%nst = 0
159 safe_deallocate_a(this%dchi)
160 safe_deallocate_a(this%zchi)
161
162 pop_sub(ace_end)
163
164 end subroutine ace_end
165
166 subroutine exchange_operator_init(this, namespace, space, st, der, mc, stencil, kpoints, cam)
167 type(exchange_operator_t), intent(inout) :: this
168 type(namespace_t), intent(in) :: namespace
169 class(space_t), intent(in) :: space
170 type(states_elec_t), intent(in) :: st
171 type(derivatives_t), intent(in) :: der
172 type(multicomm_t), intent(in) :: mc
173 type(stencil_t), intent(in) :: stencil
174 type(kpoints_t), intent(in) :: kpoints
175 type(xc_cam_t), intent(in) :: cam
176
177 push_sub(exchange_operator_init)
178
179 this%cam = cam
181 !%Variable AdaptivelyCompressedExchange
182 !%Type logical
183 !%Default false
184 !%Section Hamiltonian
185 !%Description
186 !% If set to yes, Octopus will use the adaptively compressed exchange
187 !% operator (ACE) for HF and hybrid calculations, as defined in
188 !% Lin, J. Chem. Theory Comput. 2016, 12, 2242.
189 !%
190 !% This is currenly ignored for TheoryLevel = rdmft
191 !%End
192 call parse_variable(namespace, 'AdaptivelyCompressedExchange', .true., this%useACE)
193 call messages_print_var_value('AdaptivelyCompressedExchange', this%useACE)
194 if (this%useACE) call this%ace%init(namespace, st)
195
196 call singularity_init(this%singul, namespace, space, st, kpoints)
197 if (states_are_real(st)) then
198 call poisson_init(this%psolver, namespace, space, der, mc, stencil, st%qtot, &
199 force_serial = .true., verbose = .false.)
200 else
201 call poisson_init(this%psolver, namespace, space, der, mc, stencil, st%qtot, &
202 force_serial = .true., verbose = .false., force_cmplx = .true.)
203 end if
204
207
208 subroutine exchange_operator_reinit(this, cam, st)
209 type(exchange_operator_t), intent(inout) :: this
210 type(xc_cam_t), intent(in ) :: cam
211 type(states_elec_t), target, optional, intent(in ) :: st
212
214
215 if (present(st)) then
216 this%st => st
217 end if
218
219 this%cam = cam
220
222 end subroutine exchange_operator_reinit
223
224 subroutine exchange_operator_end(this)
225 type(exchange_operator_t), intent(inout) :: this
226
227 push_sub(exchange_operator_end)
228
229 if (associated(this%st) .and. .not. this%useACE) then
231 call states_elec_end(this%st)
232 safe_deallocate_p(this%st)
233 end if
234 nullify(this%st)
235
236 call this%ace%end()
237 call singularity_end(this%singul)
238 call fourier_space_op_end(coulb)
239 call poisson_end(this%psolver)
240
241 pop_sub(exchange_operator_end)
242 end subroutine exchange_operator_end
243
244 subroutine exchange_operator_rdmft_occ_apply(this, mesh, hpsib)
245 type(exchange_operator_t), intent(in) :: this
246 type(mesh_t), intent(in) :: mesh
247 class(wfs_elec_t), intent(inout) :: hpsib
248
250
251 ! multiply linear terms in hamiltonian with occupation number
252 ! nonlinear occupation number dependency occurs only in the exchange, which is treated there
253 call batch_scal(mesh%np, this%st%occ(:, hpsib%ik), hpsib)
254
257
258
259#include "undef.F90"
260#include "real.F90"
261#include "exchange_operator_inc.F90"
262
263#include "undef.F90"
264#include "complex.F90"
265#include "exchange_operator_inc.F90"
266
268
269!! Local Variables:
270!! mode: f90
271!! coding: utf-8
272!! End:
scale a batch by a constant or vector
Definition: batch_ops.F90:162
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:180
This module implements batches of mesh functions.
Definition: batch.F90:133
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:116
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_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, 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:117
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:115
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:116
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:118
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:537
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:713
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1085
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:145
Some general things and nomenclature:
Definition: par_vec.F90:171
subroutine, public poisson_init(this, namespace, space, der, mc, stencil, qtot, label, solver, verbose, force_serial, force_cmplx)
Definition: poisson.F90:234
subroutine, public poisson_end(this)
Definition: poisson.F90:710
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:135
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
This module defines the unit system, used for input and output.
Describes mesh distribution to nodes.
Definition: mesh.F90:186
The states_elec_t class contains all electronic wave functions.
batches of electronic states
Definition: wfs_elec.F90:139
Coulomb-attenuating method parameters, used in the partitioning of the Coulomb potential into a short...
Definition: xc_cam.F90:139
int true(void)