1 #ifndef UTIL_MEAN_SQ_DISP_ARRAY_H 2 #define UTIL_MEAN_SQ_DISP_ARRAY_H 12 #include <util/param/ParamComposite.h> 13 #include <util/containers/RingBuffer.h> 14 #include <util/containers/Array.h> 17 #include <util/accumulators/MeanSqDispArray.h> 18 #include <util/accumulators/setToZero.h> 19 #include <util/space/Vector.h> 20 #include <util/format/Int.h> 21 #include <util/format/Dbl.h> 40 template <
typename Data>
97 template <
class Archive>
98 void serialize(Archive& ar,
const unsigned int version);
125 void output(std::ostream& out);
131 {
return bufferCapacity_; }
137 {
return nEnsemble_; }
157 int ensembleCapacity_;
187 double sqDiff(
const Data& data1,
const Data& data2);
195 template <
typename Data>
200 ensembleCapacity_(0),
209 template <
typename Data>
216 template <
typename Data>
219 read<int>(in,
"ensembleCapacity", ensembleCapacity_);
220 read<int>(in,
"bufferCapacity", bufferCapacity_);
222 nEnsemble_ = ensembleCapacity_;
228 template <
typename Data>
232 ensembleCapacity_ = ensembleCapacity;
236 nEnsemble_ = ensembleCapacity;
242 template <
typename Data>
245 if (ensembleCapacity_ == 0)
246 UTIL_THROW(
"No memory has been allocated: ensembleCapacity_ == 0");
247 if (nEnsemble > ensembleCapacity_)
255 template <
typename Data>
258 loadParameter<int>(ar,
"ensembleCapacity", ensembleCapacity_);
259 loadParameter<int>(ar,
"bufferCapacity", bufferCapacity_);
270 template <
typename Data>
271 template <
class Archive>
274 ar & ensembleCapacity_;
275 ar & bufferCapacity_;
286 template <
typename Data>
293 template <
typename Data>
298 if (bufferCapacity_ > 0) {
301 for (i = 0; i < bufferCapacity_; ++i) {
306 for (i = 0; i < ensembleCapacity_; ++i) {
317 template <
typename Data>
320 if (bufferCapacity_ > 0) {
323 sqDiffSums_.
allocate(bufferCapacity_);
327 buffers_.allocate(ensembleCapacity_);
328 for (
int i=0; i < ensembleCapacity_; ++i) {
329 buffers_[i].allocate(bufferCapacity_);
339 template <
typename Data>
346 for (i = 0; i < nEnsemble_; ++i) {
347 buffers_[i].append(values[i]);
350 int bufferSize = buffers_[0].size();
351 for (j = 0; j < bufferSize; ++j) {
352 for (i = 0; i < nEnsemble_; ++i) {
353 sqDiffSums_[j] += sqDiff(buffers_[i][j], values[i]);
370 diff = data1 - data2;
371 return double(diff*diff);
385 diff = data1 - data2;
407 template <
typename Data>
413 int bufferSize = buffers_[0].size();
414 for (
int i = 0; i < bufferSize; ++i) {
415 msd = sqDiffSums_[i]/double(nValues_[i]*nEnsemble_);
416 out <<
Int(i) <<
Dbl(msd) << std::endl;
A Vector is a Cartesian vector.
void serialize(Archive &ar, const unsigned int version)
Serialize this MeanSqDispArray to/from an archive.
void sample(const Array< Data > &values)
Sample an array of current values.
Wrapper for a double precision number, for formatted ostream output.
Array container class template.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
int bufferCapacity()
Return capacity of the history buffer for each sequence.
Saving / output archive for binary ostream.
int nSample()
Return number of values sampled from each sequence thus far.
int nEnsemble()
Return number of sequences in the ensemble.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void readParameters(std::istream &in)
Read parameters, allocate memory and clear history.
void clear()
Reset to empty state.
void setToZero(int &value)
Set an int variable to zero.
Utility classes for scientific computation.
Wrapper for an int, for formatted ostream output.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Mean-squared displacement (MSD) vs.
Dynamically allocatable contiguous array template.
Saving archive for binary istream.
void setNEnsemble(int nEnsemble)
Set actual number of sequences in ensemble.
Vector & subtract(const Vector &v1, const Vector &v2)
Subtract vector v2 from v1.
void setClassName(const char *className)
Set class name string.
void allocate(int capacity)
Allocate the underlying C array.
An object that can read multiple parameters from file.
void setParam(int ensembleCapacity, int bufferCapacity)
Set parameters, allocate memory, and clear history.
void output(std::ostream &out)
Output the autocorrelation function.
double square() const
Return square magnitude of this vector.