Simpatico  v1.10
InterIntraLink.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2014, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "InterIntraLink.h"
9 #include <mcMd/simulation/Simulation.h>
10 #include <mcMd/links/LinkMaster.h>
11 #include <util/misc/FileMaster.h>
12 #include <mcMd/chemistry/Molecule.h>
13 #include <mcMd/chemistry/Atom.h>
14 
15 
16 namespace McMd
17 {
18 
19  using namespace Util;
20 
23  : SystemAnalyzer<System>(system)
24  { setClassName("InterIntraLink"); }
25 
27  void InterIntraLink::readParameters(std::istream& in)
28  {
29  readInterval(in);
31  //read<int>(in,"nSamplePerBlock", nSamplePerBlock_);
32 
33  nSamplePerBlock_ = 0;
34  accumulatorInter_.setNSamplePerBlock(nSamplePerBlock_);
35  accumulatorIntra_.setNSamplePerBlock(nSamplePerBlock_);
36 
37  // If nSamplePerBlock != 0, open an output file for block averages.
38  if (nSamplePerBlock_ != 0) {
39  fileMaster().openOutputFile(outputFileName(".dat"), outputFile_);
40  }
41 
42  }
43 
44  /*
45  * Clear accumulator.
46  */
48  { accumulatorInter_.clear();
49  accumulatorIntra_.clear();
50  }
51 
53  void InterIntraLink::sample(long iStep)
54  {
55  int interLink, intraLink;
56  int nLink, iLink, iMol0, iMol1;
57  Link* linkPtr;
58  Atom *atom0Ptr, *atom1Ptr;
59  Molecule *mol0Ptr, *mol1Ptr;
60 
61  if (isAtInterval(iStep)) {
62 
63  interLink = 0;
64  intraLink = 0;
65 
66  nLink = system().linkMaster().nLink();
67  for (iLink = 0; iLink < nLink ; ++iLink) {
68  linkPtr = &(system().linkMaster().link(iLink));
69  atom0Ptr = &(linkPtr->atom0());
70  atom1Ptr = &(linkPtr->atom1());
71  mol0Ptr = &atom0Ptr->molecule();
72  mol1Ptr = &atom1Ptr->molecule();
73  iMol0 = system().moleculeId(*mol0Ptr);
74  iMol1 = system().moleculeId(*mol1Ptr);
75  if (iMol0==iMol1) {
76  intraLink+=1;
77  }
78  else {
79  interLink+=1;
80  }
81  }
82  accumulatorInter_.sample(interLink, outputFile_);
83  accumulatorIntra_.sample(intraLink, outputFile_);
84  }
85  }
86 
87  /*
88  * Output results to file after simulation is completed.
89  */
91  {
92  // If outputFile_ was used to write block averages, close it.
93  if (nSamplePerBlock_ != 0) {
94  outputFile_.close();
95  }
96 
97  // Write parameters to file
98  fileMaster().openOutputFile(outputFileName(".prm"), outputFile_);
99  ParamComposite::writeParam(outputFile_);
100  outputFile_.close();
101 
102  // Write average to file
103  fileMaster().openOutputFile(outputFileName(".ave"), outputFile_);
104  outputFile_ << "Average number of intermolecular links: " << std::endl;
105  accumulatorInter_.output(outputFile_);
106  outputFile_ << std::endl;
107  outputFile_ << "Average number of intramolecular links: " << std::endl;
108  accumulatorIntra_.output(outputFile_);
109  outputFile_.close();
110  }
111 
112 }
int nLink() const
Get the total number of active Links.
Definition: LinkMaster.h:261
Molecule & molecule() const
Get the parent Molecule by reference.
void clear()
Clear all accumulators, set to empty initial state.
Definition: Average.cpp:42
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.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
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.
A point particle within a Molecule.
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
void sample(double value)
Add a sampled value to the ensemble.
Definition: Average.cpp:94
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
void setClassName(const char *className)
Set class name string.
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.
A physical molecule (a set of covalently bonded Atoms).
int moleculeId(const Molecule &molecule) const
Get the index of a Molecule within its Species in this System.
Definition: System.cpp:1189
LinkMaster & linkMaster() const
Get the LinkMaster by reference.
Definition: System.h:1074