Octopus
ion_electron_local_potential.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2021 Nicolas Tancogne-Dejean
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
23 use atom_oct_m
24 use comm_oct_m
25 use debug_oct_m
28 use epot_oct_m
29 use global_oct_m
32 use ions_oct_m
33 use, intrinsic :: iso_fortran_env
36 use mesh_oct_m
42 use ps_oct_m
45 use space_oct_m
51
52 implicit none
53
54 private
55 public :: &
57
59 private
60
61 type(poisson_t), pointer :: psolver
62 type(mesh_t), pointer :: mesh
63 type(space_t), pointer :: space
64
65 ! This information should be copied, and not obtained thanks to pointer
66 ! This is a temporary change here
67 type(distributed_t), pointer, public :: atoms_dist => null()
68 type(atom_t), pointer, public :: atom(:) => null()
69 real(real64), pointer, public :: pos(:,:) => null()
70 type(lattice_vectors_t), pointer :: latt => null()
71
72 ! Temporary pointer to namespace
73 type(namespace_t), pointer :: namespace
74
75 logical :: have_density
76
79 type(double_grid_t) :: dgrid
84 type(distributed_t), pointer :: atoms_dist_plane => null()
85
86 contains
87 procedure :: init => ion_electron_local_potential_init
88 procedure :: bind => ion_electron_local_potential_bind
89 procedure :: calculate => ion_electron_local_potential_calculate
90 procedure :: calculate_energy => ion_electron_local_potential_calculate_energy
91 procedure :: end => ion_electron_local_potential_end
98
99contains
100
101 ! ---------------------------------------------------------
102 function ion_electron_local_potential_constructor(partner) result(this)
103 class(interaction_partner_t), target, intent(inout) :: partner
104 class(ion_electron_local_potential_t), pointer :: this
105
107
108 allocate(this)
109
110 this%label = "ion-electron local"
111
112 this%partner => partner
113
116
117 ! ---------------------------------------------------------
118 subroutine ion_electron_local_potential_init(this, mesh, psolver, ions, namespace, dgrid, atoms_dist_plane)
119 class(ion_electron_local_potential_t), intent(inout) :: this
120 class(mesh_t), target, intent(in) :: mesh
121 type(poisson_t), target, intent(in) :: psolver
122 type(ions_t), target, intent(in) :: ions
123 type(namespace_t), target, intent(in) :: namespace
125 type(double_grid_t), optional, intent(in) :: dgrid
127 type(distributed_t), optional, target, intent(in) :: atoms_dist_plane
128
129 integer :: ia
132
133 this%mesh => mesh
134 this%psolver => psolver
136 if (present(dgrid)) this%dgrid = dgrid
137 if (present(atoms_dist_plane)) this%atoms_dist_plane => atoms_dist_plane
138
139 safe_allocate(this%potential(1:mesh%np, 1))
141 this%have_density = .false.
142 do ia = 1, ions%nspecies
143 if (local_potential_has_density(ions%space, ions%species(ia)%s)) then
144 this%have_density = .true.
145 exit
146 end if
147 end do
148
149 this%atoms_dist => ions%atoms_dist
150 this%atom => ions%atom
151 this%space => ions%space
152 this%pos => ions%pos
153 this%latt => ions%latt
154
155 this%namespace => namespace
160 ! ---------------------------------------------------------
163 subroutine ion_electron_local_potential_bind(this, psolver, ions)
164 class(ion_electron_local_potential_t), intent(inout) :: this
165 type(poisson_t), target, intent(in) :: psolver
166 type(ions_t), target, intent(in) :: ions
167
169
170 this%psolver => psolver
171 this%atoms_dist => ions%atoms_dist
172 this%atom => ions%atom
173 this%space => ions%space
174 this%pos => ions%pos
175 this%latt => ions%latt
176
179
180 ! ---------------------------------------------------------
181 ! Note: this code is adapted from epot_local_potential. There are code duplication at the moment
183 class(ion_electron_local_potential_t), intent(inout) :: this
184
185 real(real64), allocatable :: density(:), rho(:), vl(:)
186 type(submesh_t) :: sphere
187 integer :: ia, ia_start, ia_end
188
191 call profiling_in("ION_ELEC_LOC_INTER")
192
193 this%potential(:,1) = m_zero
194
195 if (this%have_density) then
196 safe_allocate(density(1:this%mesh%np))
197 density = m_zero
198 end if
199
200 ! The per-atom placements are distributed with the shared epot-owned plane
201 ! distribution; its start/end cover all atoms when it is not parallel, and no
202 ! reduction must follow in that case. Without the shared distribution the
203 ! atoms_dist path is used, as before.
204 if (associated(this%atoms_dist_plane)) then
205 ia_start = this%atoms_dist_plane%start
206 ia_end = this%atoms_dist_plane%end
207 else
208 ia_start = this%atoms_dist%start
209 ia_end = this%atoms_dist%end
210 end if
211
212 do ia = ia_start, ia_end
213 ! Local potential, we can get it by solving the Poisson equation
214 ! (for all-electron species or pseudopotentials in periodic
215 ! systems) or by applying it directly to the grid
216
217 if (local_potential_has_density(this%space, this%atom(ia)%species)) then
218
219 safe_allocate(rho(1:this%mesh%np))
220 call species_get_long_range_density(this%atom(ia)%species, this%namespace, this%space, this%latt, &
221 this%pos(:, ia), this%mesh, rho, sphere)
222 call lalg_axpy(this%mesh%np, m_one, rho, density)
223 safe_deallocate_a(rho)
224
225 else
226
227 safe_allocate(vl(1:this%mesh%np))
228 call species_get_local(this%atom(ia)%species, this%namespace, this%space, this%latt, &
229 this%pos(:, ia), this%mesh, vl)
230 call lalg_axpy(this%mesh%np, m_one, vl, this%potential(:,1))
231 safe_deallocate_a(vl)
232
233 end if
234
235 ! then we add the localized part, with the double-grid transform when enabled so
236 ! vpsl is consistent with the transformed projectors, forces and stress
237 call species_get_local_sr(this%atom(ia)%species, this%space, this%latt, this%pos(:, ia), &
238 this%mesh, sphere, this%potential(:,1), this%dgrid)
239 call submesh_end(sphere)
240 end do
241
242 ! reduce over atoms if required
243 if (associated(this%atoms_dist_plane)) then
244 if (this%atoms_dist_plane%parallel) then
245 call comm_allreduce(this%atoms_dist_plane%mpi_grp, this%potential(:,1), dim = this%mesh%np)
246 if (this%have_density) then
247 call comm_allreduce(this%atoms_dist_plane%mpi_grp, density, dim = this%mesh%np)
248 end if
249 end if
250 else if (this%atoms_dist%parallel) then
251 call comm_allreduce(this%atoms_dist%mpi_grp, this%potential(:,1), dim = this%mesh%np)
252 if (this%have_density) then
253 call comm_allreduce(this%atoms_dist%mpi_grp, density, dim = this%mesh%np)
254 end if
255 end if
256
257 ! now we solve the poisson equation with the density of all nodes
258 if (this%have_density) then
259
260 safe_allocate(vl(1:this%mesh%np_part))
261 call dpoisson_solve(this%psolver, this%namespace, vl, density)
262 call lalg_axpy(this%mesh%np, m_one, vl, this%potential(:,1))
263 safe_deallocate_a(vl)
264
265 end if
266 safe_deallocate_a(density)
267
268 call profiling_out("ION_ELEC_LOC_INTER")
269
272
273 ! ---------------------------------------------------------
274 subroutine ion_electron_local_potential_end(this)
275 class(ion_electron_local_potential_t), intent(inout) :: this
276
278
279 safe_deallocate_a(this%potential)
280 nullify(this%mesh)
281 nullify(this%psolver)
282
283 call interaction_end(this)
284
287
288
289 ! ---------------------------------------------------------
291 type(ion_electron_local_potential_t), intent(inout) :: this
292
294
296
299
300 ! ---------------------------------------------------------
302 class(ion_electron_local_potential_t), intent(inout) :: this
303
305
307 assert(.false.)
308
310
312
313
315
316!! Local Variables:
317!! mode: f90
318!! coding: utf-8
319!! End:
constant times a vector plus a vector
Definition: lalg_basic.F90:171
The Ono-Hirose double-grid technique [T. Ono and K. Hirose, Phys. Rev. Lett. 82, 5016 (1999); Phys....
logical pure function, public local_potential_has_density(space, species)
Definition: epot.F90:772
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_one
Definition: global.F90:174
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.
class(ion_electron_local_potential_t) function, pointer ion_electron_local_potential_constructor(partner)
subroutine ion_electron_local_potential_bind(this, psolver, ions)
Rebind ion-electron local potential helper pointers after a Hamiltonian copy. Ensure the local potent...
subroutine ion_electron_local_potential_init(this, mesh, psolver, ions, namespace, dgrid, atoms_dist_plane)
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
Definition: poisson.F90:909
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:672
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:604
Definition: ps.F90:93
This module defines the quantity_t class and the IDs for quantities, which can be exposed by a system...
Definition: quantity.F90:117
subroutine, public species_get_local(species, namespace, space, latt, pos, mesh, vl)
used when the density is not available, or otherwise the Poisson eqn would be used instead
subroutine, public species_get_long_range_density(species, namespace, space, latt, pos, mesh, rho, sphere_inout, nlr_x)
subroutine, public species_get_local_sr(species, space, latt, pos, mesh, sphere, vpsl, dgrid)
Accumulate the short-range (localized) part of the local pseudopotential of one atom into vpsl,...
subroutine, public submesh_end(this)
Definition: submesh.F90:693
A submesh is a type of mesh, used for the projectors in the pseudopotentials It contains points on a ...
Definition: submesh.F90:154
int true(void)