Simpatico  v1.10
LinkLengthDist.cpp
1 #ifndef LINK_LENGTH_DIST_CPP
2 #define LINK_LENGTH_DIST_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 "LinkLengthDist.h"
12 #include <mcMd/simulation/Simulation.h>
13 #include <mcMd/links/LinkMaster.h>
14 #include <simp/species/Species.h>
15 #include <simp/boundary/Boundary.h>
16 #include <mcMd/chemistry/Molecule.h>
17 #include <mcMd/chemistry/Atom.h>
18 #include <util/misc/FileMaster.h>
19 
20 #include <util/global.h>
21 
22 namespace McMd
23 {
24 
25  using namespace Util;
26  using namespace Simp;
27 
30  : SystemAnalyzer<System>(system)
31  { setClassName("LinkLengthDist"); }
32 
34  void LinkLengthDist::readParameters(std::istream& in)
35  {
36  readInterval(in);
38  read<int>(in, "speciesId", speciesId_);
39  if (speciesId_ < 0) {
40  UTIL_THROW("Negative speciesId");
41  }
42  readParamComposite(in, accumulator_);
43  }
44 
45  /*
46  * Clear accumulator.
47  */
49  { accumulator_.clear(); }
50 
52  void LinkLengthDist::sample(long iStep)
53  {
54  if (isAtInterval(iStep)) {
55  Link link;
56  int nLinks0, idLink;
57  double lsq, l;
58 
59  // Go through all the links.
60  nLinks0 = system().linkMaster().nLink();
61  for (idLink=0; idLink < nLinks0; idLink++) {
62  link = system().linkMaster().link(idLink);
63  lsq = system().boundary().distanceSq(link.atom0().position(), link.atom1().position());
64  l = sqrt(lsq);
65  accumulator_.sample(l);
66  }
67 
68  }
69  }
70 
71 
74  {
75 
76  // Echo parameters to a log file
77  fileMaster().openOutputFile(outputFileName(".prm"), outputFile_);
78  writeParam(outputFile_);
79  outputFile_.close();
80 
81  // Output statistical analysis to separate data file
82  fileMaster().openOutputFile(outputFileName(".dat"), outputFile_);
83  accumulator_.output(outputFile_);
84  outputFile_.close();
85 
86  }
87 
88 }
89 #endif
int nLink() const
Get the total number of active Links.
Definition: LinkMaster.h:261
virtual void setup()
Clear accumulator.
virtual void readParameters(std::istream &in)
Read parameters from file.
double distanceSq(const Vector &r1, const Vector &r2) const
Return square distance between positions r1 and r2.
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
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
System & system()
Return reference to parent system.
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
virtual void output()
Output results to output file.
LinkLengthDist(System &system)
Constructor.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
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
void sample(double value)
Sample a value.
Template for Analyzer associated with one System.
void output(std::ostream &out)
Output the distribution to file.
virtual void clear()
Clear (i.e., zero) previously allocated histogram.
Boundary & boundary() const
Get the Boundary by reference.
Definition: System.h:1064
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void setClassName(const char *className)
Set class name string.
void readParamComposite(std::istream &in, ParamComposite &child, bool next=true)
Add and read a required child ParamComposite.
Link & link(int id) const
Return an active link by an internal set index.
Definition: LinkMaster.h:255
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.
void sample(long iStep)
Add particle pairs to LinkLengthDist histogram.
const Vector & position() const
Get the position Vector by const reference.
LinkMaster & linkMaster() const
Get the LinkMaster by reference.
Definition: System.h:1074