1 #ifndef MCMD_STRESS_AUTO_CORR_H 2 #define MCMD_STRESS_AUTO_CORR_H 11 #include <mcMd/analyzers/SystemAnalyzer.h> 12 #include <util/space/Tensor.h> 13 #include <util/accumulators/AutoCorrelation.tpp> 27 template <
class SystemType>
50 virtual void readParameters(std::istream& in);
72 template <
class Archive>
73 void serialize(Archive& ar,
const unsigned int version);
85 virtual void sample(
long iStep);
90 virtual void output();
99 virtual void computeStress(
Tensor& stress) = 0;
115 std::ofstream outputFile_;
137 template <
class SystemType>
145 isInitialized_(false)
151 template <
class SystemType>
158 template <
class SystemType>
163 read(in,
"capacity", capacity_);
166 accumulator_.
setParam(capacity_, maxStageId_, blockFactor_);
167 accumulator_.
clear();
169 isInitialized_ =
true;
175 template <
class SystemType>
183 if (accumulator_.bufferCapacity() != capacity_) {
184 UTIL_THROW(
"Inconsistent values of capacity");
187 isInitialized_ =
true;
193 template <
class SystemType>
201 template <
class SystemType>
202 template <
class Archive>
205 const unsigned int version)
215 template <
class SystemType>
218 if (!isInitialized_) {
221 accumulator_.
clear();
227 template <
class SystemType>
237 system().computeVirialStress(virial);
238 system().computeKineticStress(kinetic);
239 total.
add(virial, kinetic);
246 double pressure = 0.0;
249 pressure += stress(i,i);
251 pressure = pressure/double(Dimension);
253 stress(i,i) -= pressure;
256 double factor = 1.0/sqrt(10.0);
259 stress(i,j) *= factor;
263 accumulator_.
sample(stress);
270 template <
class SystemType>
276 outputFile_ << std::endl;
277 outputFile_ <<
"bufferCapacity " 279 outputFile_ <<
"nSample " 280 << accumulator_.
nSample() << std::endl;
281 outputFile_ << std::endl;
286 accumulator_.
output(outputFile_);
const int Dimension
Dimensionality of space.
virtual ~StressAutoCorr()
Destructor.
Compute stress autocorrelation for an isotropic system.
virtual void computeStress(Tensor &stress)=0
Compute total stress tensor.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
virtual void loadParameters(Serializable::IArchive &ar)
Load parameters from archive.
SystemType & system()
Return reference to parent system.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
void clear()
Clear accumulators and destroy descendants.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
void serialize(Archive &ar, PairSelector &selector, const unsigned int version)
Serialize a PairSelector.
virtual void setup()
Setup before beginning of loop.
A Tensor represents a Cartesian tensor.
Tensor & add(const Tensor &t1, const Tensor &t2)
Add tensors t1 and t2.
void output(std::ostream &out)
Output the autocorrelation function, assuming zero mean.
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
virtual void writeParam(std::ostream &out)
Write all parameters to an output stream.
void readInterval(std::istream &in)
Read interval from file, with error checking.
Utility classes for scientific computation.
void setParam(int bufferCapacity=64, int maxStageId=0, int blockFactor=2)
Set all parameters and allocate to initialize state.
StressAutoCorr(SystemType &system)
Constructor.
ScalarParam< Type > & loadParameter(Serializable::IArchive &ar, const char *label, Type &value, bool isRequired)
Add and load a new ScalarParam < Type > object.
long nSample() const
Return the number of sampled values.
Template for Analyzer associated with one System.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
virtual void sample(long iStep)
Sample stress tensor and add to accumulator.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int bufferCapacity() const
Return capacity of history buffer.
FileMaster & fileMaster()
Get the FileMaster by reference.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
const std::string & outputFileName() const
Return outputFileName string.
virtual void sample(Data value)
Sample a value.
ScalarParam< Type > & read(std::istream &in, const char *label, Type &value)
Add and read a new required ScalarParam < Type > object.
virtual void output()
Output results to file (parameters and autocorrelation function).
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.