Skip to content

Commit 77d57ba

Browse files
authored
Optimize Ω+K a little (#1266)
1 parent 96e5542 commit 77d57ba

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/densities.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ end
8585
(ik, n) = kn
8686

8787
kpt = basis.kpoints[ik]
88-
ifft!(storage.ψnk_real, basis, kpt, ψ[ik][:, n])
88+
ifft!(storage.ψnk_real, basis, kpt, ψ[ik][:, n]; normalize=false)
8989
# … and then we compute the real Fourier transform in the adequate basis.
90-
ifft!(storage.δψnk_real, basis, δψ_plus_k[ik].kpt, δψ_plus_k[ik].ψk[:, n])
90+
ifft!(storage.δψnk_real, basis, δψ_plus_k[ik].kpt, δψ_plus_k[ik].ψk[:, n]; normalize=false)
91+
# use unnormalized plans for extra speed, normalize at the end
92+
ifft_normalization = basis.fft_grid.ifft_normalization
9193

92-
storage.δρ[:, :, :, kpt.spin] .+= real_qzero.(
94+
storage.δρ[:, :, :, kpt.spin] .+= ifft_normalization^2 .* real_qzero.(
9395
2 .* occupation[ik][n] .* basis.kweights[ik] .* conj.(storage.ψnk_real)
9496
.* storage.δψnk_real
9597
.+ δoccupation[ik][n] .* basis.kweights[ik] .* abs2.(storage.ψnk_real))

src/response/hessian.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ from ψ and Λ is the set of Rayleigh coefficients ψk' * Hk * ψk at each k-poi
2929
"""
3030
@timing function apply_Ω(δψ, ψ, H::Hamiltonian, Λ)
3131
δψ = proj_tangent(δψ, ψ)
32-
Ωδψ = [H.blocks[ik] * δψk - δψk * Λ[ik] for (ik, δψk) in enumerate(δψ)]
33-
proj_tangent!(Ωδψ, ψ)
32+
map(enumerate(δψ)) do (ik, δψk)
33+
Ωδψ = H.blocks[ik] * δψk
34+
mul!(Ωδψ, δψk, Λ[ik], -1, 1)
35+
proj_tangent_kpt!(Ωδψ, ψ[ik])
36+
Ωδψ
37+
end
3438
end
3539

3640
"""
@@ -48,16 +52,18 @@ Compute the application of K defined at ψ to δψ. ρ is the density issued fro
4852
δψ = proj_tangent(δψ, ψ)
4953
δρ = compute_δρ(basis, ψ, δψ, occupation)
5054
δV = apply_kernel(basis, δρ; ρ)
55+
# normalize here so we can use unnormalized FFTs for extra speed
56+
δV .*= basis.fft_grid.ifft_normalization * basis.fft_grid.fft_normalization
5157

5258
ψnk_real = similar(G_vectors(basis), promote_type(T, eltype(ψ[1])))
5359
Kδψ = map(enumerate(ψ)) do (ik, ψk)
5460
kpt = basis.kpoints[ik]
5561
δVψk = similar(ψk)
5662

5763
for n = 1:size(ψk, 2)
58-
ifft!(ψnk_real, basis, kpt, ψk[:, n])
64+
ifft!(ψnk_real, basis, kpt, ψk[:, n]; normalize=false)
5965
ψnk_real .*= δV[:, :, :, kpt.spin]
60-
fft!(δVψk[:, n], basis, kpt, ψnk_real)
66+
fft!(δVψk[:, n], basis, kpt, ψnk_real; normalize=false)
6167
end
6268
δVψk
6369
end

0 commit comments

Comments
 (0)