| 53 |
|
#include <mpi.h> |
| 54 |
|
#endif |
| 55 |
|
|
| 56 |
+ |
#ifdef _MSC_VER |
| 57 |
+ |
#define isnan(x) _isnan((x)) |
| 58 |
+ |
#define isinf(x) (!_finite(x) && !_isnan(x)) |
| 59 |
+ |
#endif |
| 60 |
+ |
|
| 61 |
|
#define HONKING_LARGE_VALUE 1.0e10 |
| 62 |
|
|
| 63 |
|
using namespace std; |
| 70 |
|
failTrialCount_ = 0; |
| 71 |
|
failRootCount_ = 0; |
| 72 |
|
|
| 68 |
– |
int seedValue; |
| 73 |
|
Globals * simParams = info->getSimParams(); |
| 74 |
|
RNEMDParameters* rnemdParams = simParams->getRNEMDParameters(); |
| 75 |
|
|
| 76 |
+ |
doRNEMD_ = rnemdParams->getUseRNEMD(); |
| 77 |
+ |
if (!doRNEMD_) return; |
| 78 |
+ |
|
| 79 |
|
stringToMethod_["Swap"] = rnemdSwap; |
| 80 |
|
stringToMethod_["NIVS"] = rnemdNIVS; |
| 81 |
|
stringToMethod_["VSS"] = rnemdVSS; |
| 84 |
|
stringToFluxType_["Px"] = rnemdPx; |
| 85 |
|
stringToFluxType_["Py"] = rnemdPy; |
| 86 |
|
stringToFluxType_["Pz"] = rnemdPz; |
| 87 |
+ |
stringToFluxType_["Pvector"] = rnemdPvector; |
| 88 |
|
stringToFluxType_["KE+Px"] = rnemdKePx; |
| 89 |
|
stringToFluxType_["KE+Py"] = rnemdKePy; |
| 90 |
|
stringToFluxType_["KE+Pvector"] = rnemdKePvector; |
| 106 |
|
sprintf(painCave.errMsg, |
| 107 |
|
"RNEMD: No fluxType was set in the md file. This parameter,\n" |
| 108 |
|
"\twhich must be one of the following values:\n" |
| 109 |
< |
"\tKE, Px, Py, Pz, KE+Px, KE+Py, KE+Pvector, must be set to\n" |
| 110 |
< |
"\tuse RNEMD\n"); |
| 109 |
> |
"\tKE, Px, Py, Pz, Pvector, KE+Px, KE+Py, KE+Pvector\n" |
| 110 |
> |
"\tmust be set to use RNEMD\n"); |
| 111 |
|
painCave.isFatal = 1; |
| 112 |
|
painCave.severity = OPENMD_ERROR; |
| 113 |
|
simError(); |
| 205 |
|
break; |
| 206 |
|
case rnemdPvector: |
| 207 |
|
hasCorrectFlux = hasMomentumFluxVector; |
| 208 |
+ |
break; |
| 209 |
|
case rnemdKePx: |
| 210 |
|
case rnemdKePy: |
| 211 |
|
hasCorrectFlux = hasMomentumFlux && hasKineticFlux; |
| 233 |
|
} |
| 234 |
|
if (!hasCorrectFlux) { |
| 235 |
|
sprintf(painCave.errMsg, |
| 236 |
< |
"RNEMD: The current method,\n" |
| 228 |
< |
"\t%s, and flux type %s\n" |
| 236 |
> |
"RNEMD: The current method, %s, and flux type, %s,\n" |
| 237 |
|
"\tdid not have the correct flux value specified. Options\n" |
| 238 |
|
"\tinclude: kineticFlux, momentumFlux, and momentumFluxVector\n", |
| 239 |
|
methStr.c_str(), fluxStr.c_str()); |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
if (hasKineticFlux) { |
| 246 |
< |
kineticFlux_ = rnemdParams->getKineticFlux(); |
| 246 |
> |
// convert the kcal / mol / Angstroms^2 / fs values in the md file |
| 247 |
> |
// into amu / fs^3: |
| 248 |
> |
kineticFlux_ = rnemdParams->getKineticFlux() |
| 249 |
> |
* PhysicalConstants::energyConvert; |
| 250 |
|
} else { |
| 251 |
|
kineticFlux_ = 0.0; |
| 252 |
|
} |
| 309 |
|
z.title = "Z"; |
| 310 |
|
z.dataType = "RealType"; |
| 311 |
|
z.accumulator.reserve(nBins_); |
| 312 |
< |
for (unsigned int i = 0; i < nBins_; i++) |
| 312 |
> |
for (int i = 0; i < nBins_; i++) |
| 313 |
|
z.accumulator.push_back( new Accumulator() ); |
| 314 |
|
data_[Z] = z; |
| 315 |
|
outputMap_["Z"] = Z; |
| 319 |
|
temperature.title = "Temperature"; |
| 320 |
|
temperature.dataType = "RealType"; |
| 321 |
|
temperature.accumulator.reserve(nBins_); |
| 322 |
< |
for (unsigned int i = 0; i < nBins_; i++) |
| 322 |
> |
for (int i = 0; i < nBins_; i++) |
| 323 |
|
temperature.accumulator.push_back( new Accumulator() ); |
| 324 |
|
data_[TEMPERATURE] = temperature; |
| 325 |
|
outputMap_["TEMPERATURE"] = TEMPERATURE; |
| 326 |
|
|
| 327 |
|
OutputData velocity; |
| 328 |
< |
velocity.units = "amu/fs"; |
| 328 |
> |
velocity.units = "angstroms/fs"; |
| 329 |
|
velocity.title = "Velocity"; |
| 330 |
|
velocity.dataType = "Vector3d"; |
| 331 |
|
velocity.accumulator.reserve(nBins_); |
| 332 |
< |
for (unsigned int i = 0; i < nBins_; i++) |
| 332 |
> |
for (int i = 0; i < nBins_; i++) |
| 333 |
|
velocity.accumulator.push_back( new VectorAccumulator() ); |
| 334 |
|
data_[VELOCITY] = velocity; |
| 335 |
|
outputMap_["VELOCITY"] = VELOCITY; |
| 339 |
|
density.title = "Density"; |
| 340 |
|
density.dataType = "RealType"; |
| 341 |
|
density.accumulator.reserve(nBins_); |
| 342 |
< |
for (unsigned int i = 0; i < nBins_; i++) |
| 342 |
> |
for (int i = 0; i < nBins_; i++) |
| 343 |
|
density.accumulator.push_back( new Accumulator() ); |
| 344 |
|
data_[DENSITY] = density; |
| 345 |
|
outputMap_["DENSITY"] = DENSITY; |
| 421 |
|
} |
| 422 |
|
|
| 423 |
|
RNEMD::~RNEMD() { |
| 424 |
< |
|
| 424 |
> |
if (!doRNEMD_) return; |
| 425 |
|
#ifdef IS_MPI |
| 426 |
|
if (worldRank == 0) { |
| 427 |
|
#endif |
| 443 |
|
} |
| 444 |
|
|
| 445 |
|
void RNEMD::doSwap() { |
| 446 |
< |
|
| 446 |
> |
if (!doRNEMD_) return; |
| 447 |
|
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 448 |
|
Mat3x3d hmat = currentSnap_->getHmat(); |
| 449 |
|
|
| 502 |
|
+ angMom[2]*angMom[2]/I(2, 2); |
| 503 |
|
} |
| 504 |
|
} //angular momenta exchange enabled |
| 494 |
– |
//energyConvert temporarily disabled |
| 495 |
– |
//make kineticExchange_ comparable between swap & scale |
| 496 |
– |
//value = value * 0.5 / PhysicalConstants::energyConvert; |
| 505 |
|
value *= 0.5; |
| 506 |
|
break; |
| 507 |
|
case rnemdPx : |
| 739 |
|
|
| 740 |
|
switch(rnemdFluxType_) { |
| 741 |
|
case rnemdKE: |
| 734 |
– |
cerr << "KE\n"; |
| 742 |
|
kineticExchange_ += max_val - min_val; |
| 743 |
|
break; |
| 744 |
|
case rnemdPx: |
| 751 |
|
momentumExchange_.z() += max_val - min_val; |
| 752 |
|
break; |
| 753 |
|
default: |
| 747 |
– |
cerr << "default\n"; |
| 754 |
|
break; |
| 755 |
|
} |
| 756 |
|
} else { |
| 773 |
|
} |
| 774 |
|
|
| 775 |
|
void RNEMD::doNIVS() { |
| 776 |
< |
|
| 776 |
> |
if (!doRNEMD_) return; |
| 777 |
|
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 778 |
|
Mat3x3d hmat = currentSnap_->getHmat(); |
| 779 |
|
|
| 1222 |
|
} |
| 1223 |
|
|
| 1224 |
|
void RNEMD::doVSS() { |
| 1225 |
< |
|
| 1225 |
> |
if (!doRNEMD_) return; |
| 1226 |
|
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 1227 |
|
RealType time = currentSnap_->getTime(); |
| 1228 |
|
Mat3x3d hmat = currentSnap_->getHmat(); |
| 1400 |
|
} |
| 1401 |
|
|
| 1402 |
|
void RNEMD::doRNEMD() { |
| 1403 |
< |
|
| 1403 |
> |
if (!doRNEMD_) return; |
| 1404 |
|
trialCount_++; |
| 1405 |
|
switch(rnemdMethod_) { |
| 1406 |
|
case rnemdSwap: |
| 1419 |
|
} |
| 1420 |
|
|
| 1421 |
|
void RNEMD::collectData() { |
| 1422 |
< |
|
| 1422 |
> |
if (!doRNEMD_) return; |
| 1423 |
|
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 1424 |
|
Mat3x3d hmat = currentSnap_->getHmat(); |
| 1425 |
|
|
| 1530 |
|
vel.x() = binPx[i] / binMass[i]; |
| 1531 |
|
vel.y() = binPy[i] / binMass[i]; |
| 1532 |
|
vel.z() = binPz[i] / binMass[i]; |
| 1533 |
< |
den = binCount[i] * nBins_ / currentSnap_->getVolume(); |
| 1533 |
> |
|
| 1534 |
> |
den = binMass[i] * nBins_ * PhysicalConstants::densityConvert |
| 1535 |
> |
/ currentSnap_->getVolume() ; |
| 1536 |
> |
|
| 1537 |
|
temp = 2.0 * binKE[i] / (binDOF[i] * PhysicalConstants::kb * |
| 1538 |
|
PhysicalConstants::energyConvert); |
| 1539 |
|
|
| 1559 |
|
} |
| 1560 |
|
|
| 1561 |
|
void RNEMD::getStarted() { |
| 1562 |
+ |
if (!doRNEMD_) return; |
| 1563 |
|
collectData(); |
| 1564 |
|
writeOutputFile(); |
| 1565 |
|
} |
| 1566 |
|
|
| 1567 |
|
void RNEMD::parseOutputFileFormat(const std::string& format) { |
| 1568 |
+ |
if (!doRNEMD_) return; |
| 1569 |
|
StringTokenizer tokenizer(format, " ,;|\t\n\r"); |
| 1570 |
|
|
| 1571 |
|
while(tokenizer.hasMoreTokens()) { |
| 1586 |
|
} |
| 1587 |
|
|
| 1588 |
|
void RNEMD::writeOutputFile() { |
| 1589 |
+ |
if (!doRNEMD_) return; |
| 1590 |
|
|
| 1591 |
|
#ifdef IS_MPI |
| 1592 |
|
// If we're the root node, should we print out the results |
| 1608 |
|
RealType time = currentSnap_->getTime(); |
| 1609 |
|
RealType avgArea; |
| 1610 |
|
areaAccumulator_->getAverage(avgArea); |
| 1611 |
< |
RealType Jz = kineticExchange_ / (2.0 * time * avgArea); |
| 1611 |
> |
RealType Jz = kineticExchange_ / (2.0 * time * avgArea) |
| 1612 |
> |
/ PhysicalConstants::energyConvert; |
| 1613 |
|
Vector3d JzP = momentumExchange_ / (2.0 * time * avgArea); |
| 1614 |
|
|
| 1615 |
|
rnemdFile_ << "#######################################################\n"; |
| 1638 |
|
rnemdFile_ << "# RNEMD report:\n"; |
| 1639 |
|
rnemdFile_ << "# running time = " << time << " fs\n"; |
| 1640 |
|
rnemdFile_ << "# target flux:\n"; |
| 1641 |
< |
rnemdFile_ << "# kinetic = " << kineticFlux_ << "\n"; |
| 1642 |
< |
rnemdFile_ << "# momentum = " << momentumFluxVector_ << "\n"; |
| 1641 |
> |
rnemdFile_ << "# kinetic = " |
| 1642 |
> |
<< kineticFlux_ / PhysicalConstants::energyConvert |
| 1643 |
> |
<< " (kcal/mol/A^2/fs)\n"; |
| 1644 |
> |
rnemdFile_ << "# momentum = " << momentumFluxVector_ |
| 1645 |
> |
<< " (amu/A/fs^2)\n"; |
| 1646 |
|
rnemdFile_ << "# target one-time exchanges:\n"; |
| 1647 |
< |
rnemdFile_ << "# kinetic = " << kineticTarget_ << "\n"; |
| 1648 |
< |
rnemdFile_ << "# momentum = " << momentumTarget_ << "\n"; |
| 1649 |
< |
rnemdFile_ << "# actual exchange totals:\n"; |
| 1650 |
< |
rnemdFile_ << "# kinetic = " << kineticExchange_ << "\n"; |
| 1651 |
< |
rnemdFile_ << "# momentum = " << momentumExchange_ << "\n"; |
| 1647 |
> |
rnemdFile_ << "# kinetic = " |
| 1648 |
> |
<< kineticTarget_ / PhysicalConstants::energyConvert |
| 1649 |
> |
<< " (kcal/mol)\n"; |
| 1650 |
> |
rnemdFile_ << "# momentum = " << momentumTarget_ |
| 1651 |
> |
<< " (amu*A/fs)\n"; |
| 1652 |
> |
rnemdFile_ << "# actual exchange totals:\n"; |
| 1653 |
> |
rnemdFile_ << "# kinetic = " |
| 1654 |
> |
<< kineticExchange_ / PhysicalConstants::energyConvert |
| 1655 |
> |
<< " (kcal/mol)\n"; |
| 1656 |
> |
rnemdFile_ << "# momentum = " << momentumExchange_ |
| 1657 |
> |
<< " (amu*A/fs)\n"; |
| 1658 |
|
rnemdFile_ << "# actual flux:\n"; |
| 1659 |
< |
rnemdFile_ << "# kinetic = " << Jz << "\n"; |
| 1660 |
< |
rnemdFile_ << "# momentum = " << JzP << "\n"; |
| 1659 |
> |
rnemdFile_ << "# kinetic = " << Jz |
| 1660 |
> |
<< " (kcal/mol/A^2/fs)\n"; |
| 1661 |
> |
rnemdFile_ << "# momentum = " << JzP |
| 1662 |
> |
<< " (amu/A/fs^2)\n"; |
| 1663 |
|
rnemdFile_ << "# exchange statistics:\n"; |
| 1664 |
|
rnemdFile_ << "# attempted = " << trialCount_ << "\n"; |
| 1665 |
|
rnemdFile_ << "# failed = " << failTrialCount_ << "\n"; |
| 1677 |
|
if (outputMask_[i]) { |
| 1678 |
|
rnemdFile_ << "\t" << data_[i].title << |
| 1679 |
|
"(" << data_[i].units << ")"; |
| 1680 |
+ |
// add some extra tabs for column alignment |
| 1681 |
+ |
if (data_[i].dataType == "Vector3d") rnemdFile_ << "\t\t"; |
| 1682 |
|
} |
| 1683 |
|
} |
| 1684 |
|
rnemdFile_ << std::endl; |
| 1685 |
|
|
| 1686 |
|
rnemdFile_.precision(8); |
| 1687 |
|
|
| 1688 |
< |
for (unsigned int j = 0; j < nBins_; j++) { |
| 1688 |
> |
for (int j = 0; j < nBins_; j++) { |
| 1689 |
|
|
| 1690 |
|
for (unsigned int i = 0; i < outputMask_.size(); ++i) { |
| 1691 |
|
if (outputMask_[i]) { |
| 1711 |
|
rnemdFile_ << "#######################################################\n"; |
| 1712 |
|
|
| 1713 |
|
|
| 1714 |
< |
for (unsigned int j = 0; j < nBins_; j++) { |
| 1714 |
> |
for (int j = 0; j < nBins_; j++) { |
| 1715 |
|
rnemdFile_ << "#"; |
| 1716 |
|
for (unsigned int i = 0; i < outputMask_.size(); ++i) { |
| 1717 |
|
if (outputMask_[i]) { |
| 1742 |
|
} |
| 1743 |
|
|
| 1744 |
|
void RNEMD::writeReal(int index, unsigned int bin) { |
| 1745 |
+ |
if (!doRNEMD_) return; |
| 1746 |
|
assert(index >=0 && index < ENDINDEX); |
| 1747 |
|
assert(bin < nBins_); |
| 1748 |
|
RealType s; |
| 1761 |
|
} |
| 1762 |
|
|
| 1763 |
|
void RNEMD::writeVector(int index, unsigned int bin) { |
| 1764 |
+ |
if (!doRNEMD_) return; |
| 1765 |
|
assert(index >=0 && index < ENDINDEX); |
| 1766 |
|
assert(bin < nBins_); |
| 1767 |
|
Vector3d s; |
| 1780 |
|
} |
| 1781 |
|
|
| 1782 |
|
void RNEMD::writeRealStdDev(int index, unsigned int bin) { |
| 1783 |
+ |
if (!doRNEMD_) return; |
| 1784 |
|
assert(index >=0 && index < ENDINDEX); |
| 1785 |
|
assert(bin < nBins_); |
| 1786 |
|
RealType s; |
| 1799 |
|
} |
| 1800 |
|
|
| 1801 |
|
void RNEMD::writeVectorStdDev(int index, unsigned int bin) { |
| 1802 |
+ |
if (!doRNEMD_) return; |
| 1803 |
|
assert(index >=0 && index < ENDINDEX); |
| 1804 |
|
assert(bin < nBins_); |
| 1805 |
|
Vector3d s; |