コード例 #1
0
Eigen::VectorXd ehamming(int len)
{
    VectorXd ham(len);
    for (int i=0;i<len;i++)
    	ham(i) = 0.54 - 0.46 * cos(2.0 * PI * i / (len - 1));
    return ham;
}
コード例 #2
0
ファイル: mnt_pair.cpp プロジェクト: J0s3f/FiSH-irssi
void PFC::restore(char * bytes,G2& w)
{
	int i,j,len,m;
	int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
	
	ZZn a,b,c;
	Big X=*x;
	if (w.ptable!=NULL) return;

	m=2*(bits(X)-2+ham(X));
	len=m*3*bytes_per_big;

	w.ptable=new ZZn3[m];
	for (i=j=0;i<m;i++)
	{
		a=from_binary(bytes_per_big,&bytes[j]);
		j+=bytes_per_big;
		b=from_binary(bytes_per_big,&bytes[j]);
		j+=bytes_per_big;
		c=from_binary(bytes_per_big,&bytes[j]);
		j+=bytes_per_big;
		w.ptable[i].set(a,b,c);
	}
	for (i=0;i<len;i++) bytes[i]=0;
	
	delete [] bytes;
}
コード例 #3
0
ファイル: mnt_pair.cpp プロジェクト: J0s3f/FiSH-irssi
int PFC::precomp_for_pairing(G2& w)
{
	int i,j,nb,type,len;
	ECn3 A,Q,B;
	ZZn3 lam,x1,y1;
	Big X=*x;
	
	A=w.g;
	A.norm();
	B=A;
	nb=bits(X);
	j=0;
	len=2*(nb-2+ham(X));
	w.ptable=new ZZn3[len];
	get_mip()->coord=MR_AFFINE;  // switch to affine
    for (i=nb-2;i>=0;i--)
    {
		Q=A;
// Evaluate line from A to A+B
		A.add(A,lam,NULL,NULL);
		Q.get(x1,y1);
		w.ptable[j++]=-lam; w.ptable[j++]=y1-lam*x1; 

		if (bit(X,i)==1)
		{
			Q=A;
			type=A.add(B,lam,NULL,NULL);
			Q.get(x1,y1);
			w.ptable[j++]=-lam; w.ptable[j++]=y1-lam*x1; 
		}
    }
	get_mip()->coord=MR_PROJECTIVE; 
	return len;
}
コード例 #4
0
ファイル: bn_pair.cpp プロジェクト: BingyZhang/CommutEnc
int PFC::spill(G2& w,char *& bytes)
{
	int i,j,len,m;
	int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
	
	Big a,b,n;
	Big X=*x;
	if (w.ptable==NULL) return 0;

	if (X<0) n=-(6*X+2);
    else n=6*X+2;

	m=2*(bits(n)+ham(n));
	len=m*2*bytes_per_big;

	bytes=new char[len];
	for (i=j=0;i<m;i++)
	{
		w.ptable[i].get(a,b);
		to_binary(a,bytes_per_big,&bytes[j],TRUE);
		j+=bytes_per_big;
		to_binary(b,bytes_per_big,&bytes[j],TRUE);
		j+=bytes_per_big;

	}

	delete [] w.ptable; 
	w.ptable=NULL;
	return len;
}
コード例 #5
0
ファイル: bn_pair.cpp プロジェクト: BingyZhang/CommutEnc
void PFC::restore(char * bytes,G2& w)
{
	int i,j,len,m;
	int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
	
	Big a,b,n;
	Big X=*x;
	if (w.ptable!=NULL) return;

	if (X<0) n=-(6*X+2);
    else n=6*X+2;

	m=2*(bits(n)+ham(n));  // number of entries in ptable
	len=m*2*bytes_per_big;

	w.ptable=new ZZn2[m];
	for (i=j=0;i<m;i++)
	{
		a=from_binary(bytes_per_big,&bytes[j]);
		j+=bytes_per_big;
		b=from_binary(bytes_per_big,&bytes[j]);
		j+=bytes_per_big;
		w.ptable[i].set(a,b);
	}
	for (i=0;i<len;i++) bytes[i]=0;
	
	delete [] bytes;
}
コード例 #6
0
ファイル: mnt_pair.cpp プロジェクト: J0s3f/FiSH-irssi
int PFC::spill(G2& w,char *& bytes)
{
	int i,j,len,m;
	int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
	
	ZZn a,b,c;
	Big X=*x;
	if (w.ptable==NULL) return 0;

	m=2*(bits(X)-2+ham(X));
	len=m*3*bytes_per_big;

	bytes=new char[len];
	for (i=j=0;i<m;i++)
	{
		w.ptable[i].get(a,b,c);
		to_binary((Big)a,bytes_per_big,&bytes[j],TRUE);
		j+=bytes_per_big;
		to_binary((Big)b,bytes_per_big,&bytes[j],TRUE);
		j+=bytes_per_big;
		to_binary((Big)c,bytes_per_big,&bytes[j],TRUE);
		j+=bytes_per_big;
	}

	delete [] w.ptable; 
	w.ptable=NULL;
	return len;
}
コード例 #7
0
ファイル: kss_pair.cpp プロジェクト: BingyZhang/CommutEnc
int PFC::precomp_for_pairing(G2& w)
{
	int i,j,nb,len;
	ECn3 A,m2A,dA,Q,B;
	ZZn3 lam,x1,y1;
	Big n;
	Big X=*x;
	
	A=w.g;
	B=A; 
	n=(X/7);
	nb=bits(n);
	j=0;
	len=2*(nb+ham(n)+1);
	w.ptable=new ZZn3[len];

	for (i=nb-2;i>=0;i--)
    {
		Q=A;
// Evaluate line from A to A+B
		A.add(A,lam);
		Q.get(x1,y1); 
		w.ptable[j++]=lam; w.ptable[j++]=y1-lam*x1;

		if (bit(n,i)==1)
		{
			Q=A;
			A.add(B,lam);
			Q.get(x1,y1);
			w.ptable[j++]=lam; w.ptable[j++]=y1-lam*x1;
		}
    }
	dA=A;
	Q=A;
	A.add(A,lam);
	Q.get(x1,y1);
	w.ptable[j++]=lam; w.ptable[j++]=y1-lam*x1;

	m2A=A;

	Q=A;
	A.add(dA,lam);
	Q.get(x1,y1);
	w.ptable[j++]=lam; w.ptable[j++]=y1-lam*x1;

	A=psi(A,*frob,6);

	Q=A;
	A.add(m2A,lam);
	Q.get(x1,y1);
	w.ptable[j++]=lam; w.ptable[j++]=y1-lam*x1;

	return len;
}
コード例 #8
0
ファイル: bn_pair.cpp プロジェクト: BingyZhang/CommutEnc
int PFC::precomp_for_pairing(G2& w)
{
	int i,j,nb,len;
	ECn2 A,Q,B,KA;
	ZZn2 lam,x1,y1;
	Big n;
	Big X=*x;
	
	A=w.g;
	A.norm();
	B=A; KA=A;
	if (X<0) n=-(6*X+2);
    else n=6*X+2;
	nb=bits(n);
	j=0;
	len=2*(nb+ham(n));    // **
	w.ptable=new ZZn2[len];
	get_mip()->coord=MR_AFFINE;  // switch to affine
    for (i=nb-2;i>=0;i--)
    {
		Q=A;
// Evaluate line from A to A+A
		A.add(A,lam);
		Q.get(x1,y1); 
		w.ptable[j++]=-lam; w.ptable[j++]=lam*x1-y1;
		if (bit(n,i)==1)
		{
			Q=A;
			A.add(B,lam);
			Q.get(x1,y1);
			w.ptable[j++]=-lam; w.ptable[j++]=lam*x1-y1;
		}
    }
	
	q_power_frobenius(KA,*frob);
	if (X<0) A=-A;
	Q=A;
	A.add(KA,lam);
	KA.get(x1,y1);
	w.ptable[j++]=-lam; w.ptable[j++]=lam*x1-y1; 

	q_power_frobenius(KA,*frob); KA=-KA;

	Q=A;
	A.add(KA,lam);
	KA.get(x1,y1);
	w.ptable[j++]=-lam; w.ptable[j++]=lam*x1-y1;

	get_mip()->coord=MR_PROJECTIVE;
	return len;
}
コード例 #9
0
ファイル: haystack.cpp プロジェクト: Hasib100/mongo
        bool run(const string& dbname, BSONObj& cmdObj, int,
                 string& errmsg, BSONObjBuilder& result, bool fromRepl) {
            string ns = dbname + "." + cmdObj.firstElement().valuestr();

            NamespaceDetails *nsd = nsdetails(ns);
            if (NULL == nsd) {
                errmsg = "can't find ns";
                return false;
            }

            vector<int> idxs;
            nsd->findIndexByType(GEOSEARCHNAME, idxs);
            if (idxs.size() == 0) {
                errmsg = "no geoSearch index";
                return false;
            }
            if (idxs.size() > 1) {
                errmsg = "more than 1 geosearch index";
                return false;
            }

            BSONElement nearElt = cmdObj["near"];
            BSONElement maxDistance = cmdObj["maxDistance"];
            BSONElement search = cmdObj["search"];

            uassert(13318, "near needs to be an array", nearElt.isABSONObj());
            uassert(13319, "maxDistance needs a number", maxDistance.isNumber());
            uassert(13320, "search needs to be an object", search.type() == Object);

            unsigned limit = 50;
            if (cmdObj["limit"].isNumber())
                limit = static_cast<unsigned>(cmdObj["limit"].numberInt());

            int idxNum = idxs[0];
            IndexDetails& id = nsd->idx(idxNum);
            if (CatalogHack::testIndexMigration()) {
                auto_ptr<IndexDescriptor> desc(CatalogHack::getDescriptor(nsd, idxNum));
                auto_ptr<HaystackAccessMethod> ham(new HaystackAccessMethod(desc.get()));
                ham->searchCommand(nearElt.Obj(), maxDistance.numberDouble(), search.Obj(),
                                   &result, limit);
            } else {
                GeoHaystackSearchIndex *si =
                    static_cast<GeoHaystackSearchIndex*>(id.getSpec().getType());
                verify(&id == si->getDetails());
                si->searchCommand(nsd, nearElt.Obj(), maxDistance.numberDouble(), search.Obj(),
                                  result, limit);
            }
            return 1;
        }
