Skip to content

Commit e547ed9

Browse files
committed
fixed greens function at finite temperature??
1 parent f823bfd commit e547ed9

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

src/BdGModel.jl

+33-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module BdG
66
using ..TightBindingToolkit.DesignUCell: ModifyIsotropicFields!
77
using ..TightBindingToolkit.BZone:BZ, MomentumPhaseFFT
88
using ..TightBindingToolkit.Hams:Hamiltonian, ModifyHamiltonianField!
9-
9+
1010
using LinearAlgebra, Tullio, TensorCast, Logging, Statistics
1111

1212
import ..TightBindingToolkit.TBModel:FindFilling, GetMu!, GetFilling!, GetGk!, GetGr!, SolveModel!, GetGap!, FreeEnergy
@@ -27,7 +27,7 @@ module BdG
2727
- `Gk :: Array{Matrix{ComplexF64}}` : An Array (corresponding to the grid of k-points in `BZ`) of Greens functions.
2828
- `Fk :: Array{Matrix{ComplexF64}}` : An Array (corresponding to the grid of k-points in `BZ`) of anomalous Greens functions.
2929
30-
Initialize this structure using
30+
Initialize this structure using
3131
```julia
3232
BdGModel(uc_hop::UnitCell, uc_pair::UnitCell, bz::BZ, Ham::Hamiltonian ; T::Float64=1e-3, filling::Float64=-1.0, mu::Float64=0.0, stat::Int64=-1)
3333
```
@@ -53,7 +53,7 @@ module BdG
5353
Fk :: Array{Matrix{ComplexF64}}
5454
Gr :: Array{Matrix{ComplexF64}}
5555
Fr :: Array{Matrix{ComplexF64}}
56-
56+
5757
BdGModel(uc_hop::UnitCell, uc_pair::UnitCell, bz::BZ, Ham::Hamiltonian ; T::Float64=1e-3, filling::Float64=-1.0, mu::Float64=0.0, stat::Int64=-1) = new{}(uc_hop, uc_pair, bz, Ham, T, filling, mu, -999.0, stat ,Array{Matrix{ComplexF64}}(undef, zeros(Int64, length(uc_hop.primitives))...), Array{Matrix{ComplexF64}}(undef, zeros(Int64, length(uc_hop.primitives))...), Array{Matrix{ComplexF64}}(undef, zeros(Int64, length(uc_hop.primitives))...),Array{Matrix{ComplexF64}}(undef, zeros(Int64, length(uc_hop.primitives))...))
5858
##### Chosen the default value of filling to be -1 which is unphysical so that the code knows when filling has not been provided and has to be calculated from mu instead!
5959
end
@@ -75,10 +75,12 @@ Because of this, if you want to calculate the filling at a different chemical po
7575
Eks = reshape(getindex.(M.Ham.bands, Ref(1:N÷2)), prod(M.bz.gridSize))
7676
U11s = reshape(getindex.(M.Ham.states, Ref(1:N÷2), Ref(1:N÷2)), prod(M.bz.gridSize))
7777
U21s = reshape(getindex.(M.Ham.states, Ref(N÷2 + 1: N), Ref(1:N÷2)), prod(M.bz.gridSize))
78+
U12s = reshape(getindex.(M.Ham.states, Ref(1:N÷2), Ref(N÷2 + 1: N)) , prod(M.bz.gridSize))
79+
U22s = reshape(getindex.(M.Ham.states, Ref(N÷2 + 1: N), Ref(N÷2 + 1: N)) , prod(M.bz.gridSize))
7880

7981
nFs = DistFunction.(Eks; T=M.T, mu=0.0, stat=M.stat)
8082

