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
52 use pblas_oct_m
57 use space_oct_m
62 use types_oct_m
64
65 implicit none
66
67 private
68
69 public :: &
94
95 interface states_elec_rotate
97 end interface states_elec_rotate
98
99contains
100
101 ! ---------------------------------------------------------
103 subroutine states_elec_orthogonalize(st, namespace, mesh)
104 type(states_elec_t), intent(inout) :: st
105 type(namespace_t), intent(in) :: namespace
106 class(mesh_t), intent(in) :: mesh
107
108 integer :: ik
109
111
112 do ik = st%d%kpt%start, st%d%kpt%end
113 if (states_are_real(st)) then
114 call dstates_elec_orthogonalization_full(st, namespace, mesh, ik)
115 else
116 call zstates_elec_orthogonalization_full(st, namespace, mesh, ik)
117 end if
118 end do
119
121 end subroutine states_elec_orthogonalize
122
123 ! ---------------------------------------------------------
125 !
126 subroutine states_elec_calc_norms(grid, kpoints, st, norm_ks)
127 type(grid_t), intent(in) :: grid
128 type(kpoints_t), intent(in) :: kpoints
129 type(states_elec_t), intent(in) :: st
130 real(real64), contiguous, intent(out) :: norm_ks(:, :)
131
132 integer :: ik_ispin, iblock, minst, maxst
133
134 push_sub(states_elec_calc_norms)
135
136 ! If state or k is parallel, norm_ks is only partially touched, then gets summed over processes,
137 ! hence initialise to zero
138 norm_ks = m_zero
139
140 do ik_ispin = st%d%kpt%start, st%d%kpt%end
141 do iblock = st%group%block_start, st%group%block_end
142 minst = states_elec_block_min(st, iblock)
143 maxst = states_elec_block_max(st, iblock)
144 ! Compute norm, defering grid communication until outside the loops
145 call mesh_batch_nrm2(grid, st%group%psib(iblock, ik_ispin), norm_ks(minst:maxst, ik_ispin), reduce=.false.)
146 enddo
147 enddo
148
149 ! Reduction over domains
150 if (grid%parallel_in_domains) then
151 norm_ks = norm_ks**2
152 call grid%allreduce(norm_ks)
153 norm_ks = sqrt(norm_ks)
154 end if
155
156 ! Reduction over states and k-points
157 call comm_allreduce(st%st_kpt_mpi_grp, norm_ks)
158
160
161 end subroutine states_elec_calc_norms
162
170 function states_elec_calc_orbital_difference(mesh, st, psib1, psib2) result(diff)
171 class(mesh_t), intent(in) :: mesh
172 type(states_elec_t), intent(in) :: st
173 type(wfs_elec_t), intent(in) :: psib1(:, st%d%kpt%start:)
174 type(wfs_elec_t), intent(in) :: psib2(:, st%d%kpt%start:)
175
176 real(real64) :: diff
177
178 integer :: ik, ib, minst, maxst
179 type(wfs_elec_t) :: delta_psi
180 real(real64), allocatable :: norm_k(:)
181
183
184 safe_allocate(norm_k(1:maxval(st%group%block_size)))
185
186 diff = m_zero
187 do ik = st%d%kpt%start, st%d%kpt%end
188 do ib = st%group%block_start, st%group%block_end
189 minst = states_elec_block_min(st, ib)
190 maxst = states_elec_block_max(st, ib)
191 call psib2(ib, ik)%copy_to(delta_psi, copy_data=.true.)
192 call batch_axpy(mesh%np, -m_one, psib1(ib, ik), delta_psi)
193 call mesh_batch_nrm2(mesh, delta_psi, norm_k, reduce=.false.)
194 diff = diff + st%kweights(ik) * sum(st%occ(minst:maxst, ik) * norm_k(1:psib1(ib, ik)%nst)**2)
195 call delta_psi%end()
196 enddo
197 enddo
198 safe_deallocate_a(norm_k)
199
200 call comm_allreduce(st%dom_st_kpt_mpi_grp, diff)
201 diff = sqrt(diff / st%qtot)
202
204
206
207
208#include "undef.F90"
209#include "real.F90"
210#include "states_elec_calc_inc.F90"
211
212#include "undef.F90"
213#include "complex.F90"
214#include "states_elec_calc_inc.F90"
215#include "undef.F90"
216
217end module states_elec_calc_oct_m
218
219
220!! Local Variables:
221!! mode: f90
222!! coding: utf-8
223!! End:
batchified version of the BLAS axpy routine:
Definition: batch_ops.F90:160
double sqrt(double __x) __attribute__((__nothrow__
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 BLACS routines Interfaces are from http:
Definition: blacs.F90:27
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.
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_one
Definition: global.F90:201
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
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:181
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
This module contains some common usage patterns of MPI routines.
Definition: mpi_lib.F90:117
Some general things and nomenclature:
Definition: par_vec.F90:173
This module contains interfaces for ScaLAPACK routines Interfaces are from http:
Definition: scalapack.F90:133
pure logical function, public states_are_real(st)
subroutine, public zstates_elec_matrix(st1, st2, mesh, aa)
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 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_matrix(st1, st2, mesh, aa)
subroutine, public zstates_elec_calc_projections(st, gs_st, namespace, mesh, ik, proj, gs_nst)
This routine computes the projection between two 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 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, public states_elec_calc_norms(grid, kpoints, st, norm_ks)
Compute the norms of the Kohn-Sham orbitals.
subroutine, public dstates_elec_calc_projections(st, gs_st, namespace, mesh, ik, proj, gs_nst)
This routine computes the projection between two 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 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 zstates_elec_rotate(st, mesh, uu, ik)
real(real64) function, public dstates_elec_residue(mesh, dim, hf, ee, ff)
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.
int true(void)