Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selector_hartree and selector_fock to meanfield #326

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2666,11 +2666,13 @@ where `U` is the onsite interaction.
- `potential`: charge-charge potential to use for both Hartree and Fock. Can be a number or a function of position. Default: `1`
- `hartree`: charge-charge potential `v_H` for the Hartree mean field. Can be a number or a function of position. Overrides `potential`. Default: `potential`
- `fock`: charge-charge potential `v_F` for the Fock mean field. Can be a number, a function of position or `nothing`. In the latter case all Fock terms (even onsite) will be dropped. Default: `hartree`
- `onsite`: charge-charge onsite potential. Overrides both Hartree and Fock potentials for onsite interactions. Default: `hartree(0)`
- `onsite`: charge-charge onsite potential. Overrides both Hartree and Fock potentials for onsite interactions, unless `fock = nothing` (it then overrides only Hartree, see above). Default: `hartree(0)`
- `charge`: a number (in single-orbital systems) or a matrix (in multi-orbital systems) representing the charge operator on each site. Default: `I`
- `nambu::Bool`: specifies whether the model is defined in Nambu space. In such case, `charge` should also be in Nambu space, typically `SA[1 0; 0 -1]` or similar. Default: `false`
- `namburotation::Bool`: if `nambu == true` and spinful systems, specifies whether the spinor basis is `[c↑, c↓, c↓⁺, -c↑⁺]` (`namburotation = true`) or `[c↑, c↓, c↑⁺, c↓⁺]` (`namburotation = false`). Default: `false`
- `selector::NamedTuple`: a collection of `hopselector` directives that defines the pairs of sites (`pair_selection` above) that interact through the charge-charge potential. Default: `(; range = 0)` (i.e. onsite)
- `selector::NamedTuple`: a collection of `hopselector` directives that defines the pairs of sites (`pair_selection` above) that interact through the charge-charge potential. Default: `(; range = 0)` (i.e. only onsite)
- `selector_hartree::NamedTuple`: same as `selector`, but restricted to the Hartree interactions. Useful e.g. to do efficient Hartree-only simulations: a long-range `selector_hartree` is cheap in periodic systems, as lattice periodicity is exploited to make the computational cost independent of the range. Default: `selector`.
- `selector_fock::NamedTuple`: same as `selector_hartree`, but for Fock interactions. Note that `selector_fock` increases the number of entries that need to be computed for the density matrix, so increasing the Fock range is typically not cheap. Default: `selector`.

Any additional keywords `kw` are passed to the `densitymatrix` function used to compute the
mean field, see above
Expand Down
12 changes: 6 additions & 6 deletions src/meanfield.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct ZeroField end
function meanfield(g::GreenFunction{T,E}, args...;
potential = Returns(1), hartree = potential, fock = hartree,
onsite = missing, charge = I, nambu::Bool = false, namburotation = missing,
selector::NamedTuple = (; range = 0), kw...) where {T,E}
selector::NamedTuple = (; range = 0), selector_fock = selector, selector_hartree = selector, kw...) where {T,E}

Vh = sanitize_potential(hartree)
Vf = sanitize_potential(fock)
Expand All @@ -40,14 +40,14 @@ function meanfield(g::GreenFunction{T,E}, args...;
isempty(boundaries(g)) || argerror("meanfield does not currently support systems with boundaries")
isfinite(U) || argerror("Onsite potential must be finite, consider setting `onsite`")

gs = g[sitepairs(; selector..., includeonsite = true)]
gs = g[sitepairs(; selector_fock..., includeonsite = true)]
rho = densitymatrix(gs, args...; kw...)

lat = lattice(hamiltonian(g))
# The sparse structure of hFock will be inherited by the evaluated mean field. Need onsite.
hFock = lat |> hopping((r, dr) -> iszero(dr) ? Uf : T(Vf(dr)); selector..., includeonsite = true)
hHartree = (Uf == U && Vh === Vf) ? hFock :
lat |> hopping((r, dr) -> iszero(dr) ? U : T(Vh(dr)); selector..., includeonsite = true)
hFock = lat |> hopping((r, dr) -> iszero(dr) ? Uf : T(Vf(dr)); selector_fock..., includeonsite = true)
hHartree = (Uf == U && Vh == Vf && selector_fock == selector_hartree) ? hFock :
lat |> hopping((r, dr) -> iszero(dr) ? U : T(Vh(dr)); selector_hartree..., includeonsite = true)
# this drops zeros
potHartree = T.(sum(unflat, harmonics(hHartree)))

Expand All @@ -66,7 +66,7 @@ function meanfield(g::GreenFunction{T,E}, args...;

encoder, decoder = nambu ? NambuEncoderDecoder(is_nambu_rotated´) : (identity, identity)
S = typeof(encoder(zero(Q)))
output = call!_output(g[sitepairs(; selector..., includeonsite = true, kernel = Q)])
output = call!_output(g[sitepairs(; selector_fock..., includeonsite = true, kernel = Q)])
sparse_enc = similar(output, S)
output = CompressedOrbitalMatrix(sparse_enc; encoder, decoder, hermitian = true)

Expand Down
2 changes: 1 addition & 1 deletion src/solvers/green/schur.jl
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ function (s::DensityMatrixSchurSolver)(µ, kBT; params...)
xs = sort!(ϕs ./ (2π))
pushfirst!(xs, -0.5)
push!(xs, 0.5)
xs = [mean(view(xs, rng)) for rng in approxruns(xs)] # elliminate approximate duplicates
xs = [mean(view(xs, rng)) for rng in approxruns(xs)] # eliminate approximate duplicates
result = call!_output(s.gs)
integrand!(x) = fermi_h!(result, s, 2π * x, µ, inv(kBT); params...)
fx! = (y, x) -> (y .= integrand!(x))
Expand Down
Loading