Simpatico  v1.10
NLinkAverage.cpp
1 #ifndef NLINK_AVERAGE_CPP
2 #define NLINK_AVERAGE_CPP
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2014, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include "NLinkAverage.h"
12 #include <mcMd/simulation/Simulation.h>
13 #include <mcMd/links/LinkMaster.h>
14 #include <util/misc/FileMaster.h>
15 
16 
17 namespace McMd
18 {
19 
20  using namespace Util;
21 
24  : SystemAnalyzer<System>(system)
25  { setClassName("NLinkAverage"); }
26 
28  void NLinkAverage::readParameters(std::istream& in)
29  {
30  readInterval(in);
32  read<int>(in,"nSamplePerBlock", nSamplePerBlock_);
33 
34  accumulator_.setNSamplePerBlock(nSamplePerBlock_);
35 
36  // If nSamplePerBlock != 0, open an output file for block averages.
37  if (accumulator_.nSamplePerBlock()) {
38  fileMaster().openOutputFile(outputFileName(".dat"), outputFile_);
39  }
40  }
41 
42  /*
43  * Clear accumulator.
44  */
46  { accumulator_.clear(); }
47 
49  void NLinkAverage::sample(long iStep)
50  {
51  if (isAtInterval(iStep)) {
52  double rn = (double) system().linkMaster().nLink();
53  accumulator_.sample(rn, outputFile_);
54  }
55  }
56 
57  /*
58  * Output results to file after simulation is completed.
59  */
61  {
62  // If outputFile_ was used to write block averages, close it.
63  if (accumulator_.nSamplePerBlock()) {
64  outputFile_.close();
65  }
66 
67  // Write parameters to file
68  fileMaster().openOutputFile(outputFileName(".prm"), outputFile_);
69  ParamComposite::writeParam(outputFile_);
70  outputFile_.close();
71 
72  // Write average to file
73  fileMaster().openOutputFile(outputFileName(".ave"), outputFile_);
74  accumulator_.output(outputFile_);
75  outputFile_.close();
76  }
77 
78 }
79 #endif
int nLink() const
Get the total number of active Links.
Definition: LinkMaster.h:261
void clear()
Clear all accumulators, set to empty initial state.
Definition: Average.cpp:42
virtual void readParameters(std::istream &in)
Read parameters from file, and allocate data array.
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
Definition: FileMaster.cpp:290
virtual void setup()
Clear accumulator.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
System & system()
Return reference to parent system.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
virtual void output()
Output results at end of simulation.
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.
Definition: accumulators.mod:1
Template for Analyzer associated with one System.
void output(std::ostream &out) const
Output final statistical properties to file.
Definition: Average.cpp:178
void setNSamplePerBlock(int nSamplePerBlock)
Set nSamplePerBlock.
Definition: Average.cpp:63
virtual void sample(long iStep)
Evaluate squared radii of gyration for all molecules, add to ensemble.
NLinkAverage(System &system)
Constructor.
void sample(double value)
Add a sampled value to the ensemble.
Definition: Average.cpp:94
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSamplePerBlock() const
Get number of samples per block average.
Definition: Average.h:220
void setClassName(const char *className)
Set class name string.
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.
LinkMaster & linkMaster() const
Get the LinkMaster by reference.
Definition: System.h:1074