-
Notifications
You must be signed in to change notification settings - Fork 0
/
initial.m
4413 lines (3586 loc) · 147 KB
/
initial.m
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
(*
NRG Ljubljana -- initial.m -- Basis construction, initial Hamiltonian
diagonalisation and calculation of irreducible matrix elements
Copyright (C) 2005-2019 Rok Zitko
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact information:
Rok Zitko
F1 - Theoretical physics
"Jozef Stefan" Institute
Jamova 39
SI-1000 Ljubljana
Slovenia
rok.zitko@ijs.si
*)
VERSION = "2.4.4";
(* Logging of Mathematica output: this is useful for bug hunting *)
If[!ValueQ[mmalog],
mmalog = OpenWrite["mmalog"];
AppendTo[$Output, mmalog];
AppendTo[$Messages, mmalog]; (* Important! *)
];
SetOptions[$Output, PageWidth -> 240];
SetOptions[$Messages, PageWidth -> 240];
(* Generalization of Print[] which wraps all strings in StandardForm[]
format directives to remove the quotation marks. *)
Print2[l__] := Print @@ ({l} /. x_String -> StandardForm[x]);
Print2["NRG Ljubljana ", VERSION, " (c) Rok Zitko, rok.zitko@ijs.si, 2005-2019"];
(* Print a warning/error message at specified verbosity level *)
DEBUG = 1;
MyPrint[msg__] := If[DEBUG >= 1, Print2[msg]];
MyPrintForm[form_, msg___] := If[DEBUG >= 1,
Print2 @ ToString @ StringForm[form, Sequence @@ (InputForm /@ {msg})]
];
MyVPrint[verbosity_, msg__] := If[DEBUG >= verbosity, Print2[msg]];
(* Prints an error message and exits *)
If[!ValueQ[ExitOnError], ExitOnError = True];
MyError[msg__] := (Print2[msg]; Print2["Aborting.\n"];
If[ExitOnError, Exit[1] ]);
(* Prints a warning message -- does not exit *)
MyWarning[msg__] := Print2[msg];
SetAttributes[MyAssert, HoldFirst];
MyAssert[expr_] := If[Evaluate[expr] =!= True, MyError["Assertion failed: ", Hold[expr] ]];
Off[InterpolatingFunction::dmvali];
Off[InterpolatingFunction::dmval];
(* Convert to a C-language compatible string, truncate to 10 significant
digits *)
cstr10[x_] := ToString[N[x, 10], CForm];
c10[x_] := CForm[N[x,10]]; (* used in dmft.m *)
(* Check version of sneg *)
majorversion[x_] := ToExpression @ First @ StringSplit[x, "."];
minorversion[x_] := ToExpression @ Last @ StringSplit[x, "."];
VERrequired = "1.188";
VERsneg = $SnegVersion;
If[!( (majorversion[VERsneg] > majorversion[VERrequired]) ||
((majorversion[VERsneg] == majorversion[VERrequired]) &&
(minorversion[VERsneg] >= minorversion[VERrequired])) ),
MyError["Lanski sneg: ", VERsneg,
" Required version of SNEG is ", VERrequired];
];
MyPrint["Mathematica version: ", $Version];
MyPrint["sneg version: ", $SnegVersion];
(* No recursion limit *)
$RecursionLimit = Infinity;
(* Timing code. Used for profiling and benchmarking. *)
ClearAll[timingdata, time0];
timingdata[_] = 0;
timestart[name_] := (time0[name] = AbsoluteTime[]);
timeadd[name_] := Module[{time1, timediff},
time1 = AbsoluteTime[];
timediff = time1-time0[name];
timingdata[name] += timediff;
];
timereport[] := Module[{t},
MyPrint["Timing report"];
t = Map[{#[[1,1,1]], #[[2]]}&, DownValues[timingdata]];
Scan[MyPrint, t];
];
(* Load a module, Get::noopen message is suppressed. *)
silentGet[x__] := Module[{ret},
Off[Get::noopen];
ret = Get[x];
On[Get::noopen];
ret
];
(* Load an external module (another .m) file. *)
loadmodule[filename_String, exitonfailure_:True] := Module[{ret},
MyPrint["Loading module ", filename];
ret = silentGet[filename, Path -> modulespath];
If[ret === $Failed,
MyWarning["Can't load " <> filename <> ". " <>
If[exitonfailure, "Aborting.", "Continuing."]];
If[exitonfailure == True, Exit[1]];
];
ret (* The result is returned! *)
];
(* External hook: if the variable 'var' ends with a ".m" suffix,
the corresponding external module is called. *)
hook[var_] := If[StringTake[var,-2] == ".m", loadmodule[var, True]];
(* List of directories in which we look for modules. *)
modulespath = {".", ".."};
If[ValueQ[PACKAGEPATH], modulespath = Join[modulespath, PACKAGEPATH]];
(* List of directories in which we look for dump files of basis vectors and
Hamiltonian matrices. In addition to the current directory, we also look
in the parent; this is useful for parameter sweeps. *)
dumppath = {".", ".."};
(* Parse parameter file, if not already performed by nrginit *)
loadmodule["initialparse.m"];
If[PARSED =!= True,
MyPrint["Parsing parameters"];
parse["param"];
];
(* External hook with a named external module *)
hookfile[keyword_] := Module[{filename},
filename = paramdefault[keyword, ""];
If[filename =!= "",
loadmodule[filename, True]
];
];
(***************************************************************)
If[!ValueQ[SYMTYPE], SYMTYPE = "QS"];
(* Implemented symmetry types are:
"QS", ==> U(1)_charge x SU(2)_spin
"QST", ==> U(1)_charge x SU(2)_spin x SO(3)_orbital [three orbitals]
"QSTZ", ==> U(1)_charge x SU(2)_spin x U(1)_orbital [three orbitals]
"QSZTZ", ==> U(1)_charge x U(1)_spin x U(1)_orbital [three orbitals]
"QJ", ==> U(1)_charge x SU(2)_total_momentum [three orbitals]
"ISO" and "ISO2", ==> SU(2)_isospin x SU(2)_spin
"QSZ", ==> U(1)_charge x U(1)_spin
"ISOSZ", ==> SU(2)_isospin x U(1)_spin
"ISOSZLR", ==> SU(2)_isospin x U(1)_spin x Z_2
"ISOLR" and "ISO2LR", ==> SU(2)_isospin x SU(2)_spin x Z_2
"QSLR", ==> U(1)_charge x SU(2)_spin x Z_2
"QSC3", ==> U(1)_charge x SU(2)_spin x Z_3 [3 channels]
"QSZLR", ==> U(1)_charge x U(1)_spin x Z_2
"SU2", ==> SU(2)_charge
"DBLSU2", ==> SU(2)_charge1 x SU(2)_charge2
"DBLISOSZ", ==> SU(2)_charge1 x SU(2)_charge2 x U(1)_spin
"U1", ==> U(1)_charge
"SPSU2", ==> SU(2)_spin
"SPU1", ==> U(1)_spin
"SPU1LR", ==> U(1)_spin x Z_2
"SPSU2LR", ==> SU(2)_spin x Z_2
"SPSU2C3", ==> SU(2)_spin x Z_3 [3 channels]
"SPSU2T", ==> SU(2)_spin x SO(3)_orbital [three orbitals]
"SL", ==> spinless fermions [U(1)_charge symmetry]
"SL3", ==> spinless fermions [threefold U(1)_charge]
"ANYJ", ==> U(1) x U(1), arbitrary spin of the conduction-band electrons
"P", ==> Z_2 fermion parity,
"PP", ==> (Z_2)^2 fermion parity,
"NONE", ==> no symmetry
*)
If[SYMTYPE == "runtime",
If[!paramexists["symtype"],
MyError["Cannot determine the symmetry type."];
];
SYMTYPE = param["symtype"];
];
knownsymtypes =
{"QS", "QST", "QSTZ", "QSZTZ", "QJ", "ISO", "ISO2", "QSZ", "ISOLR", "ISO2LR", "QSLR", "QSC3",
"QSZLR", "DBLSU2", "DBLISOSZ",
"SU2", "U1", "SPSU2", "SPU1", "SPU1LR", "SPSU2LR", "SPSU2C3", "SPSU2T",
"SL", "SL3", "ANYJ", "P", "PP", "NONE", "ISOSZ", "ISOSZLR"};
If[!(MemberQ[knownsymtypes, SYMTYPE]),
MyError["Unknown SYMTYPE."];
];
(* isLR[] returns True if the problem has Z_2 parity symmetry. For symmetry
types in this list, we create a parity-adapted set of basis states as
step number 5 in the basis-state-generation part of the code. *)
lrsymtypes = {"QSLR", "QSZLR", "ISOLR", "ISO2LR", "ISOSZLR", "SPU1LR", "SPSU2LR"};
isLR[] := MemberQ[lrsymtypes, SYMTYPE];
qstypes = {"QS", "QSLR"};
qsztypes = {"QSZ", "QSZLR"};
isotypes = {"ISO", "ISO2", "ISOLR", "ISO2LR"};
isosztypes = { "ISOSZ", "ISOSZLR" };
sctypes = {"SPSU2", "SPU1", "SPU1LR", "SPSU2LR", "SPSU2T", "P", "PP", "NONE", "SPSU2C3"};
orbtypes = {"QST", "SPSU2T", "QSTZ", "QSZTZ"}; (* quantum number T *)
isQS[] := MemberQ[qstypes, SYMTYPE];
isQSZ[] := MemberQ[qsztypes, SYMTYPE];
isISO[] := MemberQ[isotypes, SYMTYPE];
isISOSZ[] := MemberQ[isosztypes, SYMTYPE];
isSC[] := MemberQ[sctypes, SYMTYPE];
isORB[] := MemberQ[orbtypes, SYMTYPE];
isSU2[] := (SYMTYPE === "SU2");
isDBLSU2[] := (SYMTYPE === "DBLSU2");
isDBLISOSZ[] := (SYMTYPE === "DBLISOSZ");
isU1[] := (SYMTYPE === "U1");
isSPSU2[] := (SYMTYPE === "SPSU2");
isSPU1[] := (SYMTYPE === "SPU1");
isSPU1LR[] := (SYMTYPE === "SPU1LR");
isSPSU2LR[] := (SYMTYPE === "SPSU2LR");
isSL[] := (SYMTYPE === "SL");
isSL3[] := (SYMTYPE === "SL3");
isANYJ[] := (SYMTYPE === "ANYJ");
isP[] := (SYMTYPE === "P");
isPP[] := (SYMTYPE === "PP");
isNONE[] := (SYMTYPE === "NONE");
isQST[] := (SYMTYPE === "QST");
isQSTZ[] := (SYMTYPE === "QSTZ");
isQSZTZ[] := (SYMTYPE === "QSZTZ");
isQJ[] := (SYMTYPE === "QJ");
isSPSU2T[] := (SYMTYPE === "SPSU2T");
isQSC3[] := (SYMTYPE === "QSC3");
isSPSU2C3[] := (SYMTYPE === "SPSU2C3");
(* TODO: remove the above! *)
is[sym_] := SYMTYPE === sym;
(********)
MODEL = paramdefault["model", "SIAM"];
VARIANT = paramdefault["variant", ""];
OPTIONS = paramdefault["options", ""];
PERTURB = paramdefault["perturb", ""];
OPS = paramdefault["ops", ""];
lambda = N @ paramdefaultnum["Lambda", 1.0];
z = N @ paramdefaultnum["z", 1.0];
BAND = paramdefault["band", "flat"];
DEBUG = paramdefaultnum["mmadebug", 1];
bandrescale = paramdefaultnum["bandrescale", 1]; (* YYY *)
DISCRETIZATION = paramdefault["discretization", "Y"];
If[StringLength[DISCRETIZATION] >= 1,
DISCRETIZATION = StringTake[DISCRETIZATION, {1}] ];
knowndiscretizationtypes = {"C", "Y", "Z"};
If[!(MemberQ[knowndiscretizationtypes, DISCRETIZATION]),
MyError["Unknown DISCRETIZATION."];
];
DY = DISCRETIZATION == "Y"; (* Original logarithmic mesh approach *)
DC = DISCRETIZATION == "C"; (* Campo and Oliveira's approach *)
DZ = DISCRETIZATION == "Z"; (* My little modification of "C" *)
(* Are the discretization coefficients for spin up and spin down different? *)
(* For QSZ and U1, this effectively doubles the number of coefficient sets,
one number of sets for spin-up electrons, the other for spin-down electrons.
For SPU1, the number is also doubled, but the off-diagonal elements are
identical in both sets. *)
POLARIZED = paramdefaultbool["polarized", False];
(* For U1, this effectively quadruples the number of coefficient sets. This
allows to describe the full 2x2 structure in the spin space. *)
POL2x2 = paramdefaultbool["pol2x2", False];
(* Allow channel-mixing terms in the Wilson chain. *)
RUNGS = paramdefaultbool["rungs", False];
(* It is possible to take into account more than a single site of the Wilson
chain in the initial.m part of the code. This is controlled by parameter
"Ninit"; its value can be interpreted as the highest index of the f-orbital
that is still retained in the initial Hamiltonian. *)
Ninit = paramdefaultnum["Ninit", 0];
(* Commonly used model parameters. These four are special,
since they can be defined in either [extra] or [param] blocks,
and they have default values if not defined anywhere. *)
getmodelparam[key_, default_] := Module[{},
If[paramexists[key, "extra"], Return[paramnum[key, "extra"]]];
If[paramexists[key, "param"], Return[paramnum[key, "param"]]];
Return[default];
];
realU = getmodelparam["U", 0.1];
realGamma = getmodelparam["Gamma", 0.1];
realdelta = getmodelparam["delta", 0.];
realt = getmodelparam["t", 0.];
parsevalue[str_String] /; klicaj[str] := ToExpression[StringDrop[str, 1]];
parsevalue[str_String] /; !klicaj[str] := importnum[str];
(* All PARAM=VALUE lines in [extra] block of the input file get transformed
into PARAM->VALUE rules in params. Since rules are applied in the order
of their appearance in the list, this implies that the preexisting rules
take precendence over these automatically appended ones. *)
addextraparams[] := Module[{params2},
If[ValueQ[listdata["extra"]],
params2 = Map[ToExpression[First[#]] -> parsevalue @ Last[#] &,
listdata["extra"]];
params = Join[params, params2];
];
];
(* Define extraPARAM=VALUE for all PARAM=VALUE lines in [extra]
block of the input file (for backward compatibility). *)
If[ValueQ[listdata["extra"]],
exmap = Map[ {ToExpression["extra" <> First[#]],
parsevalue @ Last[#] }&, listdata["extra"] ];
MapThread[Set, Transpose[exmap]];
];
If[!ValueQ[BASISRULE],BASISRULE = ""]; (* Transformation rule for basis states *)
(* This can be used, for example, to project out doubly occupied impurity
state to simulate U=infinity Anderson model, etc. *)
(* Workaround: StringSplit is only available in Mathematica starting in 5.1.
The following routine thus extends the compatibility of "NRG Ljubljana" to
Mathematica 5.0. *)
MyStringSplit[l_]:=Module[{c, p},
c=Characters[l];
p=Position[c," "]//Flatten;
p=Join[{0},p,{Length[c]+1}];
Table[StringTake[l,{p[[i-1]]+1,p[[i]]-1}],{i,2,Length[p]}]
];
MyStringSplit[""] := {};
(* OPS is a space delimited list of operators that we request to compute
during the NRG iteration. *)
(* 7.3.2016: sort alphabetically *)
lops = Sort @ MyStringSplit[OPS];
(* calcopq[op] returns True if we requested calculation of operator 'op'.
This is used in the generation of the input file for NRG iteration. *)
calcopq[op_] := MemberQ[lops, op];
(* Generate a list of all operators with a given prefix. *)
(* Returns a list of {string, suffix, expr}, where 'string' is the matching
string, while 'suffix' is the string without the prefix, while 'expr'
is 'suffix' with eventual leading ( and trailing ) stripped. *)
calcoplist[prefix_] := Module[{len, l, stringstrip},
len = StringLength[prefix];
l = Select[lops, StringLength[#] >= len &];
l = Select[l, StringTake[#, len] == prefix &];
(* stringstrip[] is ugly, but works with Mathematica 5.0 *)
stringstrip[str_] :=
stringstrip @ StringDrop[str, 1] /;
StringLength[str] >= 1 && StringTake[str, 1] == "(";
stringstrip[str_] :=
stringstrip @ StringDrop[str, -1] /;
StringLength[str] >= 1 && StringTake[str, -1] == ")";
stringstrip[str_] := str;
If[l === {},
{},
Map[{#, tempstr=StringDrop[#, len], stringstrip @ tempstr}&, l]
]
];
(* OPTIONS is a space delimited list of additional options that are
defined in the parameters file. *)
loptions = MyStringSplit[OPTIONS];
MyPrint["Options: ", loptions];
(* option[keyword] returns True if option 'keyword' is specified *)
option[keyword_] := MemberQ[locateoption[keyword], True];
(* Careful: locateoption[] is not fool-proof. This should better be done
with regex searches, but this only appeared in Mathematica starting in
version 5.1 *)
locateoption[keyword_] := Map[StringPosition[#, keyword] != {} &, loptions];
(* Options can have values: key=value *)
optionvalue[keyword_] := Module[{loc, pos, pair},
loc = locateoption[keyword];
If[Count[loc, True] != 1,
MyError["Error parsing keyword:", keyword];
];
pos = Position[loc, True] [[1,1]];
pair = loptions [[pos]];
If[StringLength[pair] <= StringLength[keyword],
MyError["Keyword found, no value:", pair];
];
StringDrop[pair, StringLength[keyword]+1] (* A string is returned! *)
];
(* We allow for dynamic adding of keywords. For some models, specific
workarounds are required which can be enabled at run-time. *)
addoption[keyword_] := AppendTo[loptions, keyword];
(*
KNOWN OPTIONS
=============
PARAMPRE - apply parameters before calling matrixrepresntationvc[]
WRITE - write basis and Hamiltonian matrix files
READBASIS - read basis from a file
READHAM - read the Hamiltonian matrices from a file
EPSCLIP - clip nonrepresentably small (in double type) floating points to zero
TEMPLATE - create a template for the output file 'data' rather than an actual output file.
This is used to create the 'data' file on computers without Mathematica.
LRTRICK - rewrite the basis states so that they are even viz. odd wrt parity
COMPLEX - enforce the generation of a complex-numbers version of the data file
NOSHUR - do not use the Shur decomposition to diagonalize matrices
MPVCSLOW - set MPVCFAST=False
*)
(* Spin of conduction-band electrons. *)
BANDSPIN = 1/2; (* Default for all codes except ANYJ. *)
If[SYMTYPE == "ANYJ",
If[!paramexists["spin"],
MyError["Define the spin of the conduction band electrons."];
];
BANDSPIN = ((ToExpression @ param["spin"])-1)/2;
MyPrint["BAND SPIN=", BANDSPIN];
];
(***************************** GENERAL STUFF *******************************)
(*
The following parameters are common to all models:
delta = deviation from p-h symmetry, delta=epsilon+U/2
U = e-e repulsion parameter
gamma = pi rho |V|^2, hybridisation strength, gamma/D = (t'/t)^2 for
single embedded dot (model SIAM). It is not used directly.
gammaPol = sqrt{gamma} \sim V, i.e. proportional to hopping
t = coupling of the side dot
For other parameters, consult the Hamiltonian definitions!
NOTE: all dimensionfull parameters are expressed in units of the
bandwidth D.
*)
snegrealconstants[delta, U, gammaPol, t];
SetAttributes[gammaPolCh, NumericFunction];
SetAttributes[hybV, NumericFunction];
SetAttributes[coefzeta, NumericFunction];
SetAttributes[coefrung, NumericFunction];
SetAttributes[coefxi, NumericFunction];
SetAttributes[coefdelta, NumericFunction];
SetAttributes[coefkappa, NumericFunction];
(* Assumption: Wilson chain coefficients are real. This is not always the case! *)
Conjugate[gammaPolCh[i__]] ^= gammaPolCh[i];
Conjugate[hybV[i__]] ^= hybV[i];
Conjugate[coefzeta[i__]] ^= coefzeta[i];
Conjugate[coefrung[i__]] ^= coefrung[i];
Conjugate[coefxi[i__]] ^= coefxi[i];
Conjugate[coefdelta[i__]] ^= coefdelta[i];
Conjugate[coefkappa[i__]] ^= coefkappa[i];
(* Quantities 'theta0' and 'gammaA' are defined below, when
discretization is set up. *)
params = {
gammaPol -> Sqrt[(1/Pi) theta0 gammaA], (* GP *)
gammaPolCh[ch_] :> Sqrt[(1/Pi) theta0Ch[ch] gammaA],
hybV[i_,j_] :> Sqrt[1/Pi] V[i,j],
coefzeta[ch_, j__] :> N[ bandrescale zeta[ch][j] ], (* channel index = 1,2,3 *)
coefxi[ch_, j__] :> N[ bandrescale xi[ch][j] ], (* N[] -> MachinePrecision! *)
coefrung[ch_, j__] :> N[ bandrescale zetaR[ch][j] ],
coefdelta[ch_, j__] :> N[ bandrescale scdelta[ch][j] ],
coefkappa[ch_, j__] :> N[ bandrescale sckappa[ch][j] ], (* YYY *)
U -> realU,
delta -> realdelta,
t -> realt
};
(* See M. Sindel, PhD dissertation, Appendix A.1 *)
(* \sqrt{ (\Gamma/\pi) \theta } *)
(* \theta_0 = \int_{-1}^{1} \Gamma(\epsilon) d\epsilon *)
(* \theta_0 = \theta \Gamma, i.e. \Gamma defines the overall scale,
\theta is the integral of the frequency dependant part. *)
(* CONVENTION: f[0], f[1] are zero sites of the Wilson chain for the first
and the second channel, d[] is the impurity orbital, a[], b[], e[], g[] are
additional impurity orbitals. *)
snegfermionoperators[{f, BANDSPIN}, a, b, d, e, g];
(* Declare additional parameters using snegrealconstants[]. addexnames[] is
called from maketable[] or manually when debugging! *)
addexnames[] := Module[{exnames},
exnames = Map[StringDrop[#,5]&, Names["extra*"]];
MyPrint["exnames=", exnames];
snegrealconstants @@ Map[Symbol, exnames];
];
(***************************** HAMILTONIAN *******************************)
(* Define default Anderson-like impurity Hamiltonians and provide default
values for nnop[]. *)
adddots[nrdots_] := Module[{},
MyPrint["adddots, nrdots=", nrdots];
H1 = 0; (* Zero-impurity cases and Kondo-like models with spin
operators only. *)
If[nrdots >= 1,
H1 = delta number[d[]] + U/2 pow[number[d[]]-1, 2];
];
If[nrdots >= 2,
Ha = delta number[a[]] + U/2 pow[number[a[]]-1, 2];
nnop[a[]] = -1;
];
If[nrdots >= 3,
Hb = delta number[b[]] + U/2 pow[number[b[]]-1, 2];
nnop[b[]] = -1;
];
If[nrdots >= 4,
He = delta number[e[]] + U/2 pow[number[e[]]-1, 2];
nnop[e[]] = -1;
];
If[nrdots >= 5,
Hg = delta number[g[]] + U/2 pow[number[g[]]-1, 2];
nnop[g[]] = -1;
];
];
(* Average number of electrons per Wilson chain site. Depends
on the degeneracy, i.e. on the electron spin. *)
AVGOCCUP = (2 BANDSPIN + 1)/2;
(* c is the channel index, i is the chain site index *)
fop[c_Integer, 0, x___] := f[c, x];
fop[c_Integer, i_Integer, x___] := f[c, i, x];
fopCR[c_Integer, 0, x___] := f[CR, c, x];
fopCR[c_Integer, i_Integer, x___] := f[CR, c, i, x];
fopAN[c_Integer, 0, x___] := f[AN, c, x];
fopAN[c_Integer, i_Integer, x___] := f[AN, c, i, x];
(* On-site Hamiltonian on i-th site (0,1,2) of the Wilson chain
for channel ch (1,2,3). *)
HBANDonsite[ch_, i_] := Module[{reg, ireg},
If[!POLARIZED && !POL2x2,
reg = coefzeta[ch, i] (number[fop[ch-1, i]] - AVGOCCUP);
];
If[POLARIZED && !POL2x2,
reg = coefzeta[ch, i] (number[fop[ch-1, i], UP] - AVGOCCUP/2) +
coefzeta[ch+CHANNELS, i] (number[fop[ch-1, i], DO] - AVGOCCUP/2);
];
(* Added 10.9.2012 *)
If[POL2x2,
reg = coefzeta[ch, i] (number[fop[ch-1, i], UP] - AVGOCCUP/2) +
coefzeta[ch+CHANNELS, i] (number[fop[ch-1, i], DO] - AVGOCCUP/2) +
coefzeta[ch+2*CHANNELS, i] (fopCR[ch-1, i, UP] ~ nc ~ fopAN[ch-1, i, DO]) + (* fixed 21.10.2019 *)
coefzeta[ch+3*CHANNELS, i] (fopCR[ch-1, i, DO] ~ nc ~ fopAN[ch-1, i, UP]); (* Hermitian! *)
];
(* Superconducting pairing contribution. This is isospinx[fop, n=0]. *)
ireg = coefdelta[ch, i] (nc[fopCR[ch-1, i, UP], fopCR[ch-1, i, DO]] +
nc[fopAN[ch-1, i, DO], fopAN[ch-1, i, UP]]);
reg + ireg
];
(* Anomalous hopping operator *)
SetAttributes[anomaloushop, Listable];
anomaloushop[op1_?fermionQ[j1___], op2_?fermionQ[j2___], sigma_] :=
op1[CR, j1, sigma] ~ nc ~ op2[CR, j2, 1-sigma] +
op2[AN, j2, 1-sigma] ~ nc ~ op1[AN, j1, sigma];
(* NOTE THE MINUS SIGN! *)
anomaloushop[op1_?fermionQ[j1___], op2_?fermionQ[j2___]] /;
(spinof[op1] == spinof[op2] == 1/2) :=
anomaloushop[op1[j1], op2[j2], UP] - anomaloushop[op1[j1], op2[j2], DO];
(* Hop with spin change. Two such terms are required to form a Hermitian
Hamiltonian. *)
hop[op1_?fermionQ[j1___], op2_?fermionQ[j2___], sigma1_, sigma2_] :=
op1[CR, j1, sigma1] ~ nc ~ op2[AN, j2, sigma2] +
op2[CR, j2, sigma2] ~ nc ~ op1[AN, j1, sigma1];
(* Hopping Hamiltonian term for hopping from i-1-th to i-th site. Note that
the order of arguments to anomaloushop[] is important to get the sign right. *)
HBANDhop[ch_, 0] := 0;
HBANDhop[ch_, i_] := Module[{reg, ireg},
If[!POLARIZED && !POL2x2,
reg = coefxi[ch, i-1] hop[fop[ch-1, i-1], fop[ch-1, i]];
];
If[POLARIZED && !POL2x2,
reg = coefxi[ch, i-1] hop[fop[ch-1, i-1], fop[ch-1, i], UP] +
coefxi[ch+CHANNELS, i-1] hop[fop[ch-1, i-1], fop[ch-1, i], DO];
];
(* Added 10.9.2012 *)
If[POL2x2,
reg = coefxi[ch, i-1] hop[fop[ch-1, i-1], fop[ch-1, i], UP] +
coefxi[ch+CHANNELS, i-1] hop[fop[ch-1, i-1], fop[ch-1, i], DO] +
coefxi[ch+2*CHANNELS, i-1] hop[fop[ch-1, i-1], fop[ch-1, i], UP, DO] +
coefxi[ch+3*CHANNELS, i-1] hop[fop[ch-1, i-1], fop[ch-1, i], DO, UP];
];
(* Add support for RUNGS *)
ireg = coefkappa[ch, i-1] anomaloushop[fop[ch-1, i-1], fop[ch-1, i]];
reg + ireg
];
(* NOTE: H0 is the chain Hamiltonian for problems where the band is not
particle-hole symmetric, or for problems where we take into account more
than the size 0 of the Wilson chain (see parameter "Ninit"). *)
HBAND[] := Module[{H0onsite, H0hop, H0bcs},
H0onsite = Sum[HBANDonsite[ch, i], {ch, CHANNELS}, {i, 0, Ninit}];
H0hop = Sum[HBANDhop[ch, i], {ch, CHANNELS}, {i, 0, Ninit}];
H0 = H0onsite + H0hop;
(* If we don't work with SPSU2 symmetry type, we drop all anomalous terms. *)
If[!isSC[],
H0 = H0 /. { coefdelta[___] -> 0, coefkappa[___] -> 0};
];
If[RUNGS && CHANNELS == 2,
H0r = Sum[coefrung[1,i] hop[fop[0, i], fop[1, i]], {i, 0, Ninit}];
Print["H0r=", H0r];
H0 = H0 + H0r;
];
MyPrint["H0=", H0];
];
(* The default band-impurity coupling Hamiltonian. *)
HC[] := Module[{},
(* Note: gammaPolCh/zeta/... are indexed as ch=1, 2, ..., while f[]
operators are indexed as ch=0, 1, ... *)
If[!POLARIZED && !POL2x2,
Hc = Sum[gammaPolCh[ch] hop[f[ch-1], d[]], {ch, CHANNELS}];
];
If[POLARIZED && !POL2x2,
Hc = Sum[gammaPolCh[ch] hop[f[ch-1], d[], UP], {ch, CHANNELS}] +
Sum[gammaPolCh[ch+CHANNELS] hop[f[ch-1], d[], DO], {ch, CHANNELS}];
];
(* Added 10.9.2012 *)
If[POL2x2,
Hc = Sum[gammaPolCh[ch] hop[f[ch-1], d[], UP], {ch, CHANNELS}] +
Sum[gammaPolCh[ch+CHANNELS] hop[f[ch-1], d[], DO], {ch, CHANNELS}] +
Sum[gammaPolCh[ch+2*CHANNELS] hop[f[ch-1], d[], UP, DO], {ch, CHANNELS}] +
Sum[gammaPolCh[ch+3*CHANNELS] hop[f[ch-1], d[], DO, UP], {ch, CHANNELS}];
];
];
(* Called from def1ch[] and def2ch[] to set up the support for spin-polarized
conduction-band calculations. *)
InitPolarized[] := Module[{},
(* Defaults. *)
COEFCHANNELS = CHANNELS;
VDIM = CHANNELS; (* NEW 2019: dimension of hybridisation matrix. Used for BAND=manual_V *)
(* Changes in the case of spin-polarized conduction bands. *)
If[POLARIZED,
If[!MemberQ[{"QSZ", "U1", "SPU1", "P", "PP", "NONE"}, SYMTYPE],
MyError["Spin polarized calculation not supported with chosen SYMTYPE."]
];
COEFCHANNELS = 2 CHANNELS; (* Double the number of coefficient sets for channels. *)
VDIM = 2 * CHANNELS;
];
If[POL2x2,
If[!MemberQ[{"U1"}, SYMTYPE],
MyError["Spin 2x2 structure not supported with chosen SYMTYPE."];
];
COEFCHANNELS = 4 CHANNELS; (* Quadruple the number of coefficient sets for channels. *)
VDIM = 2 * CHANNELS; (* !! *)
];
If[POLARIZE && POL2x2,
MyError["POLARIZED or POL2x2? Choose one!"];
];
MyPrint["COEFCHANNELS:", COEFCHANNELS];
];
(* Default settings for 1-channel models *)
def1ch[nrdots_:1] := Module[{},
CHANNELS = 1;
NRDOTS = nrdots;
MyPrint["def1ch, NRDOTS=", NRDOTS];
InitPolarized[];
HC[];
HBAND[];
(* Default operator numbering for isospin symmetry generation: d[]
has an inverted sign, but the first site in the Wilson's chain does
not! *)
nnop[d[] ] = -1;
nnop[f[0]] = 0;
nnop[f[0, 1]] = -1;
adddots[NRDOTS];
];
(* Default settings for 2-channel models *)
def2ch[nrdots_:1] := Module[{},
CHANNELS = 2;
NRDOTS = nrdots;
MyPrint["def2ch, NRDOTS=", NRDOTS];
InitPolarized[];
HC[];
HBAND[];
nnop[f[0]] = 0;
nnop[f[1]] = 0;
(* For SYMTYPE=ISO, we must have nnop[f[0]] = nnop[f[1]] = 0. *)
(* For SYMTYPE=ISO2, we must have nnop[f[0]] = 0, nnop[f[1]] = 1. *)
If[SYMTYPE == "ISO2" || SYMTYPE == "ISO2LR",
nnop[f[0]] = 0;
nnop[f[1]] = 1;
];
(* WARNING: in TQD, d is the impurity in the middle, so the
default rule for d[] has to be overriden!! *)
nnop[d[] ] = -2;
adddots[nrdots];
];
(* Default settings for 3-channel models *)
def3ch[nrdots_:1] := Module[{},
CHANNELS = 3;
NRDOTS = nrdots;
MyPrint["def3ch, NRDOTS=", NRDOTS];
InitPolarized[];
HC[];
HBAND[];
(* The current implementation of SYMTYPE=ISO is such that nnop[f[i]]
are all equal! *)
nnop[f[0]] = 0;
nnop[f[1]] = 0;
nnop[f[2]] = 0;
nnop[d[] ] = -1;
adddots[nrdots];
];
(* Default settings for 4-channel models *)
def4ch[nrdots_:1] := Module[{},
CHANNELS = 4;
NRDOTS = nrdots;
MyPrint["def4ch, NRDOTS=", NRDOTS];
InitPolarized[];
HC[];
HBAND[];
(* The current implementation of SYMTYPE=ISO is such that nnop[f[i]]
are all equal! *)
nnop[f[0]] = 0;
nnop[f[1]] = 0;
nnop[f[2]] = 0;
nnop[f[3]] = 0;
nnop[d[] ] = -1;
adddots[nrdots];
];
CHANNELS = -1; (* Bug trap *)
NRDOTS = -1; (* Bug trap *)
MAKESPINKET = Null; (* Operator(s?) that is converted to spin kets *)
MAKEORBKET = Null;
MAKEPHONON = Null; (* 1 = one phonon mode, etc. *)
(** Reflection symmetry (parity) **)
(* List 'lrchain' holds the operators that describe the ordering of sites in
the real-space configuration of the impurities, for example: {f[0], d[],
f[1]} for two-channel single-impurity Kondo problem. This list is used to
generate parity-adapted basis states. List 'lrextrarule' contains additional
transformation rules that need to be applied to the basis when constructing
the mirror-symmetric states. For example: in the case of antisymmetric
coupling of a phonon mode to a hopping term, all phonon kets need to be
multiplied by -1. *)
lrchain = {};
lrextrarule = {};
(* Some useful functions for Hamiltonian construction and error checking. *)
checkQSZ[] := If[Nor[isQSZ[], isP[], isPP[], isNONE[], isDBLSU2[], isDBLISOSZ[], isSU2[], isU1[],
isSPU1[], isSPU1LR, isISOSZ[]],
MyError["SYMTYPE==QSZ (and similar) only"]
];
(**************************** MODEL DEPENDENT ******************************)
(* Trivial examples: no impurity and single impurity Anderson model *)
(* No impurity: clean conduction band. WARNING: thermodynamic properties
of the band still depend on the "hybridization function"! *)
If[ MODEL == "CLEAN",
def1ch[0];
H = H0;
];
(* Single Impurity Anderson Model and its variants *)
If[ MODEL == "SIAM" && (VARIANT == "" || VARIANT == "MAGFIELD"),
def1ch[1];
(* SIAM in magnetic field. Only for SYMTYPE=QSZ. *)
If[VARIANT == "MAGFIELD",
checkQSZ[];
H1 = H1 + B spinz[d[]]; (* Zeeman term *)
];
H = H0 + H1 + Hc;
];
(* Important: all left sides of the table params should be defined as sneg
parameters. Currently they are all real constants! Call addparamnames[]
after adding parameters to params list. *)
(* TODO: only if symbols? *)
addparamnames[] := Module[{paramnames},
paramnames = params[[All, 1]];
paramnames = Select[paramnames, AtomQ]; (* Drop parametrized rules *)
MyVPrint[3, "Declaring as constants: ", paramnames];
snegrealconstants @@ paramnames;
];
(* Load additional model definitions *)
loadmodule["models.m"];
loadmodule["custommodels.m", False];
(* If a model name ends in .m, we load a package file of this name!
This is an alternative to adding new model definitions to custommodels.m *)
SCRIPTMODEL = False;
If[StringLength[MODEL] >= 2 && StringTake[MODEL, -2] == ".m",
loadmodule[MODEL];
SCRIPTMODEL = True; (* Use to generate suitable filename *)
];
addextraparams[];
addparamnames[];
MyPrint["params=", params];
If[NRDOTS == -1, MyError["NRDOTS = -1"]]; (* Bug trap *)
If[CHANNELS == -1, MyError["CHANNELS = -1"]]; (* Bug trap *)
MyPrint["NRDOTS:", NRDOTS];
MyPrint["CHANNELS:", CHANNELS];
basopsch = Table[f[n], {n, 0, CHANNELS-1}];
Do[basopsch = Join[basopsch, Table[f[n, i], {n, 0, CHANNELS-1}]], {i, 1, Ninit}];
basopsdot = Take[{d[], a[], b[], e[], g[]}, NRDOTS];
basisops = basops = Sort[Join[basopsch, basopsdot]];
MyPrint["basis:", basisops];
MyPrint["lrchain:", lrchain];
MyPrint["lrextrarule:", lrextrarule];
(* Check for consistency between the number of operators and the numbers of
dots and channels *)
NROPS = Length[basisops];
If[NROPS != NRDOTS + CHANNELS (1+Ninit),
MyError["Number of operators does not match what we were expecting."];
];
MyPrint["NROPS:", NROPS];
If[NRDOTS >= 1,
(** We define some useful operators, such as total spin and total charge. **)
opstot = Plus @@ Map[spinxyz, basopsdot];
opq = Plus @@ Map[(number[#]-1)&, basopsdot];
ntot = Plus @@ Map[number, basopsdot];
(* Square of total occupancy *)
ntot2 = pow[ntot, 2];
(* Total S^2 operator. *)
ops2 = inner[opstot, opstot] //Expand;
(* Total S_Z, S_+ and S_- operators. I define them here mostly for
convenience and for testing purposes. *)
opsz = opstot[[3]];
opsplus = opstot[[1]] + I opstot[[2]];
opsminus = opstot[[1]] - I opstot[[2]],
(* else *)
opstot = opq = ntot = ntot2 = ops2 = opsz = opsplus = opsminus = 0;
];
MyVPrint[3, "opstot:", opstot];
MyVPrint[3, "opq:", opq];
MyVPrint[3, "ntot:", ntot];
(* Even combination of (all) creation operators *)
If[NRDOTS >= 1,
creven = (Plus @@ Map[# /. op_[] -> op[CR, sigma] &, basopsdot]) / Sqrt[NRDOTS];
aneven = conj[creven];
neven = Sum[ nc[creven, aneven], {sigma, 0, 1}] // Expand;
sxyzeven = spinxyzgen[(creven/.sigma->#)&];
s2even = inner[sxyzeven, sxyzeven] // Expand;
MyVPrint[3, "neven:", neven]; (* Report level 3 = nonessntial stuff *)
MyVPrint[3, "s2even:", s2even];
];
(* Odd combination of creation operators for TWO DOTS. This might be
useful even for more than two dots, as one of the orthogonal
combinations of states. *)
If[NRDOTS >= 2,
crodd = 1/Sqrt[2] ( d[CR, sigma] - a[CR, sigma] );
anodd = conj[crodd];
nodd = Sum[ nc[crodd, anodd], {sigma, 0, 1}] // Expand;
sxyzodd = spinxyzgen[(crodd/.sigma->#)&];
s2odd = inner[sxyzodd, sxyzodd] // Expand;
MyVPrint[3, "nodd:", nodd];
MyVPrint[3, "s2odd:", s2odd];
seso = inner[sxyzeven, sxyzodd] // Expand;
MyVPrint[3, "seso:", seso];
];
(* Expand will factor common operators. We also collect common factors in
advance. *)
H = Expand[H];
MyPrint["Hamiltonian generated. ", H];
(* Is Hamiltonian Hermitian? *)
If[paramdefaultbool["checkHc", True],
Hc = conj[H];
Hdiff = Simplify[Expand[H-Hc]];
MyPrint["H-conj[H]=", Hdiff];
hookfile["Hcsimpl"];
If[POL2x2, (* hack *)
Hdiff = Hdiff /. coefzeta[4,i_]->coefzeta[3,i];
];
Hdiff = Hdiff /. {0. -> 0, Complex[0.,0.] -> 0};
If[Hdiff =!= 0,
MyError["Non-Hermitian Hamiltonian!"]
];
];
If[DEBUG >= 4,
(* Rewrite the Hamiltonian in terms of high-level functions. This
makes the debugging of Hamiltonian definitions significantly easier.
Note, however, that this operation may take a lot of time! *)
MyPrint["Hamiltonian -> ", SnegSimplify[H]];
];
(*************************)
(* In NRG, it is customary to define a dimensionless Hamiltonian H_N whose
smallest coefficients are of order 1. To be definite, we rescale the
Hamiltonian so that the hopping matrix elements along the Wilson chain
become precisely 1 in the asymptotic N->inf limit. This is achieved by
dividing the truncated Hamiltonian with a suitable prefactor which can be
further decomposed into a N-dependant part LAMBDA^(-(N-1)/2), and a constant
prefactor. *)