| 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 |
|
|
* 1. Acknowledgement of the program authors must be made in any |
| 10 |
|
|
* publication of scientific results based in part on use of the |
| 11 |
|
|
* program. An acceptable form of acknowledgement is citation of |
| 12 |
|
|
* the article in which the program was described (Matthew |
| 13 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
| 14 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
| 15 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
| 16 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
| 17 |
|
|
* |
| 18 |
|
|
* 2. Redistributions of source code must retain the above copyright |
| 19 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 20 |
|
|
* |
| 21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
| 22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 23 |
|
|
* documentation and/or other materials provided with the |
| 24 |
|
|
* distribution. |
| 25 |
|
|
* |
| 26 |
|
|
* This software is provided "AS IS," without a warranty of any |
| 27 |
|
|
* kind. All express or implied conditions, representations and |
| 28 |
|
|
* warranties, including any implied warranty of merchantability, |
| 29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
| 30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
| 31 |
|
|
* be liable for any damages suffered by licensee as a result of |
| 32 |
|
|
* using, modifying or distributing the software or its |
| 33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
| 34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
| 35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
| 36 |
|
|
* damages, however caused and regardless of the theory of liability, |
| 37 |
|
|
* arising out of the use of or inability to use software, even if the |
| 38 |
|
|
* University of Notre Dame has been advised of the possibility of |
| 39 |
|
|
* such damages. |
| 40 |
|
|
*/ |
| 41 |
|
|
|
| 42 |
|
|
#include "applications/dynamicProps/ActionCorrFunc.hpp" |
| 43 |
|
|
#include "utils/OOPSEConstant.hpp" |
| 44 |
|
|
#include "brains/ForceManager.hpp" |
| 45 |
|
|
#include "brains/Thermo.hpp" |
| 46 |
|
|
|
| 47 |
|
|
namespace oopse { |
| 48 |
|
|
|
| 49 |
|
|
// We need all of the positions, velocities, etc. so that we can |
| 50 |
|
|
// recalculate pressures and actions on the fly: |
| 51 |
|
|
ActionCorrFunc::ActionCorrFunc(SimInfo* info, const std::string& filename, |
| 52 |
|
|
const std::string& sele1, |
| 53 |
|
|
const std::string& sele2) |
| 54 |
|
|
: FrameTimeCorrFunc(info, filename, sele1, sele2, |
| 55 |
|
|
DataStorage::dslPosition | |
| 56 |
|
|
DataStorage::dslVelocity | |
| 57 |
|
|
DataStorage::dslForce ){ |
| 58 |
|
|
|
| 59 |
|
|
setCorrFuncType("ActionCorrFunc"); |
| 60 |
|
|
setOutputName(getPrefix(dumpFilename_) + ".action"); |
| 61 |
|
|
histogram_.resize(nTimeBins_); |
| 62 |
|
|
count_.resize(nTimeBins_); |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
|
void ActionCorrFunc::correlateFrames(int frame1, int frame2) { |
| 66 |
|
|
Snapshot* snapshot1 = bsMan_->getSnapshot(frame1); |
| 67 |
|
|
Snapshot* snapshot2 = bsMan_->getSnapshot(frame2); |
| 68 |
|
|
assert(snapshot1 && snapshot2); |
| 69 |
|
|
|
| 70 |
|
|
RealType time1 = snapshot1->getTime(); |
| 71 |
|
|
RealType time2 = snapshot2->getTime(); |
| 72 |
|
|
RealType vol1 = snapshot1->getVolume(); |
| 73 |
|
|
RealType vol2 = snapshot2->getVolume(); |
| 74 |
|
|
|
| 75 |
|
|
int timeBin = int ((time2 - time1) /deltaTime_ + 0.5); |
| 76 |
|
|
|
| 77 |
|
|
//std::cerr << "times = " << time1 << " " << time2 << "\n"; |
| 78 |
|
|
//std::cerr << "vols = " << vol1 << " " << vol2 << "\n"; |
| 79 |
|
|
|
| 80 |
|
|
int i; |
| 81 |
|
|
int j; |
| 82 |
|
|
|
| 83 |
|
|
StuntDouble* sd1; |
| 84 |
|
|
|
| 85 |
|
|
Mat3x3d actionTensor1(0.0); |
| 86 |
|
|
//std::cerr << "at1 = " << actionTensor1 << "\n"; |
| 87 |
|
|
Mat3x3d actionTensor2(0.0); |
| 88 |
|
|
//std::cerr << "at2 = " << actionTensor2 << "\n"; |
| 89 |
|
|
|
| 90 |
|
|
for (sd1 = seleMan1_.beginSelected(i); sd1 != NULL; |
| 91 |
|
|
sd1 = seleMan1_.nextSelected(i)) { |
| 92 |
|
|
//std::cerr << "found a SD\n"; |
| 93 |
|
|
Vector3d r1 = sd1->getPos(frame1); |
| 94 |
|
|
//std::cerr << "r1 = " << r1 << "\n"; |
| 95 |
|
|
Vector3d v1 = sd1->getVel(frame1); |
| 96 |
|
|
//std::cerr << "v1 = " << v1 << "\n"; |
| 97 |
|
|
Vector3d r2 = sd1->getPos(frame2); |
| 98 |
|
|
//std::cerr << "r2 = " << r2 << "\n"; |
| 99 |
|
|
Vector3d v2 = sd1->getVel(frame2); |
| 100 |
|
|
//std::cerr << "v2 = " << v2 << "\n"; |
| 101 |
|
|
|
| 102 |
|
|
RealType m = sd1->getMass(); |
| 103 |
|
|
|
| 104 |
|
|
//std::cerr << "m = " << m << "\n"; |
| 105 |
|
|
|
| 106 |
|
|
actionTensor1 += m*outProduct(r1, v1); |
| 107 |
|
|
actionTensor2 += m*outProduct(r2, v2); |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
actionTensor1 /= vol1; |
| 111 |
|
|
//std::cerr << "at1 = " << actionTensor1 << "\n"; |
| 112 |
|
|
actionTensor2 /= vol2; |
| 113 |
|
|
//std::cerr << "at2 = " << actionTensor2 << "\n"; |
| 114 |
|
|
|
| 115 |
|
|
Mat3x3d corrTensor(0.0); |
| 116 |
|
|
//std::cerr << "ct = " << corrTensor << "\n"; |
| 117 |
|
|
RealType thisTerm; |
| 118 |
|
|
|
| 119 |
|
|
for (i = 0; i < 3; i++) { |
| 120 |
|
|
for (j = 0; j < 3; j++) { |
| 121 |
|
|
|
| 122 |
|
|
//std::cerr << "i, j = " << i << " " << j << "\n"; |
| 123 |
|
|
if (i == j) { |
| 124 |
|
|
thisTerm = (actionTensor2(i, j) - actionTensor1(i, j) - avePress_ *(time2-time1)); |
| 125 |
|
|
std::cerr << "at1, at2 = " << actionTensor1(i,j) << " " << actionTensor2(i,j) << " p = " << avePress_ << "\n"; |
| 126 |
|
|
} else { |
| 127 |
|
|
thisTerm = (actionTensor2(i, j) - actionTensor1(i, j)); |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
//std::cerr << "thisTerm = " << thisTerm << "\n"; |
| 131 |
|
|
corrTensor(i, j) += thisTerm * thisTerm; |
| 132 |
|
|
} |
| 133 |
|
|
} |
| 134 |
|
|
|
| 135 |
|
|
//std::cerr << "ct = " << corrTensor << "\n"; |
| 136 |
|
|
//std::cerr << "hist = " << histogram_[timeBin] << "\n"; |
| 137 |
|
|
histogram_[timeBin] += corrTensor; |
| 138 |
|
|
count_[timeBin]++; |
| 139 |
|
|
|
| 140 |
|
|
} |
| 141 |
|
|
|
| 142 |
|
|
void ActionCorrFunc::postCorrelate() { |
| 143 |
|
|
for (int i =0 ; i < nTimeBins_; ++i) { |
| 144 |
|
|
if (count_[i] > 0) { |
| 145 |
|
|
histogram_[i] /= count_[i]; |
| 146 |
|
|
} |
| 147 |
|
|
} |
| 148 |
|
|
} |
| 149 |
|
|
|
| 150 |
|
|
|
| 151 |
|
|
void ActionCorrFunc::preCorrelate() { |
| 152 |
|
|
// Fill the histogram with empty 3x3 matrices: |
| 153 |
|
|
std::fill(histogram_.begin(), histogram_.end(), Mat3x3d(0.0)); |
| 154 |
|
|
// count array set to zero |
| 155 |
|
|
std::fill(count_.begin(), count_.end(), 0); |
| 156 |
|
|
|
| 157 |
|
|
SimInfo::MoleculeIterator mi; |
| 158 |
|
|
Molecule* mol; |
| 159 |
|
|
Molecule::AtomIterator ai; |
| 160 |
|
|
Atom* atom; |
| 161 |
|
|
|
| 162 |
|
|
// We'll need the force manager to compute forces for the average pressure |
| 163 |
|
|
ForceManager* forceMan = new ForceManager(info_); |
| 164 |
|
|
forceMan->init(); |
| 165 |
|
|
|
| 166 |
|
|
// We'll need thermo to compute the pressures from the virial |
| 167 |
|
|
Thermo* thermo = new Thermo(info_); |
| 168 |
|
|
|
| 169 |
|
|
// prepare the averages |
| 170 |
|
|
RealType pSum = 0.0; |
| 171 |
|
|
RealType vSum = 0.0; |
| 172 |
|
|
int nsamp = 0; |
| 173 |
|
|
|
| 174 |
|
|
// dump files can be enormous, so read them in block-by-block: |
| 175 |
|
|
int nblocks = bsMan_->getNBlocks(); |
| 176 |
|
|
for (int i = 0; i < nblocks; ++i) { |
| 177 |
|
|
std::cerr << "block = " << i << "\n"; |
| 178 |
|
|
bsMan_->loadBlock(i); |
| 179 |
|
|
assert(bsMan_->isBlockActive(i)); |
| 180 |
|
|
SnapshotBlock block1 = bsMan_->getSnapshotBlock(i); |
| 181 |
|
|
for (int j = block1.first; j < block1.second; ++j) { |
| 182 |
|
|
|
| 183 |
|
|
// go snapshot-by-snapshot through this block: |
| 184 |
|
|
Snapshot* snap = bsMan_->getSnapshot(j); |
| 185 |
|
|
|
| 186 |
|
|
// update the positions and velocities of the atoms belonging |
| 187 |
|
|
// to rigid bodies: |
| 188 |
|
|
|
| 189 |
|
|
updateFrame(j); |
| 190 |
|
|
|
| 191 |
|
|
// do the forces: |
| 192 |
|
|
forceMan->calcForces(true, true); |
| 193 |
|
|
// call thermo to get the pressure and volume. |
| 194 |
|
|
pSum += thermo->getPressure(); |
| 195 |
|
|
vSum += thermo->getVolume(); |
| 196 |
|
|
nsamp++; |
| 197 |
|
|
|
| 198 |
|
|
} |
| 199 |
|
|
bsMan_->unloadBlock(i); |
| 200 |
|
|
} |
| 201 |
|
|
|
| 202 |
|
|
avePress_ = pSum / ( OOPSEConstant::pressureConvert * (RealType)nsamp); |
| 203 |
|
|
aveVol_ = vSum / (RealType)nsamp; |
| 204 |
|
|
std::cout << "pAve = " << avePress_ << " vAve = " << aveVol_ << "\n"; |
| 205 |
|
|
} |
| 206 |
|
|
|
| 207 |
|
|
|
| 208 |
|
|
void ActionCorrFunc::writeCorrelate() { |
| 209 |
|
|
std::ofstream ofs(getOutputFileName().c_str()); |
| 210 |
|
|
|
| 211 |
|
|
if (ofs.is_open()) { |
| 212 |
|
|
|
| 213 |
|
|
ofs << "#" << getCorrFuncType() << "\n"; |
| 214 |
|
|
ofs << "#time\tcorrTensor\txx\txy\txz\tyx\tyy\tyz\tzx\tzy\tzz\n"; |
| 215 |
|
|
|
| 216 |
|
|
for (int i = 0; i < nTimeBins_; ++i) { |
| 217 |
|
|
ofs << time_[i] << "\t" << |
| 218 |
|
|
histogram_[i](0,0) << "\t" << |
| 219 |
|
|
histogram_[i](0,1) << "\t" << |
| 220 |
|
|
histogram_[i](0,2) << "\t" << |
| 221 |
|
|
histogram_[i](1,0) << "\t" << |
| 222 |
|
|
histogram_[i](1,1) << "\t" << |
| 223 |
|
|
histogram_[i](1,2) << "\t" << |
| 224 |
|
|
histogram_[i](2,0) << "\t" << |
| 225 |
|
|
histogram_[i](2,1) << "\t" << |
| 226 |
|
|
histogram_[i](2,2) << "\t" << "\n"; |
| 227 |
|
|
} |
| 228 |
|
|
|
| 229 |
|
|
} else { |
| 230 |
|
|
sprintf(painCave.errMsg, |
| 231 |
|
|
"ActionCorrFunc::writeCorrelate Error: fail to open %s\n", getOutputFileName().c_str()); |
| 232 |
|
|
painCave.isFatal = 1; |
| 233 |
|
|
simError(); |
| 234 |
|
|
} |
| 235 |
|
|
|
| 236 |
|
|
ofs.close(); |
| 237 |
|
|
} |
| 238 |
|
|
|
| 239 |
|
|
} |