| 1 |
/* |
| 2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
* |
| 4 |
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
* non-exclusive, royalty free, license to use, modify and |
| 6 |
* redistribute this software in source and binary code form, provided |
| 7 |
* that the following conditions are met: |
| 8 |
* |
| 9 |
* 1. Acknowledgement of the program authors must be made in any |
| 10 |
* publication of scientific results based in part on use of the |
| 11 |
* program. An acceptable form of acknowledgement is citation of |
| 12 |
* the article in which the program was described (Matthew |
| 13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
| 14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
| 15 |
* Parallel Simulation Engine for Molecular Dynamics," |
| 16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
| 17 |
* |
| 18 |
* 2. Redistributions of source code must retain the above copyright |
| 19 |
* notice, this list of conditions and the following disclaimer. |
| 20 |
* |
| 21 |
* 3. Redistributions in binary form must reproduce the above copyright |
| 22 |
* notice, this list of conditions and the following disclaimer in the |
| 23 |
* documentation and/or other materials provided with the |
| 24 |
* distribution. |
| 25 |
* |
| 26 |
* This software is provided "AS IS," without a warranty of any |
| 27 |
* kind. All express or implied conditions, representations and |
| 28 |
* warranties, including any implied warranty of merchantability, |
| 29 |
* fitness for a particular purpose or non-infringement, are hereby |
| 30 |
* excluded. The University of Notre Dame and its licensors shall not |
| 31 |
* be liable for any damages suffered by licensee as a result of |
| 32 |
* using, modifying or distributing the software or its |
| 33 |
* derivatives. In no event will the University of Notre Dame or its |
| 34 |
* licensors be liable for any lost revenue, profit or data, or for |
| 35 |
* direct, indirect, special, consequential, incidental or punitive |
| 36 |
* damages, however caused and regardless of the theory of liability, |
| 37 |
* arising out of the use of or inability to use software, even if the |
| 38 |
* University of Notre Dame has been advised of the possibility of |
| 39 |
* such damages. |
| 40 |
*/ |
| 41 |
|
| 42 |
#include "integrators/RNEMD.hpp" |
| 43 |
#include "math/Vector3.hpp" |
| 44 |
#include "math/SquareMatrix3.hpp" |
| 45 |
#include "primitives/Molecule.hpp" |
| 46 |
#include "primitives/StuntDouble.hpp" |
| 47 |
#include "utils/OOPSEConstant.hpp" |
| 48 |
#include "utils/Tuple.hpp" |
| 49 |
|
| 50 |
#ifndef IS_MPI |
| 51 |
#include "math/SeqRandNumGen.hpp" |
| 52 |
#else |
| 53 |
#include "math/ParallelRandNumGen.hpp" |
| 54 |
#endif |
| 55 |
|
| 56 |
/* Remove me after testing*/ |
| 57 |
/* |
| 58 |
#include <cstdio> |
| 59 |
#include <iostream> |
| 60 |
*/ |
| 61 |
/*End remove me*/ |
| 62 |
|
| 63 |
namespace oopse { |
| 64 |
|
| 65 |
RNEMD::RNEMD(SimInfo* info) : info_(info), evaluator_(info), seleMan_(info) { |
| 66 |
|
| 67 |
int seedValue; |
| 68 |
Globals * simParams = info->getSimParams(); |
| 69 |
|
| 70 |
stringToEnumMap_["Kinetic"] = rnemdKinetic; |
| 71 |
stringToEnumMap_["Px"] = rnemdPx; |
| 72 |
stringToEnumMap_["Py"] = rnemdPy; |
| 73 |
stringToEnumMap_["Pz"] = rnemdPz; |
| 74 |
stringToEnumMap_["Unknown"] = rnemdUnknown; |
| 75 |
|
| 76 |
rnemdObjectSelection_ = simParams->getRNEMD_objectSelection(); |
| 77 |
|
| 78 |
std::cerr << "calling evaluator with " << rnemdObjectSelection_ << "\n"; |
| 79 |
evaluator_.loadScriptString(rnemdObjectSelection_); |
| 80 |
std::cerr << "done"; |
| 81 |
|
| 82 |
const std::string st = simParams->getRNEMD_swapType(); |
| 83 |
|
| 84 |
std::map<std::string, RNEMDTypeEnum>::iterator i; |
| 85 |
i = stringToEnumMap_.find(st); |
| 86 |
rnemdType_ = (i == stringToEnumMap_.end()) ? RNEMD::rnemdUnknown : i->second; |
| 87 |
|
| 88 |
set_RNEMD_swapTime(simParams->getRNEMD_swapTime()); |
| 89 |
set_RNEMD_nBins(simParams->getRNEMD_nBins()); |
| 90 |
exchangeSum_ = 0.0; |
| 91 |
|
| 92 |
#ifndef IS_MPI |
| 93 |
if (simParams->haveSeed()) { |
| 94 |
seedValue = simParams->getSeed(); |
| 95 |
randNumGen_ = new SeqRandNumGen(seedValue); |
| 96 |
}else { |
| 97 |
randNumGen_ = new SeqRandNumGen(); |
| 98 |
} |
| 99 |
#else |
| 100 |
if (simParams->haveSeed()) { |
| 101 |
seedValue = simParams->getSeed(); |
| 102 |
randNumGen_ = new ParallelRandNumGen(seedValue); |
| 103 |
}else { |
| 104 |
randNumGen_ = new ParallelRandNumGen(); |
| 105 |
} |
| 106 |
#endif |
| 107 |
} |
| 108 |
|
| 109 |
RNEMD::~RNEMD() { |
| 110 |
delete randNumGen_; |
| 111 |
} |
| 112 |
|
| 113 |
void RNEMD::doSwap() { |
| 114 |
std::cerr << "in RNEMD!\n"; |
| 115 |
std::cerr << "nBins = " << nBins_ << "\n"; |
| 116 |
int midBin = nBins_ / 2; |
| 117 |
std::cerr << "midBin = " << midBin << "\n"; |
| 118 |
std::cerr << "swapTime = " << swapTime_ << "\n"; |
| 119 |
std::cerr << "exchangeSum = " << exchangeSum_ << "\n"; |
| 120 |
std::cerr << "swapType = " << rnemdType_ << "\n"; |
| 121 |
std::cerr << "selection = " << rnemdObjectSelection_ << "\n"; |
| 122 |
|
| 123 |
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 124 |
Mat3x3d hmat = currentSnap_->getHmat(); |
| 125 |
|
| 126 |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 127 |
|
| 128 |
std::cerr << "selectionCount = " << seleMan_.getSelectionCount() << "\n\n"; |
| 129 |
|
| 130 |
int i; |
| 131 |
StuntDouble* sd; |
| 132 |
int idx = sd->getLocalIndex(); |
| 133 |
|
| 134 |
std::vector<tuple3<RealType, int, StuntDouble* > > endSlice; |
| 135 |
std::vector<tuple3<RealType, int, StuntDouble* > > midSlice; |
| 136 |
|
| 137 |
for (sd = seleMan_.beginSelected(i); sd != NULL; |
| 138 |
sd = seleMan_.nextSelected(i)) { |
| 139 |
|
| 140 |
Vector3d pos = sd->getPos(); |
| 141 |
|
| 142 |
// wrap the stuntdouble's position back into the box: |
| 143 |
|
| 144 |
if (usePeriodicBoundaryConditions_) |
| 145 |
currentSnap_->wrapVector(pos); |
| 146 |
|
| 147 |
// which bin is this stuntdouble in? |
| 148 |
|
| 149 |
int binNo = int(nBins_ * (pos.z()) / hmat(2,2)); |
| 150 |
|
| 151 |
// if we're in bin 0 or the middleBin |
| 152 |
if (binNo == 0 || binNo == midBin) { |
| 153 |
|
| 154 |
RealType mass = sd->getMass(); |
| 155 |
Vector3d vel = sd->getVel(); |
| 156 |
RealType value; |
| 157 |
|
| 158 |
switch(rnemdType_) { |
| 159 |
case rnemdKinetic : |
| 160 |
|
| 161 |
value = mass * (vel[0]*vel[0] + vel[1]*vel[1] + |
| 162 |
vel[2]*vel[2]); |
| 163 |
|
| 164 |
if (sd->isDirectional()) { |
| 165 |
Vector3d angMom = sd->getJ(); |
| 166 |
Mat3x3d I = sd->getI(); |
| 167 |
|
| 168 |
if (sd->isLinear()) { |
| 169 |
int i = sd->linearAxis(); |
| 170 |
int j = (i + 1) % 3; |
| 171 |
int k = (i + 2) % 3; |
| 172 |
value += angMom[j] * angMom[j] / I(j, j) + |
| 173 |
angMom[k] * angMom[k] / I(k, k); |
| 174 |
} else { |
| 175 |
value += angMom[0]*angMom[0]/I(0, 0) |
| 176 |
+ angMom[1]*angMom[1]/I(1, 1) |
| 177 |
+ angMom[2]*angMom[2]/I(2, 2); |
| 178 |
} |
| 179 |
} |
| 180 |
value = value * 0.5 / OOPSEConstant::energyConvert; |
| 181 |
break; |
| 182 |
case rnemdPx : |
| 183 |
value = mass * vel[0]; |
| 184 |
break; |
| 185 |
case rnemdPy : |
| 186 |
value = mass * vel[1]; |
| 187 |
break; |
| 188 |
case rnemdPz : |
| 189 |
value = mass * vel[2]; |
| 190 |
break; |
| 191 |
case rnemdUnknown : |
| 192 |
default : |
| 193 |
break; |
| 194 |
} |
| 195 |
|
| 196 |
if (binNo == 0) |
| 197 |
endSlice.push_back( make_tuple3(value, idx, sd)); |
| 198 |
|
| 199 |
if (binNo == midBin) |
| 200 |
midSlice.push_back( make_tuple3(value, idx, sd)); |
| 201 |
} |
| 202 |
|
| 203 |
// find smallest value in endSlice: |
| 204 |
std::sort(endSlice.begin(), endSlice.end()); |
| 205 |
RealType min_val = endSlice[0].first; |
| 206 |
int min_idx = endSlice[0].second; |
| 207 |
StuntDouble* min_sd = endSlice[0].third; |
| 208 |
|
| 209 |
std::cerr << "smallest value = " << min_val << " idx = " << min_idx << "\n"; |
| 210 |
|
| 211 |
// find largest value in midSlice: |
| 212 |
std::sort(midSlice.rbegin(), midSlice.rend()); |
| 213 |
RealType max_val = midSlice[0].first; |
| 214 |
int max_idx = midSlice[0].second; |
| 215 |
StuntDouble* max_sd = midSlice[0].third; |
| 216 |
|
| 217 |
std::cerr << "largest value = " << max_val << " idx = " << max_idx << "\n"; |
| 218 |
|
| 219 |
} |
| 220 |
} |
| 221 |
} |