ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dynamicProps/StressCorrFunc.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 6 months ago) by gezelter
File size: 8326 byte(s)
Log Message:
updated copyright notices

File Contents

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

Properties

Name Value
svn:eol-style native