ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/rnemd/RNEMD.cpp
(Generate patch)

Comparing branches/development/src/rnemd/RNEMD.cpp (file contents):
Revision 1830 by gezelter, Wed Jan 9 22:02:30 2013 UTC vs.
Revision 1854 by gezelter, Thu Mar 28 20:54:06 2013 UTC

# 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 <sstream>
44 + #include <string>
45 +
46   #include "rnemd/RNEMD.hpp"
47   #include "math/Vector3.hpp"
48   #include "math/Vector.hpp"
# Line 49 | Line 52
52   #include "primitives/StuntDouble.hpp"
53   #include "utils/PhysicalConstants.hpp"
54   #include "utils/Tuple.hpp"
55 + #include "brains/Thermo.hpp"
56 + #include "math/ConvexHull.hpp"
57   #ifdef IS_MPI
58   #include <mpi.h>
59   #endif
# Line 64 | Line 69 | namespace OpenMD {
69   namespace OpenMD {
70    
71    RNEMD::RNEMD(SimInfo* info) : info_(info), evaluator_(info), seleMan_(info),
72 +                                evaluatorA_(info), seleManA_(info),
73 +                                commonA_(info), evaluatorB_(info),
74 +                                seleManB_(info), commonB_(info),
75                                  usePeriodicBoundaryConditions_(info->getSimParams()->getUsePeriodicBoundaryConditions()) {
76  
77      trialCount_ = 0;
78      failTrialCount_ = 0;
79      failRootCount_ = 0;
80  
81 <    Globals * simParams = info->getSimParams();
81 >    Globals* simParams = info->getSimParams();
82      RNEMDParameters* rnemdParams = simParams->getRNEMDParameters();
83  
84      doRNEMD_ = rnemdParams->getUseRNEMD();
# Line 85 | Line 93 | namespace OpenMD {
93      stringToFluxType_["Py"]  = rnemdPy;
94      stringToFluxType_["Pz"]  = rnemdPz;
95      stringToFluxType_["Pvector"]  = rnemdPvector;
96 +    stringToFluxType_["Lx"]  = rnemdLx;
97 +    stringToFluxType_["Ly"]  = rnemdLy;
98 +    stringToFluxType_["Lz"]  = rnemdLz;
99 +    stringToFluxType_["Lvector"]  = rnemdLvector;
100      stringToFluxType_["KE+Px"]  = rnemdKePx;
101      stringToFluxType_["KE+Py"]  = rnemdKePy;
102      stringToFluxType_["KE+Pvector"]  = rnemdKePvector;
103 +    stringToFluxType_["KE+Lx"]  = rnemdKeLx;
104 +    stringToFluxType_["KE+Ly"]  = rnemdKeLy;
105 +    stringToFluxType_["KE+Lz"]  = rnemdKeLz;
106 +    stringToFluxType_["KE+Lvector"]  = rnemdKeLvector;
107  
108      runTime_ = simParams->getRunTime();
109      statusTime_ = simParams->getStatusTime();
110  
95    rnemdObjectSelection_ = rnemdParams->getObjectSelection();
96    evaluator_.loadScriptString(rnemdObjectSelection_);
97    seleMan_.setSelectionSet(evaluator_.evaluate());
98
111      const string methStr = rnemdParams->getMethod();
112      bool hasFluxType = rnemdParams->haveFluxType();
113  
114 +    rnemdObjectSelection_ = rnemdParams->getObjectSelection();
115 +
116      string fluxStr;
117      if (hasFluxType) {
118        fluxStr = rnemdParams->getFluxType();
# Line 106 | Line 120 | namespace OpenMD {
120        sprintf(painCave.errMsg,
121                "RNEMD: No fluxType was set in the md file.  This parameter,\n"
122                "\twhich must be one of the following values:\n"
123 <              "\tKE, Px, Py, Pz, Pvector, KE+Px, KE+Py, KE+Pvector\n"
123 >              "\tKE, Px, Py, Pz, Pvector, Lx, Ly, Lz, Lvector,\n"
124 >              "\tKE+Px, KE+Py, KE+Pvector, KE+Lx, KE+Ly, KE+Lz, KE+Lvector\n"
125                "\tmust be set to use RNEMD\n");
126        painCave.isFatal = 1;
127        painCave.severity = OPENMD_ERROR;
# Line 116 | Line 131 | namespace OpenMD {
131      bool hasKineticFlux = rnemdParams->haveKineticFlux();
132      bool hasMomentumFlux = rnemdParams->haveMomentumFlux();
133      bool hasMomentumFluxVector = rnemdParams->haveMomentumFluxVector();
134 +    bool hasAngularMomentumFlux = rnemdParams->haveAngularMomentumFlux();
135 +    bool hasAngularMomentumFluxVector = rnemdParams->haveAngularMomentumFluxVector();
136 +    hasSelectionA_ = rnemdParams->haveSelectionA();
137 +    hasSelectionB_ = rnemdParams->haveSelectionB();
138      bool hasSlabWidth = rnemdParams->haveSlabWidth();
139      bool hasSlabACenter = rnemdParams->haveSlabACenter();
140      bool hasSlabBCenter = rnemdParams->haveSlabBCenter();
141 +    bool hasSphereARadius = rnemdParams->haveSphereARadius();
142 +    hasSphereBRadius_ = rnemdParams->haveSphereBRadius();
143 +    bool hasCoordinateOrigin = rnemdParams->haveCoordinateOrigin();
144      bool hasOutputFileName = rnemdParams->haveOutputFileName();
145      bool hasOutputFields = rnemdParams->haveOutputFields();
146      
# Line 203 | Line 225 | namespace OpenMD {
225        case rnemdPz:
226          hasCorrectFlux = hasMomentumFlux;
227          break;
228 +      case rnemdLx:
229 +      case rnemdLy:
230 +      case rnemdLz:
231 +        hasCorrectFlux = hasAngularMomentumFlux;
232 +        break;
233        case rnemdPvector:
234          hasCorrectFlux = hasMomentumFluxVector;
235          break;
236 +      case rnemdLvector:
237 +        hasCorrectFlux = hasAngularMomentumFluxVector;
238 +        break;
239        case rnemdKePx:
240        case rnemdKePy:
241          hasCorrectFlux = hasMomentumFlux && hasKineticFlux;
242 +        break;
243 +      case rnemdKeLx:
244 +      case rnemdKeLy:
245 +      case rnemdKeLz:
246 +        hasCorrectFlux = hasAngularMomentumFlux && hasKineticFlux;
247          break;
248        case rnemdKePvector:
249          hasCorrectFlux = hasMomentumFluxVector && hasKineticFlux;
250          break;
251 +      case rnemdKeLvector:
252 +        hasCorrectFlux = hasAngularMomentumFluxVector && hasKineticFlux;
253 +        break;
254        default:
255          methodFluxMismatch = true;
256          break;
# Line 235 | Line 273 | namespace OpenMD {
273        sprintf(painCave.errMsg,
274                "RNEMD: The current method, %s, and flux type, %s,\n"
275                "\tdid not have the correct flux value specified. Options\n"
276 <              "\tinclude: kineticFlux, momentumFlux, and momentumFluxVector\n",
276 >              "\tinclude: kineticFlux, momentumFlux, angularMomentumFlux,\n"
277 >              "\tmomentumFluxVector, and angularMomentumFluxVector.\n",
278                methStr.c_str(), fluxStr.c_str());
279        painCave.isFatal = 1;
280        painCave.severity = OPENMD_ERROR;
# Line 275 | Line 314 | namespace OpenMD {
314          default:
315            break;
316          }
317 <      }    
318 <    }
317 >      }
318 >      if (hasAngularMomentumFluxVector) {
319 >        angularMomentumFluxVector_ = rnemdParams->getAngularMomentumFluxVector();
320 >      } else {
321 >        angularMomentumFluxVector_ = V3Zero;
322 >        if (hasAngularMomentumFlux) {
323 >          RealType angularMomentumFlux = rnemdParams->getAngularMomentumFlux();
324 >          switch (rnemdFluxType_) {
325 >          case rnemdLx:
326 >            angularMomentumFluxVector_.x() = angularMomentumFlux;
327 >            break;
328 >          case rnemdLy:
329 >            angularMomentumFluxVector_.y() = angularMomentumFlux;
330 >            break;
331 >          case rnemdLz:
332 >            angularMomentumFluxVector_.z() = angularMomentumFlux;
333 >            break;
334 >          case rnemdKeLx:
335 >            angularMomentumFluxVector_.x() = angularMomentumFlux;
336 >            break;
337 >          case rnemdKeLy:
338 >            angularMomentumFluxVector_.y() = angularMomentumFlux;
339 >            break;
340 >          case rnemdKeLz:
341 >            angularMomentumFluxVector_.z() = angularMomentumFlux;
342 >            break;
343 >          default:
344 >            break;
345 >          }
346 >        }        
347 >      }
348  
349 <    // do some sanity checking
350 <
351 <    int selectionCount = seleMan_.getSelectionCount();
349 >      if (hasCoordinateOrigin) {
350 >        coordinateOrigin_ = rnemdParams->getCoordinateOrigin();
351 >      } else {
352 >        coordinateOrigin_ = V3Zero;
353 >      }
354  
355 <    int nIntegrable = info->getNGlobalIntegrableObjects();
355 >      // do some sanity checking
356  
357 <    if (selectionCount > nIntegrable) {
288 <      sprintf(painCave.errMsg,
289 <              "RNEMD: The current objectSelection,\n"
290 <              "\t\t%s\n"
291 <              "\thas resulted in %d selected objects.  However,\n"
292 <              "\tthe total number of integrable objects in the system\n"
293 <              "\tis only %d.  This is almost certainly not what you want\n"
294 <              "\tto do.  A likely cause of this is forgetting the _RB_0\n"
295 <              "\tselector in the selection script!\n",
296 <              rnemdObjectSelection_.c_str(),
297 <              selectionCount, nIntegrable);
298 <      painCave.isFatal = 0;
299 <      painCave.severity = OPENMD_WARNING;
300 <      simError();
301 <    }
357 >      int selectionCount = seleMan_.getSelectionCount();
358  
359 <    areaAccumulator_ = new Accumulator();
359 >      int nIntegrable = info->getNGlobalIntegrableObjects();
360  
361 <    nBins_ = rnemdParams->getOutputBins();
361 >      if (selectionCount > nIntegrable) {
362 >        sprintf(painCave.errMsg,
363 >                "RNEMD: The current objectSelection,\n"
364 >                "\t\t%s\n"
365 >                "\thas resulted in %d selected objects.  However,\n"
366 >                "\tthe total number of integrable objects in the system\n"
367 >                "\tis only %d.  This is almost certainly not what you want\n"
368 >                "\tto do.  A likely cause of this is forgetting the _RB_0\n"
369 >                "\tselector in the selection script!\n",
370 >                rnemdObjectSelection_.c_str(),
371 >                selectionCount, nIntegrable);
372 >        painCave.isFatal = 0;
373 >        painCave.severity = OPENMD_WARNING;
374 >        simError();
375 >      }
376  
377 <    data_.resize(RNEMD::ENDINDEX);
308 <    OutputData z;
309 <    z.units =  "Angstroms";
310 <    z.title =  "Z";
311 <    z.dataType = "RealType";
312 <    z.accumulator.reserve(nBins_);
313 <    for (int i = 0; i < nBins_; i++)
314 <      z.accumulator.push_back( new Accumulator() );
315 <    data_[Z] = z;
316 <    outputMap_["Z"] =  Z;
377 >      areaAccumulator_ = new Accumulator();
378  
379 <    OutputData temperature;
380 <    temperature.units =  "K";
320 <    temperature.title =  "Temperature";
321 <    temperature.dataType = "RealType";
322 <    temperature.accumulator.reserve(nBins_);
323 <    for (int i = 0; i < nBins_; i++)
324 <      temperature.accumulator.push_back( new Accumulator() );
325 <    data_[TEMPERATURE] = temperature;
326 <    outputMap_["TEMPERATURE"] =  TEMPERATURE;
379 >      nBins_ = rnemdParams->getOutputBins();
380 >      binWidth_ = rnemdParams->getOutputBinWidth();
381  
382 <    OutputData velocity;
383 <    velocity.units = "angstroms/fs";
384 <    velocity.title =  "Velocity";  
385 <    velocity.dataType = "Vector3d";
386 <    velocity.accumulator.reserve(nBins_);
387 <    for (int i = 0; i < nBins_; i++)
388 <      velocity.accumulator.push_back( new VectorAccumulator() );
389 <    data_[VELOCITY] = velocity;
390 <    outputMap_["VELOCITY"] = VELOCITY;
382 >      data_.resize(RNEMD::ENDINDEX);
383 >      OutputData z;
384 >      z.units =  "Angstroms";
385 >      z.title =  "Z";
386 >      z.dataType = "RealType";
387 >      z.accumulator.reserve(nBins_);
388 >      for (int i = 0; i < nBins_; i++)
389 >        z.accumulator.push_back( new Accumulator() );
390 >      data_[Z] = z;
391 >      outputMap_["Z"] =  Z;
392  
393 <    OutputData density;
394 <    density.units =  "g cm^-3";
395 <    density.title =  "Density";
396 <    density.dataType = "RealType";
397 <    density.accumulator.reserve(nBins_);
398 <    for (int i = 0; i < nBins_; i++)
399 <      density.accumulator.push_back( new Accumulator() );
400 <    data_[DENSITY] = density;
401 <    outputMap_["DENSITY"] =  DENSITY;
393 >      OutputData r;
394 >      r.units =  "Angstroms";
395 >      r.title =  "R";
396 >      r.dataType = "RealType";
397 >      r.accumulator.reserve(nBins_);
398 >      for (int i = 0; i < nBins_; i++)
399 >        r.accumulator.push_back( new Accumulator() );
400 >      data_[R] = r;
401 >      outputMap_["R"] =  R;
402  
403 <    if (hasOutputFields) {
404 <      parseOutputFileFormat(rnemdParams->getOutputFields());
405 <    } else {
406 <      outputMask_.set(Z);
407 <      switch (rnemdFluxType_) {
408 <      case rnemdKE:
409 <      case rnemdRotKE:
410 <      case rnemdFullKE:
411 <        outputMask_.set(TEMPERATURE);
412 <        break;
413 <      case rnemdPx:
414 <      case rnemdPy:
415 <        outputMask_.set(VELOCITY);
416 <        break;
417 <      case rnemdPz:        
418 <      case rnemdPvector:
419 <        outputMask_.set(VELOCITY);
420 <        outputMask_.set(DENSITY);
421 <        break;
422 <      case rnemdKePx:
423 <      case rnemdKePy:
424 <        outputMask_.set(TEMPERATURE);
425 <        outputMask_.set(VELOCITY);
426 <        break;
427 <      case rnemdKePvector:
428 <        outputMask_.set(TEMPERATURE);
429 <        outputMask_.set(VELOCITY);
430 <        outputMask_.set(DENSITY);        
431 <        break;
432 <      default:
433 <        break;
403 >      OutputData temperature;
404 >      temperature.units =  "K";
405 >      temperature.title =  "Temperature";
406 >      temperature.dataType = "RealType";
407 >      temperature.accumulator.reserve(nBins_);
408 >      for (int i = 0; i < nBins_; i++)
409 >        temperature.accumulator.push_back( new Accumulator() );
410 >      data_[TEMPERATURE] = temperature;
411 >      outputMap_["TEMPERATURE"] =  TEMPERATURE;
412 >
413 >      OutputData velocity;
414 >      velocity.units = "angstroms/fs";
415 >      velocity.title =  "Velocity";  
416 >      velocity.dataType = "Vector3d";
417 >      velocity.accumulator.reserve(nBins_);
418 >      for (int i = 0; i < nBins_; i++)
419 >        velocity.accumulator.push_back( new VectorAccumulator() );
420 >      data_[VELOCITY] = velocity;
421 >      outputMap_["VELOCITY"] = VELOCITY;
422 >
423 >      OutputData density;
424 >      density.units =  "g cm^-3";
425 >      density.title =  "Density";
426 >      density.dataType = "RealType";
427 >      density.accumulator.reserve(nBins_);
428 >      for (int i = 0; i < nBins_; i++)
429 >        density.accumulator.push_back( new Accumulator() );
430 >      data_[DENSITY] = density;
431 >      outputMap_["DENSITY"] =  DENSITY;
432 >
433 >      if (hasOutputFields) {
434 >        parseOutputFileFormat(rnemdParams->getOutputFields());
435 >      } else {
436 >        if (usePeriodicBoundaryConditions_)
437 >          outputMask_.set(Z);
438 >        else
439 >          outputMask_.set(R);
440 >        switch (rnemdFluxType_) {
441 >        case rnemdKE:
442 >        case rnemdRotKE:
443 >        case rnemdFullKE:
444 >          outputMask_.set(TEMPERATURE);
445 >          break;
446 >        case rnemdPx:
447 >        case rnemdPy:
448 >          outputMask_.set(VELOCITY);
449 >          break;
450 >        case rnemdPz:        
451 >        case rnemdPvector:
452 >          outputMask_.set(VELOCITY);
453 >          outputMask_.set(DENSITY);
454 >          break;
455 >        case rnemdLx:
456 >        case rnemdLy:
457 >        case rnemdLz:
458 >        case rnemdLvector:
459 >          outputMask_.set(ANGULARVELOCITY);
460 >          break;
461 >        case rnemdKeLx:
462 >        case rnemdKeLy:
463 >        case rnemdKeLz:
464 >        case rnemdKeLvector:
465 >          outputMask_.set(TEMPERATURE);
466 >          outputMask_.set(ANGULARVELOCITY);
467 >          break;
468 >        case rnemdKePx:
469 >        case rnemdKePy:
470 >          outputMask_.set(TEMPERATURE);
471 >          outputMask_.set(VELOCITY);
472 >          break;
473 >        case rnemdKePvector:
474 >          outputMask_.set(TEMPERATURE);
475 >          outputMask_.set(VELOCITY);
476 >          outputMask_.set(DENSITY);        
477 >          break;
478 >        default:
479 >          break;
480 >        }
481        }
380    }
482        
483 <    if (hasOutputFileName) {
484 <      rnemdFileName_ = rnemdParams->getOutputFileName();
485 <    } else {
486 <      rnemdFileName_ = getPrefix(info->getFinalConfigFileName()) + ".rnemd";
487 <    }          
483 >      if (hasOutputFileName) {
484 >        rnemdFileName_ = rnemdParams->getOutputFileName();
485 >      } else {
486 >        rnemdFileName_ = getPrefix(info->getFinalConfigFileName()) + ".rnemd";
487 >      }          
488  
489 <    exchangeTime_ = rnemdParams->getExchangeTime();
489 >      exchangeTime_ = rnemdParams->getExchangeTime();
490  
491 <    Snapshot* currentSnap_ = info->getSnapshotManager()->getCurrentSnapshot();
492 <    Mat3x3d hmat = currentSnap_->getHmat();
392 <  
393 <    // Target exchange quantities (in each exchange) =  2 Lx Ly dt flux
394 <    // Lx, Ly = box dimensions in x & y
395 <    // dt = exchange time interval
396 <    // flux = target flux
491 >      Snapshot* currentSnap_ = info->getSnapshotManager()->getCurrentSnapshot();
492 >      // total exchange sums are zeroed out at the beginning:
493  
494 <    RealType area = currentSnap_->getXYarea();
495 <    kineticTarget_ = 2.0 * kineticFlux_ * exchangeTime_ * area;
496 <    momentumTarget_ = 2.0 * momentumFluxVector_ * exchangeTime_ * area;
494 >      kineticExchange_ = 0.0;
495 >      momentumExchange_ = V3Zero;
496 >      angularMomentumExchange_ = V3Zero;
497  
498 <    // total exchange sums are zeroed out at the beginning:
499 <
404 <    kineticExchange_ = 0.0;
405 <    momentumExchange_ = V3Zero;
406 <
407 <    if (hasSlabWidth)
408 <      slabWidth_ = rnemdParams->getSlabWidth();
409 <    else
410 <      slabWidth_ = hmat(2,2) / 10.0;
411 <  
412 <    if (hasSlabACenter)
413 <      slabACenter_ = rnemdParams->getSlabACenter();
414 <    else
415 <      slabACenter_ = 0.0;
498 >      std::ostringstream selectionAstream;
499 >      std::ostringstream selectionBstream;
500      
501 <    if (hasSlabBCenter)
502 <      slabBCenter_ = rnemdParams->getSlabBCenter();
503 <    else
504 <      slabBCenter_ = hmat(2,2) / 2.0;
501 >      if (hasSelectionA_) {
502 >        selectionA_ = rnemdParams->getSelectionA();
503 >      } else {
504 >        if (usePeriodicBoundaryConditions_) {    
505 >          Mat3x3d hmat = currentSnap_->getHmat();
506 >        
507 >          if (hasSlabWidth)
508 >            slabWidth_ = rnemdParams->getSlabWidth();
509 >          else
510 >            slabWidth_ = hmat(2,2) / 10.0;
511 >        
512 >          if (hasSlabACenter)
513 >            slabACenter_ = rnemdParams->getSlabACenter();
514 >          else
515 >            slabACenter_ = 0.0;
516 >        
517 >          selectionAstream << "select wrappedz > "
518 >                           << slabACenter_ - 0.5*slabWidth_
519 >                           <<  " && wrappedz < "
520 >                           << slabACenter_ + 0.5*slabWidth_;
521 >          selectionA_ = selectionAstream.str();
522 >        } else {
523 >          if (hasSphereARadius)
524 >            sphereARadius_ = rnemdParams->getSphereARadius();
525 >          else {
526 >            // use an initial guess to the size of the inner slab to be 1/10 the
527 >            // radius of an approximately spherical hull:
528 >            Thermo thermo(info);
529 >            RealType hVol = thermo.getHullVolume();
530 >            sphereARadius_ = 0.1 * pow((3.0 * hVol / (4.0 * M_PI)), 1.0/3.0);
531 >          }
532 >          selectionAstream << "select r < " << sphereARadius_;
533 >          selectionA_ = selectionAstream.str();
534 >        }
535 >      }
536      
537 +      if (hasSelectionB_) {
538 +        selectionB_ = rnemdParams->getSelectionB();
539 +      } else {
540 +        if (usePeriodicBoundaryConditions_) {    
541 +          Mat3x3d hmat = currentSnap_->getHmat();
542 +        
543 +          if (hasSlabWidth)
544 +            slabWidth_ = rnemdParams->getSlabWidth();
545 +          else
546 +            slabWidth_ = hmat(2,2) / 10.0;
547 +        
548 +          if (hasSlabBCenter)
549 +            slabBCenter_ = rnemdParams->getSlabACenter();
550 +          else
551 +            slabBCenter_ = hmat(2,2) / 2.0;
552 +        
553 +          selectionBstream << "select wrappedz > "
554 +                           << slabBCenter_ - 0.5*slabWidth_
555 +                           <<  " && wrappedz < "
556 +                           << slabBCenter_ + 0.5*slabWidth_;
557 +          selectionB_ = selectionBstream.str();
558 +        } else {
559 +          if (hasSphereBRadius_) {
560 +            sphereBRadius_ = rnemdParams->getSphereBRadius();
561 +            selectionBstream << "select r > " << sphereBRadius_;
562 +            selectionB_ = selectionBstream.str();
563 +          } else {
564 +            selectionB_ = "select hull";
565 +            hasSelectionB_ = true;
566 +          }
567 +        }
568 +      }
569 +    }
570 +    // object evaluator:
571 +    evaluator_.loadScriptString(rnemdObjectSelection_);
572 +    seleMan_.setSelectionSet(evaluator_.evaluate());
573 +    
574 +    evaluatorA_.loadScriptString(selectionA_);
575 +    evaluatorB_.loadScriptString(selectionB_);
576 +    
577 +    seleManA_.setSelectionSet(evaluatorA_.evaluate());
578 +    seleManB_.setSelectionSet(evaluatorB_.evaluate());
579 +    
580 +    commonA_ = seleManA_ & seleMan_;
581 +    commonB_ = seleManB_ & seleMan_;    
582    }
583 <  
583 >  
584 >    
585    RNEMD::~RNEMD() {
586      if (!doRNEMD_) return;
587   #ifdef IS_MPI
# Line 436 | Line 597 | namespace OpenMD {
597   #endif
598    }
599    
600 <  bool RNEMD::inSlabA(Vector3d pos) {
440 <    return (abs(pos.z() - slabACenter_) < 0.5*slabWidth_);
441 <  }
442 <  bool RNEMD::inSlabB(Vector3d pos) {
443 <    return (abs(pos.z() - slabBCenter_) < 0.5*slabWidth_);
444 <  }
445 <
446 <  void RNEMD::doSwap() {
600 >  void RNEMD::doSwap(SelectionManager& smanA, SelectionManager& smanB) {
601      if (!doRNEMD_) return;
602 +    int selei;
603 +    int selej;
604 +
605      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
606      Mat3x3d hmat = currentSnap_->getHmat();
607  
451    seleMan_.setSelectionSet(evaluator_.evaluate());
452
453    int selei;
608      StuntDouble* sd;
609  
610      RealType min_val;
# Line 461 | Line 615 | namespace OpenMD {
615      bool max_found = false;
616      StuntDouble* max_sd;
617  
618 <    for (sd = seleMan_.beginSelected(selei); sd != NULL;
619 <         sd = seleMan_.nextSelected(selei)) {
618 >    for (sd = seleManA_.beginSelected(selei); sd != NULL;
619 >         sd = seleManA_.nextSelected(selei)) {
620  
621        Vector3d pos = sd->getPos();
622 <
622 >      
623        // wrap the stuntdouble's position back into the box:
624 <
624 >      
625        if (usePeriodicBoundaryConditions_)
626          currentSnap_->wrapVector(pos);
627 <      bool inA = inSlabA(pos);
628 <      bool inB = inSlabB(pos);
629 <
630 <      if (inA || inB) {
627 >      
628 >      RealType mass = sd->getMass();
629 >      Vector3d vel = sd->getVel();
630 >      RealType value;
631 >      
632 >      switch(rnemdFluxType_) {
633 >      case rnemdKE :
634          
635 <        RealType mass = sd->getMass();
636 <        Vector3d vel = sd->getVel();
637 <        RealType value;
638 <        
639 <        switch(rnemdFluxType_) {
483 <        case rnemdKE :
635 >        value = mass * vel.lengthSquare();
636 >        
637 >        if (sd->isDirectional()) {
638 >          Vector3d angMom = sd->getJ();
639 >          Mat3x3d I = sd->getI();
640            
641 <          value = mass * vel.lengthSquare();
642 <          
643 <          if (sd->isDirectional()) {
644 <            Vector3d angMom = sd->getJ();
645 <            Mat3x3d I = sd->getI();
646 <            
647 <            if (sd->isLinear()) {
648 <              int i = sd->linearAxis();
649 <              int j = (i + 1) % 3;
650 <              int k = (i + 2) % 3;
651 <              value += angMom[j] * angMom[j] / I(j, j) +
652 <                angMom[k] * angMom[k] / I(k, k);
653 <            } else {                        
654 <              value += angMom[0]*angMom[0]/I(0, 0)
655 <                + angMom[1]*angMom[1]/I(1, 1)
656 <                + angMom[2]*angMom[2]/I(2, 2);
657 <            }
658 <          } //angular momenta exchange enabled
659 <          value *= 0.5;
660 <          break;
661 <        case rnemdPx :
662 <          value = mass * vel[0];
663 <          break;
664 <        case rnemdPy :
665 <          value = mass * vel[1];
666 <          break;
667 <        case rnemdPz :
668 <          value = mass * vel[2];
669 <          break;
670 <        default :
671 <          break;
641 >          if (sd->isLinear()) {
642 >            int i = sd->linearAxis();
643 >            int j = (i + 1) % 3;
644 >            int k = (i + 2) % 3;
645 >            value += angMom[j] * angMom[j] / I(j, j) +
646 >              angMom[k] * angMom[k] / I(k, k);
647 >          } else {                        
648 >            value += angMom[0]*angMom[0]/I(0, 0)
649 >              + angMom[1]*angMom[1]/I(1, 1)
650 >              + angMom[2]*angMom[2]/I(2, 2);
651 >          }
652 >        } //angular momenta exchange enabled
653 >        value *= 0.5;
654 >        break;
655 >      case rnemdPx :
656 >        value = mass * vel[0];
657 >        break;
658 >      case rnemdPy :
659 >        value = mass * vel[1];
660 >        break;
661 >      case rnemdPz :
662 >        value = mass * vel[2];
663 >        break;
664 >      default :
665 >        break;
666 >      }
667 >      if (!max_found) {
668 >        max_val = value;
669 >        max_sd = sd;
670 >        max_found = true;
671 >      } else {
672 >        if (max_val < value) {
673 >          max_val = value;
674 >          max_sd = sd;
675          }
676 +      }  
677 +    }
678          
679 <        if (inA == 0) {
680 <          if (!min_found) {
681 <            min_val = value;
682 <            min_sd = sd;
683 <            min_found = true;
684 <          } else {
685 <            if (min_val > value) {
686 <              min_val = value;
687 <              min_sd = sd;
688 <            }
689 <          }
690 <        } else {
691 <          if (!max_found) {
692 <            max_val = value;
693 <            max_sd = sd;
694 <            max_found = true;
695 <          } else {
696 <            if (max_val < value) {
697 <              max_val = value;
698 <              max_sd = sd;
699 <            }
700 <          }      
701 <        }
679 >    for (sd = seleManB_.beginSelected(selej); sd != NULL;
680 >         sd = seleManB_.nextSelected(selej)) {
681 >
682 >      Vector3d pos = sd->getPos();
683 >      
684 >      // wrap the stuntdouble's position back into the box:
685 >      
686 >      if (usePeriodicBoundaryConditions_)
687 >        currentSnap_->wrapVector(pos);
688 >      
689 >      RealType mass = sd->getMass();
690 >      Vector3d vel = sd->getVel();
691 >      RealType value;
692 >      
693 >      switch(rnemdFluxType_) {
694 >      case rnemdKE :
695 >        
696 >        value = mass * vel.lengthSquare();
697 >        
698 >        if (sd->isDirectional()) {
699 >          Vector3d angMom = sd->getJ();
700 >          Mat3x3d I = sd->getI();
701 >          
702 >          if (sd->isLinear()) {
703 >            int i = sd->linearAxis();
704 >            int j = (i + 1) % 3;
705 >            int k = (i + 2) % 3;
706 >            value += angMom[j] * angMom[j] / I(j, j) +
707 >              angMom[k] * angMom[k] / I(k, k);
708 >          } else {                        
709 >            value += angMom[0]*angMom[0]/I(0, 0)
710 >              + angMom[1]*angMom[1]/I(1, 1)
711 >              + angMom[2]*angMom[2]/I(2, 2);
712 >          }
713 >        } //angular momenta exchange enabled
714 >        value *= 0.5;
715 >        break;
716 >      case rnemdPx :
717 >        value = mass * vel[0];
718 >        break;
719 >      case rnemdPy :
720 >        value = mass * vel[1];
721 >        break;
722 >      case rnemdPz :
723 >        value = mass * vel[2];
724 >        break;
725 >      default :
726 >        break;
727 >      }
728 >      
729 >      if (!min_found) {
730 >        min_val = value;
731 >        min_sd = sd;
732 >        min_found = true;
733 >      } else {
734 >        if (min_val > value) {
735 >          min_val = value;
736 >          min_sd = sd;
737 >        }
738        }
739      }
740      
# Line 767 | Line 964 | namespace OpenMD {
964      }    
965    }
966    
967 <  void RNEMD::doNIVS() {
967 >  void RNEMD::doNIVS(SelectionManager& smanA, SelectionManager& smanB) {
968      if (!doRNEMD_) return;
969 +    int selei;
970 +    int selej;
971 +
972      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
973 +    RealType time = currentSnap_->getTime();    
974      Mat3x3d hmat = currentSnap_->getHmat();
975  
775    seleMan_.setSelectionSet(evaluator_.evaluate());
776
777    int selei;
976      StuntDouble* sd;
977  
978      vector<StuntDouble*> hotBin, coldBin;
# Line 794 | Line 992 | namespace OpenMD {
992      RealType Kcz = 0.0;
993      RealType Kcw = 0.0;
994  
995 <    for (sd = seleMan_.beginSelected(selei); sd != NULL;
996 <         sd = seleMan_.nextSelected(selei)) {
995 >    for (sd = smanA.beginSelected(selei); sd != NULL;
996 >         sd = smanA.nextSelected(selei)) {
997  
998        Vector3d pos = sd->getPos();
999 <
999 >      
1000        // wrap the stuntdouble's position back into the box:
1001 <
1001 >      
1002        if (usePeriodicBoundaryConditions_)
1003          currentSnap_->wrapVector(pos);
1004 +      
1005 +      
1006 +      RealType mass = sd->getMass();
1007 +      Vector3d vel = sd->getVel();
1008 +      
1009 +      hotBin.push_back(sd);
1010 +      Phx += mass * vel.x();
1011 +      Phy += mass * vel.y();
1012 +      Phz += mass * vel.z();
1013 +      Khx += mass * vel.x() * vel.x();
1014 +      Khy += mass * vel.y() * vel.y();
1015 +      Khz += mass * vel.z() * vel.z();
1016 +      if (sd->isDirectional()) {
1017 +        Vector3d angMom = sd->getJ();
1018 +        Mat3x3d I = sd->getI();
1019 +        if (sd->isLinear()) {
1020 +          int i = sd->linearAxis();
1021 +          int j = (i + 1) % 3;
1022 +          int k = (i + 2) % 3;
1023 +          Khw += angMom[j] * angMom[j] / I(j, j) +
1024 +            angMom[k] * angMom[k] / I(k, k);
1025 +        } else {
1026 +          Khw += angMom[0]*angMom[0]/I(0, 0)
1027 +            + angMom[1]*angMom[1]/I(1, 1)
1028 +            + angMom[2]*angMom[2]/I(2, 2);
1029 +        }
1030 +      }
1031 +    }
1032 +    for (sd = smanB.beginSelected(selej); sd != NULL;
1033 +         sd = smanB.nextSelected(selej)) {
1034 +      Vector3d pos = sd->getPos();
1035 +      
1036 +      // wrap the stuntdouble's position back into the box:
1037 +      
1038 +      if (usePeriodicBoundaryConditions_)
1039 +        currentSnap_->wrapVector(pos);
1040 +            
1041 +      RealType mass = sd->getMass();
1042 +      Vector3d vel = sd->getVel();
1043  
1044 <      // which bin is this stuntdouble in?
1045 <      bool inA = inSlabA(pos);
1046 <      bool inB = inSlabB(pos);
1047 <
1048 <      if (inA || inB) {
1049 <              
1050 <        RealType mass = sd->getMass();
1051 <        Vector3d vel = sd->getVel();
1052 <      
1053 <        if (inA) {
1054 <          hotBin.push_back(sd);
1055 <          Phx += mass * vel.x();
1056 <          Phy += mass * vel.y();
1057 <          Phz += mass * vel.z();
1058 <          Khx += mass * vel.x() * vel.x();
1059 <          Khy += mass * vel.y() * vel.y();
1060 <          Khz += mass * vel.z() * vel.z();
1061 <          if (sd->isDirectional()) {
1062 <            Vector3d angMom = sd->getJ();
1063 <            Mat3x3d I = sd->getI();
1064 <            if (sd->isLinear()) {
828 <              int i = sd->linearAxis();
829 <              int j = (i + 1) % 3;
830 <              int k = (i + 2) % 3;
831 <              Khw += angMom[j] * angMom[j] / I(j, j) +
832 <                angMom[k] * angMom[k] / I(k, k);
833 <            } else {
834 <              Khw += angMom[0]*angMom[0]/I(0, 0)
835 <                + angMom[1]*angMom[1]/I(1, 1)
836 <                + angMom[2]*angMom[2]/I(2, 2);
837 <            }
838 <          }
839 <        } else {
840 <          coldBin.push_back(sd);
841 <          Pcx += mass * vel.x();
842 <          Pcy += mass * vel.y();
843 <          Pcz += mass * vel.z();
844 <          Kcx += mass * vel.x() * vel.x();
845 <          Kcy += mass * vel.y() * vel.y();
846 <          Kcz += mass * vel.z() * vel.z();
847 <          if (sd->isDirectional()) {
848 <            Vector3d angMom = sd->getJ();
849 <            Mat3x3d I = sd->getI();
850 <            if (sd->isLinear()) {
851 <              int i = sd->linearAxis();
852 <              int j = (i + 1) % 3;
853 <              int k = (i + 2) % 3;
854 <              Kcw += angMom[j] * angMom[j] / I(j, j) +
855 <                angMom[k] * angMom[k] / I(k, k);
856 <            } else {
857 <              Kcw += angMom[0]*angMom[0]/I(0, 0)
858 <                + angMom[1]*angMom[1]/I(1, 1)
859 <                + angMom[2]*angMom[2]/I(2, 2);
860 <            }
861 <          }
862 <        }
1044 >      coldBin.push_back(sd);
1045 >      Pcx += mass * vel.x();
1046 >      Pcy += mass * vel.y();
1047 >      Pcz += mass * vel.z();
1048 >      Kcx += mass * vel.x() * vel.x();
1049 >      Kcy += mass * vel.y() * vel.y();
1050 >      Kcz += mass * vel.z() * vel.z();
1051 >      if (sd->isDirectional()) {
1052 >        Vector3d angMom = sd->getJ();
1053 >        Mat3x3d I = sd->getI();
1054 >        if (sd->isLinear()) {
1055 >          int i = sd->linearAxis();
1056 >          int j = (i + 1) % 3;
1057 >          int k = (i + 2) % 3;
1058 >          Kcw += angMom[j] * angMom[j] / I(j, j) +
1059 >            angMom[k] * angMom[k] / I(k, k);
1060 >        } else {
1061 >          Kcw += angMom[0]*angMom[0]/I(0, 0)
1062 >            + angMom[1]*angMom[1]/I(1, 1)
1063 >            + angMom[2]*angMom[2]/I(2, 2);
1064 >        }
1065        }
1066      }
1067      
# Line 1209 | Line 1411 | namespace OpenMD {
1411        failTrialCount_++;
1412      }
1413    }
1414 <
1415 <  void RNEMD::doVSS() {
1414 >  
1415 >  void RNEMD::doVSS(SelectionManager& smanA, SelectionManager& smanB) {
1416      if (!doRNEMD_) return;
1417 +    int selei;
1418 +    int selej;
1419 +
1420      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
1421      RealType time = currentSnap_->getTime();    
1422      Mat3x3d hmat = currentSnap_->getHmat();
1423  
1219    seleMan_.setSelectionSet(evaluator_.evaluate());
1220
1221    int selei;
1424      StuntDouble* sd;
1425  
1426      vector<StuntDouble*> hotBin, coldBin;
1427  
1428      Vector3d Ph(V3Zero);
1429 +    Vector3d Lh(V3Zero);
1430      RealType Mh = 0.0;
1431 +    Mat3x3d Ih(0.0);
1432      RealType Kh = 0.0;
1433      Vector3d Pc(V3Zero);
1434 +    Vector3d Lc(V3Zero);
1435      RealType Mc = 0.0;
1436 +    Mat3x3d Ic(0.0);
1437      RealType Kc = 0.0;
1438      
1439 +    for (sd = smanA.beginSelected(selei); sd != NULL;
1440 +         sd = smanA.nextSelected(selei)) {
1441  
1234    for (sd = seleMan_.beginSelected(selei); sd != NULL;
1235         sd = seleMan_.nextSelected(selei)) {
1236
1442        Vector3d pos = sd->getPos();
1443  
1444        // wrap the stuntdouble's position back into the box:
1445 +      
1446 +      if (usePeriodicBoundaryConditions_)
1447 +        currentSnap_->wrapVector(pos);
1448 +      
1449 +      RealType mass = sd->getMass();
1450 +      Vector3d vel = sd->getVel();
1451 +      Vector3d rPos = sd->getPos() - coordinateOrigin_;
1452 +      RealType r2;
1453 +      
1454 +      hotBin.push_back(sd);
1455 +      Ph += mass * vel;
1456 +      Mh += mass;
1457 +      Kh += mass * vel.lengthSquare();
1458 +      Lh += mass * cross(rPos, vel);
1459 +      Ih -= outProduct(rPos, rPos) * mass;
1460 +      r2 = rPos.lengthSquare();
1461 +      Ih(0, 0) += mass * r2;
1462 +      Ih(1, 1) += mass * r2;
1463 +      Ih(2, 2) += mass * r2;
1464 +      
1465 +      if (rnemdFluxType_ == rnemdFullKE) {
1466 +        if (sd->isDirectional()) {
1467 +          Vector3d angMom = sd->getJ();
1468 +          Mat3x3d I = sd->getI();
1469 +          if (sd->isLinear()) {
1470 +            int i = sd->linearAxis();
1471 +            int j = (i + 1) % 3;
1472 +            int k = (i + 2) % 3;
1473 +            Kh += angMom[j] * angMom[j] / I(j, j) +
1474 +              angMom[k] * angMom[k] / I(k, k);
1475 +          } else {
1476 +            Kh += angMom[0] * angMom[0] / I(0, 0) +
1477 +              angMom[1] * angMom[1] / I(1, 1) +
1478 +              angMom[2] * angMom[2] / I(2, 2);
1479 +          }
1480 +        }
1481 +      }
1482 +    }
1483 +    for (sd = smanB.beginSelected(selej); sd != NULL;
1484 +         sd = smanB.nextSelected(selej)) {
1485  
1486 +      Vector3d pos = sd->getPos();
1487 +      
1488 +      // wrap the stuntdouble's position back into the box:
1489 +      
1490        if (usePeriodicBoundaryConditions_)
1491          currentSnap_->wrapVector(pos);
1492 +      
1493 +      RealType mass = sd->getMass();
1494 +      Vector3d vel = sd->getVel();
1495 +      Vector3d rPos = sd->getPos() - coordinateOrigin_;
1496 +      RealType r2;
1497  
1498 <      // which bin is this stuntdouble in?
1499 <      bool inA = inSlabA(pos);
1500 <      bool inB = inSlabB(pos);
1498 >      coldBin.push_back(sd);
1499 >      Pc += mass * vel;
1500 >      Mc += mass;
1501 >      Kc += mass * vel.lengthSquare();
1502 >      Lc += mass * cross(rPos, vel);
1503 >      Ic -= outProduct(rPos, rPos) * mass;
1504 >      r2 = rPos.lengthSquare();
1505 >      Ic(0, 0) += mass * r2;
1506 >      Ic(1, 1) += mass * r2;
1507 >      Ic(2, 2) += mass * r2;
1508        
1509 <      if (inA || inB) {
1510 <        
1511 <        RealType mass = sd->getMass();
1512 <        Vector3d vel = sd->getVel();
1513 <      
1514 <        if (inA) {
1515 <          hotBin.push_back(sd);
1516 <          Ph += mass * vel;
1517 <          Mh += mass;
1518 <          Kh += mass * vel.lengthSquare();
1519 <          if (rnemdFluxType_ == rnemdFullKE) {
1520 <            if (sd->isDirectional()) {
1521 <              Vector3d angMom = sd->getJ();
1522 <              Mat3x3d I = sd->getI();
1523 <              if (sd->isLinear()) {
1524 <                int i = sd->linearAxis();
1264 <                int j = (i + 1) % 3;
1265 <                int k = (i + 2) % 3;
1266 <                Kh += angMom[j] * angMom[j] / I(j, j) +
1267 <                  angMom[k] * angMom[k] / I(k, k);
1268 <              } else {
1269 <                Kh += angMom[0] * angMom[0] / I(0, 0) +
1270 <                  angMom[1] * angMom[1] / I(1, 1) +
1271 <                  angMom[2] * angMom[2] / I(2, 2);
1272 <              }
1273 <            }
1274 <          }
1275 <        } else { //midBin_
1276 <          coldBin.push_back(sd);
1277 <          Pc += mass * vel;
1278 <          Mc += mass;
1279 <          Kc += mass * vel.lengthSquare();
1280 <          if (rnemdFluxType_ == rnemdFullKE) {
1281 <            if (sd->isDirectional()) {
1282 <              Vector3d angMom = sd->getJ();
1283 <              Mat3x3d I = sd->getI();
1284 <              if (sd->isLinear()) {
1285 <                int i = sd->linearAxis();
1286 <                int j = (i + 1) % 3;
1287 <                int k = (i + 2) % 3;
1288 <                Kc += angMom[j] * angMom[j] / I(j, j) +
1289 <                  angMom[k] * angMom[k] / I(k, k);
1290 <              } else {
1291 <                Kc += angMom[0] * angMom[0] / I(0, 0) +
1292 <                  angMom[1] * angMom[1] / I(1, 1) +
1293 <                  angMom[2] * angMom[2] / I(2, 2);
1294 <              }
1295 <            }
1296 <          }
1297 <        }
1509 >      if (rnemdFluxType_ == rnemdFullKE) {
1510 >        if (sd->isDirectional()) {
1511 >          Vector3d angMom = sd->getJ();
1512 >          Mat3x3d I = sd->getI();
1513 >          if (sd->isLinear()) {
1514 >            int i = sd->linearAxis();
1515 >            int j = (i + 1) % 3;
1516 >            int k = (i + 2) % 3;
1517 >            Kc += angMom[j] * angMom[j] / I(j, j) +
1518 >              angMom[k] * angMom[k] / I(k, k);
1519 >          } else {
1520 >            Kc += angMom[0] * angMom[0] / I(0, 0) +
1521 >              angMom[1] * angMom[1] / I(1, 1) +
1522 >              angMom[2] * angMom[2] / I(2, 2);
1523 >          }
1524 >        }
1525        }
1526      }
1527      
# Line 1304 | Line 1531 | namespace OpenMD {
1531   #ifdef IS_MPI
1532      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Ph[0], 3, MPI::REALTYPE, MPI::SUM);
1533      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Pc[0], 3, MPI::REALTYPE, MPI::SUM);
1534 +    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Lh[0], 3, MPI::REALTYPE, MPI::SUM);
1535 +    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Lc[0], 3, MPI::REALTYPE, MPI::SUM);
1536      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Mh, 1, MPI::REALTYPE, MPI::SUM);
1537      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Kh, 1, MPI::REALTYPE, MPI::SUM);
1538      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Mc, 1, MPI::REALTYPE, MPI::SUM);
1539      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &Kc, 1, MPI::REALTYPE, MPI::SUM);
1540 +    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, Ih.getArrayPointer(), 9,
1541 +                              MPI::REALTYPE, MPI::SUM);
1542 +    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, Ic.getArrayPointer(), 9,
1543 +                              MPI::REALTYPE, MPI::SUM);
1544   #endif
1545 <
1545 >    
1546      bool successfulExchange = false;
1547      if ((Mh > 0.0) && (Mc > 0.0)) {//both slabs are not empty
1548        Vector3d vc = Pc / Mc;
1549        Vector3d ac = -momentumTarget_ / Mc + vc;
1550        Vector3d acrec = -momentumTarget_ / Mc;
1551 <      RealType cNumerator = Kc - kineticTarget_ - 0.5 * Mc * ac.lengthSquare();
1551 >      
1552 >      // We now need the inverse of the inertia tensor to calculate the
1553 >      // angular velocity of the cold slab;
1554 >      Mat3x3d Ici = Ic.inverse();
1555 >      Vector3d omegac = Ici * Lc;
1556 >      Vector3d bc  = -(Ici * angularMomentumTarget_) + omegac;
1557 >      Vector3d bcrec = bc - omegac;
1558 >      
1559 >      RealType cNumerator = Kc - kineticTarget_
1560 >        - 0.5 * Mc * ac.lengthSquare() - 0.5 * ( dot(bc, Ic * bc));
1561        if (cNumerator > 0.0) {
1562 <        RealType cDenominator = Kc - 0.5 * Mc * vc.lengthSquare();
1562 >        
1563 >        RealType cDenominator = Kc - 0.5 * Mc * vc.lengthSquare()
1564 >          - 0.5*(dot(omegac, Ic * omegac));
1565 >        
1566          if (cDenominator > 0.0) {
1567            RealType c = sqrt(cNumerator / cDenominator);
1568            if ((c > 0.9) && (c < 1.1)) {//restrict scaling coefficients
1569 +            
1570              Vector3d vh = Ph / Mh;
1571              Vector3d ah = momentumTarget_ / Mh + vh;
1572              Vector3d ahrec = momentumTarget_ / Mh;
1573 <            RealType hNumerator = Kh + kineticTarget_
1574 <              - 0.5 * Mh * ah.lengthSquare();
1575 <            if (hNumerator > 0.0) {
1576 <              RealType hDenominator = Kh - 0.5 * Mh * vh.lengthSquare();
1573 >            
1574 >            // We now need the inverse of the inertia tensor to
1575 >            // calculate the angular velocity of the hot slab;
1576 >            Mat3x3d Ihi = Ih.inverse();
1577 >            Vector3d omegah = Ihi * Lh;
1578 >            Vector3d bh  = (Ihi * angularMomentumTarget_) + omegah;
1579 >            Vector3d bhrec = bh - omegah;
1580 >            
1581 >            RealType hNumerator = Kh + kineticTarget_
1582 >              - 0.5 * Mh * ah.lengthSquare() - 0.5 * ( dot(bh, Ih * bh));;
1583 >            if (hNumerator > 0.0) {
1584 >              
1585 >              RealType hDenominator = Kh - 0.5 * Mh * vh.lengthSquare()
1586 >                - 0.5*(dot(omegah, Ih * omegah));
1587 >              
1588                if (hDenominator > 0.0) {
1589                  RealType h = sqrt(hNumerator / hDenominator);
1590                  if ((h > 0.9) && (h < 1.1)) {
1591 <
1591 >                  
1592                    vector<StuntDouble*>::iterator sdi;
1593                    Vector3d vel;
1594 +                  Vector3d rPos;
1595 +                  
1596                    for (sdi = coldBin.begin(); sdi != coldBin.end(); sdi++) {
1597                      //vel = (*sdi)->getVel();
1598 <                    vel = ((*sdi)->getVel() - vc) * c + ac;
1598 >                    rPos = (*sdi)->getPos() - coordinateOrigin_;
1599 >                    vel = ((*sdi)->getVel() - vc - cross(omegac, rPos)) * c
1600 >                      + ac + cross(bc, rPos);
1601                      (*sdi)->setVel(vel);
1602                      if (rnemdFluxType_ == rnemdFullKE) {
1603                        if ((*sdi)->isDirectional()) {
# Line 1347 | Line 1608 | namespace OpenMD {
1608                    }
1609                    for (sdi = hotBin.begin(); sdi != hotBin.end(); sdi++) {
1610                      //vel = (*sdi)->getVel();
1611 <                    vel = ((*sdi)->getVel() - vh) * h + ah;
1611 >                    rPos = (*sdi)->getPos() - coordinateOrigin_;
1612 >                    vel = ((*sdi)->getVel() - vh - cross(omegah, rPos)) * h
1613 >                      + ah + cross(bh, rPos);                  
1614                      (*sdi)->setVel(vel);
1615                      if (rnemdFluxType_ == rnemdFullKE) {
1616                        if ((*sdi)->isDirectional()) {
# Line 1359 | Line 1622 | namespace OpenMD {
1622                    successfulExchange = true;
1623                    kineticExchange_ += kineticTarget_;
1624                    momentumExchange_ += momentumTarget_;
1625 +                  angularMomentumExchange_ += angularMomentumTarget_;
1626                  }
1627                }
1628              }
# Line 1378 | Line 1642 | namespace OpenMD {
1642      }
1643    }
1644  
1645 +  RealType RNEMD::getDividingArea() {
1646 +
1647 +    if (hasDividingArea_) return dividingArea_;
1648 +
1649 +    RealType areaA, areaB;
1650 +    Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
1651 +
1652 +    if (hasSelectionA_) {
1653 +      int isd;
1654 +      StuntDouble* sd;
1655 +      vector<StuntDouble*> aSites;
1656 +      ConvexHull* surfaceMeshA = new ConvexHull();
1657 +      seleManA_.setSelectionSet(evaluatorA_.evaluate());
1658 +      for (sd = seleManA_.beginSelected(isd); sd != NULL;
1659 +           sd = seleManA_.nextSelected(isd)) {
1660 +        aSites.push_back(sd);
1661 +      }
1662 +      surfaceMeshA->computeHull(aSites);
1663 +      areaA = surfaceMeshA->getArea();
1664 +    } else {
1665 +      if (usePeriodicBoundaryConditions_) {
1666 +        // in periodic boundaries, the surface area is twice the x-y
1667 +        // area of the current box:
1668 +        areaA = 2.0 * snap->getXYarea();
1669 +      } else {
1670 +        // in non-periodic simulations, without explicitly setting
1671 +        // selections, the sphere radius sets the surface area of the
1672 +        // dividing surface:
1673 +        areaA = 4.0 * M_PI * pow(sphereARadius_, 2);
1674 +      }
1675 +    }
1676 +
1677 +    if (hasSelectionB_) {
1678 +      int isd;
1679 +      StuntDouble* sd;
1680 +      vector<StuntDouble*> bSites;
1681 +      ConvexHull* surfaceMeshB = new ConvexHull();
1682 +      seleManB_.setSelectionSet(evaluatorB_.evaluate());
1683 +      for (sd = seleManB_.beginSelected(isd); sd != NULL;
1684 +           sd = seleManB_.nextSelected(isd)) {
1685 +        bSites.push_back(sd);
1686 +      }
1687 +      surfaceMeshB->computeHull(bSites);
1688 +      areaB = surfaceMeshB->getArea();
1689 +    } else {
1690 +      if (usePeriodicBoundaryConditions_) {
1691 +        // in periodic boundaries, the surface area is twice the x-y
1692 +        // area of the current box:
1693 +        areaB = 2.0 * snap->getXYarea();
1694 +      } else {
1695 +        // in non-periodic simulations, without explicitly setting
1696 +        // selections, but if a sphereBradius has been set, just use that:
1697 +        areaB = 4.0 * M_PI * pow(sphereBRadius_, 2);
1698 +      }
1699 +    }
1700 +    
1701 +    dividingArea_ = min(areaA, areaB);
1702 +    hasDividingArea_ = true;
1703 +    return dividingArea_;
1704 +  }
1705 +  
1706    void RNEMD::doRNEMD() {
1707      if (!doRNEMD_) return;
1708      trialCount_++;
1709 +
1710 +    // object evaluator:
1711 +    evaluator_.loadScriptString(rnemdObjectSelection_);
1712 +    seleMan_.setSelectionSet(evaluator_.evaluate());
1713 +
1714 +    evaluatorA_.loadScriptString(selectionA_);
1715 +    evaluatorB_.loadScriptString(selectionB_);
1716 +
1717 +    seleManA_.setSelectionSet(evaluatorA_.evaluate());
1718 +    seleManB_.setSelectionSet(evaluatorB_.evaluate());
1719 +
1720 +    commonA_ = seleManA_ & seleMan_;
1721 +    commonB_ = seleManB_ & seleMan_;
1722 +
1723 +    // Target exchange quantities (in each exchange) = dividingArea * dt * flux
1724 +    // dt = exchange time interval
1725 +    // flux = target flux
1726 +    // dividingArea = smallest dividing surface between the two regions
1727 +
1728 +    hasDividingArea_ = false;
1729 +    RealType area = getDividingArea();
1730 +
1731 +    kineticTarget_ = kineticFlux_ * exchangeTime_ * area;
1732 +    momentumTarget_ = momentumFluxVector_ * exchangeTime_ * area;
1733 +    angularMomentumTarget_ = angularMomentumFluxVector_ * exchangeTime_ * area;
1734 +
1735      switch(rnemdMethod_) {
1736      case rnemdSwap:
1737 <      doSwap();
1737 >      doSwap(commonA_, commonB_);
1738        break;
1739      case rnemdNIVS:
1740 <      doNIVS();
1740 >      doNIVS(commonA_, commonB_);
1741        break;
1742      case rnemdVSS:
1743 <      doVSS();
1743 >      doVSS(commonA_, commonB_);
1744        break;
1745      case rnemdUnkownMethod:
1746      default :
# Line 1400 | Line 1751 | namespace OpenMD {
1751    void RNEMD::collectData() {
1752      if (!doRNEMD_) return;
1753      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
1403    Mat3x3d hmat = currentSnap_->getHmat();
1754  
1755 <    areaAccumulator_->add(currentSnap_->getXYarea());
1755 >    // collectData can be called more frequently than the doRNEMD, so use the
1756 >    // computed area from the last exchange time:
1757  
1758 +    areaAccumulator_->add(getDividingArea());
1759 +    Mat3x3d hmat = currentSnap_->getHmat();
1760      seleMan_.setSelectionSet(evaluator_.evaluate());
1761  
1762      int selei(0);
1763      StuntDouble* sd;
1764 +    int binNo;
1765  
1766      vector<RealType> binMass(nBins_, 0.0);
1767      vector<RealType> binPx(nBins_, 0.0);
1768      vector<RealType> binPy(nBins_, 0.0);
1769      vector<RealType> binPz(nBins_, 0.0);
1770 +    vector<RealType> binOmegax(nBins_, 0.0);
1771 +    vector<RealType> binOmegay(nBins_, 0.0);
1772 +    vector<RealType> binOmegaz(nBins_, 0.0);
1773      vector<RealType> binKE(nBins_, 0.0);
1774      vector<int> binDOF(nBins_, 0);
1775      vector<int> binCount(nBins_, 0);
# Line 1420 | Line 1777 | namespace OpenMD {
1777      // alternative approach, track all molecules instead of only those
1778      // selected for scaling/swapping:
1779      /*
1780 <    SimInfo::MoleculeIterator miter;
1781 <    vector<StuntDouble*>::iterator iiter;
1782 <    Molecule* mol;
1783 <    StuntDouble* sd;
1784 <    for (mol = info_->beginMolecule(miter); mol != NULL;
1780 >      SimInfo::MoleculeIterator miter;
1781 >      vector<StuntDouble*>::iterator iiter;
1782 >      Molecule* mol;
1783 >      StuntDouble* sd;
1784 >      for (mol = info_->beginMolecule(miter); mol != NULL;
1785        mol = info_->nextMolecule(miter))
1786        sd is essentially sd
1787 <        for (sd = mol->beginIntegrableObject(iiter);
1788 <             sd != NULL;
1789 <             sd = mol->nextIntegrableObject(iiter))
1787 >      for (sd = mol->beginIntegrableObject(iiter);
1788 >      sd != NULL;
1789 >      sd = mol->nextIntegrableObject(iiter))
1790      */
1791  
1792      for (sd = seleMan_.beginSelected(selei); sd != NULL;
# Line 1439 | Line 1796 | namespace OpenMD {
1796  
1797        // wrap the stuntdouble's position back into the box:
1798        
1799 <      if (usePeriodicBoundaryConditions_)
1799 >      if (usePeriodicBoundaryConditions_) {
1800          currentSnap_->wrapVector(pos);
1801 +        // which bin is this stuntdouble in?
1802 +        // wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)]
1803 +        // Shift molecules by half a box to have bins start at 0
1804 +        // The modulo operator is used to wrap the case when we are
1805 +        // beyond the end of the bins back to the beginning.
1806 +        binNo = int(nBins_ * (pos.z() / hmat(2,2) + 0.5)) % nBins_;
1807 +      } else {
1808 +        Vector3d rPos = pos - coordinateOrigin_;
1809 +        binNo = int(rPos.length() / binWidth_);
1810 +      }
1811  
1445
1446      // which bin is this stuntdouble in?
1447      // wrapped positions are in the range [-0.5*hmat(2,2), +0.5*hmat(2,2)]
1448      // Shift molecules by half a box to have bins start at 0
1449      // The modulo operator is used to wrap the case when we are
1450      // beyond the end of the bins back to the beginning.
1451      int binNo = int(nBins_ * (pos.z() / hmat(2,2) + 0.5)) % nBins_;
1452
1812        RealType mass = sd->getMass();
1813        Vector3d vel = sd->getVel();
1814 <
1815 <      binCount[binNo]++;
1816 <      binMass[binNo] += mass;
1817 <      binPx[binNo] += mass*vel.x();
1818 <      binPy[binNo] += mass*vel.y();
1819 <      binPz[binNo] += mass*vel.z();
1820 <      binKE[binNo] += 0.5 * (mass * vel.lengthSquare());
1821 <      binDOF[binNo] += 3;
1822 <
1823 <      if (sd->isDirectional()) {
1824 <        Vector3d angMom = sd->getJ();
1825 <        Mat3x3d I = sd->getI();
1826 <        if (sd->isLinear()) {
1827 <          int i = sd->linearAxis();
1828 <          int j = (i + 1) % 3;
1829 <          int k = (i + 2) % 3;
1830 <          binKE[binNo] += 0.5 * (angMom[j] * angMom[j] / I(j, j) +
1831 <                                 angMom[k] * angMom[k] / I(k, k));
1832 <          binDOF[binNo] += 2;
1833 <        } else {
1834 <          binKE[binNo] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) +
1835 <                                 angMom[1] * angMom[1] / I(1, 1) +
1836 <                                 angMom[2] * angMom[2] / I(2, 2));
1837 <          binDOF[binNo] += 3;
1814 >      Vector3d rPos = sd->getPos() - coordinateOrigin_;
1815 >      Vector3d aVel = cross(rPos, vel);
1816 >      
1817 >      if (binNo < nBins_)  {
1818 >        binCount[binNo]++;
1819 >        binMass[binNo] += mass;
1820 >        binPx[binNo] += mass*vel.x();
1821 >        binPy[binNo] += mass*vel.y();
1822 >        binPz[binNo] += mass*vel.z();
1823 >        binOmegax[binNo] += aVel.x();
1824 >        binOmegay[binNo] += aVel.y();
1825 >        binOmegaz[binNo] += aVel.z();
1826 >        binKE[binNo] += 0.5 * (mass * vel.lengthSquare());
1827 >        binDOF[binNo] += 3;
1828 >        
1829 >        if (sd->isDirectional()) {
1830 >          Vector3d angMom = sd->getJ();
1831 >          Mat3x3d I = sd->getI();
1832 >          if (sd->isLinear()) {
1833 >            int i = sd->linearAxis();
1834 >            int j = (i + 1) % 3;
1835 >            int k = (i + 2) % 3;
1836 >            binKE[binNo] += 0.5 * (angMom[j] * angMom[j] / I(j, j) +
1837 >                                   angMom[k] * angMom[k] / I(k, k));
1838 >            binDOF[binNo] += 2;
1839 >          } else {
1840 >            binKE[binNo] += 0.5 * (angMom[0] * angMom[0] / I(0, 0) +
1841 >                                   angMom[1] * angMom[1] / I(1, 1) +
1842 >                                   angMom[2] * angMom[2] / I(2, 2));
1843 >            binDOF[binNo] += 3;
1844 >          }
1845          }
1846        }
1847      }
# Line 1491 | Line 1857 | namespace OpenMD {
1857                                nBins_, MPI::REALTYPE, MPI::SUM);
1858      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binPz[0],
1859                                nBins_, MPI::REALTYPE, MPI::SUM);
1860 +    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegax[0],
1861 +                              nBins_, MPI::REALTYPE, MPI::SUM);
1862 +    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegay[0],
1863 +                              nBins_, MPI::REALTYPE, MPI::SUM);
1864 +    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binOmegaz[0],
1865 +                              nBins_, MPI::REALTYPE, MPI::SUM);
1866      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binKE[0],
1867                                nBins_, MPI::REALTYPE, MPI::SUM);
1868      MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &binDOF[0],
# Line 1498 | Line 1870 | namespace OpenMD {
1870   #endif
1871  
1872      Vector3d vel;
1873 +    Vector3d aVel;
1874      RealType den;
1875      RealType temp;
1876      RealType z;
1877 +    RealType r;
1878      for (int i = 0; i < nBins_; i++) {
1879 <      z = (((RealType)i + 0.5) / (RealType)nBins_) * hmat(2,2);
1879 >      if (usePeriodicBoundaryConditions_) {
1880 >        z = (((RealType)i + 0.5) / (RealType)nBins_) * hmat(2,2);
1881 >        den = binMass[i] * nBins_ * PhysicalConstants::densityConvert
1882 >          / currentSnap_->getVolume() ;
1883 >      } else {
1884 >        r = (((RealType)i + 0.5) * binWidth_);
1885 >        RealType rinner = (RealType)i * binWidth_;
1886 >        RealType router = (RealType)(i+1) * binWidth_;
1887 >        den = binMass[i] * 3.0 * PhysicalConstants::densityConvert
1888 >          / (4.0 * M_PI * (pow(router,3) - pow(rinner,3)));
1889 >      }
1890        vel.x() = binPx[i] / binMass[i];
1891        vel.y() = binPy[i] / binMass[i];
1892        vel.z() = binPz[i] / binMass[i];
1893 +      aVel.x() = binOmegax[i];
1894 +      aVel.y() = binOmegay[i];
1895 +      aVel.z() = binOmegaz[i];
1896  
1510      den = binMass[i] * nBins_ * PhysicalConstants::densityConvert
1511        / currentSnap_->getVolume() ;
1512
1897        if (binCount[i] > 0) {
1898          // only add values if there are things to add
1899          temp = 2.0 * binKE[i] / (binDOF[i] * PhysicalConstants::kb *
# Line 1521 | Line 1905 | namespace OpenMD {
1905              case Z:
1906                dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(z);
1907                break;
1908 +            case R:
1909 +              dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(r);
1910 +              break;
1911              case TEMPERATURE:
1912                dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(temp);
1913                break;
1914              case VELOCITY:
1915                dynamic_cast<VectorAccumulator *>(data_[j].accumulator[i])->add(vel);
1916                break;
1917 +            case ANGULARVELOCITY:
1918 +              dynamic_cast<VectorAccumulator *>(data_[j].accumulator[i])->add(aVel);
1919 +              break;
1920              case DENSITY:
1921                dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(den);
1922                break;
# Line 1539 | Line 1929 | namespace OpenMD {
1929  
1930    void RNEMD::getStarted() {
1931      if (!doRNEMD_) return;
1932 +    hasDividingArea_ = false;
1933      collectData();
1934      writeOutputFile();
1935    }
# Line 1587 | Line 1978 | namespace OpenMD {
1978        RealType time = currentSnap_->getTime();
1979        RealType avgArea;
1980        areaAccumulator_->getAverage(avgArea);
1981 <      RealType Jz = kineticExchange_ / (2.0 * time * avgArea)
1981 >      RealType Jz = kineticExchange_ / (time * avgArea)
1982          / PhysicalConstants::energyConvert;
1983 <      Vector3d JzP = momentumExchange_ / (2.0 * time * avgArea);      
1983 >      Vector3d JzP = momentumExchange_ / (time * avgArea);      
1984 >      Vector3d JzL = angularMomentumExchange_ / (time * avgArea);      
1985  
1986        rnemdFile_ << "#######################################################\n";
1987        rnemdFile_ << "# RNEMD {\n";
# Line 1609 | Line 2001 | namespace OpenMD {
2001  
2002        rnemdFile_ << "#    objectSelection = \""
2003                   << rnemdObjectSelection_ << "\";\n";
2004 <      rnemdFile_ << "#    slabWidth = " << slabWidth_ << ";\n";
2005 <      rnemdFile_ << "#    slabAcenter = " << slabACenter_ << ";\n";
1614 <      rnemdFile_ << "#    slabBcenter = " << slabBCenter_ << ";\n";
2004 >      rnemdFile_ << "#    selectionA = \"" << selectionA_ << "\";\n";
2005 >      rnemdFile_ << "#    selectionB = \"" << selectionB_ << "\";\n";
2006        rnemdFile_ << "# }\n";
2007        rnemdFile_ << "#######################################################\n";
2008        rnemdFile_ << "# RNEMD report:\n";      
2009 <      rnemdFile_ << "#     running time = " << time << " fs\n";
2010 <      rnemdFile_ << "#     target flux:\n";
2011 <      rnemdFile_ << "#         kinetic = "
2009 >      rnemdFile_ << "#      running time = " << time << " fs\n";
2010 >      rnemdFile_ << "# Target flux:\n";
2011 >      rnemdFile_ << "#           kinetic = "
2012                   << kineticFlux_ / PhysicalConstants::energyConvert
2013                   << " (kcal/mol/A^2/fs)\n";
2014 <      rnemdFile_ << "#         momentum = " << momentumFluxVector_
2014 >      rnemdFile_ << "#          momentum = " << momentumFluxVector_
2015                   << " (amu/A/fs^2)\n";
2016 <      rnemdFile_ << "#     target one-time exchanges:\n";
2017 <      rnemdFile_ << "#         kinetic = "
2016 >      rnemdFile_ << "#  angular momentum = " << angularMomentumFluxVector_
2017 >                 << " (amu/A^2/fs^2)\n";
2018 >      rnemdFile_ << "# Target one-time exchanges:\n";
2019 >      rnemdFile_ << "#          kinetic = "
2020                   << kineticTarget_ / PhysicalConstants::energyConvert
2021                   << " (kcal/mol)\n";
2022 <      rnemdFile_ << "#         momentum = " << momentumTarget_
2022 >      rnemdFile_ << "#          momentum = " << momentumTarget_
2023                   << " (amu*A/fs)\n";
2024 <      rnemdFile_ << "#     actual exchange totals:\n";
2025 <      rnemdFile_ << "#         kinetic = "
2024 >      rnemdFile_ << "#  angular momentum = " << angularMomentumTarget_
2025 >                 << " (amu*A^2/fs)\n";
2026 >      rnemdFile_ << "# Actual exchange totals:\n";
2027 >      rnemdFile_ << "#          kinetic = "
2028                   << kineticExchange_ / PhysicalConstants::energyConvert
2029                   << " (kcal/mol)\n";
2030 <      rnemdFile_ << "#         momentum = " << momentumExchange_
2030 >      rnemdFile_ << "#          momentum = " << momentumExchange_
2031                   << " (amu*A/fs)\n";      
2032 <      rnemdFile_ << "#     actual flux:\n";
2033 <      rnemdFile_ << "#         kinetic = " << Jz
2032 >      rnemdFile_ << "#  angular momentum = " << angularMomentumExchange_
2033 >                 << " (amu*A^2/fs)\n";      
2034 >      rnemdFile_ << "# Actual flux:\n";
2035 >      rnemdFile_ << "#          kinetic = " << Jz
2036                   << " (kcal/mol/A^2/fs)\n";
2037 <      rnemdFile_ << "#         momentum = " << JzP
2037 >      rnemdFile_ << "#          momentum = " << JzP
2038                   << " (amu/A/fs^2)\n";
2039 <      rnemdFile_ << "#     exchange statistics:\n";
2040 <      rnemdFile_ << "#         attempted = " << trialCount_ << "\n";
2041 <      rnemdFile_ << "#         failed = " << failTrialCount_ << "\n";    
2039 >      rnemdFile_ << "#  angular momentum = " << JzL
2040 >                 << " (amu/A^2/fs^2)\n";
2041 >      rnemdFile_ << "# Exchange statistics:\n";
2042 >      rnemdFile_ << "#               attempted = " << trialCount_ << "\n";
2043 >      rnemdFile_ << "#                  failed = " << failTrialCount_ << "\n";
2044        if (rnemdMethod_ == rnemdNIVS) {
2045 <        rnemdFile_ << "#         NIVS root-check errors = "
2045 >        rnemdFile_ << "#  NIVS root-check errors = "
2046                     << failRootCount_ << "\n";
2047        }
2048        rnemdFile_ << "#######################################################\n";
# Line 1725 | Line 2124 | namespace OpenMD {
2124      assert(index >=0 && index < ENDINDEX);
2125      assert(int(bin) < nBins_);
2126      RealType s;
2127 +    int count;
2128      
2129 +    count = dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->count();
2130 +    if (count == 0) return;
2131 +    
2132      dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->getAverage(s);
2133      
2134      if (! isinf(s) && ! isnan(s)) {
# Line 1744 | Line 2147 | namespace OpenMD {
2147      assert(index >=0 && index < ENDINDEX);
2148      assert(int(bin) < nBins_);
2149      Vector3d s;
2150 +    int count;
2151 +    
2152 +    count = dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->count();
2153 +    if (count == 0) return;
2154 +
2155      dynamic_cast<VectorAccumulator*>(data_[index].accumulator[bin])->getAverage(s);
2156      if (isinf(s[0]) || isnan(s[0]) ||
2157          isinf(s[1]) || isnan(s[1]) ||
# Line 1763 | Line 2171 | namespace OpenMD {
2171      assert(index >=0 && index < ENDINDEX);
2172      assert(int(bin) < nBins_);
2173      RealType s;
2174 +    int count;
2175      
2176 +    count = dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->count();
2177 +    if (count == 0) return;
2178 +    
2179      dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->getStdDev(s);
2180      
2181      if (! isinf(s) && ! isnan(s)) {
# Line 1782 | Line 2194 | namespace OpenMD {
2194      assert(index >=0 && index < ENDINDEX);
2195      assert(int(bin) < nBins_);
2196      Vector3d s;
2197 +    int count;
2198 +    
2199 +    count = dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->count();
2200 +    if (count == 0) return;
2201 +
2202      dynamic_cast<VectorAccumulator*>(data_[index].accumulator[bin])->getStdDev(s);
2203      if (isinf(s[0]) || isnan(s[0]) ||
2204          isinf(s[1]) || isnan(s[1]) ||

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines