Skip to content

Commit dec431a

Browse files
committed
Make apply_kernel error when not implemented, instead of assuming zero (#1141)
1 parent 0ea2afe commit dec431a

File tree

9 files changed

+15
-10
lines changed

9 files changed

+15
-10
lines changed

src/terms/entropy.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ function ene_ops(term::TermEntropy, basis::PlaneWaveBasis{T}, ψ, occupation;
3737

3838
(; E, ops)
3939
end
40+
compute_kernel(term::TermEntropy, basis::AbstractBasis; kwargs...) = nothing
41+
apply_kernel(term::TermEntropy, basis::AbstractBasis, δρ; kwargs...) = nothing

src/terms/ewald.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Base.@kwdef struct Ewald
1111
end
1212
(ewald::Ewald)(basis) = TermEwald(basis; η=something(ewald.η, default_η(basis.model.lattice)))
1313

14-
struct TermEwald{T} <: Term
14+
struct TermEwald{T} <: TermLinear
1515
energy::T # precomputed energy
1616
forces::Vector{Vec3{T}} # and forces
1717
η::T # Parameter used for the splitting

src/terms/kinetic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Base.show(io::IO, kin::Kinetic)
1616
print(io, "Kinetic($bup$fac)")
1717
end
1818

19-
struct TermKinetic <: Term
19+
struct TermKinetic <: TermLinear
2020
scaling_factor::Real # scaling factor, absorbed into kinetic_energies
2121
# kinetic energies 1/2(k+G)^2 *blowup(|k+G|, Ecut) for each k-point.
2222
kinetic_energies::Vector{<:AbstractVector}

src/terms/local.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# potential in real space on the grid. If the potential is different in the α and β
55
# components then it should be a 4d-array with the last axis running over the
66
# two spin components.
7-
abstract type TermLocalPotential <: Term end
7+
abstract type TermLocalPotential <: TermLinear end
88

99
@timing "ene_ops: local" function ene_ops(term::TermLocalPotential,
1010
basis::PlaneWaveBasis{T}, ψ, occupation;

src/terms/magnetic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function (M::MagneticFromValues)(Apotential)
2222
TermMagnetic(basis, Apotential)
2323
end
2424

25-
struct TermMagnetic <: Term
25+
struct TermMagnetic <: TermLinear
2626
# Apotential[α] is an array of size fft_size for α=1:3
2727
Apotential::Vector{<:AbstractArray}
2828
end

src/terms/nonlocal.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function (::AtomicNonlocal)(basis::PlaneWaveBasis{T}) where {T}
2424
TermAtomicNonlocal(ops)
2525
end
2626

27-
struct TermAtomicNonlocal <: Term
27+
struct TermAtomicNonlocal <: TermLinear
2828
ops::Vector{NonlocalOperator}
2929
end
3030

src/terms/pairwise.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
TermPairwisePotential(P.V, P.params, T(P.max_radius), energy, forces)
2626
end
2727

28-
struct TermPairwisePotential{TV, Tparams, T} <:Term
28+
struct TermPairwisePotential{TV, Tparams, T} <: TermLinear
2929
V::TV
3030
params::Tparams
3131
max_radius::T

src/terms/psp_correction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Pseudopotential correction energy. TODO discuss the need for this.
44
struct PspCorrection end
55
(::PspCorrection)(basis) = TermPspCorrection(basis)
66

7-
struct TermPspCorrection{T} <: Term
7+
struct TermPspCorrection{T} <: TermLinear
88
energy::T # precomputed energy
99
end
1010
function TermPspCorrection(basis::PlaneWaveBasis)

src/terms/terms.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ include("operators.jl")
1616
# In particular, dE/dψn = 2 fn |Hψn> (plus weighting for k-point sampling)
1717
abstract type Term end
1818

19+
# Terms that are linear in the density matrix, i.e. have zero second derivative
20+
abstract type TermLinear <: Term end
21+
compute_kernel(term::TermLinear, basis::AbstractBasis; kwargs...) = nothing
22+
apply_kernel(term::TermLinear, basis::AbstractBasis, δρ; kwargs...) = nothing
23+
1924
# Terms that are non-linear in the density (i.e. which give rise to a Hamiltonian
2025
# contribution that is density-dependent or orbital-dependent as well)
2126
abstract type TermNonlinear <: Term end
@@ -33,7 +38,7 @@ DftFunctionals.needs_τ(t::Term) = false
3338
"""
3439
A term with a constant zero energy.
3540
"""
36-
struct TermNoop <: Term end
41+
struct TermNoop <: TermLinear end
3742
function ene_ops(term::TermNoop, basis::PlaneWaveBasis{T}, ψ, occupation; kwargs...) where {T}
3843
(; E=zero(eltype(T)), ops=[NoopOperator(basis, kpt) for kpt in basis.kpoints])
3944
end
@@ -101,7 +106,6 @@ In this case the matrix has effectively 4 blocks
101106
end
102107
kernel
103108
end
104-
compute_kernel(::Term, ::AbstractBasis{T}; kwargs...) where {T} = nothing # By default no kernel
105109

106110

107111
"""
@@ -128,4 +132,3 @@ as a 4D `(i,j,k,σ)` array.
128132
end
129133
δV
130134
end
131-
apply_kernel(::Term, ::AbstractBasis{T}, δρ; kwargs...) where {T} = nothing # by default, no kernel

0 commit comments

Comments
 (0)