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 1855 by gezelter, Tue Apr 2 18:31:51 2013 UTC vs.
Revision 1868 by gezelter, Tue Apr 30 15:56:54 2013 UTC

# Line 71 | Line 71 | namespace OpenMD {
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),
74 >                                seleManB_(info), commonB_(info),
75 >                                hasData_(false),
76                                  usePeriodicBoundaryConditions_(info->getSimParams()->getUsePeriodicBoundaryConditions()) {
77  
78      trialCount_ = 0;
# Line 556 | Line 557 | namespace OpenMD {
557              slabWidth_ = hmat(2,2) / 10.0;
558          
559            if (hasSlabBCenter)
560 <            slabBCenter_ = rnemdParams->getSlabACenter();
560 >            slabBCenter_ = rnemdParams->getSlabBCenter();
561            else
562              slabBCenter_ = hmat(2,2) / 2.0;
563          
# Line 577 | Line 578 | namespace OpenMD {
578          }
579        }
580      }
581 +
582      // object evaluator:
583      evaluator_.loadScriptString(rnemdObjectSelection_);
584      seleMan_.setSelectionSet(evaluator_.evaluate());
583    
585      evaluatorA_.loadScriptString(selectionA_);
586      evaluatorB_.loadScriptString(selectionB_);
586    
587      seleManA_.setSelectionSet(evaluatorA_.evaluate());
588      seleManB_.setSelectionSet(evaluatorB_.evaluate());
589    
589      commonA_ = seleManA_ & seleMan_;
590 <    commonB_ = seleManB_ & seleMan_;    
590 >    commonB_ = seleManB_ & seleMan_;  
591    }
592    
593      
# Line 605 | Line 604 | namespace OpenMD {
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) {
# Line 1445 | Line 1448 | namespace OpenMD {
1448      RealType Mc = 0.0;
1449      Mat3x3d Ic(0.0);
1450      RealType Kc = 0.0;
1451 +
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 +    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)) {
# Line 1553 | Line 1594 | namespace OpenMD {
1594                                MPI::REALTYPE, MPI::SUM);
1595   #endif
1596      
1597 +
1598 +    Vector3d ac, acrec, bc, bcrec;
1599 +    Vector3d ah, ahrec, bh, bhrec;
1600 +    RealType cNumerator, cDenominator;
1601 +    RealType hNumerator, hDenominator;
1602 +
1603 +
1604      bool successfulExchange = false;
1605      if ((Mh > 0.0) && (Mc > 0.0)) {//both slabs are not empty
1606        Vector3d vc = Pc / Mc;
1607 <      Vector3d ac = -momentumTarget_ / Mc + vc;
1608 <      Vector3d acrec = -momentumTarget_ / Mc;
1607 >      ac = -momentumTarget_ / Mc + vc;
1608 >      acrec = -momentumTarget_ / Mc;
1609        
1610        // We now need the inverse of the inertia tensor to calculate the
1611        // angular velocity of the cold slab;
1612        Mat3x3d Ici = Ic.inverse();
1613        Vector3d omegac = Ici * Lc;
1614 <      Vector3d bc  = -(Ici * angularMomentumTarget_) + omegac;
1615 <      Vector3d bcrec = bc - omegac;
1614 >      bc  = -(Ici * angularMomentumTarget_) + omegac;
1615 >      bcrec = bc - omegac;
1616        
1617 <      RealType cNumerator = Kc - kineticTarget_
1618 <        - 0.5 * Mc * ac.lengthSquare() - 0.5 * ( dot(bc, Ic * bc));
1617 >      cNumerator = Kc - kineticTarget_;
1618 >      if (doLinearPart)
1619 >        cNumerator -= 0.5 * Mc * ac.lengthSquare();
1620 >      
1621 >      if (doAngularPart)
1622 >        cNumerator -= 0.5 * ( dot(bc, Ic * bc));
1623 >
1624        if (cNumerator > 0.0) {
1625          
1626 <        RealType cDenominator = Kc - 0.5 * Mc * vc.lengthSquare()
1627 <          - 0.5*(dot(omegac, Ic * omegac));
1626 >        cDenominator = Kc;
1627 >
1628 >        if (doLinearPart)
1629 >          cDenominator -= 0.5 * Mc * vc.lengthSquare();
1630 >
1631 >        if (doAngularPart)
1632 >          cDenominator -= 0.5*(dot(omegac, Ic * omegac));
1633          
1634          if (cDenominator > 0.0) {
1635            RealType c = sqrt(cNumerator / cDenominator);
1636            if ((c > 0.9) && (c < 1.1)) {//restrict scaling coefficients
1637              
1638              Vector3d vh = Ph / Mh;
1639 <            Vector3d ah = momentumTarget_ / Mh + vh;
1640 <            Vector3d ahrec = momentumTarget_ / Mh;
1639 >            ah = momentumTarget_ / Mh + vh;
1640 >            ahrec = momentumTarget_ / Mh;
1641              
1642              // We now need the inverse of the inertia tensor to
1643              // calculate the angular velocity of the hot slab;
1644              Mat3x3d Ihi = Ih.inverse();
1645              Vector3d omegah = Ihi * Lh;
1646 <            Vector3d bh  = (Ihi * angularMomentumTarget_) + omegah;
1647 <            Vector3d bhrec = bh - omegah;
1646 >            bh  = (Ihi * angularMomentumTarget_) + omegah;
1647 >            bhrec = bh - omegah;
1648              
1649 <            RealType hNumerator = Kh + kineticTarget_
1650 <              - 0.5 * Mh * ah.lengthSquare() - 0.5 * ( dot(bh, Ih * bh));;
1649 >            hNumerator = Kh + kineticTarget_;
1650 >            if (doLinearPart)
1651 >              hNumerator -= 0.5 * Mh * ah.lengthSquare();
1652 >            
1653 >            if (doAngularPart)
1654 >              hNumerator -= 0.5 * ( dot(bh, Ih * bh));
1655 >              
1656              if (hNumerator > 0.0) {
1657                
1658 <              RealType hDenominator = Kh - 0.5 * Mh * vh.lengthSquare()
1659 <                - 0.5*(dot(omegah, Ih * omegah));
1658 >              hDenominator = Kh;
1659 >              if (doLinearPart)
1660 >                hDenominator -= 0.5 * Mh * vh.lengthSquare();
1661 >              if (doAngularPart)
1662 >                hDenominator -= 0.5*(dot(omegah, Ih * omegah));
1663                
1664                if (hDenominator > 0.0) {
1665                  RealType h = sqrt(hNumerator / hDenominator);
# Line 1606 | Line 1672 | namespace OpenMD {
1672                    for (sdi = coldBin.begin(); sdi != coldBin.end(); sdi++) {
1673                      //vel = (*sdi)->getVel();
1674                      rPos = (*sdi)->getPos() - coordinateOrigin_;
1675 <                    vel = ((*sdi)->getVel() - vc - cross(omegac, rPos)) * c
1676 <                      + ac + cross(bc, rPos);
1675 >                    if (doLinearPart)
1676 >                      vel = ((*sdi)->getVel() - vc) * c + ac;
1677 >                    if (doAngularPart)
1678 >                      vel = ((*sdi)->getVel() - cross(omegac, rPos)) * c + cross(bc, rPos);
1679 >
1680                      (*sdi)->setVel(vel);
1681                      if (rnemdFluxType_ == rnemdFullKE) {
1682                        if ((*sdi)->isDirectional()) {
# Line 1619 | Line 1688 | namespace OpenMD {
1688                    for (sdi = hotBin.begin(); sdi != hotBin.end(); sdi++) {
1689                      //vel = (*sdi)->getVel();
1690                      rPos = (*sdi)->getPos() - coordinateOrigin_;
1691 <                    vel = ((*sdi)->getVel() - vh - cross(omegah, rPos)) * h
1692 <                      + ah + cross(bh, rPos);    
1693 <                    cerr << "setting vel to " << vel << "\n";
1691 >                    if (doLinearPart)
1692 >                      vel = ((*sdi)->getVel() - vh) * h + ah;    
1693 >                    if (doAngularPart)
1694 >                      vel = ((*sdi)->getVel() - cross(omegah, rPos)) * h + cross(bh, rPos);    
1695 >
1696                      (*sdi)->setVel(vel);
1697                      if (rnemdFluxType_ == rnemdFullKE) {
1698                        if ((*sdi)->isDirectional()) {
# Line 1664 | Line 1735 | namespace OpenMD {
1735        int isd;
1736        StuntDouble* sd;
1737        vector<StuntDouble*> aSites;
1667      ConvexHull* surfaceMeshA = new ConvexHull();
1738        seleManA_.setSelectionSet(evaluatorA_.evaluate());
1739        for (sd = seleManA_.beginSelected(isd); sd != NULL;
1740             sd = seleManA_.nextSelected(isd)) {
1741          aSites.push_back(sd);
1742        }
1743 +      ConvexHull* surfaceMeshA = new ConvexHull();
1744        surfaceMeshA->computeHull(aSites);
1745        areaA = surfaceMeshA->getArea();
1746 +      delete surfaceMeshA;
1747 +
1748      } else {
1749        if (usePeriodicBoundaryConditions_) {
1750          // in periodic boundaries, the surface area is twice the x-y
# Line 1685 | Line 1758 | namespace OpenMD {
1758        }
1759      }
1760  
1761 +
1762 +
1763      if (hasSelectionB_) {
1764        int isd;
1765        StuntDouble* sd;
1766        vector<StuntDouble*> bSites;
1692      ConvexHull* surfaceMeshB = new ConvexHull();
1767        seleManB_.setSelectionSet(evaluatorB_.evaluate());
1768        for (sd = seleManB_.beginSelected(isd); sd != NULL;
1769             sd = seleManB_.nextSelected(isd)) {
1770          bSites.push_back(sd);
1771        }
1772 +      ConvexHull* surfaceMeshB = new ConvexHull();    
1773        surfaceMeshB->computeHull(bSites);
1774        areaB = surfaceMeshB->getArea();
1775 +      delete surfaceMeshB;
1776 +
1777      } else {
1778        if (usePeriodicBoundaryConditions_) {
1779          // in periodic boundaries, the surface area is twice the x-y
# Line 1718 | Line 1795 | namespace OpenMD {
1795      if (!doRNEMD_) return;
1796      trialCount_++;
1797  
1721    cerr << "trialCount = " << trialCount_ << "\n";
1798      // object evaluator:
1799      evaluator_.loadScriptString(rnemdObjectSelection_);
1800      seleMan_.setSelectionSet(evaluator_.evaluate());
# Line 1764 | Line 1840 | namespace OpenMD {
1840      if (!doRNEMD_) return;
1841      Snapshot* currentSnap_ = info_->getSnapshotManager()->getCurrentSnapshot();
1842      
1767    cerr << "collecting data\n";
1843      // collectData can be called more frequently than the doRNEMD, so use the
1844      // computed area from the last exchange time:
1845      RealType area = getDividingArea();
# Line 1903 | Line 1978 | namespace OpenMD {
1978        vel.x() = binPx[i] / binMass[i];
1979        vel.y() = binPy[i] / binMass[i];
1980        vel.z() = binPz[i] / binMass[i];
1981 <      aVel.x() = binOmegax[i];
1982 <      aVel.y() = binOmegay[i];
1983 <      aVel.z() = binOmegaz[i];
1981 >      aVel.x() = binOmegax[i] / binCount[i];
1982 >      aVel.y() = binOmegay[i] / binCount[i];
1983 >      aVel.z() = binOmegaz[i] / binCount[i];
1984  
1985        if (binCount[i] > 0) {
1986          // only add values if there are things to add
# Line 1938 | Line 2013 | namespace OpenMD {
2013          }
2014        }
2015      }
2016 +    hasData_ = true;
2017    }
2018  
2019    void RNEMD::getStarted() {
# Line 1970 | Line 2046 | namespace OpenMD {
2046    
2047    void RNEMD::writeOutputFile() {
2048      if (!doRNEMD_) return;
2049 +    if (!hasData_) return;
2050      
2051   #ifdef IS_MPI
2052      // If we're the root node, should we print out the results
# Line 1991 | Line 2068 | namespace OpenMD {
2068        RealType time = currentSnap_->getTime();
2069        RealType avgArea;
2070        areaAccumulator_->getAverage(avgArea);
2071 <      RealType Jz = kineticExchange_ / (time * avgArea)
2072 <        / PhysicalConstants::energyConvert;
2073 <      Vector3d JzP = momentumExchange_ / (time * avgArea);      
2074 <      Vector3d JzL = angularMomentumExchange_ / (time * avgArea);      
2071 >
2072 >      RealType Jz(0.0);
2073 >      Vector3d JzP(V3Zero);
2074 >      Vector3d JzL(V3Zero);
2075 >      if (time >= info_->getSimParams()->getDt()) {
2076 >        Jz = kineticExchange_ / (time * avgArea)
2077 >          / PhysicalConstants::energyConvert;
2078 >        JzP = momentumExchange_ / (time * avgArea);
2079 >        JzL = angularMomentumExchange_ / (time * avgArea);
2080 >      }
2081  
2082        rnemdFile_ << "#######################################################\n";
2083        rnemdFile_ << "# RNEMD {\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines