示例#1
0
文件: precond.c 项目: momtx/meataxe
int main(int argc, const char **argv)

{
    int mj;

    if (Init(argc,argv) != 0)
    {
	MTX_ERROR("Initialization failed");
	return -1;
    }

    /* Main loop: for all constituents of M
       ------------------------------------ */
    for (mj = 0; mj < InfoM.NCf; mj++)
    {
	MatRep_t *rep_m;	    /* Generators for const. of M */
	int nj;

	if (InfoM.Cf[mj].peakword < 0)
	{
	    MESSAGE(0,("WARNING: No peak word word available for %s%s\n",
		InfoM.BaseName,Lat_CfName(&InfoM,mj)));
	}
	MESSAGE(0,("%s%s ",InfoM.BaseName,Lat_CfName(&InfoM,mj)));

	/* Read the generators for the <mj>-th contituent of M, and find
	   the corresponding (=contragredient) constituent in N.
	   ------------------------------------------------------------- */
	rep_m = Lat_ReadCfGens(&InfoM,mj,InfoM.Cf[mj].peakword >= 0 ? LAT_RG_STD : 0);
	nj = FindConstituentInN(mj,rep_m);

	/* Calculate the P and Q matrix for this constituent
	   ------------------------------------------------- */
	if (nj >= 0)
	{
	    MESSAGE(0,(" <--> %s%s\n",InfoN.BaseName,
		Lat_CfName(&InfoN,nj)));
	    TKInfo.CfIndex[0][TKInfo.NCf] = mj;
	    TKInfo.CfIndex[1][TKInfo.NCf] = nj;
	    MakePQ(TKInfo.NCf,mj,nj);
	    TKInfo.NCf++;
	}
	else
	    MESSAGE(0,(" not found in %s\n",InfoN.BaseName));

	/* Clean up
	   -------- */
	MrFree(rep_m);
    }

    CalcDim();				/* Calculate dimension */
    TK_WriteInfo(&TKInfo,TkiName);	/* Write .tki file */
    if (App != NULL) AppFree(App);
    return 0;
}
示例#2
0
/**
 * Builds all the up and down base kets in the momentum base
 * Sort them so we have a block diagonal matrix according to total momentum
 */
void MomHamiltonian::BuildBase()
{
    baseUp.reserve(CalcDim(L,Nu));
    baseDown.reserve(CalcDim(L,Nd));

    for(myint i=0; i<Hb; i++)
    {
        if(CountBits(i) == Nd)
            baseDown.push_back(i);

        if(CountBits(i) == Nu)
            baseUp.push_back(i);
    }

    std::vector< std::tuple<int,int,int> > totalmom;
    totalmom.reserve(dim);

    // count momentum of earch state
    for(unsigned int a=0; a<baseUp.size(); a++)
        for(unsigned int b=0; b<baseDown.size(); b++)
        {
            auto calcK = [] (myint cur)
            {
                int tot = 0;

                while(cur)
                {
                    // select rightmost up state in the ket
                    myint ksp = cur & (~cur + 1);
                    // set it to zero
                    cur ^= ksp;

                    tot += BareHamiltonian::CountBits(ksp-1);
                }

                return tot;
            };

            int K = calcK(baseUp[a]) + calcK(baseDown[b]);

            K = K % L;

            totalmom.push_back(std::make_tuple(a,b,K));
        }

    std::sort(totalmom.begin(), totalmom.end(),
              [](const std::tuple<int,int,int> & a, const std::tuple<int,int,int> & b) -> bool
    {
        return std::get<2>(a) < std::get<2>(b);
    });

    // a block for each momenta
    mombase.resize(L);

    std::for_each(totalmom.begin(), totalmom.end(), [this](std::tuple<int,int,int> elem)
    {
        auto tmp = std::make_pair(std::get<0>(elem), std::get<1>(elem));
        mombase[std::get<2>(elem)].push_back(tmp);
    } );

//    for(unsigned int i=0;i<mombase.size();i++)
//    {
//        std::cout << "K = " << i << " (" << mombase[i].size() << ")" << std::endl;
//        for(unsigned int j=0;j<mombase[i].size();j++)
//            std::cout << j << "\t" << mombase[i][j].first << "\t" << mombase[i][j].second << "\t" << print_bin(baseUp[mombase[i][j].first]) << "\t" << print_bin(baseDown[mombase[i][j].second]) << std::endl;
//    }
}