Skip to content

Commit 477346f

Browse files
Rename variables for DielectricAdjoint ε to ε_adj to avoid confusion (#1150)
1 parent 4e8406b commit 477346f

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/response/hessian.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,14 @@ Input parameters:
293293

294294
# compute total δρ
295295
# TODO Can be smarter here, e.g. use mixing to come up with initial guess.
296-
ε = DielectricAdjoint(ham, ρ, ψ, occupation, εF, eigenvalues, occupation_threshold,
297-
bandtolalg, maxiter_sternheimer, q)
296+
ε_adj = DielectricAdjoint(ham, ρ, ψ, occupation, εF, eigenvalues, occupation_threshold,
297+
bandtolalg, maxiter_sternheimer, q)
298298
precon = FunctionPreconditioner() do Pδρ, δρ
299299
Pδρ .= vec(mix_density(mixing, basis, reshape(δρ, size(ρ));
300300
ham, basis, ρin=ρ, εF, eigenvalues, ψ))
301301
end
302302
callback_inner(info) = callback(merge(info, (; runtime_ns=time_ns() - start_ns)))
303-
info_gmres = inexact_gmres(ε, vec(δρ0);
303+
info_gmres = inexact_gmres(ε_adj, vec(δρ0);
304304
tol, precon, krylovdim, maxiter, s,
305305
callback=callback_inner, kwargs...)
306306
δρ = reshape(info_gmres.x, size(ρ))
@@ -333,7 +333,7 @@ Input parameters:
333333
Axinfos=[(; basis, tol=tol*factor_final, resfinal...)]))
334334

335335
(; resfinal.δψ, δρ, δHψ, δVind, δρ0, δeigenvalues, resfinal.δoccupation,
336-
resfinal.δεF, ε, info_gmres)
336+
resfinal.δεF, ε_adj, info_gmres)
337337
end
338338

339339
function solve_ΩplusK_split(scfres::NamedTuple, rhs; kwargs...)
@@ -363,26 +363,26 @@ end
363363

364364
@doc raw"""
365365
Representation of the dielectric adjoint operator ``ε^† = (1 - χ_0 K)``.
366-
This is the adjoint of the dielectric operator ``(1 - K χ_0)``.
366+
This is the adjoint of the dielectric operator ``ε = (1 - K χ_0)``.
367367
"""
368368
function DielectricAdjoint(scfres; bandtolalg=BandtolBalanced(scfres), q=zero(Vec3{Float64}), maxiter=100)
369369
DielectricAdjoint(scfres.ham, scfres.ρ, scfres.ψ, scfres.occupation, scfres.εF,
370370
scfres.eigenvalues, scfres.occupation_threshold, bandtolalg, maxiter, q)
371371
end
372-
@timing "DielectricAdjoint" function mul_approximate(ε::DielectricAdjoint, δρ; rtol=0.0, kwargs...)
373-
δρ = reshape(δρ, size(ε.ρ))
374-
basis = ε.ham.basis
375-
δV = apply_kernel(basis, δρ; ε.ρ, ε.q)
376-
res = apply_χ0(ε.ham, ε.ψ, ε.occupation, ε.εF, ε.eigenvalues, δV;
377-
miniter=1, ε.occupation_threshold, tol=rtol*norm(δρ),
378-
ε.bandtolalg, ε.q, ε.maxiter, kwargs...)
372+
@timing "DielectricAdjoint" function mul_approximate(ε_adj::DielectricAdjoint, δρ; rtol=0.0, kwargs...)
373+
δρ = reshape(δρ, size(ε_adj.ρ))
374+
basis = ε_adj.ham.basis
375+
δV = apply_kernel(basis, δρ; ε_adj.ρ, ε_adj.q)
376+
res = apply_χ0(ε_adj.ham, ε_adj.ψ, ε_adj.occupation, ε_adj.εF, ε_adj.eigenvalues, δV;
377+
miniter=1, ε_adj.occupation_threshold, tol=rtol*norm(δρ),
378+
ε_adj.bandtolalg, ε_adj.q, ε_adj.maxiter, kwargs...)
379379
χ0δV = res.δρ
380380
Ax = vec(δρ - χ0δV) # (1 - χ0 K) δρ
381381
(; Ax, info=(; rtol, basis, res...))
382382
end
383-
function size(ε::DielectricAdjoint, i::Integer)
383+
function size(ε_adj::DielectricAdjoint, i::Integer)
384384
if 1 i 2
385-
return prod(size(ε.ρ))
385+
return prod(size(ε_adj.ρ))
386386
else
387387
return one(i)
388388
end

test/hessian.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function test_solve_ΩplusK(scfres, δVext)
3333
@test maximum(abs, δρ0 - ref.δρ0) < 1e-11
3434
end
3535
@testset "Residual is small" begin
36-
ε = DFTK.DielectricAdjoint(scfres; bandtolalg=DFTK.BandtolGuaranteed(scfres))
37-
εδρ = reshape(DFTK.mul_approximate(ε, ref.δρ; tol=1e-13).Ax, size(δρ0))
38-
@test maximum(abs, δρ0 - εδρ) < 1e-11
36+
ε_adj = DFTK.DielectricAdjoint(scfres; bandtolalg=DFTK.BandtolGuaranteed(scfres))
37+
ε_adj_δρ = reshape(DFTK.mul_approximate(ε_adj, ref.δρ; tol=1e-13).Ax, size(δρ0))
38+
@test maximum(abs, δρ0 - ε_adj_δρ) < 1e-11
3939
end
4040

4141
@testset "Adaptive algorithm yields desired tolerances" begin

0 commit comments

Comments
 (0)