@@ -6,7 +6,7 @@ module BdG
6
6
using .. TightBindingToolkit. DesignUCell: ModifyIsotropicFields!
7
7
using .. TightBindingToolkit. BZone: BZ, MomentumPhaseFFT
8
8
using .. TightBindingToolkit. Hams: Hamiltonian, ModifyHamiltonianField!
9
-
9
+
10
10
using LinearAlgebra, Tullio, TensorCast, Logging, Statistics
11
11
12
12
import .. TightBindingToolkit. TBModel: FindFilling, GetMu!, GetFilling!, GetGk!, GetGr!, SolveModel!, GetGap!, FreeEnergy
@@ -27,7 +27,7 @@ module BdG
27
27
- `Gk :: Array{Matrix{ComplexF64}}` : An Array (corresponding to the grid of k-points in `BZ`) of Greens functions.
28
28
- `Fk :: Array{Matrix{ComplexF64}}` : An Array (corresponding to the grid of k-points in `BZ`) of anomalous Greens functions.
29
29
30
- Initialize this structure using
30
+ Initialize this structure using
31
31
```julia
32
32
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)
33
33
```
@@ -53,7 +53,7 @@ module BdG
53
53
Fk :: Array{Matrix{ComplexF64}}
54
54
Gr :: Array{Matrix{ComplexF64}}
55
55
Fr :: Array{Matrix{ComplexF64}}
56
-
56
+
57
57
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))... ))
58
58
# #### 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!
59
59
end
@@ -75,10 +75,12 @@ Because of this, if you want to calculate the filling at a different chemical po
75
75
Eks = reshape (getindex .(M. Ham. bands, Ref (1 : N÷ 2 )), prod (M. bz. gridSize))
76
76
U11s = reshape (getindex .(M. Ham. states, Ref (1 : N÷ 2 ), Ref (1 : N÷ 2 )), prod (M. bz. gridSize))
77
77
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))
78
80
79
81
nFs = DistFunction .(Eks; T= M. T, mu= 0.0 , stat= M. stat)
80
82
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])
82
84
+ (conj (U21s[k1][i, j]) * U21s[k1][i, j] * (1 - nFs[k1][j])))
83
85
84
86
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)
109
111
Function to get the correct chemical potential given a filling.
110
112
"""
111
113
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)
113
115
@info " Found chemical potential μ = $(M. mu) for given filling = $(M. filling) ."
114
-
116
+
115
117
end
116
118
117
119
@@ -127,16 +129,16 @@ Finding the Greens functions, and anomalous greens functions in momentum space a
127
129
Eks = reshape (getindex .(M. Ham. bands, Ref (1 : N÷ 2 )) , prod (M. bz. gridSize)) # #### Only the negative energies from the bdG spectrum
128
130
129
131
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))
132
134
U22s = reshape (getindex .(M. Ham. states, Ref (N÷ 2 + 1 : N), Ref (N÷ 2 + 1 : N)) , prod (M. bz. gridSize))
133
135
134
136
nFs = DistFunction .(Eks; T= M. T, mu= 0.0 , stat= M. stat)
135
137
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])))
138
140
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])
140
142
+ (conj (U12s[k1][i, l]) * U22s[k1][j, l] * (1 - nFs[k1][l])))
141
143
M. Gk = reshape (Gk, M. bz. gridSize... )
142
144
M. Fk = reshape (Fk, M. bz. gridSize... )
@@ -152,14 +154,14 @@ Finding the equal-time Greens functions and anomalous Greens function in real sp
152
154
153
155
"""
154
156
function GetGr! (M:: BdGModel )
155
-
157
+
156
158
phaseShift = MomentumPhaseFFT (M. bz, M. uc_hop)
157
159
158
- Gr = FFTArrayofMatrix (M. Gk)
159
- M. Gr = Gr .* phaseShift
160
+ Gr = FFTArrayofMatrix (M. Gk)
161
+ M. Gr = Gr .* phaseShift
160
162
161
- Fr = FFTArrayofMatrix (M. Fk)
162
- M. Fr = Fr .* phaseShift
163
+ Fr = FFTArrayofMatrix (M. Fk)
164
+ M. Fr = Fr .* phaseShift
163
165
end
164
166
165
167
@@ -169,9 +171,10 @@ SolveModel!(M::BdGModel)
169
171
```
170
172
one-step function to find all the attributes in BdGModel after it has been initialized.
171
173
"""
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 )
173
175
@assert M. Ham. is_BdG== true " Use other format for pure hopping Hamiltonian"
174
-
176
+ # println(mu_guess)
177
+ # println(M.Ham.bandwidth)
175
178
if M. filling< 0 # #### Must imply that filling was not provided by user and hence needs to be calculated from given mu
176
179
GetFilling! (M)
177
180
else
@@ -188,7 +191,7 @@ one-step function to find all the attributes in BdGModel after it has been init
188
191
GetGk! (M)
189
192
GetGr! (M)
190
193
end
191
-
194
+
192
195
if verbose
193
196
@info " System Filled!"
194
197
end
@@ -225,4 +228,14 @@ Calculate the free energy of the given `BdGModel`.
225
228
end
226
229
227
230
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