コード例 #10
0
ファイル: ssp_pair.cpp プロジェクト: C00IHandLuke/CPEN442VPN
void PFC::restore(char * bytes,G1& w)
{
	int i,j,n=2*(bits(*ord-1)-2+ham(*ord));
	int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
	int len=n*bytes_per_big;
	Big x;

	if (w.ptable!=NULL) return;

	w.ptable=new ZZn[n];
	for (i=j=0;i<n;i++)
	{
		x=from_binary(bytes_per_big,&bytes[j]);
		w.ptable[i]=x;
		j+=bytes_per_big;
	}
	for (i=0;i<len;i++) bytes[i]=0;
	delete [] bytes;
}
コード例 #11
0
int main() {
  int nR = 11;
  int nTheta = 7;
  double rMax = 10;
  double tolerance = 1.5e-10;
  int maxIterations = 100;
  double bareMass = 1.;

  ExtrinsicCurvature kij;
  SphericalBasis* basis = new SphericalBasis();
  Hamiltonian ham(kij,basis);
  ham.setBareMass(bareMass);
  ham.setMaximumRadius(rMax);
  ham.setRanks(nR, nTheta);
  ham.solve(tolerance, maxIterations);
  TestFields test(ham, kij);

  std::cout << test.psi(0.5, 1.0) << "\n";
  std::cout << test.psi(1.0, 1.0) << "\n";
}
コード例 #12
0
ファイル: ssp_pair.cpp プロジェクト: C00IHandLuke/CPEN442VPN
int PFC::spill(G1& w,char *& bytes)
{
	int i,j,n=2*(bits(*ord-1)-2+ham(*ord));
	int bytes_per_big=(MIRACL/8)*(get_mip()->nib-1);
	int len=n*bytes_per_big;
	Big x;
	if (w.ptable==NULL) return 0;

	bytes=new char[len];
	for (i=j=0;i<n;i++)
	{
		x=w.ptable[i];
		to_binary(x,bytes_per_big,&bytes[j],TRUE);
		j+=bytes_per_big;
	}

	delete [] w.ptable; 
	w.ptable=NULL;
	return len;
}
コード例 #13
0
ファイル: ssp_pair.cpp プロジェクト: ferozsalam/FYP
int PFC::precomp_for_pairing(G1& w)
{
    int i,j,nb,len;
    ECn A,Q,B;
    ZZn lam,x,y;
    big ptr;
    Big iters=*ord-1;

    A=w.g;
    normalise(A);
    B=A;
    nb=bits(iters);
    j=0;
    len=2*(nb-2+ham(*ord));
    w.ptable=new ZZn[len];
    get_mip()->coord=MR_AFFINE;
    for (i=nb-2; i>=0; i--)
    {
        Q=A;
// Evaluate line from A to A+B
        A.add(A,&ptr);
        lam=ptr;
        extract(Q,x,y);
        w.ptable[j++]=lam;
        w.ptable[j++]=lam*x-y;

        if (bit(iters,i)==1)
        {
            Q=A;
            A.add(B,&ptr);
            lam=ptr;
            extract(Q,x,y);
            w.ptable[j++]=lam;
            w.ptable[j++]=lam*x-y;
        }
    }
    get_mip()->coord=MR_PROJECTIVE;
    return len;
}
コード例 #14
0
ファイル: kss8.cpp プロジェクト: BingyZhang/CommutEnc
int main()
{
	miracl *mip=&precision;
	Big s,x,q,p,t,A,B,cf,X,Y,sru,n,best_s,f;
	Big T,P,F,m1,m2;
	ECn W;
	ECn2 Q;
	ZZn2 r;
	mip->IOBASE=16;
	int i,ns,sign,best_ham=1000;
    sign=1;  // 1= positive, 2=negative for +/- x solutions
	s="1400000000000000";
	ns=1;
	for (i=0;i<100;i++)
	{
		forever
		{
			forever
			{
				sign=3-sign;    // always looking for +ve x solutions.
				if (sign==1) s+=1;
				if (sign==1) x=5+30*s;
				else         x=5-30*s;

				t=(2*pow(x,3) - 11*x + 15)/15;
				q=(pow(x,4) - 8*pow(x,2) + 25)/450;
				cf=(5*x*x+10*x+25)/2;
				n=cf*q;
				p=cf*q+t-1;  // avoids overflow..

				if (p%8!=5) continue;  // p will be 1 mod 4
				if (!prime(q)) continue;
				if (!prime(p)) continue;
		
				break;
			}

			T=t*t-2*p;
			P=p*p;
			F=(4*P-T*T);

			F=sqrt(F);
			m1=P+1-F;  // Wrong Curve
 
			m2=P+1+F;

			A=0; B=0;
			forever
			{
				A+=1;
				do
				{
					X=rand(p);
					Y=sqrt(X*X*X+A*X,p);
				} while (Y==0);
        
				ecurve(A,B,p,MR_AFFINE);

				W.set(X,Y);
				W*=cf;
				if ((q*W).iszero()) break;
			}

			mip->TWIST=MR_QUARTIC_M;
			do
			{
				r=randn2();
			} while (!Q.set(r)); 
  
			Q*=(m2/q);
 
			if ((q*Q).iszero()) break;

			mip->TWIST=MR_QUARTIC_D;
			do
			{
				r=randn2();
			} while (!Q.set(r)); 
  
			Q*=(m2/q);
 
			if ((q*Q).iszero()) break;

			cout << "Something wrong!" << endl;
			exit(0);
		}
		cout << "solution " << ns << endl;
		cout << "irreducible polynomial = X^4 - [0,1]" << endl;

		if (sign==1)
		{
			cout << "s= +" << s << endl;
			cout << "s%12= " << s%12 << endl;
		}
		else
		{
			cout << "s= -" << s << endl;
			cout << "s%12= " << 12-(s%12) << endl;
		}
		cout << "x= " << x << " ham(x)= " << ham(x) << endl;
		cout << "p= " << p << " bits(p)= " << bits(p) << endl;
		cout << "q= " << q << " bits(q)= " << bits(q) << endl;
		cout << "n= " << n << endl;
		cout << "t= " << t << endl;
		cout << "cf= " << cf << endl;

		//cout << "W= " << W << endl;
		cout << "q*W= " << q*W << endl;
		mip->IOBASE=10;
		cout << "E(Fp): y^2=x^3+" << A << "x" << endl;
		mip->IOBASE=16;
		if (mip->TWIST==MR_QUARTIC_M) cout << "Twist type M" << endl;
		if (mip->TWIST==MR_QUARTIC_D) cout << "Twist type D" << endl;

		//cout << "Q= " << Q << endl;
		Q*=q;
		cout << "check - if right twist should be O - q*Q= " << Q << endl;	
		if (ham(x)<best_ham) {best_ham=ham(x);best_s=s;}	
		cout << "So far minimum hamming weight of x= " << best_ham << endl;
		cout << "for seed= " << best_s << endl << endl;
		ns++;
	}
	return 0;
}
コード例 #15
0
int main(int argc, char const *argv[]) {
  Eigen::setNbThreads(NumCores);
#ifdef MKL
  mkl_set_num_threads(NumCores);
#endif
  INFO("Eigen3 uses " << Eigen::nbThreads() << " threads.");
  int L;
  RealType J12ratio;
  int OBC;
  int N1, N2;
  int dynamics, Tsteps;
  RealType Uin, phi, dt;
  std::vector<RealType> Vin;
  LoadParameters( "conf.h5", L, J12ratio, OBC, N1, N2, Uin, Vin, phi, dynamics, Tsteps, dt);
  HDF5IO *file = new HDF5IO("FSSH.h5");
  // const int L = 5;
  // const bool OBC = true;
  // const RealType J12ratio = 0.010e0;
  INFO("Build Lattice - ");
  std::vector<DT> J;
  if ( OBC ){
    // J = std::vector<DT>(L - 1, 0.0);// NOTE: Atomic limit testing
    J = std::vector<DT>(L - 1, 1.0);
    if ( J12ratio > 1.0e0 ) {
      for (size_t cnt = 1; cnt < L-1; cnt+=2) {
        J.at(cnt) /= J12ratio;
      }
    } else{
      for (size_t cnt = 0; cnt < L-1; cnt+=2) {
        J.at(cnt) *= J12ratio;
      }
    }
  } else{
    J = std::vector<DT>(L, 1.0);
    if ( J12ratio > 1.0e0 ) {
      for (size_t cnt = 1; cnt < L; cnt+=2) {
        J.at(cnt) /= J12ratio;
      }
    } else{
      for (size_t cnt = 0; cnt < L; cnt+=2) {
        J.at(cnt) *= J12ratio;
      }
    }
#ifndef DTYPE
    if ( std::abs(phi) > 1.0e-10 ){
      J.at(L-1) *= exp( DT(0.0, 1.0) * phi );
    }
#endif
  }
  for ( auto &val : J ){
    INFO_NONEWLINE(val << " ");
  }
  INFO("");
  const std::vector< Node<DT>* > lattice = NN_1D_Chain(L, J, OBC);
  file->saveNumber("1DChain", "L", L);
  file->saveStdVector("1DChain", "J", J);
  for ( auto &lt : lattice ){
    if ( !(lt->VerifySite()) ) RUNTIME_ERROR("Wrong lattice setup!");
  }
  INFO("DONE!");
  INFO("Build Basis - ");
  // int N1 = (L+1)/2;
  Basis F1(L, N1, true);
  F1.Fermion();
  std::vector<int> st1 = F1.getFStates();
  std::vector<size_t> tg1 = F1.getFTags();
  // for (size_t cnt = 0; cnt < st1.size(); cnt++) {
  //   INFO_NONEWLINE( std::setw(3) << st1.at(cnt) << " - ");
  //   F1.printFermionBasis(st1.at(cnt));
  //   INFO("- " << tg1.at(st1.at(cnt)));
  // }
  // int N2 = (L-1)/2;
  Basis F2(L, N2, true);
  F2.Fermion();
  std::vector<int> st2 = F2.getFStates();
  std::vector<size_t> tg2 = F2.getFTags();
  // for (size_t cnt = 0; cnt < st2.size(); cnt++) {
  //   INFO_NONEWLINE( std::setw(3) << st2.at(cnt) << " - ");
  //   F2.printFermionBasis(st2.at(cnt));
  //   INFO("- " << tg2.at(st2.at(cnt)));
  // }
  file->saveNumber("Basis", "N1", N1);
  file->saveStdVector("Basis", "F1States", st1);
  file->saveStdVector("Basis", "F1Tags", tg1);
  file->saveNumber("Basis", "N2", N2);
  file->saveStdVector("Basis", "F2States", st2);
  file->saveStdVector("Basis", "F2Tags", tg2);
  INFO("DONE!");
  INFO_NONEWLINE("Build Hamiltonian - ");
  std::vector<Basis> Bases;
  Bases.push_back(F1);
  Bases.push_back(F2);
  Hamiltonian<DT> ham( Bases );
  std::vector< std::vector<DT> > Vloc;
  std::vector<DT> Vtmp;//(L, 1.0);
  for ( RealType &val : Vin ){
    Vtmp.push_back((DT)val);
  }
  Vloc.push_back(Vtmp);
  Vloc.push_back(Vtmp);
  std::vector< std::vector<DT> > Uloc;
  // std::vector<DT> Utmp(L, DT(10.0e0, 0.0e0) );
  std::vector<DT> Utmp(L, (DT)Uin);
  Uloc.push_back(Utmp);
  Uloc.push_back(Utmp);
  ham.BuildLocalHamiltonian(Vloc, Uloc, Bases);
  INFO(" - BuildLocalHamiltonian DONE!");
  ham.BuildHoppingHamiltonian(Bases, lattice);
  INFO(" - BuildHoppingHamiltonian DONE!");
  ham.BuildTotalHamiltonian();
  INFO("DONE!");
  INFO_NONEWLINE("Diagonalize Hamiltonian - ");
  std::vector<RealType> Val;
  Hamiltonian<DT>::VectorType Vec;
  ham.eigh(Val, Vec);
  INFO("GS energy = " << Val.at(0));
  file->saveVector("GS", "EVec", Vec);
  file->saveStdVector("GS", "EVal", Val);
  INFO("DONE!");
  std::vector< DTV > Nfi = Ni( Bases, Vec, ham );
  INFO(" Up Spin - ");
  INFO(Nfi.at(0));
  INFO(" Down Spin - ");
  INFO(Nfi.at(1));
  INFO(" N_i - ");
  DTV Niall = Nfi.at(0) + Nfi.at(1);
  INFO(Niall);
  DTM Nud = NupNdn( Bases, Vec, ham );
  INFO(" Correlation NupNdn");
  INFO(Nud);
  DTM Nuu = NupNup( Bases, Vec, ham );
  INFO(" Correlation NupNup");
  INFO(Nuu);
  DTM Ndd = NdnNdn( Bases, Vec, ham );
  INFO(" Correlation NdnNdn");
  INFO(Ndd);
  INFO(" N_i^2 - ");
  DTM Ni2 = Nuu.diagonal() + Ndd.diagonal() + 2.0e0 * Nud.diagonal();
  INFO(Ni2);
  file->saveVector("Obs", "Nup", Nfi.at(0));
  file->saveVector("Obs", "Ndn", Nfi.at(1));
  file->saveMatrix("Obs", "NupNdn", Nud);
  file->saveMatrix("Obs", "NupNup", Nuu);
  file->saveMatrix("Obs", "NdnNdn", Ndd);
  delete file;
  if ( dynamics ){
    ComplexType Prefactor = ComplexType(0.0, -1.0e0*dt);/* NOTE: hbar = 1 */
    std::cout << "Begin dynamics......" << std::endl;
    std::cout << "Cut the boundary." << std::endl;
    J.pop_back();
    std::vector< Node<DT>* > lattice2 = NN_1D_Chain(L, J, true);// cut to open
    ham.BuildHoppingHamiltonian(Bases, lattice2);
    INFO(" - Update Hopping Hamiltonian DONE!");
    ham.BuildTotalHamiltonian();
    INFO(" - Update Total Hamiltonian DONE!");
    for (size_t cntT = 1; cntT <= Tsteps; cntT++) {
      ham.expH(Prefactor, Vec);
      if ( cntT % 2 == 0 ){
        HDF5IO file2("DYN.h5");
        std::string gname = "Obs-";
        gname.append(std::to_string((unsigned long long)cntT));
        gname.append("/");
        Nfi = Ni( Bases, Vec, ham );
        Nud = NupNdn( Bases, Vec, ham );
        Nuu = NupNup( Bases, Vec, ham );
        Ndd = NdnNdn( Bases, Vec, ham );
        file2.saveVector(gname, "Nup", Nfi.at(0));
        file2.saveVector(gname, "Ndn", Nfi.at(1));
        file2.saveMatrix(gname, "NupNdn", Nud);
        file2.saveMatrix(gname, "NupNup", Nuu);
        file2.saveMatrix(gname, "NdnNdn", Ndd);
      }
    }
  }
  return 0;
}
コード例 #16
0
ファイル: bls24.cpp プロジェクト: asgene/sm2
int main()
{
	miracl *mip=&precision;
	Big s,x,q,p,t,A,B,cf,X,Y,sru,n,best_s,f,tau[5],TAU;
	Big T,P,F,m1,m2,m3,m4;
	BOOL got_one;
	ECn W;
	ECn4 Q;
	ZZn4 XX,YY,r;	
	ZZn2 xi;
	int i,ns,sign,best_ham=1000;
	mip->IOBASE=16;
	s="E000000000000000";   

	ns=1;
	
	forever
	{
		s+=1;
		for (sign=1;sign<=2;sign++)
		{

			if (sign==1) x=s;
			else         x=-s;

			if (x<0 || ham(x)>7) continue; // filter out difficult or poor solutions

			t=1+x;
			p=1+x+x*x-pow(x,4)+2*pow(x,5)-pow(x,6)+pow(x,8)-2*pow(x,9)+pow(x,10);
			q=1-pow(x,4)+pow(x,8);
	
			if (p%3!=0) continue;
			p/=3;
			
			if (p%8==1) continue;
			if (!prime(p)) continue;
			if (!prime(q)) continue;

			modulo(p);
			if (p%8==5) xi.set(0,1);
			if (p%8==3) xi.set(1,1);
			if (p%8==7) xi.set(2,1);

// make sure its irreducible
			if (pow(xi,(p*p-1)/2)==1) {/*cout << "Failed - not a square" << endl; */ continue;}
			if (pow(xi,(p*p-1)/3)==1) {/*cout << "Failed - not a cube" << endl; */ continue;}  // make sure that x^6-c is irreducible

			n=p+1-t;
			cf=n/q;

			tau[0]=2;  // count points on twist over extension p^4
			tau[1]=t;
			for (i=1;i<4;i++ ) tau[i+1]=t*tau[i]-p*tau[i-1];
			P=p*p*p*p;
			TAU=tau[4];

			F=(4*P-TAU*TAU)/3;
			F=sqrt(F);
		
			m2=P+1-(3*F+TAU)/2;

		//	cout << "m2%q= " << m2%q << endl;

			B=1;   // find curve equation
	
			forever
			{
				B+=1;
				if (B==2)
				{
					X=-1; Y=1;
				}
				else if (B==3)
				{
					X=1; Y=2;
				}
				else if (B==8)
				{
					X=1; Y=3;
				}
				else if (B==15)
				{
					X=1; Y=4;
				}
				else
				{
					do
					{
						X=rand(p);
						Y=sqrt(X*X*X+B,p);
					} while (Y==0);
				}
        
				ecurve(0,B,p,MR_AFFINE);
				W.set(X,Y);
				W*=cf;
				if ((q*W).iszero()) break;
			}

			mip->TWIST=MR_SEXTIC_M;  // is it an M-type twist...?
			do
			{
				r=randn4();
			} while (!Q.set(r)); 
			got_one=FALSE;

			Q*=(m2/q);

			if ((q*Q).iszero()) got_one=TRUE;

//			cout << "m1*Q= " << m1*Q << endl;
//			cout << "m1%q= " << m1%q << endl;
			else
			{
				mip->TWIST=MR_SEXTIC_D;  // no, so it must be D-type.
				do
				{
					r=randn4();
				} while (!Q.set(r)); 
			
				Q*=(m2/q);

				if ((q*Q).iszero()) got_one=TRUE;
			}
			if (!got_one) {cout << "Bad twist" << endl; exit(0);}  // Huh?
	
			if (mip->TWIST==MR_SEXTIC_M) continue;  // not interested just now

			cout << "solution " << ns << endl;
		
			cout << "x= " << x << " ham(x)= " << ham(x) << endl;
			cout << "p= " << p << " bits(p)= " << bits(p) << endl;
			cout << "q= " << q << " bits(q)= " << bits(q) << endl;
			cout << "n= " << n << endl;
			cout << "t= " << t << endl;
			cout << "cf= " << cf << endl;
			

			cout << "W= " << W << endl;
			cout << "q*W= " << q*W << endl;
			mip->IOBASE=10;
			cout << "E(Fp): y^2=x^3+" << B << endl;
			cout << "(p-1)%24= " << (p-1)%24 << endl;
			cout << "p%8= " << p%8 << endl;
			mip->IOBASE=16;
			if (mip->TWIST==MR_SEXTIC_M) cout << "Twist type M" << endl;
			if (mip->TWIST==MR_SEXTIC_D) cout << "Twist type D" << endl;

			Q*=q;
			cout << "check - if right twist should be O - q*Q= " << Q << endl;	
						
			if (ham(x)<best_ham) {best_ham=ham(x);best_s=s;}	
			cout << "So far minimum hamming weight of x= " << best_ham << endl;
			cout << "for seed= " << best_s << endl;
						
			cout << endl;
			ns++;
		}
	}

	return 0;
}
コード例 #17
0
ファイル: schro.cpp プロジェクト: nsgarv/PHYS103
void main() {

  //* Initialize parameters (grid spacing, time step, etc.)
  cout << "Enter number of grid points: "; int N; cin >> N;
  double L = 100;        // System extends from -L/2 to L/2
  double h = L/(N-1);    // Grid size
  double h_bar = 1;  double mass = 1; // Natural units
  cout << "Enter time step: "; double tau; cin >> tau;
  Matrix x(N);
  int i, j, k;
  for( i=1; i<=N; i++ )
    x(i) = h*(i-1) - L/2;  // Coordinates  of grid points

  //* Set up the Hamiltonian operator matrix
  Matrix eye(N,N), ham(N,N);
  eye.set(0.0);  // Set all elements to zero
  for( i=1; i<=N; i++ ) // Identity matrix
    eye(i,i) = 1.0;
  ham.set(0.0);  // Set all elements to zero
  double coeff = -h_bar*h_bar/(2*mass*h*h);
  for( i=2; i<=(N-1); i++ ) {
    ham(i,i-1) = coeff;
    ham(i,i) = -2*coeff;  // Set interior rows
    ham(i,i+1) = coeff;
  }
  // First and last rows for periodic boundary conditions
  ham(1,N) = coeff;   ham(1,1) = -2*coeff; ham(1,2) = coeff;
  ham(N,N-1) = coeff; ham(N,N) = -2*coeff; ham(N,1) = coeff;

  //* Compute the Crank-Nicolson matrix
  Matrix RealA(N,N), ImagA(N,N), RealB(N,N), ImagB(N,N);
  for( i=1; i<=N; i++ )
   for( j=1; j<=N; j++ ) {
     RealA(i,j) = eye(i,j);
     ImagA(i,j) = 0.5*tau/h_bar*ham(i,j);
     RealB(i,j) = eye(i,j);
     ImagB(i,j) = -0.5*tau/h_bar*ham(i,j);
   }
  Matrix RealAi(N,N), ImagAi(N,N);
  cout << "Computing matrix inverse ... " << flush;
  cinv( RealA, ImagA, RealAi, ImagAi );  // Complex matrix inverse
  cout << "done" << endl;
  Matrix RealD(N,N), ImagD(N,N); // Crank-Nicolson matrix
  for( i=1; i<=N; i++ )
   for( j=1; j<=N; j++ ) {
    RealD(i,j) = 0.0;           // Matrix (complex) multiplication
    ImagD(i,j) = 0.0;
    for( k=1; k<=N; k++ ) {
      RealD(i,j) += RealAi(i,k)*RealB(k,j) - ImagAi(i,k)*ImagB(k,j);
      ImagD(i,j) += RealAi(i,k)*ImagB(k,j) + ImagAi(i,k)*RealB(k,j);
    }
   }
			 
  //* Initialize the wavefunction 
  const double pi = 3.141592654;
  double x0 = 0;          // Location of the center of the wavepacket
  double velocity = 0.5;  // Average velocity of the packet
  double k0 = mass*velocity/h_bar;       // Average wavenumber
  double sigma0 = L/10;   // Standard deviation of the wavefunction
  double Norm_psi = 1/(sqrt(sigma0*sqrt(pi)));  // Normalization
  Matrix RealPsi(N), ImagPsi(N), rpi(N), ipi(N);
  for( i=1; i<=N; i++ ) {
    double expFactor = exp(-(x(i)-x0)*(x(i)-x0)/(2*sigma0*sigma0));
    RealPsi(i) = Norm_psi * cos(k0*x(i)) * expFactor;
    ImagPsi(i) = Norm_psi * sin(k0*x(i)) * expFactor;
    rpi(i) = RealPsi(i);    // Record initial wavefunction
    ipi(i) = ImagPsi(i);    // for plotting
  }

  //* Initialize loop and plot variables 
  int nStep = (int)(L/(velocity*tau));  // Particle should circle system
  int nplots = 20;                      // Number of plots to record
  double plotStep = nStep/nplots;       // Iterations between plots          
  Matrix p_plot(N,nplots+2);
  for( i=1; i<=N; i++ )      // Record initial condition
    p_plot(i,1) = RealPsi(i)*RealPsi(i) + ImagPsi(i)*ImagPsi(i);
  int iplot = 1;

  //* Loop over desired number of steps (wave circles system once)
  int iStep;
  Matrix RealNewPsi(N), ImagNewPsi(N);
  for( iStep=1; iStep<=nStep; iStep++ )	{
	
    //* Compute new wave function using the Crank-Nicolson scheme
	RealNewPsi.set(0.0);  ImagNewPsi.set(0.0);
    for( i=1; i<=N; i++ )        // Matrix multiply D*psi
      for( j=1; j<=N; j++ ) {
        RealNewPsi(i) += RealD(i,j)*RealPsi(j) - ImagD(i,j)*ImagPsi(j);
        ImagNewPsi(i) += RealD(i,j)*ImagPsi(j) + ImagD(i,j)*RealPsi(j);
      }
    RealPsi = RealNewPsi;  // Copy new values into Psi
    ImagPsi = ImagNewPsi;
        
    //* Periodically record values for plotting
    if( fmod(iStep,plotStep) < 1 ) {  
      iplot++;
      for( i=1; i<=N; i++ ) 
        p_plot(i,iplot) = RealPsi(i)*RealPsi(i) + ImagPsi(i)*ImagPsi(i);
      cout << "Finished " << iStep << " of " << nStep << " steps" << endl; 
    }
  }
  // Record final probability density
  iplot++;
  for( i=1; i<=N; i++ ) 
    p_plot(i,iplot) = RealPsi(i)*RealPsi(i) + ImagPsi(i)*ImagPsi(i); 
  nplots = iplot;   // Actual number of plots recorded
  
  //* Print out the plotting variables:  x, rpi, ipi, p_plot
  ofstream xOut("x.txt"), rpiOut("rpi.txt"), ipiOut("ipi.txt"), 
	       p_plotOut("p_plot.txt");
  for( i=1; i<=N; i++ ) {
    xOut << x(i) << endl;
    rpiOut << rpi(i) << endl;
    ipiOut << ipi(i) << endl;
    for( j=1; j<nplots; j++ )
      p_plotOut << p_plot(i,j) << ", ";
    p_plotOut << p_plot(i,nplots) << endl;
  }
}
コード例 #18
0
ファイル: hamiltonian.cpp プロジェクト: atkinsmc/dom_clean
// returns the real part of the Hamiltonian in coordinate space.
// This is needed when solving the Schroedinger-like equation
// for the overlap functions.
//
matrix_t
re_hamiltonian( const std::vector< double > &rmesh, double Ecm,
                int L, double J, double A, pot &U ) {

    U.setEnergy( Ecm );
    U.setAM( L, J );

    double rdelt = rmesh.at(1) - rmesh.at( 0 );

    // initialize matrix
    matrix_t ham( rmesh.size(), rmesh.size() );
    for ( unsigned int i = 0; i < rmesh.size(); ++i ) {
        for ( unsigned int j = 0; j <= i; ++j ) {

            ham( i, j ) = 0.0;
            ham( j, i ) = ham( i, j );
        }
    }

    // \hbar^2 / ( 2 * mu ), mu is reduced mass
    double mu_factor = A / ( A + 1.0 );
    double fac = - 1 / ( U.kconstant * mu_factor );

    // Construct Tridiagonal matrix for kinetic energy term
    // and add in diagonal parts of potential
    for ( unsigned int i = 0; i < rmesh.size(); ++i ) {

        // Diagonal Part of Kinetic Energy
        double KE_diagonal = -2 * fac / std::pow( rdelt, 2 )
                             - fac * L * ( L + 1 ) / std::pow( rmesh[i], 2 );

        // Off-diagonal part of Kinetic energy
        double KE_off_diagonal = fac / std::pow( rdelt, 2 );

        // Diagonal Parts of Potential Energy
        double PE_diagonal = real ( U.localPart( rmesh[i] ) );

        ham( i, i ) = PE_diagonal + KE_diagonal;
        if ( i != 0 ) ham( i, i - 1 ) = KE_off_diagonal;
        if ( i != rmesh.size() - 1 ) ham( i, i + 1 ) = KE_off_diagonal;

        // Boundary Condition
        if ( i == 0 ) ham( 0, 0 ) -= KE_off_diagonal * std::pow( -1.0, L );

        // Now add in nonlocal components
        for ( unsigned int j = 0; j <= i; ++j ) {

            // nonlocalPart is already multiplied by r, r'
            ham( i, j ) += real( U.nonlocalPart( rmesh[i], rmesh[j] ) ) * rdelt;

            if ( j != i ) ham( j, i ) = ham( i, j );

            //std::cout << i << " " << j << " " << ham( i, j ) << std::endl;
        } // end loop over j

    } // end loop over i

    return ham;
}
コード例 #19
0
int main(int argc, char const *argv[]) {
  Eigen::setNbThreads(NumCores);
#ifdef MKL
  mkl_set_num_threads(NumCores);
#endif
  INFO("Eigen3 uses " << Eigen::nbThreads() << " threads.");
  int L;
  RealType J12ratio;
  int OBC;
  int N;
  RealType Uin, phi;
  std::vector<RealType> Vin;
  LoadParameters( "conf.h5", L, J12ratio, OBC, N, Uin, Vin, phi);
  HDF5IO file("BSSH.h5");
  // const int L = 5;
  // const bool OBC = true;
  // const RealType J12ratio = 0.010e0;
  INFO("Build Lattice - ");
  std::vector<ComplexType> J;
  if ( OBC ){
    J = std::vector<ComplexType>(L - 1, ComplexType(1.0, 0.0));
    for (size_t cnt = 0; cnt < L-1; cnt+=2) {
      J.at(cnt) *= J12ratio;
    }
  } else{
    J = std::vector<ComplexType>(L, ComplexType(1.0, 0.0));
    for (size_t cnt = 0; cnt < L; cnt+=2) {
      J.at(cnt) *= J12ratio;
    }
    if ( std::abs(phi) > 1.0e-10 ){
      J.at(L-1) *= exp( ComplexType(0.0e0, 1.0e0) * phi );
      // INFO(exp( ComplexType(0.0e0, 1.0e0) * phi ));
    }
  }
  for ( auto &val : J ){
    INFO_NONEWLINE(val << " ");
  }
  INFO("");
  const std::vector< Node<ComplexType>* > lattice = NN_1D_Chain(L, J, OBC);
  file.saveNumber("1DChain", "L", L);
  file.saveNumber("1DChain", "U", Uin);
  file.saveStdVector("1DChain", "J", J);
  for ( auto &lt : lattice ){
    if ( !(lt->VerifySite()) ) RUNTIME_ERROR("Wrong lattice setup!");
  }
  INFO("DONE!");
  INFO("Build Basis - ");
  // int N1 = (L+1)/2;
  Basis B1(L, N);
  B1.Boson();
  // std::vector< std::vector<int> > st = B1.getBStates();
  // std::vector< RealType > tg = B1.getBTags();
  // for (size_t cnt = 0; cnt < tg.size(); cnt++) {
  //   INFO_NONEWLINE( std::setw(3) << cnt << " - ");
  //   for (auto &j : st.at(cnt)){
  //     INFO_NONEWLINE(j << " ");
  //   }
  //   INFO("- " << tg.at(cnt));
  // }
  file.saveNumber("1DChain", "N", N);
  // file.saveStdVector("Basis", "States", st);
  // file.saveStdVector("Basis", "Tags", tg);
  INFO("DONE!");
  INFO_NONEWLINE("Build Hamiltonian - ");
  std::vector<Basis> Bases;
  Bases.push_back(B1);
  Hamiltonian<ComplexType> ham( Bases );
  std::vector< std::vector<ComplexType> > Vloc;
  std::vector<ComplexType> Vtmp;//(L, 1.0);
  for ( RealType &val : Vin ){
    Vtmp.push_back((ComplexType)val);
  }
  Vloc.push_back(Vtmp);
  std::vector< std::vector<ComplexType> > Uloc;
  // std::vector<ComplexType> Utmp(L, ComplexType(10.0e0, 0.0e0) );
  std::vector<ComplexType> Utmp(L, (ComplexType)Uin);
  Uloc.push_back(Utmp);
  ham.BuildLocalHamiltonian(Vloc, Uloc, Bases);
  ham.BuildHoppingHamiltonian(Bases, lattice);
  ham.BuildTotalHamiltonian();
  INFO("DONE!");
  INFO_NONEWLINE("Diagonalize Hamiltonian - ");
  std::vector<RealType> Val;
  Hamiltonian<ComplexType>::VectorType Vec;
  ham.eigh(Val, Vec);
  INFO("GS energy = " << Val.at(0));
  file.saveVector("GS", "EVec", Vec);
  file.saveStdVector("GS", "EVal", Val);
  INFO("DONE!");
  std::vector<ComplexType> Nbi = Ni( Bases, Vec );
  for (auto &n : Nbi ){
    INFO( n << " " );
  }
  ComplexMatrixType Nij = NiNj( Bases, Vec );
  INFO(Nij);
  INFO(Nij.diagonal());
  file.saveStdVector("Obs", "Nb", Nbi);
  file.saveMatrix("Obs", "Nij", Nij);
  return 0;
}
コード例 #20
0
ファイル: quasiholenew.cpp プロジェクト: atkinsmc/nonlocaldom
int main(){

sky sky1;

double Mu = M;   //Mass in MeV
complex <double> M_I(0,1);

// Create momentum space grid
std::vector<double> kmesh;
std::vector<double> kweights;
double const kmax = 5.0;
int const kpts = 300;
kmesh.resize( kpts );
kweights.resize( kpts );
GausLeg( 0., kmax, kmesh, kweights );

////////Input Parameters of the potential (fit parameters) /////
std::string parameters_filename="Input.inp";

NuclearParameters Nu = read_nucleus_parameters( "Input/nca40.inp" );

double Ef=Nu.Ef;
int lmax=6;
double z0=20.0;
double zp0;
double A0=40.0;
double tz=-0.5;

int type=1;
int mvolume = 4;
int AsyVolume = 1;

double A = 40.0;

double  mu = (A)/((A-1.));

if (tz>0) { zp0=1;}
else {zp0=0;}

double ph_gap = Nu.ph_gap;
cout<<"ph_gap = "<<Nu.ph_gap<<endl;
double  rStart = .05;
double  rmax = 20.;
int  ham_pts = 300; 

double  rdelt = rmax / ham_pts;

vector<double> dr;
dr.assign(ham_pts,rdelt);

// Construct Parameters Object
Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, zp0 );

