Octopus
nlcc.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
22module nlcc_oct_m
23 use atom_oct_m
24 use comm_oct_m
25 use debug_oct_m
29 use global_oct_m
32 use ions_oct_m
34 use mesh_oct_m
39 use ps_oct_m
42 use space_oct_m
47
48 implicit none
49
50 private
51 public :: &
52 nlcc_t
53
54 type, extends(density_interaction_t) :: nlcc_t
55 private
56
57 type(mesh_t), pointer :: mesh => null()
58 type(space_t), pointer :: space => null()
59
60 ! This information should be copied, and not obtained thanks to pointer
61 ! This is a temporary change here
62 type(distributed_t), pointer, public :: atoms_dist => null()
63 type(atom_t), pointer, public :: atom(:) => null()
64 real(real64), pointer, public :: pos(:,:) => null()
65 type(lattice_vectors_t), pointer :: latt => null()
66
69 type(double_grid_t) :: dgrid
70 type(distributed_t), pointer :: atoms_dist_plane => null()
71
72 contains
73 procedure :: init => nlcc_init
74 procedure :: bind => nlcc_bind
75 procedure :: calculate => nlcc_calculate
76 procedure :: calculate_energy => nlcc_calculate_energy
77 procedure :: end => nlcc_end
78 final :: nlcc_finalize
79 end type nlcc_t
80
81 interface nlcc_t
82 module procedure nlcc_constructor
83 end interface nlcc_t
84
85contains
86
87 ! ---------------------------------------------------------
88 function nlcc_constructor(partner) result(this)
89 class(interaction_partner_t), target, intent(inout) :: partner
90 class(nlcc_t), pointer :: this
91
92 push_sub(nlcc_constructor)
93
94 allocate(this)
95
96 this%label = "nlcc"
97
98 this%partner => partner
99
100 pop_sub(nlcc_constructor)
101 end function nlcc_constructor
102
103 ! ---------------------------------------------------------
104 subroutine nlcc_init(this, mesh, ions, dgrid, atoms_dist_plane)
105 class(nlcc_t), intent(inout) :: this
106 class(mesh_t), target, intent(in) :: mesh
107 type(ions_t), target, intent(in) :: ions
108 type(double_grid_t), optional, intent(in) :: dgrid
109 type(distributed_t), optional, target, intent(in) :: atoms_dist_plane
110
111 push_sub(nlcc_init)
112
113 this%mesh => mesh
114
115 safe_allocate(this%density(1:mesh%np,1))
116
117 this%atoms_dist => ions%atoms_dist
118 this%atom => ions%atom
119 this%space => ions%space
120 this%pos => ions%pos
121 this%latt => ions%latt
122
123 if (present(dgrid)) this%dgrid = dgrid
124 if (present(atoms_dist_plane)) this%atoms_dist_plane => atoms_dist_plane
125
126 pop_sub(nlcc_init)
127 end subroutine nlcc_init
128
129 ! ---------------------------------------------------------
132 subroutine nlcc_bind(this, ions)
133 class(nlcc_t), intent(inout) :: this
134 type(ions_t), target, intent(in) :: ions
136 push_sub(nlcc_bind)
138 this%atoms_dist => ions%atoms_dist
139 this%atom => ions%atom
140 this%space => ions%space
141 this%pos => ions%pos
142 this%latt => ions%latt
143
144 pop_sub(nlcc_bind)
145 end subroutine nlcc_bind
147 ! ---------------------------------------------------------
148 subroutine nlcc_calculate(this)
149 class(nlcc_t), intent(inout) :: this
151 integer :: ia, ia_start, ia_end
152
153 push_sub(nlcc_calculate)
154
155 call profiling_in("NLCC_INTER")
156
157 this%density(:,:) = m_zero
158
159 ! The per-atom placements are distributed with the shared epot-owned plane
160 ! distribution; its start/end cover all atoms when it is not parallel, and no
161 ! reduction must follow in that case. Without the shared distribution the
162 ! atoms_dist path is used, as before.
163 if (associated(this%atoms_dist_plane)) then
164 ia_start = this%atoms_dist_plane%start
165 ia_end = this%atoms_dist_plane%end
166 else
167 ia_start = this%atoms_dist%start
168 ia_end = this%atoms_dist%end
169 end if
170
171 do ia = ia_start, ia_end
172 if (this%atom(ia)%species%is_ps_with_nlcc()) then
173 call species_get_nlcc(this%atom(ia)%species, this%space, this%latt, this%pos(:, ia), this%mesh, &
174 this%density(:,1), accumulate=.true., dgrid=this%dgrid)
175 end if
176 end do
177
178 ! reduce over atoms if required
179 if (associated(this%atoms_dist_plane)) then
180 if (this%atoms_dist_plane%parallel) then
181 call comm_allreduce(this%atoms_dist_plane%mpi_grp, this%density(:,1))
182 end if
183 else if (this%atoms_dist%parallel) then
184 call comm_allreduce(this%atoms_dist%mpi_grp, this%density(:,1))
185 end if
186
187 call profiling_out("NLCC_INTER")
188
189 pop_sub(nlcc_calculate)
190 end subroutine nlcc_calculate
191
192 ! ---------------------------------------------------------
193 subroutine nlcc_end(this)
194 class(nlcc_t), intent(inout) :: this
195
196 push_sub(nlcc_end)
197
198 safe_deallocate_a(this%density)
199 nullify(this%mesh)
200 call double_grid_end(this%dgrid)
201
202 call interaction_end(this)
203
204 pop_sub(nlcc_end)
205 end subroutine nlcc_end
206
207
208 ! ---------------------------------------------------------
209 subroutine nlcc_finalize(this)
210 type(nlcc_t), intent(inout) :: this
211
212 push_sub(nlcc_finalize)
213
214 call nlcc_end(this)
215
216 pop_sub(nlcc_finalize)
217 end subroutine nlcc_finalize
218
219 ! ---------------------------------------------------------
220 subroutine nlcc_calculate_energy(this)
221 class(nlcc_t), intent(inout) :: this
222
223 push_sub(nlcc_calculate_energy)
224
225 !NLCC has no energy by itself. The energy is obtained through exchange and correlation
226
227 this%energy = m_zero
228
229 pop_sub(nlcc_calculate_energy)
230 end subroutine nlcc_calculate_energy
231
232end module nlcc_oct_m
233
234!! Local Variables:
235!! mode: f90
236!! coding: utf-8
237!! End:
The Ono-Hirose double-grid technique [T. Ono and K. Hirose, Phys. Rev. Lett. 82, 5016 (1999); Phys....
subroutine, public double_grid_end(this)
real(real64), parameter, public m_zero
Definition: global.F90:173
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.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
subroutine nlcc_end(this)
Definition: nlcc.F90:266
subroutine nlcc_calculate(this)
Definition: nlcc.F90:221
subroutine nlcc_finalize(this)
Definition: nlcc.F90:282
subroutine nlcc_init(this, mesh, ions, dgrid, atoms_dist_plane)
Definition: nlcc.F90:177
class(nlcc_t) function, pointer nlcc_constructor(partner)
Definition: nlcc.F90:161
subroutine nlcc_calculate_energy(this)
Definition: nlcc.F90:293
subroutine nlcc_bind(this, ions)
Rebind NLCC helper pointers after copying the ionic geometry. The movers in NLCC reference ionic arra...
Definition: nlcc.F90:205
/* 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_nlcc(species, space, latt, pos, mesh, rho_core, accumulate, dgrid)
int true(void)