EwaldPeriodic(const matrix3<>& R, int nAtoms)
	: R(R), G((2*M_PI)*inv(R)), RTR((~R)*R), GGT(G*(~G))
	{	logPrintf("\n---------- Setting up ewald sum ----------\n");
		//Determine optimum gaussian width for Ewald sums:
		// From below, the number of reciprocal cells ~ Prod_k |R.column[k]|
		//    and number of real space cells ~ Prod_k |G.row[k]|
		// including the fact that the real space cost ~ Natoms^2/cell
		//    and the reciprocal space cost ~ Natoms/cell
		sigma = 1.;
		for(int k=0; k<3; k++)
			sigma *= R.column(k).length() / G.row(k).length();
		sigma = pow(sigma/std::max(1,nAtoms), 1./6);
		logPrintf("Optimum gaussian width for ewald sums = %lf bohr.\n", sigma);
		
		//Carry real space sums to Rmax = 10 sigma and Gmax = 10/sigma
		//This leads to relative errors ~ 1e-22 in both sums, well within double precision limits
		for(int k=0; k<3; k++)
		{	Nreal[k] = 1+ceil(CoulombKernel::nSigmasPerWidth * G.row(k).length() * sigma / (2*M_PI));
			Nrecip[k] = 1+ceil(CoulombKernel::nSigmasPerWidth * R.column(k).length() / (2*M_PI*sigma));
		}
		logPrintf("Real space sum over %d unit cells with max indices ", (2*Nreal[0]+1)*(2*Nreal[1]+1)*(2*Nreal[2]+1));
		Nreal.print(globalLog, " %d ");
		logPrintf("Reciprocal space sum over %d terms with max indices ", (2*Nrecip[0]+1)*(2*Nrecip[1]+1)*(2*Nrecip[2]+1));
		Nrecip.print(globalLog, " %d ");
	}
Beispiel #2
0
void Basis::setup(const GridInfo& gInfo, const IonInfo& iInfo, double Ecut, const vector3<> k)
{	//Find the indices within Ecut:
	vector3<int> iGbox; for(int i=0; i<3; i++) iGbox[i] = 1 + int(sqrt(2*Ecut) * gInfo.R.column(i).length() / (2*M_PI));
	std::vector< vector3<int> > iGvec;
	std::vector<int> indexVec;
	vector3<int> iG;
	for(iG[0]=-iGbox[0]; iG[0]<=iGbox[0]; iG[0]++)
		for(iG[1]=-iGbox[1]; iG[1]<=iGbox[1]; iG[1]++)
			for(iG[2]=-iGbox[2]; iG[2]<=iGbox[2]; iG[2]++)
				if(0.5*dot(iG+k, gInfo.GGT*(iG+k)) <= Ecut)
				{	iGvec.push_back(iG);
					indexVec.push_back(gInfo.fullGindex(iG));
				}
	setup(gInfo, iInfo, indexVec, iGvec);
	logPrintf("nbasis = %lu for k = ", nbasis); k.print(globalLog, " %6.3f ");
}