# | Line 35 | Line 35 | |
---|---|---|
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 "integrators/RNEMD.hpp" |
43 | > | #include <sstream> |
44 | > | #include <string> |
45 | > | |
46 | > | #include "rnemd/RNEMD.hpp" |
47 | #include "math/Vector3.hpp" | |
48 | #include "math/Vector.hpp" | |
49 | #include "math/SquareMatrix3.hpp" | |
# | Line 49 | Line 52 | |
52 | #include "primitives/StuntDouble.hpp" | |
53 | #include "utils/PhysicalConstants.hpp" | |
54 | #include "utils/Tuple.hpp" | |
55 | < | |
56 | < | #ifndef IS_MPI |
57 | < | #include "math/SeqRandNumGen.hpp" |
55 | < | #else |
56 | < | #include "math/ParallelRandNumGen.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 | + | hasData_(false), hasDividingArea_(false), |
76 | usePeriodicBoundaryConditions_(info->getSimParams()->getUsePeriodicBoundaryConditions()) { | |
77 | ||
78 | + | trialCount_ = 0; |
79 | failTrialCount_ = 0; | |
80 | failRootCount_ = 0; | |
81 | ||
82 | < | int seedValue; |
83 | < | Globals * simParams = info->getSimParams(); |
82 | > | Globals* simParams = info->getSimParams(); |
83 | > | RNEMDParameters* rnemdParams = simParams->getRNEMDParameters(); |
84 | ||
85 | < | stringToEnumMap_["KineticSwap"] = rnemdKineticSwap; |
86 | < | stringToEnumMap_["KineticScale"] = rnemdKineticScale; |
76 | < | stringToEnumMap_["KineticScaleVAM"] = rnemdKineticScaleVAM; |
77 | < | stringToEnumMap_["KineticScaleAM"] = rnemdKineticScaleAM; |
78 | < | stringToEnumMap_["PxScale"] = rnemdPxScale; |
79 | < | stringToEnumMap_["PyScale"] = rnemdPyScale; |
80 | < | stringToEnumMap_["PzScale"] = rnemdPzScale; |
81 | < | stringToEnumMap_["Px"] = rnemdPx; |
82 | < | stringToEnumMap_["Py"] = rnemdPy; |
83 | < | stringToEnumMap_["Pz"] = rnemdPz; |
84 | < | stringToEnumMap_["ShiftScaleV"] = rnemdShiftScaleV; |
85 | < | stringToEnumMap_["ShiftScaleVAM"] = rnemdShiftScaleVAM; |
86 | < | stringToEnumMap_["Unknown"] = rnemdUnknown; |
85 | > | doRNEMD_ = rnemdParams->getUseRNEMD(); |
86 | > | if (!doRNEMD_) return; |
87 | ||
88 | < | rnemdObjectSelection_ = simParams->getRNEMD_objectSelection(); |
89 | < | evaluator_.loadScriptString(rnemdObjectSelection_); |
90 | < | seleMan_.setSelectionSet(evaluator_.evaluate()); |
88 | > | stringToMethod_["Swap"] = rnemdSwap; |
89 | > | stringToMethod_["NIVS"] = rnemdNIVS; |
90 | > | stringToMethod_["VSS"] = rnemdVSS; |
91 | ||
92 | < | // do some sanity checking |
92 | > | stringToFluxType_["KE"] = rnemdKE; |
93 | > | stringToFluxType_["Px"] = rnemdPx; |
94 | > | stringToFluxType_["Py"] = rnemdPy; |
95 | > | stringToFluxType_["Pz"] = rnemdPz; |
96 | > | stringToFluxType_["Pvector"] = rnemdPvector; |
97 | > | stringToFluxType_["Lx"] = rnemdLx; |
98 | > | stringToFluxType_["Ly"] = rnemdLy; |
99 | > | stringToFluxType_["Lz"] = rnemdLz; |
100 | > | stringToFluxType_["Lvector"] = rnemdLvector; |
101 | > | stringToFluxType_["KE+Px"] = rnemdKePx; |
102 | > | stringToFluxType_["KE+Py"] = rnemdKePy; |
103 | > | stringToFluxType_["KE+Pvector"] = rnemdKePvector; |
104 | > | stringToFluxType_["KE+Lx"] = rnemdKeLx; |
105 | > | stringToFluxType_["KE+Ly"] = rnemdKeLy; |
106 | > | stringToFluxType_["KE+Lz"] = rnemdKeLz; |
107 | > | stringToFluxType_["KE+Lvector"] = rnemdKeLvector; |
108 | ||
109 | < | int selectionCount = seleMan_.getSelectionCount(); |
110 | < | int nIntegrable = info->getNGlobalIntegrableObjects(); |
109 | > | runTime_ = simParams->getRunTime(); |
110 | > | statusTime_ = simParams->getStatusTime(); |
111 | ||
112 | < | if (selectionCount > nIntegrable) { |
112 | > | const string methStr = rnemdParams->getMethod(); |
113 | > | bool hasFluxType = rnemdParams->haveFluxType(); |
114 | > | |
115 | > | rnemdObjectSelection_ = rnemdParams->getObjectSelection(); |
116 | > | |
117 | > | string fluxStr; |
118 | > | if (hasFluxType) { |
119 | > | fluxStr = rnemdParams->getFluxType(); |
120 | > | } else { |
121 | sprintf(painCave.errMsg, | |
122 | < | "RNEMD: The current RNEMD_objectSelection,\n" |
123 | < | "\t\t%s\n" |
124 | < | "\thas resulted in %d selected objects. However,\n" |
125 | < | "\tthe total number of integrable objects in the system\n" |
126 | < | "\tis only %d. This is almost certainly not what you want\n" |
127 | < | "\tto do. A likely cause of this is forgetting the _RB_0\n" |
128 | < | "\tselector in the selection script!\n", |
106 | < | rnemdObjectSelection_.c_str(), |
107 | < | selectionCount, nIntegrable); |
108 | < | painCave.isFatal = 0; |
109 | < | painCave.severity = OPENMD_WARNING; |
122 | > | "RNEMD: No fluxType was set in the md file. This parameter,\n" |
123 | > | "\twhich must be one of the following values:\n" |
124 | > | "\tKE, Px, Py, Pz, Pvector, Lx, Ly, Lz, Lvector,\n" |
125 | > | "\tKE+Px, KE+Py, KE+Pvector, KE+Lx, KE+Ly, KE+Lz, KE+Lvector\n" |
126 | > | "\tmust be set to use RNEMD\n"); |
127 | > | painCave.isFatal = 1; |
128 | > | painCave.severity = OPENMD_ERROR; |
129 | simError(); | |
130 | } | |
131 | + | |
132 | + | bool hasKineticFlux = rnemdParams->haveKineticFlux(); |
133 | + | bool hasMomentumFlux = rnemdParams->haveMomentumFlux(); |
134 | + | bool hasMomentumFluxVector = rnemdParams->haveMomentumFluxVector(); |
135 | + | bool hasAngularMomentumFlux = rnemdParams->haveAngularMomentumFlux(); |
136 | + | bool hasAngularMomentumFluxVector = rnemdParams->haveAngularMomentumFluxVector(); |
137 | + | hasSelectionA_ = rnemdParams->haveSelectionA(); |
138 | + | hasSelectionB_ = rnemdParams->haveSelectionB(); |
139 | + | bool hasSlabWidth = rnemdParams->haveSlabWidth(); |
140 | + | bool hasSlabACenter = rnemdParams->haveSlabACenter(); |
141 | + | bool hasSlabBCenter = rnemdParams->haveSlabBCenter(); |
142 | + | bool hasSphereARadius = rnemdParams->haveSphereARadius(); |
143 | + | hasSphereBRadius_ = rnemdParams->haveSphereBRadius(); |
144 | + | bool hasCoordinateOrigin = rnemdParams->haveCoordinateOrigin(); |
145 | + | bool hasOutputFileName = rnemdParams->haveOutputFileName(); |
146 | + | bool hasOutputFields = rnemdParams->haveOutputFields(); |
147 | ||
148 | < | const string st = simParams->getRNEMD_exchangeType(); |
148 | > | map<string, RNEMDMethod>::iterator i; |
149 | > | i = stringToMethod_.find(methStr); |
150 | > | if (i != stringToMethod_.end()) |
151 | > | rnemdMethod_ = i->second; |
152 | > | else { |
153 | > | sprintf(painCave.errMsg, |
154 | > | "RNEMD: The current method,\n" |
155 | > | "\t\t%s is not one of the recognized\n" |
156 | > | "\texchange methods: Swap, NIVS, or VSS\n", |
157 | > | methStr.c_str()); |
158 | > | painCave.isFatal = 1; |
159 | > | painCave.severity = OPENMD_ERROR; |
160 | > | simError(); |
161 | > | } |
162 | ||
163 | < | map<string, RNEMDTypeEnum>::iterator i; |
164 | < | i = stringToEnumMap_.find(st); |
165 | < | rnemdType_ = (i == stringToEnumMap_.end()) ? RNEMD::rnemdUnknown : i->second; |
166 | < | if (rnemdType_ == rnemdUnknown) { |
163 | > | map<string, RNEMDFluxType>::iterator j; |
164 | > | j = stringToFluxType_.find(fluxStr); |
165 | > | if (j != stringToFluxType_.end()) |
166 | > | rnemdFluxType_ = j->second; |
167 | > | else { |
168 | sprintf(painCave.errMsg, | |
169 | < | "RNEMD: The current RNEMD_exchangeType,\n" |
169 | > | "RNEMD: The current fluxType,\n" |
170 | "\t\t%s\n" | |
171 | < | "\tis not one of the recognized exchange types.\n", |
172 | < | st.c_str()); |
171 | > | "\tis not one of the recognized flux types.\n", |
172 | > | fluxStr.c_str()); |
173 | painCave.isFatal = 1; | |
174 | painCave.severity = OPENMD_ERROR; | |
175 | simError(); | |
176 | } | |
128 | – | |
129 | – | outputTemp_ = false; |
130 | – | if (simParams->haveRNEMD_outputTemperature()) { |
131 | – | outputTemp_ = simParams->getRNEMD_outputTemperature(); |
132 | – | } else if ((rnemdType_ == rnemdKineticSwap) || |
133 | – | (rnemdType_ == rnemdKineticScale) || |
134 | – | (rnemdType_ == rnemdKineticScaleVAM) || |
135 | – | (rnemdType_ == rnemdKineticScaleAM)) { |
136 | – | outputTemp_ = true; |
137 | – | } |
138 | – | outputVx_ = false; |
139 | – | if (simParams->haveRNEMD_outputVx()) { |
140 | – | outputVx_ = simParams->getRNEMD_outputVx(); |
141 | – | } else if ((rnemdType_ == rnemdPx) || (rnemdType_ == rnemdPxScale)) { |
142 | – | outputVx_ = true; |
143 | – | } |
144 | – | outputVy_ = false; |
145 | – | if (simParams->haveRNEMD_outputVy()) { |
146 | – | outputVy_ = simParams->getRNEMD_outputVy(); |
147 | – | } else if ((rnemdType_ == rnemdPy) || (rnemdType_ == rnemdPyScale)) { |
148 | – | outputVy_ = true; |
149 | – | } |
150 | – | output3DTemp_ = false; |
151 | – | if (simParams->haveRNEMD_outputXyzTemperature()) { |
152 | – | output3DTemp_ = simParams->getRNEMD_outputXyzTemperature(); |
153 | – | } |
154 | – | outputRotTemp_ = false; |
155 | – | if (simParams->haveRNEMD_outputRotTemperature()) { |
156 | – | outputRotTemp_ = simParams->getRNEMD_outputRotTemperature(); |
157 | – | } |
177 | ||
178 | < | #ifdef IS_MPI |
179 | < | if (worldRank == 0) { |
180 | < | #endif |
181 | < | |
182 | < | //may have rnemdWriter separately |
183 | < | string rnemdFileName; |
184 | < | |
185 | < | if (outputTemp_) { |
186 | < | rnemdFileName = "temperature.log"; |
187 | < | tempLog_.open(rnemdFileName.c_str()); |
178 | > | bool methodFluxMismatch = false; |
179 | > | bool hasCorrectFlux = false; |
180 | > | switch(rnemdMethod_) { |
181 | > | case rnemdSwap: |
182 | > | switch (rnemdFluxType_) { |
183 | > | case rnemdKE: |
184 | > | hasCorrectFlux = hasKineticFlux; |
185 | > | break; |
186 | > | case rnemdPx: |
187 | > | case rnemdPy: |
188 | > | case rnemdPz: |
189 | > | hasCorrectFlux = hasMomentumFlux; |
190 | > | break; |
191 | > | default : |
192 | > | methodFluxMismatch = true; |
193 | > | break; |
194 | } | |
195 | < | if (outputVx_) { |
196 | < | rnemdFileName = "velocityX.log"; |
197 | < | vxzLog_.open(rnemdFileName.c_str()); |
195 | > | break; |
196 | > | case rnemdNIVS: |
197 | > | switch (rnemdFluxType_) { |
198 | > | case rnemdKE: |
199 | > | case rnemdRotKE: |
200 | > | case rnemdFullKE: |
201 | > | hasCorrectFlux = hasKineticFlux; |
202 | > | break; |
203 | > | case rnemdPx: |
204 | > | case rnemdPy: |
205 | > | case rnemdPz: |
206 | > | hasCorrectFlux = hasMomentumFlux; |
207 | > | break; |
208 | > | case rnemdKePx: |
209 | > | case rnemdKePy: |
210 | > | hasCorrectFlux = hasMomentumFlux && hasKineticFlux; |
211 | > | break; |
212 | > | default: |
213 | > | methodFluxMismatch = true; |
214 | > | break; |
215 | } | |
216 | < | if (outputVy_) { |
217 | < | rnemdFileName = "velocityY.log"; |
218 | < | vyzLog_.open(rnemdFileName.c_str()); |
216 | > | break; |
217 | > | case rnemdVSS: |
218 | > | switch (rnemdFluxType_) { |
219 | > | case rnemdKE: |
220 | > | case rnemdRotKE: |
221 | > | case rnemdFullKE: |
222 | > | hasCorrectFlux = hasKineticFlux; |
223 | > | break; |
224 | > | case rnemdPx: |
225 | > | case rnemdPy: |
226 | > | case rnemdPz: |
227 | > | hasCorrectFlux = hasMomentumFlux; |
228 | > | break; |
229 | > | case rnemdLx: |
230 | > | case rnemdLy: |
231 | > | case rnemdLz: |
232 | > | hasCorrectFlux = hasAngularMomentumFlux; |
233 | > | break; |
234 | > | case rnemdPvector: |
235 | > | hasCorrectFlux = hasMomentumFluxVector; |
236 | > | break; |
237 | > | case rnemdLvector: |
238 | > | hasCorrectFlux = hasAngularMomentumFluxVector; |
239 | > | break; |
240 | > | case rnemdKePx: |
241 | > | case rnemdKePy: |
242 | > | hasCorrectFlux = hasMomentumFlux && hasKineticFlux; |
243 | > | break; |
244 | > | case rnemdKeLx: |
245 | > | case rnemdKeLy: |
246 | > | case rnemdKeLz: |
247 | > | hasCorrectFlux = hasAngularMomentumFlux && hasKineticFlux; |
248 | > | break; |
249 | > | case rnemdKePvector: |
250 | > | hasCorrectFlux = hasMomentumFluxVector && hasKineticFlux; |
251 | > | break; |
252 | > | case rnemdKeLvector: |
253 | > | hasCorrectFlux = hasAngularMomentumFluxVector && hasKineticFlux; |
254 | > | break; |
255 | > | default: |
256 | > | methodFluxMismatch = true; |
257 | > | break; |
258 | } | |
259 | + | default: |
260 | + | break; |
261 | + | } |
262 | ||
263 | < | if (output3DTemp_) { |
264 | < | rnemdFileName = "temperatureX.log"; |
265 | < | xTempLog_.open(rnemdFileName.c_str()); |
266 | < | rnemdFileName = "temperatureY.log"; |
267 | < | yTempLog_.open(rnemdFileName.c_str()); |
268 | < | rnemdFileName = "temperatureZ.log"; |
269 | < | zTempLog_.open(rnemdFileName.c_str()); |
263 | > | if (methodFluxMismatch) { |
264 | > | sprintf(painCave.errMsg, |
265 | > | "RNEMD: The current method,\n" |
266 | > | "\t\t%s\n" |
267 | > | "\tcannot be used with the current flux type, %s\n", |
268 | > | methStr.c_str(), fluxStr.c_str()); |
269 | > | painCave.isFatal = 1; |
270 | > | painCave.severity = OPENMD_ERROR; |
271 | > | simError(); |
272 | > | } |
273 | > | if (!hasCorrectFlux) { |
274 | > | sprintf(painCave.errMsg, |
275 | > | "RNEMD: The current method, %s, and flux type, %s,\n" |
276 | > | "\tdid not have the correct flux value specified. Options\n" |
277 | > | "\tinclude: kineticFlux, momentumFlux, angularMomentumFlux,\n" |
278 | > | "\tmomentumFluxVector, and angularMomentumFluxVector.\n", |
279 | > | methStr.c_str(), fluxStr.c_str()); |
280 | > | painCave.isFatal = 1; |
281 | > | painCave.severity = OPENMD_ERROR; |
282 | > | simError(); |
283 | > | } |
284 | > | |
285 | > | if (hasKineticFlux) { |
286 | > | // convert the kcal / mol / Angstroms^2 / fs values in the md file |
287 | > | // into amu / fs^3: |
288 | > | kineticFlux_ = rnemdParams->getKineticFlux() |
289 | > | * PhysicalConstants::energyConvert; |
290 | > | } else { |
291 | > | kineticFlux_ = 0.0; |
292 | > | } |
293 | > | if (hasMomentumFluxVector) { |
294 | > | momentumFluxVector_ = rnemdParams->getMomentumFluxVector(); |
295 | > | } else { |
296 | > | momentumFluxVector_ = V3Zero; |
297 | > | if (hasMomentumFlux) { |
298 | > | RealType momentumFlux = rnemdParams->getMomentumFlux(); |
299 | > | switch (rnemdFluxType_) { |
300 | > | case rnemdPx: |
301 | > | momentumFluxVector_.x() = momentumFlux; |
302 | > | break; |
303 | > | case rnemdPy: |
304 | > | momentumFluxVector_.y() = momentumFlux; |
305 | > | break; |
306 | > | case rnemdPz: |
307 | > | momentumFluxVector_.z() = momentumFlux; |
308 | > | break; |
309 | > | case rnemdKePx: |
310 | > | momentumFluxVector_.x() = momentumFlux; |
311 | > | break; |
312 | > | case rnemdKePy: |
313 | > | momentumFluxVector_.y() = momentumFlux; |
314 | > | break; |
315 | > | default: |
316 | > | break; |
317 | > | } |
318 | } | |
319 | < | if (outputRotTemp_) { |
320 | < | rnemdFileName = "temperatureR.log"; |
321 | < | rotTempLog_.open(rnemdFileName.c_str()); |
319 | > | if (hasAngularMomentumFluxVector) { |
320 | > | angularMomentumFluxVector_ = rnemdParams->getAngularMomentumFluxVector(); |
321 | > | } else { |
322 | > | angularMomentumFluxVector_ = V3Zero; |
323 | > | if (hasAngularMomentumFlux) { |
324 | > | RealType angularMomentumFlux = rnemdParams->getAngularMomentumFlux(); |
325 | > | switch (rnemdFluxType_) { |
326 | > | case rnemdLx: |
327 | > | angularMomentumFluxVector_.x() = angularMomentumFlux; |
328 | > | break; |
329 | > | case rnemdLy: |
330 | > | angularMomentumFluxVector_.y() = angularMomentumFlux; |
331 | > | break; |
332 | > | case rnemdLz: |
333 | > | angularMomentumFluxVector_.z() = angularMomentumFlux; |
334 | > | break; |
335 | > | case rnemdKeLx: |
336 | > | angularMomentumFluxVector_.x() = angularMomentumFlux; |
337 | > | break; |
338 | > | case rnemdKeLy: |
339 | > | angularMomentumFluxVector_.y() = angularMomentumFlux; |
340 | > | break; |
341 | > | case rnemdKeLz: |
342 | > | angularMomentumFluxVector_.z() = angularMomentumFlux; |
343 | > | break; |
344 | > | default: |
345 | > | break; |
346 | > | } |
347 | > | } |
348 | } | |
349 | ||
350 | < | #ifdef IS_MPI |
351 | < | } |
194 | < | #endif |
195 | < | |
196 | < | set_RNEMD_exchange_time(simParams->getRNEMD_exchangeTime()); |
197 | < | set_RNEMD_nBins(simParams->getRNEMD_nBins()); |
198 | < | midBin_ = nBins_ / 2; |
199 | < | if (simParams->haveRNEMD_binShift()) { |
200 | < | if (simParams->getRNEMD_binShift()) { |
201 | < | zShift_ = 0.5 / (RealType)(nBins_); |
350 | > | if (hasCoordinateOrigin) { |
351 | > | coordinateOrigin_ = rnemdParams->getCoordinateOrigin(); |
352 | } else { | |
353 | < | zShift_ = 0.0; |
353 | > | coordinateOrigin_ = V3Zero; |
354 | } | |
205 | – | } else { |
206 | – | zShift_ = 0.0; |
207 | – | } |
208 | – | //cerr << "I shift slabs by " << zShift_ << " Lz\n"; |
209 | – | //shift slabs by half slab width, maybe useful in heterogeneous systems |
210 | – | //set to 0.0 if not using it; N/A in status output yet |
211 | – | if (simParams->haveRNEMD_logWidth()) { |
212 | – | set_RNEMD_logWidth(simParams->getRNEMD_logWidth()); |
213 | – | /*arbitary rnemdLogWidth_, no checking; |
214 | – | if (rnemdLogWidth_ != nBins_ && rnemdLogWidth_ != midBin_ + 1) { |
215 | – | cerr << "WARNING! RNEMD_logWidth has abnormal value!\n"; |
216 | – | cerr << "Automaically set back to default.\n"; |
217 | – | rnemdLogWidth_ = nBins_; |
218 | – | }*/ |
219 | – | } else { |
220 | – | set_RNEMD_logWidth(nBins_); |
221 | – | } |
222 | – | tempHist_.resize(rnemdLogWidth_, 0.0); |
223 | – | tempCount_.resize(rnemdLogWidth_, 0); |
224 | – | pxzHist_.resize(rnemdLogWidth_, 0.0); |
225 | – | //vxzCount_.resize(rnemdLogWidth_, 0); |
226 | – | pyzHist_.resize(rnemdLogWidth_, 0.0); |
227 | – | //vyzCount_.resize(rnemdLogWidth_, 0); |
355 | ||
356 | < | mHist_.resize(rnemdLogWidth_, 0.0); |
230 | < | xTempHist_.resize(rnemdLogWidth_, 0.0); |
231 | < | yTempHist_.resize(rnemdLogWidth_, 0.0); |
232 | < | zTempHist_.resize(rnemdLogWidth_, 0.0); |
233 | < | xyzTempCount_.resize(rnemdLogWidth_, 0); |
234 | < | rotTempHist_.resize(rnemdLogWidth_, 0.0); |
235 | < | rotTempCount_.resize(rnemdLogWidth_, 0); |
356 | > | // do some sanity checking |
357 | ||
358 | < | set_RNEMD_exchange_total(0.0); |
238 | < | if (simParams->haveRNEMD_targetFlux()) { |
239 | < | set_RNEMD_target_flux(simParams->getRNEMD_targetFlux()); |
240 | < | } else { |
241 | < | set_RNEMD_target_flux(0.0); |
242 | < | } |
243 | < | if (simParams->haveRNEMD_targetJzKE()) { |
244 | < | set_RNEMD_target_JzKE(simParams->getRNEMD_targetJzKE()); |
245 | < | } else { |
246 | < | set_RNEMD_target_JzKE(0.0); |
247 | < | } |
248 | < | if (simParams->haveRNEMD_targetJzpx()) { |
249 | < | set_RNEMD_target_jzpx(simParams->getRNEMD_targetJzpx()); |
250 | < | } else { |
251 | < | set_RNEMD_target_jzpx(0.0); |
252 | < | } |
253 | < | jzp_.x() = targetJzpx_; |
254 | < | njzp_.x() = -targetJzpx_; |
255 | < | if (simParams->haveRNEMD_targetJzpy()) { |
256 | < | set_RNEMD_target_jzpy(simParams->getRNEMD_targetJzpy()); |
257 | < | } else { |
258 | < | set_RNEMD_target_jzpy(0.0); |
259 | < | } |
260 | < | jzp_.y() = targetJzpy_; |
261 | < | njzp_.y() = -targetJzpy_; |
262 | < | if (simParams->haveRNEMD_targetJzpz()) { |
263 | < | set_RNEMD_target_jzpz(simParams->getRNEMD_targetJzpz()); |
264 | < | } else { |
265 | < | set_RNEMD_target_jzpz(0.0); |
266 | < | } |
267 | < | jzp_.z() = targetJzpz_; |
268 | < | njzp_.z() = -targetJzpz_; |
358 | > | int selectionCount = seleMan_.getSelectionCount(); |
359 | ||
360 | < | #ifndef IS_MPI |
361 | < | if (simParams->haveSeed()) { |
362 | < | seedValue = simParams->getSeed(); |
363 | < | randNumGen_ = new SeqRandNumGen(seedValue); |
364 | < | }else { |
365 | < | randNumGen_ = new SeqRandNumGen(); |
366 | < | } |
367 | < | #else |
368 | < | if (simParams->haveSeed()) { |
369 | < | seedValue = simParams->getSeed(); |
370 | < | randNumGen_ = new ParallelRandNumGen(seedValue); |
371 | < | }else { |
372 | < | randNumGen_ = new ParallelRandNumGen(); |
373 | < | } |
374 | < | #endif |
360 | > | int nIntegrable = info->getNGlobalIntegrableObjects(); |
361 | > | |
362 | > | if (selectionCount > nIntegrable) { |
363 | > | sprintf(painCave.errMsg, |
364 | > | "RNEMD: The current objectSelection,\n" |
365 | > | "\t\t%s\n" |
366 | > | "\thas resulted in %d selected objects. However,\n" |
367 | > | "\tthe total number of integrable objects in the system\n" |
368 | > | "\tis only %d. This is almost certainly not what you want\n" |
369 | > | "\tto do. A likely cause of this is forgetting the _RB_0\n" |
370 | > | "\tselector in the selection script!\n", |
371 | > | rnemdObjectSelection_.c_str(), |
372 | > | selectionCount, nIntegrable); |
373 | > | painCave.isFatal = 0; |
374 | > | painCave.severity = OPENMD_WARNING; |
375 | > | simError(); |
376 | > | } |
377 | > | |
378 | > | areaAccumulator_ = new Accumulator(); |
379 | > | |
380 | > | nBins_ = rnemdParams->getOutputBins(); |
381 | > | binWidth_ = rnemdParams->getOutputBinWidth(); |
382 | > | |
383 | > | data_.resize(RNEMD::ENDINDEX); |
384 | > | OutputData z; |
385 | > | z.units = "Angstroms"; |
386 | > | z.title = "Z"; |
387 | > | z.dataType = "RealType"; |
388 | > | z.accumulator.reserve(nBins_); |
389 | > | for (int i = 0; i < nBins_; i++) |
390 | > | z.accumulator.push_back( new Accumulator() ); |
391 | > | data_[Z] = z; |
392 | > | outputMap_["Z"] = Z; |
393 | > | |
394 | > | OutputData r; |
395 | > | r.units = "Angstroms"; |
396 | > | r.title = "R"; |
397 | > | r.dataType = "RealType"; |
398 | > | r.accumulator.reserve(nBins_); |
399 | > | for (int i = 0; i < nBins_; i++) |
400 | > | r.accumulator.push_back( new Accumulator() ); |
401 | > | data_[R] = r; |
402 | > | outputMap_["R"] = R; |
403 | > | |
404 | > | OutputData temperature; |
405 | > | temperature.units = "K"; |
406 | > | temperature.title = "Temperature"; |
407 | > | temperature.dataType = "RealType"; |
408 | > | temperature.accumulator.reserve(nBins_); |
409 | > | for (int i = 0; i < nBins_; i++) |
410 | > | temperature.accumulator.push_back( new Accumulator() ); |
411 | > | data_[TEMPERATURE] = temperature; |
412 | > | outputMap_["TEMPERATURE"] = TEMPERATURE; |
413 | > | |
414 | > | OutputData velocity; |
415 | > | velocity.units = "angstroms/fs"; |
416 | > | velocity.title = "Velocity"; |
417 | > | velocity.dataType = "Vector3d"; |
418 | > | velocity.accumulator.reserve(nBins_); |
419 | > | for (int i = 0; i < nBins_; i++) |
420 | > | velocity.accumulator.push_back( new VectorAccumulator() ); |
421 | > | data_[VELOCITY] = velocity; |
422 | > | outputMap_["VELOCITY"] = VELOCITY; |
423 | > | |
424 | > | OutputData angularVelocity; |
425 | > | angularVelocity.units = "angstroms^2/fs"; |
426 | > | angularVelocity.title = "AngularVelocity"; |
427 | > | angularVelocity.dataType = "Vector3d"; |
428 | > | angularVelocity.accumulator.reserve(nBins_); |
429 | > | for (int i = 0; i < nBins_; i++) |
430 | > | angularVelocity.accumulator.push_back( new VectorAccumulator() ); |
431 | > | data_[ANGULARVELOCITY] = angularVelocity; |
432 | > | outputMap_["ANGULARVELOCITY"] = ANGULARVELOCITY; |
433 | > | |
434 | > | OutputData density; |
435 | > | density.units = "g cm^-3"; |
436 | > | density.title = "Density"; |
437 | > | density.dataType = "RealType"; |
438 | > | density.accumulator.reserve(nBins_); |
439 | > | for (int i = 0; i < nBins_; i++) |
440 | > | density.accumulator.push_back( new Accumulator() ); |
441 | > | data_[DENSITY] = density; |
442 | > | outputMap_["DENSITY"] = DENSITY; |
443 | > | |
444 | > | if (hasOutputFields) { |
445 | > | parseOutputFileFormat(rnemdParams->getOutputFields()); |
446 | > | } else { |
447 | > | if (usePeriodicBoundaryConditions_) |
448 | > | outputMask_.set(Z); |
449 | > | else |
450 | > | outputMask_.set(R); |
451 | > | switch (rnemdFluxType_) { |
452 | > | case rnemdKE: |
453 | > | case rnemdRotKE: |
454 | > | case rnemdFullKE: |
455 | > | outputMask_.set(TEMPERATURE); |
456 | > | break; |
457 | > | case rnemdPx: |
458 | > | case rnemdPy: |
459 | > | outputMask_.set(VELOCITY); |
460 | > | break; |
461 | > | case rnemdPz: |
462 | > | case rnemdPvector: |
463 | > | outputMask_.set(VELOCITY); |
464 | > | outputMask_.set(DENSITY); |
465 | > | break; |
466 | > | case rnemdLx: |
467 | > | case rnemdLy: |
468 | > | case rnemdLz: |
469 | > | case rnemdLvector: |
470 | > | outputMask_.set(ANGULARVELOCITY); |
471 | > | break; |
472 | > | case rnemdKeLx: |
473 | > | case rnemdKeLy: |
474 | > | case rnemdKeLz: |
475 | > | case rnemdKeLvector: |
476 | > | outputMask_.set(TEMPERATURE); |
477 | > | outputMask_.set(ANGULARVELOCITY); |
478 | > | break; |
479 | > | case rnemdKePx: |
480 | > | case rnemdKePy: |
481 | > | outputMask_.set(TEMPERATURE); |
482 | > | outputMask_.set(VELOCITY); |
483 | > | break; |
484 | > | case rnemdKePvector: |
485 | > | outputMask_.set(TEMPERATURE); |
486 | > | outputMask_.set(VELOCITY); |
487 | > | outputMask_.set(DENSITY); |
488 | > | break; |
489 | > | default: |
490 | > | break; |
491 | > | } |
492 | > | } |
493 | > | |
494 | > | if (hasOutputFileName) { |
495 | > | rnemdFileName_ = rnemdParams->getOutputFileName(); |
496 | > | } else { |
497 | > | rnemdFileName_ = getPrefix(info->getFinalConfigFileName()) + ".rnemd"; |
498 | > | } |
499 | > | |
500 | > | exchangeTime_ = rnemdParams->getExchangeTime(); |
501 | > | |
502 | > | Snapshot* currentSnap_ = info->getSnapshotManager()->getCurrentSnapshot(); |
503 | > | // total exchange sums are zeroed out at the beginning: |
504 | > | |
505 | > | kineticExchange_ = 0.0; |
506 | > | momentumExchange_ = V3Zero; |
507 | > | angularMomentumExchange_ = V3Zero; |
508 | > | |
509 | > | std::ostringstream selectionAstream; |
510 | > | std::ostringstream selectionBstream; |
511 | > | |
512 | > | if (hasSelectionA_) { |
513 | > | selectionA_ = rnemdParams->getSelectionA(); |
514 | > | } else { |
515 | > | if (usePeriodicBoundaryConditions_) { |
516 | > | Mat3x3d hmat = currentSnap_->getHmat(); |
517 | > | |
518 | > | if (hasSlabWidth) |
519 | > | slabWidth_ = rnemdParams->getSlabWidth(); |
520 | > | else |
521 | > | slabWidth_ = hmat(2,2) / 10.0; |
522 | > | |
523 | > | if (hasSlabACenter) |
524 | > | slabACenter_ = rnemdParams->getSlabACenter(); |
525 | > | else |
526 | > | slabACenter_ = 0.0; |
527 | > | |
528 | > | selectionAstream << "select wrappedz > " |
529 | > | << slabACenter_ - 0.5*slabWidth_ |
530 | > | << " && wrappedz < " |
531 | > | << slabACenter_ + 0.5*slabWidth_; |
532 | > | selectionA_ = selectionAstream.str(); |
533 | > | } else { |
534 | > | if (hasSphereARadius) |
535 | > | sphereARadius_ = rnemdParams->getSphereARadius(); |
536 | > | else { |
537 | > | // use an initial guess to the size of the inner slab to be 1/10 the |
538 | > | // radius of an approximately spherical hull: |
539 | > | Thermo thermo(info); |
540 | > | RealType hVol = thermo.getHullVolume(); |
541 | > | sphereARadius_ = 0.1 * pow((3.0 * hVol / (4.0 * M_PI)), 1.0/3.0); |
542 | > | } |
543 | > | selectionAstream << "select r < " << sphereARadius_; |
544 | > | selectionA_ = selectionAstream.str(); |
545 | > | } |
546 | > | } |
547 | > | |
548 | > | if (hasSelectionB_) { |
549 | > | selectionB_ = rnemdParams->getSelectionB(); |
550 | > | } else { |
551 | > | if (usePeriodicBoundaryConditions_) { |
552 | > | Mat3x3d hmat = currentSnap_->getHmat(); |
553 | > | |
554 | > | if (hasSlabWidth) |
555 | > | slabWidth_ = rnemdParams->getSlabWidth(); |
556 | > | else |
557 | > | slabWidth_ = hmat(2,2) / 10.0; |
558 | > | |
559 | > | if (hasSlabBCenter) |
560 | > | slabBCenter_ = rnemdParams->getSlabBCenter(); |
561 | > | else |
562 | > | slabBCenter_ = hmat(2,2) / 2.0; |
563 | > | |
564 | > | selectionBstream << "select wrappedz > " |
565 | > | << slabBCenter_ - 0.5*slabWidth_ |
566 | > | << " && wrappedz < " |
567 | > | << slabBCenter_ + 0.5*slabWidth_; |
568 | > | selectionB_ = selectionBstream.str(); |
569 | > | } else { |
570 | > | if (hasSphereBRadius_) { |
571 | > | sphereBRadius_ = rnemdParams->getSphereBRadius(); |
572 | > | selectionBstream << "select r > " << sphereBRadius_; |
573 | > | selectionB_ = selectionBstream.str(); |
574 | > | } else { |
575 | > | selectionB_ = "select hull"; |
576 | > | hasSelectionB_ = true; |
577 | > | } |
578 | > | } |
579 | > | } |
580 | > | } |
581 | > | |
582 | > | // object evaluator: |
583 | > | evaluator_.loadScriptString(rnemdObjectSelection_); |
584 | > | seleMan_.setSelectionSet(evaluator_.evaluate()); |
585 | > | evaluatorA_.loadScriptString(selectionA_); |
586 | > | evaluatorB_.loadScriptString(selectionB_); |
587 | > | seleManA_.setSelectionSet(evaluatorA_.evaluate()); |
588 | > | seleManB_.setSelectionSet(evaluatorB_.evaluate()); |
589 | > | commonA_ = seleManA_ & seleMan_; |
590 | > | commonB_ = seleManB_ & seleMan_; |
591 | } | |
592 | ||
287 | – | RNEMD::~RNEMD() { |
288 | – | delete randNumGen_; |
593 | ||
594 | + | RNEMD::~RNEMD() { |
595 | + | if (!doRNEMD_) return; |
596 | #ifdef IS_MPI | |
597 | if (worldRank == 0) { | |
598 | #endif | |
293 | – | |
294 | – | sprintf(painCave.errMsg, |
295 | – | "RNEMD: total failed trials: %d\n", |
296 | – | failTrialCount_); |
297 | – | painCave.isFatal = 0; |
298 | – | painCave.severity = OPENMD_INFO; |
299 | – | simError(); |
599 | ||
600 | < | if (outputTemp_) tempLog_.close(); |
302 | < | if (outputVx_) vxzLog_.close(); |
303 | < | if (outputVy_) vyzLog_.close(); |
600 | > | writeOutputFile(); |
601 | ||
602 | < | if (rnemdType_ == rnemdKineticScale || rnemdType_ == rnemdPxScale || |
603 | < | rnemdType_ == rnemdPyScale) { |
307 | < | sprintf(painCave.errMsg, |
308 | < | "RNEMD: total root-checking warnings: %d\n", |
309 | < | failRootCount_); |
310 | < | painCave.isFatal = 0; |
311 | < | painCave.severity = OPENMD_INFO; |
312 | < | simError(); |
313 | < | } |
314 | < | if (output3DTemp_) { |
315 | < | xTempLog_.close(); |
316 | < | yTempLog_.close(); |
317 | < | zTempLog_.close(); |
318 | < | } |
319 | < | if (outputRotTemp_) rotTempLog_.close(); |
320 | < | |
602 | > | rnemdFile_.close(); |
603 | > | |
604 | #ifdef IS_MPI | |
605 | } | |
606 | #endif | |
607 | + | |
608 | + | // delete all of the objects we created: |
609 | + | delete areaAccumulator_; |
610 | + | data_.clear(); |
611 | } | |
612 | + | |
613 | + | void RNEMD::doSwap(SelectionManager& smanA, SelectionManager& smanB) { |
614 | + | if (!doRNEMD_) return; |
615 | + | int selei; |
616 | + | int selej; |
617 | ||
326 | – | void RNEMD::doSwap() { |
327 | – | |
618 | Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); | |
619 | Mat3x3d hmat = currentSnap_->getHmat(); | |
620 | ||
331 | – | seleMan_.setSelectionSet(evaluator_.evaluate()); |
332 | – | |
333 | – | int selei; |
621 | StuntDouble* sd; | |
335 | – | int idx; |
622 | ||
623 | RealType min_val; | |
624 | bool min_found = false; | |
# | Line 342 | Line 628 | namespace OpenMD { | |
628 | bool max_found = false; | |
629 | StuntDouble* max_sd; | |
630 | ||
631 | < | for (sd = seleMan_.beginSelected(selei); sd != NULL; |
632 | < | sd = seleMan_.nextSelected(selei)) { |
631 | > | for (sd = seleManA_.beginSelected(selei); sd != NULL; |
632 | > | sd = seleManA_.nextSelected(selei)) { |
633 | ||
348 | – | idx = sd->getLocalIndex(); |
349 | – | |
634 | Vector3d pos = sd->getPos(); | |
635 | < | |
635 | > | |
636 | // wrap the stuntdouble's position back into the box: | |
637 | < | |
637 | > | |
638 | if (usePeriodicBoundaryConditions_) | |
639 | currentSnap_->wrapVector(pos); | |
640 | < | |
641 | < | // which bin is this stuntdouble in? |
642 | < | // wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)] |
643 | < | |
644 | < | int binNo = int(nBins_ * (pos.z() / hmat(2,2) + zShift_ + 0.5)) % nBins_; |
645 | < | |
646 | < | |
363 | < | // if we're in bin 0 or the middleBin |
364 | < | if (binNo == 0 || binNo == midBin_) { |
640 | > | |
641 | > | RealType mass = sd->getMass(); |
642 | > | Vector3d vel = sd->getVel(); |
643 | > | RealType value; |
644 | > | |
645 | > | switch(rnemdFluxType_) { |
646 | > | case rnemdKE : |
647 | ||
648 | < | RealType mass = sd->getMass(); |
649 | < | Vector3d vel = sd->getVel(); |
650 | < | RealType value; |
651 | < | |
652 | < | switch(rnemdType_) { |
371 | < | case rnemdKineticSwap : |
648 | > | value = mass * vel.lengthSquare(); |
649 | > | |
650 | > | if (sd->isDirectional()) { |
651 | > | Vector3d angMom = sd->getJ(); |
652 | > | Mat3x3d I = sd->getI(); |
653 | ||
654 | < | value = mass * vel.lengthSquare(); |
655 | < | |
656 | < | if (sd->isDirectional()) { |
657 | < | Vector3d angMom = sd->getJ(); |
658 | < | Mat3x3d I = sd->getI(); |
659 | < | |
660 | < | if (sd->isLinear()) { |
661 | < | int i = sd->linearAxis(); |
662 | < | int j = (i + 1) % 3; |
663 | < | int k = (i + 2) % 3; |
664 | < | value += angMom[j] * angMom[j] / I(j, j) + |
665 | < | angMom[k] * angMom[k] / I(k, k); |
666 | < | } else { |
667 | < | value += angMom[0]*angMom[0]/I(0, 0) |
668 | < | + angMom[1]*angMom[1]/I(1, 1) |
669 | < | + angMom[2]*angMom[2]/I(2, 2); |
670 | < | } |
671 | < | } //angular momenta exchange enabled |
672 | < | //energyConvert temporarily disabled |
673 | < | //make exchangeSum_ comparable between swap & scale |
674 | < | //value = value * 0.5 / PhysicalConstants::energyConvert; |
675 | < | value *= 0.5; |
676 | < | break; |
677 | < | case rnemdPx : |
678 | < | value = mass * vel[0]; |
679 | < | break; |
680 | < | case rnemdPy : |
681 | < | value = mass * vel[1]; |
682 | < | break; |
683 | < | case rnemdPz : |
684 | < | value = mass * vel[2]; |
685 | < | break; |
686 | < | default : |
687 | < | break; |
654 | > | if (sd->isLinear()) { |
655 | > | int i = sd->linearAxis(); |
656 | > | int j = (i + 1) % 3; |
657 | > | int k = (i + 2) % 3; |
658 | > | value += angMom[j] * angMom[j] / I(j, j) + |
659 | > | angMom[k] * angMom[k] / I(k, k); |
660 | > | } else { |
661 | > | value += angMom[0]*angMom[0]/I(0, 0) |
662 | > | + angMom[1]*angMom[1]/I(1, 1) |
663 | > | + angMom[2]*angMom[2]/I(2, 2); |
664 | > | } |
665 | > | } //angular momenta exchange enabled |
666 | > | value *= 0.5; |
667 | > | break; |
668 | > | case rnemdPx : |
669 | > | value = mass * vel[0]; |
670 | > | break; |
671 | > | case rnemdPy : |
672 | > | value = mass * vel[1]; |
673 | > | break; |
674 | > | case rnemdPz : |
675 | > | value = mass * vel[2]; |
676 | > | break; |
677 | > | default : |
678 | > | break; |
679 | > | } |
680 | > | if (!max_found) { |
681 | > | max_val = value; |
682 | > | max_sd = sd; |
683 | > | max_found = true; |
684 | > | } else { |
685 | > | if (max_val < value) { |
686 | > | max_val = value; |
687 | > | max_sd = sd; |
688 | } | |
689 | + | } |
690 | + | } |
691 | ||
692 | < | if (binNo == 0) { |
693 | < | if (!min_found) { |
694 | < | min_val = value; |
695 | < | min_sd = sd; |
696 | < | min_found = true; |
697 | < | } else { |
698 | < | if (min_val > value) { |
699 | < | min_val = value; |
700 | < | min_sd = sd; |
701 | < | } |
702 | < | } |
703 | < | } else { //midBin_ |
704 | < | if (!max_found) { |
705 | < | max_val = value; |
706 | < | max_sd = sd; |
707 | < | max_found = true; |
708 | < | } else { |
709 | < | if (max_val < value) { |
710 | < | max_val = value; |
711 | < | max_sd = sd; |
712 | < | } |
713 | < | } |
714 | < | } |
692 | > | for (sd = seleManB_.beginSelected(selej); sd != NULL; |
693 | > | sd = seleManB_.nextSelected(selej)) { |
694 | > | |
695 | > | Vector3d pos = sd->getPos(); |
696 | > | |
697 | > | // wrap the stuntdouble's position back into the box: |
698 | > | |
699 | > | if (usePeriodicBoundaryConditions_) |
700 | > | currentSnap_->wrapVector(pos); |
701 | > | |
702 | > | RealType mass = sd->getMass(); |
703 | > | Vector3d vel = sd->getVel(); |
704 | > | RealType value; |
705 | > | |
706 | > | switch(rnemdFluxType_) { |
707 | > | case rnemdKE : |
708 | > | |
709 | > | value = mass * vel.lengthSquare(); |
710 | > | |
711 | > | if (sd->isDirectional()) { |
712 | > | Vector3d angMom = sd->getJ(); |
713 | > | Mat3x3d I = sd->getI(); |
714 | > | |
715 | > | if (sd->isLinear()) { |
716 | > | int i = sd->linearAxis(); |
717 | > | int j = (i + 1) % 3; |
718 | > | int k = (i + 2) % 3; |
719 | > | value += angMom[j] * angMom[j] / I(j, j) + |
720 | > | angMom[k] * angMom[k] / I(k, k); |
721 | > | } else { |
722 | > | value += angMom[0]*angMom[0]/I(0, 0) |
723 | > | + angMom[1]*angMom[1]/I(1, 1) |
724 | > | + angMom[2]*angMom[2]/I(2, 2); |
725 | > | } |
726 | > | } //angular momenta exchange enabled |
727 | > | value *= 0.5; |
728 | > | break; |
729 | > | case rnemdPx : |
730 | > | value = mass * vel[0]; |
731 | > | break; |
732 | > | case rnemdPy : |
733 | > | value = mass * vel[1]; |
734 | > | break; |
735 | > | case rnemdPz : |
736 | > | value = mass * vel[2]; |
737 | > | break; |
738 | > | default : |
739 | > | break; |
740 | } | |
741 | + | |
742 | + | if (!min_found) { |
743 | + | min_val = value; |
744 | + | min_sd = sd; |
745 | + | min_found = true; |
746 | + | } else { |
747 | + | if (min_val > value) { |
748 | + | min_val = value; |
749 | + | min_sd = sd; |
750 | + | } |
751 | + | } |
752 | } | |
753 | < | |
754 | < | #ifdef IS_MPI |
755 | < | int nProc, worldRank; |
756 | < | |
438 | < | nProc = MPI::COMM_WORLD.Get_size(); |
439 | < | worldRank = MPI::COMM_WORLD.Get_rank(); |
440 | < | |
753 | > | |
754 | > | #ifdef IS_MPI |
755 | > | int worldRank = MPI::COMM_WORLD.Get_rank(); |
756 | > | |
757 | bool my_min_found = min_found; | |
758 | bool my_max_found = max_found; | |
759 | ||
# | Line 454 | Line 770 | namespace OpenMD { | |
770 | RealType val; | |
771 | int rank; | |
772 | } max_vals, min_vals; | |
773 | < | |
773 | > | |
774 | if (my_min_found) { | |
775 | min_vals.val = min_val; | |
776 | } else { | |
# | Line 492 | Line 808 | namespace OpenMD { | |
808 | Vector3d max_vel = max_sd->getVel(); | |
809 | RealType temp_vel; | |
810 | ||
811 | < | switch(rnemdType_) { |
812 | < | case rnemdKineticSwap : |
811 | > | switch(rnemdFluxType_) { |
812 | > | case rnemdKE : |
813 | min_sd->setVel(max_vel); | |
814 | max_sd->setVel(min_vel); | |
815 | if (min_sd->isDirectional() && max_sd->isDirectional()) { | |
# | Line 544 | Line 860 | namespace OpenMD { | |
860 | min_vel.getArrayPointer(), 3, MPI::REALTYPE, | |
861 | min_vals.rank, 0, status); | |
862 | ||
863 | < | switch(rnemdType_) { |
864 | < | case rnemdKineticSwap : |
863 | > | switch(rnemdFluxType_) { |
864 | > | case rnemdKE : |
865 | max_sd->setVel(min_vel); | |
866 | //angular momenta exchange enabled | |
867 | if (max_sd->isDirectional()) { | |
# | Line 590 | Line 906 | namespace OpenMD { | |
906 | max_vel.getArrayPointer(), 3, MPI::REALTYPE, | |
907 | max_vals.rank, 0, status); | |
908 | ||
909 | < | switch(rnemdType_) { |
910 | < | case rnemdKineticSwap : |
909 | > | switch(rnemdFluxType_) { |
910 | > | case rnemdKE : |
911 | min_sd->setVel(max_vel); | |
912 | //angular momenta exchange enabled | |
913 | if (min_sd->isDirectional()) { | |
# | Line 625 | Line 941 | namespace OpenMD { | |
941 | } | |
942 | } | |
943 | #endif | |
944 | < | exchangeSum_ += max_val - min_val; |
944 | > | |
945 | > | switch(rnemdFluxType_) { |
946 | > | case rnemdKE: |
947 | > | kineticExchange_ += max_val - min_val; |
948 | > | break; |
949 | > | case rnemdPx: |
950 | > | momentumExchange_.x() += max_val - min_val; |
951 | > | break; |
952 | > | case rnemdPy: |
953 | > | momentumExchange_.y() += max_val - min_val; |
954 | > | break; |
955 | > | case rnemdPz: |
956 | > | momentumExchange_.z() += max_val - min_val; |
957 | > | break; |
958 | > | default: |
959 | > | break; |
960 | > | } |
961 | } else { | |
962 | sprintf(painCave.errMsg, | |
963 | < | "RNEMD: exchange NOT performed because min_val > max_val\n"); |
963 | > | "RNEMD::doSwap exchange NOT performed because min_val > max_val\n"); |
964 | painCave.isFatal = 0; | |
965 | painCave.severity = OPENMD_INFO; | |
966 | simError(); | |
# | Line 636 | Line 968 | namespace OpenMD { | |
968 | } | |
969 | } else { | |
970 | sprintf(painCave.errMsg, | |
971 | < | "RNEMD: exchange NOT performed because selected object\n" |
972 | < | "\tnot present in at least one of the two slabs.\n"); |
971 | > | "RNEMD::doSwap exchange NOT performed because selected object\n" |
972 | > | "\twas not present in at least one of the two slabs.\n"); |
973 | painCave.isFatal = 0; | |
974 | painCave.severity = OPENMD_INFO; | |
975 | simError(); | |
976 | failTrialCount_++; | |
977 | < | } |
646 | < | |
977 | > | } |
978 | } | |
979 | ||
980 | < | void RNEMD::doScale() { |
980 | > | void RNEMD::doNIVS(SelectionManager& smanA, SelectionManager& smanB) { |
981 | > | if (!doRNEMD_) return; |
982 | > | int selei; |
983 | > | int selej; |
984 | ||
985 | Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); | |
986 | + | RealType time = currentSnap_->getTime(); |
987 | Mat3x3d hmat = currentSnap_->getHmat(); | |
988 | ||
654 | – | seleMan_.setSelectionSet(evaluator_.evaluate()); |
655 | – | |
656 | – | int selei; |
989 | StuntDouble* sd; | |
658 | – | int idx; |
990 | ||
991 | vector<StuntDouble*> hotBin, coldBin; | |
992 | ||
# | Line 674 | Line 1005 | namespace OpenMD { | |
1005 | RealType Kcz = 0.0; | |
1006 | RealType Kcw = 0.0; | |
1007 | ||
1008 | < | for (sd = seleMan_.beginSelected(selei); sd != NULL; |
1009 | < | sd = seleMan_.nextSelected(selei)) { |
1008 | > | for (sd = smanA.beginSelected(selei); sd != NULL; |
1009 | > | sd = smanA.nextSelected(selei)) { |
1010 | ||
680 | – | idx = sd->getLocalIndex(); |
681 | – | |
1011 | Vector3d pos = sd->getPos(); | |
1012 | < | |
1012 | > | |
1013 | // wrap the stuntdouble's position back into the box: | |
1014 | < | |
1014 | > | |
1015 | if (usePeriodicBoundaryConditions_) | |
1016 | currentSnap_->wrapVector(pos); | |
1017 | < | |
1018 | < | // which bin is this stuntdouble in? |
1019 | < | // wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)] |
1020 | < | |
1021 | < | int binNo = int(nBins_ * (pos.z() / hmat(2,2) + zShift_ + 0.5)) % nBins_; |
1022 | < | |
1023 | < | // if we're in bin 0 or the middleBin |
1024 | < | if (binNo == 0 || binNo == midBin_) { |
1025 | < | |
1026 | < | RealType mass = sd->getMass(); |
1027 | < | Vector3d vel = sd->getVel(); |
1028 | < | |
1029 | < | if (binNo == 0) { |
1030 | < | hotBin.push_back(sd); |
1031 | < | Phx += mass * vel.x(); |
1032 | < | Phy += mass * vel.y(); |
1033 | < | Phz += mass * vel.z(); |
1034 | < | Khx += mass * vel.x() * vel.x(); |
1035 | < | Khy += mass * vel.y() * vel.y(); |
1036 | < | Khz += mass * vel.z() * vel.z(); |
1037 | < | //if (rnemdType_ == rnemdKineticScaleVAM) { |
1038 | < | if (sd->isDirectional()) { |
1039 | < | Vector3d angMom = sd->getJ(); |
1040 | < | Mat3x3d I = sd->getI(); |
1041 | < | if (sd->isLinear()) { |
1042 | < | int i = sd->linearAxis(); |
1043 | < | int j = (i + 1) % 3; |
1044 | < | int k = (i + 2) % 3; |
1045 | < | Khw += angMom[j] * angMom[j] / I(j, j) + |
1046 | < | angMom[k] * angMom[k] / I(k, k); |
1047 | < | } else { |
1048 | < | Khw += angMom[0]*angMom[0]/I(0, 0) |
1049 | < | + angMom[1]*angMom[1]/I(1, 1) |
1050 | < | + angMom[2]*angMom[2]/I(2, 2); |
1051 | < | } |
1052 | < | } |
1053 | < | //} |
1054 | < | } else { //midBin_ |
1055 | < | coldBin.push_back(sd); |
1056 | < | Pcx += mass * vel.x(); |
1057 | < | Pcy += mass * vel.y(); |
1058 | < | Pcz += mass * vel.z(); |
1059 | < | Kcx += mass * vel.x() * vel.x(); |
1060 | < | Kcy += mass * vel.y() * vel.y(); |
1061 | < | Kcz += mass * vel.z() * vel.z(); |
1062 | < | //if (rnemdType_ == rnemdKineticScaleVAM) { |
1063 | < | if (sd->isDirectional()) { |
1064 | < | Vector3d angMom = sd->getJ(); |
1065 | < | Mat3x3d I = sd->getI(); |
1066 | < | if (sd->isLinear()) { |
1067 | < | int i = sd->linearAxis(); |
1068 | < | int j = (i + 1) % 3; |
1069 | < | int k = (i + 2) % 3; |
1070 | < | Kcw += angMom[j] * angMom[j] / I(j, j) + |
1071 | < | angMom[k] * angMom[k] / I(k, k); |
1072 | < | } else { |
1073 | < | Kcw += angMom[0]*angMom[0]/I(0, 0) |
1074 | < | + angMom[1]*angMom[1]/I(1, 1) |
1075 | < | + angMom[2]*angMom[2]/I(2, 2); |
1076 | < | } |
1077 | < | } |
749 | < | //} |
750 | < | } |
1017 | > | |
1018 | > | |
1019 | > | RealType mass = sd->getMass(); |
1020 | > | Vector3d vel = sd->getVel(); |
1021 | > | |
1022 | > | hotBin.push_back(sd); |
1023 | > | Phx += mass * vel.x(); |
1024 | > | Phy += mass * vel.y(); |
1025 | > | Phz += mass * vel.z(); |
1026 | > | Khx += mass * vel.x() * vel.x(); |
1027 | > | Khy += mass * vel.y() * vel.y(); |
1028 | > | Khz += mass * vel.z() * vel.z(); |
1029 | > | if (sd->isDirectional()) { |
1030 | > | Vector3d angMom = sd->getJ(); |
1031 | > | Mat3x3d I = sd->getI(); |
1032 | > | if (sd->isLinear()) { |
1033 | > | int i = sd->linearAxis(); |
1034 | > | int j = (i + 1) % 3; |
1035 | > | int k = (i + 2) % 3; |
1036 | > | Khw += angMom[j] * angMom[j] / I(j, j) + |
1037 | > | angMom[k] * angMom[k] / I(k, k); |
1038 | > | } else { |
1039 | > | Khw += angMom[0]*angMom[0]/I(0, 0) |
1040 | > | + angMom[1]*angMom[1]/I(1, 1) |
1041 | > | + angMom[2]*angMom[2]/I(2, 2); |
1042 | > | } |
1043 | > | } |
1044 | > | } |
1045 | > | for (sd = smanB.beginSelected(selej); sd != NULL; |
1046 | > | sd = smanB.nextSelected(selej)) { |
1047 | > | Vector3d pos = sd->getPos(); |
1048 | > | |
1049 | > | // wrap the stuntdouble's position back into the box: |
1050 | > | |
1051 | > | if (usePeriodicBoundaryConditions_) |
1052 | > | currentSnap_->wrapVector(pos); |
1053 | > | |
1054 | > | RealType mass = sd->getMass(); |
1055 | > | Vector3d vel = sd->getVel(); |
1056 | > | |
1057 | > | coldBin.push_back(sd); |
1058 | > | Pcx += mass * vel.x(); |
1059 | > | Pcy += mass * vel.y(); |
1060 | > | Pcz += mass * vel.z(); |
1061 | > | Kcx += mass * vel.x() * vel.x(); |
1062 | > | Kcy += mass * vel.y() * vel.y(); |
1063 | > | Kcz += mass * vel.z() * vel.z(); |
1064 | > | if (sd->isDirectional()) { |
1065 | > | Vector3d angMom = sd->getJ(); |
1066 | > | Mat3x3d I = sd->getI(); |
1067 | > | if (sd->isLinear()) { |
1068 | > | int i = sd->linearAxis(); |
1069 | > | int j = (i + 1) % 3; |
1070 | > | int k = (i + 2) % 3; |
1071 | > | Kcw += angMom[j] * angMom[j] / I(j, j) + |
1072 | > | angMom[k] * angMom[k] / I(k, k); |
1073 | > | } else { |
1074 | > | Kcw += angMom[0]*angMom[0]/I(0, 0) |
1075 | > | + angMom[1]*angMom[1]/I(1, 1) |
1076 | > | + angMom[2]*angMom[2]/I(2, 2); |
1077 | > | } |
1078 | } | |
1079 | } | |
1080 | ||
# | Line 760 | Line 1087 | namespace OpenMD { | |
1087 | Kcz *= 0.5; | |
1088 | Kcw *= 0.5; | |
1089 | ||
763 | – | std::cerr << "Khx= " << Khx << "\tKhy= " << Khy << "\tKhz= " << Khz |
764 | – | << "\tKhw= " << Khw << "\tKcx= " << Kcx << "\tKcy= " << Kcy |
765 | – | << "\tKcz= " << Kcz << "\tKcw= " << Kcw << "\n"; |
766 | – | std::cerr << "Phx= " << Phx << "\tPhy= " << Phy << "\tPhz= " << Phz |
767 | – | << "\tPcx= " << Pcx << "\tPcy= " << Pcy << "\tPcz= " <<Pcz<<"\n"; |
768 | – | |
1090 | #ifdef IS_MPI | |
1091 | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Phx, 1, MPI::REALTYPE, MPI::SUM); | |
1092 | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Phy, 1, MPI::REALTYPE, MPI::SUM); | |
# | Line 791 | Line 1112 | namespace OpenMD { | |
1112 | RealType pz = Pcz / Phz; | |
1113 | RealType c, x, y, z; | |
1114 | bool successfulScale = false; | |
1115 | < | if ((rnemdType_ == rnemdKineticScaleVAM) || |
1116 | < | (rnemdType_ == rnemdKineticScaleAM)) { |
1115 | > | if ((rnemdFluxType_ == rnemdFullKE) || |
1116 | > | (rnemdFluxType_ == rnemdRotKE)) { |
1117 | //may need sanity check Khw & Kcw > 0 | |
1118 | ||
1119 | < | if (rnemdType_ == rnemdKineticScaleVAM) { |
1120 | < | c = 1.0 - targetFlux_ / (Kcx + Kcy + Kcz + Kcw); |
1119 | > | if (rnemdFluxType_ == rnemdFullKE) { |
1120 | > | c = 1.0 - kineticTarget_ / (Kcx + Kcy + Kcz + Kcw); |
1121 | } else { | |
1122 | < | c = 1.0 - targetFlux_ / Kcw; |
1122 | > | c = 1.0 - kineticTarget_ / Kcw; |
1123 | } | |
1124 | ||
1125 | if ((c > 0.81) && (c < 1.21)) {//restrict scaling coefficients | |
1126 | c = sqrt(c); | |
1127 | < | std::cerr << "cold slab scaling coefficient: " << c << endl; |
807 | < | //now convert to hotBin coefficient |
1127 | > | |
1128 | RealType w = 0.0; | |
1129 | < | if (rnemdType_ == rnemdKineticScaleVAM) { |
1129 | > | if (rnemdFluxType_ == rnemdFullKE) { |
1130 | x = 1.0 + px * (1.0 - c); | |
1131 | y = 1.0 + py * (1.0 - c); | |
1132 | z = 1.0 + pz * (1.0 - c); | |
# | Line 820 | Line 1140 | namespace OpenMD { | |
1140 | */ | |
1141 | if ((fabs(x - 1.0) < 0.1) && (fabs(y - 1.0) < 0.1) && | |
1142 | (fabs(z - 1.0) < 0.1)) { | |
1143 | < | w = 1.0 + (targetFlux_ + Khx * (1.0 - x * x) + Khy * (1.0 - y * y) |
1143 | > | w = 1.0 + (kineticTarget_ |
1144 | > | + Khx * (1.0 - x * x) + Khy * (1.0 - y * y) |
1145 | + Khz * (1.0 - z * z)) / Khw; | |
1146 | }//no need to calculate w if x, y or z is out of range | |
1147 | } else { | |
1148 | < | w = 1.0 + targetFlux_ / Khw; |
1148 | > | w = 1.0 + kineticTarget_ / Khw; |
1149 | } | |
1150 | if ((w > 0.81) && (w < 1.21)) {//restrict scaling coefficients | |
1151 | //if w is in the right range, so should be x, y, z. | |
1152 | vector<StuntDouble*>::iterator sdi; | |
1153 | Vector3d vel; | |
1154 | < | for (sdi = coldBin.begin(); sdi != coldBin.end(); sdi++) { |
1155 | < | if (rnemdType_ == rnemdKineticScaleVAM) { |
1154 | > | for (sdi = coldBin.begin(); sdi != coldBin.end(); ++sdi) { |
1155 | > | if (rnemdFluxType_ == rnemdFullKE) { |
1156 | vel = (*sdi)->getVel() * c; | |
836 | – | //vel.x() *= c; |
837 | – | //vel.y() *= c; |
838 | – | //vel.z() *= c; |
1157 | (*sdi)->setVel(vel); | |
1158 | } | |
1159 | if ((*sdi)->isDirectional()) { | |
1160 | Vector3d angMom = (*sdi)->getJ() * c; | |
843 | – | //angMom[0] *= c; |
844 | – | //angMom[1] *= c; |
845 | – | //angMom[2] *= c; |
1161 | (*sdi)->setJ(angMom); | |
1162 | } | |
1163 | } | |
1164 | w = sqrt(w); | |
1165 | < | std::cerr << "xh= " << x << "\tyh= " << y << "\tzh= " << z |
1166 | < | << "\twh= " << w << endl; |
852 | < | for (sdi = hotBin.begin(); sdi != hotBin.end(); sdi++) { |
853 | < | if (rnemdType_ == rnemdKineticScaleVAM) { |
1165 | > | for (sdi = hotBin.begin(); sdi != hotBin.end(); ++sdi) { |
1166 | > | if (rnemdFluxType_ == rnemdFullKE) { |
1167 | vel = (*sdi)->getVel(); | |
1168 | vel.x() *= x; | |
1169 | vel.y() *= y; | |
# | Line 859 | Line 1172 | namespace OpenMD { | |
1172 | } | |
1173 | if ((*sdi)->isDirectional()) { | |
1174 | Vector3d angMom = (*sdi)->getJ() * w; | |
862 | – | //angMom[0] *= w; |
863 | – | //angMom[1] *= w; |
864 | – | //angMom[2] *= w; |
1175 | (*sdi)->setJ(angMom); | |
1176 | } | |
1177 | } | |
1178 | successfulScale = true; | |
1179 | < | exchangeSum_ += targetFlux_; |
1179 | > | kineticExchange_ += kineticTarget_; |
1180 | } | |
1181 | } | |
1182 | } else { | |
1183 | RealType a000, a110, c0, a001, a111, b01, b11, c1; | |
1184 | < | switch(rnemdType_) { |
1185 | < | case rnemdKineticScale : |
1184 | > | switch(rnemdFluxType_) { |
1185 | > | case rnemdKE : |
1186 | /* used hotBin coeff's & only scale x & y dimensions | |
1187 | RealType px = Phx / Pcx; | |
1188 | RealType py = Phy / Pcy; | |
1189 | a110 = Khy; | |
1190 | < | c0 = - Khx - Khy - targetFlux_; |
1190 | > | c0 = - Khx - Khy - kineticTarget_; |
1191 | a000 = Khx; | |
1192 | a111 = Kcy * py * py; | |
1193 | b11 = -2.0 * Kcy * py * (1.0 + py); | |
1194 | < | c1 = Kcy * py * (2.0 + py) + Kcx * px * ( 2.0 + px) + targetFlux_; |
1194 | > | c1 = Kcy * py * (2.0 + py) + Kcx * px * ( 2.0 + px) + kineticTarget_; |
1195 | b01 = -2.0 * Kcx * px * (1.0 + px); | |
1196 | a001 = Kcx * px * px; | |
1197 | */ | |
1198 | //scale all three dimensions, let c_x = c_y | |
1199 | a000 = Kcx + Kcy; | |
1200 | a110 = Kcz; | |
1201 | < | c0 = targetFlux_ - Kcx - Kcy - Kcz; |
1201 | > | c0 = kineticTarget_ - Kcx - Kcy - Kcz; |
1202 | a001 = Khx * px * px + Khy * py * py; | |
1203 | a111 = Khz * pz * pz; | |
1204 | b01 = -2.0 * (Khx * px * (1.0 + px) + Khy * py * (1.0 + py)); | |
1205 | b11 = -2.0 * Khz * pz * (1.0 + pz); | |
1206 | c1 = Khx * px * (2.0 + px) + Khy * py * (2.0 + py) | |
1207 | < | + Khz * pz * (2.0 + pz) - targetFlux_; |
1207 | > | + Khz * pz * (2.0 + pz) - kineticTarget_; |
1208 | break; | |
1209 | < | case rnemdPxScale : |
1210 | < | c = 1 - targetFlux_ / Pcx; |
1209 | > | case rnemdPx : |
1210 | > | c = 1 - momentumTarget_.x() / Pcx; |
1211 | a000 = Kcy; | |
1212 | a110 = Kcz; | |
1213 | c0 = Kcx * c * c - Kcx - Kcy - Kcz; | |
# | Line 908 | Line 1218 | namespace OpenMD { | |
1218 | c1 = Khy * py * (2.0 + py) + Khz * pz * (2.0 + pz) | |
1219 | + Khx * (fastpow(c * px - px - 1.0, 2) - 1.0); | |
1220 | break; | |
1221 | < | case rnemdPyScale : |
1222 | < | c = 1 - targetFlux_ / Pcy; |
1221 | > | case rnemdPy : |
1222 | > | c = 1 - momentumTarget_.y() / Pcy; |
1223 | a000 = Kcx; | |
1224 | a110 = Kcz; | |
1225 | c0 = Kcy * c * c - Kcx - Kcy - Kcz; | |
# | Line 920 | Line 1230 | namespace OpenMD { | |
1230 | c1 = Khx * px * (2.0 + px) + Khz * pz * (2.0 + pz) | |
1231 | + Khy * (fastpow(c * py - py - 1.0, 2) - 1.0); | |
1232 | break; | |
1233 | < | case rnemdPzScale ://we don't really do this, do we? |
1234 | < | c = 1 - targetFlux_ / Pcz; |
1233 | > | case rnemdPz ://we don't really do this, do we? |
1234 | > | c = 1 - momentumTarget_.z() / Pcz; |
1235 | a000 = Kcx; | |
1236 | a110 = Kcy; | |
1237 | c0 = Kcz * c * c - Kcx - Kcy - Kcz; | |
# | Line 971 | Line 1281 | namespace OpenMD { | |
1281 | vector<RealType>::iterator ri; | |
1282 | RealType r1, r2, alpha0; | |
1283 | vector<pair<RealType,RealType> > rps; | |
1284 | < | for (ri = realRoots.begin(); ri !=realRoots.end(); ri++) { |
1284 | > | for (ri = realRoots.begin(); ri !=realRoots.end(); ++ri) { |
1285 | r2 = *ri; | |
1286 | //check if FindRealRoots() give the right answer | |
1287 | if ( fabs(u0 + r2 * (u1 + r2 * (u2 + r2 * (u3 + r2 * u4)))) > 1e-6 ) { | |
# | Line 1003 | Line 1313 | namespace OpenMD { | |
1313 | RealType diff; | |
1314 | pair<RealType,RealType> bestPair = make_pair(1.0, 1.0); | |
1315 | vector<pair<RealType,RealType> >::iterator rpi; | |
1316 | < | for (rpi = rps.begin(); rpi != rps.end(); rpi++) { |
1316 | > | for (rpi = rps.begin(); rpi != rps.end(); ++rpi) { |
1317 | r1 = (*rpi).first; | |
1318 | r2 = (*rpi).second; | |
1319 | < | switch(rnemdType_) { |
1320 | < | case rnemdKineticScale : |
1319 | > | switch(rnemdFluxType_) { |
1320 | > | case rnemdKE : |
1321 | diff = fastpow(1.0 - r1, 2) + fastpow(1.0 - r2, 2) | |
1322 | + fastpow(r1 * r1 / r2 / r2 - Kcz/Kcx, 2) | |
1323 | + fastpow(r1 * r1 / r2 / r2 - Kcz/Kcy, 2); | |
1324 | break; | |
1325 | < | case rnemdPxScale : |
1325 | > | case rnemdPx : |
1326 | diff = fastpow(1.0 - r1, 2) + fastpow(1.0 - r2, 2) | |
1327 | + fastpow(r1 * r1 / r2 / r2 - Kcz/Kcy, 2); | |
1328 | break; | |
1329 | < | case rnemdPyScale : |
1329 | > | case rnemdPy : |
1330 | diff = fastpow(1.0 - r1, 2) + fastpow(1.0 - r2, 2) | |
1331 | + fastpow(r1 * r1 / r2 / r2 - Kcz/Kcx, 2); | |
1332 | break; | |
1333 | < | case rnemdPzScale : |
1333 | > | case rnemdPz : |
1334 | diff = fastpow(1.0 - r1, 2) + fastpow(1.0 - r2, 2) | |
1335 | + fastpow(r1 * r1 / r2 / r2 - Kcy/Kcx, 2); | |
1336 | default : | |
# | Line 1034 | Line 1344 | namespace OpenMD { | |
1344 | #ifdef IS_MPI | |
1345 | if (worldRank == 0) { | |
1346 | #endif | |
1347 | < | sprintf(painCave.errMsg, |
1348 | < | "RNEMD: roots r1= %lf\tr2 = %lf\n", |
1349 | < | bestPair.first, bestPair.second); |
1350 | < | painCave.isFatal = 0; |
1351 | < | painCave.severity = OPENMD_INFO; |
1352 | < | simError(); |
1347 | > | // sprintf(painCave.errMsg, |
1348 | > | // "RNEMD: roots r1= %lf\tr2 = %lf\n", |
1349 | > | // bestPair.first, bestPair.second); |
1350 | > | // painCave.isFatal = 0; |
1351 | > | // painCave.severity = OPENMD_INFO; |
1352 | > | // simError(); |
1353 | #ifdef IS_MPI | |
1354 | } | |
1355 | #endif | |
1356 | ||
1357 | < | switch(rnemdType_) { |
1358 | < | case rnemdKineticScale : |
1357 | > | switch(rnemdFluxType_) { |
1358 | > | case rnemdKE : |
1359 | x = bestPair.first; | |
1360 | y = bestPair.first; | |
1361 | z = bestPair.second; | |
1362 | break; | |
1363 | < | case rnemdPxScale : |
1363 | > | case rnemdPx : |
1364 | x = c; | |
1365 | y = bestPair.first; | |
1366 | z = bestPair.second; | |
1367 | break; | |
1368 | < | case rnemdPyScale : |
1368 | > | case rnemdPy : |
1369 | x = bestPair.first; | |
1370 | y = c; | |
1371 | z = bestPair.second; | |
1372 | break; | |
1373 | < | case rnemdPzScale : |
1373 | > | case rnemdPz : |
1374 | x = bestPair.first; | |
1375 | y = bestPair.second; | |
1376 | z = c; | |
# | Line 1070 | Line 1380 | namespace OpenMD { | |
1380 | } | |
1381 | vector<StuntDouble*>::iterator sdi; | |
1382 | Vector3d vel; | |
1383 | < | for (sdi = coldBin.begin(); sdi != coldBin.end(); sdi++) { |
1383 | > | for (sdi = coldBin.begin(); sdi != coldBin.end(); ++sdi) { |
1384 | vel = (*sdi)->getVel(); | |
1385 | vel.x() *= x; | |
1386 | vel.y() *= y; | |
# | Line 1081 | Line 1391 | namespace OpenMD { | |
1391 | x = 1.0 + px * (1.0 - x); | |
1392 | y = 1.0 + py * (1.0 - y); | |
1393 | z = 1.0 + pz * (1.0 - z); | |
1394 | < | for (sdi = hotBin.begin(); sdi != hotBin.end(); sdi++) { |
1394 | > | for (sdi = hotBin.begin(); sdi != hotBin.end(); ++sdi) { |
1395 | vel = (*sdi)->getVel(); | |
1396 | vel.x() *= x; | |
1397 | vel.y() *= y; | |
# | Line 1089 | Line 1399 | namespace OpenMD { | |
1399 | (*sdi)->setVel(vel); | |
1400 | } | |
1401 | successfulScale = true; | |
1402 | < | exchangeSum_ += targetFlux_; |
1402 | > | switch(rnemdFluxType_) { |
1403 | > | case rnemdKE : |
1404 | > | kineticExchange_ += kineticTarget_; |
1405 | > | break; |
1406 | > | case rnemdPx : |
1407 | > | case rnemdPy : |
1408 | > | case rnemdPz : |
1409 | > | momentumExchange_ += momentumTarget_; |
1410 | > | break; |
1411 | > | default : |
1412 | > | break; |
1413 | > | } |
1414 | } | |
1415 | } | |
1416 | if (successfulScale != true) { | |
1417 | sprintf(painCave.errMsg, | |
1418 | < | "RNEMD: exchange NOT performed!\n"); |
1418 | > | "RNEMD::doNIVS exchange NOT performed - roots that solve\n" |
1419 | > | "\tthe constraint equations may not exist or there may be\n" |
1420 | > | "\tno selected objects in one or both slabs.\n"); |
1421 | painCave.isFatal = 0; | |
1422 | painCave.severity = OPENMD_INFO; | |
1423 | simError(); | |
1424 | failTrialCount_++; | |
1425 | } | |
1426 | } | |
1427 | + | |
1428 | + | void RNEMD::doVSS(SelectionManager& smanA, SelectionManager& smanB) { |
1429 | + | if (!doRNEMD_) return; |
1430 | + | int selei; |
1431 | + | int selej; |
1432 | ||
1105 | – | void RNEMD::doShiftScale() { |
1106 | – | |
1433 | Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); | |
1434 | + | RealType time = currentSnap_->getTime(); |
1435 | Mat3x3d hmat = currentSnap_->getHmat(); | |
1436 | ||
1110 | – | seleMan_.setSelectionSet(evaluator_.evaluate()); |
1111 | – | |
1112 | – | int selei; |
1437 | StuntDouble* sd; | |
1114 | – | int idx; |
1438 | ||
1439 | vector<StuntDouble*> hotBin, coldBin; | |
1440 | ||
1441 | Vector3d Ph(V3Zero); | |
1442 | + | Vector3d Lh(V3Zero); |
1443 | RealType Mh = 0.0; | |
1444 | + | Mat3x3d Ih(0.0); |
1445 | RealType Kh = 0.0; | |
1446 | Vector3d Pc(V3Zero); | |
1447 | + | Vector3d Lc(V3Zero); |
1448 | RealType Mc = 0.0; | |
1449 | + | Mat3x3d Ic(0.0); |
1450 | RealType Kc = 0.0; | |
1451 | ||
1452 | < | for (sd = seleMan_.beginSelected(selei); sd != NULL; |
1453 | < | sd = seleMan_.nextSelected(selei)) { |
1452 | > | // Constraints can be on only the linear or angular momentum, but |
1453 | > | // not both. Usually, the user will specify which they want, but |
1454 | > | // in case they don't, the use of periodic boundaries should make |
1455 | > | // the choice for us. |
1456 | > | bool doLinearPart = false; |
1457 | > | bool doAngularPart = false; |
1458 | ||
1459 | < | idx = sd->getLocalIndex(); |
1459 | > | switch (rnemdFluxType_) { |
1460 | > | case rnemdPx: |
1461 | > | case rnemdPy: |
1462 | > | case rnemdPz: |
1463 | > | case rnemdPvector: |
1464 | > | case rnemdKePx: |
1465 | > | case rnemdKePy: |
1466 | > | case rnemdKePvector: |
1467 | > | doLinearPart = true; |
1468 | > | break; |
1469 | > | case rnemdLx: |
1470 | > | case rnemdLy: |
1471 | > | case rnemdLz: |
1472 | > | case rnemdLvector: |
1473 | > | case rnemdKeLx: |
1474 | > | case rnemdKeLy: |
1475 | > | case rnemdKeLz: |
1476 | > | case rnemdKeLvector: |
1477 | > | doAngularPart = true; |
1478 | > | break; |
1479 | > | case rnemdKE: |
1480 | > | case rnemdRotKE: |
1481 | > | case rnemdFullKE: |
1482 | > | default: |
1483 | > | if (usePeriodicBoundaryConditions_) |
1484 | > | doLinearPart = true; |
1485 | > | else |
1486 | > | doAngularPart = true; |
1487 | > | break; |
1488 | > | } |
1489 | > | |
1490 | > | for (sd = smanA.beginSelected(selei); sd != NULL; |
1491 | > | sd = smanA.nextSelected(selei)) { |
1492 | ||
1493 | Vector3d pos = sd->getPos(); | |
1494 | ||
1495 | // wrap the stuntdouble's position back into the box: | |
1496 | + | |
1497 | + | if (usePeriodicBoundaryConditions_) |
1498 | + | currentSnap_->wrapVector(pos); |
1499 | + | |
1500 | + | RealType mass = sd->getMass(); |
1501 | + | Vector3d vel = sd->getVel(); |
1502 | + | Vector3d rPos = sd->getPos() - coordinateOrigin_; |
1503 | + | RealType r2; |
1504 | + | |
1505 | + | hotBin.push_back(sd); |
1506 | + | Ph += mass * vel; |
1507 | + | Mh += mass; |
1508 | + | Kh += mass * vel.lengthSquare(); |
1509 | + | Lh += mass * cross(rPos, vel); |
1510 | + | Ih -= outProduct(rPos, rPos) * mass; |
1511 | + | r2 = rPos.lengthSquare(); |
1512 | + | Ih(0, 0) += mass * r2; |
1513 | + | Ih(1, 1) += mass * r2; |
1514 | + | Ih(2, 2) += mass * r2; |
1515 | + | |
1516 | + | if (rnemdFluxType_ == rnemdFullKE) { |
1517 | + | if (sd->isDirectional()) { |
1518 | + | Vector3d angMom = sd->getJ(); |
1519 | + | Mat3x3d I = sd->getI(); |
1520 | + | if (sd->isLinear()) { |
1521 | + | int i = sd->linearAxis(); |
1522 | + | int j = (i + 1) % 3; |
1523 | + | int k = (i + 2) % 3; |
1524 | + | Kh += angMom[j] * angMom[j] / I(j, j) + |
1525 | + | angMom[k] * angMom[k] / I(k, k); |
1526 | + | } else { |
1527 | + | Kh += angMom[0] * angMom[0] / I(0, 0) + |
1528 | + | angMom[1] * angMom[1] / I(1, 1) + |
1529 | + | angMom[2] * angMom[2] / I(2, 2); |
1530 | + | } |
1531 | + | } |
1532 | + | } |
1533 | + | } |
1534 | + | for (sd = smanB.beginSelected(selej); sd != NULL; |
1535 | + | sd = smanB.nextSelected(selej)) { |
1536 | ||
1537 | + | Vector3d pos = sd->getPos(); |
1538 | + | |
1539 | + | // wrap the stuntdouble's position back into the box: |
1540 | + | |
1541 | if (usePeriodicBoundaryConditions_) | |
1542 | currentSnap_->wrapVector(pos); | |
1543 | + | |
1544 | + | RealType mass = sd->getMass(); |
1545 | + | Vector3d vel = sd->getVel(); |
1546 | + | Vector3d rPos = sd->getPos() - coordinateOrigin_; |
1547 | + | RealType r2; |
1548 | ||
1549 | < | // which bin is this stuntdouble in? |
1550 | < | // wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)] |
1551 | < | |
1552 | < | int binNo = int(nBins_ * (pos.z() / hmat(2,2) + zShift_ + 0.5)) % nBins_; |
1553 | < | |
1554 | < | // if we're in bin 0 or the middleBin |
1555 | < | if (binNo == 0 || binNo == midBin_) { |
1556 | < | |
1557 | < | RealType mass = sd->getMass(); |
1558 | < | Vector3d vel = sd->getVel(); |
1559 | < | |
1560 | < | if (binNo == 0) { |
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 (rnemdType_ == rnemdShiftScaleVAM) { |
1568 | < | if (sd->isDirectional()) { |
1569 | < | Vector3d angMom = sd->getJ(); |
1570 | < | Mat3x3d I = sd->getI(); |
1571 | < | if (sd->isLinear()) { |
1572 | < | int i = sd->linearAxis(); |
1573 | < | int j = (i + 1) % 3; |
1574 | < | int k = (i + 2) % 3; |
1575 | < | Kh += angMom[j] * angMom[j] / I(j, j) + |
1164 | < | angMom[k] * angMom[k] / I(k, k); |
1165 | < | } else { |
1166 | < | Kh += angMom[0] * angMom[0] / I(0, 0) + |
1167 | < | angMom[1] * angMom[1] / I(1, 1) + |
1168 | < | angMom[2] * angMom[2] / I(2, 2); |
1169 | < | } |
1170 | < | } |
1171 | < | } |
1172 | < | } else { //midBin_ |
1173 | < | coldBin.push_back(sd); |
1174 | < | Pc += mass * vel; |
1175 | < | Mc += mass; |
1176 | < | Kc += mass * vel.lengthSquare(); |
1177 | < | if (rnemdType_ == rnemdShiftScaleVAM) { |
1178 | < | if (sd->isDirectional()) { |
1179 | < | Vector3d angMom = sd->getJ(); |
1180 | < | Mat3x3d I = sd->getI(); |
1181 | < | if (sd->isLinear()) { |
1182 | < | int i = sd->linearAxis(); |
1183 | < | int j = (i + 1) % 3; |
1184 | < | int k = (i + 2) % 3; |
1185 | < | Kc += angMom[j] * angMom[j] / I(j, j) + |
1186 | < | angMom[k] * angMom[k] / I(k, k); |
1187 | < | } else { |
1188 | < | Kc += angMom[0] * angMom[0] / I(0, 0) + |
1189 | < | angMom[1] * angMom[1] / I(1, 1) + |
1190 | < | angMom[2] * angMom[2] / I(2, 2); |
1191 | < | } |
1192 | < | } |
1193 | < | } |
1194 | < | } |
1549 | > | coldBin.push_back(sd); |
1550 | > | Pc += mass * vel; |
1551 | > | Mc += mass; |
1552 | > | Kc += mass * vel.lengthSquare(); |
1553 | > | Lc += mass * cross(rPos, vel); |
1554 | > | Ic -= outProduct(rPos, rPos) * mass; |
1555 | > | r2 = rPos.lengthSquare(); |
1556 | > | Ic(0, 0) += mass * r2; |
1557 | > | Ic(1, 1) += mass * r2; |
1558 | > | Ic(2, 2) += mass * r2; |
1559 | > | |
1560 | > | if (rnemdFluxType_ == rnemdFullKE) { |
1561 | > | if (sd->isDirectional()) { |
1562 | > | Vector3d angMom = sd->getJ(); |
1563 | > | Mat3x3d I = sd->getI(); |
1564 | > | if (sd->isLinear()) { |
1565 | > | int i = sd->linearAxis(); |
1566 | > | int j = (i + 1) % 3; |
1567 | > | int k = (i + 2) % 3; |
1568 | > | Kc += angMom[j] * angMom[j] / I(j, j) + |
1569 | > | angMom[k] * angMom[k] / I(k, k); |
1570 | > | } else { |
1571 | > | Kc += angMom[0] * angMom[0] / I(0, 0) + |
1572 | > | angMom[1] * angMom[1] / I(1, 1) + |
1573 | > | angMom[2] * angMom[2] / I(2, 2); |
1574 | > | } |
1575 | > | } |
1576 | } | |
1577 | } | |
1578 | ||
1579 | Kh *= 0.5; | |
1580 | Kc *= 0.5; | |
1581 | < | |
1201 | < | std::cerr << "Mh= " << Mh << "\tKh= " << Kh << "\tMc= " << Mc |
1202 | < | << "\tKc= " << Kc << endl; |
1203 | < | std::cerr << "Ph= " << Ph << "\tPc= " << Pc << endl; |
1204 | < | |
1581 | > | |
1582 | #ifdef IS_MPI | |
1583 | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Ph[0], 3, MPI::REALTYPE, MPI::SUM); | |
1584 | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Pc[0], 3, MPI::REALTYPE, MPI::SUM); | |
1585 | + | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Lh[0], 3, MPI::REALTYPE, MPI::SUM); |
1586 | + | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Lc[0], 3, MPI::REALTYPE, MPI::SUM); |
1587 | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Mh, 1, MPI::REALTYPE, MPI::SUM); | |
1588 | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Kh, 1, MPI::REALTYPE, MPI::SUM); | |
1589 | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Mc, 1, MPI::REALTYPE, MPI::SUM); | |
1590 | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Kc, 1, MPI::REALTYPE, MPI::SUM); | |
1591 | + | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, Ih.getArrayPointer(), 9, |
1592 | + | MPI::REALTYPE, MPI::SUM); |
1593 | + | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, Ic.getArrayPointer(), 9, |
1594 | + | MPI::REALTYPE, MPI::SUM); |
1595 | #endif | |
1596 | + | |
1597 | ||
1598 | + | Vector3d ac, acrec, bc, bcrec; |
1599 | + | Vector3d ah, ahrec, bh, bhrec; |
1600 | + | |
1601 | bool successfulExchange = false; | |
1602 | if ((Mh > 0.0) && (Mc > 0.0)) {//both slabs are not empty | |
1603 | Vector3d vc = Pc / Mc; | |
1604 | < | Vector3d ac = njzp_ / Mc + vc; |
1605 | < | RealType cNumerator = Kc - targetJzKE_ - 0.5 * Mc * ac.lengthSquare(); |
1604 | > | ac = -momentumTarget_ / Mc + vc; |
1605 | > | acrec = -momentumTarget_ / Mc; |
1606 | > | |
1607 | > | // We now need the inverse of the inertia tensor to calculate the |
1608 | > | // angular velocity of the cold slab; |
1609 | > | Mat3x3d Ici = Ic.inverse(); |
1610 | > | Vector3d omegac = Ici * Lc; |
1611 | > | bc = -(Ici * angularMomentumTarget_) + omegac; |
1612 | > | bcrec = bc - omegac; |
1613 | > | |
1614 | > | RealType cNumerator = Kc - kineticTarget_; |
1615 | > | if (doLinearPart) |
1616 | > | cNumerator -= 0.5 * Mc * ac.lengthSquare(); |
1617 | > | |
1618 | > | if (doAngularPart) |
1619 | > | cNumerator -= 0.5 * ( dot(bc, Ic * bc)); |
1620 | > | |
1621 | if (cNumerator > 0.0) { | |
1622 | < | RealType cDenominator = Kc - 0.5 * Mc * vc.lengthSquare(); |
1622 | > | |
1623 | > | RealType cDenominator = Kc; |
1624 | > | |
1625 | > | if (doLinearPart) |
1626 | > | cDenominator -= 0.5 * Mc * vc.lengthSquare(); |
1627 | > | |
1628 | > | if (doAngularPart) |
1629 | > | cDenominator -= 0.5*(dot(omegac, Ic * omegac)); |
1630 | > | |
1631 | if (cDenominator > 0.0) { | |
1632 | RealType c = sqrt(cNumerator / cDenominator); | |
1633 | if ((c > 0.9) && (c < 1.1)) {//restrict scaling coefficients | |
1634 | + | |
1635 | Vector3d vh = Ph / Mh; | |
1636 | < | Vector3d ah = jzp_ / Mh + vh; |
1637 | < | RealType hNumerator = Kh + targetJzKE_ |
1638 | < | - 0.5 * Mh * ah.lengthSquare(); |
1639 | < | if (hNumerator > 0.0) { |
1640 | < | RealType hDenominator = Kh - 0.5 * Mh * vh.lengthSquare(); |
1636 | > | ah = momentumTarget_ / Mh + vh; |
1637 | > | ahrec = momentumTarget_ / Mh; |
1638 | > | |
1639 | > | // We now need the inverse of the inertia tensor to |
1640 | > | // calculate the angular velocity of the hot slab; |
1641 | > | Mat3x3d Ihi = Ih.inverse(); |
1642 | > | Vector3d omegah = Ihi * Lh; |
1643 | > | bh = (Ihi * angularMomentumTarget_) + omegah; |
1644 | > | bhrec = bh - omegah; |
1645 | > | |
1646 | > | RealType hNumerator = Kh + kineticTarget_; |
1647 | > | if (doLinearPart) |
1648 | > | hNumerator -= 0.5 * Mh * ah.lengthSquare(); |
1649 | > | |
1650 | > | if (doAngularPart) |
1651 | > | hNumerator -= 0.5 * ( dot(bh, Ih * bh)); |
1652 | > | |
1653 | > | if (hNumerator > 0.0) { |
1654 | > | |
1655 | > | RealType hDenominator = Kh; |
1656 | > | if (doLinearPart) |
1657 | > | hDenominator -= 0.5 * Mh * vh.lengthSquare(); |
1658 | > | if (doAngularPart) |
1659 | > | hDenominator -= 0.5*(dot(omegah, Ih * omegah)); |
1660 | > | |
1661 | if (hDenominator > 0.0) { | |
1662 | RealType h = sqrt(hNumerator / hDenominator); | |
1663 | if ((h > 0.9) && (h < 1.1)) { | |
1664 | < | std::cerr << "cold slab scaling coefficient: " << c << "\n"; |
1234 | < | std::cerr << "hot slab scaling coefficient: " << h << "\n"; |
1664 | > | |
1665 | vector<StuntDouble*>::iterator sdi; | |
1666 | Vector3d vel; | |
1667 | < | for (sdi = coldBin.begin(); sdi != coldBin.end(); sdi++) { |
1667 | > | Vector3d rPos; |
1668 | > | |
1669 | > | for (sdi = coldBin.begin(); sdi != coldBin.end(); ++sdi) { |
1670 | //vel = (*sdi)->getVel(); | |
1671 | < | vel = ((*sdi)->getVel() - vc) * c + ac; |
1671 | > | rPos = (*sdi)->getPos() - coordinateOrigin_; |
1672 | > | if (doLinearPart) |
1673 | > | vel = ((*sdi)->getVel() - vc) * c + ac; |
1674 | > | if (doAngularPart) |
1675 | > | vel = ((*sdi)->getVel() - cross(omegac, rPos)) * c + cross(bc, rPos); |
1676 | > | |
1677 | (*sdi)->setVel(vel); | |
1678 | < | if (rnemdType_ == rnemdShiftScaleVAM) { |
1678 | > | if (rnemdFluxType_ == rnemdFullKE) { |
1679 | if ((*sdi)->isDirectional()) { | |
1680 | Vector3d angMom = (*sdi)->getJ() * c; | |
1681 | (*sdi)->setJ(angMom); | |
1682 | } | |
1683 | } | |
1684 | } | |
1685 | < | for (sdi = hotBin.begin(); sdi != hotBin.end(); sdi++) { |
1685 | > | for (sdi = hotBin.begin(); sdi != hotBin.end(); ++sdi) { |
1686 | //vel = (*sdi)->getVel(); | |
1687 | < | vel = ((*sdi)->getVel() - vh) * h + ah; |
1687 | > | rPos = (*sdi)->getPos() - coordinateOrigin_; |
1688 | > | if (doLinearPart) |
1689 | > | vel = ((*sdi)->getVel() - vh) * h + ah; |
1690 | > | if (doAngularPart) |
1691 | > | vel = ((*sdi)->getVel() - cross(omegah, rPos)) * h + cross(bh, rPos); |
1692 | > | |
1693 | (*sdi)->setVel(vel); | |
1694 | < | if (rnemdType_ == rnemdShiftScaleVAM) { |
1694 | > | if (rnemdFluxType_ == rnemdFullKE) { |
1695 | if ((*sdi)->isDirectional()) { | |
1696 | Vector3d angMom = (*sdi)->getJ() * h; | |
1697 | (*sdi)->setJ(angMom); | |
# | Line 1257 | Line 1699 | namespace OpenMD { | |
1699 | } | |
1700 | } | |
1701 | successfulExchange = true; | |
1702 | < | exchangeSum_ += targetFlux_; |
1703 | < | // this is a redundant variable for doShiftScale() so that |
1704 | < | // RNEMD can output one exchange quantity needed in a job. |
1263 | < | // need a better way to do this. |
1702 | > | kineticExchange_ += kineticTarget_; |
1703 | > | momentumExchange_ += momentumTarget_; |
1704 | > | angularMomentumExchange_ += angularMomentumTarget_; |
1705 | } | |
1706 | } | |
1707 | } | |
# | Line 1270 | Line 1711 | namespace OpenMD { | |
1711 | } | |
1712 | if (successfulExchange != true) { | |
1713 | sprintf(painCave.errMsg, | |
1714 | < | "RNEMD: exchange NOT performed!\n"); |
1714 | > | "RNEMD::doVSS exchange NOT performed - roots that solve\n" |
1715 | > | "\tthe constraint equations may not exist or there may be\n" |
1716 | > | "\tno selected objects in one or both slabs.\n"); |
1717 | painCave.isFatal = 0; | |
1718 | painCave.severity = OPENMD_INFO; | |
1719 | simError(); | |
# | Line 1278 | Line 1721 | namespace OpenMD { | |
1721 | } | |
1722 | } | |
1723 | ||
1724 | + | RealType RNEMD::getDividingArea() { |
1725 | + | |
1726 | + | if (hasDividingArea_) return dividingArea_; |
1727 | + | |
1728 | + | RealType areaA, areaB; |
1729 | + | Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
1730 | + | |
1731 | + | if (hasSelectionA_) { |
1732 | + | int isd; |
1733 | + | StuntDouble* sd; |
1734 | + | vector<StuntDouble*> aSites; |
1735 | + | seleManA_.setSelectionSet(evaluatorA_.evaluate()); |
1736 | + | for (sd = seleManA_.beginSelected(isd); sd != NULL; |
1737 | + | sd = seleManA_.nextSelected(isd)) { |
1738 | + | aSites.push_back(sd); |
1739 | + | } |
1740 | + | #if defined(HAVE_QHULL) |
1741 | + | ConvexHull* surfaceMeshA = new ConvexHull(); |
1742 | + | surfaceMeshA->computeHull(aSites); |
1743 | + | areaA = surfaceMeshA->getArea(); |
1744 | + | delete surfaceMeshA; |
1745 | + | #else |
1746 | + | sprintf( painCave.errMsg, |
1747 | + | "RNEMD::getDividingArea : Hull calculation is not possible\n" |
1748 | + | "\twithout libqhull. Please rebuild OpenMD with qhull enabled."); |
1749 | + | painCave.severity = OPENMD_ERROR; |
1750 | + | painCave.isFatal = 1; |
1751 | + | simError(); |
1752 | + | #endif |
1753 | + | |
1754 | + | } else { |
1755 | + | if (usePeriodicBoundaryConditions_) { |
1756 | + | // in periodic boundaries, the surface area is twice the x-y |
1757 | + | // area of the current box: |
1758 | + | areaA = 2.0 * snap->getXYarea(); |
1759 | + | } else { |
1760 | + | // in non-periodic simulations, without explicitly setting |
1761 | + | // selections, the sphere radius sets the surface area of the |
1762 | + | // dividing surface: |
1763 | + | areaA = 4.0 * M_PI * pow(sphereARadius_, 2); |
1764 | + | } |
1765 | + | } |
1766 | + | |
1767 | + | if (hasSelectionB_) { |
1768 | + | int isd; |
1769 | + | StuntDouble* sd; |
1770 | + | vector<StuntDouble*> bSites; |
1771 | + | seleManB_.setSelectionSet(evaluatorB_.evaluate()); |
1772 | + | for (sd = seleManB_.beginSelected(isd); sd != NULL; |
1773 | + | sd = seleManB_.nextSelected(isd)) { |
1774 | + | bSites.push_back(sd); |
1775 | + | } |
1776 | + | |
1777 | + | #if defined(HAVE_QHULL) |
1778 | + | ConvexHull* surfaceMeshB = new ConvexHull(); |
1779 | + | surfaceMeshB->computeHull(bSites); |
1780 | + | areaB = surfaceMeshB->getArea(); |
1781 | + | delete surfaceMeshB; |
1782 | + | #else |
1783 | + | sprintf( painCave.errMsg, |
1784 | + | "RNEMD::getDividingArea : Hull calculation is not possible\n" |
1785 | + | "\twithout libqhull. Please rebuild OpenMD with qhull enabled."); |
1786 | + | painCave.severity = OPENMD_ERROR; |
1787 | + | painCave.isFatal = 1; |
1788 | + | simError(); |
1789 | + | #endif |
1790 | + | |
1791 | + | |
1792 | + | } else { |
1793 | + | if (usePeriodicBoundaryConditions_) { |
1794 | + | // in periodic boundaries, the surface area is twice the x-y |
1795 | + | // area of the current box: |
1796 | + | areaB = 2.0 * snap->getXYarea(); |
1797 | + | } else { |
1798 | + | // in non-periodic simulations, without explicitly setting |
1799 | + | // selections, but if a sphereBradius has been set, just use that: |
1800 | + | areaB = 4.0 * M_PI * pow(sphereBRadius_, 2); |
1801 | + | } |
1802 | + | } |
1803 | + | |
1804 | + | dividingArea_ = min(areaA, areaB); |
1805 | + | hasDividingArea_ = true; |
1806 | + | return dividingArea_; |
1807 | + | } |
1808 | + | |
1809 | void RNEMD::doRNEMD() { | |
1810 | + | if (!doRNEMD_) return; |
1811 | + | trialCount_++; |
1812 | ||
1813 | < | switch(rnemdType_) { |
1814 | < | case rnemdKineticScale : |
1815 | < | case rnemdKineticScaleVAM : |
1816 | < | case rnemdKineticScaleAM : |
1817 | < | case rnemdPxScale : |
1818 | < | case rnemdPyScale : |
1819 | < | case rnemdPzScale : |
1820 | < | doScale(); |
1813 | > | // object evaluator: |
1814 | > | evaluator_.loadScriptString(rnemdObjectSelection_); |
1815 | > | seleMan_.setSelectionSet(evaluator_.evaluate()); |
1816 | > | |
1817 | > | evaluatorA_.loadScriptString(selectionA_); |
1818 | > | evaluatorB_.loadScriptString(selectionB_); |
1819 | > | |
1820 | > | seleManA_.setSelectionSet(evaluatorA_.evaluate()); |
1821 | > | seleManB_.setSelectionSet(evaluatorB_.evaluate()); |
1822 | > | |
1823 | > | commonA_ = seleManA_ & seleMan_; |
1824 | > | commonB_ = seleManB_ & seleMan_; |
1825 | > | |
1826 | > | // Target exchange quantities (in each exchange) = dividingArea * dt * flux |
1827 | > | // dt = exchange time interval |
1828 | > | // flux = target flux |
1829 | > | // dividingArea = smallest dividing surface between the two regions |
1830 | > | |
1831 | > | hasDividingArea_ = false; |
1832 | > | RealType area = getDividingArea(); |
1833 | > | |
1834 | > | kineticTarget_ = kineticFlux_ * exchangeTime_ * area; |
1835 | > | momentumTarget_ = momentumFluxVector_ * exchangeTime_ * area; |
1836 | > | angularMomentumTarget_ = angularMomentumFluxVector_ * exchangeTime_ * area; |
1837 | > | |
1838 | > | switch(rnemdMethod_) { |
1839 | > | case rnemdSwap: |
1840 | > | doSwap(commonA_, commonB_); |
1841 | break; | |
1842 | < | case rnemdKineticSwap : |
1843 | < | case rnemdPx : |
1294 | < | case rnemdPy : |
1295 | < | case rnemdPz : |
1296 | < | doSwap(); |
1842 | > | case rnemdNIVS: |
1843 | > | doNIVS(commonA_, commonB_); |
1844 | break; | |
1845 | < | case rnemdShiftScaleV : |
1846 | < | case rnemdShiftScaleVAM : |
1300 | < | doShiftScale(); |
1845 | > | case rnemdVSS: |
1846 | > | doVSS(commonA_, commonB_); |
1847 | break; | |
1848 | < | case rnemdUnknown : |
1848 | > | case rnemdUnkownMethod: |
1849 | default : | |
1850 | break; | |
1851 | } | |
1852 | } | |
1853 | ||
1854 | void RNEMD::collectData() { | |
1855 | < | |
1855 | > | if (!doRNEMD_) return; |
1856 | Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); | |
1857 | + | |
1858 | + | // collectData can be called more frequently than the doRNEMD, so use the |
1859 | + | // computed area from the last exchange time: |
1860 | + | RealType area = getDividingArea(); |
1861 | + | areaAccumulator_->add(area); |
1862 | Mat3x3d hmat = currentSnap_->getHmat(); | |
1312 | – | |
1863 | seleMan_.setSelectionSet(evaluator_.evaluate()); | |
1864 | ||
1865 | < | int selei; |
1865 | > | int selei(0); |
1866 | StuntDouble* sd; | |
1867 | < | int idx; |
1867 | > | int binNo; |
1868 | ||
1869 | + | vector<RealType> binMass(nBins_, 0.0); |
1870 | + | vector<RealType> binPx(nBins_, 0.0); |
1871 | + | vector<RealType> binPy(nBins_, 0.0); |
1872 | + | vector<RealType> binPz(nBins_, 0.0); |
1873 | + | vector<RealType> binOmegax(nBins_, 0.0); |
1874 | + | vector<RealType> binOmegay(nBins_, 0.0); |
1875 | + | vector<RealType> binOmegaz(nBins_, 0.0); |
1876 | + | vector<RealType> binKE(nBins_, 0.0); |
1877 | + | vector<int> binDOF(nBins_, 0); |
1878 | + | vector<int> binCount(nBins_, 0); |
1879 | + | |
1880 | // alternative approach, track all molecules instead of only those | |
1881 | // selected for scaling/swapping: | |
1882 | /* | |
1883 | < | SimInfo::MoleculeIterator miter; |
1884 | < | vector<StuntDouble*>::iterator iiter; |
1885 | < | Molecule* mol; |
1886 | < | StuntDouble* integrableObject; |
1887 | < | for (mol = info_->beginMolecule(miter); mol != NULL; |
1888 | < | mol = info_->nextMolecule(miter)) |
1889 | < | integrableObject is essentially sd |
1890 | < | for (integrableObject = mol->beginIntegrableObject(iiter); |
1891 | < | integrableObject != NULL; |
1892 | < | integrableObject = mol->nextIntegrableObject(iiter)) |
1883 | > | SimInfo::MoleculeIterator miter; |
1884 | > | vector<StuntDouble*>::iterator iiter; |
1885 | > | Molecule* mol; |
1886 | > | StuntDouble* sd; |
1887 | > | for (mol = info_->beginMolecule(miter); mol != NULL; |
1888 | > | mol = info_->nextMolecule(miter)) |
1889 | > | sd is essentially sd |
1890 | > | for (sd = mol->beginIntegrableObject(iiter); |
1891 | > | sd != NULL; |
1892 | > | sd = mol->nextIntegrableObject(iiter)) |
1893 | */ | |
1894 | + | |
1895 | for (sd = seleMan_.beginSelected(selei); sd != NULL; | |
1896 | < | sd = seleMan_.nextSelected(selei)) { |
1897 | < | |
1336 | < | idx = sd->getLocalIndex(); |
1337 | < | |
1896 | > | sd = seleMan_.nextSelected(selei)) { |
1897 | > | |
1898 | Vector3d pos = sd->getPos(); | |
1899 | ||
1900 | // wrap the stuntdouble's position back into the box: | |
1901 | ||
1902 | < | if (usePeriodicBoundaryConditions_) |
1902 | > | if (usePeriodicBoundaryConditions_) { |
1903 | currentSnap_->wrapVector(pos); | |
1904 | < | |
1905 | < | // which bin is this stuntdouble in? |
1906 | < | // wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)] |
1907 | < | |
1908 | < | int binNo = int(rnemdLogWidth_ * (pos.z() / hmat(2,2) + 0.5)) % |
1909 | < | rnemdLogWidth_; |
1910 | < | // no symmetrization allowed due to arbitary rnemdLogWidth_ |
1911 | < | /* |
1912 | < | if (rnemdLogWidth_ == midBin_ + 1) |
1913 | < | if (binNo > midBin_) |
1914 | < | binNo = nBins_ - binNo; |
1355 | < | */ |
1904 | > | // which bin is this stuntdouble in? |
1905 | > | // wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)] |
1906 | > | // Shift molecules by half a box to have bins start at 0 |
1907 | > | // The modulo operator is used to wrap the case when we are |
1908 | > | // beyond the end of the bins back to the beginning. |
1909 | > | binNo = int(nBins_ * (pos.z() / hmat(2,2) + 0.5)) % nBins_; |
1910 | > | } else { |
1911 | > | Vector3d rPos = pos - coordinateOrigin_; |
1912 | > | binNo = int(rPos.length() / binWidth_); |
1913 | > | } |
1914 | > | |
1915 | RealType mass = sd->getMass(); | |
1357 | – | mHist_[binNo] += mass; |
1916 | Vector3d vel = sd->getVel(); | |
1917 | < | RealType value; |
1918 | < | //RealType xVal, yVal, zVal; |
1919 | < | |
1920 | < | if (outputTemp_) { |
1921 | < | value = mass * vel.lengthSquare(); |
1922 | < | tempCount_[binNo] += 3; |
1923 | < | if (sd->isDirectional()) { |
1924 | < | Vector3d angMom = sd->getJ(); |
1925 | < | Mat3x3d I = sd->getI(); |
1926 | < | if (sd->isLinear()) { |
1927 | < | int i = sd->linearAxis(); |
1928 | < | int j = (i + 1) % 3; |
1929 | < | int k = (i + 2) % 3; |
1930 | < | value += angMom[j] * angMom[j] / I(j, j) + |
1931 | < | angMom[k] * angMom[k] / I(k, k); |
1932 | < | tempCount_[binNo] +=2; |
1933 | < | } else { |
1934 | < | value += angMom[0] * angMom[0] / I(0, 0) + |
1935 | < | angMom[1]*angMom[1]/I(1, 1) + |
1936 | < | angMom[2]*angMom[2]/I(2, 2); |
1937 | < | tempCount_[binNo] +=3; |
1938 | < | } |
1939 | < | } |
1940 | < | value = value / PhysicalConstants::energyConvert |
1941 | < | / PhysicalConstants::kb;//may move to getStatus() |
1942 | < | tempHist_[binNo] += value; |
1917 | > | Vector3d rPos = sd->getPos() - coordinateOrigin_; |
1918 | > | Vector3d aVel = cross(rPos, vel); |
1919 | > | |
1920 | > | if (binNo >= 0 && binNo < nBins_) { |
1921 | > | binCount[binNo]++; |
1922 | > | binMass[binNo] += mass; |
1923 | > | binPx[binNo] += mass*vel.x(); |
1924 | > | binPy[binNo] += mass*vel.y(); |
1925 | > | binPz[binNo] += mass*vel.z(); |
1926 | > | binOmegax[binNo] += aVel.x(); |
1927 | > | binOmegay[binNo] += aVel.y(); |
1928 | > | binOmegaz[binNo] += aVel.z(); |
1929 | > | binKE[binNo] += 0.5 * (mass * vel.lengthSquare()); |
1930 | > | binDOF[binNo] += 3; |
1931 | > | |
1932 | > | if (sd->isDirectional()) { |
1933 | > | Vector3d angMom = sd->getJ(); |
1934 | > | Mat3x3d I = sd->getI(); |
1935 | > | if (sd->isLinear()) { |
1936 | > | int i = sd->linearAxis(); |
1937 | > | int j = (i + 1) % 3; |
1938 | > | int k = (i + 2) % 3; |
1939 | > | binKE[binNo] += 0.5 * (angMom[j] * angMom[j] / I(j, j) + |
1940 | > | angMom[k] * angMom[k] / I(k, k)); |
1941 | > | binDOF[binNo] += 2; |
1942 | > | } else { |
1943 | > | binKE[binNo] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) + |
1944 | > | angMom[1] * angMom[1] / I(1, 1) + |
1945 | > | angMom[2] * angMom[2] / I(2, 2)); |
1946 | > | binDOF[binNo] += 3; |
1947 | > | } |
1948 | > | } |
1949 | } | |
1950 | < | if (outputVx_) { |
1951 | < | value = mass * vel[0]; |
1952 | < | //vxzCount_[binNo]++; |
1953 | < | pxzHist_[binNo] += value; |
1954 | < | } |
1955 | < | if (outputVy_) { |
1956 | < | value = mass * vel[1]; |
1957 | < | //vyzCount_[binNo]++; |
1958 | < | pyzHist_[binNo] += value; |
1959 | < | } |
1950 | > | } |
1951 | > | |
1952 | > | #ifdef IS_MPI |
1953 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binCount[0], |
1954 | > | nBins_, MPI::INT, MPI::SUM); |
1955 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binMass[0], |
1956 | > | nBins_, MPI::REALTYPE, MPI::SUM); |
1957 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binPx[0], |
1958 | > | nBins_, MPI::REALTYPE, MPI::SUM); |
1959 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binPy[0], |
1960 | > | nBins_, MPI::REALTYPE, MPI::SUM); |
1961 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binPz[0], |
1962 | > | nBins_, MPI::REALTYPE, MPI::SUM); |
1963 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegax[0], |
1964 | > | nBins_, MPI::REALTYPE, MPI::SUM); |
1965 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegay[0], |
1966 | > | nBins_, MPI::REALTYPE, MPI::SUM); |
1967 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegaz[0], |
1968 | > | nBins_, MPI::REALTYPE, MPI::SUM); |
1969 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binKE[0], |
1970 | > | nBins_, MPI::REALTYPE, MPI::SUM); |
1971 | > | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binDOF[0], |
1972 | > | nBins_, MPI::INT, MPI::SUM); |
1973 | > | #endif |
1974 | ||
1975 | < | if (output3DTemp_) { |
1976 | < | value = mass * vel.x() * vel.x(); |
1977 | < | xTempHist_[binNo] += value; |
1978 | < | value = mass * vel.y() * vel.y() / PhysicalConstants::energyConvert |
1979 | < | / PhysicalConstants::kb; |
1980 | < | yTempHist_[binNo] += value; |
1981 | < | value = mass * vel.z() * vel.z() / PhysicalConstants::energyConvert |
1982 | < | / PhysicalConstants::kb; |
1983 | < | zTempHist_[binNo] += value; |
1984 | < | xyzTempCount_[binNo]++; |
1975 | > | Vector3d vel; |
1976 | > | Vector3d aVel; |
1977 | > | RealType den; |
1978 | > | RealType temp; |
1979 | > | RealType z; |
1980 | > | RealType r; |
1981 | > | for (int i = 0; i < nBins_; i++) { |
1982 | > | if (usePeriodicBoundaryConditions_) { |
1983 | > | z = (((RealType)i + 0.5) / (RealType)nBins_) * hmat(2,2); |
1984 | > | den = binMass[i] * nBins_ * PhysicalConstants::densityConvert |
1985 | > | / currentSnap_->getVolume() ; |
1986 | > | } else { |
1987 | > | r = (((RealType)i + 0.5) * binWidth_); |
1988 | > | RealType rinner = (RealType)i * binWidth_; |
1989 | > | RealType router = (RealType)(i+1) * binWidth_; |
1990 | > | den = binMass[i] * 3.0 * PhysicalConstants::densityConvert |
1991 | > | / (4.0 * M_PI * (pow(router,3) - pow(rinner,3))); |
1992 | } | |
1993 | < | if (outputRotTemp_) { |
1994 | < | if (sd->isDirectional()) { |
1995 | < | Vector3d angMom = sd->getJ(); |
1996 | < | Mat3x3d I = sd->getI(); |
1997 | < | if (sd->isLinear()) { |
1998 | < | int i = sd->linearAxis(); |
1414 | < | int j = (i + 1) % 3; |
1415 | < | int k = (i + 2) % 3; |
1416 | < | value = angMom[j] * angMom[j] / I(j, j) + |
1417 | < | angMom[k] * angMom[k] / I(k, k); |
1418 | < | rotTempCount_[binNo] +=2; |
1419 | < | } else { |
1420 | < | value = angMom[0] * angMom[0] / I(0, 0) + |
1421 | < | angMom[1] * angMom[1] / I(1, 1) + |
1422 | < | angMom[2] * angMom[2] / I(2, 2); |
1423 | < | rotTempCount_[binNo] +=3; |
1424 | < | } |
1425 | < | } |
1426 | < | value = value / PhysicalConstants::energyConvert |
1427 | < | / PhysicalConstants::kb;//may move to getStatus() |
1428 | < | rotTempHist_[binNo] += value; |
1429 | < | } |
1993 | > | vel.x() = binPx[i] / binMass[i]; |
1994 | > | vel.y() = binPy[i] / binMass[i]; |
1995 | > | vel.z() = binPz[i] / binMass[i]; |
1996 | > | aVel.x() = binOmegax[i] / binCount[i]; |
1997 | > | aVel.y() = binOmegay[i] / binCount[i]; |
1998 | > | aVel.z() = binOmegaz[i] / binCount[i]; |
1999 | ||
2000 | + | if (binCount[i] > 0) { |
2001 | + | // only add values if there are things to add |
2002 | + | temp = 2.0 * binKE[i] / (binDOF[i] * PhysicalConstants::kb * |
2003 | + | PhysicalConstants::energyConvert); |
2004 | + | |
2005 | + | for (unsigned int j = 0; j < outputMask_.size(); ++j) { |
2006 | + | if(outputMask_[j]) { |
2007 | + | switch(j) { |
2008 | + | case Z: |
2009 | + | dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(z); |
2010 | + | break; |
2011 | + | case R: |
2012 | + | dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(r); |
2013 | + | break; |
2014 | + | case TEMPERATURE: |
2015 | + | dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(temp); |
2016 | + | break; |
2017 | + | case VELOCITY: |
2018 | + | dynamic_cast<VectorAccumulator *>(data_[j].accumulator[i])->add(vel); |
2019 | + | break; |
2020 | + | case ANGULARVELOCITY: |
2021 | + | dynamic_cast<VectorAccumulator *>(data_[j].accumulator[i])->add(aVel); |
2022 | + | break; |
2023 | + | case DENSITY: |
2024 | + | dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(den); |
2025 | + | break; |
2026 | + | } |
2027 | + | } |
2028 | + | } |
2029 | + | } |
2030 | } | |
2031 | + | hasData_ = true; |
2032 | } | |
2033 | ||
2034 | void RNEMD::getStarted() { | |
2035 | + | if (!doRNEMD_) return; |
2036 | + | hasDividingArea_ = false; |
2037 | collectData(); | |
2038 | < | /*now can output profile in step 0, but might not be useful; |
1437 | < | Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
1438 | < | Stats& stat = currentSnap_->statData; |
1439 | < | stat[Stats::RNEMD_EXCHANGE_TOTAL] = exchangeSum_; |
1440 | < | */ |
1441 | < | //may output a header for the log file here |
1442 | < | getStatus(); |
2038 | > | writeOutputFile(); |
2039 | } | |
2040 | ||
2041 | < | void RNEMD::getStatus() { |
2042 | < | |
2043 | < | Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
2044 | < | Stats& stat = currentSnap_->statData; |
2045 | < | RealType time = currentSnap_->getTime(); |
2046 | < | |
2047 | < | stat[Stats::RNEMD_EXCHANGE_TOTAL] = exchangeSum_; |
2048 | < | //or to be more meaningful, define another item as exchangeSum_ / time |
2049 | < | int j; |
2050 | < | |
2041 | > | void RNEMD::parseOutputFileFormat(const std::string& format) { |
2042 | > | if (!doRNEMD_) return; |
2043 | > | StringTokenizer tokenizer(format, " ,;|\t\n\r"); |
2044 | > | |
2045 | > | while(tokenizer.hasMoreTokens()) { |
2046 | > | std::string token(tokenizer.nextToken()); |
2047 | > | toUpper(token); |
2048 | > | OutputMapType::iterator i = outputMap_.find(token); |
2049 | > | if (i != outputMap_.end()) { |
2050 | > | outputMask_.set(i->second); |
2051 | > | } else { |
2052 | > | sprintf( painCave.errMsg, |
2053 | > | "RNEMD::parseOutputFileFormat: %s is not a recognized\n" |
2054 | > | "\toutputFileFormat keyword.\n", token.c_str() ); |
2055 | > | painCave.isFatal = 0; |
2056 | > | painCave.severity = OPENMD_ERROR; |
2057 | > | simError(); |
2058 | > | } |
2059 | > | } |
2060 | > | } |
2061 | > | |
2062 | > | void RNEMD::writeOutputFile() { |
2063 | > | if (!doRNEMD_) return; |
2064 | > | if (!hasData_) return; |
2065 | > | |
2066 | #ifdef IS_MPI | |
1456 | – | |
1457 | – | // all processors have the same number of bins, and STL vectors pack their |
1458 | – | // arrays, so in theory, this should be safe: |
1459 | – | |
1460 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &mHist_[0], |
1461 | – | rnemdLogWidth_, MPI::REALTYPE, MPI::SUM); |
1462 | – | if (outputTemp_) { |
1463 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &tempHist_[0], |
1464 | – | rnemdLogWidth_, MPI::REALTYPE, MPI::SUM); |
1465 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &tempCount_[0], |
1466 | – | rnemdLogWidth_, MPI::INT, MPI::SUM); |
1467 | – | } |
1468 | – | if (outputVx_) { |
1469 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &pxzHist_[0], |
1470 | – | rnemdLogWidth_, MPI::REALTYPE, MPI::SUM); |
1471 | – | //MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &vxzCount_[0], |
1472 | – | // rnemdLogWidth_, MPI::INT, MPI::SUM); |
1473 | – | } |
1474 | – | if (outputVy_) { |
1475 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &pyzHist_[0], |
1476 | – | rnemdLogWidth_, MPI::REALTYPE, MPI::SUM); |
1477 | – | //MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &vyzCount_[0], |
1478 | – | // rnemdLogWidth_, MPI::INT, MPI::SUM); |
1479 | – | } |
1480 | – | if (output3DTemp_) { |
1481 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &xTempHist_[0], |
1482 | – | rnemdLogWidth_, MPI::REALTYPE, MPI::SUM); |
1483 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &yTempHist_[0], |
1484 | – | rnemdLogWidth_, MPI::REALTYPE, MPI::SUM); |
1485 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &zTempHist_[0], |
1486 | – | rnemdLogWidth_, MPI::REALTYPE, MPI::SUM); |
1487 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &xyzTempCount_[0], |
1488 | – | rnemdLogWidth_, MPI::INT, MPI::SUM); |
1489 | – | } |
1490 | – | if (outputRotTemp_) { |
1491 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &rotTempHist_[0], |
1492 | – | rnemdLogWidth_, MPI::REALTYPE, MPI::SUM); |
1493 | – | MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &rotTempCount_[0], |
1494 | – | rnemdLogWidth_, MPI::INT, MPI::SUM); |
1495 | – | } |
1496 | – | |
2067 | // If we're the root node, should we print out the results | |
2068 | int worldRank = MPI::COMM_WORLD.Get_rank(); | |
2069 | if (worldRank == 0) { | |
2070 | #endif | |
2071 | + | rnemdFile_.open(rnemdFileName_.c_str(), std::ios::out | std::ios::trunc ); |
2072 | + | |
2073 | + | if( !rnemdFile_ ){ |
2074 | + | sprintf( painCave.errMsg, |
2075 | + | "Could not open \"%s\" for RNEMD output.\n", |
2076 | + | rnemdFileName_.c_str()); |
2077 | + | painCave.isFatal = 1; |
2078 | + | simError(); |
2079 | + | } |
2080 | ||
2081 | < | if (outputTemp_) { |
2082 | < | tempLog_ << time; |
2083 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
2084 | < | tempLog_ << "\t" << tempHist_[j] / (RealType)tempCount_[j]; |
2085 | < | } |
2086 | < | tempLog_ << endl; |
2081 | > | Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
2082 | > | |
2083 | > | RealType time = currentSnap_->getTime(); |
2084 | > | RealType avgArea; |
2085 | > | areaAccumulator_->getAverage(avgArea); |
2086 | > | |
2087 | > | RealType Jz(0.0); |
2088 | > | Vector3d JzP(V3Zero); |
2089 | > | Vector3d JzL(V3Zero); |
2090 | > | if (time >= info_->getSimParams()->getDt()) { |
2091 | > | Jz = kineticExchange_ / (time * avgArea) |
2092 | > | / PhysicalConstants::energyConvert; |
2093 | > | JzP = momentumExchange_ / (time * avgArea); |
2094 | > | JzL = angularMomentumExchange_ / (time * avgArea); |
2095 | } | |
2096 | < | if (outputVx_) { |
2097 | < | vxzLog_ << time; |
2098 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
2099 | < | vxzLog_ << "\t" << pxzHist_[j] / mHist_[j]; |
2100 | < | } |
2101 | < | vxzLog_ << endl; |
2096 | > | |
2097 | > | rnemdFile_ << "#######################################################\n"; |
2098 | > | rnemdFile_ << "# RNEMD {\n"; |
2099 | > | |
2100 | > | map<string, RNEMDMethod>::iterator mi; |
2101 | > | for(mi = stringToMethod_.begin(); mi != stringToMethod_.end(); ++mi) { |
2102 | > | if ( (*mi).second == rnemdMethod_) |
2103 | > | rnemdFile_ << "# exchangeMethod = \"" << (*mi).first << "\";\n"; |
2104 | } | |
2105 | < | if (outputVy_) { |
2106 | < | vyzLog_ << time; |
2107 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
2108 | < | vyzLog_ << "\t" << pyzHist_[j] / mHist_[j]; |
1520 | < | } |
1521 | < | vyzLog_ << endl; |
2105 | > | map<string, RNEMDFluxType>::iterator fi; |
2106 | > | for(fi = stringToFluxType_.begin(); fi != stringToFluxType_.end(); ++fi) { |
2107 | > | if ( (*fi).second == rnemdFluxType_) |
2108 | > | rnemdFile_ << "# fluxType = \"" << (*fi).first << "\";\n"; |
2109 | } | |
2110 | + | |
2111 | + | rnemdFile_ << "# exchangeTime = " << exchangeTime_ << ";\n"; |
2112 | ||
2113 | < | if (output3DTemp_) { |
2114 | < | RealType temp; |
2115 | < | xTempLog_ << time; |
2116 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
2117 | < | if (outputVx_) |
2118 | < | xTempHist_[j] -= pxzHist_[j] * pxzHist_[j] / mHist_[j]; |
2119 | < | temp = xTempHist_[j] / (RealType)xyzTempCount_[j] |
2120 | < | / PhysicalConstants::energyConvert / PhysicalConstants::kb; |
2121 | < | xTempLog_ << "\t" << temp; |
2113 | > | rnemdFile_ << "# objectSelection = \"" |
2114 | > | << rnemdObjectSelection_ << "\";\n"; |
2115 | > | rnemdFile_ << "# selectionA = \"" << selectionA_ << "\";\n"; |
2116 | > | rnemdFile_ << "# selectionB = \"" << selectionB_ << "\";\n"; |
2117 | > | rnemdFile_ << "# }\n"; |
2118 | > | rnemdFile_ << "#######################################################\n"; |
2119 | > | rnemdFile_ << "# RNEMD report:\n"; |
2120 | > | rnemdFile_ << "# running time = " << time << " fs\n"; |
2121 | > | rnemdFile_ << "# Target flux:\n"; |
2122 | > | rnemdFile_ << "# kinetic = " |
2123 | > | << kineticFlux_ / PhysicalConstants::energyConvert |
2124 | > | << " (kcal/mol/A^2/fs)\n"; |
2125 | > | rnemdFile_ << "# momentum = " << momentumFluxVector_ |
2126 | > | << " (amu/A/fs^2)\n"; |
2127 | > | rnemdFile_ << "# angular momentum = " << angularMomentumFluxVector_ |
2128 | > | << " (amu/A^2/fs^2)\n"; |
2129 | > | rnemdFile_ << "# Target one-time exchanges:\n"; |
2130 | > | rnemdFile_ << "# kinetic = " |
2131 | > | << kineticTarget_ / PhysicalConstants::energyConvert |
2132 | > | << " (kcal/mol)\n"; |
2133 | > | rnemdFile_ << "# momentum = " << momentumTarget_ |
2134 | > | << " (amu*A/fs)\n"; |
2135 | > | rnemdFile_ << "# angular momentum = " << angularMomentumTarget_ |
2136 | > | << " (amu*A^2/fs)\n"; |
2137 | > | rnemdFile_ << "# Actual exchange totals:\n"; |
2138 | > | rnemdFile_ << "# kinetic = " |
2139 | > | << kineticExchange_ / PhysicalConstants::energyConvert |
2140 | > | << " (kcal/mol)\n"; |
2141 | > | rnemdFile_ << "# momentum = " << momentumExchange_ |
2142 | > | << " (amu*A/fs)\n"; |
2143 | > | rnemdFile_ << "# angular momentum = " << angularMomentumExchange_ |
2144 | > | << " (amu*A^2/fs)\n"; |
2145 | > | rnemdFile_ << "# Actual flux:\n"; |
2146 | > | rnemdFile_ << "# kinetic = " << Jz |
2147 | > | << " (kcal/mol/A^2/fs)\n"; |
2148 | > | rnemdFile_ << "# momentum = " << JzP |
2149 | > | << " (amu/A/fs^2)\n"; |
2150 | > | rnemdFile_ << "# angular momentum = " << JzL |
2151 | > | << " (amu/A^2/fs^2)\n"; |
2152 | > | rnemdFile_ << "# Exchange statistics:\n"; |
2153 | > | rnemdFile_ << "# attempted = " << trialCount_ << "\n"; |
2154 | > | rnemdFile_ << "# failed = " << failTrialCount_ << "\n"; |
2155 | > | if (rnemdMethod_ == rnemdNIVS) { |
2156 | > | rnemdFile_ << "# NIVS root-check errors = " |
2157 | > | << failRootCount_ << "\n"; |
2158 | > | } |
2159 | > | rnemdFile_ << "#######################################################\n"; |
2160 | > | |
2161 | > | |
2162 | > | |
2163 | > | //write title |
2164 | > | rnemdFile_ << "#"; |
2165 | > | for (unsigned int i = 0; i < outputMask_.size(); ++i) { |
2166 | > | if (outputMask_[i]) { |
2167 | > | rnemdFile_ << "\t" << data_[i].title << |
2168 | > | "(" << data_[i].units << ")"; |
2169 | > | // add some extra tabs for column alignment |
2170 | > | if (data_[i].dataType == "Vector3d") rnemdFile_ << "\t\t"; |
2171 | } | |
1534 | – | xTempLog_ << endl; |
1535 | – | yTempLog_ << time; |
1536 | – | for (j = 0; j < rnemdLogWidth_; j++) { |
1537 | – | yTempLog_ << "\t" << yTempHist_[j] / (RealType)xyzTempCount_[j]; |
1538 | – | } |
1539 | – | yTempLog_ << endl; |
1540 | – | zTempLog_ << time; |
1541 | – | for (j = 0; j < rnemdLogWidth_; j++) { |
1542 | – | zTempLog_ << "\t" << zTempHist_[j] / (RealType)xyzTempCount_[j]; |
1543 | – | } |
1544 | – | zTempLog_ << endl; |
2172 | } | |
2173 | < | if (outputRotTemp_) { |
2174 | < | rotTempLog_ << time; |
2175 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
2176 | < | rotTempLog_ << "\t" << rotTempHist_[j] / (RealType)rotTempCount_[j]; |
2177 | < | } |
2178 | < | rotTempLog_ << endl; |
2179 | < | } |
2173 | > | rnemdFile_ << std::endl; |
2174 | > | |
2175 | > | rnemdFile_.precision(8); |
2176 | > | |
2177 | > | for (int j = 0; j < nBins_; j++) { |
2178 | > | |
2179 | > | for (unsigned int i = 0; i < outputMask_.size(); ++i) { |
2180 | > | if (outputMask_[i]) { |
2181 | > | if (data_[i].dataType == "RealType") |
2182 | > | writeReal(i,j); |
2183 | > | else if (data_[i].dataType == "Vector3d") |
2184 | > | writeVector(i,j); |
2185 | > | else { |
2186 | > | sprintf( painCave.errMsg, |
2187 | > | "RNEMD found an unknown data type for: %s ", |
2188 | > | data_[i].title.c_str()); |
2189 | > | painCave.isFatal = 1; |
2190 | > | simError(); |
2191 | > | } |
2192 | > | } |
2193 | > | } |
2194 | > | rnemdFile_ << std::endl; |
2195 | > | |
2196 | > | } |
2197 | ||
2198 | + | rnemdFile_ << "#######################################################\n"; |
2199 | + | rnemdFile_ << "# Standard Deviations in those quantities follow:\n"; |
2200 | + | rnemdFile_ << "#######################################################\n"; |
2201 | + | |
2202 | + | |
2203 | + | for (int j = 0; j < nBins_; j++) { |
2204 | + | rnemdFile_ << "#"; |
2205 | + | for (unsigned int i = 0; i < outputMask_.size(); ++i) { |
2206 | + | if (outputMask_[i]) { |
2207 | + | if (data_[i].dataType == "RealType") |
2208 | + | writeRealStdDev(i,j); |
2209 | + | else if (data_[i].dataType == "Vector3d") |
2210 | + | writeVectorStdDev(i,j); |
2211 | + | else { |
2212 | + | sprintf( painCave.errMsg, |
2213 | + | "RNEMD found an unknown data type for: %s ", |
2214 | + | data_[i].title.c_str()); |
2215 | + | painCave.isFatal = 1; |
2216 | + | simError(); |
2217 | + | } |
2218 | + | } |
2219 | + | } |
2220 | + | rnemdFile_ << std::endl; |
2221 | + | |
2222 | + | } |
2223 | + | |
2224 | + | rnemdFile_.flush(); |
2225 | + | rnemdFile_.close(); |
2226 | + | |
2227 | #ifdef IS_MPI | |
2228 | } | |
2229 | #endif | |
2230 | + | |
2231 | + | } |
2232 | + | |
2233 | + | void RNEMD::writeReal(int index, unsigned int bin) { |
2234 | + | if (!doRNEMD_) return; |
2235 | + | assert(index >=0 && index < ENDINDEX); |
2236 | + | assert(int(bin) < nBins_); |
2237 | + | RealType s; |
2238 | + | int count; |
2239 | + | |
2240 | + | count = data_[index].accumulator[bin]->count(); |
2241 | + | if (count == 0) return; |
2242 | + | |
2243 | + | dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->getAverage(s); |
2244 | + | |
2245 | + | if (! isinf(s) && ! isnan(s)) { |
2246 | + | rnemdFile_ << "\t" << s; |
2247 | + | } else{ |
2248 | + | sprintf( painCave.errMsg, |
2249 | + | "RNEMD detected a numerical error writing: %s for bin %u", |
2250 | + | data_[index].title.c_str(), bin); |
2251 | + | painCave.isFatal = 1; |
2252 | + | simError(); |
2253 | + | } |
2254 | + | } |
2255 | + | |
2256 | + | void RNEMD::writeVector(int index, unsigned int bin) { |
2257 | + | if (!doRNEMD_) return; |
2258 | + | assert(index >=0 && index < ENDINDEX); |
2259 | + | assert(int(bin) < nBins_); |
2260 | + | Vector3d s; |
2261 | + | int count; |
2262 | + | |
2263 | + | count = data_[index].accumulator[bin]->count(); |
2264 | ||
2265 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
2266 | < | mHist_[j] = 0.0; |
2265 | > | if (count == 0) return; |
2266 | > | |
2267 | > | dynamic_cast<VectorAccumulator*>(data_[index].accumulator[bin])->getAverage(s); |
2268 | > | if (isinf(s[0]) || isnan(s[0]) || |
2269 | > | isinf(s[1]) || isnan(s[1]) || |
2270 | > | isinf(s[2]) || isnan(s[2]) ) { |
2271 | > | sprintf( painCave.errMsg, |
2272 | > | "RNEMD detected a numerical error writing: %s for bin %u", |
2273 | > | data_[index].title.c_str(), bin); |
2274 | > | painCave.isFatal = 1; |
2275 | > | simError(); |
2276 | > | } else { |
2277 | > | rnemdFile_ << "\t" << s[0] << "\t" << s[1] << "\t" << s[2]; |
2278 | } | |
2279 | < | if (outputTemp_) |
1562 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
1563 | < | tempCount_[j] = 0; |
1564 | < | tempHist_[j] = 0.0; |
1565 | < | } |
1566 | < | if (outputVx_) |
1567 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
1568 | < | //pxzCount_[j] = 0; |
1569 | < | pxzHist_[j] = 0.0; |
1570 | < | } |
1571 | < | if (outputVy_) |
1572 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
1573 | < | //pyzCount_[j] = 0; |
1574 | < | pyzHist_[j] = 0.0; |
1575 | < | } |
2279 | > | } |
2280 | ||
2281 | < | if (output3DTemp_) |
2282 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
2283 | < | xTempHist_[j] = 0.0; |
2284 | < | yTempHist_[j] = 0.0; |
2285 | < | zTempHist_[j] = 0.0; |
2286 | < | xyzTempCount_[j] = 0; |
2287 | < | } |
2288 | < | if (outputRotTemp_) |
2289 | < | for (j = 0; j < rnemdLogWidth_; j++) { |
2290 | < | rotTempCount_[j] = 0; |
2291 | < | rotTempHist_[j] = 0.0; |
2292 | < | } |
2281 | > | void RNEMD::writeRealStdDev(int index, unsigned int bin) { |
2282 | > | if (!doRNEMD_) return; |
2283 | > | assert(index >=0 && index < ENDINDEX); |
2284 | > | assert(int(bin) < nBins_); |
2285 | > | RealType s; |
2286 | > | int count; |
2287 | > | |
2288 | > | count = data_[index].accumulator[bin]->count(); |
2289 | > | if (count == 0) return; |
2290 | > | |
2291 | > | dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->getStdDev(s); |
2292 | > | |
2293 | > | if (! isinf(s) && ! isnan(s)) { |
2294 | > | rnemdFile_ << "\t" << s; |
2295 | > | } else{ |
2296 | > | sprintf( painCave.errMsg, |
2297 | > | "RNEMD detected a numerical error writing: %s std. dev. for bin %u", |
2298 | > | data_[index].title.c_str(), bin); |
2299 | > | painCave.isFatal = 1; |
2300 | > | simError(); |
2301 | > | } |
2302 | } | |
2303 | + | |
2304 | + | void RNEMD::writeVectorStdDev(int index, unsigned int bin) { |
2305 | + | if (!doRNEMD_) return; |
2306 | + | assert(index >=0 && index < ENDINDEX); |
2307 | + | assert(int(bin) < nBins_); |
2308 | + | Vector3d s; |
2309 | + | int count; |
2310 | + | |
2311 | + | count = data_[index].accumulator[bin]->count(); |
2312 | + | if (count == 0) return; |
2313 | + | |
2314 | + | dynamic_cast<VectorAccumulator*>(data_[index].accumulator[bin])->getStdDev(s); |
2315 | + | if (isinf(s[0]) || isnan(s[0]) || |
2316 | + | isinf(s[1]) || isnan(s[1]) || |
2317 | + | isinf(s[2]) || isnan(s[2]) ) { |
2318 | + | sprintf( painCave.errMsg, |
2319 | + | "RNEMD detected a numerical error writing: %s std. dev. for bin %u", |
2320 | + | data_[index].title.c_str(), bin); |
2321 | + | painCave.isFatal = 1; |
2322 | + | simError(); |
2323 | + | } else { |
2324 | + | rnemdFile_ << "\t" << s[0] << "\t" << s[1] << "\t" << s[2]; |
2325 | + | } |
2326 | + | } |
2327 | } | |
2328 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |