Skip to content

Commit

Permalink
kpt.basis -> G_vectors(kpt)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-levitt authored and mfherbst committed Jan 22, 2020
1 parent 6ccd5e4 commit 1c7301c
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/HamiltonianBlock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Base.eltype(block::HamiltonianBlock) = complex(eltype(block.values_kinetic))


function Matrix(block::HamiltonianBlock)
n_bas = length(block.kpt.basis)
n_bas = length(G_vectors(block.kpt))
T = eltype(block)
mat = Matrix{T}(undef, (n_bas, n_bas))
v = fill(zero(T), n_bas)
Expand Down
2 changes: 1 addition & 1 deletion src/Kinetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ function kblock(kin::Kinetic, kpt::Kpoint)

T = eltype(basis.kpoints[1].coordinate)
Diagonal(Vector{T}([sum(abs2, model.recip_lattice * (G + kpt.coordinate))
for G in kpt.basis] ./ 2))
for G in G_vectors(kpt)] ./ 2))
end
10 changes: 6 additions & 4 deletions src/PlaneWaveBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ include("fft.jl")

# Each Kpoint has its own `basis`, consisting of all G vectors such that 1/2 |k+G|^2 ≤ Ecut
struct Kpoint{T <: Real}
spin::Symbol # :up, :down, :both or :spinless
coordinate::Vec3{T} # Fractional coordinate of k-Point
mapping::Vector{Int} # Index of basis[i] on FFT grid
basis::Vector{Vec3{Int}} # Wave vectors in integer coordinates
spin::Symbol # :up, :down, :both or :spinless
coordinate::Vec3{T} # Fractional coordinate of k-Point
mapping::Vector{Int} # Index of G_vectors[i] on the FFT grid:
# G_vectors(pwbasis)[kpt.mapping[i]] == G_vectors(kpt)[i]
G_vectors::Vector{Vec3{Int}} # Wave vectors in integer coordinates
end
G_vectors(kpt::Kpoint) = kpt.G_vectors

struct PlaneWaveBasis{T <: Real, Tgrid, TopFFT, TipFFT}
model::Model{T}
Expand Down
2 changes: 1 addition & 1 deletion src/PotNonLocal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct PotNonLocalBlock
kpt::Kpoint

# Projection vectors and coefficients for this basis and k-Point
# n_Gk = length(kpoint.basis)
# n_Gk = length(G_vectors(kpt))
# n_proj = ∑_atom ∑_l n_proj_per_l_for_atom * (2l + 1)
proj_vectors # n_proj × n_proj
proj_coeffs # n_Gk × n_proj
Expand Down
2 changes: 1 addition & 1 deletion src/densities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function compute_density(pw::PlaneWaveBasis, Psi::AbstractVector{VecT},
@assert n_k == length(Psi)
@assert n_k == length(occupation)
for ik in 1:n_k
@assert length(pw.kpoints[ik].basis) == size(Psi[ik], 1)
@assert length(G_vectors(pw.kpoints[ik])) == size(Psi[ik], 1)
@assert length(occupation[ik]) == size(Psi[ik], 2)
end
@assert n_k > 0
Expand Down
10 changes: 5 additions & 5 deletions src/eigen/diag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ function interpolate_at_kpoint(kpt_old, kpt_new, data_oldk::AbstractVecOrMat)
if kpt_old == kpt_new
return data_oldk
end
@assert length(kpt_old.basis) == size(data_oldk, 1)
@assert length(G_vectors(kpt_old)) == size(data_oldk, 1)
n_bands = size(data_oldk, 2)

data_newk = similar(data_oldk, length(kpt_new.basis), n_bands) .= 0
for (iold, inew) in enumerate(indexin(kpt_old.basis, kpt_new.basis))
data_newk = similar(data_oldk, length(G_vectors(kpt_new)), n_bands) .= 0
for (iold, inew) in enumerate(indexin(G_vectors(kpt_old), G_vectors(kpt_new)))
inew !== nothing && (data_newk[inew, :] = data_oldk[iold, :])
end
data_newk
Expand Down Expand Up @@ -46,10 +46,10 @@ function diagonalise_all_kblocks(eigensolver, ham::Hamiltonian, nev_per_kpoint::
# random initial guess
# TODO The double conversion is needed due to an issue in Julia
# see https://github.com/JuliaLang/julia/pull/32979
qrres = qr(randn(T, length(kpoints[ik].basis), nev_per_kpoint))
qrres = qr(randn(T, length(G_vectors(kpoints[ik])), nev_per_kpoint))
guessk = Matrix{T}(qrres.Q)
end
@assert size(guessk) == (length(kpoints[ik].basis), nev_per_kpoint)
@assert size(guessk) == (length(G_vectors(kpoints[ik])), nev_per_kpoint)

prec = nothing
prec_type !== nothing && (prec = prec_type(ham, kpt))
Expand Down
2 changes: 1 addition & 1 deletion src/eigen/preconditioners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end

function PreconditionerTPA(ham::Hamiltonian, kpt::Kpoint{T}) where T
kin = Vector{T}([sum(abs2, ham.basis.model.recip_lattice * (G + kpt.coordinate))
for G in kpt.basis] ./ 2)
for G in G_vectors(kpt)] ./ 2)
@assert ham.basis.model.spin_polarisation in (:none, :collinear, :spinless)
PreconditionerTPA{T}(ham, kpt, kin, nothing)
end
Expand Down
2 changes: 1 addition & 1 deletion src/scf/direct_minimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function direct_minimization(basis::PlaneWaveBasis{T}, Psi0;
Nk = length(basis.kpoints)

if Psi0 === nothing
Psi0 = [ortho(randn(Complex{T}, length(k.basis), n_bands)) for k in basis.kpoints]
Psi0 = [ortho(randn(Complex{T}, length(G_vectors(kpt)), n_bands)) for kpt in basis.kpoints]
end
occupation = [filled_occ * ones(T, n_bands) for ik = 1:Nk]

Expand Down
6 changes: 3 additions & 3 deletions src/terms/term_nonlocal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ build_projection_vectors_(basis, potentials, kpt)
model = basis.model
T = eltype(basis.kpoints[1].coordinate)

proj_vectors = zeros(Complex{T}, length(kpt.basis), n_proj)
qs = [model.recip_lattice * (kpt.coordinate + G) for G in kpt.basis]
proj_vectors = zeros(Complex{T}, length(G_vectors(kpt)), n_proj)
qs = [model.recip_lattice * (kpt.coordinate + G) for G in G_vectors(kpt)]
qsqs = [sum(abs2, q) for q in qs]

count = 0
for (psp, positions) in potentials, r in positions
structure_factors = [cis(-2T(π) * dot(G, r)) for G in kpt.basis]
structure_factors = [cis(-2T(π) * dot(G, r)) for G in G_vectors(kpt)]
radial_proj(iproj, l, qsq) = eval_psp_projection_radial(psp, iproj, l, qsq)

for l in 0:psp.lmax, m in -l:l
Expand Down
2 changes: 1 addition & 1 deletion test/HamiltonianBlock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include("testcases.jl")
hamk = kblock(ham, kpt)
mat = Matrix(kblock(ham, kpt))

v = randn(ComplexF64, length(kpt.basis))
v = randn(ComplexF64, length(G_vectors(kpt)))
@test mat * v hamk * v
end
end
6 changes: 3 additions & 3 deletions test/PlaneWaveBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function test_pw_cutoffs(testcase, Ecut, fft_size)
pw = PlaneWaveBasis(model, Ecut, testcase.kcoords, testcase.ksymops; fft_size=fft_size)

for (ik, kpt) in enumerate(pw.kpoints)
for G in kpt.basis
for G in G_vectors(kpt)
@test sum(abs2, model.recip_lattice * (kpt.coordinate + G)) 2 * Ecut
end
end
Expand Down Expand Up @@ -38,10 +38,10 @@ end
kpt = pw.kpoints[ik]
@test kpt.coordinate == kcoord

for (ig, G) in enumerate(kpt.basis)
for (ig, G) in enumerate(G_vectors(kpt))
@test g_start <= G <= g_stop
end
@test g_all[kpt.mapping] == kpt.basis
@test g_all[kpt.mapping] == G_vectors(kpt)
end
@test pw.kweights == [1, 8, 6, 12] / 27
end
Expand Down
2 changes: 1 addition & 1 deletion test/fourier_transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ include("testcases.jl")

@testset "Transformation B_k <-> C_ρ^∗, 1 vector" begin
kpt = pw.kpoints[2]
f_G = Array{ComplexF64}(randn(Float64, length(kpt.basis)))
f_G = Array{ComplexF64}(randn(Float64, length(G_vectors(kpt))))

f_R = Array{ComplexF64}(undef, pw.fft_size...)
G_to_r!(f_R, pw, kpt, f_G)
Expand Down

0 comments on commit 1c7301c

Please sign in to comment.