-
Notifications
You must be signed in to change notification settings - Fork 6
/
lda.py
executable file
·2137 lines (1685 loc) · 77.4 KB
/
lda.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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import logging
# create logger
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from matplotlib import rc
rc('font',**{'family':'serif'})
rc('text', usetex=True)
from vec3 import vec3, cross
import scipy.constants as C
"""
This file provides a way of calculating trap profiles in the local density
approximation. It needs to have a way of calculating:
* local band structure
* local tunneling rate, t
* local onsite interactions, U
From these thre quantities it can go ahead an use the solutions to the
homogeneous Fermi-Hubbard (FH) model to calculate the LDA.
In the homogeenous FH problem the chemical potential and the zero of
energy are always specified with respect to some point in the local band
structure. This point depends on how the Hamiltonian is written down:
A. Traditional hamiltonian.
i, j : lattice sites
<i,j> : nearest neighbors
s : spin
su : spin-up
sd : spin-down
Kinetic energy = -t \sum_{s} \sum_{<i,j>} a_{i,s}^{\dagger} a_{j,s}
Onsite energy = U \sum_{i} n_{i,su} n_{i,sd}
Using the traditional hamiltonian half-filling occurrs at a chemical
potential mu = U/2.
The zero of energy in the traditional hamiltonian is exactly midway through
the lowest band of the U=0 hamiltonian.
B. Half-filling hamiltonian
Kinetic energy = -t \sum_{s} \sum_{<i,j>} a_{i,s}^{\dagger} a_{j,s}
Onsite energy = U \sum_{i} ( n_{i,su} - 1/2 )( n_{i,sd} - 1/2 )
Using the half-filling hamiltonian half-filling occurrs at a chemical
potential mu = 0, a convenient value.
The zero of energy in the half-filling hamiltonian is shifted by U/2
with respect to the zero in the traditional hamiltonian.
....
Considerations for LDA
....
When doing the local density approximation (LDA) we will essentially have a
homogenous FH model that is shifted in energy by the enveloping potential of
the trap and by the local band structure. In the LDA the zero of energy is
defined as the energy of an atom at a point where there are no external
potentials. A global chemical potential will be defined with respect to the
LDA zero of energy.
To calculate the local thermodynamic quantities, such as density, entropy,
double occupancy, etc. we will use theoretical results for a homogeneous FH
model. The local chemical potential will be determined based on the local
value of the enveloping potential and the local band structure (which can be
obtained from the local lattice depth).
"""
import udipole
import scubic
from mpl_toolkits.mplot3d import axes3d
from scipy import integrate
from scipy import optimize
from scipy.interpolate import interp1d
# Load up the HTSE solutions
from htse import htse_dens, htse_doub, htse_entr, htse_cmpr
from nlce import nlce_dens, nlce_entr, nlce_spi, nlce_cmpr
import qmc, qmc_spi
def get_dens( T, t, mu, U, select='htse', ignoreLowT=False, verbose=True):
""" This function packages all three methods for obtaining
the thermodynamic quantities: htse, nlce, qmc"""
if select == 'htse':
return htse_dens( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
elif select == 'nlce':
return nlce_dens( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
elif select == 'qmc':
return qmc.qmc_dens( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
def get_entr( T, t, mu, U, select='htse', ignoreLowT=False, verbose=True):
""" This function packages all three methods for obtaining
the thermodynamic quantities: htse, nlce, qmc"""
if select == 'htse':
return htse_entr( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
elif select == 'nlce':
return nlce_entr( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
elif select == 'qmc':
return qmc.qmc_entr( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
def get_spi( T, t, mu, U, select='htse', ignoreLowT=False, verbose=True):
""" This function packages all three methods for obtaining
the thermodynamic quantities: htse, nlce, qmc"""
if select == 'htse':
return np.ones_like( t )
elif select == 'nlce':
return nlce_spi( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
elif select == 'qmc':
return qmc.qmc_spi( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
def get_doub( T, t, mu, U, select='htse', ignoreLowT=False, verbose=True):
""" This function packages all three methods for obtaining
the thermodynamic quantities: htse, nlce, qmc"""
if select == 'htse':
return htse_doub( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
else:
raise "doublons not defined"
def get_cmpr( T, t, mu, U, select='htse', ignoreLowT=False, verbose=True):
""" This function packages all three methods for obtaining
the thermodynamic quantities: htse, nlce, qmc"""
if select == 'htse':
return htse_cmpr( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
elif select == 'nlce':
return nlce_cmpr( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
elif select == 'qmc':
return qmc.qmc_cmpr( T, t, mu, U, ignoreLowT=ignoreLowT, verbose=verbose)
#...............
# LDA CLASS
#...............
class lda:
"""
This class provides the machinery to do the lda. It provides a way to
determine the global chemical potential for a given number or for a half
filled sample.
"""
def __init__( self, **kwargs ):
self.verbose = kwargs.get('verbose', False)
# Flag to ignore errors related to the slope of the density profile
# or the slope of the band bottom
self.ignoreSlopeErrors = kwargs.get( 'ignoreSlopeErrors',False)
# Flag to ignore errors related to the global chemical potential
# spilling into the beams
self.ignoreMuThreshold = kwargs.get('ignoreMuThreshold', False )
# Flag to ignore errors related to low temperatures beyond the reach
# of the htse
self.ignoreLowT = kwargs.get('ignoreLowT',False)
# Flag to ignore errors related to a non-vanishing density
# distribution within the extents
self.ignoreExtents = kwargs.get('ignoreExtents',False)
# The potential needs to offer a way of calculating the local band
# band structure via provided functions. The following functions
# and variables must exist:
#
# To calculate lda:
# - pot.l
# - pot.bandStructure( X,Y,Z )
#
# To make plots
# - pot.unitlabel
# - pot.Bottom( X,Y,Z )
# - pot.LatticeMod( X,Y,Z )
# - pot.Info()
# - pot.EffAlpha()
# - pot.firstExcited( X,Y,Z )
# - pot.S0( X,Y,Z )
self.pot = kwargs.pop( 'potential', None)
if self.pot is None:
raise ValueError(\
'A potential needs to be defined to carry out the LDA')
# The potential also contains the lattice wavelength, which defines
# the lattice spacing
self.a = self.pot.l / 2.
# Initialize temperature. Temperature is specified in units of
# Er. For a 7 Er lattice t = 0.04 Er
self.T = kwargs.get('Temperature', 0.40 )
# Initialize interactions.
self.a_s = kwargs.get('a_s',300.)
# Initialize extents
self.extents = kwargs.pop('extents', 40.)
# Initialize the type of Hubbard solution
# type can be: 'htse', 'nlce', 'qmc'
self.select = kwargs.get('select','htse')
# Make a cut line along 111 to calculate integrals of the
# thermodynamic quantities
# set the number of points to use in the cut
if self.select == 'htse':
NPOINTS = 320
else:
NPOINTS = 80
OVERRIDE_NPOINTS = kwargs.pop('override_npoints', None)
if OVERRIDE_NPOINTS is not None:
NPOINTS = OVERRIDE_NPOINTS
direc111 = (np.arctan(np.sqrt(2)), np.pi/4)
unit = vec3(); th = direc111[0]; ph = direc111[1]
unit.set_spherical( 1., th, ph);
t111, self.X111, self.Y111, self.Z111, lims = \
udipole.linecut_points( direc=direc111, extents=self.extents,\
npoints=NPOINTS)
# Below we get the signed distance from the origin
self.r111 = self.X111*unit[0] + self.Y111*unit[1] + self.Z111*unit[2]
# Obtain band structure and interactions along the 111 direction
bandbot_111, bandtop_111, \
self.Ezero_111, self.tunneling_111, self.onsite_t_111 = \
self.pot.bandStructure( self.X111, self.Y111, self.Z111)
# The onsite interactions are scaled up by the scattering length
self.onsite_t_111 = self.a_s * self.onsite_t_111
self.onsite_111 = self.onsite_t_111 * self.tunneling_111
# Lowst value of E0 is obtained
self.LowestE0 = np.amin( bandbot_111 )
self.Ezero0_111 = self.Ezero_111.min()
#---------------------
# CHECK FOR NO BUMP IN BAND BOTTOM
#---------------------
# Calculate first derivative of the band bottom at small radii, to
# assess whether or not the potential is a valid potential
# (no bum in the center due to compensation )
positive_r = np.logical_and( self.r111 > 0. , self.r111 < 10. )
# absolute energy of the lowest band, elb
elb = bandbot_111[ positive_r ]
elb_slope = np.diff( elb ) < -1e-4
n_elb_slope = np.sum( elb_slope )
if n_elb_slope > 0:
msg = "ERROR: Bottom of the band has a negative slope"
if self.verbose:
print msg
print elb
print np.diff(elb)
print elb_slope
if not self.ignoreSlopeErrors:
raise ValueError(msg)
else:
if self.verbose:
print "OK: Bottom of the band has positive slope up to "\
+ "r111 = 10 um"
#------------------------------
# SET GLOBAL CHEMICAL POTENTIAL
#------------------------------
# Initialize global chemical potential and atom number
# globalMu can be given directly or can be specified via the
# number of atoms. If the Natoms is specified we calculate
# the required gMu using this function:
self.muHalfMott = self.onsite_111.max()/2.
if 'globalMu' in kwargs.keys():
# globalMu is given in Er, and is measured from the value
# of Ezero at the center of the potential
# When using it in the phase diagram it has to be changed to
# units of the tunneling
self.globalMu = kwargs.get('globalMu', 0.15)
if self.globalMu == 'halfMott':
self.globalMu = self.muHalfMott \
+ kwargs.get('halfMottPlus',0.)
else :
self.Number = kwargs.get('Natoms', 3e5)
self.Search_mu0(**kwargs)
#---------------------
# EVAPORATION ENERGIES
#---------------------
# Calculate energies to estimate eta parameter for evaporation
self.globalMuZ0 = self.Ezero0_111 + self.globalMu
# Make a cut line along 100 to calculate the threshold for evaporation
direc100 = (np.pi/2, 0.)
t100, self.X100, self.Y100, self.Z100, lims = \
udipole.linecut_points( direc=direc100, extents = 1200.)
# Obtain band structure along the 100 direction
bandbot_100, bandtop_100, self.Ezero_100, self.tunneling_100 = \
self.pot.bandStructure( self.X100, self.Y100, self.Z100, \
getonsite=False)
self.Ezero0_100 = self.Ezero_100.min()
# evapTH0_100 accounts for situations in which there is a local barrier
# as you move along 100 to the edge
self.evapTH0_100 = bandbot_100.max()
# Once past the local barrier we calculate the bandbot energy along
# a beam
self.beamBOT_100 = bandbot_100[-1]
if self.verbose:
#This obtains the value of g0, careful when using anisotropic params
scubic.get_max_comp( self.pot, 650., self.T, verbose=False)
#------------------------------------------------
# CONTROL THE CHEMICAL POTENTIAL SO THAT IT STAYS
# BELOW THE THRESHOLD FOR EVAPORATION
#------------------------------------------------
# For a valid scenario we need
# self.globalMuZ0 < self.beamBOT_100
# self.globalMuZ0 < self.evapTH0_100
# Otherwise the density distribution will spill out into the beams
# and the assumption of spherical symmetry won't be valid.
if self.globalMuZ0 + self.T*1.2 > self.evapTH0_100:
msg = "ERROR: Chemical potential exceeds the evaporation threshold "
if self.verbose:
print msg
print " mu0 = %.3f" % self.globalMuZ0
print " T = %.3f" % (self.T*1.2)
print " Eth = %.3f" % self.evapTH0_100
if not self.ignoreMuThreshold :
raise ValueError(msg)
elif self.verbose:
print "OK: Chemical potential is below evaporation threshold."
if self.globalMuZ0 + self.T*1.2 > self.beamBOT_100:
msg = "ERROR: Chemical potential exceeds the bottom of the band " +\
"along 100"
if self.verbose:
print msg
print " mu0 = %.3f" % self.globalMuZ0
print " T = %.3f" % (self.T*1.2)
print "E100 = %.3f" % self.beamBOT_100
if not self.ignoreMuThreshold :
raise ValueError(msg)
elif self.verbose:
print "OK: Chemical potential is below the bottom of the band " +\
"along 100"
#-----------------------
# ESTIMATION OF ETA EVAP
#-----------------------
mu = self.globalMuZ0 - self.LowestE0
th = self.evapTH0_100 - self.LowestE0
self.EtaEvap = th/mu
self.DeltaEvap = th - mu
if False:
print "mu global = %.3g" % self.globalMuZ0
print "evap th = %.3g" % self.evapTH0_100
print "lowest E = %.3g" % self.LowestE0
print "mu = %.3g" % mu
print "th = %.3g" % th
print "eta = %.3g" % (th/mu)
print "th-mu = %.3g" % (th-mu)
# After the chemical potential is established the local chemical
# potential along 111 can be defined. It is used to calculate other
# thermodynamic quantities
gMuZero = self.Ezero0_111 + self.globalMu
self.localMu_t_111= (gMuZero - self.Ezero_111) / self.tunneling_111
self.localMu_111= (gMuZero - self.Ezero_111)
localMu = gMuZero - self.Ezero_111
# If the global chemical potential is fixed then the lda
# class can have an easier time calculating the necessary
# temperature to obtain a certain entropy per particle.
# This option is provided here:
if ( 'globalMu' in kwargs.keys() and 'SN' in kwargs.keys() ) \
or kwargs.get('forceSN',False):
self.SN = kwargs.get('SN', 2.0)
# Shut down density extent errors during the search
igExt = self.ignoreExtents
self.ignoreExtents = True
fSN = lambda x : self.getEntropy(x) / \
self.getNumber(self.globalMu, x ) \
- self.SN
if self.verbose:
print "Searching for T => S/N=%.2f, "% self.SN
TBrent = kwargs.get('TBrent',(0.14,1.8))
try:
Tres, TbrentResults = \
optimize.brentq(fSN, TBrent[0], TBrent[1], \
xtol=2e-3, rtol=2e-3, full_output=True)
if self.verbose:
print "Brent T result = %.2f Er" % Tres
self.T = Tres
except Exception as e:
errstr = 'f(a) and f(b) must have different signs'
if errstr in e.message:
print "T0 = %.3f --> fSN = %.3f" % \
(TBrent[0], fSN(TBrent[0]) )
print "T1 = %.3f --> fSN = %.3f" % \
(TBrent[1], fSN(TBrent[1]) )
raise
print "Search for S/N=%.2f did not converge"%self.SN
print "Temperature will be set at T = %.2f Er" % self.T
print "ERROR:"
print e.message
print self.pot.Info()
print
self.ignoreExtents = igExt
# Once the temperature is established we can calculate the ratio
# of temperature to chemical potential, with the chem. potential
# measured from the lowest energy state
self.Tmu = self.T / mu
# We define an etaF_star which allows us to control for atoms
# spilling along the beams in situations with non-zero temperature
# such as what we can access with HTSE
self.etaF_star = self.EtaEvap - self.Tmu*1.4
# Obtain trap integrated values of the thermodynamic quantities
self.Number = self.getNumber( self.globalMu, self.T )
self.noEntropy = kwargs.get('noEntropy', False)
if not self.noEntropy:
self.Entropy = self.getEntropy( self.T)
def Search_mu0( self, **kwargs ):
# Choose here whether search is chaged to nlce:
select_previous = self.select
if False:
if select_previous == 'qmc':
self.select = 'nlce'
# First this is going to do a rough search for the
# atom number using NLCE at T=0.036
fN = lambda x : self.getNumber( self.muHalfMott + x,self.T, \
verbose=False)- self.Number
if 'halfMottPlus' in kwargs.keys():
muPlus = kwargs.get('halfMottPlus',0.)
muBrent = ( muPlus - 0.040, muPlus + 0.040 )
print "muPlus = %.3f"%muPlus
else:
muBrent = kwargs.get('muBrent', (-0.2, 0.3)) # Maybe the default
# muBrent range should
# be U dependent
muBrentShift = kwargs.get('muBrentShift', 0. )
muBrent = ( muBrent[0] + muBrentShift * self.muHalfMott, \
muBrent[1] + muBrentShift * self.muHalfMott )
if self.verbose :
print "Searching for globalMu => N=%.3g, "% self.Number,
try:
muBrentOpt, brentResults = \
optimize.brentq(fN, muBrent[0], muBrent[1], \
xtol=2e-3, rtol=1e-2, full_output=True)
print "muOpt = %.3f"% muBrentOpt
print "fN(muBrentOpt) = ", fN(muBrentOpt)
self.globalMu = self.muHalfMott + muBrentOpt
except Exception as e:
errstr = 'f(a) and f(b) must have different signs'
if errstr in e.message:
print "Natoms = {:.4g}".format(self.Number)
print "mu0 = %.2f --> Nlda = %.2g" % \
(muBrent[0], fN(muBrent[0]) + self.Number )
print "mu1 = %.2f --> Nlda = %.2g" % \
(muBrent[1], fN(muBrent[1]) + self.Number )
raise
if self.verbose:
print "gMu=%.3f, " % brentResults.root,
print "n_iter=%d, " % brentResults.iterations,
print "n eval=%d, " % brentResults.function_calls,
print "converge?=", brentResults.converged
self.select = select_previous
def Info( self ):
"""
Returns a latex string with the information pertinent to the
hubbard parameters
"""
# Tunneling label
tmin = self.tunneling_111.min()
tmin_kHz = tmin * 29.2
tlabel = '$t=%.2f\,\mathrm{kHz}$'%(tmin_kHz)
# Scattering length
aslabel = '$a_{s}=%.0fa_{0}$' % self.a_s
# U/t label
Utlabel = '$U/t=%.1f$' % self.onsite_t_111.max()
# Temperature label
Tlabel = '$T/t=%.1f$' % (self.T/self.tunneling_111).max()
LDAlabel = '\n'.join( [ aslabel, Utlabel, Tlabel, tlabel ] )
return LDAlabel
def ThermoInfo( self ):
"""
Returns a latex string with the information pertinent to the
calculated thermodynamic quantities.
"""
wLs = self.pot.w
waists = sum( wLs, ())
wL = np.mean(waists)
self.NumberD = self.getNumberD( self.T )
rlabel = r'$\mathrm{HWHM} = %.2f\,w_{L}$' % ( self.getRadius()/wL )
Nlabel = r'$N=%.2f\times 10^{5}$' % (self.Number/1e5)
Dlabel = r'$D=%.3f$' % ( self.NumberD / self.Number )
Slabel = r'$S/N=%.2fk_{\mathrm{B}}$' % ( self.Entropy / self.Number )
return '\n'.join([rlabel, Nlabel, Dlabel, Slabel])
def getRadius( self ):
"""
This function calculates the HWHM (half-width at half max) of the
density distribution.
"""
gMu = self.globalMu
T = self.T
gMuZero = self.Ezero0_111 + gMu
localMu = gMuZero - self.Ezero_111
density = get_dens( T, self.tunneling_111, localMu, \
self.onsite_111, select=self.select,\
ignoreLowT=self.ignoreLowT, \
verbose=self.verbose)
posradii = self.r111 >= 0.
r111pos = self.r111[ posradii]
posdens = density[ posradii ]
try:
hwhm = r111pos[ posdens - posdens[0]/2. < 0.][0]
return hwhm
except:
print r111pos
print posdens
raise
def get_localMu_t( self, gMu):
gMuZero = self.Ezero0_111 + gMu
localMu = gMuZero - self.Ezero_111
localMu_t = localMu / self.tunneling_111
return localMu_t
def getDensity( self, gMu, T ):
"""
This function calculates and returns the density along
the 111 direction
Parameters
----------
gMu : global chemical potential
"""
gMuZero = self.Ezero0_111 + gMu
localMu = gMuZero - self.Ezero_111
localMu_t = localMu / self.tunneling_111
density = get_dens( T, self.tunneling_111, localMu, \
self.onsite_111, select=self.select,\
ignoreLowT=self.ignoreLowT, \
verbose=self.verbose)
return self.r111 , density
def getEntropy111( self, gMu, T ):
"""
This function calculates and returns the entropy along
the 111 direction
Parameters
----------
gMu : global chemical potential
"""
gMuZero = self.Ezero0_111 + gMu
localMu = gMuZero - self.Ezero_111
localMu_t = localMu / self.tunneling_111
entropy = get_entr( T, self.tunneling_111, localMu, \
self.onsite_111, select=self.select,\
ignoreLowT=self.ignoreLowT, \
verbose=self.verbose)
return self.r111 , entropy
def getSpi111( self, gMu, T ):
"""
This function calculates and returns the structure factor along
the 111 direction
Parameters
----------
gMu : global chemical potential
"""
gMuZero = self.Ezero0_111 + gMu
localMu = gMuZero - self.Ezero_111
localMu_t = localMu / self.tunneling_111
spi = get_spi( T, self.tunneling_111, localMu, \
self.onsite_111, select=self.select,\
ignoreLowT=self.ignoreLowT, \
verbose=self.verbose)
return self.r111 , spi
def getBulkSpi( self, **kwargs ):
r111, n111 = self.getDensity( self.globalMu, self.T )
t0 = self.tunneling_111.min()
Tspi = kwargs.get( 'Tspi', self.T / t0 )
logger.info( "Tspi in units of t0 = " + str(Tspi) )
Tspi = Tspi * t0
logger.info( "Tspi in units of Er = " + str(Tspi) )
logger.info( " t0 in units of Er = " + str( t0 ) )
gMuZero = self.Ezero0_111 + self.globalMu
localMu = gMuZero - self.Ezero_111
localMu_t = localMu / self.tunneling_111
# Get the bulk Spi and the Spi profile
# ALSO
# Get the overall S/N and the s profiles, both s per lattice site
# and s per particle
spibulk, spi, sthbulk, sth, overall_entropy, entropy, \
lda_number, density = \
qmc_spi.spi_bulk( r111, n111, localMu_t, Tspi, \
self.tunneling_111, self.onsite_111, **kwargs )
do_k111 = kwargs.get('do_k111', False)
if do_k111:
# Get the compressibility
k111 = get_cmpr( self.T, self.tunneling_111, localMu, \
self.onsite_111, select=self.select,\
ignoreLowT=self.ignoreLowT, \
verbose=self.verbose)
k111htse_list = []
for Thtse in [ 1.8, 2.3, 2.8]:
k111htse = get_cmpr( Thtse*t0, self.tunneling_111, localMu, \
self.onsite_111, select='htse',\
ignoreLowT=self.ignoreLowT, \
verbose=self.verbose)
k111htse_list.append( [Thtse, k111htse] )
else:
k111 = None
k111htse_list = []
U111 = self.onsite_111 / self.tunneling_111
mut111 = localMu_t
return spibulk, spi, sthbulk, sth, r111, n111, U111, self.tunneling_111, \
mut111, \
overall_entropy, entropy, lda_number, density, k111, \
k111htse_list
def getSpiFineGrid( self, **kwargs):
direc111 = (np.arctan(np.sqrt(2)), np.pi/4)
unit = vec3(); th = direc111[0]; ph = direc111[1]
unit.set_spherical( 1., th, ph);
numpoints = kwargs.pop('numpoints', 80 )
t111, X111_, Y111_, Z111_, lims_ = \
udipole.linecut_points( direc=direc111, extents=self.extents,\
npoints=numpoints)
# Below we get the signed distance from the origin
r111_ = X111_*unit[0] + Y111_*unit[1] + Z111_*unit[2]
# Obtain band structure and interactions along the 111 direction
bandbot_111_, bandtop_111_, \
Ezero_111_, tunneling_111_, onsite_t_111_ = \
self.pot.bandStructure( X111_, Y111_, Z111_)
# The onsite interactions are scaled up by the scattering length
onsite_t_111_ = self.a_s * onsite_t_111_
onsite_111_ = onsite_t_111_ * tunneling_111_
# Lowst value of E0 is obtained
LowestE0_ = np.amin( bandbot_111_ )
Ezero0_111_ = Ezero_111_.min()
t0 = tunneling_111_.min()
Tspi = kwargs.get( 'Tspi', self.T / t0 )
Tspi = Tspi * t0
localMu_ = self.globalMu + Ezero0_111_ - Ezero_111_
localMu_t_ = localMu_ / tunneling_111_
# Get the density
density_ = get_dens( self.T, tunneling_111_, localMu_, \
onsite_111_, select=self.select,\
ignoreLowT=self.ignoreLowT, \
verbose=self.verbose)
# Get the bulk Spi and the Spi profile
# ALSO
# Get the overall S/N and the s profiles, both s per lattice site
# and s per particle
kwargs['do_kappa']=False
spibulk, spi, sthbulk, sth, overall_entropy, entropy, \
lda_number, density = \
qmc_spi.spi_bulk( r111_, density_, localMu_t_, Tspi, \
tunneling_111_, onsite_111_, **kwargs )
U111 = onsite_111_ / tunneling_111_
#return spibulk, spi, r111, n111, U111, self.tunneling_111, \
# overall_entropy, entropy, lda_number, density
return r111_, spi, density_, None, localMu_t_ * tunneling_111_
def getNumber( self, gMu, T, **kwargs):
"""
This function calculates and returns the total number of atoms.
It integrates along 111 assuming a spherically symmetric sample.
Parameters
----------
gMu : global chemical potential
"""
kwverbose = kwargs.get('verbose', None)
if kwverbose is not None:
NVerbose = kwverbose
else:
NVerbose = self.verbose
gMuZero = self.Ezero0_111 + gMu
localMu = gMuZero - self.Ezero_111
localMu_t = localMu / self.tunneling_111
density = get_dens( T, self.tunneling_111, localMu, \
self.onsite_111, select=self.select,\
ignoreLowT=self.ignoreLowT, \
verbose=self.verbose)
# Under some circumnstances the green compensation can
# cause dips in the density profile. This can happen only
# if the green beam waist is smaller than the IR beam waist
# Experimentally we have seen that we do not handle these very
# well, so we want to avoid them at all cost
# The occurence of this is flagged by a change in the derivative
# of the radial density. This derivative should always be negative.
# If the green beam waist is larger than the IR beam waist, then
# the problem with the non-monotonic density can also be found
# when trying to push the compensation such that muGlobal gets
# close to the evaporation threshold
# This can be pathological because it leads to an accumulation of atoms
# that are not trapped but this lda code integrates over them and counts
# them anyways.
# To avoid any of the two situations desribed above we force the
# density to decrease monotonically over the extent of our calculation.
# If the density slope is positive the we report it as an error
#
# find the point at which the density changes derivative
radius_check = 1e-3
posradii = self.r111 > radius_check
posdens = density[ posradii ]
neg_slope = np.diff( posdens ) > 1e-4
n_neg_slope = np.sum( neg_slope )
if n_neg_slope > 0:
msg = "ERROR: Radial density profile along 111 " + \
"has a positive slope"
if NVerbose:
print msg
print "\n\nradius check start = ", radius_check
print posdens
print np.diff( posdens ) > 1e-4
if not self.ignoreSlopeErrors:
raise ValueError(msg)
elif NVerbose:
print "OK: Radial density profile along 111 decreases " + \
"monotonically."
if False:
print " posdens len = ",len(posdens)
print " n_neg_slope = ",n_neg_slope
# Checks that the density goes to zero within the current extents
if kwverbose is not None and kwverbose is False:
edgecuttof = 10.
else:
edgecuttof = 2e-2
if posdens[-1]/posdens[0] > edgecuttof:
msg = "ERROR: Density does not vanish within current " + \
"extents"
if not self.ignoreExtents:
print msg
print posdens[0]
print posdens[-1]
print posdens
print self.pot.g0
#print "etaF = ", self.EtaEvap
#print "etaFstar = ", self.etaF_star
#print "extents = ", self.extents
raise ValueError(msg)
if NVerbose:
print msg
print posdens[0]
print posdens[-1]
print self.pot.g0
dens = density[~np.isnan(density)]
r = self.r111[~np.isnan(density)]
self.PeakD = dens.max()
return np.power(self.a,-3)*2*np.pi*integrate.simps(dens*(r**2),r)
def getNumberD( self, T):
"""
This function calculates and returns the total number of doublons.
It integrates along 111 assuming a spherically symmetric sample.
"""
doublons = get_doub( T, self.tunneling_111, self.localMu_111,\
self.onsite_111, select=self.select,\
ignoreLowT=self.ignoreLowT,\
verbose=self.verbose)
doub = doublons[~np.isnan(doublons)]
r = self.r111[~np.isnan(doublons)]
return 2.*np.power(self.a,-3)*2*np.pi*integrate.simps(doub*(r**2),r)
def getEntropy( self, T):
"""
This function calculates and returns the total entropy.
It integrates along 111 assuming a spherically symmetric sample.
"""
entropy = get_entr( T, self.tunneling_111, self.localMu_111,\
self.onsite_111, select=self.select,\
ignoreLowT=self.ignoreLowT,\
verbose=self.verbose)
entr = entropy[~np.isnan(entropy)]
r = self.r111[~np.isnan(entropy)]
return np.power(self.a,-3)*2*np.pi*integrate.simps(entr*(r**2),r)
def column_density( self ):
"""
This function calculates and returns the column density of the
cloud
"""
return None
def plotLine( lda0, **kwargs):
# Flag to ignore errors related to low temperatures beyond the reach
# of the htse
ignoreLowT = kwargs.get('ignoreLowT',False)
scale = 0.9
figGS = plt.figure(figsize=(6.0*scale,4.2*scale))
gs3Line = matplotlib.gridspec.GridSpec(2,2,\
width_ratios=[1.6, 1.], height_ratios=[2.0,1.4],\
wspace=0.25,
left=0.13, right=0.90,
bottom=0.15, top=0.78)
tightrect = [0.,0.00, 0.95, 0.84]
Ax1 = [];
Ymin =[]; Ymax=[]
line_direction = kwargs.pop('line_direction', '111')
direcs = { \
'100':(np.pi/2, 0.), \
'010':(np.pi/2, np.pi/2), \
'001':(0., np.pi), \
'111':(np.arctan(np.sqrt(2)), np.pi/4) }
labels = { \
'100':'$(\mathbf{100})$', \
'010':'$(\mathbf{010})$', \
'001':'$(\mathbf{001})$', \
'111':'$(\mathbf{111})$' }
cutkwargs = kwargs.pop( 'cutkwargs', { } )
cutkwargs['direc'] = direcs[ line_direction ]
cutkwargs['ax0label']= labels[ line_direction ]
cutkwargs['extents']= kwargs.pop('extents', 40.)
t, X,Y,Z, lims = udipole.linecut_points( **cutkwargs )
potkwargs = kwargs.pop( 'potkwargs', { } )
potkwargs['direc'] = direcs[ line_direction ]
potkwargs['ax0label']= labels[ line_direction ]
potkwargs['extents']= kwargs.pop('x1lims', (lims[0],lims[1]))[1]
tp, Xp,Yp,Zp, lims = udipole.linecut_points( **potkwargs )
kwargs['suptitleY'] = 0.96
kwargs['foottextY'] = 0.84
x1lims = kwargs.get('x1lims', (lims[0],lims[1]))
ax1 = figGS.add_subplot( gs3Line[0:3,0] )
ax1.set_xlim( *x1lims )
ax1.grid()
ax1.grid(which='minor')
ax1.set_xlabel('$\mu\mathrm{m}$ '+cutkwargs['ax0label'], fontsize=13.)
ax1.set_ylabel( lda0.pot.unitlabel, rotation=0, fontsize=13., labelpad=15 )
ax1.xaxis.set_major_locator( matplotlib.ticker.MultipleLocator(20) )
ax1.xaxis.set_minor_locator( matplotlib.ticker.MultipleLocator(10) )
ax1.yaxis.set_major_locator( matplotlib.ticker.MaxNLocator(7) )
ax1.yaxis.set_minor_locator( matplotlib.ticker.AutoMinorLocator() )
ax2 = figGS.add_subplot( gs3Line[0,1] )
ax3 = None
#ax2.grid()
ax2.set_xlabel('$\mu\mathrm{m}$', fontsize=12, labelpad=0)
#ax2.set_ylabel('$n$', rotation=0, fontsize=14, labelpad=11 )
ax2.xaxis.set_major_locator( matplotlib.ticker.MultipleLocator(20) )
ax2.xaxis.set_minor_locator( matplotlib.ticker.MultipleLocator(10) )
#----------------------------------
# CALCULATE ALL RELEVANT QUANTITIES
#----------------------------------
# All the relevant lines are first calculated here
bandbot_XYZ, bandtop_XYZ, \
Ezero_XYZ, tunneling_XYZ, onsite_t_XYZ = \
lda0.pot.bandStructure( X, Y, Z )
# The onsite interactions are scaled up by the scattering length
onsite_t_XYZ = lda0.a_s * onsite_t_XYZ
onsite_XYZ = onsite_t_XYZ * tunneling_XYZ
Ezero0_XYZ = Ezero_XYZ.min()
bottom = lda0.pot.Bottom( X, Y, Z )
lattmod = lda0.pot.LatticeMod( X, Y, Z )
excbot_XYZ, exctop_XYZ = lda0.pot.firstExcited( X, Y, Z )