ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/ObjectCount.cpp
(Generate patch)

Comparing trunk/src/applications/staticProps/ObjectCount.cpp (file contents):
Revision 1513 by gezelter, Tue Oct 19 18:40:54 2010 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 35 | Line 35
35   *                                                                      
36   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37   * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 < * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 < * [4]  Vardeman & Gezelter, in progress (2009).                        
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39 > * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 > * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include <algorithm>
# Line 51 | Line 52 | namespace OpenMD {
52    ObjectCount::ObjectCount(SimInfo* info, const std::string& filename,
53                             const std::string& sele)
54      : StaticAnalyser(info, filename), selectionScript_(sele),
55 <      evaluator_(info), seleMan_(info)   {
55 >      seleMan_(info), evaluator_(info) {
56      
57      setOutputName(getPrefix(filename) + ".counts");
58      
# Line 62 | Line 63 | namespace OpenMD {
63      }            
64    }
65  
66 < void ObjectCount::process() {
67 <  Molecule* mol;
68 <  RigidBody* rb;
69 <  SimInfo::MoleculeIterator mi;
70 <  Molecule::RigidBodyIterator rbIter;
66 >  void ObjectCount::process() {
67 >    Molecule* mol;
68 >    RigidBody* rb;
69 >    SimInfo::MoleculeIterator mi;
70 >    Molecule::RigidBodyIterator rbIter;
71    
72 <  DumpReader reader(info_, dumpFilename_);    
73 <  int nFrames = reader.getNFrames();
74 <  for (int i = 0; i < nFrames; i += step_) {
75 <    reader.readFrame(i);
76 <    currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
72 >    counts_.clear();
73 >    counts_.resize(10, 0);
74 >    DumpReader reader(info_, dumpFilename_);    
75 >    int nFrames = reader.getNFrames();
76 >    unsigned long int nsum = 0;
77 >    unsigned long int n2sum = 0;
78 >
79 >    for (int i = 0; i < nFrames; i += step_) {
80 >      reader.readFrame(i);
81 >      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
82      
83 <    for (mol = info_->beginMolecule(mi); mol != NULL;
84 <         mol = info_->nextMolecule(mi)) {
85 <      //change the positions of atoms which belong to the rigidbodies
86 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
87 <           rb = mol->nextRigidBody(rbIter)) {
88 <        rb->updateAtoms();        
89 <      }      
90 <    }
83 >      for (mol = info_->beginMolecule(mi); mol != NULL;
84 >           mol = info_->nextMolecule(mi)) {
85 >        //change the positions of atoms which belong to the rigidbodies
86 >        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
87 >             rb = mol->nextRigidBody(rbIter)) {
88 >          rb->updateAtoms();        
89 >        }      
90 >      }
91      
92 <    if (evaluator_.isDynamic()) {
92 >      if (evaluator_.isDynamic()) {
93          seleMan_.setSelectionSet(evaluator_.evaluate());
94 <    }
94 >      }
95          
96 <    int count = 0;
91 <    int k;
96 >      unsigned int count = seleMan_.getSelectionCount();
97  
98 <    for (StuntDouble* sd = seleMan_.beginSelected(k);
99 <         sd != NULL; sd = seleMan_.nextSelected(k)) {
100 <      count++;
98 >      if (counts_.size() <= count)  {
99 >        counts_.resize(count, 0);
100 >      }
101 >
102 >      counts_[count]++;
103 >
104 >      nsum += count;
105 >      n2sum += count * count;
106      }
97    
98    if (counts_.size() < count) counts_.resize(count);
99    counts_[count]++;
100  }
107    
108 <  int nProcessed = nFrames /step_;
108 >    int nProcessed = nFrames /step_;
109  
110 <  vector<int>::iterator it;
111 <  unsigned long int n;
112 <  unsigned long int nsum = 0;
113 <  unsigned long int n2sum = 0;
108 <  for (it = counts_.begin(); it != counts_.end(); ++it) {
109 <    n = (*it);
110 <    nsum += n;
111 <    n2sum += n*n;
110 >    nAvg = nsum / nProcessed;
111 >    n2Avg = n2sum / nProcessed;
112 >    sDev = sqrt(n2Avg - nAvg*nAvg);
113 >    writeCounts();  
114    }
113
114  nAvg = nsum / nProcessed;
115  n2Avg = n2sum / nProcessed;
116  sDev = sqrt(n2Avg - nAvg*nAvg);
117  writeCounts();  
118 }
115    
116    void ObjectCount::writeCounts() {
117      std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
# Line 125 | Line 121 | void ObjectCount::process() {
121        ofs << "# <N> = "<< nAvg << "\n";
122        ofs << "# <N^2> = " << n2Avg << "\n";
123        ofs << "# sqrt(<N^2> - <N>^2)  = " << sDev << "\n";
124 <      ofs << "# N\tcount(N)\n";
124 >      ofs << "# N\tcounts[N]\n";
125 >      for (unsigned int i = 0; i < counts_.size(); ++i) {
126 >        ofs << i << "\t" << counts_[i] << "\n";
127 >      }
128        
130      for (int i = 0; i < counts_.size(); ++i) {
131        ofs << i <<"\t" << counts_[i]<< std::endl;
132      }        
129      } else {
130        
131 <      sprintf(painCave.errMsg, "ObjectCount: unable to open %s\n", outputFilename_.c_str());
131 >      sprintf(painCave.errMsg, "ObjectCount: unable to open %s\n",
132 >              outputFilename_.c_str());
133        painCave.isFatal = 1;
134        simError();  
135      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines