Skip to content

Commit

Permalink
zerofield
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosanjose committed Oct 25, 2024
1 parent 8d08478 commit 0862160
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions docs/src/advanced/meanfield.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Schematically the process is as follows:
```julia
julia> model_0 = hopping(1); # a possible non-interacting model

julia> model_1 = @onsite((i; Φ = meanfield()) --> Φ[i]);
julia> model_1 = @onsite((i; Φ = zerofield) --> Φ[i]);

julia> model_2 = @hopping((i, j; Φ = meanfield()) -> Φ[i, j]);Fock
julia> model_2 = @hopping((i, j; Φ = zerofield) -> Φ[i, j]);Fock

julia> h = lat |> hamiltonian(model_0 + model_1 + model_2)
```
Here `model_1` corresponds to Hartree and onsite-Fock mean field terms, while `model_2` corresponds to inter-site Fock terms.
The default value `Φ = meanfield()` is a `ZeroMeanField` object that represents no interactions, so `model_1` and `model_2` vanish by default.
The default value `Φ = zerofield` is an singleton object that represents no interactions, so `model_1` and `model_2` vanish by default.
- We build the `GreenFunction` of `h` with `g = greenfunction(h, solver; kw...)` using the `GreenSolver` of choice
- We construct a `M::MeanField` object using `M = meanfield(g; potential = pot, other_options...)`

Expand Down Expand Up @@ -74,7 +74,7 @@ With the serializer functionality we can build a version of the fixed-point func
```julia
julia> using SIAMFANLEquations

julia> h = LP.linear() |> supercell(4) |> onsite(r->r[1]) - hopping(1) + @onsite((i; phi = meanfield()) --> phi[i]);
julia> h = LP.linear() |> supercell(4) |> onsite(r->r[1]) - hopping(1) + @onsite((i; phi = zerofield) --> phi[i]);

julia> M = meanfield(greenfunction(h); onsite = 1, selector = (; range = 0), fock = nothing)
MeanField{ComplexF64} : builder of Hartree-Fock mean fields
Expand Down Expand Up @@ -132,7 +132,7 @@ julia> using SIAMFANLEquations

julia> h = LP.linear() |> supercell(4) |> supercell |> onsite(1) - hopping(1) + @onsite((i; phi) --> phi[i]);

julia> (phi = meanfield()) = meanfield(greenfunction(h(; phi), GS.Spectrum()); onsite = 1, selector = (; range = 0), fock = nothing)
julia> (phi = zerofield) = meanfield(greenfunction(h(; phi), GS.Spectrum()); onsite = 1, selector = (; range = 0), fock = nothing)
M´ (generic function with 3 methods)

julia> Φ0 = ()(0.0, 0.0);
Expand Down
2 changes: 1 addition & 1 deletion src/Quantica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export sublat, bravais_matrix, lattice, sites, supercell, hamiltonian,
conductance, josephson, ldos, current, transmission, densitymatrix,
OrbitalSliceArray, OrbitalSliceVector, OrbitalSliceMatrix, orbaxes, siteindexdict,
serializer, serialize, serialize!, deserialize!, deserialize,
meanfield
meanfield, zerofield

export LatticePresets, LP, RegionPresets, RP, HamiltonianPresets, HP, ExternalPresets, EP
export EigenSolvers, ES, GreenSolvers, GS
Expand Down
8 changes: 4 additions & 4 deletions src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2602,10 +2602,10 @@ interaction potentials, and `ρ` is the density matrix evaluated at specific che
potential and temperature. Also `ν = ifelse(nambu, 0.5, 1.0)`, and `v_F(0) = v_H(0) = U`,
where `U` is the onsite interaction.
meanfield()
zerofield
Build an `M::ZeroMeanField` object that represents a zero-values mean field. It has the
property that it returns zero no matter how it is indexed (`M[inds...] = 0.0 * I`), so it is
An sigleton of type `ZeroField` that represents a zero-values field. It has the property
that it returns zero no matter how it is indexed (`zerofield[inds...] = 0.0 * I`), so it is
useful as a default value in a non-spatial model involving mean fields.
## Keywords
Expand All @@ -2631,7 +2631,7 @@ e.g. `ϕ[sites(2:3), sites(1)]`, see `OrbitalSliceArray` for details.
# Examples
```jldoctest
julia> model = hopping(I) - @onsite((i; phi = meanfield()) --> phi[i]);
julia> model = hopping(I) - @onsite((i; phi = zerofield) --> phi[i]);
julia> g = LP.honeycomb() |> hamiltonian(model, orbitals = 2) |> supercell((1,-1)) |> greenfunction;
Expand Down
10 changes: 5 additions & 5 deletions src/meanfield.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct MeanField{B,T,S<:SparseMatrixCSC,H<:DensityMatrix,F<:DensityMatrix}
onsite_tmp::Vector{Complex{T}}
end

struct ZeroMeanField end
struct ZeroField end

#region ## Constructors ##

Expand Down Expand Up @@ -120,13 +120,13 @@ function (m::MeanField{B})(args...; chopsmall = true, params...) where {B}
end


## ZeroMeanField
## ZeroField

meanfield() = ZeroMeanField()
const zerofield = ZeroField()

(m::ZeroMeanField)(args...; kw...) = m
(m::ZeroField)(args...; kw...) = m

Base.getindex(::ZeroMeanField, _...) = 0.0 * I
Base.getindex(::ZeroField, _...) = 0.0 * I

#endregion

Expand Down
2 changes: 1 addition & 1 deletion test/test_hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ end
@test_throws ArgumentError h()

# out of bounds indexing
h = LP.linear() |> @hopping((i,j; phi = missing) --> phi[i, j]);
h = LP.linear() |> @hopping((i,j; phi = zerofield()) --> phi[i, j]);
ϕ = h[cells = 0]
@test h(phi = ϕ) isa Hamiltonian
end
Expand Down

0 comments on commit 0862160

Please sign in to comment.