Octopus
states_elec_calc.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
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#ifndef NDEBUG
23 use, intrinsic :: ieee_exceptions
24#endif
25 use accel_oct_m
27 use batch_oct_m
29 use blas_oct_m
30 use blacs_oct_m
31 use iso_c_binding
32 use comm_oct_m
33 use debug_oct_m
37 use global_oct_m
38 use grid_oct_m
43 use math_oct_m
45 use mesh_oct_m
48 use mpi_oct_m
53 use phase_oct_m
54 use pblas_oct_m
59 use space_oct_m
64 use types_oct_m
66
67 implicit none
68
69 private
70
71 public :: &
96
97 interface states_elec_rotate
99 end interface states_elec_rotate
100
101contains
102
103 ! ---------------------------------------------------------
105 subroutine states_elec_orthogonalize(st, namespace, mesh)
106 type(states_elec_t), intent(inout) :: st
107 type(namespace_t), intent(in) :: namespace
108 class(mesh_t), intent(in) :: mesh
109
110 integer :: ik
111
113
114 do ik = st%d%kpt%start, st%d%kpt%end
115 if (states_are_real(st)) then
116 call dstates_elec_orthogonalization_full(st, namespace, mesh, ik)
117 else
118 call zstates_elec_orthogonalization_full(st, namespace, mesh, ik)
119 end if
120 end do
121
123 end subroutine states_elec_orthogonalize
124
125 ! ---------------------------------------------------------
127 !
128 subroutine states_elec_calc_norms(grid, kpoints, st, norm_ks, aug_overlap, phase)
129 type(grid_t), intent(in) :: grid
130 type(kpoints_t), intent(in) :: kpoints
131 type(states_elec_t), intent(in) :: st
132 real(real64), contiguous, intent(out) :: norm_ks(:, :)
133 type(nonlocal_pseudopotential_t), optional, intent(in) :: aug_overlap
134 type(phase_t), optional, intent(in) :: phase
135
136 integer :: ik_ispin, iblock, minst, maxst
137 type(wfs_elec_t) :: spsib
138 complex(real64), allocatable :: sdiag(:)
139
140 push_sub(states_elec_calc_norms)
141
142 ! If state or k is parallel, norm_ks is only partially touched, then gets summed over processes,
143 ! hence initialise to zero
144 norm_ks = m_zero
145
146 ! For ultrasoft/PAW the physical norm is the generalized one, sqrt(<psi_i|S|psi_i>).
147 assert(.not. (present(aug_overlap) .and. states_are_real(st)))
148
149 do ik_ispin = st%d%kpt%start, st%d%kpt%end
150 do iblock = st%group%block_start, st%group%block_end
151 minst = states_elec_block_min(st, iblock)
152 maxst = states_elec_block_max(st, iblock)
153 if (present(aug_overlap)) then
154 ! Generalized norm: norm_ks(i) = sqrt(<psi_i|S psi_i>)
155 call st%group%psib(iblock, ik_ispin)%copy_to(spsib)
156 call znonlocal_pseudopotential_apply_overlap(aug_overlap, grid, st%d, &
157 st%group%psib(iblock, ik_ispin), spsib, phase=phase)
158 safe_allocate(sdiag(minst:maxst))
159 call zmesh_batch_dotp_vector(grid, st%group%psib(iblock, ik_ispin), spsib, sdiag, reduce=.false.)
160 ! Store the (possibly domain-partial) real part <psi_i|S psi_i>; the domain sum and the
161 ! sqrt are taken below, so that negative partial-domain contributions are not dropped.
162 norm_ks(minst:maxst, ik_ispin) = real(sdiag, real64)
163 safe_deallocate_a(sdiag)
164 call spsib%end()
165 else
166 ! Compute norm, defering grid communication until outside the loops
167 call mesh_batch_nrm2(grid, st%group%psib(iblock, ik_ispin), norm_ks(minst:maxst, ik_ispin), reduce=.false.)
168 end if
169 enddo
170 enddo
171
172 ! Reduction over domains
173 if (present(aug_overlap)) then
174 ! norm_ks currently holds the domain-partial real part of <psi_i|S psi_i>.
175 if (grid%parallel_in_domains) call grid%allreduce(norm_ks)
176 norm_ks = sqrt(max(norm_ks, m_zero))
177 else if (grid%parallel_in_domains) then
178 norm_ks = norm_ks**2
179 call grid%allreduce(norm_ks)
180 norm_ks = sqrt(norm_ks)
181 end if
182
183 ! Reduction over states and k-points
184 call comm_allreduce(st%st_kpt_mpi_grp, norm_ks)
185
187
188 end subroutine states_elec_calc_norms
189
197 function states_elec_calc_orbital_difference(mesh, st, psib1, psib2) result(diff)
198 class(mesh_t), intent(in) :: mesh
199 type(states_elec_t), intent(in) :: st
200 type(wfs_elec_t), intent(in) :: psib1(:, st%d%kpt%start:)
201 type(wfs_elec_t), intent(in) :: psib2(:, st%d%kpt%start:)
202
203 real(real64) :: diff
204
205 integer :: ik, ib, minst, maxst
206 type(wfs_elec_t) :: delta_psi
207 real(real64), allocatable :: norm_k(:)
208
210
211 safe_allocate(norm_k(1:maxval(st%group%block_size)))
212
213 diff = m_zero
214 do ik = st%d%kpt%start, st%d%kpt%end
215 do ib = st%group%block_start, st%group%block_end
216 minst = states_elec_block_min(st, ib)
217 maxst = states_elec_block_max(st, ib)
218 call psib2(ib, ik)%copy_to(delta_psi, copy_data=.true.)
219 call batch_axpy(mesh%np, -m_one, psib1(ib, ik), delta_psi)
220 call mesh_batch_nrm2(mesh, delta_psi, norm_k, reduce=.false.)
221 diff = diff + st%kweights(ik) * sum(st%occ(minst:maxst, ik) * norm_k(1:psib1(ib, ik)%nst)**2)
222 call delta_psi%end()
223 enddo
224 enddo
225 safe_deallocate_a(norm_k)
226
227 call comm_allreduce(st%dom_st_kpt_mpi_grp, diff)
228 diff = sqrt(diff / st%qtot)
229
231
233
234
235#include "undef.F90"
236#include "real.F90"
237#include "states_elec_calc_inc.F90"
238
239#include "undef.F90"
240#include "complex.F90"
241#include "states_elec_calc_inc.F90"
242#include "undef.F90"
243
244end module states_elec_calc_oct_m
245
246
247!! Local Variables:
248!! mode: f90
249!! coding: utf-8
250!! End:
batchified version of the BLAS axpy routine:
Definition: batch_ops.F90:139
double sqrt(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
Definition: batch.F90:112
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:95
This module contains interfaces for BLACS routines Interfaces are from http://www....
Definition: blacs.F90:25
This module contains interfaces for BLAS routines You should not use these routines directly....
Definition: blas.F90:97
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_one
Definition: global.F90:174
This module implements the underlying real-space grid.
Definition: grid.F90:96
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
This module defines functions over batches of mesh functions.
Definition: mesh_batch.F90:95
subroutine, public mesh_batch_nrm2(mesh, aa, nrm2, reduce)
Calculate the norms (norm2, not the square!) of a batch of mesh functions.
Definition: mesh_batch.F90:155
subroutine, public zmesh_batch_dotp_vector(mesh, aa, bb, dot, reduce, cproduct)
A simple switch between specialized kernels and generic kernels.
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
This module contains some common usage patterns of MPI routines.
Definition: mpi_lib.F90:94
subroutine, public znonlocal_pseudopotential_apply_overlap(this, mesh, std, psib, spsib, phase, spiral_bnd, apply_phase)
Apply the ultrasoft/PAW generalized overlap S = 1 + sum_ij |beta_i> q_ij <beta_j| (or,...
Some general things and nomenclature:
Definition: par_vec.F90:150
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
This module contains interfaces for ScaLAPACK routines Interfaces are from http://www....
Definition: scalapack.F90:110
pure logical function, public states_are_real(st)
subroutine, public states_elec_orthogonalize(st, namespace, mesh)
Orthogonalize electronic states.
real(real64) function, public states_elec_calc_orbital_difference(mesh, st, psib1, psib2)
Compute the occupation- and k-point-weighted RMS difference between two sets of orbitals.
subroutine, public dstates_elec_matrix(st1, st2, mesh, aa, aug_overlap, phase)
subroutine, public zstates_elec_orthogonalize_single(st, mesh, nst, iqn, phi, normalize, mask, overlap, norm, Theta_fi, beta_ij, against_all)
ofthogonalize a single wave function against a set of states
subroutine, public dstates_elec_orthogonalization_full(st, namespace, mesh, ik)
Orthonormalizes nst orbitals in mesh (honours state parallelization).
subroutine, public dstates_elec_rrqr_decomposition(st, namespace, mesh, act_bands, ik, jpvt)
Perform RRQR on the transpose states stored in the states object and return the pivot vector.
real(real64) function, public zstates_elec_residue(mesh, dim, hf, ee, ff)
subroutine, public dstates_elec_calc_projections(st, gs_st, namespace, mesh, ik, proj, gs_nst, aug_overlap, phase)
This routine computes the projection between two set of states.
subroutine, public zstates_elec_calc_orth_test(st, namespace, mesh, kpoints)
subroutine, public dstates_elec_orthogonalize_single_batch(st, mesh, nst, iqn, phi, normalize, mask, overlap, norm, Theta_fi, beta_ij, against_all)
orthogonalize a single wave function against a set of states
subroutine dstates_elec_rotate(st, mesh, uu, ik)
subroutine, public zstates_elec_orthogonalization(mesh, nst, dim, psi, phi, normalize, mask, overlap, norm, Theta_fi, beta_ij, gs_scheme)
Orthonormalizes phi to the nst orbitals psi.
subroutine, public zstates_elec_matrix(st1, st2, mesh, aa, aug_overlap, phase)
subroutine, public dstates_elec_calc_orth_test(st, namespace, mesh, kpoints)
subroutine, public zstates_elec_calc_overlap(st, mesh, ik, overlap)
Computes the overlap matrix of the Kohn-Sham states with k-point ik.
subroutine, public dstates_elec_orthogonalization(mesh, nst, dim, psi, phi, normalize, mask, overlap, norm, Theta_fi, beta_ij, gs_scheme)
Orthonormalizes phi to the nst orbitals psi.
subroutine, public dstates_elec_orthogonalize_single(st, mesh, nst, iqn, phi, normalize, mask, overlap, norm, Theta_fi, beta_ij, against_all)
ofthogonalize a single wave function against a set of states
subroutine, public zstates_elec_orthogonalize_single_batch(st, mesh, nst, iqn, phi, normalize, mask, overlap, norm, Theta_fi, beta_ij, against_all)
orthogonalize a single wave function against a set of states
subroutine, public zstates_elec_rrqr_decomposition(st, namespace, mesh, act_bands, ik, jpvt)
Perform RRQR on the transpose states stored in the states object and return the pivot vector.
subroutine, public zstates_elec_orthogonalization_full(st, namespace, mesh, ik)
Orthonormalizes nst orbitals in mesh (honours state parallelization).
subroutine, public states_elec_calc_norms(grid, kpoints, st, norm_ks, aug_overlap, phase)
Compute the norms of the Kohn-Sham orbitals.
subroutine zstates_elec_rotate(st, mesh, uu, ik)
real(real64) function, public dstates_elec_residue(mesh, dim, hf, ee, ff)
subroutine, public zstates_elec_calc_projections(st, gs_st, namespace, mesh, ik, proj, gs_nst, aug_overlap, phase)
This routine computes the projection between two set of states.
subroutine, public dstates_elec_calc_overlap(st, mesh, ik, overlap)
Computes the overlap matrix of the Kohn-Sham states with k-point ik.
This module handles spin dimensions of the states and the k-point distribution.
integer pure function, public states_elec_block_max(st, ib)
return index of last state in block ib
integer pure function, public states_elec_block_min(st, ib)
return index of first state in block ib
This module provides routines for communicating states when using states parallelization.
Describes mesh distribution to nodes.
Definition: mesh.F90:165
The states_elec_t class contains all electronic wave functions.
batches of electronic states
Definition: wfs_elec.F90:120
int true(void)