// Construct Potential Object
pot pottt = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
pot * pott = &pottt;

boundRspace initiate(rmax , ham_pts , Ef, ph_gap , lmax , Nu.Z , zp0 , Nu.A , pott);

 double Elower = -11.61818;
 double Eupper = -9.4;
 double jj = .5;
 int ll = 0;
 int Ifine = 1;
 initiate.searchNonLoc( Elower, Eupper, jj,  ll,  Ifine);
 initiate.exteriorWaveFunct(ll);
 initiate.normalizeWF();


double tol=.01;
double estart=Ef;

///// Making rmesh///

std::vector<double> rmesh_p= initiate.make_rmesh_point();
std::vector<double> rmesh= initiate.make_rmesh();

double  rdelt_p = rdelt / 1.025641026;

double Emax = 2*Ef;
double Emin=-200.0 + Emax;

//Generating the propagator

double J;

//Starting loop over L and J to construct the density matrix
//want to start at L=3 to see what QPE I find
lmax=6;
for(int L=0;L<lmax+1;L++){
	for(int s=0;s<2;s++){	
		J=L-0.5+s;
		if(J<0){
			J=0.5;
			s=1;
		}	

		string presky = "waves/neutron/data/ecut120/";

		string jlab = sky1.jlab(J);

		string llab = sky1.llab(L);
	
		cout<<endl;
		cout<<"L = "<<L<<" J = "<<J<<endl;
		cout<<endl;

		int N = 0;

		double QPE = initiate.find_level(rmesh, Ef, N, L, J, tol);

		//cout<<"    QPE = "<<QPE<<endl;

		//dom_nonlocal_r dom(Ef, N, L, J, rmesh, dr);
		matrix_t ham;
		ham.clear();
		//change this back to QPE when needed
		ham = initiate.re_hamiltonian(rmesh, QPE, L, J);

		matrix_t nonlocal;
		nonlocal.clear();
		nonlocal = initiate.nonlocal_ham(rmesh,QPE,L,J);

		/* string hamname = "waves/ham" + llab + jlab + ".txt";
		ofstream fham(hamname.c_str());
		
		double hmax=0.0;

		for(int i=0;i<kmesh.size();i++){
			for(int j=0;j<kmesh.size();j++){
				fham << ham(i,j) << " ";
				if(ham(i,j) > hmax){
					hmax = ham(i,j);
				}
			}
			fham<<endl;
		}
		fham.close();

		*/

		vector <eigen_t> hameig = initiate.real_eigvecs(ham);

		string ename = "waves/hameig" + llab + jlab + ".txt";
		ofstream efile(ename.c_str());

		cvector_t local(rmesh.size());

		double enorm = 0;

		double fac = -1.0 / ( pott->kconstant * mu );

		for(int i=0;i<rmesh.size();i++){
			enorm += pow(hameig[0].second[i], 2) * rdelt;
			local[i] = pott->localPart(rmesh[i]); /* - 2 * fac / pow( rdelt, 2 ) - fac * L * ( L + 1 ) / pow( rmesh[i], 2 ); */
			ham(i,i) -= real(local[i]);
		}

		/*

		ofstream hamfile("waves/ham.txt");

		for(int i=0;i<rmesh.size();i++){
			hamfile << ham(i,i) << endl;
		}

		hamfile.close();

		*/

		//cout << "enorm = " << enorm << endl;

		//cout << "initial ham eig = " << hameig[0].first << endl;

/*

		double kh;
		double kh2;	
		double kh3;
		
		for(int i=0;i<kmesh.size();i++){
			if(i%30 == 0){
				cout<<"i = "<<i<<endl;
			}
			for(int j=0;j<kmesh.size();j++){
				kh=0;
				kh2=0;
				kh3=0;
				for(int ii=0;ii<rmesh.size();ii++){
					//kh += bess_mtx(i,ii) * bess_mtx(j,ii) * (2.0/M_PI) * real(local[ii]) * pow(rmesh[ii], 2) * rdelt;
					kh += bess_mtx(i,ii) * bess_mtx(j,ii) * (2.0/M_PI) * real(local[ii]) * rmesh[ii] * rdelt;
					//kh3 += bess_mtx(i,ii) * bess_mtx(j,ii) * (2.0/M_PI) * real(local[ii]) * pow(rmesh[ii], 2) * rdelt;
					kh3 += bess_mtx(i,ii) * bess_mtx(j,ii) * (2.0/M_PI) * real(local[ii]) * rmesh[ii] * rdelt;
					for(int jj=0;jj<rmesh.size();jj++){
						//Assuming hamiltonian as not factors of rmesh in it
						kh += bess_mtx(i,ii) * bess_mtx(j,jj) * (2.0/M_PI) * nonlocal(ii,jj)*rmesh[ii]*rmesh[jj]*pow(rdelt,2);
						//kh += bess_mtx(i,ii) * bess_mtx(j,jj) * (2.0/M_PI) * nonlocal(ii,jj)*pow(rmesh[ii]*rmesh[jj]*rdelt,2);
						kh2 += bess_mtx(i,ii) * bess_mtx(j,jj) * (2.0/M_PI) * ham(ii,jj) * rmesh[ii] * rmesh[jj] * pow(rdelt,2);
						//kh2 += bess_mtx(i,ii) * bess_mtx(j,jj) * (2.0/M_PI) * ham(ii,jj) * pow(rmesh[ii] * rmesh[jj] *rdelt,2);
						kh3 += bess_mtx(i,ii) * bess_mtx(j,jj) * (2.0/M_PI) * ham(ii,jj) * rmesh[ii] * rmesh[jj] * pow(rdelt,2);
						//kh3 += bess_mtx(i,ii) * bess_mtx(j,jj) * (2.0/M_PI) * ham(ii,jj) * pow(rmesh[ii] * rmesh[jj] *rdelt,2);
						if(ii==jj){
							//kh3 -= bess_mtx(i,ii) * bess_mtx(j,jj) * (2.0/M_PI) * real(local[ii]) * pow(rmesh[ii],2) * rdelt;
							kh3 -= bess_mtx(i,ii) * bess_mtx(j,jj) * (2.0/M_PI) * real(local[ii]) * rmesh[jj] * rdelt;
						}
					}
				}
				k_ham(i,j) = kh;
				k_ham2(i,j) = kh2;
				k_ham3(i,j) = kh3;
			}
			//adding kinetic part here
			k_ham(i,i) += pow(kmesh[i],2) / (2*mu);
		}

		vector <eigen_t> khameig = initiate.real_eigvecs(k_ham);
		vector <eigen_t> khameig2 = initiate.real_eigvecs(k_ham2);
		vector <eigen_t> khameig3 = initiate.real_eigvecs(k_ham3);

		cout << "k-space ham eig[0] = " << khameig[0].first << endl;
		cout << "k-space ham eig[N] = " << khameig[rmesh.size()-1].first << endl;
		cout << "k-space ham2 eig[0] = " << khameig2[0].first << endl;
		cout << "k-space ham2 eig[N] = " << khameig2[rmesh.size()-1].first << endl;
		cout << "k-space ham3 eig[0] = " << khameig3[0].first << endl;
		cout << "k-space ham3 eig[N] = " << khameig3[rmesh.size()-1].first << endl;

		*/

		int Nmax=14;
		if(L>1){
			Nmax=13;
		}
		if(L>3){
			Nmax=12;
		}

		matrix_t skyham(Nmax, Nmax);
		skyham.clear();	

		for(int N=0;N<Nmax;N++){
			Nlab = sky1.Nlab(N);

//opening skyrme file which gives u(r)
			vector<double> sky0 = sky1.read(N,L,J,presky,rmesh.size());	

			vector <double> expo;
			expo.assign(rmesh.size(),0);

			vector <double> wave = hameig[N].second;
			
			for(int M=0;M<Nmax;M++){
				string Mlab;
				ostringstream convert;
				convert << M;
				Mlab = convert.str();

//opening skyrme file which gives u(r)
				vector<double> skyrme = sky1.read(M,L,J,presky,rmesh.size());

				double proj=0;

				for(int i=0;i<rmesh.size();i++){
					proj += wave[i]/sqrt(enorm) * skyrme[i] * rdelt;
				}

				for(int i=0;i<rmesh.size();i++){
					expo[i] += proj * skyrme[i];
				}

				//gonna do in terms of rdelt_p
				//ham definitely has r*r'*dr in it
				for(int i=0;i<rmesh.size();i++){
					for(int j=0;j<rmesh.size();j++){
						//skyham(N,M) += ham(i,j) * sky0[i] * skyrme[j] * pow(rmesh_p[i]/rmesh[i] * rmesh_p[j]/rmesh[j] * rdelt_p,2) / rdelt;
						skyham(N,M) += ham(i,j) * sky0[i] * skyrme[j] * rdelt;
					}
					//delta functions in local part get rid of one integral
					//assuming even the diagonal also has r*r'*dr included
					//skyham(N,M) += real(local[i]) * sky0[i] * skyrme[i] / pow(rmesh[i],4) / rdelt * pow(rmesh_p[i],2) * rdelt_p;
					skyham(N,M) += real(local[i]) * sky0[i] * skyrme[i] / pow(rmesh[i],2);
				}

			} //end loop over m

			string exponame = "waves/expo" + llab + jlab + Nlab + ".txt";
			ofstream expofile(exponame.c_str());

			double expnorm=0;
			for(int i=0;i<rmesh.size();i++){
				expnorm += pow(expo[i],2) * rdelt;
			}

		//cout << "expnorm = "<<expnorm<<endl;

			double factor;
	
			if(expo[10]<0){
				factor=-1.0;
			}else{	
				factor=1.0;
			}

			for(int i=0;i<rmesh.size();i++){
				expofile << rmesh[i] << " " << expo[i]/rmesh[i]/sqrt(expnorm)*factor << endl;
			}

		//acting on the expanded wavefuncion with h(r,r')
		/*double act=0;		
		for(int i=0;i<rmesh.size();i++){
			act += ham(0,i) * expo[i];
		}

		cout<<"act = "<<act/expo[0]<<endl;

		*/

		} //end loop over n
	
		vector <eigen_t> eig = initiate.real_eigvecs(skyham);

		for(int M=0;M<Nmax;M++){
			cout<<"M = "<<M<<endl;
			string Mlab;
			ostringstream convert;
			convert << M;
			Mlab = convert.str();

			cout<<"hameig = "<<hameig[M].first<<endl;

			string fname = "waves/eigvec" + llab + jlab + Mlab + ".txt";
			ofstream feig(fname.c_str());

			eigen_t dom_wf = initiate.find_boundstate(rmesh, Ef, M, L, J, tol);
			cout<<"bound energy = "<<dom_wf.first<<endl;

			string domname = "waves/dom" + llab + jlab + Mlab + ".txt";
			ofstream domfile(domname.c_str());

			double hnorm=0;
			for(int i=0;i<rmesh.size();i++){
				hnorm += pow(hameig[M].second[i],2) * rdelt;
			}

			for(int i=0;i<rmesh.size();i++){
				//domfile << rmesh[i] << " " << dom_wf.second[i]<< endl;
				domfile << rmesh[i] << " " << hameig[M].second[i]/rmesh[i]/sqrt(hnorm) << endl;
			}

			//the eigenvector is already normalized
			for(int i=0;i<Nmax;i++){
				feig << eig[M].second[i] << endl;
			}

			cout << "eigval = " << eig[M].first << endl;

			vector<double> qpf;
			qpf.assign(rmesh.size(),0);
		
			for(int j=0;j<Nmax;j++){
				vector<double> skyrme = sky1.read(N,L,J,presky,rmesh.size());
				for(int i=0;i<rmesh.size();i++){
					qpf[i] += eig[M].second[j] * skyrme[i];
				}
			}

			string qpname = "waves/qp" + llab + jlab + Mlab + ".txt";
			ofstream qpfile(qpname.c_str());
			string oname = "waves/overlap" + llab +jlab + Mlab + ".txt";
			ofstream ofile(oname.c_str());

			double norm=0;
			double overlap=0;

			for(int i=0;i<rmesh.size();i++){
				norm += pow(qpf[i],2) * rdelt;
			}

			double fac;
		
			if(qpf[10] < 0){
				fac = -1.0;
			}else{
				fac = 1.0;
			}


			for(int i=0;i<rmesh.size();i++){
				qpfile << rmesh[i] <<" "<< qpf[i] / sqrt(norm) / rmesh[i] * fac << endl;
				overlap += qpf[i] / sqrt(norm) * dom_wf.second[i] * rmesh[i] * rdelt;
			}

			cout << "overlap = " << overlap << endl;

		}

			
	} //end loop over J
} //end loop over L



}