| 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 |
gezelter |
1884 |
RealType z; |
| 90 |
|
|
|
| 91 |
|
|
hmat_ = currentSnapshot_->getHmat(); |
| 92 |
|
|
for (int i = 0; i < nBins_; i++) { |
| 93 |
|
|
z = (((RealType)i + 0.5) / (RealType)nBins_) * hmat_(2,2); |
| 94 |
|
|
dynamic_cast<Accumulator*>(z_->accumulator[i])->add(z); |
| 95 |
|
|
} |
| 96 |
|
|
volume_ = currentSnapshot_->getVolume(); |
| 97 |
|
|
|
| 98 |
|
|
|
| 99 |
gezelter |
1881 |
Molecule* mol; |
| 100 |
|
|
RigidBody* rb; |
| 101 |
|
|
StuntDouble* sd; |
| 102 |
|
|
SimInfo::MoleculeIterator mi; |
| 103 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 104 |
|
|
int i; |
| 105 |
gezelter |
1865 |
|
| 106 |
gezelter |
1881 |
vector<RealType> binMass(nBins_, 0.0); |
| 107 |
gezelter |
1892 |
vector<RealType> binPx(nBins_, 0.0); |
| 108 |
|
|
vector<RealType> binPy(nBins_, 0.0); |
| 109 |
|
|
vector<RealType> binPz(nBins_, 0.0); |
| 110 |
gezelter |
1881 |
vector<RealType> binKE(nBins_, 0.0); |
| 111 |
gezelter |
1883 |
vector<unsigned int> binDof(nBins_, 0); |
| 112 |
|
|
vector<unsigned int> binCount(nBins_, 0); |
| 113 |
gezelter |
1881 |
|
| 114 |
|
|
|
| 115 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 116 |
|
|
mol = info_->nextMolecule(mi)) { |
| 117 |
|
|
|
| 118 |
|
|
// change the positions of atoms which belong to the rigidbodies |
| 119 |
|
|
|
| 120 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 121 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
| 122 |
gezelter |
1892 |
rb->updateAtomVel(); |
| 123 |
gezelter |
1865 |
} |
| 124 |
|
|
} |
| 125 |
gezelter |
1884 |
|
| 126 |
gezelter |
1881 |
if (evaluator_.isDynamic()) { |
| 127 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 128 |
|
|
} |
| 129 |
gezelter |
1865 |
|
| 130 |
gezelter |
1881 |
// loop over the selected atoms: |
| 131 |
|
|
|
| 132 |
|
|
for (sd = seleMan_.beginSelected(i); sd != NULL; |
| 133 |
|
|
sd = seleMan_.nextSelected(i)) { |
| 134 |
|
|
|
| 135 |
|
|
// figure out where that object is: |
| 136 |
|
|
Vector3d pos = sd->getPos(); |
| 137 |
gezelter |
1883 |
Vector3d vel = sd->getVel(); |
| 138 |
|
|
RealType m = sd->getMass(); |
| 139 |
|
|
|
| 140 |
gezelter |
1881 |
int bin = getBin(pos); |
| 141 |
gezelter |
1884 |
|
| 142 |
gezelter |
1883 |
binCount[bin] += 1; |
| 143 |
gezelter |
1881 |
|
| 144 |
|
|
binMass[bin] += m; |
| 145 |
gezelter |
1892 |
binPx[bin] += m * vel.x(); |
| 146 |
|
|
binPy[bin] += m * vel.y(); |
| 147 |
|
|
binPz[bin] += m * vel.z(); |
| 148 |
gezelter |
1881 |
binKE[bin] += 0.5 * (m * vel.lengthSquare()); |
| 149 |
|
|
binDof[bin] += 3; |
| 150 |
|
|
|
| 151 |
|
|
if (sd->isDirectional()) { |
| 152 |
|
|
Vector3d angMom = sd->getJ(); |
| 153 |
|
|
Mat3x3d I = sd->getI(); |
| 154 |
|
|
if (sd->isLinear()) { |
| 155 |
|
|
int i = sd->linearAxis(); |
| 156 |
|
|
int j = (i + 1) % 3; |
| 157 |
|
|
int k = (i + 2) % 3; |
| 158 |
|
|
binKE[bin] += 0.5 * (angMom[j] * angMom[j] / I(j, j) + |
| 159 |
|
|
angMom[k] * angMom[k] / I(k, k)); |
| 160 |
|
|
binDof[bin] += 2; |
| 161 |
|
|
} else { |
| 162 |
|
|
binKE[bin] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + |
| 163 |
|
|
angMom[1] * angMom[1] / I(1, 1) + |
| 164 |
|
|
angMom[2] * angMom[2] / I(2, 2)); |
| 165 |
|
|
binDof[bin] += 3; |
| 166 |
|
|
} |
| 167 |
|
|
} |
| 168 |
|
|
} |
| 169 |
|
|
|
| 170 |
gezelter |
1883 |
for (unsigned int i = 0; i < nBins_; i++) { |
| 171 |
gezelter |
1885 |
|
| 172 |
gezelter |
1882 |
if (binDof[i] > 0) { |
| 173 |
|
|
RealType temp = 2.0 * binKE[i] / (binDof[i] * PhysicalConstants::kb * |
| 174 |
|
|
PhysicalConstants::energyConvert); |
| 175 |
|
|
RealType den = binMass[i] * nBins_ * PhysicalConstants::densityConvert |
| 176 |
|
|
/ volume_; |
| 177 |
gezelter |
1892 |
Vector3d vel; |
| 178 |
|
|
vel.x() = binPx[i] / binMass[i]; |
| 179 |
|
|
vel.y() = binPy[i] / binMass[i]; |
| 180 |
|
|
vel.z() = binPz[i] / binMass[i]; |
| 181 |
|
|
|
| 182 |
gezelter |
1882 |
dynamic_cast<Accumulator *>(temperature->accumulator[i])->add(temp); |
| 183 |
|
|
dynamic_cast<VectorAccumulator *>(velocity->accumulator[i])->add(vel); |
| 184 |
|
|
dynamic_cast<Accumulator *>(density->accumulator[i])->add(den); |
| 185 |
|
|
dynamic_cast<Accumulator *>(counts_->accumulator[i])->add(1); |
| 186 |
|
|
} |
| 187 |
gezelter |
1881 |
} |
| 188 |
gezelter |
1865 |
} |
| 189 |
gezelter |
1881 |
|
| 190 |
|
|
void RNEMDZ::processStuntDouble(StuntDouble* sd, int bin) { |
| 191 |
|
|
} |
| 192 |
gezelter |
1865 |
|
| 193 |
|
|
RNEMDR::RNEMDR(SimInfo* info, const std::string& filename, |
| 194 |
|
|
const std::string& sele, int nrbins) |
| 195 |
|
|
: ShellStatistics(info, filename, sele, nrbins) { |
| 196 |
|
|
|
| 197 |
|
|
|
| 198 |
|
|
setOutputName(getPrefix(filename) + ".rnemdR"); |
| 199 |
|
|
|
| 200 |
|
|
temperature = new OutputData; |
| 201 |
|
|
temperature->units = "K"; |
| 202 |
|
|
temperature->title = "Temperature"; |
| 203 |
|
|
temperature->dataType = odtReal; |
| 204 |
|
|
temperature->dataHandling = odhAverage; |
| 205 |
|
|
temperature->accumulator.reserve(nBins_); |
| 206 |
|
|
for (int i = 0; i < nBins_; i++) |
| 207 |
|
|
temperature->accumulator.push_back( new Accumulator() ); |
| 208 |
|
|
data_.push_back(temperature); |
| 209 |
|
|
|
| 210 |
|
|
angularVelocity = new OutputData; |
| 211 |
|
|
angularVelocity->units = "angstroms^2/fs"; |
| 212 |
|
|
angularVelocity->title = "Velocity"; |
| 213 |
|
|
angularVelocity->dataType = odtVector3; |
| 214 |
|
|
angularVelocity->dataHandling = odhAverage; |
| 215 |
|
|
angularVelocity->accumulator.reserve(nBins_); |
| 216 |
|
|
for (int i = 0; i < nBins_; i++) |
| 217 |
|
|
angularVelocity->accumulator.push_back( new VectorAccumulator() ); |
| 218 |
|
|
data_.push_back(angularVelocity); |
| 219 |
|
|
|
| 220 |
|
|
density = new OutputData; |
| 221 |
|
|
density->units = "g cm^-3"; |
| 222 |
|
|
density->title = "Density"; |
| 223 |
|
|
density->dataType = odtReal; |
| 224 |
|
|
density->dataHandling = odhAverage; |
| 225 |
|
|
density->accumulator.reserve(nBins_); |
| 226 |
|
|
for (int i = 0; i < nBins_; i++) |
| 227 |
|
|
density->accumulator.push_back( new Accumulator() ); |
| 228 |
|
|
data_.push_back(density); |
| 229 |
|
|
} |
| 230 |
|
|
|
| 231 |
|
|
|
| 232 |
gezelter |
1887 |
void RNEMDR::processFrame(int istep) { |
| 233 |
gezelter |
1865 |
|
| 234 |
gezelter |
1887 |
Molecule* mol; |
| 235 |
|
|
RigidBody* rb; |
| 236 |
|
|
StuntDouble* sd; |
| 237 |
|
|
SimInfo::MoleculeIterator mi; |
| 238 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 239 |
|
|
int i; |
| 240 |
|
|
|
| 241 |
|
|
vector<RealType> binMass(nBins_, 0.0); |
| 242 |
|
|
vector<Vector3d> binaVel(nBins_, V3Zero); |
| 243 |
|
|
vector<RealType> binKE(nBins_, 0.0); |
| 244 |
|
|
vector<unsigned int> binDof(nBins_, 0); |
| 245 |
|
|
vector<unsigned int> binCount(nBins_, 0); |
| 246 |
|
|
|
| 247 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 248 |
|
|
mol = info_->nextMolecule(mi)) { |
| 249 |
|
|
|
| 250 |
|
|
// change the positions of atoms which belong to the rigidbodies |
| 251 |
|
|
|
| 252 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 253 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
| 254 |
gezelter |
1892 |
rb->updateAtomVel(); |
| 255 |
gezelter |
1865 |
} |
| 256 |
|
|
} |
| 257 |
gezelter |
1887 |
|
| 258 |
|
|
if (evaluator_.isDynamic()) { |
| 259 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 260 |
|
|
} |
| 261 |
gezelter |
1865 |
|
| 262 |
gezelter |
1887 |
// loop over the selected atoms: |
| 263 |
|
|
|
| 264 |
|
|
for (sd = seleMan_.beginSelected(i); sd != NULL; |
| 265 |
|
|
sd = seleMan_.nextSelected(i)) { |
| 266 |
|
|
|
| 267 |
|
|
// figure out where that object is: |
| 268 |
gezelter |
1865 |
|
| 269 |
gezelter |
1887 |
Vector3d rPos = sd->getPos() - coordinateOrigin_; |
| 270 |
|
|
Vector3d vel = sd->getVel(); |
| 271 |
|
|
Vector3d aVel = cross(rPos, vel); |
| 272 |
|
|
RealType m = sd->getMass(); |
| 273 |
|
|
|
| 274 |
gezelter |
1888 |
int bin = getBin(rPos); |
| 275 |
gezelter |
1887 |
|
| 276 |
|
|
binCount[bin] += 1; |
| 277 |
|
|
|
| 278 |
|
|
binMass[bin] += m; |
| 279 |
|
|
binaVel[bin] += aVel; |
| 280 |
|
|
binKE[bin] += 0.5 * (m * vel.lengthSquare()); |
| 281 |
|
|
binDof[bin] += 3; |
| 282 |
|
|
|
| 283 |
|
|
if (sd->isDirectional()) { |
| 284 |
|
|
Vector3d angMom = sd->getJ(); |
| 285 |
|
|
Mat3x3d I = sd->getI(); |
| 286 |
|
|
if (sd->isLinear()) { |
| 287 |
|
|
int i = sd->linearAxis(); |
| 288 |
|
|
int j = (i + 1) % 3; |
| 289 |
|
|
int k = (i + 2) % 3; |
| 290 |
|
|
binKE[bin] += 0.5 * (angMom[j] * angMom[j] / I(j, j) + |
| 291 |
|
|
angMom[k] * angMom[k] / I(k, k)); |
| 292 |
|
|
binDof[bin] += 2; |
| 293 |
|
|
} else { |
| 294 |
|
|
binKE[bin] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + |
| 295 |
|
|
angMom[1] * angMom[1] / I(1, 1) + |
| 296 |
|
|
angMom[2] * angMom[2] / I(2, 2)); |
| 297 |
|
|
binDof[bin] += 3; |
| 298 |
|
|
} |
| 299 |
|
|
} |
| 300 |
|
|
} |
| 301 |
gezelter |
1865 |
|
| 302 |
gezelter |
1887 |
for (unsigned int i = 0; i < nBins_; i++) { |
| 303 |
|
|
RealType rinner = (RealType)i * binWidth_; |
| 304 |
|
|
RealType router = (RealType)(i+1) * binWidth_; |
| 305 |
|
|
if (binDof[i] > 0) { |
| 306 |
|
|
RealType temp = 2.0 * binKE[i] / (binDof[i] * PhysicalConstants::kb * |
| 307 |
|
|
PhysicalConstants::energyConvert); |
| 308 |
|
|
RealType den = binMass[i] * 3.0 * PhysicalConstants::densityConvert |
| 309 |
|
|
/ (4.0 * M_PI * (pow(router,3) - pow(rinner,3))); |
| 310 |
|
|
Vector3d aVel = binaVel[i] / RealType(binCount[i]); |
| 311 |
|
|
dynamic_cast<Accumulator *>(temperature->accumulator[i])->add(temp); |
| 312 |
|
|
dynamic_cast<VectorAccumulator *>(angularVelocity->accumulator[i])->add(aVel); |
| 313 |
|
|
dynamic_cast<Accumulator *>(density->accumulator[i])->add(den); |
| 314 |
|
|
dynamic_cast<Accumulator *>(counts_->accumulator[i])->add(1); |
| 315 |
|
|
} |
| 316 |
|
|
} |
| 317 |
|
|
} |
| 318 |
gezelter |
1865 |
|
| 319 |
gezelter |
1887 |
|
| 320 |
|
|
void RNEMDR::processStuntDouble(StuntDouble* sd, int bin) { |
| 321 |
gezelter |
1865 |
} |
| 322 |
|
|
} |
| 323 |
|
|
|