1 |
gezelter |
1329 |
/* |
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 |
gezelter |
1332 |
#include "math/Vector3.hpp" |
44 |
gezelter |
1329 |
#include "math/SquareMatrix3.hpp" |
45 |
|
|
#include "primitives/Molecule.hpp" |
46 |
|
|
#include "primitives/StuntDouble.hpp" |
47 |
gezelter |
1332 |
#include "utils/OOPSEConstant.hpp" |
48 |
|
|
#include "utils/Tuple.hpp" |
49 |
gezelter |
1329 |
|
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 |
gezelter |
1331 |
RNEMD::RNEMD(SimInfo* info) : info_(info), evaluator_(info), seleMan_(info) { |
66 |
gezelter |
1329 |
|
67 |
|
|
int seedValue; |
68 |
|
|
Globals * simParams = info->getSimParams(); |
69 |
skuang |
1330 |
|
70 |
|
|
stringToEnumMap_["Kinetic"] = rnemdKinetic; |
71 |
|
|
stringToEnumMap_["Px"] = rnemdPx; |
72 |
|
|
stringToEnumMap_["Py"] = rnemdPy; |
73 |
|
|
stringToEnumMap_["Pz"] = rnemdPz; |
74 |
|
|
stringToEnumMap_["Unknown"] = rnemdUnknown; |
75 |
|
|
|
76 |
gezelter |
1331 |
rnemdObjectSelection_ = simParams->getRNEMD_objectSelection(); |
77 |
|
|
|
78 |
|
|
std::cerr << "calling evaluator with " << rnemdObjectSelection_ << "\n"; |
79 |
|
|
evaluator_.loadScriptString(rnemdObjectSelection_); |
80 |
|
|
std::cerr << "done"; |
81 |
|
|
|
82 |
skuang |
1330 |
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 |
gezelter |
1329 |
|
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 |
skuang |
1330 |
|
113 |
gezelter |
1329 |
void RNEMD::doSwap() { |
114 |
|
|
std::cerr << "in RNEMD!\n"; |
115 |
skuang |
1330 |
std::cerr << "nBins = " << nBins_ << "\n"; |
116 |
gezelter |
1332 |
int midBin = nBins_ / 2; |
117 |
|
|
std::cerr << "midBin = " << midBin << "\n"; |
118 |
skuang |
1330 |
std::cerr << "swapTime = " << swapTime_ << "\n"; |
119 |
|
|
std::cerr << "exchangeSum = " << exchangeSum_ << "\n"; |
120 |
|
|
std::cerr << "swapType = " << rnemdType_ << "\n"; |
121 |
gezelter |
1331 |
std::cerr << "selection = " << rnemdObjectSelection_ << "\n"; |
122 |
|
|
|
123 |
gezelter |
1332 |
Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
124 |
|
|
Mat3x3d hmat = currentSnap_->getHmat(); |
125 |
|
|
|
126 |
gezelter |
1333 |
std::cerr << "hmat = " << hmat << "\n"; |
127 |
|
|
|
128 |
gezelter |
1331 |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
129 |
|
|
|
130 |
|
|
std::cerr << "selectionCount = " << seleMan_.getSelectionCount() << "\n\n"; |
131 |
|
|
|
132 |
gezelter |
1333 |
int selei; |
133 |
gezelter |
1331 |
StuntDouble* sd; |
134 |
gezelter |
1333 |
int idx; |
135 |
gezelter |
1331 |
|
136 |
gezelter |
1332 |
std::vector<tuple3<RealType, int, StuntDouble* > > endSlice; |
137 |
|
|
std::vector<tuple3<RealType, int, StuntDouble* > > midSlice; |
138 |
|
|
|
139 |
gezelter |
1333 |
for (sd = seleMan_.beginSelected(selei); sd != NULL; |
140 |
|
|
sd = seleMan_.nextSelected(selei)) { |
141 |
gezelter |
1332 |
|
142 |
gezelter |
1333 |
idx = sd->getLocalIndex(); |
143 |
|
|
|
144 |
gezelter |
1331 |
Vector3d pos = sd->getPos(); |
145 |
gezelter |
1332 |
|
146 |
gezelter |
1333 |
std::cerr << "idx = " << idx << "pos = " << pos << "\n"; |
147 |
gezelter |
1332 |
// wrap the stuntdouble's position back into the box: |
148 |
|
|
|
149 |
gezelter |
1331 |
if (usePeriodicBoundaryConditions_) |
150 |
gezelter |
1332 |
currentSnap_->wrapVector(pos); |
151 |
gezelter |
1333 |
std::cerr << "new pos.z = " << pos.z() << "\n"; |
152 |
gezelter |
1332 |
|
153 |
|
|
// which bin is this stuntdouble in? |
154 |
|
|
|
155 |
gezelter |
1331 |
int binNo = int(nBins_ * (pos.z()) / hmat(2,2)); |
156 |
gezelter |
1332 |
|
157 |
gezelter |
1333 |
std::cerr << "bin = " << binNo << "\n"; |
158 |
|
|
|
159 |
gezelter |
1332 |
// if we're in bin 0 or the middleBin |
160 |
|
|
if (binNo == 0 || binNo == midBin) { |
161 |
|
|
|
162 |
|
|
RealType mass = sd->getMass(); |
163 |
|
|
Vector3d vel = sd->getVel(); |
164 |
|
|
RealType value; |
165 |
|
|
|
166 |
|
|
switch(rnemdType_) { |
167 |
|
|
case rnemdKinetic : |
168 |
|
|
|
169 |
|
|
value = mass * (vel[0]*vel[0] + vel[1]*vel[1] + |
170 |
|
|
vel[2]*vel[2]); |
171 |
|
|
|
172 |
|
|
if (sd->isDirectional()) { |
173 |
|
|
Vector3d angMom = sd->getJ(); |
174 |
|
|
Mat3x3d I = sd->getI(); |
175 |
|
|
|
176 |
|
|
if (sd->isLinear()) { |
177 |
|
|
int i = sd->linearAxis(); |
178 |
|
|
int j = (i + 1) % 3; |
179 |
|
|
int k = (i + 2) % 3; |
180 |
|
|
value += angMom[j] * angMom[j] / I(j, j) + |
181 |
|
|
angMom[k] * angMom[k] / I(k, k); |
182 |
|
|
} else { |
183 |
|
|
value += angMom[0]*angMom[0]/I(0, 0) |
184 |
|
|
+ angMom[1]*angMom[1]/I(1, 1) |
185 |
|
|
+ angMom[2]*angMom[2]/I(2, 2); |
186 |
|
|
} |
187 |
|
|
} |
188 |
|
|
value = value * 0.5 / OOPSEConstant::energyConvert; |
189 |
|
|
break; |
190 |
|
|
case rnemdPx : |
191 |
|
|
value = mass * vel[0]; |
192 |
|
|
break; |
193 |
|
|
case rnemdPy : |
194 |
|
|
value = mass * vel[1]; |
195 |
|
|
break; |
196 |
|
|
case rnemdPz : |
197 |
|
|
value = mass * vel[2]; |
198 |
|
|
break; |
199 |
|
|
case rnemdUnknown : |
200 |
|
|
default : |
201 |
|
|
break; |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
if (binNo == 0) |
205 |
|
|
endSlice.push_back( make_tuple3(value, idx, sd)); |
206 |
|
|
|
207 |
|
|
if (binNo == midBin) |
208 |
|
|
midSlice.push_back( make_tuple3(value, idx, sd)); |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
// find smallest value in endSlice: |
212 |
|
|
std::sort(endSlice.begin(), endSlice.end()); |
213 |
|
|
RealType min_val = endSlice[0].first; |
214 |
|
|
int min_idx = endSlice[0].second; |
215 |
|
|
StuntDouble* min_sd = endSlice[0].third; |
216 |
|
|
|
217 |
|
|
std::cerr << "smallest value = " << min_val << " idx = " << min_idx << "\n"; |
218 |
|
|
|
219 |
|
|
// find largest value in midSlice: |
220 |
|
|
std::sort(midSlice.rbegin(), midSlice.rend()); |
221 |
|
|
RealType max_val = midSlice[0].first; |
222 |
|
|
int max_idx = midSlice[0].second; |
223 |
|
|
StuntDouble* max_sd = midSlice[0].third; |
224 |
|
|
|
225 |
|
|
std::cerr << "largest value = " << max_val << " idx = " << max_idx << "\n"; |
226 |
|
|
|
227 |
gezelter |
1331 |
} |
228 |
gezelter |
1329 |
} |
229 |
|
|
} |