예제 #1
0
파일: box.cpp 프로젝트: trisyoungs/duq
// Calculate the RDF normalisation for the Box
bool Box::calculateRDFNormalisation(ProcessPool& procPool, Data2D& boxNorm, double rdfRange, double rdfBinWidth, int nPoints) const
{
	// Setup array - we will use a nominal bin width of 0.1 Angstroms and then interpolate to the rdfBinWidth afterwards
	const double binWidth = 0.1;
	const double rBinWidth = 1.0/binWidth;
	int bin, nBins = rdfRange / binWidth;
	Data2D normData;
	normData.initialise(nBins);
	Array<double>& y = normData.arrayY();
	for (int n=0; n<nBins; ++n) normData.arrayX()[n] = (n+0.5)*binWidth;
	
	Vec3<double> centre = axes_*Vec3<double>(0.5,0.5,0.5);

	// Divide points over processes
	const int nPointsPerProcess = nPoints / procPool.nProcesses();
	Messenger::print("--> Number of insertion points (per process) is %i\n", nPointsPerProcess);
	y = 0.0;
	for (int n=0; n<nPointsPerProcess; ++n)
	{
		bin = (randomCoordinate() - centre).magnitude() * rBinWidth;
		if (bin < nBins) y[bin] += 1.0;
	}
	if (!procPool.allSum(y.array(), nBins)) return false;

	// Normalise histogram data, and scale by volume and binWidth ratio
	y /= double(nPointsPerProcess*procPool.nProcesses());
	y *= volume_ * (rdfBinWidth / binWidth);
	normData.interpolate();

	// Write histogram data for random distribution
	if (procPool.isMaster()) normData.save("duq.box.random");
	
	// Now we have the interpolated data, create the proper interpolated data
	nBins = rdfRange/rdfBinWidth;
	boxNorm.clear();

	// Rescale against expected volume for spherical shells
	double shellVolume, r = 0.0, maxHalf = inscribedSphereRadius(), x = 0.5*rdfBinWidth;
	for (int n=0; n<nBins; ++n)
	{
		// We know that up to the maximum (orthogonal) half-cell width the normalisation should be exactly 1.0...
		if (x < maxHalf) boxNorm.addPoint(x, 1.0);
		else
		{
			shellVolume = (4.0/3.0)*PI*(pow(r+rdfBinWidth,3.0) - pow(r,3.0));
			boxNorm.addPoint(x,  shellVolume / normData.interpolated(x));
// 			boxNorm[n] = normData.interpolated(r);
		}
		r += rdfBinWidth;
		x += rdfBinWidth;
	}
	
	// Interpolate normalisation array
	boxNorm.interpolate();

	// Write final box normalisation file
	if (procPool.isMaster()) boxNorm.save("duq.box.norm");

	return true;
}
예제 #2
0
/*!
 * \brief Smooth data
 */
void Data2D::smooth(int avgSize, int skip)
{
	// First, create a new dataset using Y-averages of the current data
	Data2D avg;
	double y;
	int n, m, i = avgSize/2;
	for (n=i; n < x_.nItems()-i; n += (1+skip))
	{
		y = 0.0;
		for (m=n-i; m <= n+i; ++m) y += y_[m];
		y /= avgSize;
		
		avg.addPoint(x_[n], y);
	}

	avg.interpolate();

	// Now go through old data, setting new Y values from the interpolation
	for (n=0; n<x_.nItems(); ++n) y_[n] = avg.interpolated(x_[n]);
}
예제 #3
0
/*!
 * \brief Subtract interpolated data
 */
void Data2D::subtractInterpolated(Data2D& source)
{
	for (int n=0; n<x_.nItems(); ++n) addY(n, -source.interpolated(x_.value(n)));
}