| 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 |
< |
* [4] Vardeman & Gezelter, in progress (2009). |
| 38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
| 39 |
> |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
> |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
|
*/ |
| 41 |
– |
|
| 42 |
– |
#include <math.h> |
| 43 |
– |
#include <iostream> |
| 42 |
|
|
| 43 |
|
#ifdef IS_MPI |
| 44 |
|
#include <mpi.h> |
| 45 |
|
#endif //is_mpi |
| 46 |
+ |
|
| 47 |
+ |
#include <math.h> |
| 48 |
+ |
#include <iostream> |
| 49 |
|
|
| 50 |
|
#include "brains/Thermo.hpp" |
| 51 |
|
#include "primitives/Molecule.hpp" |
| 52 |
|
#include "utils/simError.h" |
| 53 |
|
#include "utils/PhysicalConstants.hpp" |
| 54 |
+ |
#include "types/FixedChargeAdapter.hpp" |
| 55 |
+ |
#include "types/FluctuatingChargeAdapter.hpp" |
| 56 |
+ |
#include "types/MultipoleAdapter.hpp" |
| 57 |
+ |
#ifdef HAVE_QHULL |
| 58 |
+ |
#include "math/ConvexHull.hpp" |
| 59 |
+ |
#include "math/AlphaHull.hpp" |
| 60 |
+ |
#endif |
| 61 |
|
|
| 62 |
+ |
using namespace std; |
| 63 |
|
namespace OpenMD { |
| 64 |
|
|
| 65 |
< |
RealType Thermo::getKinetic() { |
| 66 |
< |
SimInfo::MoleculeIterator miter; |
| 67 |
< |
std::vector<StuntDouble*>::iterator iiter; |
| 68 |
< |
Molecule* mol; |
| 69 |
< |
StuntDouble* integrableObject; |
| 70 |
< |
Vector3d vel; |
| 71 |
< |
Vector3d angMom; |
| 72 |
< |
Mat3x3d I; |
| 73 |
< |
int i; |
| 74 |
< |
int j; |
| 75 |
< |
int k; |
| 76 |
< |
RealType mass; |
| 77 |
< |
RealType kinetic = 0.0; |
| 78 |
< |
RealType kinetic_global = 0.0; |
| 70 |
< |
|
| 71 |
< |
for (mol = info_->beginMolecule(miter); mol != NULL; mol = info_->nextMolecule(miter)) { |
| 72 |
< |
for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; |
| 73 |
< |
integrableObject = mol->nextIntegrableObject(iiter)) { |
| 65 |
> |
RealType Thermo::getTranslationalKinetic() { |
| 66 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 67 |
> |
|
| 68 |
> |
if (!snap->hasTranslationalKineticEnergy) { |
| 69 |
> |
SimInfo::MoleculeIterator miter; |
| 70 |
> |
vector<StuntDouble*>::iterator iiter; |
| 71 |
> |
Molecule* mol; |
| 72 |
> |
StuntDouble* sd; |
| 73 |
> |
Vector3d vel; |
| 74 |
> |
RealType mass; |
| 75 |
> |
RealType kinetic(0.0); |
| 76 |
> |
|
| 77 |
> |
for (mol = info_->beginMolecule(miter); mol != NULL; |
| 78 |
> |
mol = info_->nextMolecule(miter)) { |
| 79 |
|
|
| 80 |
< |
mass = integrableObject->getMass(); |
| 81 |
< |
vel = integrableObject->getVel(); |
| 82 |
< |
|
| 83 |
< |
kinetic += mass * (vel[0]*vel[0] + vel[1]*vel[1] + vel[2]*vel[2]); |
| 84 |
< |
|
| 85 |
< |
if (integrableObject->isDirectional()) { |
| 86 |
< |
angMom = integrableObject->getJ(); |
| 87 |
< |
I = integrableObject->getI(); |
| 80 |
> |
for (sd = mol->beginIntegrableObject(iiter); sd != NULL; |
| 81 |
> |
sd = mol->nextIntegrableObject(iiter)) { |
| 82 |
> |
|
| 83 |
> |
mass = sd->getMass(); |
| 84 |
> |
vel = sd->getVel(); |
| 85 |
> |
|
| 86 |
> |
kinetic += mass * (vel[0]*vel[0] + vel[1]*vel[1] + vel[2]*vel[2]); |
| 87 |
> |
|
| 88 |
> |
} |
| 89 |
> |
} |
| 90 |
> |
|
| 91 |
> |
#ifdef IS_MPI |
| 92 |
> |
MPI_Allreduce(MPI_IN_PLACE, &kinetic, 1, MPI_REALTYPE, |
| 93 |
> |
MPI_SUM, MPI_COMM_WORLD); |
| 94 |
> |
#endif |
| 95 |
> |
|
| 96 |
> |
kinetic = kinetic * 0.5 / PhysicalConstants::energyConvert; |
| 97 |
> |
|
| 98 |
> |
|
| 99 |
> |
snap->setTranslationalKineticEnergy(kinetic); |
| 100 |
> |
} |
| 101 |
> |
return snap->getTranslationalKineticEnergy(); |
| 102 |
> |
} |
| 103 |
|
|
| 104 |
< |
if (integrableObject->isLinear()) { |
| 105 |
< |
i = integrableObject->linearAxis(); |
| 106 |
< |
j = (i + 1) % 3; |
| 107 |
< |
k = (i + 2) % 3; |
| 108 |
< |
kinetic += angMom[j] * angMom[j] / I(j, j) + angMom[k] * angMom[k] / I(k, k); |
| 109 |
< |
} else { |
| 110 |
< |
kinetic += angMom[0]*angMom[0]/I(0, 0) + angMom[1]*angMom[1]/I(1, 1) |
| 111 |
< |
+ angMom[2]*angMom[2]/I(2, 2); |
| 112 |
< |
} |
| 113 |
< |
} |
| 104 |
> |
RealType Thermo::getRotationalKinetic() { |
| 105 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 106 |
> |
|
| 107 |
> |
if (!snap->hasRotationalKineticEnergy) { |
| 108 |
> |
SimInfo::MoleculeIterator miter; |
| 109 |
> |
vector<StuntDouble*>::iterator iiter; |
| 110 |
> |
Molecule* mol; |
| 111 |
> |
StuntDouble* sd; |
| 112 |
> |
Vector3d angMom; |
| 113 |
> |
Mat3x3d I; |
| 114 |
> |
int i, j, k; |
| 115 |
> |
RealType kinetic(0.0); |
| 116 |
> |
|
| 117 |
> |
for (mol = info_->beginMolecule(miter); mol != NULL; |
| 118 |
> |
mol = info_->nextMolecule(miter)) { |
| 119 |
> |
|
| 120 |
> |
for (sd = mol->beginIntegrableObject(iiter); sd != NULL; |
| 121 |
> |
sd = mol->nextIntegrableObject(iiter)) { |
| 122 |
> |
|
| 123 |
> |
if (sd->isDirectional()) { |
| 124 |
> |
angMom = sd->getJ(); |
| 125 |
> |
I = sd->getI(); |
| 126 |
|
|
| 127 |
+ |
if (sd->isLinear()) { |
| 128 |
+ |
i = sd->linearAxis(); |
| 129 |
+ |
j = (i + 1) % 3; |
| 130 |
+ |
k = (i + 2) % 3; |
| 131 |
+ |
kinetic += angMom[j] * angMom[j] / I(j, j) |
| 132 |
+ |
+ angMom[k] * angMom[k] / I(k, k); |
| 133 |
+ |
} else { |
| 134 |
+ |
kinetic += angMom[0]*angMom[0]/I(0, 0) |
| 135 |
+ |
+ angMom[1]*angMom[1]/I(1, 1) |
| 136 |
+ |
+ angMom[2]*angMom[2]/I(2, 2); |
| 137 |
+ |
} |
| 138 |
+ |
} |
| 139 |
+ |
} |
| 140 |
|
} |
| 141 |
< |
} |
| 97 |
< |
|
| 141 |
> |
|
| 142 |
|
#ifdef IS_MPI |
| 143 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &kinetic, 1, MPI_REALTYPE, |
| 144 |
+ |
MPI_SUM, MPI_COMM_WORLD); |
| 145 |
+ |
#endif |
| 146 |
+ |
|
| 147 |
+ |
kinetic = kinetic * 0.5 / PhysicalConstants::energyConvert; |
| 148 |
+ |
|
| 149 |
+ |
snap->setRotationalKineticEnergy(kinetic); |
| 150 |
+ |
} |
| 151 |
+ |
return snap->getRotationalKineticEnergy(); |
| 152 |
+ |
} |
| 153 |
|
|
| 154 |
< |
MPI_Allreduce(&kinetic, &kinetic_global, 1, MPI_REALTYPE, MPI_SUM, |
| 101 |
< |
MPI_COMM_WORLD); |
| 102 |
< |
kinetic = kinetic_global; |
| 154 |
> |
|
| 155 |
|
|
| 156 |
< |
#endif //is_mpi |
| 156 |
> |
RealType Thermo::getKinetic() { |
| 157 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 158 |
|
|
| 159 |
< |
kinetic = kinetic * 0.5 / PhysicalConstants::energyConvert; |
| 160 |
< |
|
| 161 |
< |
return kinetic; |
| 159 |
> |
if (!snap->hasKineticEnergy) { |
| 160 |
> |
RealType ke = getTranslationalKinetic() + getRotationalKinetic(); |
| 161 |
> |
snap->setKineticEnergy(ke); |
| 162 |
> |
} |
| 163 |
> |
return snap->getKineticEnergy(); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
RealType Thermo::getPotential() { |
| 112 |
– |
RealType potential = 0.0; |
| 113 |
– |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 114 |
– |
RealType shortRangePot_local = curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] ; |
| 167 |
|
|
| 168 |
< |
// Get total potential for entire system from MPI. |
| 168 |
> |
// ForceManager computes the potential and stores it in the |
| 169 |
> |
// Snapshot. All we have to do is report it. |
| 170 |
|
|
| 171 |
< |
#ifdef IS_MPI |
| 171 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 172 |
> |
return snap->getPotentialEnergy(); |
| 173 |
> |
} |
| 174 |
|
|
| 175 |
< |
MPI_Allreduce(&shortRangePot_local, &potential, 1, MPI_REALTYPE, MPI_SUM, |
| 121 |
< |
MPI_COMM_WORLD); |
| 122 |
< |
potential += curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL]; |
| 175 |
> |
RealType Thermo::getTotalEnergy() { |
| 176 |
|
|
| 177 |
< |
#else |
| 177 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 178 |
|
|
| 179 |
< |
potential = shortRangePot_local + curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL]; |
| 179 |
> |
if (!snap->hasTotalEnergy) { |
| 180 |
> |
snap->setTotalEnergy(this->getKinetic() + this->getPotential()); |
| 181 |
> |
} |
| 182 |
|
|
| 183 |
< |
#endif // is_mpi |
| 129 |
< |
|
| 130 |
< |
return potential; |
| 183 |
> |
return snap->getTotalEnergy(); |
| 184 |
|
} |
| 185 |
|
|
| 133 |
– |
RealType Thermo::getTotalE() { |
| 134 |
– |
RealType total; |
| 135 |
– |
|
| 136 |
– |
total = this->getKinetic() + this->getPotential(); |
| 137 |
– |
return total; |
| 138 |
– |
} |
| 139 |
– |
|
| 186 |
|
RealType Thermo::getTemperature() { |
| 141 |
– |
|
| 142 |
– |
RealType temperature = ( 2.0 * this->getKinetic() ) / (info_->getNdf()* PhysicalConstants::kb ); |
| 143 |
– |
return temperature; |
| 144 |
– |
} |
| 187 |
|
|
| 188 |
< |
RealType Thermo::getVolume() { |
| 147 |
< |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 148 |
< |
return curSnapshot->getVolume(); |
| 149 |
< |
} |
| 188 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 189 |
|
|
| 190 |
< |
RealType Thermo::getPressure() { |
| 190 |
> |
if (!snap->hasTemperature) { |
| 191 |
|
|
| 192 |
< |
// Relies on the calculation of the full molecular pressure tensor |
| 192 |
> |
RealType temperature = ( 2.0 * this->getKinetic() ) |
| 193 |
> |
/ (info_->getNdf()* PhysicalConstants::kb ); |
| 194 |
|
|
| 195 |
+ |
snap->setTemperature(temperature); |
| 196 |
+ |
} |
| 197 |
+ |
|
| 198 |
+ |
return snap->getTemperature(); |
| 199 |
+ |
} |
| 200 |
|
|
| 201 |
< |
Mat3x3d tensor; |
| 202 |
< |
RealType pressure; |
| 201 |
> |
RealType Thermo::getElectronicTemperature() { |
| 202 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 203 |
|
|
| 204 |
< |
tensor = getPressureTensor(); |
| 204 |
> |
if (!snap->hasElectronicTemperature) { |
| 205 |
> |
|
| 206 |
> |
SimInfo::MoleculeIterator miter; |
| 207 |
> |
vector<Atom*>::iterator iiter; |
| 208 |
> |
Molecule* mol; |
| 209 |
> |
Atom* atom; |
| 210 |
> |
RealType cvel; |
| 211 |
> |
RealType cmass; |
| 212 |
> |
RealType kinetic(0.0); |
| 213 |
> |
RealType eTemp; |
| 214 |
> |
|
| 215 |
> |
for (mol = info_->beginMolecule(miter); mol != NULL; |
| 216 |
> |
mol = info_->nextMolecule(miter)) { |
| 217 |
> |
|
| 218 |
> |
for (atom = mol->beginFluctuatingCharge(iiter); atom != NULL; |
| 219 |
> |
atom = mol->nextFluctuatingCharge(iiter)) { |
| 220 |
> |
|
| 221 |
> |
cmass = atom->getChargeMass(); |
| 222 |
> |
cvel = atom->getFlucQVel(); |
| 223 |
> |
|
| 224 |
> |
kinetic += cmass * cvel * cvel; |
| 225 |
> |
|
| 226 |
> |
} |
| 227 |
> |
} |
| 228 |
> |
|
| 229 |
> |
#ifdef IS_MPI |
| 230 |
> |
MPI_Allreduce(MPI_IN_PLACE, &kinetic, 1, MPI_REALTYPE, |
| 231 |
> |
MPI_SUM, MPI_COMM_WORLD); |
| 232 |
> |
#endif |
| 233 |
|
|
| 234 |
< |
pressure = PhysicalConstants::pressureConvert * (tensor(0, 0) + tensor(1, 1) + tensor(2, 2)) / 3.0; |
| 234 |
> |
kinetic *= 0.5; |
| 235 |
> |
eTemp = (2.0 * kinetic) / |
| 236 |
> |
(info_->getNFluctuatingCharges() * PhysicalConstants::kb ); |
| 237 |
> |
|
| 238 |
> |
snap->setElectronicTemperature(eTemp); |
| 239 |
> |
} |
| 240 |
|
|
| 241 |
< |
return pressure; |
| 241 |
> |
return snap->getElectronicTemperature(); |
| 242 |
|
} |
| 243 |
|
|
| 166 |
– |
RealType Thermo::getPressure(int direction) { |
| 244 |
|
|
| 245 |
< |
// Relies on the calculation of the full molecular pressure tensor |
| 245 |
> |
RealType Thermo::getVolume() { |
| 246 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 247 |
> |
return snap->getVolume(); |
| 248 |
> |
} |
| 249 |
|
|
| 250 |
< |
|
| 251 |
< |
Mat3x3d tensor; |
| 172 |
< |
RealType pressure; |
| 250 |
> |
RealType Thermo::getPressure() { |
| 251 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 252 |
|
|
| 253 |
< |
tensor = getPressureTensor(); |
| 254 |
< |
|
| 255 |
< |
pressure = PhysicalConstants::pressureConvert * tensor(direction, direction); |
| 256 |
< |
|
| 257 |
< |
return pressure; |
| 253 |
> |
if (!snap->hasPressure) { |
| 254 |
> |
// Relies on the calculation of the full molecular pressure tensor |
| 255 |
> |
|
| 256 |
> |
Mat3x3d tensor; |
| 257 |
> |
RealType pressure; |
| 258 |
> |
|
| 259 |
> |
tensor = getPressureTensor(); |
| 260 |
> |
|
| 261 |
> |
pressure = PhysicalConstants::pressureConvert * |
| 262 |
> |
(tensor(0, 0) + tensor(1, 1) + tensor(2, 2)) / 3.0; |
| 263 |
> |
|
| 264 |
> |
snap->setPressure(pressure); |
| 265 |
> |
} |
| 266 |
> |
|
| 267 |
> |
return snap->getPressure(); |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
Mat3x3d Thermo::getPressureTensor() { |
| 271 |
|
// returns pressure tensor in units amu*fs^-2*Ang^-1 |
| 272 |
|
// routine derived via viral theorem description in: |
| 273 |
|
// Paci, E. and Marchi, M. J.Phys.Chem. 1996, 100, 4314-4322 |
| 274 |
< |
Mat3x3d pressureTensor; |
| 186 |
< |
Mat3x3d p_local(0.0); |
| 187 |
< |
Mat3x3d p_global(0.0); |
| 274 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 275 |
|
|
| 276 |
< |
SimInfo::MoleculeIterator i; |
| 190 |
< |
std::vector<StuntDouble*>::iterator j; |
| 191 |
< |
Molecule* mol; |
| 192 |
< |
StuntDouble* integrableObject; |
| 193 |
< |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
| 194 |
< |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
| 195 |
< |
integrableObject = mol->nextIntegrableObject(j)) { |
| 276 |
> |
if (!snap->hasPressureTensor) { |
| 277 |
|
|
| 278 |
< |
RealType mass = integrableObject->getMass(); |
| 279 |
< |
Vector3d vcom = integrableObject->getVel(); |
| 280 |
< |
p_local += mass * outProduct(vcom, vcom); |
| 278 |
> |
Mat3x3d pressureTensor; |
| 279 |
> |
Mat3x3d p_tens(0.0); |
| 280 |
> |
RealType mass; |
| 281 |
> |
Vector3d vcom; |
| 282 |
> |
|
| 283 |
> |
SimInfo::MoleculeIterator i; |
| 284 |
> |
vector<StuntDouble*>::iterator j; |
| 285 |
> |
Molecule* mol; |
| 286 |
> |
StuntDouble* sd; |
| 287 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 288 |
> |
mol = info_->nextMolecule(i)) { |
| 289 |
> |
|
| 290 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
| 291 |
> |
sd = mol->nextIntegrableObject(j)) { |
| 292 |
> |
|
| 293 |
> |
mass = sd->getMass(); |
| 294 |
> |
vcom = sd->getVel(); |
| 295 |
> |
p_tens += mass * outProduct(vcom, vcom); |
| 296 |
> |
} |
| 297 |
|
} |
| 298 |
+ |
|
| 299 |
+ |
#ifdef IS_MPI |
| 300 |
+ |
MPI_Allreduce(MPI_IN_PLACE, p_tens.getArrayPointer(), 9, |
| 301 |
+ |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 302 |
+ |
#endif |
| 303 |
+ |
|
| 304 |
+ |
RealType volume = this->getVolume(); |
| 305 |
+ |
Mat3x3d stressTensor = snap->getStressTensor(); |
| 306 |
+ |
|
| 307 |
+ |
pressureTensor = (p_tens + |
| 308 |
+ |
PhysicalConstants::energyConvert * stressTensor)/volume; |
| 309 |
+ |
|
| 310 |
+ |
snap->setPressureTensor(pressureTensor); |
| 311 |
|
} |
| 312 |
< |
|
| 312 |
> |
return snap->getPressureTensor(); |
| 313 |
> |
} |
| 314 |
> |
|
| 315 |
> |
|
| 316 |
> |
|
| 317 |
> |
|
| 318 |
> |
Vector3d Thermo::getSystemDipole() { |
| 319 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 320 |
> |
|
| 321 |
> |
if (!snap->hasSystemDipole) { |
| 322 |
> |
SimInfo::MoleculeIterator miter; |
| 323 |
> |
vector<Atom*>::iterator aiter; |
| 324 |
> |
Molecule* mol; |
| 325 |
> |
Atom* atom; |
| 326 |
> |
RealType charge; |
| 327 |
> |
Vector3d ri(0.0); |
| 328 |
> |
Vector3d dipoleVector(0.0); |
| 329 |
> |
Vector3d nPos(0.0); |
| 330 |
> |
Vector3d pPos(0.0); |
| 331 |
> |
RealType nChg(0.0); |
| 332 |
> |
RealType pChg(0.0); |
| 333 |
> |
int nCount = 0; |
| 334 |
> |
int pCount = 0; |
| 335 |
> |
|
| 336 |
> |
RealType chargeToC = 1.60217733e-19; |
| 337 |
> |
RealType angstromToM = 1.0e-10; |
| 338 |
> |
RealType debyeToCm = 3.33564095198e-30; |
| 339 |
> |
|
| 340 |
> |
for (mol = info_->beginMolecule(miter); mol != NULL; |
| 341 |
> |
mol = info_->nextMolecule(miter)) { |
| 342 |
> |
|
| 343 |
> |
for (atom = mol->beginAtom(aiter); atom != NULL; |
| 344 |
> |
atom = mol->nextAtom(aiter)) { |
| 345 |
> |
|
| 346 |
> |
charge = 0.0; |
| 347 |
> |
|
| 348 |
> |
FixedChargeAdapter fca = FixedChargeAdapter(atom->getAtomType()); |
| 349 |
> |
if ( fca.isFixedCharge() ) { |
| 350 |
> |
charge = fca.getCharge(); |
| 351 |
> |
} |
| 352 |
> |
|
| 353 |
> |
FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atom->getAtomType()); |
| 354 |
> |
if ( fqa.isFluctuatingCharge() ) { |
| 355 |
> |
charge += atom->getFlucQPos(); |
| 356 |
> |
} |
| 357 |
> |
|
| 358 |
> |
charge *= chargeToC; |
| 359 |
> |
|
| 360 |
> |
ri = atom->getPos(); |
| 361 |
> |
snap->wrapVector(ri); |
| 362 |
> |
ri *= angstromToM; |
| 363 |
> |
|
| 364 |
> |
if (charge < 0.0) { |
| 365 |
> |
nPos += ri; |
| 366 |
> |
nChg -= charge; |
| 367 |
> |
nCount++; |
| 368 |
> |
} else if (charge > 0.0) { |
| 369 |
> |
pPos += ri; |
| 370 |
> |
pChg += charge; |
| 371 |
> |
pCount++; |
| 372 |
> |
} |
| 373 |
> |
|
| 374 |
> |
if (atom->isDipole()) { |
| 375 |
> |
dipoleVector += atom->getDipole() * debyeToCm; |
| 376 |
> |
} |
| 377 |
> |
} |
| 378 |
> |
} |
| 379 |
> |
|
| 380 |
> |
|
| 381 |
|
#ifdef IS_MPI |
| 382 |
< |
MPI_Allreduce(p_local.getArrayPointer(), p_global.getArrayPointer(), 9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 383 |
< |
#else |
| 384 |
< |
p_global = p_local; |
| 385 |
< |
#endif // is_mpi |
| 382 |
> |
MPI_Allreduce(MPI_IN_PLACE, &pChg, 1, MPI_REALTYPE, |
| 383 |
> |
MPI_SUM, MPI_COMM_WORLD); |
| 384 |
> |
MPI_Allreduce(MPI_IN_PLACE, &nChg, 1, MPI_REALTYPE, |
| 385 |
> |
MPI_SUM, MPI_COMM_WORLD); |
| 386 |
> |
|
| 387 |
> |
MPI_Allreduce(MPI_IN_PLACE, &pCount, 1, MPI_INTEGER, |
| 388 |
> |
MPI_SUM, MPI_COMM_WORLD); |
| 389 |
> |
MPI_Allreduce(MPI_IN_PLACE, &nCount, 1, MPI_INTEGER, |
| 390 |
> |
MPI_SUM, MPI_COMM_WORLD); |
| 391 |
> |
|
| 392 |
> |
MPI_Allreduce(MPI_IN_PLACE, pPos.getArrayPointer(), 3, |
| 393 |
> |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 394 |
> |
MPI_Allreduce(MPI_IN_PLACE, nPos.getArrayPointer(), 3, |
| 395 |
> |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 396 |
|
|
| 397 |
< |
RealType volume = this->getVolume(); |
| 398 |
< |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 399 |
< |
Mat3x3d tau = curSnapshot->statData.getTau(); |
| 397 |
> |
MPI_Allreduce(MPI_IN_PLACE, dipoleVector.getArrayPointer(), |
| 398 |
> |
3, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 399 |
> |
#endif |
| 400 |
> |
|
| 401 |
> |
// first load the accumulated dipole moment (if dipoles were present) |
| 402 |
> |
Vector3d boxDipole = dipoleVector; |
| 403 |
> |
// now include the dipole moment due to charges |
| 404 |
> |
// use the lesser of the positive and negative charge totals |
| 405 |
> |
RealType chg_value = nChg <= pChg ? nChg : pChg; |
| 406 |
> |
|
| 407 |
> |
// find the average positions |
| 408 |
> |
if (pCount > 0 && nCount > 0 ) { |
| 409 |
> |
pPos /= pCount; |
| 410 |
> |
nPos /= nCount; |
| 411 |
> |
} |
| 412 |
> |
|
| 413 |
> |
// dipole is from the negative to the positive (physics notation) |
| 414 |
> |
boxDipole += (pPos - nPos) * chg_value; |
| 415 |
> |
snap->setSystemDipole(boxDipole); |
| 416 |
> |
} |
| 417 |
|
|
| 418 |
< |
pressureTensor = (p_global + PhysicalConstants::energyConvert* tau)/volume; |
| 214 |
< |
|
| 215 |
< |
return pressureTensor; |
| 418 |
> |
return snap->getSystemDipole(); |
| 419 |
|
} |
| 420 |
|
|
| 421 |
|
|
| 422 |
< |
void Thermo::saveStat(){ |
| 423 |
< |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 221 |
< |
Stats& stat = currSnapshot->statData; |
| 222 |
< |
|
| 223 |
< |
stat[Stats::KINETIC_ENERGY] = getKinetic(); |
| 224 |
< |
stat[Stats::POTENTIAL_ENERGY] = getPotential(); |
| 225 |
< |
stat[Stats::TOTAL_ENERGY] = stat[Stats::KINETIC_ENERGY] + stat[Stats::POTENTIAL_ENERGY] ; |
| 226 |
< |
stat[Stats::TEMPERATURE] = getTemperature(); |
| 227 |
< |
stat[Stats::PRESSURE] = getPressure(); |
| 228 |
< |
stat[Stats::VOLUME] = getVolume(); |
| 422 |
> |
Mat3x3d Thermo::getSystemQuadrupole() { |
| 423 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 424 |
|
|
| 425 |
< |
Mat3x3d tensor =getPressureTensor(); |
| 426 |
< |
stat[Stats::PRESSURE_TENSOR_XX] = tensor(0, 0); |
| 427 |
< |
stat[Stats::PRESSURE_TENSOR_XY] = tensor(0, 1); |
| 428 |
< |
stat[Stats::PRESSURE_TENSOR_XZ] = tensor(0, 2); |
| 429 |
< |
stat[Stats::PRESSURE_TENSOR_YX] = tensor(1, 0); |
| 430 |
< |
stat[Stats::PRESSURE_TENSOR_YY] = tensor(1, 1); |
| 431 |
< |
stat[Stats::PRESSURE_TENSOR_YZ] = tensor(1, 2); |
| 432 |
< |
stat[Stats::PRESSURE_TENSOR_ZX] = tensor(2, 0); |
| 433 |
< |
stat[Stats::PRESSURE_TENSOR_ZY] = tensor(2, 1); |
| 434 |
< |
stat[Stats::PRESSURE_TENSOR_ZZ] = tensor(2, 2); |
| 425 |
> |
if (!snap->hasSystemQuadrupole) { |
| 426 |
> |
SimInfo::MoleculeIterator miter; |
| 427 |
> |
vector<Atom*>::iterator aiter; |
| 428 |
> |
Molecule* mol; |
| 429 |
> |
Atom* atom; |
| 430 |
> |
RealType charge; |
| 431 |
> |
Vector3d ri(0.0); |
| 432 |
> |
Vector3d dipole(0.0); |
| 433 |
> |
Mat3x3d qpole(0.0); |
| 434 |
> |
|
| 435 |
> |
RealType chargeToC = 1.60217733e-19; |
| 436 |
> |
RealType angstromToM = 1.0e-10; |
| 437 |
> |
RealType debyeToCm = 3.33564095198e-30; |
| 438 |
> |
|
| 439 |
> |
for (mol = info_->beginMolecule(miter); mol != NULL; |
| 440 |
> |
mol = info_->nextMolecule(miter)) { |
| 441 |
> |
|
| 442 |
> |
for (atom = mol->beginAtom(aiter); atom != NULL; |
| 443 |
> |
atom = mol->nextAtom(aiter)) { |
| 444 |
|
|
| 445 |
+ |
ri = atom->getPos(); |
| 446 |
+ |
snap->wrapVector(ri); |
| 447 |
+ |
ri *= angstromToM; |
| 448 |
+ |
|
| 449 |
+ |
charge = 0.0; |
| 450 |
+ |
|
| 451 |
+ |
FixedChargeAdapter fca = FixedChargeAdapter(atom->getAtomType()); |
| 452 |
+ |
if ( fca.isFixedCharge() ) { |
| 453 |
+ |
charge = fca.getCharge(); |
| 454 |
+ |
} |
| 455 |
+ |
|
| 456 |
+ |
FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atom->getAtomType()); |
| 457 |
+ |
if ( fqa.isFluctuatingCharge() ) { |
| 458 |
+ |
charge += atom->getFlucQPos(); |
| 459 |
+ |
} |
| 460 |
+ |
|
| 461 |
+ |
charge *= chargeToC; |
| 462 |
+ |
|
| 463 |
+ |
qpole += 0.5 * charge * outProduct(ri, ri); |
| 464 |
|
|
| 465 |
< |
Globals* simParams = info_->getSimParams(); |
| 465 |
> |
MultipoleAdapter ma = MultipoleAdapter(atom->getAtomType()); |
| 466 |
> |
|
| 467 |
> |
if ( ma.isDipole() ) { |
| 468 |
> |
dipole = atom->getDipole() * debyeToCm; |
| 469 |
> |
qpole += 0.5 * outProduct( dipole, ri ); |
| 470 |
> |
} |
| 471 |
|
|
| 472 |
+ |
if ( ma.isQuadrupole() ) { |
| 473 |
+ |
qpole += atom->getQuadrupole() * debyeToCm * angstromToM; |
| 474 |
+ |
} |
| 475 |
+ |
} |
| 476 |
+ |
} |
| 477 |
+ |
|
| 478 |
+ |
#ifdef IS_MPI |
| 479 |
+ |
MPI_Allreduce(MPI_IN_PLACE, qpole.getArrayPointer(), |
| 480 |
+ |
9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 481 |
+ |
#endif |
| 482 |
+ |
|
| 483 |
+ |
snap->setSystemQuadrupole(qpole); |
| 484 |
+ |
} |
| 485 |
+ |
|
| 486 |
+ |
return snap->getSystemQuadrupole(); |
| 487 |
+ |
} |
| 488 |
+ |
|
| 489 |
+ |
// Returns the Heat Flux Vector for the system |
| 490 |
+ |
Vector3d Thermo::getHeatFlux(){ |
| 491 |
+ |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 492 |
+ |
SimInfo::MoleculeIterator miter; |
| 493 |
+ |
vector<StuntDouble*>::iterator iiter; |
| 494 |
+ |
Molecule* mol; |
| 495 |
+ |
StuntDouble* sd; |
| 496 |
+ |
RigidBody::AtomIterator ai; |
| 497 |
+ |
Atom* atom; |
| 498 |
+ |
Vector3d vel; |
| 499 |
+ |
Vector3d angMom; |
| 500 |
+ |
Mat3x3d I; |
| 501 |
+ |
int i; |
| 502 |
+ |
int j; |
| 503 |
+ |
int k; |
| 504 |
+ |
RealType mass; |
| 505 |
+ |
|
| 506 |
+ |
Vector3d x_a; |
| 507 |
+ |
RealType kinetic; |
| 508 |
+ |
RealType potential; |
| 509 |
+ |
RealType eatom; |
| 510 |
+ |
// Convective portion of the heat flux |
| 511 |
+ |
Vector3d heatFluxJc = V3Zero; |
| 512 |
+ |
|
| 513 |
+ |
/* Calculate convective portion of the heat flux */ |
| 514 |
+ |
for (mol = info_->beginMolecule(miter); mol != NULL; |
| 515 |
+ |
mol = info_->nextMolecule(miter)) { |
| 516 |
+ |
|
| 517 |
+ |
for (sd = mol->beginIntegrableObject(iiter); |
| 518 |
+ |
sd != NULL; |
| 519 |
+ |
sd = mol->nextIntegrableObject(iiter)) { |
| 520 |
+ |
|
| 521 |
+ |
mass = sd->getMass(); |
| 522 |
+ |
vel = sd->getVel(); |
| 523 |
+ |
|
| 524 |
+ |
kinetic = mass * (vel[0]*vel[0] + vel[1]*vel[1] + vel[2]*vel[2]); |
| 525 |
+ |
|
| 526 |
+ |
if (sd->isDirectional()) { |
| 527 |
+ |
angMom = sd->getJ(); |
| 528 |
+ |
I = sd->getI(); |
| 529 |
+ |
|
| 530 |
+ |
if (sd->isLinear()) { |
| 531 |
+ |
i = sd->linearAxis(); |
| 532 |
+ |
j = (i + 1) % 3; |
| 533 |
+ |
k = (i + 2) % 3; |
| 534 |
+ |
kinetic += angMom[j] * angMom[j] / I(j, j) |
| 535 |
+ |
+ angMom[k] * angMom[k] / I(k, k); |
| 536 |
+ |
} else { |
| 537 |
+ |
kinetic += angMom[0]*angMom[0]/I(0, 0) |
| 538 |
+ |
+ angMom[1]*angMom[1]/I(1, 1) |
| 539 |
+ |
+ angMom[2]*angMom[2]/I(2, 2); |
| 540 |
+ |
} |
| 541 |
+ |
} |
| 542 |
+ |
|
| 543 |
+ |
potential = 0.0; |
| 544 |
+ |
|
| 545 |
+ |
if (sd->isRigidBody()) { |
| 546 |
+ |
RigidBody* rb = dynamic_cast<RigidBody*>(sd); |
| 547 |
+ |
for (atom = rb->beginAtom(ai); atom != NULL; |
| 548 |
+ |
atom = rb->nextAtom(ai)) { |
| 549 |
+ |
potential += atom->getParticlePot(); |
| 550 |
+ |
} |
| 551 |
+ |
} else { |
| 552 |
+ |
potential = sd->getParticlePot(); |
| 553 |
+ |
} |
| 554 |
+ |
|
| 555 |
+ |
potential *= PhysicalConstants::energyConvert; // amu A^2/fs^2 |
| 556 |
+ |
// The potential may not be a 1/2 factor |
| 557 |
+ |
eatom = (kinetic + potential)/2.0; // amu A^2/fs^2 |
| 558 |
+ |
heatFluxJc[0] += eatom*vel[0]; // amu A^3/fs^3 |
| 559 |
+ |
heatFluxJc[1] += eatom*vel[1]; // amu A^3/fs^3 |
| 560 |
+ |
heatFluxJc[2] += eatom*vel[2]; // amu A^3/fs^3 |
| 561 |
+ |
} |
| 562 |
+ |
} |
| 563 |
+ |
|
| 564 |
+ |
/* The J_v vector is reduced in the forceManager so everyone has |
| 565 |
+ |
* the global Jv. Jc is computed over the local atoms and must be |
| 566 |
+ |
* reduced among all processors. |
| 567 |
+ |
*/ |
| 568 |
+ |
#ifdef IS_MPI |
| 569 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &heatFluxJc[0], 3, MPI_REALTYPE, |
| 570 |
+ |
MPI_SUM, MPI_COMM_WORLD); |
| 571 |
+ |
#endif |
| 572 |
+ |
|
| 573 |
+ |
// (kcal/mol * A/fs) * conversion => (amu A^3)/fs^3 |
| 574 |
+ |
|
| 575 |
+ |
Vector3d heatFluxJv = currSnapshot->getConductiveHeatFlux() * |
| 576 |
+ |
PhysicalConstants::energyConvert; |
| 577 |
+ |
|
| 578 |
+ |
// Correct for the fact the flux is 1/V (Jc + Jv) |
| 579 |
+ |
return (heatFluxJv + heatFluxJc) / this->getVolume(); // amu / fs^3 |
| 580 |
+ |
} |
| 581 |
+ |
|
| 582 |
+ |
|
| 583 |
+ |
Vector3d Thermo::getComVel(){ |
| 584 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 585 |
+ |
|
| 586 |
+ |
if (!snap->hasCOMvel) { |
| 587 |
+ |
|
| 588 |
+ |
SimInfo::MoleculeIterator i; |
| 589 |
+ |
Molecule* mol; |
| 590 |
+ |
|
| 591 |
+ |
Vector3d comVel(0.0); |
| 592 |
+ |
RealType totalMass(0.0); |
| 593 |
+ |
|
| 594 |
+ |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 595 |
+ |
mol = info_->nextMolecule(i)) { |
| 596 |
+ |
RealType mass = mol->getMass(); |
| 597 |
+ |
totalMass += mass; |
| 598 |
+ |
comVel += mass * mol->getComVel(); |
| 599 |
+ |
} |
| 600 |
+ |
|
| 601 |
+ |
#ifdef IS_MPI |
| 602 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &totalMass, 1, MPI_REALTYPE, |
| 603 |
+ |
MPI_SUM, MPI_COMM_WORLD); |
| 604 |
+ |
MPI_Allreduce(MPI_IN_PLACE, comVel.getArrayPointer(), 3, |
| 605 |
+ |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 606 |
+ |
#endif |
| 607 |
+ |
|
| 608 |
+ |
comVel /= totalMass; |
| 609 |
+ |
snap->setCOMvel(comVel); |
| 610 |
+ |
} |
| 611 |
+ |
return snap->getCOMvel(); |
| 612 |
+ |
} |
| 613 |
+ |
|
| 614 |
+ |
Vector3d Thermo::getCom(){ |
| 615 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 616 |
+ |
|
| 617 |
+ |
if (!snap->hasCOM) { |
| 618 |
+ |
|
| 619 |
+ |
SimInfo::MoleculeIterator i; |
| 620 |
+ |
Molecule* mol; |
| 621 |
+ |
|
| 622 |
+ |
Vector3d com(0.0); |
| 623 |
+ |
RealType totalMass(0.0); |
| 624 |
+ |
|
| 625 |
+ |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 626 |
+ |
mol = info_->nextMolecule(i)) { |
| 627 |
+ |
RealType mass = mol->getMass(); |
| 628 |
+ |
totalMass += mass; |
| 629 |
+ |
com += mass * mol->getCom(); |
| 630 |
+ |
} |
| 631 |
+ |
|
| 632 |
+ |
#ifdef IS_MPI |
| 633 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &totalMass, 1, MPI_REALTYPE, |
| 634 |
+ |
MPI_SUM, MPI_COMM_WORLD); |
| 635 |
+ |
MPI_Allreduce(MPI_IN_PLACE, com.getArrayPointer(), 3, |
| 636 |
+ |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 637 |
+ |
#endif |
| 638 |
+ |
|
| 639 |
+ |
com /= totalMass; |
| 640 |
+ |
snap->setCOM(com); |
| 641 |
+ |
} |
| 642 |
+ |
return snap->getCOM(); |
| 643 |
+ |
} |
| 644 |
+ |
|
| 645 |
+ |
/** |
| 646 |
+ |
* Returns center of mass and center of mass velocity in one |
| 647 |
+ |
* function call. |
| 648 |
+ |
*/ |
| 649 |
+ |
void Thermo::getComAll(Vector3d &com, Vector3d &comVel){ |
| 650 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 651 |
+ |
|
| 652 |
+ |
if (!(snap->hasCOM && snap->hasCOMvel)) { |
| 653 |
+ |
|
| 654 |
+ |
SimInfo::MoleculeIterator i; |
| 655 |
+ |
Molecule* mol; |
| 656 |
+ |
|
| 657 |
+ |
RealType totalMass(0.0); |
| 658 |
+ |
|
| 659 |
+ |
com = 0.0; |
| 660 |
+ |
comVel = 0.0; |
| 661 |
+ |
|
| 662 |
+ |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 663 |
+ |
mol = info_->nextMolecule(i)) { |
| 664 |
+ |
RealType mass = mol->getMass(); |
| 665 |
+ |
totalMass += mass; |
| 666 |
+ |
com += mass * mol->getCom(); |
| 667 |
+ |
comVel += mass * mol->getComVel(); |
| 668 |
+ |
} |
| 669 |
+ |
|
| 670 |
+ |
#ifdef IS_MPI |
| 671 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &totalMass, 1, MPI_REALTYPE, |
| 672 |
+ |
MPI_SUM, MPI_COMM_WORLD); |
| 673 |
+ |
MPI_Allreduce(MPI_IN_PLACE, com.getArrayPointer(), 3, |
| 674 |
+ |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 675 |
+ |
MPI_Allreduce(MPI_IN_PLACE, comVel.getArrayPointer(), 3, |
| 676 |
+ |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 677 |
+ |
#endif |
| 678 |
+ |
|
| 679 |
+ |
com /= totalMass; |
| 680 |
+ |
comVel /= totalMass; |
| 681 |
+ |
snap->setCOM(com); |
| 682 |
+ |
snap->setCOMvel(comVel); |
| 683 |
+ |
} |
| 684 |
+ |
com = snap->getCOM(); |
| 685 |
+ |
comVel = snap->getCOMvel(); |
| 686 |
+ |
return; |
| 687 |
+ |
} |
| 688 |
+ |
|
| 689 |
+ |
/** |
| 690 |
+ |
* \brief Return inertia tensor for entire system and angular momentum |
| 691 |
+ |
* Vector. |
| 692 |
+ |
* |
| 693 |
+ |
* |
| 694 |
+ |
* |
| 695 |
+ |
* [ Ixx -Ixy -Ixz ] |
| 696 |
+ |
* I =| -Iyx Iyy -Iyz | |
| 697 |
+ |
* [ -Izx -Iyz Izz ] |
| 698 |
+ |
*/ |
| 699 |
+ |
void Thermo::getInertiaTensor(Mat3x3d &inertiaTensor, |
| 700 |
+ |
Vector3d &angularMomentum){ |
| 701 |
+ |
|
| 702 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 703 |
+ |
|
| 704 |
+ |
if (!(snap->hasInertiaTensor && snap->hasCOMw)) { |
| 705 |
+ |
|
| 706 |
+ |
RealType xx = 0.0; |
| 707 |
+ |
RealType yy = 0.0; |
| 708 |
+ |
RealType zz = 0.0; |
| 709 |
+ |
RealType xy = 0.0; |
| 710 |
+ |
RealType xz = 0.0; |
| 711 |
+ |
RealType yz = 0.0; |
| 712 |
+ |
Vector3d com(0.0); |
| 713 |
+ |
Vector3d comVel(0.0); |
| 714 |
+ |
|
| 715 |
+ |
getComAll(com, comVel); |
| 716 |
+ |
|
| 717 |
+ |
SimInfo::MoleculeIterator i; |
| 718 |
+ |
Molecule* mol; |
| 719 |
+ |
|
| 720 |
+ |
Vector3d thisq(0.0); |
| 721 |
+ |
Vector3d thisv(0.0); |
| 722 |
+ |
|
| 723 |
+ |
RealType thisMass = 0.0; |
| 724 |
+ |
|
| 725 |
+ |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 726 |
+ |
mol = info_->nextMolecule(i)) { |
| 727 |
+ |
|
| 728 |
+ |
thisq = mol->getCom()-com; |
| 729 |
+ |
thisv = mol->getComVel()-comVel; |
| 730 |
+ |
thisMass = mol->getMass(); |
| 731 |
+ |
// Compute moment of intertia coefficients. |
| 732 |
+ |
xx += thisq[0]*thisq[0]*thisMass; |
| 733 |
+ |
yy += thisq[1]*thisq[1]*thisMass; |
| 734 |
+ |
zz += thisq[2]*thisq[2]*thisMass; |
| 735 |
+ |
|
| 736 |
+ |
// compute products of intertia |
| 737 |
+ |
xy += thisq[0]*thisq[1]*thisMass; |
| 738 |
+ |
xz += thisq[0]*thisq[2]*thisMass; |
| 739 |
+ |
yz += thisq[1]*thisq[2]*thisMass; |
| 740 |
+ |
|
| 741 |
+ |
angularMomentum += cross( thisq, thisv ) * thisMass; |
| 742 |
+ |
} |
| 743 |
+ |
|
| 744 |
+ |
inertiaTensor(0,0) = yy + zz; |
| 745 |
+ |
inertiaTensor(0,1) = -xy; |
| 746 |
+ |
inertiaTensor(0,2) = -xz; |
| 747 |
+ |
inertiaTensor(1,0) = -xy; |
| 748 |
+ |
inertiaTensor(1,1) = xx + zz; |
| 749 |
+ |
inertiaTensor(1,2) = -yz; |
| 750 |
+ |
inertiaTensor(2,0) = -xz; |
| 751 |
+ |
inertiaTensor(2,1) = -yz; |
| 752 |
+ |
inertiaTensor(2,2) = xx + yy; |
| 753 |
+ |
|
| 754 |
+ |
#ifdef IS_MPI |
| 755 |
+ |
MPI_Allreduce(MPI_IN_PLACE, inertiaTensor.getArrayPointer(), |
| 756 |
+ |
9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 757 |
+ |
MPI_Allreduce(MPI_IN_PLACE, |
| 758 |
+ |
angularMomentum.getArrayPointer(), 3, |
| 759 |
+ |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 760 |
+ |
#endif |
| 761 |
+ |
|
| 762 |
+ |
snap->setCOMw(angularMomentum); |
| 763 |
+ |
snap->setInertiaTensor(inertiaTensor); |
| 764 |
+ |
} |
| 765 |
+ |
|
| 766 |
+ |
angularMomentum = snap->getCOMw(); |
| 767 |
+ |
inertiaTensor = snap->getInertiaTensor(); |
| 768 |
+ |
|
| 769 |
+ |
return; |
| 770 |
+ |
} |
| 771 |
+ |
|
| 772 |
+ |
|
| 773 |
+ |
Mat3x3d Thermo::getBoundingBox(){ |
| 774 |
+ |
|
| 775 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 776 |
+ |
|
| 777 |
+ |
if (!(snap->hasBoundingBox)) { |
| 778 |
+ |
|
| 779 |
+ |
SimInfo::MoleculeIterator i; |
| 780 |
+ |
Molecule::RigidBodyIterator ri; |
| 781 |
+ |
Molecule::AtomIterator ai; |
| 782 |
+ |
Molecule* mol; |
| 783 |
+ |
RigidBody* rb; |
| 784 |
+ |
Atom* atom; |
| 785 |
+ |
Vector3d pos, bMax, bMin; |
| 786 |
+ |
int index = 0; |
| 787 |
+ |
|
| 788 |
+ |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 789 |
+ |
mol = info_->nextMolecule(i)) { |
| 790 |
+ |
|
| 791 |
+ |
//change the positions of atoms which belong to the rigidbodies |
| 792 |
+ |
for (rb = mol->beginRigidBody(ri); rb != NULL; |
| 793 |
+ |
rb = mol->nextRigidBody(ri)) { |
| 794 |
+ |
rb->updateAtoms(); |
| 795 |
+ |
} |
| 796 |
+ |
|
| 797 |
+ |
for(atom = mol->beginAtom(ai); atom != NULL; |
| 798 |
+ |
atom = mol->nextAtom(ai)) { |
| 799 |
+ |
|
| 800 |
+ |
pos = atom->getPos(); |
| 801 |
+ |
|
| 802 |
+ |
if (index == 0) { |
| 803 |
+ |
bMax = pos; |
| 804 |
+ |
bMin = pos; |
| 805 |
+ |
} else { |
| 806 |
+ |
for (int i = 0; i < 3; i++) { |
| 807 |
+ |
bMax[i] = max(bMax[i], pos[i]); |
| 808 |
+ |
bMin[i] = min(bMin[i], pos[i]); |
| 809 |
+ |
} |
| 810 |
+ |
} |
| 811 |
+ |
index++; |
| 812 |
+ |
} |
| 813 |
+ |
} |
| 814 |
+ |
|
| 815 |
+ |
#ifdef IS_MPI |
| 816 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &bMax[0], 3, MPI_REALTYPE, |
| 817 |
+ |
MPI_MAX, MPI_COMM_WORLD); |
| 818 |
+ |
|
| 819 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &bMin[0], 3, MPI_REALTYPE, |
| 820 |
+ |
MPI_MIN, MPI_COMM_WORLD); |
| 821 |
+ |
#endif |
| 822 |
+ |
Mat3x3d bBox = Mat3x3d(0.0); |
| 823 |
+ |
for (int i = 0; i < 3; i++) { |
| 824 |
+ |
bBox(i,i) = bMax[i] - bMin[i]; |
| 825 |
+ |
} |
| 826 |
+ |
snap->setBoundingBox(bBox); |
| 827 |
+ |
} |
| 828 |
+ |
|
| 829 |
+ |
return snap->getBoundingBox(); |
| 830 |
+ |
} |
| 831 |
+ |
|
| 832 |
+ |
|
| 833 |
+ |
// Returns the angular momentum of the system |
| 834 |
+ |
Vector3d Thermo::getAngularMomentum(){ |
| 835 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 836 |
+ |
|
| 837 |
+ |
if (!snap->hasCOMw) { |
| 838 |
+ |
|
| 839 |
+ |
Vector3d com(0.0); |
| 840 |
+ |
Vector3d comVel(0.0); |
| 841 |
+ |
Vector3d angularMomentum(0.0); |
| 842 |
+ |
|
| 843 |
+ |
getComAll(com, comVel); |
| 844 |
+ |
|
| 845 |
+ |
SimInfo::MoleculeIterator i; |
| 846 |
+ |
Molecule* mol; |
| 847 |
+ |
|
| 848 |
+ |
Vector3d thisr(0.0); |
| 849 |
+ |
Vector3d thisp(0.0); |
| 850 |
+ |
|
| 851 |
+ |
RealType thisMass; |
| 852 |
+ |
|
| 853 |
+ |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 854 |
+ |
mol = info_->nextMolecule(i)) { |
| 855 |
+ |
thisMass = mol->getMass(); |
| 856 |
+ |
thisr = mol->getCom() - com; |
| 857 |
+ |
thisp = (mol->getComVel() - comVel) * thisMass; |
| 858 |
+ |
|
| 859 |
+ |
angularMomentum += cross( thisr, thisp ); |
| 860 |
+ |
} |
| 861 |
+ |
|
| 862 |
+ |
#ifdef IS_MPI |
| 863 |
+ |
MPI_Allreduce(MPI_IN_PLACE, |
| 864 |
+ |
angularMomentum.getArrayPointer(), 3, |
| 865 |
+ |
MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 866 |
+ |
#endif |
| 867 |
+ |
|
| 868 |
+ |
snap->setCOMw(angularMomentum); |
| 869 |
+ |
} |
| 870 |
+ |
|
| 871 |
+ |
return snap->getCOMw(); |
| 872 |
+ |
} |
| 873 |
+ |
|
| 874 |
+ |
|
| 875 |
+ |
/** |
| 876 |
+ |
* Returns the Volume of the system based on a ellipsoid with |
| 877 |
+ |
* semi-axes based on the radius of gyration V=4/3*Pi*R_1*R_2*R_3 |
| 878 |
+ |
* where R_i are related to the principle inertia moments |
| 879 |
+ |
* R_i = sqrt(C*I_i/N), this reduces to |
| 880 |
+ |
* V = 4/3*Pi*(C/N)^3/2*sqrt(det(I)). |
| 881 |
+ |
* See S.E. Baltazar et. al. Comp. Mat. Sci. 37 (2006) 526-536. |
| 882 |
+ |
*/ |
| 883 |
+ |
RealType Thermo::getGyrationalVolume(){ |
| 884 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 885 |
+ |
|
| 886 |
+ |
if (!snap->hasGyrationalVolume) { |
| 887 |
+ |
|
| 888 |
+ |
Mat3x3d intTensor; |
| 889 |
+ |
RealType det; |
| 890 |
+ |
Vector3d dummyAngMom; |
| 891 |
+ |
RealType sysconstants; |
| 892 |
+ |
RealType geomCnst; |
| 893 |
+ |
RealType volume; |
| 894 |
+ |
|
| 895 |
+ |
geomCnst = 3.0/2.0; |
| 896 |
+ |
/* Get the inertial tensor and angular momentum for free*/ |
| 897 |
+ |
getInertiaTensor(intTensor, dummyAngMom); |
| 898 |
+ |
|
| 899 |
+ |
det = intTensor.determinant(); |
| 900 |
+ |
sysconstants = geomCnst / (RealType)(info_->getNGlobalIntegrableObjects()); |
| 901 |
+ |
volume = 4.0/3.0*NumericConstant::PI*pow(sysconstants,geomCnst)*sqrt(det); |
| 902 |
+ |
|
| 903 |
+ |
snap->setGyrationalVolume(volume); |
| 904 |
+ |
} |
| 905 |
+ |
return snap->getGyrationalVolume(); |
| 906 |
+ |
} |
| 907 |
+ |
|
| 908 |
+ |
void Thermo::getGyrationalVolume(RealType &volume, RealType &detI){ |
| 909 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 910 |
+ |
|
| 911 |
+ |
if (!(snap->hasInertiaTensor && snap->hasGyrationalVolume)) { |
| 912 |
+ |
|
| 913 |
+ |
Mat3x3d intTensor; |
| 914 |
+ |
Vector3d dummyAngMom; |
| 915 |
+ |
RealType sysconstants; |
| 916 |
+ |
RealType geomCnst; |
| 917 |
+ |
|
| 918 |
+ |
geomCnst = 3.0/2.0; |
| 919 |
+ |
/* Get the inertia tensor and angular momentum for free*/ |
| 920 |
+ |
this->getInertiaTensor(intTensor, dummyAngMom); |
| 921 |
+ |
|
| 922 |
+ |
detI = intTensor.determinant(); |
| 923 |
+ |
sysconstants = geomCnst/(RealType)(info_->getNGlobalIntegrableObjects()); |
| 924 |
+ |
volume = 4.0/3.0*NumericConstant::PI*pow(sysconstants,geomCnst)*sqrt(detI); |
| 925 |
+ |
snap->setGyrationalVolume(volume); |
| 926 |
+ |
} else { |
| 927 |
+ |
volume = snap->getGyrationalVolume(); |
| 928 |
+ |
detI = snap->getInertiaTensor().determinant(); |
| 929 |
+ |
} |
| 930 |
+ |
return; |
| 931 |
+ |
} |
| 932 |
+ |
|
| 933 |
+ |
RealType Thermo::getTaggedAtomPairDistance(){ |
| 934 |
+ |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 935 |
+ |
Globals* simParams = info_->getSimParams(); |
| 936 |
+ |
|
| 937 |
|
if (simParams->haveTaggedAtomPair() && |
| 938 |
|
simParams->havePrintTaggedPairDistance()) { |
| 939 |
|
if ( simParams->getPrintTaggedPairDistance()) { |
| 940 |
|
|
| 941 |
< |
std::pair<int, int> tap = simParams->getTaggedAtomPair(); |
| 941 |
> |
pair<int, int> tap = simParams->getTaggedAtomPair(); |
| 942 |
|
Vector3d pos1, pos2, rab; |
| 943 |
< |
|
| 943 |
> |
|
| 944 |
|
#ifdef IS_MPI |
| 252 |
– |
std::cerr << "tap = " << tap.first << " " << tap.second << std::endl; |
| 253 |
– |
|
| 945 |
|
int mol1 = info_->getGlobalMolMembership(tap.first); |
| 946 |
|
int mol2 = info_->getGlobalMolMembership(tap.second); |
| 256 |
– |
std::cerr << "mols = " << mol1 << " " << mol2 << std::endl; |
| 947 |
|
|
| 948 |
|
int proc1 = info_->getMolToProc(mol1); |
| 949 |
|
int proc2 = info_->getMolToProc(mol2); |
| 950 |
|
|
| 261 |
– |
std::cerr << " procs = " << proc1 << " " <<proc2 <<std::endl; |
| 262 |
– |
|
| 951 |
|
RealType data[3]; |
| 952 |
|
if (proc1 == worldRank) { |
| 953 |
|
StuntDouble* sd1 = info_->getIOIndexToIntegrableObject(tap.first); |
| 266 |
– |
std::cerr << " on proc " << proc1 << ", sd1 has global index= " << sd1->getGlobalIndex() << std::endl; |
| 954 |
|
pos1 = sd1->getPos(); |
| 955 |
|
data[0] = pos1.x(); |
| 956 |
|
data[1] = pos1.y(); |
| 961 |
|
pos1 = Vector3d(data); |
| 962 |
|
} |
| 963 |
|
|
| 277 |
– |
|
| 964 |
|
if (proc2 == worldRank) { |
| 965 |
|
StuntDouble* sd2 = info_->getIOIndexToIntegrableObject(tap.second); |
| 280 |
– |
std::cerr << " on proc " << proc2 << ", sd2 has global index= " << sd2->getGlobalIndex() << std::endl; |
| 966 |
|
pos2 = sd2->getPos(); |
| 967 |
|
data[0] = pos2.x(); |
| 968 |
|
data[1] = pos2.y(); |
| 969 |
< |
data[2] = pos2.z(); |
| 969 |
> |
data[2] = pos2.z(); |
| 970 |
|
MPI_Bcast(data, 3, MPI_REALTYPE, proc2, MPI_COMM_WORLD); |
| 971 |
|
} else { |
| 972 |
|
MPI_Bcast(data, 3, MPI_REALTYPE, proc2, MPI_COMM_WORLD); |
| 980 |
|
#endif |
| 981 |
|
rab = pos2 - pos1; |
| 982 |
|
currSnapshot->wrapVector(rab); |
| 983 |
< |
stat[Stats::TAGGED_PAIR_DISTANCE] = rab.length(); |
| 983 |
> |
return rab.length(); |
| 984 |
|
} |
| 985 |
+ |
return 0.0; |
| 986 |
|
} |
| 987 |
+ |
return 0.0; |
| 988 |
+ |
} |
| 989 |
+ |
|
| 990 |
+ |
RealType Thermo::getHullVolume(){ |
| 991 |
+ |
#ifdef HAVE_QHULL |
| 992 |
+ |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 993 |
+ |
if (!snap->hasHullVolume) { |
| 994 |
+ |
Hull* surfaceMesh_; |
| 995 |
|
|
| 996 |
< |
/**@todo need refactorying*/ |
| 997 |
< |
//Conserved Quantity is set by integrator and time is set by setTime |
| 996 |
> |
Globals* simParams = info_->getSimParams(); |
| 997 |
> |
const std::string ht = simParams->getHULL_Method(); |
| 998 |
> |
|
| 999 |
> |
if (ht == "Convex") { |
| 1000 |
> |
surfaceMesh_ = new ConvexHull(); |
| 1001 |
> |
} else if (ht == "AlphaShape") { |
| 1002 |
> |
surfaceMesh_ = new AlphaHull(simParams->getAlpha()); |
| 1003 |
> |
} else { |
| 1004 |
> |
return 0.0; |
| 1005 |
> |
} |
| 1006 |
> |
|
| 1007 |
> |
// Build a vector of stunt doubles to determine if they are |
| 1008 |
> |
// surface atoms |
| 1009 |
> |
std::vector<StuntDouble*> localSites_; |
| 1010 |
> |
Molecule* mol; |
| 1011 |
> |
StuntDouble* sd; |
| 1012 |
> |
SimInfo::MoleculeIterator i; |
| 1013 |
> |
Molecule::IntegrableObjectIterator j; |
| 1014 |
> |
|
| 1015 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 1016 |
> |
mol = info_->nextMolecule(i)) { |
| 1017 |
> |
for (sd = mol->beginIntegrableObject(j); |
| 1018 |
> |
sd != NULL; |
| 1019 |
> |
sd = mol->nextIntegrableObject(j)) { |
| 1020 |
> |
localSites_.push_back(sd); |
| 1021 |
> |
} |
| 1022 |
> |
} |
| 1023 |
> |
|
| 1024 |
> |
// Compute surface Mesh |
| 1025 |
> |
surfaceMesh_->computeHull(localSites_); |
| 1026 |
> |
snap->setHullVolume(surfaceMesh_->getVolume()); |
| 1027 |
> |
|
| 1028 |
> |
delete surfaceMesh_; |
| 1029 |
> |
} |
| 1030 |
|
|
| 1031 |
+ |
return snap->getHullVolume(); |
| 1032 |
+ |
#else |
| 1033 |
+ |
return 0.0; |
| 1034 |
+ |
#endif |
| 1035 |
|
} |
| 1036 |
|
|
| 1037 |
< |
} //end namespace OpenMD |
| 1037 |
> |
|
| 1038 |
> |
} |