8 #include "RadialDistribution.h" 9 #include <util/math/feq.h> 10 #include <util/format/Int.h> 11 #include <util/format/Dbl.h> 23 outputIntegral_(false)
32 nSnapshot_(other.nSnapshot_),
33 outputIntegral_(other.outputIntegral_)
47 nSnapshot_ = other.nSnapshot_;
58 read<double>(in,
"max",
max_);
59 read<int>(in,
"nBin",
nBin_);
84 loadParameter<double>(ar,
"max",
max_);
85 loadParameter<int>(ar,
"nBin",
nBin_);
94 UTIL_THROW(
"Inconsistent value for binWidth_");
96 if (
nBin_ != histogram_.capacity()) {
132 { outputIntegral_ = outputIntegral; }
139 double r, rho, prefactor, dV, hist, integral;
140 prefactor = 4.0*3.14159265359/3.0;
143 for (
int i=0; i <
nBin_; ++i) {
144 r = binWidth_*(double(i) + 0.5);
145 dV = prefactor*double(3*i*i + 3*i + 1);
146 hist = double(
histogram_[i])/double(nSnapshot_);
147 rho = hist/(dV*norm_);
148 out <<
Dbl(r, 18, 8) <<
Dbl(rho, 18, 8);
149 if (outputIntegral_) {
150 integral += (hist - dV*norm_)/norm_;
151 out << Dbl(integral, 18, 8);
void setParam(double max, int nBin)
Set parameters and initialize.
double max_
maximum value.
void output(std::ostream &out)
Output the distribution to file.
int nSample_
Number of sampled values in Histogram.
Wrapper for a double precision number, for formatted ostream output.
void setOutputIntegral(bool outputIntegral)
Set true to enable output of spatial integral of g(r).
RadialDistribution()
Default constructor.
double min_
minimum value.
Saving / output archive for binary ostream.
void setNorm(double norm)
Set the factor used to normalize the RDF before output.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
double binWidth_
width of bin = (max_-min_)/nBin_ .
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void beginSnapshot()
Mark the beginning of a "snapshot" (i.e., a sampled time step).
Utility classes for scientific computation.
Distribution & operator=(const Distribution &other)
Assignment operator.
RadialDistribution & operator=(const RadialDistribution &other)
Assignment.
virtual void clear()
Clear (i.e., zero) previously allocated histogram.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
DArray< long > histogram_
Histogram of occurences, one element per bin.
Saving archive for binary istream.
int nReject_
Number of sampled values that were out of range.
virtual void readParameters(std::istream &in)
Read values of min, max, and nBin from file.
int nBin() const
Get the number of bins.
void setClassName(const char *className)
Set class name string.
Distribution (or histogram) of values for particle separations.
virtual void clear()
Clear all accumulators.
void allocate(int capacity)
Allocate the underlying C array.
A distribution (or histogram) of values for a real variable.
bool feq(double x, double y, double eps=1.0E-10)
Are two floating point numbers equal to within round-off error?
double max() const
Get maximum value in range of histogram.