-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathdmrg.cc
More file actions
74 lines (65 loc) · 1.92 KB
/
dmrg.cc
File metadata and controls
74 lines (65 loc) · 1.92 KB
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
#include "itensor/all.h"
#include "itensor/util/print_macro.h"
using namespace itensor;
int
main()
{
int N = 100;
//
// Initialize the site degrees of freedom
// Setting "ConserveQNs=",true makes the indices
// carry Sz quantum numbers and will lead to
// block-sparse MPO and MPS tensors
//
//auto sites = SpinHalf(N); //make a chain of N spin 1/2's
auto sites = SpinOne(N); //make a chain of N spin 1's
//
// Use the AutoMPO feature to create the
// next-neighbor Heisenberg model
//
auto ampo = AutoMPO(sites);
for(auto j : range1(N-1))
{
ampo += 0.5,"S+",j,"S-",j+1;
ampo += 0.5,"S-",j,"S+",j+1;
ampo += "Sz",j,"Sz",j+1;
}
auto H = toMPO(ampo);
// Set the initial wavefunction matrix product state
// to be a Neel state.
//
auto state = InitState(sites);
for(auto i : range1(N))
{
if(i%2 == 1) state.set(i,"Up");
else state.set(i,"Dn");
}
auto psi0 = MPS(state);
//
// inner calculates matrix elements of MPO's with respect to MPS's
// inner(psi,H,psi) = <psi|H|psi>
//
printfln("Initial energy = %.5f", inner(psi0,H,psi0) );
//
// Set the parameters controlling the accuracy of the DMRG
// calculation for each DMRG sweep.
// Here less than 5 cutoff values are provided, for example,
// so all remaining sweeps will use the last one given (= 1E-10).
//
auto sweeps = Sweeps(5);
sweeps.maxdim() = 10,20,100,100,200;
sweeps.cutoff() = 1E-10;
sweeps.niter() = 2;
sweeps.noise() = 1E-7,1E-8,0.0;
println(sweeps);
//
// Begin the DMRG calculation
//
auto [energy,psi] = dmrg(H,psi0,sweeps,"Quiet");
//
// Print the final energy reported by DMRG
//
printfln("\nGround State Energy = %.10f",energy);
printfln("\nUsing inner = %.10f", inner(psi,H,psi) );
return 0;
}