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

Comparing:
branches/development/src/rnemd/RNEMD.cpp (file contents), Revision 1775 by gezelter, Wed Aug 8 18:45:52 2012 UTC vs.
trunk/src/rnemd/RNEMD.cpp (file contents), Revision 1791 by gezelter, Fri Aug 31 16:48:50 2012 UTC

# Line 53 | Line 53
53   #include <mpi.h>
54   #endif
55  
56 + #ifdef _MSC_VER
57 + #define isnan(x) _isnan((x))
58 + #define isinf(x) (!_finite(x) && !_isnan(x))
59 + #endif
60 +
61   #define HONKING_LARGE_VALUE 1.0e10
62  
63   using namespace std;
# Line 65 | Line 70 | namespace OpenMD {
70      failTrialCount_ = 0;
71      failRootCount_ = 0;
72  
68    int seedValue;
73      Globals * simParams = info->getSimParams();
74      RNEMDParameters* rnemdParams = simParams->getRNEMDParameters();
75  
76 +    doRNEMD_ = rnemdParams->getUseRNEMD();
77 +    if (!doRNEMD_) return;
78 +
79      stringToMethod_["Swap"]  = rnemdSwap;
80      stringToMethod_["NIVS"]  = rnemdNIVS;
81      stringToMethod_["VSS"]   = rnemdVSS;
# Line 77 | Line 84 | namespace OpenMD {
84      stringToFluxType_["Px"]  = rnemdPx;
85      stringToFluxType_["Py"]  = rnemdPy;
86      stringToFluxType_["Pz"]  = rnemdPz;
87 +    stringToFluxType_["Pvector"]  = rnemdPvector;
88      stringToFluxType_["KE+Px"]  = rnemdKePx;
89      stringToFluxType_["KE+Py"]  = rnemdKePy;
90      stringToFluxType_["KE+Pvector"]  = rnemdKePvector;
# Line 98 | Line 106 | namespace OpenMD {
106        sprintf(painCave.errMsg,
107                "RNEMD: No fluxType was set in the md file.  This parameter,\n"
108                "\twhich must be one of the following values:\n"
109 <              "\tKE, Px, Py, Pz, KE+Px, KE+Py, KE+Pvector, must be set to\n"
110 <              "\tuse RNEMD\n");
109 >              "\tKE, Px, Py, Pz, Pvector, KE+Px, KE+Py, KE+Pvector\n"
110 >              "\tmust be set to use RNEMD\n");
111        painCave.isFatal = 1;
112        painCave.severity = OPENMD_ERROR;
113        simError();
# Line 197 | Line 205 | namespace OpenMD {
205          break;
206        case rnemdPvector:
207          hasCorrectFlux = hasMomentumFluxVector;
208 +        break;
209        case rnemdKePx:
210        case rnemdKePy:
211          hasCorrectFlux = hasMomentumFlux && hasKineticFlux;
# Line 224 | Line 233 | namespace OpenMD {
233      }
234      if (!hasCorrectFlux) {
235        sprintf(painCave.errMsg,
236 <              "RNEMD: The current method,\n"
228 <              "\t%s, and flux type %s\n"
236 >              "RNEMD: The current method, %s, and flux type, %s,\n"
237                "\tdid not have the correct flux value specified. Options\n"
238                "\tinclude: kineticFlux, momentumFlux, and momentumFluxVector\n",
239                methStr.c_str(), fluxStr.c_str());
# Line 235 | Line 243 | namespace OpenMD {
243      }
244  
245      if (hasKineticFlux) {
246 <      kineticFlux_ = rnemdParams->getKineticFlux();
246 >      // convert the kcal / mol / Angstroms^2 / fs values in the md file
247 >      // into  amu / fs^3:
248 >      kineticFlux_ = rnemdParams->getKineticFlux()
249 >        * PhysicalConstants::energyConvert;
250      } else {
251        kineticFlux_ = 0.0;
252      }
# Line 298 | Line 309 | namespace OpenMD {
309      z.title =  "Z";
310      z.dataType = "RealType";
311      z.accumulator.reserve(nBins_);
312 <    for (unsigned int i = 0; i < nBins_; i++)
312 >    for (int i = 0; i < nBins_; i++)
313        z.accumulator.push_back( new Accumulator() );
314      data_[Z] = z;
315      outputMap_["Z"] =  Z;
# Line 308 | Line 319 | namespace OpenMD {
319      temperature.title =  "Temperature";
320      temperature.dataType = "RealType";
321      temperature.accumulator.reserve(nBins_);
322 <    for (unsigned int i = 0; i < nBins_; i++)
322 >    for (int i = 0; i < nBins_; i++)
323        temperature.accumulator.push_back( new Accumulator() );
324      data_[TEMPERATURE] = temperature;
325      outputMap_["TEMPERATURE"] =  TEMPERATURE;
326  
327      OutputData velocity;
328 <    velocity.units = "amu/fs";
328 >    velocity.units = "angstroms/fs";
329      velocity.title =  "Velocity";  
330      velocity.dataType = "Vector3d";
331      velocity.accumulator.reserve(nBins_);
332 <    for (unsigned int i = 0; i < nBins_; i++)
332 >    for (int i = 0; i < nBins_; i++)
333        velocity.accumulator.push_back( new VectorAccumulator() );
334      data_[VELOCITY] = velocity;
335      outputMap_["VELOCITY"] = VELOCITY;
# Line 328 | Line 339 | namespace OpenMD {
339      density.title =  "Density";
340      density.dataType = "RealType";
341      density.accumulator.reserve(nBins_);
342 <    for (unsigned int i = 0; i < nBins_; i++)
342 >    for (int i = 0; i < nBins_; i++)
343        density.accumulator.push_back( new Accumulator() );
344      data_[DENSITY] = density;
345      outputMap_["DENSITY"] =  DENSITY;
# Line 410 | Line 421 | namespace OpenMD {
421    }
422    
423    RNEMD::~RNEMD() {
424 <    
424 >    if (!doRNEMD_) return;
425   #ifdef IS_MPI
426      if (worldRank == 0) {
427   #endif
# Line 432 | Line 443 | namespace OpenMD {
443    }
444  
445    void RNEMD::doSwap() {
446 <
446 >    if (!doRNEMD_) return;
447      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
448      Mat3x3d hmat = currentSnap_->getHmat();
449  
# Line 491 | Line 502 | namespace OpenMD {
502                  + angMom[2]*angMom[2]/I(2, 2);
503              }
504            } //angular momenta exchange enabled
494          //energyConvert temporarily disabled
495          //make kineticExchange_ comparable between swap & scale
496          //value = value * 0.5 / PhysicalConstants::energyConvert;
505            value *= 0.5;
506            break;
507          case rnemdPx :
# Line 731 | Line 739 | namespace OpenMD {
739          
740          switch(rnemdFluxType_) {
741          case rnemdKE:
734          cerr << "KE\n";
742            kineticExchange_ += max_val - min_val;
743            break;
744          case rnemdPx:
# Line 744 | Line 751 | namespace OpenMD {
751            momentumExchange_.z() += max_val - min_val;
752            break;
753          default:
747          cerr << "default\n";
754            break;
755          }
756        } else {        
# Line 767 | Line 773 | namespace OpenMD {
773    }
774    
775    void RNEMD::doNIVS() {
776 <
776 >    if (!doRNEMD_) return;
777      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
778      Mat3x3d hmat = currentSnap_->getHmat();
779  
# Line 1216 | Line 1222 | namespace OpenMD {
1222    }
1223  
1224    void RNEMD::doVSS() {
1225 <
1225 >    if (!doRNEMD_) return;
1226      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
1227      RealType time = currentSnap_->getTime();    
1228      Mat3x3d hmat = currentSnap_->getHmat();
# Line 1394 | Line 1400 | namespace OpenMD {
1400    }
1401  
1402    void RNEMD::doRNEMD() {
1403 <
1403 >    if (!doRNEMD_) return;
1404      trialCount_++;
1405      switch(rnemdMethod_) {
1406      case rnemdSwap:
# Line 1413 | Line 1419 | namespace OpenMD {
1419    }
1420  
1421    void RNEMD::collectData() {
1422 <
1422 >    if (!doRNEMD_) return;
1423      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
1424      Mat3x3d hmat = currentSnap_->getHmat();
1425  
# Line 1524 | Line 1530 | namespace OpenMD {
1530        vel.x() = binPx[i] / binMass[i];
1531        vel.y() = binPy[i] / binMass[i];
1532        vel.z() = binPz[i] / binMass[i];
1533 <      den = binCount[i] * nBins_ / currentSnap_->getVolume();
1533 >
1534 >      den = binMass[i] * nBins_ * PhysicalConstants::densityConvert
1535 >        / currentSnap_->getVolume() ;
1536 >
1537        temp = 2.0 * binKE[i] / (binDOF[i] * PhysicalConstants::kb *
1538                                 PhysicalConstants::energyConvert);
1539  
# Line 1532 | Line 1541 | namespace OpenMD {
1541          if(outputMask_[j]) {
1542            switch(j) {
1543            case Z:
1544 <            (data_[j].accumulator[i])->add(z);
1544 >            dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(z);
1545              break;
1546            case TEMPERATURE:
1547 <            data_[j].accumulator[i]->add(temp);
1547 >            dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(temp);
1548              break;
1549            case VELOCITY:
1550              dynamic_cast<VectorAccumulator *>(data_[j].accumulator[i])->add(vel);
1551              break;
1552            case DENSITY:
1553 <            data_[j].accumulator[i]->add(den);
1553 >            dynamic_cast<Accumulator *>(data_[j].accumulator[i])->add(den);
1554              break;
1555            }
1556          }
# Line 1550 | Line 1559 | namespace OpenMD {
1559    }
1560  
1561    void RNEMD::getStarted() {
1562 +    if (!doRNEMD_) return;
1563      collectData();
1564      writeOutputFile();
1565    }
1566  
1567    void RNEMD::parseOutputFileFormat(const std::string& format) {
1568 +    if (!doRNEMD_) return;
1569      StringTokenizer tokenizer(format, " ,;|\t\n\r");
1570      
1571      while(tokenizer.hasMoreTokens()) {
# Line 1575 | Line 1586 | namespace OpenMD {
1586    }
1587    
1588    void RNEMD::writeOutputFile() {
1589 +    if (!doRNEMD_) return;
1590      
1591   #ifdef IS_MPI
1592      // If we're the root node, should we print out the results
# Line 1596 | Line 1608 | namespace OpenMD {
1608        RealType time = currentSnap_->getTime();
1609        RealType avgArea;
1610        areaAccumulator_->getAverage(avgArea);
1611 <      RealType Jz = kineticExchange_ / (2.0 * time * avgArea);
1611 >      RealType Jz = kineticExchange_ / (2.0 * time * avgArea)
1612 >        / PhysicalConstants::energyConvert;
1613        Vector3d JzP = momentumExchange_ / (2.0 * time * avgArea);      
1614  
1615        rnemdFile_ << "#######################################################\n";
# Line 1625 | Line 1638 | namespace OpenMD {
1638        rnemdFile_ << "# RNEMD report:\n";      
1639        rnemdFile_ << "#     running time = " << time << " fs\n";
1640        rnemdFile_ << "#     target flux:\n";
1641 <      rnemdFile_ << "#         kinetic = " << kineticFlux_ << "\n";
1642 <      rnemdFile_ << "#         momentum = " << momentumFluxVector_ << "\n";
1641 >      rnemdFile_ << "#         kinetic = "
1642 >                 << kineticFlux_ / PhysicalConstants::energyConvert
1643 >                 << " (kcal/mol/A^2/fs)\n";
1644 >      rnemdFile_ << "#         momentum = " << momentumFluxVector_
1645 >                 << " (amu/A/fs^2)\n";
1646        rnemdFile_ << "#     target one-time exchanges:\n";
1647 <      rnemdFile_ << "#         kinetic = " << kineticTarget_ << "\n";
1648 <      rnemdFile_ << "#         momentum = " << momentumTarget_ << "\n";
1647 >      rnemdFile_ << "#         kinetic = "
1648 >                 << kineticTarget_ / PhysicalConstants::energyConvert
1649 >                 << " (kcal/mol)\n";
1650 >      rnemdFile_ << "#         momentum = " << momentumTarget_
1651 >                 << " (amu*A/fs)\n";
1652        rnemdFile_ << "#     actual exchange totals:\n";
1653 <      rnemdFile_ << "#         kinetic = " << kineticExchange_ << "\n";
1654 <      rnemdFile_ << "#         momentum = " << momentumExchange_  << "\n";
1653 >      rnemdFile_ << "#         kinetic = "
1654 >                 << kineticExchange_ / PhysicalConstants::energyConvert
1655 >                 << " (kcal/mol)\n";
1656 >      rnemdFile_ << "#         momentum = " << momentumExchange_
1657 >                 << " (amu*A/fs)\n";      
1658        rnemdFile_ << "#     actual flux:\n";
1659 <      rnemdFile_ << "#         kinetic = " << Jz << "\n";
1660 <      rnemdFile_ << "#         momentum = " << JzP  << "\n";
1659 >      rnemdFile_ << "#         kinetic = " << Jz
1660 >                 << " (kcal/mol/A^2/fs)\n";
1661 >      rnemdFile_ << "#         momentum = " << JzP
1662 >                 << " (amu/A/fs^2)\n";
1663        rnemdFile_ << "#     exchange statistics:\n";
1664        rnemdFile_ << "#         attempted = " << trialCount_ << "\n";
1665        rnemdFile_ << "#         failed = " << failTrialCount_ << "\n";    
# Line 1653 | Line 1677 | namespace OpenMD {
1677          if (outputMask_[i]) {
1678            rnemdFile_ << "\t" << data_[i].title <<
1679              "(" << data_[i].units << ")";
1680 +          // add some extra tabs for column alignment
1681 +          if (data_[i].dataType == "Vector3d") rnemdFile_ << "\t\t";
1682          }
1683        }
1684        rnemdFile_ << std::endl;
1685        
1686        rnemdFile_.precision(8);
1687        
1688 <      for (unsigned int j = 0; j < nBins_; j++) {        
1688 >      for (int j = 0; j < nBins_; j++) {        
1689          
1690          for (unsigned int i = 0; i < outputMask_.size(); ++i) {
1691            if (outputMask_[i]) {
# Line 1685 | Line 1711 | namespace OpenMD {
1711        rnemdFile_ << "#######################################################\n";
1712  
1713  
1714 <      for (unsigned int j = 0; j < nBins_; j++) {        
1714 >      for (int j = 0; j < nBins_; j++) {        
1715          rnemdFile_ << "#";
1716          for (unsigned int i = 0; i < outputMask_.size(); ++i) {
1717            if (outputMask_[i]) {
# Line 1716 | Line 1742 | namespace OpenMD {
1742    }
1743    
1744    void RNEMD::writeReal(int index, unsigned int bin) {
1745 +    if (!doRNEMD_) return;
1746      assert(index >=0 && index < ENDINDEX);
1747      assert(bin < nBins_);
1748      RealType s;
1749      
1750 <    data_[index].accumulator[bin]->getAverage(s);
1750 >    dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->getAverage(s);
1751      
1752      if (! isinf(s) && ! isnan(s)) {
1753        rnemdFile_ << "\t" << s;
# Line 1734 | Line 1761 | namespace OpenMD {
1761    }
1762    
1763    void RNEMD::writeVector(int index, unsigned int bin) {
1764 +    if (!doRNEMD_) return;
1765      assert(index >=0 && index < ENDINDEX);
1766      assert(bin < nBins_);
1767      Vector3d s;
# Line 1752 | Line 1780 | namespace OpenMD {
1780    }  
1781  
1782    void RNEMD::writeRealStdDev(int index, unsigned int bin) {
1783 +    if (!doRNEMD_) return;
1784      assert(index >=0 && index < ENDINDEX);
1785      assert(bin < nBins_);
1786      RealType s;
1787      
1788 <    data_[index].accumulator[bin]->getStdDev(s);
1788 >    dynamic_cast<Accumulator *>(data_[index].accumulator[bin])->getStdDev(s);
1789      
1790      if (! isinf(s) && ! isnan(s)) {
1791        rnemdFile_ << "\t" << s;
# Line 1770 | Line 1799 | namespace OpenMD {
1799    }
1800    
1801    void RNEMD::writeVectorStdDev(int index, unsigned int bin) {
1802 +    if (!doRNEMD_) return;
1803      assert(index >=0 && index < ENDINDEX);
1804      assert(bin < nBins_);
1805      Vector3d s;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines