ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/RNEMDStats.cpp
Revision: 1882
Committed: Tue Jun 18 16:10:07 2013 UTC (11 years, 10 months ago) by gezelter
File size: 9221 byte(s)
Log Message:
Minor bug

File Contents

# User Rev Content
1 gezelter 1865 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9     * 1. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     *
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
28     * arising out of the use of or inability to use software, even if the
29     * University of Notre Dame has been advised of the possibility of
30     * such damages.
31     *
32     * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33     * research, please cite the appropriate papers when you publish your
34     * work. Good starting points are:
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, 234107 (2008).
39     * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     */
41    
42    
43     #include <algorithm>
44     #include <fstream>
45     #include "applications/staticProps/RNEMDStats.hpp"
46 gezelter 1881 #include "primitives/Molecule.hpp"
47 gezelter 1865 #include "utils/PhysicalConstants.hpp"
48    
49     namespace OpenMD {
50    
51     RNEMDZ::RNEMDZ(SimInfo* info, const std::string& filename,
52     const std::string& sele, int nzbins)
53     : SlabStatistics(info, filename, sele, nzbins) {
54    
55     setOutputName(getPrefix(filename) + ".rnemdZ");
56    
57     temperature = new OutputData;
58     temperature->units = "K";
59     temperature->title = "Temperature";
60     temperature->dataType = odtReal;
61     temperature->dataHandling = odhAverage;
62     temperature->accumulator.reserve(nBins_);
63     for (int i = 0; i < nBins_; i++)
64     temperature->accumulator.push_back( new Accumulator() );
65     data_.push_back(temperature);
66    
67     velocity = new OutputData;
68     velocity->units = "angstroms/fs";
69     velocity->title = "Velocity";
70     velocity->dataType = odtVector3;
71     velocity->dataHandling = odhAverage;
72     velocity->accumulator.reserve(nBins_);
73     for (int i = 0; i < nBins_; i++)
74     velocity->accumulator.push_back( new VectorAccumulator() );
75     data_.push_back(velocity);
76    
77     density = new OutputData;
78     density->units = "g cm^-3";
79     density->title = "Density";
80     density->dataType = odtReal;
81     density->dataHandling = odhAverage;
82     density->accumulator.reserve(nBins_);
83     for (int i = 0; i < nBins_; i++)
84     density->accumulator.push_back( new Accumulator() );
85     data_.push_back(density);
86     }
87    
88 gezelter 1881 void RNEMDZ::processFrame(int istep) {
89     Molecule* mol;
90     RigidBody* rb;
91     StuntDouble* sd;
92     SimInfo::MoleculeIterator mi;
93     Molecule::RigidBodyIterator rbIter;
94     int i;
95 gezelter 1865
96 gezelter 1881 vector<RealType> binMass(nBins_, 0.0);
97     vector<Vector3d> binVel(nBins_, V3Zero);
98     vector<RealType> binKE(nBins_, 0.0);
99     vector<int> binDof(nBins_, 0);
100     vector<int> binCount(nBins_, 0);
101    
102    
103     for (mol = info_->beginMolecule(mi); mol != NULL;
104     mol = info_->nextMolecule(mi)) {
105    
106     // change the positions of atoms which belong to the rigidbodies
107    
108     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
109     rb = mol->nextRigidBody(rbIter)) {
110     rb->updateAtoms();
111 gezelter 1865 }
112     }
113    
114 gezelter 1881 if (evaluator_.isDynamic()) {
115     seleMan_.setSelectionSet(evaluator_.evaluate());
116     }
117 gezelter 1865
118 gezelter 1881 // loop over the selected atoms:
119    
120     for (sd = seleMan_.beginSelected(i); sd != NULL;
121     sd = seleMan_.nextSelected(i)) {
122    
123     // figure out where that object is:
124     Vector3d pos = sd->getPos();
125     currentSnapshot_->wrapVector(pos);
126 gezelter 1865
127 gezelter 1881 int bin = getBin(pos);
128     binCount[bin]++;
129    
130     RealType m = sd->getMass();
131     binMass[bin] += m;
132     Vector3d vel = sd->getVel();
133     binVel[bin] += vel;
134     binKE[bin] += 0.5 * (m * vel.lengthSquare());
135     binDof[bin] += 3;
136    
137     if (sd->isDirectional()) {
138     Vector3d angMom = sd->getJ();
139     Mat3x3d I = sd->getI();
140     if (sd->isLinear()) {
141     int i = sd->linearAxis();
142     int j = (i + 1) % 3;
143     int k = (i + 2) % 3;
144     binKE[bin] += 0.5 * (angMom[j] * angMom[j] / I(j, j) +
145     angMom[k] * angMom[k] / I(k, k));
146     binDof[bin] += 2;
147     } else {
148     binKE[bin] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) +
149     angMom[1] * angMom[1] / I(1, 1) +
150     angMom[2] * angMom[2] / I(2, 2));
151     binDof[bin] += 3;
152     }
153     }
154     }
155    
156     for (int i = 0; i < nBins_; i++) {
157 gezelter 1882 if (binDof[i] > 0) {
158     RealType temp = 2.0 * binKE[i] / (binDof[i] * PhysicalConstants::kb *
159     PhysicalConstants::energyConvert);
160     RealType den = binMass[i] * nBins_ * PhysicalConstants::densityConvert
161     / volume_;
162     Vector3d vel = binVel[i] / RealType(binCount[i]);
163     dynamic_cast<Accumulator *>(temperature->accumulator[i])->add(temp);
164     dynamic_cast<VectorAccumulator *>(velocity->accumulator[i])->add(vel);
165     dynamic_cast<Accumulator *>(density->accumulator[i])->add(den);
166     dynamic_cast<Accumulator *>(counts_->accumulator[i])->add(1);
167     }
168 gezelter 1881 }
169 gezelter 1865 }
170 gezelter 1881
171     void RNEMDZ::processStuntDouble(StuntDouble* sd, int bin) {
172     }
173 gezelter 1865
174     RNEMDR::RNEMDR(SimInfo* info, const std::string& filename,
175     const std::string& sele, int nrbins)
176     : ShellStatistics(info, filename, sele, nrbins) {
177    
178    
179     setOutputName(getPrefix(filename) + ".rnemdR");
180    
181     temperature = new OutputData;
182     temperature->units = "K";
183     temperature->title = "Temperature";
184     temperature->dataType = odtReal;
185     temperature->dataHandling = odhAverage;
186     temperature->accumulator.reserve(nBins_);
187     for (int i = 0; i < nBins_; i++)
188     temperature->accumulator.push_back( new Accumulator() );
189     data_.push_back(temperature);
190    
191     angularVelocity = new OutputData;
192     angularVelocity->units = "angstroms^2/fs";
193     angularVelocity->title = "Velocity";
194     angularVelocity->dataType = odtVector3;
195     angularVelocity->dataHandling = odhAverage;
196     angularVelocity->accumulator.reserve(nBins_);
197     for (int i = 0; i < nBins_; i++)
198     angularVelocity->accumulator.push_back( new VectorAccumulator() );
199     data_.push_back(angularVelocity);
200    
201     density = new OutputData;
202     density->units = "g cm^-3";
203     density->title = "Density";
204     density->dataType = odtReal;
205     density->dataHandling = odhAverage;
206     density->accumulator.reserve(nBins_);
207     for (int i = 0; i < nBins_; i++)
208     density->accumulator.push_back( new Accumulator() );
209     data_.push_back(density);
210     }
211    
212     void RNEMDR::processStuntDouble(StuntDouble* sd, int bin) {
213     RealType mass = sd->getMass();
214     Vector3d vel = sd->getVel();
215     Vector3d rPos = sd->getPos() - coordinateOrigin_;
216     Vector3d aVel = cross(rPos, vel);
217    
218     RealType KE = 0.5 * (mass * vel.lengthSquare());
219     int dof = 3;
220    
221     if (sd->isDirectional()) {
222     Vector3d angMom = sd->getJ();
223     Mat3x3d I = sd->getI();
224     if (sd->isLinear()) {
225     int i = sd->linearAxis();
226     int j = (i + 1) % 3;
227     int k = (i + 2) % 3;
228     KE += 0.5 * (angMom[j] * angMom[j] / I(j, j) +
229     angMom[k] * angMom[k] / I(k, k));
230     dof += 2;
231     } else {
232     KE += 0.5 * (angMom[0] * angMom[0] / I(0, 0) +
233     angMom[1] * angMom[1] / I(1, 1) +
234     angMom[2] * angMom[2] / I(2, 2));
235     dof += 3;
236     }
237     }
238    
239     RealType temp = 2.0 * KE / (dof * PhysicalConstants::kb *
240     PhysicalConstants::energyConvert);
241    
242     RealType rinner = (RealType)bin * binWidth_;
243     RealType router = (RealType)(bin+1) * binWidth_;
244     RealType den = mass * 3.0 * PhysicalConstants::densityConvert
245     / (4.0 * M_PI * (pow(router,3) - pow(rinner,3)));
246    
247     dynamic_cast<Accumulator *>(temperature->accumulator[bin])->add(temp);
248     dynamic_cast<VectorAccumulator *>(angularVelocity->accumulator[bin])->add(aVel);
249     dynamic_cast<Accumulator *>(density->accumulator[bin])->add(den);
250    
251     }
252     }
253    

Properties

Name Value
svn:eol-style native