81-
@tullio filling := ((conj(U11s[k1][i, j]) * U11s[k1][i, j] * nFs[k1][j])
83+
@tullio filling := ((conj(U11s[k1][i, j]) * U11s[k1][i, j] * nFs[k1][j])
8284
+ (conj(U21s[k1][i, j]) * U21s[k1][i, j] * (1 - nFs[k1][j])))
8385

8486
return real(filling) / (prod(M.bz.gridSize) * M.uc_hop.localDim * length(M.uc_hop.basis))
@@ -109,9 +111,9 @@ GetMu!(M::BdGModel ; tol::Float64=0.001)
109111
Function to get the correct chemical potential given a filling.
110112
"""
111113
function GetMu!(M::BdGModel ; guess::Float64 = 0.0, mu_tol::Float64 = 0.001, filling_tol::Float64 = 1e-6)
112-
M.mu = BinarySearch(M.filling, M.Ham.bandwidth, FindFilling, (M,) ; initial = guess, x_tol = mu_tol, target_tol = filling_tol)
114+
M.mu = BinarySearch(M.filling, (2*M.Ham.bandwidth[1], 2*M.Ham.bandwidth[2]), FindFilling, (M,) ; initial = guess, x_tol = mu_tol, target_tol = filling_tol)
113115
@info "Found chemical potential μ = $(M.mu) for given filling = $(M.filling)."
114-
116+
115117
end
116118

117119

@@ -127,16 +129,16 @@ Finding the Greens functions, and anomalous greens functions in momentum space a
127129
Eks = reshape(getindex.(M.Ham.bands, Ref(1:N÷2)) , prod(M.bz.gridSize)) ##### Only the negative energies from the bdG spectrum
128130

129131
U11s = reshape(getindex.(M.Ham.states, Ref(1:N÷2), Ref(1:N÷2)) , prod(M.bz.gridSize)) ##### The 4 different quadrants in the Unitary relating the BdG quasiparticles and the nambu basis
130-
U21s = reshape(getindex.(M.Ham.states, Ref(N÷2 + 1: N), Ref(1:N÷2)) , prod(M.bz.gridSize))
131-
U12s = reshape(getindex.(M.Ham.states, Ref(1:N÷2), Ref(N÷2 + 1: N)) , prod(M.bz.gridSize))
132+
U21s = reshape(getindex.(M.Ham.states, Ref(N÷2 + 1: N), Ref(1:N÷2)) , prod(M.bz.gridSize))
133+
U12s = reshape(getindex.(M.Ham.states, Ref(1:N÷2), Ref(N÷2 + 1: N)) , prod(M.bz.gridSize))
132134
U22s = reshape(getindex.(M.Ham.states, Ref(N÷2 + 1: N), Ref(N÷2 + 1: N)) , prod(M.bz.gridSize))
133135

134136
nFs = DistFunction.(Eks; T=M.T, mu=0.0, stat=M.stat)
135137

136-
@reduce Gk[k1][i, j] |= sum(l) ((conj(U11s[k1][i, l]) * U11s[k1][j, l] * nFs[k1][l])
137-
+ (conj(U12s[k1][i, l]) * U12s[k1][j, l] * (1 - nFs[k1][l])))
138+
@reduce Gk[k1][i, j] |= sum(l) ((conj(U11s[k1][i, l]) * U11s[k1][j, l] * nFs[k1][l])
139+
+ (conj(U21s[k1][i, l]) * U21s[k1][j, l] * (1 - nFs[k1][l])))
138140

139-
@reduce Fk[k1][i, j] |= sum(l) ((conj(U11s[k1][i, l]) * U21s[k1][j, l] * nFs[k1][l])
141+
@reduce Fk[k1][i, j] |= sum(l) ((conj(U11s[k1][i, l]) * U21s[k1][j, l] * nFs[k1][l])
140142
+ (conj(U12s[k1][i, l]) * U22s[k1][j, l] * (1 - nFs[k1][l])))
141143
M.Gk = reshape(Gk, M.bz.gridSize...)
142144
M.Fk = reshape(Fk, M.bz.gridSize...)
@@ -152,14 +154,14 @@ Finding the equal-time Greens functions and anomalous Greens function in real sp
152154
153155
"""
154156
function GetGr!(M::BdGModel)
155-
157+
156158
phaseShift = MomentumPhaseFFT(M.bz, M.uc_hop)
157159

158-
Gr = FFTArrayofMatrix(M.Gk)
159-
M.Gr = Gr .* phaseShift
160+
Gr = FFTArrayofMatrix(M.Gk)
161+
M.Gr = Gr .* phaseShift
160162

161-
Fr = FFTArrayofMatrix(M.Fk)
162-
M.Fr = Fr .* phaseShift
163+
Fr = FFTArrayofMatrix(M.Fk)
164+
M.Fr = Fr .* phaseShift
163165
end
164166

165167

@@ -169,9 +171,10 @@ SolveModel!(M::BdGModel)
169171
```
170172
one-step function to find all the attributes in BdGModel after it has been initialized.
171173
"""
172-
function SolveModel!(M::BdGModel ; mu_guess::Float64 = M.Ham.bandwidth[1] + M.filling * (M.Ham.bandwidth[2] - M.Ham.bandwidth[1]), get_correlations::Bool = true, get_gap::Bool = false, verbose::Bool = true, mu_tol::Float64 = 1e-3, filling_tol::Float64 = 1e-6)
174+
function SolveModel!(M::BdGModel ; mu_guess::Float64 = 2*M.Ham.bandwidth[1] + 2*M.filling * (M.Ham.bandwidth[2] - M.Ham.bandwidth[1]), get_correlations::Bool = true, get_gap::Bool = false, verbose::Bool = true, mu_tol::Float64 = 1e-3, filling_tol::Float64 = 1e-6)
173175
@assert M.Ham.is_BdG==true "Use other format for pure hopping Hamiltonian"
174-
176+
# println(mu_guess)
177+
# println(M.Ham.bandwidth)
175178
if M.filling<0 ##### Must imply that filling was not provided by user and hence needs to be calculated from given mu
176179
GetFilling!(M)
177180
else
@@ -188,7 +191,7 @@ one-step function to find all the attributes in BdGModel after it has been init
188191
GetGk!(M)
189192
GetGr!(M)
190193
end
191-
194+
192195
if verbose
193196
@info "System Filled!"
194197
end
@@ -225,4 +228,14 @@ Calculate the free energy of the given `BdGModel`.
225228
end
226229

227230

228-
end
231+
# function entropy(M::BdGModel)
232+
# Es = 2*reduce(vcat, M.Ham.bands)
233+
# ps = DistFunction(Es; T=M.T, mu=M.mu, stat=M.stat)
234+
235+
236+
# return S
237+
238+
239+
end
240+
241+
# end

0 commit comments

Comments
 (0)