-
Notifications
You must be signed in to change notification settings - Fork 0
/
fermi_gas.py
879 lines (708 loc) · 29 KB
/
fermi_gas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
"""
Compute properties of a one- or two-component non-interacting Fermi gas
"""
import numpy as np
from scipy.optimize import root_scalar, minimize
from warnings import warn
def fermi(beta,
mu,
energy) -> np.ndarray:
"""
Fermi function, handling beta = 0 and infinity appropriately. Beta, mu, and energy should be provided in consistent
energy units. This function is compatible with array broadcasting.
:param beta: inverse temperature
:param mu: chemical potential
:param energy: energy
:return: fermi function at given beta, mu, energy
"""
# ensure numpy arrays of at least 1 dimension
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
energy = np.asarray(energy)
if energy.ndim == 0:
energy = energy[None]
mu = np.asarray(mu)
if mu.ndim == 0:
mu = mu[None]
nf = np.divide(1, np.exp(beta * (energy - mu)) + 1)
# handle zero temperature
nf[np.logical_and(beta == np.inf, energy - mu <= 0)] = 1.
nf[np.logical_and(beta == np.inf, energy - mu > 0)] = 0.
# infinite temperature, nothing to do
return nf
def fermi_derivatives(beta,
mu,
energy,
eta: float = 0.1):
"""
Calculate the derivatives of the fermi function with respect to the various inputs. Beta, mu, and
energy should be given in consistent units.
:param beta: inverse temperature
:param mu: chemical potential
:param energy: energy
:param eta: broadening parameter. TODO: Does this do anything?
:return: (dfdmu, dfde, dfdbeta, dfdT)
"""
# ensure numpy arrays of at least 1 dimension
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
energy = np.asarray(energy)
if energy.ndim == 0:
energy = energy[None]
mu = np.asarray(mu)
if mu.ndim == 0:
mu = mu[None]
# compute derivative
e_minus_mu = energy - mu
beta_times_e_minus_mu = beta * e_minus_mu
dfdx = -fermi(beta, mu, energy) * (1 - fermi(beta, mu, energy))
dfdu = -beta * dfdx
dfde = beta * dfdx
dfdbeta = (energy - mu) * dfdx
# handle zero temperature. In this case, dfdu would be a delta function, because f is a step. To do numerical
# calculations we must broaden the delta function by parameter eta
# TODO: is this implemented correctly/what does it do?
infinite_t_pts = np.logical_or(beta_times_e_minus_mu == np.inf, np.isnan(beta_times_e_minus_mu))
if np.any(infinite_t_pts):
dfdu[infinite_t_pts] = np.divide(np.pi / eta, e_minus_mu[infinite_t_pts] ** 2 + eta ** 2)
dfde[infinite_t_pts] = np.divide(np.pi / eta, e_minus_mu[infinite_t_pts] ** 2 + eta ** 2)
dfdbeta[infinite_t_pts] = np.divide(np.pi / eta, e_minus_mu[infinite_t_pts] ** 2 + eta ** 2)
return dfdu, dfde, dfdbeta
def get_allowed_kvects(nx: int,
ny: int,
mode: str = 'balanced'):
"""
Get k-vectors allowed on a periodic lattice of sizes Nx x Ny.
:param nx:
:param ny:
:param mode: either 'balanced' or
:return: (kxkx, kyky, dkx, dky)
kxkx is a grid of kx vectors of size Ny x Nx
dkx is kx spacing
"""
kxs = 2 * np.pi / nx * np.arange(0, nx)
kys = 2 * np.pi / ny * np.arange(0, ny)
dkx = 2 * np.pi / nx
dky = 2 * np.pi / ny
if mode == 'balanced':
kxs[kxs >= np.pi] = kxs[kxs >= np.pi] - 2 * np.pi
kys[kys >= np.pi] = kys[kys >= np.pi] - 2 * np.pi
kxs.sort()
kys.sort()
elif mode == 'positive':
pass
else:
raise Exception("mode should be either 'balanced' or 'positive' but was %s." % mode)
kxkx, kyky = np.meshgrid(kxs, kys)
return kxkx, kyky, dkx, dky
def get_energy_spacing(es):
"""
Compute mean energy spacing from a 1D or 2D distribution of energies
:param es: energies, array of arbitrary shape.
:return: (emin, emax, emean)
emin: minimum spacing between adjacent energies.
emax: maximum spacing between adjacent energies.
emean: mean spacing between adjacent energies.
"""
es_list = np.sort(es.ravel())
ediff = np.round(es_list[1:] - es_list[:-1], 12)
ediff = ediff[ediff > 0]
return np.min(ediff), np.max(ediff), np.mean(ediff)
def get_dos(es,
e_end_pts):
"""
Determine density of states in energy bins for given energy spectrum
:param es:
:param e_end_pts:
:return:
"""
e_means = 0.5 * (e_end_pts[1:] + e_end_pts[:-1])
de = e_end_pts[1:] - e_end_pts[:-1]
num_in_bin, _ = np.histogram(es.ravel(), e_end_pts)
dos = np.divide(num_in_bin, de) / es.size
return dos
def get_dos2(nsites: int = 100,
dim: str = '2d'):
"""
:param nsites:
:param dim:
:return:
"""
# TODO: want function that will automatically choose good binning to get a smooth DOS
if dim == '2d':
kxkx, kyky, _, _ = get_allowed_kvects(nsites, nsites, 'balanced')
dispersion = lambda kx, ky: -2 * (np.cos(kx) + np.cos(ky))
es = dispersion(kxkx, kyky)
elif dim == '1d':
kxkx, _, _, _ = get_allowed_kvects(nsites, 1, 'balanced')
dispersion = lambda kx: -2 * np.cos(kxkx)
es = dispersion(kxkx)
else:
raise Exception("expected dim to be '1d' or '2d' but it was '%s'" % dim)
# determine bin widths from energy spacing
emin, emax, emean = get_energy_spacing(es)
# empircally need something like this many points per bin to get smooth DOS
pts_per_bin = 2000
de = pts_per_bin * emean
# determine bin number from bin widths
nbins = np.floor((np.max(es) - np.min(es)) / de)
# ensure odd number of bins
if nbins % 2 == 0:
nbins = nbins + 1
# bin edges and means
e_bin_end_pts = np.linspace(np.min(es), np.max(es), nbins)
e_means = 0.5 * (e_bin_end_pts[1:] + e_bin_end_pts[:-1])
num_in_bin, _ = np.histogram(es.ravel(), e_bin_end_pts)
dos = np.divide(num_in_bin, de) / es.size
return dos, e_means
# green's functions
def fg_kspace_gfns(beta,
mu,
ks,
time: float = 0.,
type: str = "greater",
dim: str = "2d"):
"""
Calculate non-interacting gas green's function and their derivatives.
All energies are in units of the tunneling energy.
The various green's functions are defined as
.. math::
G_\\text{greater}(k, t) &= -i \\langle c_k(t) c^\\dagger_k(0) \\rangle
G_\\text{lesser}(k, t) &= i \\langle c^\\dagger_k(0) c_k(t) \\rangle
G_\\text{retarded}(k, t) &= -i \\theta(t) \\left \\langle \\left[c_k(t), c^\\dagger_k(0) \\right]_+ \\right \\rangle
G_\\text{advanced}(k, t) &= i \\theta(-t) \\left \\langle \\left[ c_k(t), c^\\dagger_k(0) \\right]_+ \\right \\rangle
G_\\text{time-ordered}(k, t) &= -i \\langle T c_k(t) c^\\dagger_k(0) \\rangle
:param beta: inverse temperature, in units of the tunneling energy.
:param mu: chemical potential, in units of the tunneling energy.
:param ks:
:param time: Time argument to Green's function. In units of hbar/t.
:param dim: dimensionality of gas: '1d' or '2d'
:param type: type of Green's function to compute: "greater", "lesser", "retarded", "advanced" or "time-ordered"
:return: (gfn, dgdmu)
gfn: Value of Green's function of given type at given parameters.
"""
# TODO: handle either multiple beta/mus or multiple times
# ensure numpy arrays of dim greater than zero
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
mu = np.asarray(mu)
if mu.ndim == 0:
mu = mu[None]
ks = np.asarray(ks)
if ks.ndim == 0:
ks = ks[None]
if dim == "1d":
if ks.ndim != 1:
raise Exception("Expected one dimensional k-vector, but ks had a different number of dimensions.")
if dim == "2d":
if ks.ndim == 1 and ks.size == 2:
ks = ks[None, :]
if ks.ndim != 2:
raise Exception("Expected two dimensional k-vector, but ks had a different number of dimensions.")
time = np.asarray(time)
if time.ndim == 0:
time = time[None]
if dim == '2d':
dispersion = lambda kx, ky: -2 * (np.cos(kx) + np.cos(ky))
ek = dispersion(ks[:, 0], ks[:, 1])
elif dim == '1d':
dispersion = lambda kx: -2 * np.cos(kx)
ek = dispersion(ks)
else:
raise Exception("dim should be either '1d' or '2d' but was %s." % dim)
# calculations for various green's functions
if type == "greater":
gfn = -1j * np.exp(-1j * (ek - mu) * time) * (1. - fermi(beta, mu, ek))
dfdmu = fermi_derivatives(beta, mu, ek)[0]
dgdmu = (time * np.exp(-1j * (ek - mu) * time) * (1. - fermi(beta, mu, ek)) +
1j * np.exp(-1j * (ek - mu) * time) * dfdmu)
elif type == "lesser":
gfn = 1j * np.exp(-1j * (ek - mu) * time) * fermi(beta, mu, ek)
dfdmu = fermi_derivatives(beta, mu, ek)[0]
dgdmu = (-time * np.exp(-1j * (ek - mu) * time) * fermi(beta, mu, ek) +
1j * np.exp(-1j * (ek - mu) * time) * dfdmu)
elif type == "retarded":
# TODO: what is correct t=0 intepretation? I guess it should be taking limit from t>0?
gfn = -1j * np.heaviside(time, 1.) * np.exp(-1j * (ek - mu) * time)
dgdmu = time * np.heaviside(time, 1.) * np.exp(-1j * (ek - mu) * time)
elif type == "advanced":
gfn = 1j * np.heaviside(-time, 1.) * np.exp(-1j * (ek - mu) * time)
dgdmu = -time * np.heaviside(-time, 1.) * np.exp(-1j * (ek - mu) * time)
elif type == "time-ordered":
gfn = -1j * np.exp(-1j * (ek - mu) * time) * (np.heaviside(time, 1.) * (1. - fermi(beta, mu, ek))
- np.heaviside(-time, 1.) * fermi(beta, mu, ek))
# TODO: implement
dgdmu = 0 * ek
else:
raise ValueError(f"Expected type argument to be 'greater', 'lesser', 'retarded', 'advanced' or 'time-ordered',"
f" but it was '{type:s}'.")
return gfn, dgdmu
def fg_realspace_gfn(beta,
mu,
corr_index: tuple = (1, 0),
time: float = 0.,
nsites: int = 100,
dim: str = '2d',
type: str = "greater"):
"""
Calculate real space green's functions :math:`G(t-t', r-r')` by Fourier transforming momentum spacing functions.
:param beta: inverse temperature
:param mu: chemical potential
:param corr_index: two component index which gives the separation r-r' in terms of lattice sites
:param time: time, which gives t-t' in
:param nsites: number of sites to use in k-space computation
:param dim: Dimension of the fermi gas, either '1d' or '2d'
:param type: 'greater', 'lesser', 'retarded', 'advanced', or 'time-ordered'
:return:
"""
# ensure numpy arrays of at least 1 dimension
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
mu = np.asarray(mu)
if mu.ndim == 0:
mu = mu[None]
# ensure correct sizes
if beta.size == 1 and mu.size > 1:
beta = beta * np.ones(mu.shape)
elif beta.size > 1 and mu.size == 1:
mu = mu * np.ones(beta.shape)
elif beta.size == mu.size:
pass
else:
raise ValueError('mu and beta must be the same size, or one of them should be a single number'
' and the other an array.')
# TODO: implement so when calculating multiple temperatures don't need to calculate k-vector each time
if beta.size > 1:
gfn = np.zeros(beta.shape, dtype=complex)
dgdmu = np.zeros(beta.shape, dtype=complex)
for ii in range(beta.size):
coord = np.unravel_index(ii, beta.shape)
gfn[coord], dgdmu[coord] = fg_realspace_gfn(beta[coord],
mu[coord],
corr_index,
time,
nsites=nsites,
dim=dim,
type=type)
else:
# TODO: use FFT instead?
if dim == '2d':
kxkx, kyky, dkx, dky = get_allowed_kvects(nsites, nsites, 'balanced')
dispersion = lambda kx, ky: -2 * (np.cos(kx) + np.cos(ky))
es = dispersion(kxkx, kyky)
ft = np.exp(1j * kxkx * corr_index[0] + 1j * kyky * corr_index[1]).ravel()
ks = np.concatenate((np.ravel(kxkx)[:, None], np.ravel(kyky)[:, None]), axis=1)
gfn_k, dgdmu_k = fg_kspace_gfns(beta, mu, ks, time, type, dim)
elif dim == '1d':
kxkx, _, dkx, _ = get_allowed_kvects(nsites, 1, 'balanced')
kxkx = kxkx.ravel()
dispersion = lambda kx: -2 * np.cos(kxkx)
es = dispersion(kxkx)
ft = np.exp(1j * kxkx * corr_index[0])
gfn_k, dgdmu_k = fg_kspace_gfns(beta, mu, kxkx, time, type, dim)
else:
raise Exception("expected dim to be '1d' or '2d' but it was '%s'" % dim)
emin, emax, emean = get_energy_spacing(es)
if emean > 1. / beta:
warn(f"mean energy spacing is larger than temperature. "
f"Minimum energy spacing is {emean:.3g} "
f"but temperature is {1. / beta[0]:.3g}")
# real space green's function is fourier transform of k-space green's function
# 1 / N = dkx * dky / (2*np.pi)**2 for 2D or dkx / (2*np.pi) for 1D
gfn = 1 / float(kxkx.size) * np.sum(ft * gfn_k)
dgdmu = 1 / float(kxkx.size) * np.sum(ft * dgdmu_k)
return gfn, dgdmu
# thermodynamic quantities
def fg_density(beta,
mu,
nsites: int = 100,
dim: str = '2d'):
"""
Compute the density of a Fermi gas in a lattice with tight-binding dispersion
:param beta: temperature in units of the tunneling
:param mu: chemical potential in units of the tunneling
:param nsites: number of sites along each dimension to use in the calculation
:param dim: '1d' or '2d'
:return: density
"""
density, _ = fg_realspace_gfn(beta, mu, corr_index=[0, 0], time=0., nsites=nsites, dim=dim, type="lesser")
density = np.abs(density)
return density
def fg_mu(beta,
density,
nsites: int = 100,
dim: str = '2d'):
"""
Compute the chemical potential for a non-interacting Fermi gas with tightbinding dispersion at given temperature
and density.
:param beta:
:param density:
:param nsites:
:param dim:
:return mu:
"""
# TODO: this still fails at T = 0 and low T near half-filling
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
density = np.asarray(density)
if density.ndim == 0:
density = density[None]
if beta.size == 1 and density.size > 1:
beta = beta * np.ones(density.shape)
elif beta.size > 1 and density.size == 1:
density = density * np.ones(beta.shape)
elif beta.size == density.size:
pass
else:
raise ValueError('n and beta must be the same size, or one of them should be a single number'
' and the other an array.')
if beta.size > 1:
mu = np.zeros(beta.shape)
for ii in range(beta.size):
coord = np.unravel_index(ii, beta.shape)
mu[coord] = fg_mu(beta[coord], density[coord], nsites, dim)
else:
min_fn = lambda mu: np.abs(fg_density(beta, mu, nsites, dim) - density)
jacobian = lambda mu: fg_compressibility(beta, mu, nsites, dim)
jacobian_fsqr = lambda mu: 2 * min_fn(mu) * jacobian(mu)
# mu_guess = np.array([0.0])
# result = scipy.optimize.minimize(min_fn, mu_guess)
# mu = result.x
if density == 0.5:
mu = 0
elif beta != np.inf:
# seems to work more robustly than scipy.optimize.minimize
# but fails at half-filling. jacobian_fsqr has a zero there...is that the reason?
fit_handle = root_scalar(jacobian_fsqr, x0=-0.1, x1=0.1)
mu = fit_handle.root
else:
# jacobian_fsqr = -inf here, which is why this fials otherwise...
mu_guess = np.array([0.0])
result = minimize(min_fn, mu_guess)
mu = result.x
return mu
def fg_compressibility(beta,
mu,
nsites: int = 100,
dim: str = '2d'):
"""
Compute the compressibility of a single component Fermi gas in a lattice with tight-binding dispersion
:param beta: temperature in units of the tunneling
:param mu: chemical potential in units of the tunneling
:param nsites: number of sites along each dimension to use in the calculation
:param dim: '1d' or '2d'
:return: density
"""
# TODO: doesn't work for zero temperature...
_, dgdmu = fg_realspace_gfn(beta, mu, corr_index=[0, 0], time=0., nsites=nsites, dim=dim, type="lesser")
dndmu = np.abs(dgdmu)
return dndmu
# correlators and response function
def fg_corr(beta,
mu,
corr_index: tuple = (1, 0),
nsites: int = 100,
dim: str = '2d'):
"""
Compute the correlator :math:`\\left \\langle n_i n_j \\right \\rangle - \\left \\langle n \\right \\rangle^2` for a single component non-interacting fermi gas with a lattice dispersion.
:param beta: Inverse temperature, in units of the hopping
:param mu: Chemical potential, in units of the hopping.
:param corr_index:
:param nsites: Number of lattice sites in each dimension to be used in the calculation
:param dim: "1d" or "2d"
:return:
"""
gfn_lesser = fg_realspace_gfn(beta, mu, corr_index, 0., nsites, dim, type="lesser")[0]
delta = not np.any(corr_index)
corr = delta * np.abs(gfn_lesser) - np.abs(gfn_lesser)**2
return corr
def fg_density_response(beta,
mu,
k: np.ndarray = np.array([0., 0.]),
omega: float = 0.,
eta: float = 0.,
nsites: int = 100,
dim: str = '2d'):
"""
:param beta:
:param mu:
:param k:
:param omega:
:param eta:
:param nsites:
:param dim:
:return:
"""
# ensure numpy arrays of at least 1 dimension
# TODO: is there a better way to do broadcasting etc?
# TODO: allow finite omega
# TODO: also get imaginary part
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
mu = np.asarray(mu)
if mu.ndim == 0:
mu = mu[None]
k = np.asarray(k)
if k.ndim == 0:
k = k[None]
# ensure correct sizes
if beta.size == 1 and mu.size > 1:
beta = beta * np.ones(mu.shape)
elif beta.size > 1 and mu.size == 1:
mu = mu * np.ones(beta.shape)
elif beta.size == mu.size:
pass
else:
raise Exception('mu and beta must be the same size, or one of them should be a single number and '
'the other an array.')
if dim == '2d':
kxkx, kyky, _, _ = get_allowed_kvects(nsites, nsites, 'balanced')
# get e_k+q
kxkx_shift = kxkx + k[0]
kyky_shift = kyky + k[1]
# get energies
dispersion = lambda kx, ky: -2 * (np.cos(kx) + np.cos(ky))
es = dispersion(kxkx, kyky)
es_q = dispersion(kxkx_shift, kyky_shift)
elif dim == '1d':
kxkx, _, _, _ = get_allowed_kvects(nsites, 1, 'balanced')
kxkx_shift = kxkx + k[0]
# get energies
dispersion = lambda kx: -2 * np.cos(kxkx)
es = dispersion(kxkx)
es_q = dispersion(kxkx_shift)
else:
raise Exception()
if beta.size > 1:
chi_real = np.zeros(beta.shape)
chi_imag = np.zeros(beta.shape)
for ii in range(beta.size):
coord = np.unravel_index(ii, beta.shape)
chi_real[coord], chi_imag[coord] = fg_density_response(beta[coord],
mu[coord],
k,
omega=omega,
eta=eta,
nsites=nsites,
dim=dim)
else:
# this expression holds except where we have accidental degeneracies.
chi_terms = np.divide(fermi(beta, mu, es) - fermi(beta, mu, es_q), omega + es - es_q + 1j * eta)
# at those points, use L'Hopital's rule to get finite value
lim = -fermi_derivatives(beta, mu, es, eta=0.0)[0]
chi_terms[np.isnan(chi_terms)] = lim[np.isnan(chi_terms)]
# sum them to get chi
chi = np.sum(chi_terms) / kxkx.size
chi_real = np.real(chi)
chi_imag = np.imag(chi)
return chi_real, chi_imag
def fg_magnetic_response(beta,
mu,
k,
omega: float = 0.,
eta: float = 0.,
nsites: int = 100,
dim: str = '2d'):
"""
Fermi gas magnetic response function
:param beta:
:param mu:
:param k:
:param omega:
:param eta:
:param nsites:
:param dim:
:return:
"""
return fg_density_response(beta, mu, k, omega, eta, nsites, dim)
# non-interacting fg of two species
def fg_singles(beta,
mu_up,
mu_dn,
nsites: int = 100,
dim: str = '2d'):
"""
Compute singles density for a two-component non-interacting Fermi gas
:param beta:
:param mu_up:
:param mu_dn:
:param nsites:
:param dim:
:return:
"""
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
mu_up = np.asarray(mu_up)
if mu_up.ndim == 0:
mu_up = mu_up[None]
mu_dn = np.asarray(mu_dn)
if mu_dn.ndim == 0:
mu_dn = mu_dn[None]
n_up = fg_density(beta, mu_up, nsites, dim)
n_dn = fg_density(beta, mu_dn, nsites, dim)
singles = n_up + n_dn - 2 * n_up * n_dn
return singles
def fg_singles_corr(beta,
mu_up,
mu_dn,
corr_index: tuple = (0, 1),
nsites: int = 100,
dim: str = '2d'):
"""
Compute correlations between singles for a two-component non-interacting Fermi gas
.. math::
\\left \\langle n_s(i) n_s(j) \\right \\rangle &=
&= \\left \\langle [n_\\uparrow(i) + n_\\downarrow(i) - 2 n_\\uparrow(i) n_\\downarrow(i)]
[n_\\uparrow (j) + n_\\downarrow(j) - 2 n_\\uparrow(j) n_\\downarrow(j)] \\right \\rangle
&= \\left \\langle n_\\uparrow(i) n_\\uparrow(j) \\right \\rangle
+ \\left \\langle n_\\downarrow (i) n_\\downarrow(j) \\right \\rangle
+ 4 \\left \\langle d(i) d(j) \\right \\rangle
- 2 \\left \\langle n_\\uparrow (i) d(j) \\right \\rangle
- 2 \\left \\langle n_\\downarrow(i) d(j) \\right \\rangle
- 2 \\left \\langle d(i) n_\\uparrow(j) \\right \\rangle
- 2 \\left \\langle d(i) n_\\downarrow(j) \\right \\rangle
We also evaluate the :math:`\\left \\langle n_{i \\uparrow} d_j \\right \\rangle` term using Wick's theorem.
Only one term contributes ...
.. math::
\\left \\langle n_\\uparrow(i) d(j) \\right \\rangle =&
-\\left \\langle c^\\dagger_\\uparrow(i) c_\\uparrow(j) \\right \\rangle
\\left \\langle c^\\dagger_{j \\uparrow} +
c_{i \\uparrow} \\right \\rangle \\left \\langle c^\\dagger_{j \\downarrow} c_{j \\downarrow} \\right \\rangle + ...
&= \\left \\langle n_\\uparrow(i) n_\\uparrow(j) \\right \\rangle_c \\left \\langle n_\\downarrow(j) \\right \\rangle
:param beta:
:param mu_up:
:param mu_dn:
:param corr_index:
:param nsites:
:param dim:
:return:
"""
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
mu_up = np.asarray(mu_up)
if mu_up.ndim == 0:
mu_up = mu_up[None]
mu_dn = np.asarray(mu_dn)
if mu_dn.ndim == 0:
mu_dn = mu_dn[None]
n_up = fg_density(beta, mu_up, nsites, dim)
n_dn = fg_density(beta, mu_dn, nsites, dim)
n_up_corr = fg_corr(beta, mu_up, corr_index, nsites, dim)
n_dn_corr = fg_corr(beta, mu_dn, corr_index, nsites, dim)
singles_corr = (n_up_corr * (1 + 4 * n_dn ** 2 - 4 * n_dn) +
n_dn_corr * (1 + 4 * n_up ** 2 - 4 * n_up) +
4 * n_up_corr * n_dn_corr)
return singles_corr
def fg_doubles(beta,
mu_up,
mu_dn,
nsites: int = 100,
dim: str = '2d'):
"""
Compute doubles density for a two-component non-interacting Fermi gas
:param beta:
:param mu_up:
:param mu_dn:
:param nsites:
:param dim:
:return:
"""
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
mu_up = np.asarray(mu_up)
if mu_up.ndim == 0:
mu_up = mu_up[None]
mu_dn = np.asarray(mu_dn)
if mu_dn.ndim == 0:
mu_dn = mu_dn[None]
n_up = fg_density(beta, mu_up, nsites, dim)
n_dn = fg_density(beta, mu_dn, nsites, dim)
d = n_up * n_dn
return d
def fg_doubles_corr(beta,
mu_up,
mu_dn,
corr_index: tuple = (0, 1),
nsites: int = 100,
dim: str = '2d'):
"""
Compute correlations between doubles for a two-component non-interacting Fermi gas. Using
Wick's theorem we can write this as
.. math::
\\left \\langle d(i) d(j) \\right \\rangle_c = n_\\uparrow^2 \\left \\langle n_\\uparrow(i) n_\\uparrow(j) \\right \\rangle_c
n_\\downarrow^2 \\left \\langle n_\\downarrow(i) n_\\downarrow(j) \\right \\rangle_c
+ \\left \\langle n_\\uparrow(i) n_\\uparrow(j) \\right \\rangle_c \\left \\langle n_\\downarrow(i) n_\\downarrow(j) \\right \\rangle_c
:param beta:
:param mu_up:
:param mu_dn:
:param corr_index:
:param nsites:
:param dim:
:return:
"""
beta = np.asarray(beta)
if beta.ndim == 0:
beta = beta[None]
mu_up = np.asarray(mu_up)
if mu_up.ndim == 0:
mu_up = mu_up[None]
mu_dn = np.asarray(mu_dn)
if mu_dn.ndim == 0:
mu_dn = mu_dn[None]
n_up = fg_density(beta, mu_up, nsites, dim)
n_dn = fg_density(beta, mu_dn, nsites, dim)
n_up_corr = fg_corr(beta, mu_up, corr_index, nsites, dim)
n_dn_corr = fg_corr(beta, mu_dn, corr_index, nsites, dim)
doubles_corr = n_up ** 2 * n_dn_corr + n_dn ** 2 * n_up_corr + n_up_corr * n_dn_corr
return doubles_corr
def fg_sz_corr(beta,
mu_up,
mu_dn,
corr_index: tuple = (0, 1),
nsites: int = 100,
dim: str = '2d'):
"""
Spin correlations for Fermi gas
:math:`4 \\left \\langle S^z S^z \\right \\rangle_c =
\\left \\langle(n_\\uparrow - n_\\downarrow) (n_\\uparrow - n_\\downarrow) \\right \\rangle`
:param beta:
:param mu_up:
:param mu_dn:
:param corr_index:
:param nsites:
:param dim:
:return:
"""
n_up_corr = fg_corr(beta, mu_up, corr_index, nsites, dim)
n_dn_corr = fg_corr(beta, mu_dn, corr_index, nsites, dim)
return n_up_corr + n_dn_corr
def fg_sx_corr(beta,
mu_up,
mu_dn,
corr_index: tuple = (0, 1),
nsites: int = 100,
dim: str = '2d'):
"""
Sx or Sy spin correlations for Fermi gas
:param beta:
:param mu_up:
:param mu_dn:
:param corr_index:
:param nsites:
:param dim:
:return:
"""
gfn_lesser_up = fg_realspace_gfn(beta, mu_up, corr_index, 0., nsites, dim, type="lesser")[0]
gfn_lesser_dn = fg_realspace_gfn(beta, mu_dn, corr_index, 0., nsites, dim, type="lesser")[0]
delta = not np.any(corr_index)
corr_sx = np.real(delta * (np.abs(gfn_lesser_up) + np.abs(gfn_lesser_dn)) - gfn_lesser_up * gfn_lesser_dn.conj() - gfn_lesser_dn * gfn_lesser_up.conj())
return corr_sx