| 1 |
/* |
| 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 |
#include "utils/PhysicalConstants.hpp" |
| 47 |
|
| 48 |
namespace OpenMD { |
| 49 |
|
| 50 |
RNEMDZ::RNEMDZ(SimInfo* info, const std::string& filename, |
| 51 |
const std::string& sele, int nzbins) |
| 52 |
: SlabStatistics(info, filename, sele, nzbins) { |
| 53 |
|
| 54 |
setOutputName(getPrefix(filename) + ".rnemdZ"); |
| 55 |
|
| 56 |
temperature = new OutputData; |
| 57 |
temperature->units = "K"; |
| 58 |
temperature->title = "Temperature"; |
| 59 |
temperature->dataType = odtReal; |
| 60 |
temperature->dataHandling = odhAverage; |
| 61 |
temperature->accumulator.reserve(nBins_); |
| 62 |
for (int i = 0; i < nBins_; i++) |
| 63 |
temperature->accumulator.push_back( new Accumulator() ); |
| 64 |
data_.push_back(temperature); |
| 65 |
|
| 66 |
velocity = new OutputData; |
| 67 |
velocity->units = "angstroms/fs"; |
| 68 |
velocity->title = "Velocity"; |
| 69 |
velocity->dataType = odtVector3; |
| 70 |
velocity->dataHandling = odhAverage; |
| 71 |
velocity->accumulator.reserve(nBins_); |
| 72 |
for (int i = 0; i < nBins_; i++) |
| 73 |
velocity->accumulator.push_back( new VectorAccumulator() ); |
| 74 |
data_.push_back(velocity); |
| 75 |
|
| 76 |
density = new OutputData; |
| 77 |
density->units = "g cm^-3"; |
| 78 |
density->title = "Density"; |
| 79 |
density->dataType = odtReal; |
| 80 |
density->dataHandling = odhAverage; |
| 81 |
density->accumulator.reserve(nBins_); |
| 82 |
for (int i = 0; i < nBins_; i++) |
| 83 |
density->accumulator.push_back( new Accumulator() ); |
| 84 |
data_.push_back(density); |
| 85 |
} |
| 86 |
|
| 87 |
void RNEMDZ::processStuntDouble(StuntDouble* sd, int bin) { |
| 88 |
RealType mass = sd->getMass(); |
| 89 |
Vector3d pos = sd->getPos(); |
| 90 |
Vector3d vel = sd->getVel(); |
| 91 |
RealType KE = 0.5 * (mass * vel.lengthSquare()); |
| 92 |
int dof = 3; |
| 93 |
|
| 94 |
if (sd->isDirectional()) { |
| 95 |
Vector3d angMom = sd->getJ(); |
| 96 |
Mat3x3d I = sd->getI(); |
| 97 |
if (sd->isLinear()) { |
| 98 |
int i = sd->linearAxis(); |
| 99 |
int j = (i + 1) % 3; |
| 100 |
int k = (i + 2) % 3; |
| 101 |
KE += 0.5 * (angMom[j] * angMom[j] / I(j, j) + |
| 102 |
angMom[k] * angMom[k] / I(k, k)); |
| 103 |
dof += 2; |
| 104 |
} else { |
| 105 |
KE += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + |
| 106 |
angMom[1] * angMom[1] / I(1, 1) + |
| 107 |
angMom[2] * angMom[2] / I(2, 2)); |
| 108 |
dof += 3; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
RealType temp = 2.0 * KE / (dof * PhysicalConstants::kb * |
| 113 |
PhysicalConstants::energyConvert); |
| 114 |
RealType den = mass * nBins_ * PhysicalConstants::densityConvert / volume_; |
| 115 |
|
| 116 |
dynamic_cast<Accumulator *>(temperature->accumulator[bin])->add(temp); |
| 117 |
dynamic_cast<VectorAccumulator *>(velocity->accumulator[bin])->add(vel); |
| 118 |
dynamic_cast<Accumulator *>(density->accumulator[bin])->add(den); |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
RNEMDR::RNEMDR(SimInfo* info, const std::string& filename, |
| 123 |
const std::string& sele, int nrbins) |
| 124 |
: ShellStatistics(info, filename, sele, nrbins) { |
| 125 |
|
| 126 |
|
| 127 |
setOutputName(getPrefix(filename) + ".rnemdR"); |
| 128 |
|
| 129 |
temperature = new OutputData; |
| 130 |
temperature->units = "K"; |
| 131 |
temperature->title = "Temperature"; |
| 132 |
temperature->dataType = odtReal; |
| 133 |
temperature->dataHandling = odhAverage; |
| 134 |
temperature->accumulator.reserve(nBins_); |
| 135 |
for (int i = 0; i < nBins_; i++) |
| 136 |
temperature->accumulator.push_back( new Accumulator() ); |
| 137 |
data_.push_back(temperature); |
| 138 |
|
| 139 |
angularVelocity = new OutputData; |
| 140 |
angularVelocity->units = "angstroms^2/fs"; |
| 141 |
angularVelocity->title = "Velocity"; |
| 142 |
angularVelocity->dataType = odtVector3; |
| 143 |
angularVelocity->dataHandling = odhAverage; |
| 144 |
angularVelocity->accumulator.reserve(nBins_); |
| 145 |
for (int i = 0; i < nBins_; i++) |
| 146 |
angularVelocity->accumulator.push_back( new VectorAccumulator() ); |
| 147 |
data_.push_back(angularVelocity); |
| 148 |
|
| 149 |
density = new OutputData; |
| 150 |
density->units = "g cm^-3"; |
| 151 |
density->title = "Density"; |
| 152 |
density->dataType = odtReal; |
| 153 |
density->dataHandling = odhAverage; |
| 154 |
density->accumulator.reserve(nBins_); |
| 155 |
for (int i = 0; i < nBins_; i++) |
| 156 |
density->accumulator.push_back( new Accumulator() ); |
| 157 |
data_.push_back(density); |
| 158 |
} |
| 159 |
|
| 160 |
void RNEMDR::processStuntDouble(StuntDouble* sd, int bin) { |
| 161 |
RealType mass = sd->getMass(); |
| 162 |
Vector3d vel = sd->getVel(); |
| 163 |
Vector3d rPos = sd->getPos() - coordinateOrigin_; |
| 164 |
Vector3d aVel = cross(rPos, vel); |
| 165 |
|
| 166 |
RealType KE = 0.5 * (mass * vel.lengthSquare()); |
| 167 |
int dof = 3; |
| 168 |
|
| 169 |
if (sd->isDirectional()) { |
| 170 |
Vector3d angMom = sd->getJ(); |
| 171 |
Mat3x3d I = sd->getI(); |
| 172 |
if (sd->isLinear()) { |
| 173 |
int i = sd->linearAxis(); |
| 174 |
int j = (i + 1) % 3; |
| 175 |
int k = (i + 2) % 3; |
| 176 |
KE += 0.5 * (angMom[j] * angMom[j] / I(j, j) + |
| 177 |
angMom[k] * angMom[k] / I(k, k)); |
| 178 |
dof += 2; |
| 179 |
} else { |
| 180 |
KE += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + |
| 181 |
angMom[1] * angMom[1] / I(1, 1) + |
| 182 |
angMom[2] * angMom[2] / I(2, 2)); |
| 183 |
dof += 3; |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
RealType temp = 2.0 * KE / (dof * PhysicalConstants::kb * |
| 188 |
PhysicalConstants::energyConvert); |
| 189 |
|
| 190 |
RealType rinner = (RealType)bin * binWidth_; |
| 191 |
RealType router = (RealType)(bin+1) * binWidth_; |
| 192 |
RealType den = mass * 3.0 * PhysicalConstants::densityConvert |
| 193 |
/ (4.0 * M_PI * (pow(router,3) - pow(rinner,3))); |
| 194 |
|
| 195 |
dynamic_cast<Accumulator *>(temperature->accumulator[bin])->add(temp); |
| 196 |
dynamic_cast<VectorAccumulator *>(angularVelocity->accumulator[bin])->add(aVel); |
| 197 |
dynamic_cast<Accumulator *>(density->accumulator[bin])->add(den); |
| 198 |
|
| 199 |
} |
| 200 |
} |
| 201 |
|