| 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). |
| 38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
| 39 |
|
* [4] Vardeman & Gezelter, in progress (2009). |
| 40 |
|
*/ |
| 41 |
|
|
| 42 |
|
#include <cmath> |
| 43 |
+ |
#include <sstream> |
| 44 |
+ |
#include <string> |
| 45 |
+ |
|
| 46 |
|
#include "rnemd/RNEMD.hpp" |
| 47 |
|
#include "math/Vector3.hpp" |
| 48 |
|
#include "math/Vector.hpp" |
| 52 |
|
#include "primitives/StuntDouble.hpp" |
| 53 |
|
#include "utils/PhysicalConstants.hpp" |
| 54 |
|
#include "utils/Tuple.hpp" |
| 55 |
+ |
#include "brains/Thermo.hpp" |
| 56 |
+ |
#include "math/ConvexHull.hpp" |
| 57 |
|
#ifdef IS_MPI |
| 58 |
|
#include <mpi.h> |
| 59 |
|
#endif |
| 60 |
|
|
| 61 |
+ |
#ifdef _MSC_VER |
| 62 |
+ |
#define isnan(x) _isnan((x)) |
| 63 |
+ |
#define isinf(x) (!_finite(x) && !_isnan(x)) |
| 64 |
+ |
#endif |
| 65 |
+ |
|
| 66 |
|
#define HONKING_LARGE_VALUE 1.0e10 |
| 67 |
|
|
| 68 |
|
using namespace std; |
| 69 |
|
namespace OpenMD { |
| 70 |
|
|
| 71 |
|
RNEMD::RNEMD(SimInfo* info) : info_(info), evaluator_(info), seleMan_(info), |
| 72 |
+ |
evaluatorA_(info), seleManA_(info), |
| 73 |
+ |
commonA_(info), evaluatorB_(info), |
| 74 |
+ |
seleManB_(info), commonB_(info), |
| 75 |
|
usePeriodicBoundaryConditions_(info->getSimParams()->getUsePeriodicBoundaryConditions()) { |
| 76 |
|
|
| 77 |
|
trialCount_ = 0; |
| 78 |
|
failTrialCount_ = 0; |
| 79 |
|
failRootCount_ = 0; |
| 80 |
|
|
| 81 |
< |
int seedValue; |
| 69 |
< |
Globals * simParams = info->getSimParams(); |
| 81 |
> |
Globals* simParams = info->getSimParams(); |
| 82 |
|
RNEMDParameters* rnemdParams = simParams->getRNEMDParameters(); |
| 83 |
|
|
| 84 |
+ |
doRNEMD_ = rnemdParams->getUseRNEMD(); |
| 85 |
+ |
if (!doRNEMD_) return; |
| 86 |
+ |
|
| 87 |
|
stringToMethod_["Swap"] = rnemdSwap; |
| 88 |
|
stringToMethod_["NIVS"] = rnemdNIVS; |
| 89 |
|
stringToMethod_["VSS"] = rnemdVSS; |
| 92 |
|
stringToFluxType_["Px"] = rnemdPx; |
| 93 |
|
stringToFluxType_["Py"] = rnemdPy; |
| 94 |
|
stringToFluxType_["Pz"] = rnemdPz; |
| 95 |
+ |
stringToFluxType_["Pvector"] = rnemdPvector; |
| 96 |
+ |
stringToFluxType_["Lx"] = rnemdLx; |
| 97 |
+ |
stringToFluxType_["Ly"] = rnemdLy; |
| 98 |
+ |
stringToFluxType_["Lz"] = rnemdLz; |
| 99 |
+ |
stringToFluxType_["Lvector"] = rnemdLvector; |
| 100 |
|
stringToFluxType_["KE+Px"] = rnemdKePx; |
| 101 |
|
stringToFluxType_["KE+Py"] = rnemdKePy; |
| 102 |
|
stringToFluxType_["KE+Pvector"] = rnemdKePvector; |
| 103 |
+ |
stringToFluxType_["KE+Lx"] = rnemdKeLx; |
| 104 |
+ |
stringToFluxType_["KE+Ly"] = rnemdKeLy; |
| 105 |
+ |
stringToFluxType_["KE+Lz"] = rnemdKeLz; |
| 106 |
+ |
stringToFluxType_["KE+Lvector"] = rnemdKeLvector; |
| 107 |
|
|
| 108 |
|
runTime_ = simParams->getRunTime(); |
| 109 |
|
statusTime_ = simParams->getStatusTime(); |
| 110 |
|
|
| 87 |
– |
rnemdObjectSelection_ = rnemdParams->getObjectSelection(); |
| 88 |
– |
evaluator_.loadScriptString(rnemdObjectSelection_); |
| 89 |
– |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 90 |
– |
|
| 111 |
|
const string methStr = rnemdParams->getMethod(); |
| 112 |
|
bool hasFluxType = rnemdParams->haveFluxType(); |
| 113 |
|
|
| 114 |
+ |
rnemdObjectSelection_ = rnemdParams->getObjectSelection(); |
| 115 |
+ |
|
| 116 |
|
string fluxStr; |
| 117 |
|
if (hasFluxType) { |
| 118 |
|
fluxStr = rnemdParams->getFluxType(); |
| 120 |
|
sprintf(painCave.errMsg, |
| 121 |
|
"RNEMD: No fluxType was set in the md file. This parameter,\n" |
| 122 |
|
"\twhich must be one of the following values:\n" |
| 123 |
< |
"\tKE, Px, Py, Pz, KE+Px, KE+Py, KE+Pvector, must be set to\n" |
| 124 |
< |
"\tuse RNEMD\n"); |
| 123 |
> |
"\tKE, Px, Py, Pz, Pvector, Lx, Ly, Lz, Lvector,\n" |
| 124 |
> |
"\tKE+Px, KE+Py, KE+Pvector, KE+Lx, KE+Ly, KE+Lz, KE+Lvector\n" |
| 125 |
> |
"\tmust be set to use RNEMD\n"); |
| 126 |
|
painCave.isFatal = 1; |
| 127 |
|
painCave.severity = OPENMD_ERROR; |
| 128 |
|
simError(); |
| 131 |
|
bool hasKineticFlux = rnemdParams->haveKineticFlux(); |
| 132 |
|
bool hasMomentumFlux = rnemdParams->haveMomentumFlux(); |
| 133 |
|
bool hasMomentumFluxVector = rnemdParams->haveMomentumFluxVector(); |
| 134 |
+ |
bool hasAngularMomentumFlux = rnemdParams->haveAngularMomentumFlux(); |
| 135 |
+ |
bool hasAngularMomentumFluxVector = rnemdParams->haveAngularMomentumFluxVector(); |
| 136 |
+ |
hasSelectionA_ = rnemdParams->haveSelectionA(); |
| 137 |
+ |
hasSelectionB_ = rnemdParams->haveSelectionB(); |
| 138 |
|
bool hasSlabWidth = rnemdParams->haveSlabWidth(); |
| 139 |
|
bool hasSlabACenter = rnemdParams->haveSlabACenter(); |
| 140 |
|
bool hasSlabBCenter = rnemdParams->haveSlabBCenter(); |
| 141 |
+ |
bool hasSphereARadius = rnemdParams->haveSphereARadius(); |
| 142 |
+ |
hasSphereBRadius_ = rnemdParams->haveSphereBRadius(); |
| 143 |
+ |
bool hasCoordinateOrigin = rnemdParams->haveCoordinateOrigin(); |
| 144 |
|
bool hasOutputFileName = rnemdParams->haveOutputFileName(); |
| 145 |
|
bool hasOutputFields = rnemdParams->haveOutputFields(); |
| 146 |
|
|
| 225 |
|
case rnemdPz: |
| 226 |
|
hasCorrectFlux = hasMomentumFlux; |
| 227 |
|
break; |
| 228 |
+ |
case rnemdLx: |
| 229 |
+ |
case rnemdLy: |
| 230 |
+ |
case rnemdLz: |
| 231 |
+ |
hasCorrectFlux = hasAngularMomentumFlux; |
| 232 |
+ |
break; |
| 233 |
|
case rnemdPvector: |
| 234 |
|
hasCorrectFlux = hasMomentumFluxVector; |
| 235 |
+ |
break; |
| 236 |
+ |
case rnemdLvector: |
| 237 |
+ |
hasCorrectFlux = hasAngularMomentumFluxVector; |
| 238 |
+ |
break; |
| 239 |
|
case rnemdKePx: |
| 240 |
|
case rnemdKePy: |
| 241 |
|
hasCorrectFlux = hasMomentumFlux && hasKineticFlux; |
| 242 |
|
break; |
| 243 |
+ |
case rnemdKeLx: |
| 244 |
+ |
case rnemdKeLy: |
| 245 |
+ |
case rnemdKeLz: |
| 246 |
+ |
hasCorrectFlux = hasAngularMomentumFlux && hasKineticFlux; |
| 247 |
+ |
break; |
| 248 |
|
case rnemdKePvector: |
| 249 |
|
hasCorrectFlux = hasMomentumFluxVector && hasKineticFlux; |
| 250 |
|
break; |
| 251 |
+ |
case rnemdKeLvector: |
| 252 |
+ |
hasCorrectFlux = hasAngularMomentumFluxVector && hasKineticFlux; |
| 253 |
+ |
break; |
| 254 |
|
default: |
| 255 |
|
methodFluxMismatch = true; |
| 256 |
|
break; |
| 271 |
|
} |
| 272 |
|
if (!hasCorrectFlux) { |
| 273 |
|
sprintf(painCave.errMsg, |
| 274 |
< |
"RNEMD: The current method,\n" |
| 228 |
< |
"\t%s, and flux type %s\n" |
| 274 |
> |
"RNEMD: The current method, %s, and flux type, %s,\n" |
| 275 |
|
"\tdid not have the correct flux value specified. Options\n" |
| 276 |
< |
"\tinclude: kineticFlux, momentumFlux, and momentumFluxVector\n", |
| 276 |
> |
"\tinclude: kineticFlux, momentumFlux, angularMomentumFlux,\n" |
| 277 |
> |
"\tmomentumFluxVector, and angularMomentumFluxVector.\n", |
| 278 |
|
methStr.c_str(), fluxStr.c_str()); |
| 279 |
|
painCave.isFatal = 1; |
| 280 |
|
painCave.severity = OPENMD_ERROR; |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
if (hasKineticFlux) { |
| 285 |
< |
kineticFlux_ = rnemdParams->getKineticFlux(); |
| 285 |
> |
// convert the kcal / mol / Angstroms^2 / fs values in the md file |
| 286 |
> |
// into amu / fs^3: |
| 287 |
> |
kineticFlux_ = rnemdParams->getKineticFlux() |
| 288 |
> |
* PhysicalConstants::energyConvert; |
| 289 |
|
} else { |
| 290 |
|
kineticFlux_ = 0.0; |
| 291 |
|
} |
| 314 |
|
default: |
| 315 |
|
break; |
| 316 |
|
} |
| 317 |
< |
} |
| 318 |
< |
} |
| 319 |
< |
|
| 320 |
< |
// do some sanity checking |
| 321 |
< |
|
| 322 |
< |
int selectionCount = seleMan_.getSelectionCount(); |
| 323 |
< |
int nIntegrable = info->getNGlobalIntegrableObjects(); |
| 324 |
< |
|
| 325 |
< |
if (selectionCount > nIntegrable) { |
| 326 |
< |
sprintf(painCave.errMsg, |
| 327 |
< |
"RNEMD: The current objectSelection,\n" |
| 328 |
< |
"\t\t%s\n" |
| 329 |
< |
"\thas resulted in %d selected objects. However,\n" |
| 330 |
< |
"\tthe total number of integrable objects in the system\n" |
| 331 |
< |
"\tis only %d. This is almost certainly not what you want\n" |
| 332 |
< |
"\tto do. A likely cause of this is forgetting the _RB_0\n" |
| 333 |
< |
"\tselector in the selection script!\n", |
| 334 |
< |
rnemdObjectSelection_.c_str(), |
| 335 |
< |
selectionCount, nIntegrable); |
| 336 |
< |
painCave.isFatal = 0; |
| 337 |
< |
painCave.severity = OPENMD_WARNING; |
| 338 |
< |
simError(); |
| 339 |
< |
} |
| 340 |
< |
|
| 341 |
< |
areaAccumulator_ = new Accumulator(); |
| 342 |
< |
|
| 343 |
< |
nBins_ = rnemdParams->getOutputBins(); |
| 317 |
> |
} |
| 318 |
> |
if (hasAngularMomentumFluxVector) { |
| 319 |
> |
angularMomentumFluxVector_ = rnemdParams->getAngularMomentumFluxVector(); |
| 320 |
> |
} else { |
| 321 |
> |
angularMomentumFluxVector_ = V3Zero; |
| 322 |
> |
if (hasAngularMomentumFlux) { |
| 323 |
> |
RealType angularMomentumFlux = rnemdParams->getAngularMomentumFlux(); |
| 324 |
> |
switch (rnemdFluxType_) { |
| 325 |
> |
case rnemdLx: |
| 326 |
> |
angularMomentumFluxVector_.x() = angularMomentumFlux; |
| 327 |
> |
break; |
| 328 |
> |
case rnemdLy: |
| 329 |
> |
angularMomentumFluxVector_.y() = angularMomentumFlux; |
| 330 |
> |
break; |
| 331 |
> |
case rnemdLz: |
| 332 |
> |
angularMomentumFluxVector_.z() = angularMomentumFlux; |
| 333 |
> |
break; |
| 334 |
> |
case rnemdKeLx: |
| 335 |
> |
angularMomentumFluxVector_.x() = angularMomentumFlux; |
| 336 |
> |
break; |
| 337 |
> |
case rnemdKeLy: |
| 338 |
> |
angularMomentumFluxVector_.y() = angularMomentumFlux; |
| 339 |
> |
break; |
| 340 |
> |
case rnemdKeLz: |
| 341 |
> |
angularMomentumFluxVector_.z() = angularMomentumFlux; |
| 342 |
> |
break; |
| 343 |
> |
default: |
| 344 |
> |
break; |
| 345 |
> |
} |
| 346 |
> |
} |
| 347 |
> |
} |
| 348 |
|
|
| 349 |
< |
data_.resize(RNEMD::ENDINDEX); |
| 350 |
< |
OutputData z; |
| 351 |
< |
z.units = "Angstroms"; |
| 352 |
< |
z.title = "Z"; |
| 353 |
< |
z.dataType = "RealType"; |
| 300 |
< |
z.accumulator.reserve(nBins_); |
| 301 |
< |
for (unsigned int i = 0; i < nBins_; i++) |
| 302 |
< |
z.accumulator.push_back( new Accumulator() ); |
| 303 |
< |
data_[Z] = z; |
| 304 |
< |
outputMap_["Z"] = Z; |
| 349 |
> |
if (hasCoordinateOrigin) { |
| 350 |
> |
coordinateOrigin_ = rnemdParams->getCoordinateOrigin(); |
| 351 |
> |
} else { |
| 352 |
> |
coordinateOrigin_ = V3Zero; |
| 353 |
> |
} |
| 354 |
|
|
| 355 |
< |
OutputData temperature; |
| 307 |
< |
temperature.units = "K"; |
| 308 |
< |
temperature.title = "Temperature"; |
| 309 |
< |
temperature.dataType = "RealType"; |
| 310 |
< |
temperature.accumulator.reserve(nBins_); |
| 311 |
< |
for (unsigned int i = 0; i < nBins_; i++) |
| 312 |
< |
temperature.accumulator.push_back( new Accumulator() ); |
| 313 |
< |
data_[TEMPERATURE] = temperature; |
| 314 |
< |
outputMap_["TEMPERATURE"] = TEMPERATURE; |
| 355 |
> |
// do some sanity checking |
| 356 |
|
|
| 357 |
< |
OutputData velocity; |
| 317 |
< |
velocity.units = "amu/fs"; |
| 318 |
< |
velocity.title = "Velocity"; |
| 319 |
< |
velocity.dataType = "Vector3d"; |
| 320 |
< |
velocity.accumulator.reserve(nBins_); |
| 321 |
< |
for (unsigned int i = 0; i < nBins_; i++) |
| 322 |
< |
velocity.accumulator.push_back( new VectorAccumulator() ); |
| 323 |
< |
data_[VELOCITY] = velocity; |
| 324 |
< |
outputMap_["VELOCITY"] = VELOCITY; |
| 357 |
> |
int selectionCount = seleMan_.getSelectionCount(); |
| 358 |
|
|
| 359 |
< |
OutputData density; |
| 360 |
< |
density.units = "g cm^-3"; |
| 361 |
< |
density.title = "Density"; |
| 362 |
< |
density.dataType = "RealType"; |
| 363 |
< |
density.accumulator.reserve(nBins_); |
| 364 |
< |
for (unsigned int i = 0; i < nBins_; i++) |
| 365 |
< |
density.accumulator.push_back( new Accumulator() ); |
| 366 |
< |
data_[DENSITY] = density; |
| 367 |
< |
outputMap_["DENSITY"] = DENSITY; |
| 359 |
> |
int nIntegrable = info->getNGlobalIntegrableObjects(); |
| 360 |
> |
|
| 361 |
> |
if (selectionCount > nIntegrable) { |
| 362 |
> |
sprintf(painCave.errMsg, |
| 363 |
> |
"RNEMD: The current objectSelection,\n" |
| 364 |
> |
"\t\t%s\n" |
| 365 |
> |
"\thas resulted in %d selected objects. However,\n" |
| 366 |
> |
"\tthe total number of integrable objects in the system\n" |
| 367 |
> |
"\tis only %d. This is almost certainly not what you want\n" |
| 368 |
> |
"\tto do. A likely cause of this is forgetting the _RB_0\n" |
| 369 |
> |
"\tselector in the selection script!\n", |
| 370 |
> |
rnemdObjectSelection_.c_str(), |
| 371 |
> |
selectionCount, nIntegrable); |
| 372 |
> |
painCave.isFatal = 0; |
| 373 |
> |
painCave.severity = OPENMD_WARNING; |
| 374 |
> |
simError(); |
| 375 |
> |
} |
| 376 |
> |
|
| 377 |
> |
areaAccumulator_ = new Accumulator(); |
| 378 |
> |
|
| 379 |
> |
nBins_ = rnemdParams->getOutputBins(); |
| 380 |
> |
binWidth_ = rnemdParams->getOutputBinWidth(); |
| 381 |
> |
|
| 382 |
> |
data_.resize(RNEMD::ENDINDEX); |
| 383 |
> |
OutputData z; |
| 384 |
> |
z.units = "Angstroms"; |
| 385 |
> |
z.title = "Z"; |
| 386 |
> |
z.dataType = "RealType"; |
| 387 |
> |
z.accumulator.reserve(nBins_); |
| 388 |
> |
for (int i = 0; i < nBins_; i++) |
| 389 |
> |
z.accumulator.push_back( new Accumulator() ); |
| 390 |
> |
data_[Z] = z; |
| 391 |
> |
outputMap_["Z"] = Z; |
| 392 |
|
|
| 393 |
< |
if (hasOutputFields) { |
| 394 |
< |
parseOutputFileFormat(rnemdParams->getOutputFields()); |
| 395 |
< |
} else { |
| 396 |
< |
outputMask_.set(Z); |
| 397 |
< |
switch (rnemdFluxType_) { |
| 398 |
< |
case rnemdKE: |
| 399 |
< |
case rnemdRotKE: |
| 400 |
< |
case rnemdFullKE: |
| 401 |
< |
outputMask_.set(TEMPERATURE); |
| 345 |
< |
break; |
| 346 |
< |
case rnemdPx: |
| 347 |
< |
case rnemdPy: |
| 348 |
< |
outputMask_.set(VELOCITY); |
| 349 |
< |
break; |
| 350 |
< |
case rnemdPz: |
| 351 |
< |
case rnemdPvector: |
| 352 |
< |
outputMask_.set(VELOCITY); |
| 353 |
< |
outputMask_.set(DENSITY); |
| 354 |
< |
break; |
| 355 |
< |
case rnemdKePx: |
| 356 |
< |
case rnemdKePy: |
| 357 |
< |
outputMask_.set(TEMPERATURE); |
| 358 |
< |
outputMask_.set(VELOCITY); |
| 359 |
< |
break; |
| 360 |
< |
case rnemdKePvector: |
| 361 |
< |
outputMask_.set(TEMPERATURE); |
| 362 |
< |
outputMask_.set(VELOCITY); |
| 363 |
< |
outputMask_.set(DENSITY); |
| 364 |
< |
break; |
| 365 |
< |
default: |
| 366 |
< |
break; |
| 367 |
< |
} |
| 368 |
< |
} |
| 369 |
< |
|
| 370 |
< |
if (hasOutputFileName) { |
| 371 |
< |
rnemdFileName_ = rnemdParams->getOutputFileName(); |
| 372 |
< |
} else { |
| 373 |
< |
rnemdFileName_ = getPrefix(info->getFinalConfigFileName()) + ".rnemd"; |
| 374 |
< |
} |
| 393 |
> |
OutputData r; |
| 394 |
> |
r.units = "Angstroms"; |
| 395 |
> |
r.title = "R"; |
| 396 |
> |
r.dataType = "RealType"; |
| 397 |
> |
r.accumulator.reserve(nBins_); |
| 398 |
> |
for (int i = 0; i < nBins_; i++) |
| 399 |
> |
r.accumulator.push_back( new Accumulator() ); |
| 400 |
> |
data_[R] = r; |
| 401 |
> |
outputMap_["R"] = R; |
| 402 |
|
|
| 403 |
< |
exchangeTime_ = rnemdParams->getExchangeTime(); |
| 403 |
> |
OutputData temperature; |
| 404 |
> |
temperature.units = "K"; |
| 405 |
> |
temperature.title = "Temperature"; |
| 406 |
> |
temperature.dataType = "RealType"; |
| 407 |
> |
temperature.accumulator.reserve(nBins_); |
| 408 |
> |
for (int i = 0; i < nBins_; i++) |
| 409 |
> |
temperature.accumulator.push_back( new Accumulator() ); |
| 410 |
> |
data_[TEMPERATURE] = temperature; |
| 411 |
> |
outputMap_["TEMPERATURE"] = TEMPERATURE; |
| 412 |
|
|
| 413 |
< |
Snapshot* currentSnap_ = info->getSnapshotManager()->getCurrentSnapshot(); |
| 414 |
< |
Mat3x3d hmat = currentSnap_->getHmat(); |
| 415 |
< |
|
| 416 |
< |
// Target exchange quantities (in each exchange) = 2 Lx Ly dt flux |
| 417 |
< |
// Lx, Ly = box dimensions in x & y |
| 418 |
< |
// dt = exchange time interval |
| 419 |
< |
// flux = target flux |
| 413 |
> |
OutputData velocity; |
| 414 |
> |
velocity.units = "angstroms/fs"; |
| 415 |
> |
velocity.title = "Velocity"; |
| 416 |
> |
velocity.dataType = "Vector3d"; |
| 417 |
> |
velocity.accumulator.reserve(nBins_); |
| 418 |
> |
for (int i = 0; i < nBins_; i++) |
| 419 |
> |
velocity.accumulator.push_back( new VectorAccumulator() ); |
| 420 |
> |
data_[VELOCITY] = velocity; |
| 421 |
> |
outputMap_["VELOCITY"] = VELOCITY; |
| 422 |
|
|
| 423 |
< |
RealType area = currentSnap_->getXYarea(); |
| 424 |
< |
kineticTarget_ = 2.0 * kineticFlux_ * exchangeTime_ * area; |
| 425 |
< |
momentumTarget_ = 2.0 * momentumFluxVector_ * exchangeTime_ * area; |
| 423 |
> |
OutputData angularVelocity; |
| 424 |
> |
angularVelocity.units = "angstroms^2/fs"; |
| 425 |
> |
angularVelocity.title = "AngularVelocity"; |
| 426 |
> |
angularVelocity.dataType = "Vector3d"; |
| 427 |
> |
angularVelocity.accumulator.reserve(nBins_); |
| 428 |
> |
for (int i = 0; i < nBins_; i++) |
| 429 |
> |
angularVelocity.accumulator.push_back( new VectorAccumulator() ); |
| 430 |
> |
data_[ANGULARVELOCITY] = angularVelocity; |
| 431 |
> |
outputMap_["ANGULARVELOCITY"] = ANGULARVELOCITY; |
| 432 |
|
|
| 433 |
< |
// total exchange sums are zeroed out at the beginning: |
| 433 |
> |
OutputData density; |
| 434 |
> |
density.units = "g cm^-3"; |
| 435 |
> |
density.title = "Density"; |
| 436 |
> |
density.dataType = "RealType"; |
| 437 |
> |
density.accumulator.reserve(nBins_); |
| 438 |
> |
for (int i = 0; i < nBins_; i++) |
| 439 |
> |
density.accumulator.push_back( new Accumulator() ); |
| 440 |
> |
data_[DENSITY] = density; |
| 441 |
> |
outputMap_["DENSITY"] = DENSITY; |
| 442 |
|
|
| 443 |
< |
kineticExchange_ = 0.0; |
| 444 |
< |
momentumExchange_ = V3Zero; |
| 443 |
> |
if (hasOutputFields) { |
| 444 |
> |
parseOutputFileFormat(rnemdParams->getOutputFields()); |
| 445 |
> |
} else { |
| 446 |
> |
if (usePeriodicBoundaryConditions_) |
| 447 |
> |
outputMask_.set(Z); |
| 448 |
> |
else |
| 449 |
> |
outputMask_.set(R); |
| 450 |
> |
switch (rnemdFluxType_) { |
| 451 |
> |
case rnemdKE: |
| 452 |
> |
case rnemdRotKE: |
| 453 |
> |
case rnemdFullKE: |
| 454 |
> |
outputMask_.set(TEMPERATURE); |
| 455 |
> |
break; |
| 456 |
> |
case rnemdPx: |
| 457 |
> |
case rnemdPy: |
| 458 |
> |
outputMask_.set(VELOCITY); |
| 459 |
> |
break; |
| 460 |
> |
case rnemdPz: |
| 461 |
> |
case rnemdPvector: |
| 462 |
> |
outputMask_.set(VELOCITY); |
| 463 |
> |
outputMask_.set(DENSITY); |
| 464 |
> |
break; |
| 465 |
> |
case rnemdLx: |
| 466 |
> |
case rnemdLy: |
| 467 |
> |
case rnemdLz: |
| 468 |
> |
case rnemdLvector: |
| 469 |
> |
outputMask_.set(ANGULARVELOCITY); |
| 470 |
> |
break; |
| 471 |
> |
case rnemdKeLx: |
| 472 |
> |
case rnemdKeLy: |
| 473 |
> |
case rnemdKeLz: |
| 474 |
> |
case rnemdKeLvector: |
| 475 |
> |
outputMask_.set(TEMPERATURE); |
| 476 |
> |
outputMask_.set(ANGULARVELOCITY); |
| 477 |
> |
break; |
| 478 |
> |
case rnemdKePx: |
| 479 |
> |
case rnemdKePy: |
| 480 |
> |
outputMask_.set(TEMPERATURE); |
| 481 |
> |
outputMask_.set(VELOCITY); |
| 482 |
> |
break; |
| 483 |
> |
case rnemdKePvector: |
| 484 |
> |
outputMask_.set(TEMPERATURE); |
| 485 |
> |
outputMask_.set(VELOCITY); |
| 486 |
> |
outputMask_.set(DENSITY); |
| 487 |
> |
break; |
| 488 |
> |
default: |
| 489 |
> |
break; |
| 490 |
> |
} |
| 491 |
> |
} |
| 492 |
> |
|
| 493 |
> |
if (hasOutputFileName) { |
| 494 |
> |
rnemdFileName_ = rnemdParams->getOutputFileName(); |
| 495 |
> |
} else { |
| 496 |
> |
rnemdFileName_ = getPrefix(info->getFinalConfigFileName()) + ".rnemd"; |
| 497 |
> |
} |
| 498 |
|
|
| 499 |
< |
if (hasSlabWidth) |
| 500 |
< |
slabWidth_ = rnemdParams->getSlabWidth(); |
| 501 |
< |
else |
| 502 |
< |
slabWidth_ = hmat(2,2) / 10.0; |
| 503 |
< |
|
| 504 |
< |
if (hasSlabACenter) |
| 505 |
< |
slabACenter_ = rnemdParams->getSlabACenter(); |
| 506 |
< |
else |
| 507 |
< |
slabACenter_ = 0.0; |
| 499 |
> |
exchangeTime_ = rnemdParams->getExchangeTime(); |
| 500 |
> |
|
| 501 |
> |
Snapshot* currentSnap_ = info->getSnapshotManager()->getCurrentSnapshot(); |
| 502 |
> |
// total exchange sums are zeroed out at the beginning: |
| 503 |
> |
|
| 504 |
> |
kineticExchange_ = 0.0; |
| 505 |
> |
momentumExchange_ = V3Zero; |
| 506 |
> |
angularMomentumExchange_ = V3Zero; |
| 507 |
> |
|
| 508 |
> |
std::ostringstream selectionAstream; |
| 509 |
> |
std::ostringstream selectionBstream; |
| 510 |
|
|
| 511 |
< |
if (hasSlabBCenter) |
| 512 |
< |
slabBCenter_ = rnemdParams->getSlabBCenter(); |
| 513 |
< |
else |
| 514 |
< |
slabBCenter_ = hmat(2,2) / 2.0; |
| 511 |
> |
if (hasSelectionA_) { |
| 512 |
> |
selectionA_ = rnemdParams->getSelectionA(); |
| 513 |
> |
} else { |
| 514 |
> |
if (usePeriodicBoundaryConditions_) { |
| 515 |
> |
Mat3x3d hmat = currentSnap_->getHmat(); |
| 516 |
> |
|
| 517 |
> |
if (hasSlabWidth) |
| 518 |
> |
slabWidth_ = rnemdParams->getSlabWidth(); |
| 519 |
> |
else |
| 520 |
> |
slabWidth_ = hmat(2,2) / 10.0; |
| 521 |
> |
|
| 522 |
> |
if (hasSlabACenter) |
| 523 |
> |
slabACenter_ = rnemdParams->getSlabACenter(); |
| 524 |
> |
else |
| 525 |
> |
slabACenter_ = 0.0; |
| 526 |
> |
|
| 527 |
> |
selectionAstream << "select wrappedz > " |
| 528 |
> |
<< slabACenter_ - 0.5*slabWidth_ |
| 529 |
> |
<< " && wrappedz < " |
| 530 |
> |
<< slabACenter_ + 0.5*slabWidth_; |
| 531 |
> |
selectionA_ = selectionAstream.str(); |
| 532 |
> |
} else { |
| 533 |
> |
if (hasSphereARadius) |
| 534 |
> |
sphereARadius_ = rnemdParams->getSphereARadius(); |
| 535 |
> |
else { |
| 536 |
> |
// use an initial guess to the size of the inner slab to be 1/10 the |
| 537 |
> |
// radius of an approximately spherical hull: |
| 538 |
> |
Thermo thermo(info); |
| 539 |
> |
RealType hVol = thermo.getHullVolume(); |
| 540 |
> |
sphereARadius_ = 0.1 * pow((3.0 * hVol / (4.0 * M_PI)), 1.0/3.0); |
| 541 |
> |
} |
| 542 |
> |
selectionAstream << "select r < " << sphereARadius_; |
| 543 |
> |
selectionA_ = selectionAstream.str(); |
| 544 |
> |
} |
| 545 |
> |
} |
| 546 |
|
|
| 547 |
+ |
if (hasSelectionB_) { |
| 548 |
+ |
selectionB_ = rnemdParams->getSelectionB(); |
| 549 |
+ |
} else { |
| 550 |
+ |
if (usePeriodicBoundaryConditions_) { |
| 551 |
+ |
Mat3x3d hmat = currentSnap_->getHmat(); |
| 552 |
+ |
|
| 553 |
+ |
if (hasSlabWidth) |
| 554 |
+ |
slabWidth_ = rnemdParams->getSlabWidth(); |
| 555 |
+ |
else |
| 556 |
+ |
slabWidth_ = hmat(2,2) / 10.0; |
| 557 |
+ |
|
| 558 |
+ |
if (hasSlabBCenter) |
| 559 |
+ |
slabBCenter_ = rnemdParams->getSlabBCenter(); |
| 560 |
+ |
else |
| 561 |
+ |
slabBCenter_ = hmat(2,2) / 2.0; |
| 562 |
+ |
|
| 563 |
+ |
selectionBstream << "select wrappedz > " |
| 564 |
+ |
<< slabBCenter_ - 0.5*slabWidth_ |
| 565 |
+ |
<< " && wrappedz < " |
| 566 |
+ |
<< slabBCenter_ + 0.5*slabWidth_; |
| 567 |
+ |
selectionB_ = selectionBstream.str(); |
| 568 |
+ |
} else { |
| 569 |
+ |
if (hasSphereBRadius_) { |
| 570 |
+ |
sphereBRadius_ = rnemdParams->getSphereBRadius(); |
| 571 |
+ |
selectionBstream << "select r > " << sphereBRadius_; |
| 572 |
+ |
selectionB_ = selectionBstream.str(); |
| 573 |
+ |
} else { |
| 574 |
+ |
selectionB_ = "select hull"; |
| 575 |
+ |
hasSelectionB_ = true; |
| 576 |
+ |
} |
| 577 |
+ |
} |
| 578 |
+ |
} |
| 579 |
+ |
} |
| 580 |
+ |
|
| 581 |
+ |
// object evaluator: |
| 582 |
+ |
evaluator_.loadScriptString(rnemdObjectSelection_); |
| 583 |
+ |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 584 |
+ |
evaluatorA_.loadScriptString(selectionA_); |
| 585 |
+ |
evaluatorB_.loadScriptString(selectionB_); |
| 586 |
+ |
seleManA_.setSelectionSet(evaluatorA_.evaluate()); |
| 587 |
+ |
seleManB_.setSelectionSet(evaluatorB_.evaluate()); |
| 588 |
+ |
commonA_ = seleManA_ & seleMan_; |
| 589 |
+ |
commonB_ = seleManB_ & seleMan_; |
| 590 |
|
} |
| 591 |
< |
|
| 412 |
< |
RNEMD::~RNEMD() { |
| 591 |
> |
|
| 592 |
|
|
| 593 |
+ |
RNEMD::~RNEMD() { |
| 594 |
+ |
if (!doRNEMD_) return; |
| 595 |
|
#ifdef IS_MPI |
| 596 |
|
if (worldRank == 0) { |
| 597 |
|
#endif |
| 605 |
|
#endif |
| 606 |
|
} |
| 607 |
|
|
| 608 |
< |
bool RNEMD::inSlabA(Vector3d pos) { |
| 609 |
< |
return (abs(pos.z() - slabACenter_) < 0.5*slabWidth_); |
| 610 |
< |
} |
| 611 |
< |
bool RNEMD::inSlabB(Vector3d pos) { |
| 431 |
< |
return (abs(pos.z() - slabBCenter_) < 0.5*slabWidth_); |
| 432 |
< |
} |
| 608 |
> |
void RNEMD::doSwap(SelectionManager& smanA, SelectionManager& smanB) { |
| 609 |
> |
if (!doRNEMD_) return; |
| 610 |
> |
int selei; |
| 611 |
> |
int selej; |
| 612 |
|
|
| 434 |
– |
void RNEMD::doSwap() { |
| 435 |
– |
|
| 613 |
|
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 614 |
|
Mat3x3d hmat = currentSnap_->getHmat(); |
| 615 |
|
|
| 439 |
– |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 440 |
– |
|
| 441 |
– |
int selei; |
| 616 |
|
StuntDouble* sd; |
| 443 |
– |
int idx; |
| 617 |
|
|
| 618 |
|
RealType min_val; |
| 619 |
|
bool min_found = false; |
| 623 |
|
bool max_found = false; |
| 624 |
|
StuntDouble* max_sd; |
| 625 |
|
|
| 626 |
< |
for (sd = seleMan_.beginSelected(selei); sd != NULL; |
| 627 |
< |
sd = seleMan_.nextSelected(selei)) { |
| 626 |
> |
for (sd = seleManA_.beginSelected(selei); sd != NULL; |
| 627 |
> |
sd = seleManA_.nextSelected(selei)) { |
| 628 |
|
|
| 456 |
– |
idx = sd->getLocalIndex(); |
| 457 |
– |
|
| 629 |
|
Vector3d pos = sd->getPos(); |
| 630 |
< |
|
| 630 |
> |
|
| 631 |
|
// wrap the stuntdouble's position back into the box: |
| 632 |
< |
|
| 632 |
> |
|
| 633 |
|
if (usePeriodicBoundaryConditions_) |
| 634 |
|
currentSnap_->wrapVector(pos); |
| 635 |
< |
bool inA = inSlabA(pos); |
| 636 |
< |
bool inB = inSlabB(pos); |
| 637 |
< |
|
| 638 |
< |
if (inA || inB) { |
| 635 |
> |
|
| 636 |
> |
RealType mass = sd->getMass(); |
| 637 |
> |
Vector3d vel = sd->getVel(); |
| 638 |
> |
RealType value; |
| 639 |
> |
|
| 640 |
> |
switch(rnemdFluxType_) { |
| 641 |
> |
case rnemdKE : |
| 642 |
|
|
| 643 |
< |
RealType mass = sd->getMass(); |
| 644 |
< |
Vector3d vel = sd->getVel(); |
| 645 |
< |
RealType value; |
| 646 |
< |
|
| 647 |
< |
switch(rnemdFluxType_) { |
| 474 |
< |
case rnemdKE : |
| 643 |
> |
value = mass * vel.lengthSquare(); |
| 644 |
> |
|
| 645 |
> |
if (sd->isDirectional()) { |
| 646 |
> |
Vector3d angMom = sd->getJ(); |
| 647 |
> |
Mat3x3d I = sd->getI(); |
| 648 |
|
|
| 649 |
< |
value = mass * vel.lengthSquare(); |
| 650 |
< |
|
| 651 |
< |
if (sd->isDirectional()) { |
| 652 |
< |
Vector3d angMom = sd->getJ(); |
| 653 |
< |
Mat3x3d I = sd->getI(); |
| 654 |
< |
|
| 655 |
< |
if (sd->isLinear()) { |
| 656 |
< |
int i = sd->linearAxis(); |
| 657 |
< |
int j = (i + 1) % 3; |
| 658 |
< |
int k = (i + 2) % 3; |
| 659 |
< |
value += angMom[j] * angMom[j] / I(j, j) + |
| 660 |
< |
angMom[k] * angMom[k] / I(k, k); |
| 661 |
< |
} else { |
| 662 |
< |
value += angMom[0]*angMom[0]/I(0, 0) |
| 663 |
< |
+ angMom[1]*angMom[1]/I(1, 1) |
| 664 |
< |
+ angMom[2]*angMom[2]/I(2, 2); |
| 665 |
< |
} |
| 666 |
< |
} //angular momenta exchange enabled |
| 667 |
< |
//energyConvert temporarily disabled |
| 668 |
< |
//make kineticExchange_ comparable between swap & scale |
| 669 |
< |
//value = value * 0.5 / PhysicalConstants::energyConvert; |
| 670 |
< |
value *= 0.5; |
| 671 |
< |
break; |
| 672 |
< |
case rnemdPx : |
| 673 |
< |
value = mass * vel[0]; |
| 674 |
< |
break; |
| 675 |
< |
case rnemdPy : |
| 676 |
< |
value = mass * vel[1]; |
| 677 |
< |
break; |
| 678 |
< |
case rnemdPz : |
| 679 |
< |
value = mass * vel[2]; |
| 680 |
< |
break; |
| 681 |
< |
default : |
| 682 |
< |
break; |
| 649 |
> |
if (sd->isLinear()) { |
| 650 |
> |
int i = sd->linearAxis(); |
| 651 |
> |
int j = (i + 1) % 3; |
| 652 |
> |
int k = (i + 2) % 3; |
| 653 |
> |
value += angMom[j] * angMom[j] / I(j, j) + |
| 654 |
> |
angMom[k] * angMom[k] / I(k, k); |
| 655 |
> |
} else { |
| 656 |
> |
value += angMom[0]*angMom[0]/I(0, 0) |
| 657 |
> |
+ angMom[1]*angMom[1]/I(1, 1) |
| 658 |
> |
+ angMom[2]*angMom[2]/I(2, 2); |
| 659 |
> |
} |
| 660 |
> |
} //angular momenta exchange enabled |
| 661 |
> |
value *= 0.5; |
| 662 |
> |
break; |
| 663 |
> |
case rnemdPx : |
| 664 |
> |
value = mass * vel[0]; |
| 665 |
> |
break; |
| 666 |
> |
case rnemdPy : |
| 667 |
> |
value = mass * vel[1]; |
| 668 |
> |
break; |
| 669 |
> |
case rnemdPz : |
| 670 |
> |
value = mass * vel[2]; |
| 671 |
> |
break; |
| 672 |
> |
default : |
| 673 |
> |
break; |
| 674 |
> |
} |
| 675 |
> |
if (!max_found) { |
| 676 |
> |
max_val = value; |
| 677 |
> |
max_sd = sd; |
| 678 |
> |
max_found = true; |
| 679 |
> |
} else { |
| 680 |
> |
if (max_val < value) { |
| 681 |
> |
max_val = value; |
| 682 |
> |
max_sd = sd; |
| 683 |
|
} |
| 684 |
+ |
} |
| 685 |
+ |
} |
| 686 |
|
|
| 687 |
< |
if (inA == 0) { |
| 688 |
< |
if (!min_found) { |
| 689 |
< |
min_val = value; |
| 690 |
< |
min_sd = sd; |
| 691 |
< |
min_found = true; |
| 692 |
< |
} else { |
| 693 |
< |
if (min_val > value) { |
| 694 |
< |
min_val = value; |
| 695 |
< |
min_sd = sd; |
| 696 |
< |
} |
| 697 |
< |
} |
| 698 |
< |
} else { |
| 699 |
< |
if (!max_found) { |
| 700 |
< |
max_val = value; |
| 701 |
< |
max_sd = sd; |
| 702 |
< |
max_found = true; |
| 703 |
< |
} else { |
| 704 |
< |
if (max_val < value) { |
| 705 |
< |
max_val = value; |
| 706 |
< |
max_sd = sd; |
| 707 |
< |
} |
| 708 |
< |
} |
| 709 |
< |
} |
| 687 |
> |
for (sd = seleManB_.beginSelected(selej); sd != NULL; |
| 688 |
> |
sd = seleManB_.nextSelected(selej)) { |
| 689 |
> |
|
| 690 |
> |
Vector3d pos = sd->getPos(); |
| 691 |
> |
|
| 692 |
> |
// wrap the stuntdouble's position back into the box: |
| 693 |
> |
|
| 694 |
> |
if (usePeriodicBoundaryConditions_) |
| 695 |
> |
currentSnap_->wrapVector(pos); |
| 696 |
> |
|
| 697 |
> |
RealType mass = sd->getMass(); |
| 698 |
> |
Vector3d vel = sd->getVel(); |
| 699 |
> |
RealType value; |
| 700 |
> |
|
| 701 |
> |
switch(rnemdFluxType_) { |
| 702 |
> |
case rnemdKE : |
| 703 |
> |
|
| 704 |
> |
value = mass * vel.lengthSquare(); |
| 705 |
> |
|
| 706 |
> |
if (sd->isDirectional()) { |
| 707 |
> |
Vector3d angMom = sd->getJ(); |
| 708 |
> |
Mat3x3d I = sd->getI(); |
| 709 |
> |
|
| 710 |
> |
if (sd->isLinear()) { |
| 711 |
> |
int i = sd->linearAxis(); |
| 712 |
> |
int j = (i + 1) % 3; |
| 713 |
> |
int k = (i + 2) % 3; |
| 714 |
> |
value += angMom[j] * angMom[j] / I(j, j) + |
| 715 |
> |
angMom[k] * angMom[k] / I(k, k); |
| 716 |
> |
} else { |
| 717 |
> |
value += angMom[0]*angMom[0]/I(0, 0) |
| 718 |
> |
+ angMom[1]*angMom[1]/I(1, 1) |
| 719 |
> |
+ angMom[2]*angMom[2]/I(2, 2); |
| 720 |
> |
} |
| 721 |
> |
} //angular momenta exchange enabled |
| 722 |
> |
value *= 0.5; |
| 723 |
> |
break; |
| 724 |
> |
case rnemdPx : |
| 725 |
> |
value = mass * vel[0]; |
| 726 |
> |
break; |
| 727 |
> |
case rnemdPy : |
| 728 |
> |
value = mass * vel[1]; |
| 729 |
> |
break; |
| 730 |
> |
case rnemdPz : |
| 731 |
> |
value = mass * vel[2]; |
| 732 |
> |
break; |
| 733 |
> |
default : |
| 734 |
> |
break; |
| 735 |
|
} |
| 736 |
+ |
|
| 737 |
+ |
if (!min_found) { |
| 738 |
+ |
min_val = value; |
| 739 |
+ |
min_sd = sd; |
| 740 |
+ |
min_found = true; |
| 741 |
+ |
} else { |
| 742 |
+ |
if (min_val > value) { |
| 743 |
+ |
min_val = value; |
| 744 |
+ |
min_sd = sd; |
| 745 |
+ |
} |
| 746 |
+ |
} |
| 747 |
|
} |
| 748 |
|
|
| 749 |
< |
#ifdef IS_MPI |
| 750 |
< |
int nProc, worldRank; |
| 749 |
> |
#ifdef IS_MPI |
| 750 |
> |
int worldRank = MPI::COMM_WORLD.Get_rank(); |
| 751 |
|
|
| 541 |
– |
nProc = MPI::COMM_WORLD.Get_size(); |
| 542 |
– |
worldRank = MPI::COMM_WORLD.Get_rank(); |
| 543 |
– |
|
| 752 |
|
bool my_min_found = min_found; |
| 753 |
|
bool my_max_found = max_found; |
| 754 |
|
|
| 939 |
|
|
| 940 |
|
switch(rnemdFluxType_) { |
| 941 |
|
case rnemdKE: |
| 734 |
– |
cerr << "KE\n"; |
| 942 |
|
kineticExchange_ += max_val - min_val; |
| 943 |
|
break; |
| 944 |
|
case rnemdPx: |
| 951 |
|
momentumExchange_.z() += max_val - min_val; |
| 952 |
|
break; |
| 953 |
|
default: |
| 747 |
– |
cerr << "default\n"; |
| 954 |
|
break; |
| 955 |
|
} |
| 956 |
|
} else { |
| 972 |
|
} |
| 973 |
|
} |
| 974 |
|
|
| 975 |
< |
void RNEMD::doNIVS() { |
| 975 |
> |
void RNEMD::doNIVS(SelectionManager& smanA, SelectionManager& smanB) { |
| 976 |
> |
if (!doRNEMD_) return; |
| 977 |
> |
int selei; |
| 978 |
> |
int selej; |
| 979 |
|
|
| 980 |
|
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 981 |
+ |
RealType time = currentSnap_->getTime(); |
| 982 |
|
Mat3x3d hmat = currentSnap_->getHmat(); |
| 773 |
– |
|
| 774 |
– |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 983 |
|
|
| 776 |
– |
int selei; |
| 984 |
|
StuntDouble* sd; |
| 778 |
– |
int idx; |
| 985 |
|
|
| 986 |
|
vector<StuntDouble*> hotBin, coldBin; |
| 987 |
|
|
| 1000 |
|
RealType Kcz = 0.0; |
| 1001 |
|
RealType Kcw = 0.0; |
| 1002 |
|
|
| 1003 |
< |
for (sd = seleMan_.beginSelected(selei); sd != NULL; |
| 1004 |
< |
sd = seleMan_.nextSelected(selei)) { |
| 1003 |
> |
for (sd = smanA.beginSelected(selei); sd != NULL; |
| 1004 |
> |
sd = smanA.nextSelected(selei)) { |
| 1005 |
|
|
| 800 |
– |
idx = sd->getLocalIndex(); |
| 801 |
– |
|
| 1006 |
|
Vector3d pos = sd->getPos(); |
| 1007 |
< |
|
| 1007 |
> |
|
| 1008 |
|
// wrap the stuntdouble's position back into the box: |
| 1009 |
< |
|
| 1009 |
> |
|
| 1010 |
|
if (usePeriodicBoundaryConditions_) |
| 1011 |
|
currentSnap_->wrapVector(pos); |
| 1012 |
< |
|
| 1013 |
< |
// which bin is this stuntdouble in? |
| 1014 |
< |
bool inA = inSlabA(pos); |
| 1015 |
< |
bool inB = inSlabB(pos); |
| 1012 |
> |
|
| 1013 |
> |
|
| 1014 |
> |
RealType mass = sd->getMass(); |
| 1015 |
> |
Vector3d vel = sd->getVel(); |
| 1016 |
> |
|
| 1017 |
> |
hotBin.push_back(sd); |
| 1018 |
> |
Phx += mass * vel.x(); |
| 1019 |
> |
Phy += mass * vel.y(); |
| 1020 |
> |
Phz += mass * vel.z(); |
| 1021 |
> |
Khx += mass * vel.x() * vel.x(); |
| 1022 |
> |
Khy += mass * vel.y() * vel.y(); |
| 1023 |
> |
Khz += mass * vel.z() * vel.z(); |
| 1024 |
> |
if (sd->isDirectional()) { |
| 1025 |
> |
Vector3d angMom = sd->getJ(); |
| 1026 |
> |
Mat3x3d I = sd->getI(); |
| 1027 |
> |
if (sd->isLinear()) { |
| 1028 |
> |
int i = sd->linearAxis(); |
| 1029 |
> |
int j = (i + 1) % 3; |
| 1030 |
> |
int k = (i + 2) % 3; |
| 1031 |
> |
Khw += angMom[j] * angMom[j] / I(j, j) + |
| 1032 |
> |
angMom[k] * angMom[k] / I(k, k); |
| 1033 |
> |
} else { |
| 1034 |
> |
Khw += angMom[0]*angMom[0]/I(0, 0) |
| 1035 |
> |
+ angMom[1]*angMom[1]/I(1, 1) |
| 1036 |
> |
+ angMom[2]*angMom[2]/I(2, 2); |
| 1037 |
> |
} |
| 1038 |
> |
} |
| 1039 |
> |
} |
| 1040 |
> |
for (sd = smanB.beginSelected(selej); sd != NULL; |
| 1041 |
> |
sd = smanB.nextSelected(selej)) { |
| 1042 |
> |
Vector3d pos = sd->getPos(); |
| 1043 |
> |
|
| 1044 |
> |
// wrap the stuntdouble's position back into the box: |
| 1045 |
> |
|
| 1046 |
> |
if (usePeriodicBoundaryConditions_) |
| 1047 |
> |
currentSnap_->wrapVector(pos); |
| 1048 |
> |
|
| 1049 |
> |
RealType mass = sd->getMass(); |
| 1050 |
> |
Vector3d vel = sd->getVel(); |
| 1051 |
|
|
| 1052 |
< |
if (inA || inB) { |
| 1053 |
< |
|
| 1054 |
< |
RealType mass = sd->getMass(); |
| 1055 |
< |
Vector3d vel = sd->getVel(); |
| 1056 |
< |
|
| 1057 |
< |
if (inA) { |
| 1058 |
< |
hotBin.push_back(sd); |
| 1059 |
< |
Phx += mass * vel.x(); |
| 1060 |
< |
Phy += mass * vel.y(); |
| 1061 |
< |
Phz += mass * vel.z(); |
| 1062 |
< |
Khx += mass * vel.x() * vel.x(); |
| 1063 |
< |
Khy += mass * vel.y() * vel.y(); |
| 1064 |
< |
Khz += mass * vel.z() * vel.z(); |
| 1065 |
< |
if (sd->isDirectional()) { |
| 1066 |
< |
Vector3d angMom = sd->getJ(); |
| 1067 |
< |
Mat3x3d I = sd->getI(); |
| 1068 |
< |
if (sd->isLinear()) { |
| 1069 |
< |
int i = sd->linearAxis(); |
| 1070 |
< |
int j = (i + 1) % 3; |
| 1071 |
< |
int k = (i + 2) % 3; |
| 1072 |
< |
Khw += angMom[j] * angMom[j] / I(j, j) + |
| 834 |
< |
angMom[k] * angMom[k] / I(k, k); |
| 835 |
< |
} else { |
| 836 |
< |
Khw += angMom[0]*angMom[0]/I(0, 0) |
| 837 |
< |
+ angMom[1]*angMom[1]/I(1, 1) |
| 838 |
< |
+ angMom[2]*angMom[2]/I(2, 2); |
| 839 |
< |
} |
| 840 |
< |
} |
| 841 |
< |
} else { |
| 842 |
< |
coldBin.push_back(sd); |
| 843 |
< |
Pcx += mass * vel.x(); |
| 844 |
< |
Pcy += mass * vel.y(); |
| 845 |
< |
Pcz += mass * vel.z(); |
| 846 |
< |
Kcx += mass * vel.x() * vel.x(); |
| 847 |
< |
Kcy += mass * vel.y() * vel.y(); |
| 848 |
< |
Kcz += mass * vel.z() * vel.z(); |
| 849 |
< |
if (sd->isDirectional()) { |
| 850 |
< |
Vector3d angMom = sd->getJ(); |
| 851 |
< |
Mat3x3d I = sd->getI(); |
| 852 |
< |
if (sd->isLinear()) { |
| 853 |
< |
int i = sd->linearAxis(); |
| 854 |
< |
int j = (i + 1) % 3; |
| 855 |
< |
int k = (i + 2) % 3; |
| 856 |
< |
Kcw += angMom[j] * angMom[j] / I(j, j) + |
| 857 |
< |
angMom[k] * angMom[k] / I(k, k); |
| 858 |
< |
} else { |
| 859 |
< |
Kcw += angMom[0]*angMom[0]/I(0, 0) |
| 860 |
< |
+ angMom[1]*angMom[1]/I(1, 1) |
| 861 |
< |
+ angMom[2]*angMom[2]/I(2, 2); |
| 862 |
< |
} |
| 863 |
< |
} |
| 864 |
< |
} |
| 1052 |
> |
coldBin.push_back(sd); |
| 1053 |
> |
Pcx += mass * vel.x(); |
| 1054 |
> |
Pcy += mass * vel.y(); |
| 1055 |
> |
Pcz += mass * vel.z(); |
| 1056 |
> |
Kcx += mass * vel.x() * vel.x(); |
| 1057 |
> |
Kcy += mass * vel.y() * vel.y(); |
| 1058 |
> |
Kcz += mass * vel.z() * vel.z(); |
| 1059 |
> |
if (sd->isDirectional()) { |
| 1060 |
> |
Vector3d angMom = sd->getJ(); |
| 1061 |
> |
Mat3x3d I = sd->getI(); |
| 1062 |
> |
if (sd->isLinear()) { |
| 1063 |
> |
int i = sd->linearAxis(); |
| 1064 |
> |
int j = (i + 1) % 3; |
| 1065 |
> |
int k = (i + 2) % 3; |
| 1066 |
> |
Kcw += angMom[j] * angMom[j] / I(j, j) + |
| 1067 |
> |
angMom[k] * angMom[k] / I(k, k); |
| 1068 |
> |
} else { |
| 1069 |
> |
Kcw += angMom[0]*angMom[0]/I(0, 0) |
| 1070 |
> |
+ angMom[1]*angMom[1]/I(1, 1) |
| 1071 |
> |
+ angMom[2]*angMom[2]/I(2, 2); |
| 1072 |
> |
} |
| 1073 |
|
} |
| 1074 |
|
} |
| 1075 |
|
|
| 1119 |
|
|
| 1120 |
|
if ((c > 0.81) && (c < 1.21)) {//restrict scaling coefficients |
| 1121 |
|
c = sqrt(c); |
| 1122 |
< |
//std::cerr << "cold slab scaling coefficient: " << c << endl; |
| 915 |
< |
//now convert to hotBin coefficient |
| 1122 |
> |
|
| 1123 |
|
RealType w = 0.0; |
| 1124 |
|
if (rnemdFluxType_ == rnemdFullKE) { |
| 1125 |
|
x = 1.0 + px * (1.0 - c); |
| 1157 |
|
} |
| 1158 |
|
} |
| 1159 |
|
w = sqrt(w); |
| 953 |
– |
// std::cerr << "xh= " << x << "\tyh= " << y << "\tzh= " << z |
| 954 |
– |
// << "\twh= " << w << endl; |
| 1160 |
|
for (sdi = hotBin.begin(); sdi != hotBin.end(); sdi++) { |
| 1161 |
|
if (rnemdFluxType_ == rnemdFullKE) { |
| 1162 |
|
vel = (*sdi)->getVel(); |
| 1419 |
|
failTrialCount_++; |
| 1420 |
|
} |
| 1421 |
|
} |
| 1422 |
< |
|
| 1423 |
< |
void RNEMD::doVSS() { |
| 1422 |
> |
|
| 1423 |
> |
void RNEMD::doVSS(SelectionManager& smanA, SelectionManager& smanB) { |
| 1424 |
> |
if (!doRNEMD_) return; |
| 1425 |
> |
int selei; |
| 1426 |
> |
int selej; |
| 1427 |
|
|
| 1428 |
|
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 1429 |
|
RealType time = currentSnap_->getTime(); |
| 1430 |
|
Mat3x3d hmat = currentSnap_->getHmat(); |
| 1223 |
– |
|
| 1224 |
– |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 1431 |
|
|
| 1226 |
– |
int selei; |
| 1432 |
|
StuntDouble* sd; |
| 1228 |
– |
int idx; |
| 1433 |
|
|
| 1434 |
|
vector<StuntDouble*> hotBin, coldBin; |
| 1435 |
|
|
| 1436 |
|
Vector3d Ph(V3Zero); |
| 1437 |
+ |
Vector3d Lh(V3Zero); |
| 1438 |
|
RealType Mh = 0.0; |
| 1439 |
+ |
Mat3x3d Ih(0.0); |
| 1440 |
|
RealType Kh = 0.0; |
| 1441 |
|
Vector3d Pc(V3Zero); |
| 1442 |
+ |
Vector3d Lc(V3Zero); |
| 1443 |
|
RealType Mc = 0.0; |
| 1444 |
+ |
Mat3x3d Ic(0.0); |
| 1445 |
|
RealType Kc = 0.0; |
| 1238 |
– |
|
| 1446 |
|
|
| 1447 |
< |
for (sd = seleMan_.beginSelected(selei); sd != NULL; |
| 1448 |
< |
sd = seleMan_.nextSelected(selei)) { |
| 1447 |
> |
// Constraints can be on only the linear or angular momentum, but |
| 1448 |
> |
// not both. Usually, the user will specify which they want, but |
| 1449 |
> |
// in case they don't, the use of periodic boundaries should make |
| 1450 |
> |
// the choice for us. |
| 1451 |
> |
bool doLinearPart = false; |
| 1452 |
> |
bool doAngularPart = false; |
| 1453 |
|
|
| 1454 |
< |
idx = sd->getLocalIndex(); |
| 1454 |
> |
switch (rnemdFluxType_) { |
| 1455 |
> |
case rnemdPx: |
| 1456 |
> |
case rnemdPy: |
| 1457 |
> |
case rnemdPz: |
| 1458 |
> |
case rnemdPvector: |
| 1459 |
> |
case rnemdKePx: |
| 1460 |
> |
case rnemdKePy: |
| 1461 |
> |
case rnemdKePvector: |
| 1462 |
> |
doLinearPart = true; |
| 1463 |
> |
break; |
| 1464 |
> |
case rnemdLx: |
| 1465 |
> |
case rnemdLy: |
| 1466 |
> |
case rnemdLz: |
| 1467 |
> |
case rnemdLvector: |
| 1468 |
> |
case rnemdKeLx: |
| 1469 |
> |
case rnemdKeLy: |
| 1470 |
> |
case rnemdKeLz: |
| 1471 |
> |
case rnemdKeLvector: |
| 1472 |
> |
doAngularPart = true; |
| 1473 |
> |
break; |
| 1474 |
> |
case rnemdKE: |
| 1475 |
> |
case rnemdRotKE: |
| 1476 |
> |
case rnemdFullKE: |
| 1477 |
> |
default: |
| 1478 |
> |
if (usePeriodicBoundaryConditions_) |
| 1479 |
> |
doLinearPart = true; |
| 1480 |
> |
else |
| 1481 |
> |
doAngularPart = true; |
| 1482 |
> |
break; |
| 1483 |
> |
} |
| 1484 |
> |
|
| 1485 |
> |
for (sd = smanA.beginSelected(selei); sd != NULL; |
| 1486 |
> |
sd = smanA.nextSelected(selei)) { |
| 1487 |
|
|
| 1488 |
|
Vector3d pos = sd->getPos(); |
| 1489 |
|
|
| 1490 |
|
// wrap the stuntdouble's position back into the box: |
| 1491 |
+ |
|
| 1492 |
+ |
if (usePeriodicBoundaryConditions_) |
| 1493 |
+ |
currentSnap_->wrapVector(pos); |
| 1494 |
+ |
|
| 1495 |
+ |
RealType mass = sd->getMass(); |
| 1496 |
+ |
Vector3d vel = sd->getVel(); |
| 1497 |
+ |
Vector3d rPos = sd->getPos() - coordinateOrigin_; |
| 1498 |
+ |
RealType r2; |
| 1499 |
+ |
|
| 1500 |
+ |
hotBin.push_back(sd); |
| 1501 |
+ |
Ph += mass * vel; |
| 1502 |
+ |
Mh += mass; |
| 1503 |
+ |
Kh += mass * vel.lengthSquare(); |
| 1504 |
+ |
Lh += mass * cross(rPos, vel); |
| 1505 |
+ |
Ih -= outProduct(rPos, rPos) * mass; |
| 1506 |
+ |
r2 = rPos.lengthSquare(); |
| 1507 |
+ |
Ih(0, 0) += mass * r2; |
| 1508 |
+ |
Ih(1, 1) += mass * r2; |
| 1509 |
+ |
Ih(2, 2) += mass * r2; |
| 1510 |
+ |
|
| 1511 |
+ |
if (rnemdFluxType_ == rnemdFullKE) { |
| 1512 |
+ |
if (sd->isDirectional()) { |
| 1513 |
+ |
Vector3d angMom = sd->getJ(); |
| 1514 |
+ |
Mat3x3d I = sd->getI(); |
| 1515 |
+ |
if (sd->isLinear()) { |
| 1516 |
+ |
int i = sd->linearAxis(); |
| 1517 |
+ |
int j = (i + 1) % 3; |
| 1518 |
+ |
int k = (i + 2) % 3; |
| 1519 |
+ |
Kh += angMom[j] * angMom[j] / I(j, j) + |
| 1520 |
+ |
angMom[k] * angMom[k] / I(k, k); |
| 1521 |
+ |
} else { |
| 1522 |
+ |
Kh += angMom[0] * angMom[0] / I(0, 0) + |
| 1523 |
+ |
angMom[1] * angMom[1] / I(1, 1) + |
| 1524 |
+ |
angMom[2] * angMom[2] / I(2, 2); |
| 1525 |
+ |
} |
| 1526 |
+ |
} |
| 1527 |
+ |
} |
| 1528 |
+ |
} |
| 1529 |
+ |
for (sd = smanB.beginSelected(selej); sd != NULL; |
| 1530 |
+ |
sd = smanB.nextSelected(selej)) { |
| 1531 |
|
|
| 1532 |
+ |
Vector3d pos = sd->getPos(); |
| 1533 |
+ |
|
| 1534 |
+ |
// wrap the stuntdouble's position back into the box: |
| 1535 |
+ |
|
| 1536 |
|
if (usePeriodicBoundaryConditions_) |
| 1537 |
|
currentSnap_->wrapVector(pos); |
| 1538 |
+ |
|
| 1539 |
+ |
RealType mass = sd->getMass(); |
| 1540 |
+ |
Vector3d vel = sd->getVel(); |
| 1541 |
+ |
Vector3d rPos = sd->getPos() - coordinateOrigin_; |
| 1542 |
+ |
RealType r2; |
| 1543 |
|
|
| 1544 |
< |
// which bin is this stuntdouble in? |
| 1545 |
< |
bool inA = inSlabA(pos); |
| 1546 |
< |
bool inB = inSlabB(pos); |
| 1544 |
> |
coldBin.push_back(sd); |
| 1545 |
> |
Pc += mass * vel; |
| 1546 |
> |
Mc += mass; |
| 1547 |
> |
Kc += mass * vel.lengthSquare(); |
| 1548 |
> |
Lc += mass * cross(rPos, vel); |
| 1549 |
> |
Ic -= outProduct(rPos, rPos) * mass; |
| 1550 |
> |
r2 = rPos.lengthSquare(); |
| 1551 |
> |
Ic(0, 0) += mass * r2; |
| 1552 |
> |
Ic(1, 1) += mass * r2; |
| 1553 |
> |
Ic(2, 2) += mass * r2; |
| 1554 |
|
|
| 1555 |
< |
if (inA || inB) { |
| 1556 |
< |
|
| 1557 |
< |
RealType mass = sd->getMass(); |
| 1558 |
< |
Vector3d vel = sd->getVel(); |
| 1559 |
< |
|
| 1560 |
< |
if (inA) { |
| 1561 |
< |
hotBin.push_back(sd); |
| 1562 |
< |
//std::cerr << "before, velocity = " << vel << endl; |
| 1563 |
< |
Ph += mass * vel; |
| 1564 |
< |
//std::cerr << "after, velocity = " << vel << endl; |
| 1565 |
< |
Mh += mass; |
| 1566 |
< |
Kh += mass * vel.lengthSquare(); |
| 1567 |
< |
if (rnemdFluxType_ == rnemdFullKE) { |
| 1568 |
< |
if (sd->isDirectional()) { |
| 1569 |
< |
Vector3d angMom = sd->getJ(); |
| 1570 |
< |
Mat3x3d I = sd->getI(); |
| 1272 |
< |
if (sd->isLinear()) { |
| 1273 |
< |
int i = sd->linearAxis(); |
| 1274 |
< |
int j = (i + 1) % 3; |
| 1275 |
< |
int k = (i + 2) % 3; |
| 1276 |
< |
Kh += angMom[j] * angMom[j] / I(j, j) + |
| 1277 |
< |
angMom[k] * angMom[k] / I(k, k); |
| 1278 |
< |
} else { |
| 1279 |
< |
Kh += angMom[0] * angMom[0] / I(0, 0) + |
| 1280 |
< |
angMom[1] * angMom[1] / I(1, 1) + |
| 1281 |
< |
angMom[2] * angMom[2] / I(2, 2); |
| 1282 |
< |
} |
| 1283 |
< |
} |
| 1284 |
< |
} |
| 1285 |
< |
} else { //midBin_ |
| 1286 |
< |
coldBin.push_back(sd); |
| 1287 |
< |
Pc += mass * vel; |
| 1288 |
< |
Mc += mass; |
| 1289 |
< |
Kc += mass * vel.lengthSquare(); |
| 1290 |
< |
if (rnemdFluxType_ == rnemdFullKE) { |
| 1291 |
< |
if (sd->isDirectional()) { |
| 1292 |
< |
Vector3d angMom = sd->getJ(); |
| 1293 |
< |
Mat3x3d I = sd->getI(); |
| 1294 |
< |
if (sd->isLinear()) { |
| 1295 |
< |
int i = sd->linearAxis(); |
| 1296 |
< |
int j = (i + 1) % 3; |
| 1297 |
< |
int k = (i + 2) % 3; |
| 1298 |
< |
Kc += angMom[j] * angMom[j] / I(j, j) + |
| 1299 |
< |
angMom[k] * angMom[k] / I(k, k); |
| 1300 |
< |
} else { |
| 1301 |
< |
Kc += angMom[0] * angMom[0] / I(0, 0) + |
| 1302 |
< |
angMom[1] * angMom[1] / I(1, 1) + |
| 1303 |
< |
angMom[2] * angMom[2] / I(2, 2); |
| 1304 |
< |
} |
| 1305 |
< |
} |
| 1306 |
< |
} |
| 1307 |
< |
} |
| 1555 |
> |
if (rnemdFluxType_ == rnemdFullKE) { |
| 1556 |
> |
if (sd->isDirectional()) { |
| 1557 |
> |
Vector3d angMom = sd->getJ(); |
| 1558 |
> |
Mat3x3d I = sd->getI(); |
| 1559 |
> |
if (sd->isLinear()) { |
| 1560 |
> |
int i = sd->linearAxis(); |
| 1561 |
> |
int j = (i + 1) % 3; |
| 1562 |
> |
int k = (i + 2) % 3; |
| 1563 |
> |
Kc += angMom[j] * angMom[j] / I(j, j) + |
| 1564 |
> |
angMom[k] * angMom[k] / I(k, k); |
| 1565 |
> |
} else { |
| 1566 |
> |
Kc += angMom[0] * angMom[0] / I(0, 0) + |
| 1567 |
> |
angMom[1] * angMom[1] / I(1, 1) + |
| 1568 |
> |
angMom[2] * angMom[2] / I(2, 2); |
| 1569 |
> |
} |
| 1570 |
> |
} |
| 1571 |
|
} |
| 1572 |
|
} |
| 1573 |
|
|
| 1574 |
|
Kh *= 0.5; |
| 1575 |
|
Kc *= 0.5; |
| 1313 |
– |
|
| 1314 |
– |
// std::cerr << "Mh= " << Mh << "\tKh= " << Kh << "\tMc= " << Mc |
| 1315 |
– |
// << "\tKc= " << Kc << endl; |
| 1316 |
– |
// std::cerr << "Ph= " << Ph << "\tPc= " << Pc << endl; |
| 1576 |
|
|
| 1577 |
|
#ifdef IS_MPI |
| 1578 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Ph[0], 3, MPI::REALTYPE, MPI::SUM); |
| 1579 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Pc[0], 3, MPI::REALTYPE, MPI::SUM); |
| 1580 |
+ |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Lh[0], 3, MPI::REALTYPE, MPI::SUM); |
| 1581 |
+ |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Lc[0], 3, MPI::REALTYPE, MPI::SUM); |
| 1582 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Mh, 1, MPI::REALTYPE, MPI::SUM); |
| 1583 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Kh, 1, MPI::REALTYPE, MPI::SUM); |
| 1584 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Mc, 1, MPI::REALTYPE, MPI::SUM); |
| 1585 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Kc, 1, MPI::REALTYPE, MPI::SUM); |
| 1586 |
+ |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, Ih.getArrayPointer(), 9, |
| 1587 |
+ |
MPI::REALTYPE, MPI::SUM); |
| 1588 |
+ |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, Ic.getArrayPointer(), 9, |
| 1589 |
+ |
MPI::REALTYPE, MPI::SUM); |
| 1590 |
|
#endif |
| 1591 |
+ |
|
| 1592 |
|
|
| 1593 |
+ |
Vector3d ac, acrec, bc, bcrec; |
| 1594 |
+ |
Vector3d ah, ahrec, bh, bhrec; |
| 1595 |
+ |
RealType cNumerator, cDenominator; |
| 1596 |
+ |
RealType hNumerator, hDenominator; |
| 1597 |
+ |
|
| 1598 |
+ |
|
| 1599 |
|
bool successfulExchange = false; |
| 1600 |
|
if ((Mh > 0.0) && (Mc > 0.0)) {//both slabs are not empty |
| 1601 |
|
Vector3d vc = Pc / Mc; |
| 1602 |
< |
Vector3d ac = -momentumTarget_ / Mc + vc; |
| 1603 |
< |
Vector3d acrec = -momentumTarget_ / Mc; |
| 1604 |
< |
RealType cNumerator = Kc - kineticTarget_ - 0.5 * Mc * ac.lengthSquare(); |
| 1602 |
> |
ac = -momentumTarget_ / Mc + vc; |
| 1603 |
> |
acrec = -momentumTarget_ / Mc; |
| 1604 |
> |
|
| 1605 |
> |
// We now need the inverse of the inertia tensor to calculate the |
| 1606 |
> |
// angular velocity of the cold slab; |
| 1607 |
> |
Mat3x3d Ici = Ic.inverse(); |
| 1608 |
> |
Vector3d omegac = Ici * Lc; |
| 1609 |
> |
bc = -(Ici * angularMomentumTarget_) + omegac; |
| 1610 |
> |
bcrec = bc - omegac; |
| 1611 |
> |
|
| 1612 |
> |
cNumerator = Kc - kineticTarget_; |
| 1613 |
> |
if (doLinearPart) |
| 1614 |
> |
cNumerator -= 0.5 * Mc * ac.lengthSquare(); |
| 1615 |
> |
|
| 1616 |
> |
if (doAngularPart) |
| 1617 |
> |
cNumerator -= 0.5 * ( dot(bc, Ic * bc)); |
| 1618 |
> |
|
| 1619 |
|
if (cNumerator > 0.0) { |
| 1620 |
< |
RealType cDenominator = Kc - 0.5 * Mc * vc.lengthSquare(); |
| 1620 |
> |
|
| 1621 |
> |
cDenominator = Kc; |
| 1622 |
> |
|
| 1623 |
> |
if (doLinearPart) |
| 1624 |
> |
cDenominator -= 0.5 * Mc * vc.lengthSquare(); |
| 1625 |
> |
|
| 1626 |
> |
if (doAngularPart) |
| 1627 |
> |
cDenominator -= 0.5*(dot(omegac, Ic * omegac)); |
| 1628 |
> |
|
| 1629 |
|
if (cDenominator > 0.0) { |
| 1630 |
|
RealType c = sqrt(cNumerator / cDenominator); |
| 1631 |
|
if ((c > 0.9) && (c < 1.1)) {//restrict scaling coefficients |
| 1632 |
+ |
|
| 1633 |
|
Vector3d vh = Ph / Mh; |
| 1634 |
< |
Vector3d ah = momentumTarget_ / Mh + vh; |
| 1635 |
< |
Vector3d ahrec = momentumTarget_ / Mh; |
| 1636 |
< |
RealType hNumerator = Kh + kineticTarget_ |
| 1637 |
< |
- 0.5 * Mh * ah.lengthSquare(); |
| 1638 |
< |
if (hNumerator > 0.0) { |
| 1639 |
< |
RealType hDenominator = Kh - 0.5 * Mh * vh.lengthSquare(); |
| 1634 |
> |
ah = momentumTarget_ / Mh + vh; |
| 1635 |
> |
ahrec = momentumTarget_ / Mh; |
| 1636 |
> |
|
| 1637 |
> |
// We now need the inverse of the inertia tensor to |
| 1638 |
> |
// calculate the angular velocity of the hot slab; |
| 1639 |
> |
Mat3x3d Ihi = Ih.inverse(); |
| 1640 |
> |
Vector3d omegah = Ihi * Lh; |
| 1641 |
> |
bh = (Ihi * angularMomentumTarget_) + omegah; |
| 1642 |
> |
bhrec = bh - omegah; |
| 1643 |
> |
|
| 1644 |
> |
hNumerator = Kh + kineticTarget_; |
| 1645 |
> |
if (doLinearPart) |
| 1646 |
> |
hNumerator -= 0.5 * Mh * ah.lengthSquare(); |
| 1647 |
> |
|
| 1648 |
> |
if (doAngularPart) |
| 1649 |
> |
hNumerator -= 0.5 * ( dot(bh, Ih * bh)); |
| 1650 |
> |
|
| 1651 |
> |
if (hNumerator > 0.0) { |
| 1652 |
> |
|
| 1653 |
> |
hDenominator = Kh; |
| 1654 |
> |
if (doLinearPart) |
| 1655 |
> |
hDenominator -= 0.5 * Mh * vh.lengthSquare(); |
| 1656 |
> |
if (doAngularPart) |
| 1657 |
> |
hDenominator -= 0.5*(dot(omegah, Ih * omegah)); |
| 1658 |
> |
|
| 1659 |
|
if (hDenominator > 0.0) { |
| 1660 |
|
RealType h = sqrt(hNumerator / hDenominator); |
| 1661 |
|
if ((h > 0.9) && (h < 1.1)) { |
| 1662 |
< |
// std::cerr << "cold slab scaling coefficient: " << c << "\n"; |
| 1349 |
< |
// std::cerr << "hot slab scaling coefficient: " << h << "\n"; |
| 1662 |
> |
|
| 1663 |
|
vector<StuntDouble*>::iterator sdi; |
| 1664 |
|
Vector3d vel; |
| 1665 |
+ |
Vector3d rPos; |
| 1666 |
+ |
|
| 1667 |
|
for (sdi = coldBin.begin(); sdi != coldBin.end(); sdi++) { |
| 1668 |
|
//vel = (*sdi)->getVel(); |
| 1669 |
< |
vel = ((*sdi)->getVel() - vc) * c + ac; |
| 1669 |
> |
rPos = (*sdi)->getPos() - coordinateOrigin_; |
| 1670 |
> |
if (doLinearPart) |
| 1671 |
> |
vel = ((*sdi)->getVel() - vc) * c + ac; |
| 1672 |
> |
if (doAngularPart) |
| 1673 |
> |
vel = ((*sdi)->getVel() - cross(omegac, rPos)) * c + cross(bc, rPos); |
| 1674 |
> |
|
| 1675 |
|
(*sdi)->setVel(vel); |
| 1676 |
|
if (rnemdFluxType_ == rnemdFullKE) { |
| 1677 |
|
if ((*sdi)->isDirectional()) { |
| 1682 |
|
} |
| 1683 |
|
for (sdi = hotBin.begin(); sdi != hotBin.end(); sdi++) { |
| 1684 |
|
//vel = (*sdi)->getVel(); |
| 1685 |
< |
vel = ((*sdi)->getVel() - vh) * h + ah; |
| 1685 |
> |
rPos = (*sdi)->getPos() - coordinateOrigin_; |
| 1686 |
> |
if (doLinearPart) |
| 1687 |
> |
vel = ((*sdi)->getVel() - vh) * h + ah; |
| 1688 |
> |
if (doAngularPart) |
| 1689 |
> |
vel = ((*sdi)->getVel() - cross(omegah, rPos)) * h + cross(bh, rPos); |
| 1690 |
> |
|
| 1691 |
|
(*sdi)->setVel(vel); |
| 1692 |
|
if (rnemdFluxType_ == rnemdFullKE) { |
| 1693 |
|
if ((*sdi)->isDirectional()) { |
| 1699 |
|
successfulExchange = true; |
| 1700 |
|
kineticExchange_ += kineticTarget_; |
| 1701 |
|
momentumExchange_ += momentumTarget_; |
| 1702 |
+ |
angularMomentumExchange_ += angularMomentumTarget_; |
| 1703 |
|
} |
| 1704 |
|
} |
| 1705 |
|
} |
| 1719 |
|
} |
| 1720 |
|
} |
| 1721 |
|
|
| 1722 |
< |
void RNEMD::doRNEMD() { |
| 1722 |
> |
RealType RNEMD::getDividingArea() { |
| 1723 |
> |
|
| 1724 |
> |
if (hasDividingArea_) return dividingArea_; |
| 1725 |
> |
|
| 1726 |
> |
RealType areaA, areaB; |
| 1727 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 1728 |
> |
|
| 1729 |
> |
if (hasSelectionA_) { |
| 1730 |
> |
int isd; |
| 1731 |
> |
StuntDouble* sd; |
| 1732 |
> |
vector<StuntDouble*> aSites; |
| 1733 |
> |
seleManA_.setSelectionSet(evaluatorA_.evaluate()); |
| 1734 |
> |
for (sd = seleManA_.beginSelected(isd); sd != NULL; |
| 1735 |
> |
sd = seleManA_.nextSelected(isd)) { |
| 1736 |
> |
aSites.push_back(sd); |
| 1737 |
> |
} |
| 1738 |
> |
ConvexHull* surfaceMeshA = new ConvexHull(); |
| 1739 |
> |
surfaceMeshA->computeHull(aSites); |
| 1740 |
> |
areaA = surfaceMeshA->getArea(); |
| 1741 |
> |
delete surfaceMeshA; |
| 1742 |
> |
|
| 1743 |
> |
} else { |
| 1744 |
> |
if (usePeriodicBoundaryConditions_) { |
| 1745 |
> |
// in periodic boundaries, the surface area is twice the x-y |
| 1746 |
> |
// area of the current box: |
| 1747 |
> |
areaA = 2.0 * snap->getXYarea(); |
| 1748 |
> |
} else { |
| 1749 |
> |
// in non-periodic simulations, without explicitly setting |
| 1750 |
> |
// selections, the sphere radius sets the surface area of the |
| 1751 |
> |
// dividing surface: |
| 1752 |
> |
areaA = 4.0 * M_PI * pow(sphereARadius_, 2); |
| 1753 |
> |
} |
| 1754 |
> |
} |
| 1755 |
> |
|
| 1756 |
> |
|
| 1757 |
|
|
| 1758 |
+ |
if (hasSelectionB_) { |
| 1759 |
+ |
int isd; |
| 1760 |
+ |
StuntDouble* sd; |
| 1761 |
+ |
vector<StuntDouble*> bSites; |
| 1762 |
+ |
seleManB_.setSelectionSet(evaluatorB_.evaluate()); |
| 1763 |
+ |
for (sd = seleManB_.beginSelected(isd); sd != NULL; |
| 1764 |
+ |
sd = seleManB_.nextSelected(isd)) { |
| 1765 |
+ |
bSites.push_back(sd); |
| 1766 |
+ |
} |
| 1767 |
+ |
ConvexHull* surfaceMeshB = new ConvexHull(); |
| 1768 |
+ |
surfaceMeshB->computeHull(bSites); |
| 1769 |
+ |
areaB = surfaceMeshB->getArea(); |
| 1770 |
+ |
delete surfaceMeshB; |
| 1771 |
+ |
|
| 1772 |
+ |
} else { |
| 1773 |
+ |
if (usePeriodicBoundaryConditions_) { |
| 1774 |
+ |
// in periodic boundaries, the surface area is twice the x-y |
| 1775 |
+ |
// area of the current box: |
| 1776 |
+ |
areaB = 2.0 * snap->getXYarea(); |
| 1777 |
+ |
} else { |
| 1778 |
+ |
// in non-periodic simulations, without explicitly setting |
| 1779 |
+ |
// selections, but if a sphereBradius has been set, just use that: |
| 1780 |
+ |
areaB = 4.0 * M_PI * pow(sphereBRadius_, 2); |
| 1781 |
+ |
} |
| 1782 |
+ |
} |
| 1783 |
+ |
|
| 1784 |
+ |
dividingArea_ = min(areaA, areaB); |
| 1785 |
+ |
hasDividingArea_ = true; |
| 1786 |
+ |
return dividingArea_; |
| 1787 |
+ |
} |
| 1788 |
+ |
|
| 1789 |
+ |
void RNEMD::doRNEMD() { |
| 1790 |
+ |
if (!doRNEMD_) return; |
| 1791 |
|
trialCount_++; |
| 1792 |
+ |
|
| 1793 |
+ |
// object evaluator: |
| 1794 |
+ |
evaluator_.loadScriptString(rnemdObjectSelection_); |
| 1795 |
+ |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 1796 |
+ |
|
| 1797 |
+ |
evaluatorA_.loadScriptString(selectionA_); |
| 1798 |
+ |
evaluatorB_.loadScriptString(selectionB_); |
| 1799 |
+ |
|
| 1800 |
+ |
seleManA_.setSelectionSet(evaluatorA_.evaluate()); |
| 1801 |
+ |
seleManB_.setSelectionSet(evaluatorB_.evaluate()); |
| 1802 |
+ |
|
| 1803 |
+ |
commonA_ = seleManA_ & seleMan_; |
| 1804 |
+ |
commonB_ = seleManB_ & seleMan_; |
| 1805 |
+ |
|
| 1806 |
+ |
// Target exchange quantities (in each exchange) = dividingArea * dt * flux |
| 1807 |
+ |
// dt = exchange time interval |
| 1808 |
+ |
// flux = target flux |
| 1809 |
+ |
// dividingArea = smallest dividing surface between the two regions |
| 1810 |
+ |
|
| 1811 |
+ |
hasDividingArea_ = false; |
| 1812 |
+ |
RealType area = getDividingArea(); |
| 1813 |
+ |
|
| 1814 |
+ |
kineticTarget_ = kineticFlux_ * exchangeTime_ * area; |
| 1815 |
+ |
momentumTarget_ = momentumFluxVector_ * exchangeTime_ * area; |
| 1816 |
+ |
angularMomentumTarget_ = angularMomentumFluxVector_ * exchangeTime_ * area; |
| 1817 |
+ |
|
| 1818 |
|
switch(rnemdMethod_) { |
| 1819 |
|
case rnemdSwap: |
| 1820 |
< |
doSwap(); |
| 1820 |
> |
doSwap(commonA_, commonB_); |
| 1821 |
|
break; |
| 1822 |
|
case rnemdNIVS: |
| 1823 |
< |
doNIVS(); |
| 1823 |
> |
doNIVS(commonA_, commonB_); |
| 1824 |
|
break; |
| 1825 |
|
case rnemdVSS: |
| 1826 |
< |
doVSS(); |
| 1826 |
> |
doVSS(commonA_, commonB_); |
| 1827 |
|
break; |
| 1828 |
|
case rnemdUnkownMethod: |
| 1829 |
|
default : |
| 1832 |
|
} |
| 1833 |
|
|
| 1834 |
|
void RNEMD::collectData() { |
| 1835 |
< |
|
| 1835 |
> |
if (!doRNEMD_) return; |
| 1836 |
|
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 1837 |
+ |
|
| 1838 |
+ |
// collectData can be called more frequently than the doRNEMD, so use the |
| 1839 |
+ |
// computed area from the last exchange time: |
| 1840 |
+ |
RealType area = getDividingArea(); |
| 1841 |
+ |
areaAccumulator_->add(area); |
| 1842 |
|
Mat3x3d hmat = currentSnap_->getHmat(); |
| 1419 |
– |
|
| 1420 |
– |
areaAccumulator_->add(currentSnap_->getXYarea()); |
| 1421 |
– |
|
| 1843 |
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 1844 |
|
|
| 1845 |
< |
int selei; |
| 1845 |
> |
int selei(0); |
| 1846 |
|
StuntDouble* sd; |
| 1847 |
< |
int idx; |
| 1847 |
> |
int binNo; |
| 1848 |
|
|
| 1849 |
|
vector<RealType> binMass(nBins_, 0.0); |
| 1850 |
|
vector<RealType> binPx(nBins_, 0.0); |
| 1851 |
|
vector<RealType> binPy(nBins_, 0.0); |
| 1852 |
|
vector<RealType> binPz(nBins_, 0.0); |
| 1853 |
+ |
vector<RealType> binOmegax(nBins_, 0.0); |
| 1854 |
+ |
vector<RealType> binOmegay(nBins_, 0.0); |
| 1855 |
+ |
vector<RealType> binOmegaz(nBins_, 0.0); |
| 1856 |
|
vector<RealType> binKE(nBins_, 0.0); |
| 1857 |
|
vector<int> binDOF(nBins_, 0); |
| 1858 |
|
vector<int> binCount(nBins_, 0); |
| 1860 |
|
// alternative approach, track all molecules instead of only those |
| 1861 |
|
// selected for scaling/swapping: |
| 1862 |
|
/* |
| 1863 |
< |
SimInfo::MoleculeIterator miter; |
| 1864 |
< |
vector<StuntDouble*>::iterator iiter; |
| 1865 |
< |
Molecule* mol; |
| 1866 |
< |
StuntDouble* sd; |
| 1867 |
< |
for (mol = info_->beginMolecule(miter); mol != NULL; |
| 1863 |
> |
SimInfo::MoleculeIterator miter; |
| 1864 |
> |
vector<StuntDouble*>::iterator iiter; |
| 1865 |
> |
Molecule* mol; |
| 1866 |
> |
StuntDouble* sd; |
| 1867 |
> |
for (mol = info_->beginMolecule(miter); mol != NULL; |
| 1868 |
|
mol = info_->nextMolecule(miter)) |
| 1869 |
|
sd is essentially sd |
| 1870 |
< |
for (sd = mol->beginIntegrableObject(iiter); |
| 1871 |
< |
sd != NULL; |
| 1872 |
< |
sd = mol->nextIntegrableObject(iiter)) |
| 1870 |
> |
for (sd = mol->beginIntegrableObject(iiter); |
| 1871 |
> |
sd != NULL; |
| 1872 |
> |
sd = mol->nextIntegrableObject(iiter)) |
| 1873 |
|
*/ |
| 1874 |
+ |
|
| 1875 |
|
for (sd = seleMan_.beginSelected(selei); sd != NULL; |
| 1876 |
< |
sd = seleMan_.nextSelected(selei)) { |
| 1877 |
< |
|
| 1453 |
< |
idx = sd->getLocalIndex(); |
| 1454 |
< |
|
| 1876 |
> |
sd = seleMan_.nextSelected(selei)) { |
| 1877 |
> |
|
| 1878 |
|
Vector3d pos = sd->getPos(); |
| 1879 |
|
|
| 1880 |
|
// wrap the stuntdouble's position back into the box: |
| 1881 |
|
|
| 1882 |
< |
if (usePeriodicBoundaryConditions_) |
| 1882 |
> |
if (usePeriodicBoundaryConditions_) { |
| 1883 |
|
currentSnap_->wrapVector(pos); |
| 1884 |
+ |
// which bin is this stuntdouble in? |
| 1885 |
+ |
// wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)] |
| 1886 |
+ |
// Shift molecules by half a box to have bins start at 0 |
| 1887 |
+ |
// The modulo operator is used to wrap the case when we are |
| 1888 |
+ |
// beyond the end of the bins back to the beginning. |
| 1889 |
+ |
binNo = int(nBins_ * (pos.z() / hmat(2,2) + 0.5)) % nBins_; |
| 1890 |
+ |
} else { |
| 1891 |
+ |
Vector3d rPos = pos - coordinateOrigin_; |
| 1892 |
+ |
binNo = int(rPos.length() / binWidth_); |
| 1893 |
+ |
} |
| 1894 |
|
|
| 1462 |
– |
|
| 1463 |
– |
// which bin is this stuntdouble in? |
| 1464 |
– |
// wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)] |
| 1465 |
– |
// Shift molecules by half a box to have bins start at 0 |
| 1466 |
– |
// The modulo operator is used to wrap the case when we are |
| 1467 |
– |
// beyond the end of the bins back to the beginning. |
| 1468 |
– |
int binNo = int(nBins_ * (pos.z() / hmat(2,2) + 0.5)) % nBins_; |
| 1469 |
– |
|
| 1895 |
|
RealType mass = sd->getMass(); |
| 1896 |
|
Vector3d vel = sd->getVel(); |
| 1897 |
< |
|
| 1898 |
< |
binCount[binNo]++; |
| 1899 |
< |
binMass[binNo] += mass; |
| 1900 |
< |
binPx[binNo] += mass*vel.x(); |
| 1901 |
< |
binPy[binNo] += mass*vel.y(); |
| 1902 |
< |
binPz[binNo] += mass*vel.z(); |
| 1903 |
< |
binKE[binNo] += 0.5 * (mass * vel.lengthSquare()); |
| 1904 |
< |
binDOF[binNo] += 3; |
| 1905 |
< |
|
| 1906 |
< |
if (sd->isDirectional()) { |
| 1907 |
< |
Vector3d angMom = sd->getJ(); |
| 1908 |
< |
Mat3x3d I = sd->getI(); |
| 1909 |
< |
if (sd->isLinear()) { |
| 1910 |
< |
int i = sd->linearAxis(); |
| 1911 |
< |
int j = (i + 1) % 3; |
| 1912 |
< |
int k = (i + 2) % 3; |
| 1913 |
< |
binKE[binNo] += 0.5 * (angMom[j] * angMom[j] / I(j, j) + |
| 1914 |
< |
angMom[k] * angMom[k] / I(k, k)); |
| 1915 |
< |
binDOF[binNo] += 2; |
| 1916 |
< |
} else { |
| 1917 |
< |
binKE[binNo] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + |
| 1918 |
< |
angMom[1] * angMom[1] / I(1, 1) + |
| 1919 |
< |
angMom[2] * angMom[2] / I(2, 2)); |
| 1920 |
< |
binDOF[binNo] += 3; |
| 1897 |
> |
Vector3d rPos = sd->getPos() - coordinateOrigin_; |
| 1898 |
> |
Vector3d aVel = cross(rPos, vel); |
| 1899 |
> |
|
| 1900 |
> |
if (binNo >= 0 && binNo < nBins_) { |
| 1901 |
> |
binCount[binNo]++; |
| 1902 |
> |
binMass[binNo] += mass; |
| 1903 |
> |
binPx[binNo] += mass*vel.x(); |
| 1904 |
> |
binPy[binNo] += mass*vel.y(); |
| 1905 |
> |
binPz[binNo] += mass*vel.z(); |
| 1906 |
> |
binOmegax[binNo] += aVel.x(); |
| 1907 |
> |
binOmegay[binNo] += aVel.y(); |
| 1908 |
> |
binOmegaz[binNo] += aVel.z(); |
| 1909 |
> |
binKE[binNo] += 0.5 * (mass * vel.lengthSquare()); |
| 1910 |
> |
binDOF[binNo] += 3; |
| 1911 |
> |
|
| 1912 |
> |
if (sd->isDirectional()) { |
| 1913 |
> |
Vector3d angMom = sd->getJ(); |
| 1914 |
> |
Mat3x3d I = sd->getI(); |
| 1915 |
> |
if (sd->isLinear()) { |
| 1916 |
> |
int i = sd->linearAxis(); |
| 1917 |
> |
int j = (i + 1) % 3; |
| 1918 |
> |
int k = (i + 2) % 3; |
| 1919 |
> |
binKE[binNo] += 0.5 * (angMom[j] * angMom[j] / I(j, j) + |
| 1920 |
> |
angMom[k] * angMom[k] / I(k, k)); |
| 1921 |
> |
binDOF[binNo] += 2; |
| 1922 |
> |
} else { |
| 1923 |
> |
binKE[binNo] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + |
| 1924 |
> |
angMom[1] * angMom[1] / I(1, 1) + |
| 1925 |
> |
angMom[2] * angMom[2] / I(2, 2)); |
| 1926 |
> |
binDOF[binNo] += 3; |
| 1927 |
> |
} |
| 1928 |
|
} |
| 1929 |
|
} |
| 1930 |
|
} |
| 1931 |
|
|
| 1500 |
– |
|
| 1932 |
|
#ifdef IS_MPI |
| 1933 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binCount[0], |
| 1934 |
|
nBins_, MPI::INT, MPI::SUM); |
| 1939 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binPy[0], |
| 1940 |
|
nBins_, MPI::REALTYPE, MPI::SUM); |
| 1941 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binPz[0], |
| 1942 |
+ |
nBins_, MPI::REALTYPE, MPI::SUM); |
| 1943 |
+ |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegax[0], |
| 1944 |
+ |
nBins_, MPI::REALTYPE, MPI::SUM); |
| 1945 |
+ |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegay[0], |
| 1946 |
|
nBins_, MPI::REALTYPE, MPI::SUM); |
| 1947 |
+ |
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegaz[0], |
| 1948 |
+ |
nBins_, MPI::REALTYPE, MPI::SUM); |
| 1949 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binKE[0], |
| 1950 |
|
nBins_, MPI::REALTYPE, MPI::SUM); |
| 1951 |
|
MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binDOF[0], |
| 1953 |
|
#endif |
| 1954 |
|
|
| 1955 |
|
Vector3d vel; |
| 1956 |
+ |
Vector3d aVel; |
| 1957 |
|
RealType den; |
| 1958 |
|
RealType temp; |
| 1959 |
|
RealType z; |
| 1960 |
+ |
RealType r; |
| 1961 |
|
for (int i = 0; i < nBins_; i++) { |
| 1962 |
< |
z = (((RealType)i + 0.5) / (RealType)nBins_) * hmat(2,2); |
| 1962 |
> |
if (usePeriodicBoundaryConditions_) { |
| 1963 |
> |
z = (((RealType)i + 0.5) / (RealType)nBins_) * hmat(2,2); |
| 1964 |
> |
den = binMass[i] * nBins_ * PhysicalConstants::densityConvert |
| 1965 |
> |
/ currentSnap_->getVolume() ; |
| 1966 |
> |
} else { |
| 1967 |
> |
r = (((RealType)i + 0.5) * binWidth_); |
| 1968 |
> |
RealType rinner = (RealType)i * binWidth_; |
| 1969 |
> |
RealType router = (RealType)(i+1) * binWidth_; |
| 1970 |
> |
den = binMass[i] * 3.0 * PhysicalConstants::densityConvert |
| 1971 |
> |
/ (4.0 * M_PI * (pow(router,3) - pow(rinner,3))); |
| 1972 |
> |
} |
| 1973 |
|
vel.x() = binPx[i] / binMass[i]; |
| 1974 |
|
vel.y() = binPy[i] / binMass[i]; |
| 1975 |
|
vel.z() = binPz[i] / binMass[i]; |
| 1976 |
< |
den = binCount[i] * nBins_ / currentSnap_->getVolume(); |
| 1977 |
< |
temp = 2.0 * binKE[i] / (binDOF[i] * PhysicalConstants::kb * |
| 1978 |
< |
PhysicalConstants::energyConvert); |
| 1976 |
> |
aVel.x() = binOmegax[i] / binCount[i]; |
| 1977 |
> |
aVel.y() = binOmegay[i] / binCount[i]; |
| 1978 |
> |
aVel.z() = binOmegaz[i] / binCount[i]; |
| 1979 |
|
|
| 1980 |
< |
for (unsigned int j = 0; j < outputMask_.size(); ++j) { |
| 1981 |
< |
if(outputMask_[j]) { |
| 1982 |
< |
switch(j) { |
| 1983 |
< |
case Z: |
| 1984 |
< |
(data_[j].accumulator[i])->add(z); |
| 1985 |
< |
break; |
| 1986 |
< |
case TEMPERATURE: |
| 1987 |
< |
data_[j].accumulator[i]->add(temp); |
| 1988 |
< |
break; |
| 1989 |
< |
case VELOCITY: |
| 1990 |
< |
dynamic_cast<VectorAccumulator *>(data_[j].accumulator[i])->add(vel); |
| 1991 |
< |
break; |
| 1992 |
< |
case DENSITY: |
| 1993 |
< |
data_[j].accumulator[i]->add(den); |
| 1994 |
< |
break; |
| 1980 |
> |
if (binCount[i] > 0) { |
| 1981 |
> |
// only add values if there are things to add |
| 1982 |
> |
temp = 2.0 * binKE[i] / (binDOF[i] * PhysicalConstants::kb * |
| 1983 |
> |
PhysicalConstants::energyConvert); |
| 1984 |
> |
|
| 1985 |
> |
for (unsigned int j = 0; j < outputMask_.size(); ++j) { |
| 1986 |
> |
if(outputMask_[j]) { |
| 1987 |
> |
switch(j) { |
| 1988 |
> |
case Z: |
| 1989 |
> |
dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(z); |
| 1990 |
> |
break; |
| 1991 |
> |
case R: |
| 1992 |
> |
dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(r); |
| 1993 |
> |
break; |
| 1994 |
> |
case TEMPERATURE: |
| 1995 |
> |
dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(temp); |
| 1996 |
> |
break; |
| 1997 |
> |
case VELOCITY: |
| 1998 |
> |
dynamic_cast<VectorAccumulator *>(data_[j].accumulator[i])->add(vel); |
| 1999 |
> |
break; |
| 2000 |
> |
case ANGULARVELOCITY: |
| 2001 |
> |
dynamic_cast<VectorAccumulator *>(data_[j].accumulator[i])->add(aVel); |
| 2002 |
> |
break; |
| 2003 |
> |
case DENSITY: |
| 2004 |
> |
dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(den); |
| 2005 |
> |
break; |
| 2006 |
> |
} |
| 2007 |
|
} |
| 2008 |
|
} |
| 2009 |
|
} |
| 2011 |
|
} |
| 2012 |
|
|
| 2013 |
|
void RNEMD::getStarted() { |
| 2014 |
+ |
if (!doRNEMD_) return; |
| 2015 |
+ |
hasDividingArea_ = false; |
| 2016 |
|
collectData(); |
| 2017 |
|
writeOutputFile(); |
| 2018 |
|
} |
| 2019 |
|
|
| 2020 |
|
void RNEMD::parseOutputFileFormat(const std::string& format) { |
| 2021 |
+ |
if (!doRNEMD_) return; |
| 2022 |
|
StringTokenizer tokenizer(format, " ,;|\t\n\r"); |
| 2023 |
|
|
| 2024 |
|
while(tokenizer.hasMoreTokens()) { |
| 2039 |
|
} |
| 2040 |
|
|
| 2041 |
|
void RNEMD::writeOutputFile() { |
| 2042 |
+ |
if (!doRNEMD_) return; |
| 2043 |
|
|
| 2044 |
|
#ifdef IS_MPI |
| 2045 |
|
// If we're the root node, should we print out the results |
| 2061 |
|
RealType time = currentSnap_->getTime(); |
| 2062 |
|
RealType avgArea; |
| 2063 |
|
areaAccumulator_->getAverage(avgArea); |
| 2064 |
< |
RealType Jz = kineticExchange_ / (2.0 * time * avgArea); |
| 2065 |
< |
Vector3d JzP = momentumExchange_ / (2.0 * time * avgArea); |
| 2064 |
> |
RealType Jz = kineticExchange_ / (time * avgArea) |
| 2065 |
> |
/ PhysicalConstants::energyConvert; |
| 2066 |
> |
Vector3d JzP = momentumExchange_ / (time * avgArea); |
| 2067 |
> |
Vector3d JzL = angularMomentumExchange_ / (time * avgArea); |
| 2068 |
|
|
| 2069 |
|
rnemdFile_ << "#######################################################\n"; |
| 2070 |
|
rnemdFile_ << "# RNEMD {\n"; |
| 2084 |
|
|
| 2085 |
|
rnemdFile_ << "# objectSelection = \"" |
| 2086 |
|
<< rnemdObjectSelection_ << "\";\n"; |
| 2087 |
< |
rnemdFile_ << "# slabWidth = " << slabWidth_ << ";\n"; |
| 2088 |
< |
rnemdFile_ << "# slabAcenter = " << slabACenter_ << ";\n"; |
| 1622 |
< |
rnemdFile_ << "# slabBcenter = " << slabBCenter_ << ";\n"; |
| 2087 |
> |
rnemdFile_ << "# selectionA = \"" << selectionA_ << "\";\n"; |
| 2088 |
> |
rnemdFile_ << "# selectionB = \"" << selectionB_ << "\";\n"; |
| 2089 |
|
rnemdFile_ << "# }\n"; |
| 2090 |
|
rnemdFile_ << "#######################################################\n"; |
| 2091 |
|
rnemdFile_ << "# RNEMD report:\n"; |
| 2092 |
< |
rnemdFile_ << "# running time = " << time << " fs\n"; |
| 2093 |
< |
rnemdFile_ << "# target flux:\n"; |
| 2094 |
< |
rnemdFile_ << "# kinetic = " << kineticFlux_ << "\n"; |
| 2095 |
< |
rnemdFile_ << "# momentum = " << momentumFluxVector_ << "\n"; |
| 2096 |
< |
rnemdFile_ << "# target one-time exchanges:\n"; |
| 2097 |
< |
rnemdFile_ << "# kinetic = " << kineticTarget_ << "\n"; |
| 2098 |
< |
rnemdFile_ << "# momentum = " << momentumTarget_ << "\n"; |
| 2099 |
< |
rnemdFile_ << "# actual exchange totals:\n"; |
| 2100 |
< |
rnemdFile_ << "# kinetic = " << kineticExchange_ << "\n"; |
| 2101 |
< |
rnemdFile_ << "# momentum = " << momentumExchange_ << "\n"; |
| 2102 |
< |
rnemdFile_ << "# actual flux:\n"; |
| 2103 |
< |
rnemdFile_ << "# kinetic = " << Jz << "\n"; |
| 2104 |
< |
rnemdFile_ << "# momentum = " << JzP << "\n"; |
| 2105 |
< |
rnemdFile_ << "# exchange statistics:\n"; |
| 2106 |
< |
rnemdFile_ << "# attempted = " << trialCount_ << "\n"; |
| 2107 |
< |
rnemdFile_ << "# failed = " << failTrialCount_ << "\n"; |
| 2092 |
> |
rnemdFile_ << "# running time = " << time << " fs\n"; |
| 2093 |
> |
rnemdFile_ << "# Target flux:\n"; |
| 2094 |
> |
rnemdFile_ << "# kinetic = " |
| 2095 |
> |
<< kineticFlux_ / PhysicalConstants::energyConvert |
| 2096 |
> |
<< " (kcal/mol/A^2/fs)\n"; |
| 2097 |
> |
rnemdFile_ << "# momentum = " << momentumFluxVector_ |
| 2098 |
> |
<< " (amu/A/fs^2)\n"; |
| 2099 |
> |
rnemdFile_ << "# angular momentum = " << angularMomentumFluxVector_ |
| 2100 |
> |
<< " (amu/A^2/fs^2)\n"; |
| 2101 |
> |
rnemdFile_ << "# Target one-time exchanges:\n"; |
| 2102 |
> |
rnemdFile_ << "# kinetic = " |
| 2103 |
> |
<< kineticTarget_ / PhysicalConstants::energyConvert |
| 2104 |
> |
<< " (kcal/mol)\n"; |
| 2105 |
> |
rnemdFile_ << "# momentum = " << momentumTarget_ |
| 2106 |
> |
<< " (amu*A/fs)\n"; |
| 2107 |
> |
rnemdFile_ << "# angular momentum = " << angularMomentumTarget_ |
| 2108 |
> |
<< " (amu*A^2/fs)\n"; |
| 2109 |
> |
rnemdFile_ << "# Actual exchange totals:\n"; |
| 2110 |
> |
rnemdFile_ << "# kinetic = " |
| 2111 |
> |
<< kineticExchange_ / PhysicalConstants::energyConvert |
| 2112 |
> |
<< " (kcal/mol)\n"; |
| 2113 |
> |
rnemdFile_ << "# momentum = " << momentumExchange_ |
| 2114 |
> |
<< " (amu*A/fs)\n"; |
| 2115 |
> |
rnemdFile_ << "# angular momentum = " << angularMomentumExchange_ |
| 2116 |
> |
<< " (amu*A^2/fs)\n"; |
| 2117 |
> |
rnemdFile_ << "# Actual flux:\n"; |
| 2118 |
> |
rnemdFile_ << "# kinetic = " << Jz |
| 2119 |
> |
<< " (kcal/mol/A^2/fs)\n"; |
| 2120 |
> |
rnemdFile_ << "# momentum = " << JzP |
| 2121 |
> |
<< " (amu/A/fs^2)\n"; |
| 2122 |
> |
rnemdFile_ << "# angular momentum = " << JzL |
| 2123 |
> |
<< " (amu/A^2/fs^2)\n"; |
| 2124 |
> |
rnemdFile_ << "# Exchange statistics:\n"; |
| 2125 |
> |
rnemdFile_ << "# attempted = " << trialCount_ << "\n"; |
| 2126 |
> |
rnemdFile_ << "# failed = " << failTrialCount_ << "\n"; |
| 2127 |
|
if (rnemdMethod_ == rnemdNIVS) { |
| 2128 |
< |
rnemdFile_ << "# NIVS root-check errors = " |
| 2128 |
> |
rnemdFile_ << "# NIVS root-check errors = " |
| 2129 |
|
<< failRootCount_ << "\n"; |
| 2130 |
|
} |
| 2131 |
|
rnemdFile_ << "#######################################################\n"; |
| 2138 |
|
if (outputMask_[i]) { |
| 2139 |
|
rnemdFile_ << "\t" << data_[i].title << |
| 2140 |
|
"(" << data_[i].units << ")"; |
| 2141 |
+ |
// add some extra tabs for column alignment |
| 2142 |
+ |
if (data_[i].dataType == "Vector3d") rnemdFile_ << "\t\t"; |
| 2143 |
|
} |
| 2144 |
|
} |
| 2145 |
|
rnemdFile_ << std::endl; |
| 2146 |
|
|
| 2147 |
|
rnemdFile_.precision(8); |
| 2148 |
|
|
| 2149 |
< |
for (unsigned int j = 0; j < nBins_; j++) { |
| 2149 |
> |
for (int j = 0; j < nBins_; j++) { |
| 2150 |
|
|
| 2151 |
|
for (unsigned int i = 0; i < outputMask_.size(); ++i) { |
| 2152 |
|
if (outputMask_[i]) { |
| 2153 |
|
if (data_[i].dataType == "RealType") |
| 2154 |
|
writeReal(i,j); |
| 2155 |
< |
else if (data_[i].dataType == "Vector3d") |
| 2155 |
> |
else if (data_[i].dataType == "Vector3d") |
| 2156 |
|
writeVector(i,j); |
| 2157 |
|
else { |
| 2158 |
|
sprintf( painCave.errMsg, |
| 2172 |
|
rnemdFile_ << "#######################################################\n"; |
| 2173 |
|
|
| 2174 |
|
|
| 2175 |
< |
for (unsigned int j = 0; j < nBins_; j++) { |
| 2175 |
> |
for (int j = 0; j < nBins_; j++) { |
| 2176 |
|
rnemdFile_ << "#"; |
| 2177 |
|
for (unsigned int i = 0; i < outputMask_.size(); ++i) { |
| 2178 |
|
if (outputMask_[i]) { |
| 2203 |
|
} |
| 2204 |
|
|
| 2205 |
|
void RNEMD::writeReal(int index, unsigned int bin) { |
| 2206 |
+ |
if (!doRNEMD_) return; |
| 2207 |
|
assert(index >=0 && index < ENDINDEX); |
| 2208 |
< |
assert(bin < nBins_); |
| 2208 |
> |
assert(int(bin) < nBins_); |
| 2209 |
|
RealType s; |
| 2210 |
+ |
int count; |
| 2211 |
|
|
| 2212 |
< |
data_[index].accumulator[bin]->getAverage(s); |
| 2212 |
> |
count = data_[index].accumulator[bin]->count(); |
| 2213 |
> |
if (count == 0) return; |
| 2214 |
|
|
| 2215 |
+ |
dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->getAverage(s); |
| 2216 |
+ |
|
| 2217 |
|
if (! isinf(s) && ! isnan(s)) { |
| 2218 |
|
rnemdFile_ << "\t" << s; |
| 2219 |
|
} else{ |
| 2226 |
|
} |
| 2227 |
|
|
| 2228 |
|
void RNEMD::writeVector(int index, unsigned int bin) { |
| 2229 |
+ |
if (!doRNEMD_) return; |
| 2230 |
|
assert(index >=0 && index < ENDINDEX); |
| 2231 |
< |
assert(bin < nBins_); |
| 2231 |
> |
assert(int(bin) < nBins_); |
| 2232 |
|
Vector3d s; |
| 2233 |
+ |
int count; |
| 2234 |
+ |
|
| 2235 |
+ |
count = data_[index].accumulator[bin]->count(); |
| 2236 |
+ |
|
| 2237 |
+ |
if (count == 0) return; |
| 2238 |
+ |
|
| 2239 |
|
dynamic_cast<VectorAccumulator*>(data_[index].accumulator[bin])->getAverage(s); |
| 2240 |
|
if (isinf(s[0]) || isnan(s[0]) || |
| 2241 |
|
isinf(s[1]) || isnan(s[1]) || |
| 2251 |
|
} |
| 2252 |
|
|
| 2253 |
|
void RNEMD::writeRealStdDev(int index, unsigned int bin) { |
| 2254 |
+ |
if (!doRNEMD_) return; |
| 2255 |
|
assert(index >=0 && index < ENDINDEX); |
| 2256 |
< |
assert(bin < nBins_); |
| 2256 |
> |
assert(int(bin) < nBins_); |
| 2257 |
|
RealType s; |
| 2258 |
+ |
int count; |
| 2259 |
|
|
| 2260 |
< |
data_[index].accumulator[bin]->getStdDev(s); |
| 2260 |
> |
count = data_[index].accumulator[bin]->count(); |
| 2261 |
> |
if (count == 0) return; |
| 2262 |
|
|
| 2263 |
+ |
dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->getStdDev(s); |
| 2264 |
+ |
|
| 2265 |
|
if (! isinf(s) && ! isnan(s)) { |
| 2266 |
|
rnemdFile_ << "\t" << s; |
| 2267 |
|
} else{ |
| 2274 |
|
} |
| 2275 |
|
|
| 2276 |
|
void RNEMD::writeVectorStdDev(int index, unsigned int bin) { |
| 2277 |
+ |
if (!doRNEMD_) return; |
| 2278 |
|
assert(index >=0 && index < ENDINDEX); |
| 2279 |
< |
assert(bin < nBins_); |
| 2279 |
> |
assert(int(bin) < nBins_); |
| 2280 |
|
Vector3d s; |
| 2281 |
+ |
int count; |
| 2282 |
+ |
|
| 2283 |
+ |
count = data_[index].accumulator[bin]->count(); |
| 2284 |
+ |
if (count == 0) return; |
| 2285 |
+ |
|
| 2286 |
|
dynamic_cast<VectorAccumulator*>(data_[index].accumulator[bin])->getStdDev(s); |
| 2287 |
|
if (isinf(s[0]) || isnan(s[0]) || |
| 2288 |
|
isinf(s[1]) || isnan(s[1]) || |