1 #ifndef MCMD_STRESS_TENSOR_AVERAGE_H 2 #define MCMD_STRESS_TENSOR_AVERAGE_H 11 #include <mcMd/analyzers/SystemAnalyzer.h> 12 #include <util/space/Tensor.h> 13 #include <util/accumulators/Average.h> 25 template <
class SystemType>
49 virtual void readParameters(std::istream& in);
71 template <
class Archive>
72 void serialize(Archive& ar,
const unsigned int version);
89 virtual void sample(
long iStep);
94 virtual void output();
99 std::ofstream outputFile_;
129 int nSamplePerBlock_;
149 template <
class SystemType>
163 isInitialized_(false)
169 template <
class SystemType>
174 read<int>(in,
"nSamplePerBlock", nSamplePerBlock_);
186 std::string filename;
190 isInitialized_ =
true;
196 template <
class SystemType>
200 loadParameter<int>(ar,
"nSamplePerBlock", nSamplePerBlock_);
212 if (nSamplePerBlock_) {
215 isInitialized_ =
true;
221 template <
class SystemType>
229 template <
class SystemType>
232 if (!isInitialized_) {
236 sxxAccumulator_.
clear();
237 sxyAccumulator_.
clear();
238 sxzAccumulator_.
clear();
239 syxAccumulator_.
clear();
240 syyAccumulator_.
clear();
241 syzAccumulator_.
clear();
242 szxAccumulator_.
clear();
243 szyAccumulator_.
clear();
244 szzAccumulator_.
clear();
250 template <
class SystemType>
261 sys.computeVirialStress(total);
262 sys.computeKineticStress(kinetic);
263 total.
add(virial, kinetic);
265 sxxAccumulator_.
sample(total(0,0));
266 sxyAccumulator_.
sample(total(0,1));
267 sxzAccumulator_.
sample(total(0,2));
268 syxAccumulator_.
sample(total(1,0));
269 syyAccumulator_.
sample(total(1,1));
270 syzAccumulator_.
sample(total(1,2));
271 szxAccumulator_.
sample(total(2,0));
272 szyAccumulator_.
sample(total(2,1));
273 szzAccumulator_.
sample(total(2,2));
280 template <
class SystemType>
284 "Sxx=" <<
Dbl(sxxAccumulator_.
average(), 17)<<
" +- " <<
Dbl(sxxAccumulator_.
error(), 9, 8) <<
"\n" <<
285 "Sxy=" <<
Dbl(sxyAccumulator_.
average(), 17)<<
" +- " <<
Dbl(sxyAccumulator_.
error(), 9, 8) <<
"\n" <<
286 "Sxz=" <<
Dbl(sxzAccumulator_.
average(), 17)<<
" +- " <<
Dbl(sxzAccumulator_.
error(), 9, 8) <<
"\n" <<
287 "Syx=" <<
Dbl(syxAccumulator_.
average(), 17)<<
" +- " <<
Dbl(syxAccumulator_.
error(), 9, 8) <<
"\n" <<
288 "Syy=" <<
Dbl(syyAccumulator_.
average(), 17)<<
" +- " <<
Dbl(syyAccumulator_.
error(), 9, 8) <<
"\n" <<
289 "Syz=" <<
Dbl(syzAccumulator_.
average(), 17)<<
" +- " <<
Dbl(syzAccumulator_.
error(), 9, 8) <<
"\n" <<
290 "Szx=" <<
Dbl(szxAccumulator_.
average(), 17)<<
" +- " <<
Dbl(szxAccumulator_.
error(), 9, 8) <<
"\n" <<
291 "Szy=" <<
Dbl(szyAccumulator_.
average(), 17)<<
" +- " <<
Dbl(szyAccumulator_.
error(), 9, 8) <<
"\n" <<
292 "Szz=" <<
Dbl(szzAccumulator_.
average(), 17)<<
" +- " <<
Dbl(szzAccumulator_.
error(), 9, 8) <<
"\n" <<
void clear()
Clear all accumulators, set to empty initial state.
StressTensorAverage(SystemType &system)
Constructor.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Calculates the average and variance of a sampled property.
double average() const
Return the average of all sampled values.
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.
Wrapper for a double precision number, for formatted ostream output.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
void serialize(Archive &ar, PairSelector &selector, const unsigned int version)
Serialize a PairSelector.
A Tensor represents a Cartesian tensor.
Tensor & add(const Tensor &t1, const Tensor &t2)
Add tensors t1 and t2.
Saving / output archive for binary ostream.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
virtual void sample(long iStep)
Sample virial stress components to accumulators.
Periodically write (tensor) StressTensor to file.
virtual void output()
Output final results to file.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void readInterval(std::istream &in)
Read interval from file, with error checking.
Utility classes for scientific computation.
virtual void clear()
Clear nSample counter.
Template for Analyzer associated with one System.
void setNSamplePerBlock(int nSamplePerBlock)
Set nSamplePerBlock.
Saving archive for binary istream.
void sample(double value)
Add a sampled value to the ensemble.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
virtual void readParameters(std::istream &in)
Read dumpPrefix and interval.
FileMaster & fileMaster()
Get the FileMaster by reference.
bool isAtInterval(long counter) const
Return true iff counter is a multiple of the interval.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
const std::string & outputFileName() const
Return outputFileName string.
virtual ~StressTensorAverage()
Destructor.
double error() const
Return a naive estimate for the std deviation of the average.