Simpatico  v1.10
LinkLTPos.cpp
1 #ifndef LINK_LT_POS_CPP
2 #define LINK_LT_POS_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 "LinkLTPos.h"
12 #include <mcMd/simulation/Simulation.h>
13 #include <mcMd/links/LinkMaster.h>
14 #include <mcMd/chemistry/Molecule.h>
15 #include <mcMd/chemistry/Atom.h>
16 #include <simp/species/Species.h>
17 #include <simp/boundary/Boundary.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("LinkLTPos"); }
32 
34  void LinkLTPos::readParameters(std::istream& in)
35  {
36  readInterval(in);
38  read<int>(in, "linkCapacity", linkCapacity_);
39  readBegin(in,"Distribution");
40  read<double>(in, "min", min_);
41  read<double>(in, "max", max_);
42  read<int>(in, "nBin", nBin_);
43  readEnd(in);
44 
45  }
46 
47 
50  {
51  system().linkMaster().Notifier<LinkAddEvent>::registerObserver(*this);
52  system().linkMaster().Notifier<LinkRemoveEvent>::registerObserver(*this);
53  system().linkMaster().Notifier<ReSetAtomEvent>::registerObserver(*this);
54 
55  int i, j, chLength = system().simulation().species(0).nAtom();
56 
57  birthTimes_.allocate(2*linkCapacity_, chLength);
58 
59  //Allocate acumulator_ array.
60  accumulator_.allocate(chLength);
61 
62  for (i=0; i<chLength; ++i) {
63  accumulator_[i].setParam(min_, max_, nBin_);
64  }
65 
66  for (j=0; j<2*linkCapacity_; ++j) {
67  for (i=0; i<chLength; ++i) {
68  birthTimes_(j,i)=-1;
69  }
70  }
71 
72  }
73 
75  void LinkLTPos::sample(long iStep)
76  { }
77 
78  void LinkLTPos::update(const LinkAddEvent& event)
79  {
80  birthTimes_((event.get()->tag())*2,event.get()->atom0().indexInMolecule()) = system().simulation().iStep();
81  birthTimes_((event.get()->tag())*2+1,event.get()->atom1().indexInMolecule()) = system().simulation().iStep();
82  }
83 
84  void LinkLTPos::update(const LinkRemoveEvent& event)
85  {
86  int btime0, btime1, dtime, ltime;
87  int i,chLength = system().simulation().species(0).nAtom();
88  int le, le1;
89 
90  dtime = system().simulation().iStep();
91  le = (event.get()->tag())*2;
92  le1 = le+1;
93 
94  for (i=0; i<chLength; ++i){
95  btime0 = birthTimes_(le,i);
96  btime1 = birthTimes_(le1,i);
97  if (btime0!=-1) {
98  ltime = dtime - btime0;
99  birthTimes_(le,i) = -1;
100  accumulator_[i].sample((double)ltime);
101  }
102  if (btime1!=-1) {
103  ltime = dtime - btime1;
104  birthTimes_(le1,i) = -1;
105  accumulator_[i].sample((double)ltime);
106  }
107  }
108  }
109 
110  void LinkLTPos::update(const ReSetAtomEvent& event)
111  {
112 
113  int tag = event.getLink()->tag();
114  int idAtom0 = event.getLink()->atom0().indexInMolecule();
115  int idAtom1 = event.getLink()->atom1().indexInMolecule();
116  int end = event.getEndId();
117  int le;
118 
119  if (end==0) {
120  le = tag*2;
121  if (birthTimes_(le,idAtom0)==-1) {
122  birthTimes_(le,idAtom0) = system().simulation().iStep();
123  }
124  }
125  if (end==1) {
126  le = tag*2+1;
127  if (birthTimes_(le,idAtom1)==-1) {
128  birthTimes_(le,idAtom1) = system().simulation().iStep();
129  }
130  }
131 
132  }
133 
136  {
137 
138  // Echo parameters to a log file
139  fileMaster().openOutputFile(outputFileName(".prm"), outputFile_);
140  writeParam(outputFile_);
141  outputFile_.close();
142 
143  // Output data to separate data file
144  fileMaster().openOutputFile(outputFileName(".dat"), outputFile_);
145  int i, chLength = system().simulation().species(0).nAtom();
146  for (i=0; i<chLength; ++i) {
147  accumulator_[i].output(outputFile_);
148  outputFile_ << std::endl;
149  }
150  outputFile_.close();
151 
152  }
153 
154 }
155 #endif
virtual void output()
Output results to output file.
Definition: LinkLTPos.cpp:135
void allocate(int capacity1, int capacity2)
Allocate memory for a matrix.
Definition: DMatrix.h:170
int nAtom() const
Get number of atoms per molecule for this Species.
Event signalling the reset of an atom from the LinkMaster.
Definition: LinkEvents.h:105
Link * get() const
Get pointer to newly added Link.
Definition: LinkEvents.h:36
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
LinkLTPos(System &system)
Constructor.
Definition: LinkLTPos.cpp:29
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
System & system()
Return reference to parent system.
End & readEnd(std::istream &in)
Add and read the closing bracket.
File containing preprocessor macros for error handling.
Event signalling removal of a Link from the LinkMaster.
Definition: LinkEvents.h:78
Classes used by all simpatico molecular simulations.
void readOutputFileName(std::istream &in)
Read outputFileName from file.
void sample(long iStep)
Don&#39;t do anything.
Definition: LinkLTPos.cpp:75
Simulation & simulation() const
Get the parent Simulation by reference.
Definition: System.h:1055
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
Event signalling addition of Link to the LinkMaster.
Definition: LinkEvents.h:20
Template for Analyzer associated with one System.
virtual void setup()
Register Observer.
Definition: LinkLTPos.cpp:49
int iStep() const
Get value of step index for main MC or MD loop.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
virtual void readParameters(std::istream &in)
Read parameters from file.
Definition: LinkLTPos.cpp:34
void setClassName(const char *className)
Set class name string.
int indexInMolecule() const
Get local index for this Atom within the parent molecule;.
Begin & readBegin(std::istream &in, const char *label, bool isRequired=true)
Add and read a class label and opening bracket.
FileMaster & fileMaster()
Get the FileMaster by reference.
const std::string & outputFileName() const
Return outputFileName string.
Species & species(int i)
Get a specific Species by reference.
LinkMaster & linkMaster() const
Get the LinkMaster by reference.
Definition: System.h:1074