Could someone see my modification of spinless.h file to simulate spinless bosons in 1D Bose-Hubbard model?
#ifndef __ITENSOR_SPINLESS_H
#define __ITENSOR_SPINLESS_H
#include "itensor/mps/siteset.h"
namespace itensor {
class SpinlessBosons;
using SpinlessBos = BasicSiteSet<SpinlessBosons>;
class SpinlessBosons
{
IQIndex s;
public:
SpinlessBosons() { }
SpinlessBosons(IQIndex I) : s(I) { }
SpinlessBosons(int n, Args const& args = Args::global())
{
s = IQIndex{
nameint("SpinlessBos",n),
Index(nameint("Emp",n),1,Site),QN("Nb=",0),
Index(nameint("N1",n),1,Site), QN("Nb=",1),
Index(nameint("N2",n),1,Site), QN("Nb=",2)
};
}
IQIndex
index() const { return s; }
IQIndexVal
state(std::string const& state)
{
if(state == "Emp" || state == "0")
{
return s(1);
}
else
if(state == "N1" || state == "1")
{
return s(2);
}
else
if(state == "N2" || state == "2")
{
return s(3);
}
else
{
Error("State " + state + " not recognized");
}
return IQIndexVal{};
}
IQTensor
op(std::string const& opname,
Args const& args) const
{
auto sP = prime(s);
auto Emp = s(1);
auto EmpP = sP(1);
auto N1 = s(2);
auto N1P = sP(2);
auto N2 = s(3);
auto N2P = sP(3);
auto Op = IQTensor(dag(s),sP);
if(opname == "N" || opname == "n")
{
Op.set(N1,N1P,1);
Op.set(N2,N2P,1);
}
else
if(opname =="A")
{
Op.set(N1, EmpP,1);
Op.set(N2,N1P,1);
}
else
if(opname == "Adag")
{
Op.set(Emp, N1P,1);
Op.set(N1,N2P,1);
}
else
{
Error("Operator \"" + opname + "\" name not recognized");
}
return Op;
}
};
} //namespace itensor
#endif
the same code with comments (i.e. the code in spinless.h is commented out ) for comparison with the file spinless.h
#ifndef __ITENSOR_SPINLESS_H
#define __ITENSOR_SPINLESS_H
#include "itensor/mps/siteset.h"
namespace itensor {
//class SpinlessSite;
class SpinlessBosons;
//using Spinless = BasicSiteSet<SpinlessSite>;
using SpinlessBos = BasicSiteSet<SpinlessBosons>;
//class SpinlessSite
class SpinlessBosons
{
IQIndex s;
public:
// SpinlessSite() { }
SpinlessBosons() { }
// SpinlessSite(IQIndex I) : s(I) { }
SpinlessBosons(IQIndex I) : s(I) { }
// SpinlessSite(int n, Args const& args = Args::global())
SpinlessBosons(int n, Args const& args = Args::global())
{
s = IQIndex{
nameint("SpinlessBos",n),
Index(nameint("Emp",n),1,Site),QN("Nb=",0),
Index(nameint("N1",n),1,Site), QN("Nb=",1),
Index(nameint("N2",n),1,Site), QN("Nb=",2)
};
/*
auto conserve_Nf = args.getBool("ConserveNf",true);
auto oddevenupdown = args.getBool("OddEvenUpDown",false);
if(!oddevenupdown) //usual case
{
auto q_occ = QN("Nf=",1);
if(not conserve_Nf) q_occ = QN("Pf=",1);
s = IQIndex{nameint("Spinless ",n),
Index(nameint("Emp ",n),1,Site),QN(),
Index(nameint("Occ ",n),1,Site),q_occ};
}
else
{
QN q_occ;
if(n%2==1) q_occ = QN("Sz",+1,"Nf=",1);
else q_occ = QN("Sz",-1,"Nf=",1);
s = IQIndex{nameint("Spinless ",n),
Index(nameint("Emp ",n),1,Site),QN(),
Index(nameint("Occ ",n),1,Site),q_occ};
}*/
}
IQIndex
index() const { return s; }
IQIndexVal
state(std::string const& state)
{
if(state == "Emp" || state == "0")
{
return s(1);
}
else
if(state == "N1" || state == "1")
{
return s(2);
}
else
if(state == "N2" || state == "2")
{
return s(3);
}
else
{
Error("State " + state + " not recognized");
}
/*
if(state == "Emp" || state == "0")
{
return s(1);
}
else
if(state == "Occ" || state == "1")
{
return s(2);
}
else
{
Error("State " + state + " not recognized");
}*/
return IQIndexVal{};
}
IQTensor
op(std::string const& opname,
Args const& args) const
{
auto sP = prime(s);
auto Emp = s(1);
auto EmpP = sP(1);
auto N1 = s(2);
auto N1P = sP(2);
auto N2 = s(3);
auto N2P = sP(3);
//auto Occ = s(2);
//auto OccP = sP(2);
auto Op = IQTensor(dag(s),sP);
/*
if(opname == "N" || opname == "n")
{
Op.set(Occ,OccP,1);
}
else
if(opname == "C")
{
Op.set(Occ,EmpP,1);
}
else
if(opname == "Cdag")
{
Op.set(Emp,OccP,1);
}
else
*/
if(opname == "N" || opname == "n")
{
Op.set(N1,N1P,1);
Op.set(N2,N2P,1);
}
else
if(opname =="A")
{
Op.set(N1, EmpP,1);
Op.set(N2,N1P,1);
}
else
if(opname == "Adag")
{
Op.set(Emp, N1P,1);
Op.set(N1,N2P,1);
}
/*
if(opname == "A")
{
Op.set(Occ,EmpP,1);
}
else
if(opname == "Adag")
{
Op.set(Emp,OccP,1);
}
else
if(opname == "F" || opname == "FermiPhase")
{
Op.set(Emp,EmpP,1);
Op.set(Occ,OccP,-1);
}
else
if(opname == "projEmp")
{
Op.set(Emp,EmpP,1);
}
else
if(opname == "projOcc")
{
Op.set(Occ,OccP,1);
}
*/
else
{
Error("Operator \"" + opname + "\" name not recognized");
}
return Op;
}
};
} //namespace itensor
#endif