Simpatico  v1.10
LinkLifeTime.cpp
1 #ifndef LINK_LIFE_TIME_CPP
2 #define LINK_LIFE_TIME_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 "LinkLifeTime.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("LinkLifeTime"); }
32 
34  void LinkLifeTime::readParameters(std::istream& in)
35  {
36  readInterval(in);
38  read<int>(in, "linkCapacity", linkCapacity_);
39  readParamComposite(in, accumulator_);
40  }
41 
42 
45  {
46  system().linkMaster().Notifier<LinkAddEvent>::registerObserver(*this);
47  system().linkMaster().Notifier<LinkRemoveEvent>::registerObserver(*this);
48  birthTimes_.allocate(linkCapacity_);
49  accumulator_.clear();
50  for (int i=0; i<linkCapacity_; ++i) {
51  birthTimes_[i]=-1;
52  }
53  }
54 
56  void LinkLifeTime::sample(long iStep)
57  { }
58 
59  void LinkLifeTime::update(const LinkAddEvent& event)
60  {
61  birthTimes_[event.get()->tag()] = system().simulation().iStep();
62  }
63 
64  void LinkLifeTime::update(const LinkRemoveEvent& event)
65  {
66  int btime, dtime, ltime;
67 
68  btime = birthTimes_[event.get()->tag()];
69  dtime = system().simulation().iStep();
70 
71  if (btime!=-1) {
72  ltime = dtime - btime;
73  birthTimes_[event.get()->tag()] = -1;
74  accumulator_.sample((double)ltime);
75  }
76 
77  }
78 
81  {
82 
83  // Echo parameters to a log file
84  fileMaster().openOutputFile(outputFileName(".prm"), outputFile_);
85  writeParam(outputFile_);
86  outputFile_.close();
87 
88  // Output data to separate data file
89  fileMaster().openOutputFile(outputFileName(".dat"), outputFile_);
90  accumulator_.output(outputFile_);
91  outputFile_.close();
92 
93  }
94 
95 }
96 #endif
virtual void output()
Output results to output file.
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.
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.
Simulation & simulation() const
Get the parent Simulation by reference.
Definition: System.h:1055
virtual void setup()
Register Observer.
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.
LinkLifeTime(System &system)
Constructor.
Event signalling addition of Link to the LinkMaster.
Definition: LinkEvents.h:20
virtual void readParameters(std::istream &in)
Read parameters from file.
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.
int iStep() const
Get value of step index for main MC or MD loop.
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.
FileMaster & fileMaster()
Get the FileMaster by reference.
const std::string & outputFileName() const
Return outputFileName string.
void allocate(int capacity)
Allocate the underlying C array.
Definition: DArray.h:191
LinkMaster & linkMaster() const
Get the LinkMaster by reference.
Definition: System.h:1074