ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/ActionCorrFunc.cpp
Revision: 1850
Committed: Wed Feb 20 15:39:39 2013 UTC (12 years, 3 months ago) by gezelter
File size: 8190 byte(s)
Log Message:
Fixed a widespread typo in the license 

File Contents

# User Rev Content
1 xsun 1183 /*
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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 xsun 1183 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 xsun 1183 * 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 gezelter 1390 *
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 gezelter 1850 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 xsun 1183 */
42    
43     #include "applications/dynamicProps/ActionCorrFunc.hpp"
44 gezelter 1390 #include "utils/PhysicalConstants.hpp"
45 xsun 1183 #include "brains/ForceManager.hpp"
46     #include "brains/Thermo.hpp"
47    
48 gezelter 1390 namespace OpenMD {
49 xsun 1183
50     // We need all of the positions, velocities, etc. so that we can
51     // recalculate pressures and actions on the fly:
52     ActionCorrFunc::ActionCorrFunc(SimInfo* info, const std::string& filename,
53     const std::string& sele1,
54 gezelter 1629 const std::string& sele2,
55     long long int memSize)
56 xsun 1183 : FrameTimeCorrFunc(info, filename, sele1, sele2,
57     DataStorage::dslPosition |
58     DataStorage::dslVelocity |
59 gezelter 1629 DataStorage::dslForce, memSize ){
60 xsun 1183
61     setCorrFuncType("ActionCorrFunc");
62     setOutputName(getPrefix(dumpFilename_) + ".action");
63     histogram_.resize(nTimeBins_);
64     count_.resize(nTimeBins_);
65     }
66    
67     void ActionCorrFunc::correlateFrames(int frame1, int frame2) {
68     Snapshot* snapshot1 = bsMan_->getSnapshot(frame1);
69     Snapshot* snapshot2 = bsMan_->getSnapshot(frame2);
70     assert(snapshot1 && snapshot2);
71    
72     RealType time1 = snapshot1->getTime();
73     RealType time2 = snapshot2->getTime();
74     RealType vol1 = snapshot1->getVolume();
75     RealType vol2 = snapshot2->getVolume();
76    
77     int timeBin = int ((time2 - time1) /deltaTime_ + 0.5);
78    
79     //std::cerr << "times = " << time1 << " " << time2 << "\n";
80     //std::cerr << "vols = " << vol1 << " " << vol2 << "\n";
81    
82     int i;
83     int j;
84    
85     StuntDouble* sd1;
86    
87     Mat3x3d actionTensor1(0.0);
88     //std::cerr << "at1 = " << actionTensor1 << "\n";
89     Mat3x3d actionTensor2(0.0);
90     //std::cerr << "at2 = " << actionTensor2 << "\n";
91    
92     for (sd1 = seleMan1_.beginSelected(i); sd1 != NULL;
93     sd1 = seleMan1_.nextSelected(i)) {
94     //std::cerr << "found a SD\n";
95     Vector3d r1 = sd1->getPos(frame1);
96     //std::cerr << "r1 = " << r1 << "\n";
97     Vector3d v1 = sd1->getVel(frame1);
98     //std::cerr << "v1 = " << v1 << "\n";
99     Vector3d r2 = sd1->getPos(frame2);
100     //std::cerr << "r2 = " << r2 << "\n";
101     Vector3d v2 = sd1->getVel(frame2);
102     //std::cerr << "v2 = " << v2 << "\n";
103    
104     RealType m = sd1->getMass();
105    
106     //std::cerr << "m = " << m << "\n";
107    
108     actionTensor1 += m*outProduct(r1, v1);
109     actionTensor2 += m*outProduct(r2, v2);
110     }
111    
112     actionTensor1 /= vol1;
113     //std::cerr << "at1 = " << actionTensor1 << "\n";
114     actionTensor2 /= vol2;
115     //std::cerr << "at2 = " << actionTensor2 << "\n";
116    
117     Mat3x3d corrTensor(0.0);
118     //std::cerr << "ct = " << corrTensor << "\n";
119     RealType thisTerm;
120    
121     for (i = 0; i < 3; i++) {
122     for (j = 0; j < 3; j++) {
123    
124     //std::cerr << "i, j = " << i << " " << j << "\n";
125     if (i == j) {
126     thisTerm = (actionTensor2(i, j) - actionTensor1(i, j) - avePress_ *(time2-time1));
127     std::cerr << "at1, at2 = " << actionTensor1(i,j) << " " << actionTensor2(i,j) << " p = " << avePress_ << "\n";
128     } else {
129     thisTerm = (actionTensor2(i, j) - actionTensor1(i, j));
130     }
131    
132     //std::cerr << "thisTerm = " << thisTerm << "\n";
133     corrTensor(i, j) += thisTerm * thisTerm;
134     }
135     }
136    
137     //std::cerr << "ct = " << corrTensor << "\n";
138     //std::cerr << "hist = " << histogram_[timeBin] << "\n";
139     histogram_[timeBin] += corrTensor;
140     count_[timeBin]++;
141    
142     }
143    
144     void ActionCorrFunc::postCorrelate() {
145     for (int i =0 ; i < nTimeBins_; ++i) {
146     if (count_[i] > 0) {
147     histogram_[i] /= count_[i];
148     }
149     }
150     }
151    
152    
153     void ActionCorrFunc::preCorrelate() {
154     // Fill the histogram with empty 3x3 matrices:
155     std::fill(histogram_.begin(), histogram_.end(), Mat3x3d(0.0));
156     // count array set to zero
157     std::fill(count_.begin(), count_.end(), 0);
158    
159     // We'll need the force manager to compute forces for the average pressure
160     ForceManager* forceMan = new ForceManager(info_);
161    
162     // We'll need thermo to compute the pressures from the virial
163     Thermo* thermo = new Thermo(info_);
164    
165     // prepare the averages
166     RealType pSum = 0.0;
167     RealType vSum = 0.0;
168     int nsamp = 0;
169    
170     // dump files can be enormous, so read them in block-by-block:
171     int nblocks = bsMan_->getNBlocks();
172     for (int i = 0; i < nblocks; ++i) {
173     std::cerr << "block = " << i << "\n";
174     bsMan_->loadBlock(i);
175     assert(bsMan_->isBlockActive(i));
176     SnapshotBlock block1 = bsMan_->getSnapshotBlock(i);
177     for (int j = block1.first; j < block1.second; ++j) {
178    
179     // go snapshot-by-snapshot through this block:
180     Snapshot* snap = bsMan_->getSnapshot(j);
181    
182     // update the positions and velocities of the atoms belonging
183     // to rigid bodies:
184    
185     updateFrame(j);
186    
187     // do the forces:
188 gezelter 1635 forceMan->calcForces();
189 xsun 1183 // call thermo to get the pressure and volume.
190     pSum += thermo->getPressure();
191     vSum += thermo->getVolume();
192     nsamp++;
193    
194     }
195     bsMan_->unloadBlock(i);
196     }
197    
198 gezelter 1390 avePress_ = pSum / ( PhysicalConstants::pressureConvert * (RealType)nsamp);
199 xsun 1183 aveVol_ = vSum / (RealType)nsamp;
200     std::cout << "pAve = " << avePress_ << " vAve = " << aveVol_ << "\n";
201     }
202    
203    
204     void ActionCorrFunc::writeCorrelate() {
205     std::ofstream ofs(getOutputFileName().c_str());
206    
207     if (ofs.is_open()) {
208    
209     ofs << "#" << getCorrFuncType() << "\n";
210     ofs << "#time\tcorrTensor\txx\txy\txz\tyx\tyy\tyz\tzx\tzy\tzz\n";
211    
212     for (int i = 0; i < nTimeBins_; ++i) {
213     ofs << time_[i] << "\t" <<
214     histogram_[i](0,0) << "\t" <<
215     histogram_[i](0,1) << "\t" <<
216     histogram_[i](0,2) << "\t" <<
217     histogram_[i](1,0) << "\t" <<
218     histogram_[i](1,1) << "\t" <<
219     histogram_[i](1,2) << "\t" <<
220     histogram_[i](2,0) << "\t" <<
221     histogram_[i](2,1) << "\t" <<
222     histogram_[i](2,2) << "\t" << "\n";
223     }
224    
225     } else {
226     sprintf(painCave.errMsg,
227     "ActionCorrFunc::writeCorrelate Error: fail to open %s\n", getOutputFileName().c_str());
228     painCave.isFatal = 1;
229     simError();
230     }
231    
232     ofs.close();
233     }
234    
235     }

Properties

Name Value
svn:keywords Author Id Revision Date