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 |
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 |
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 |
|
|
// We'll need the force manager to compute forces for the average pressure |
161 |
|
|
ForceManager* forceMan = new ForceManager(info_); |
162 |
|
|
|
163 |
|
|
// We'll need thermo to compute the pressures from the virial |
164 |
|
|
Thermo* thermo = new Thermo(info_); |
165 |
|
|
|
166 |
|
|
// prepare the averages |
167 |
|
|
RealType pSum = 0.0; |
168 |
|
|
RealType vSum = 0.0; |
169 |
|
|
int nsamp = 0; |
170 |
|
|
|
171 |
|
|
// dump files can be enormous, so read them in block-by-block: |
172 |
|
|
int nblocks = bsMan_->getNBlocks(); |
173 |
|
|
for (int i = 0; i < nblocks; ++i) { |
174 |
|
|
std::cerr << "block = " << i << "\n"; |
175 |
|
|
bsMan_->loadBlock(i); |
176 |
|
|
assert(bsMan_->isBlockActive(i)); |
177 |
|
|
SnapshotBlock block1 = bsMan_->getSnapshotBlock(i); |
178 |
|
|
for (int j = block1.first; j < block1.second; ++j) { |
179 |
|
|
|
180 |
|
|
// go snapshot-by-snapshot through this block: |
181 |
|
|
Snapshot* snap = bsMan_->getSnapshot(j); |
182 |
|
|
|
183 |
|
|
// update the positions and velocities of the atoms belonging |
184 |
|
|
// to rigid bodies: |
185 |
|
|
|
186 |
|
|
updateFrame(j); |
187 |
|
|
|
188 |
|
|
// do the forces: |
189 |
|
|
//forceMan->calcForces(true, true); |
190 |
|
|
// call thermo to get the pressure and volume. |
191 |
|
|
pSum += thermo->getPressure(); |
192 |
|
|
vSum += thermo->getVolume(); |
193 |
|
|
nsamp++; |
194 |
|
|
|
195 |
|
|
} |
196 |
|
|
bsMan_->unloadBlock(i); |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
avePress_ = pSum / ( PhysicalConstants::pressureConvert * (RealType)nsamp); |
200 |
|
|
aveVol_ = vSum / (RealType)nsamp; |
201 |
|
|
std::cout << "pAve = " << avePress_ << " vAve = " << aveVol_ << "\n"; |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
|
205 |
|
|
void StressCorrFunc::writeCorrelate() { |
206 |
|
|
std::ofstream ofs(getOutputFileName().c_str()); |
207 |
|
|
|
208 |
|
|
if (ofs.is_open()) { |
209 |
|
|
|
210 |
|
|
ofs << "#" << getCorrFuncType() << "\n"; |
211 |
|
|
ofs << "#time\tcorrTensor\txx\txy\txz\tyx\tyy\tyz\tzx\tzy\tzz\n"; |
212 |
|
|
|
213 |
|
|
for (int i = 0; i < nTimeBins_; ++i) { |
214 |
|
|
ofs << time_[i] << "\t" << |
215 |
|
|
histogram_[i](0,0) << "\t" << |
216 |
|
|
histogram_[i](0,1) << "\t" << |
217 |
|
|
histogram_[i](0,2) << "\t" << |
218 |
|
|
histogram_[i](1,0) << "\t" << |
219 |
|
|
histogram_[i](1,1) << "\t" << |
220 |
|
|
histogram_[i](1,2) << "\t" << |
221 |
|
|
histogram_[i](2,0) << "\t" << |
222 |
|
|
histogram_[i](2,1) << "\t" << |
223 |
|
|
histogram_[i](2,2) << "\t" << "\n"; |
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
} else { |
227 |
|
|
sprintf(painCave.errMsg, |
228 |
|
|
"StressCorrFunc::writeCorrelate Error: fail to open %s\n", getOutputFileName().c_str()); |
229 |
|
|
painCave.isFatal = 1; |
230 |
|
|
simError(); |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
ofs.close(); |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
} |