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

Comparing branches/development/src/brains/ForceManager.cpp (file contents):
Revision 1711 by gezelter, Sat May 19 02:58:35 2012 UTC vs.
Revision 1756 by gezelter, Mon Jun 18 18:23:20 2012 UTC

# Line 110 | Line 110 | namespace OpenMD {
110      Globals* simParams_ = info_->getSimParams();
111      ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
112      int mdFileVersion;
113 +    rCut_ = 0.0; //Needs a value for a later max() call;  
114      
115      if (simParams_->haveMDfileVersion())
116        mdFileVersion = simParams_->getMDfileVersion();
# Line 390 | Line 391 | namespace OpenMD {
391        info_->prepareTopology();      
392  
393        doParticlePot_ = info_->getSimParams()->getOutputParticlePotential();
394 <      cerr << "dPP = " << doParticlePot_ << "\n";
394 >      doHeatFlux_ = info_->getSimParams()->getPrintHeatFlux();
395 >      if (doHeatFlux_) doParticlePot_ = true;
396    
397      }
398  
# Line 472 | Line 474 | namespace OpenMD {
474      }
475      
476      // Zero out the stress tensor
477 <    tau *= 0.0;
478 <    
477 >    stressTensor *= 0.0;
478 >    // Zero out the heatFlux
479 >    fDecomp_->setHeatFlux( Vector3d(0.0) );    
480    }
481    
482    void ForceManager::shortRangeInteractions() {
# Line 506 | Line 509 | namespace OpenMD {
509  
510        for (bond = mol->beginBond(bondIter); bond != NULL;
511             bond = mol->nextBond(bondIter)) {
512 <        bond->calcForce();
512 >        bond->calcForce(doParticlePot_);
513          bondPotential += bond->getPotential();
514        }
515  
# Line 514 | Line 517 | namespace OpenMD {
517             bend = mol->nextBend(bendIter)) {
518          
519          RealType angle;
520 <        bend->calcForce(angle);
520 >        bend->calcForce(angle, doParticlePot_);
521          RealType currBendPot = bend->getPotential();          
522          
523          bendPotential += bend->getPotential();
# Line 539 | Line 542 | namespace OpenMD {
542        for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
543             torsion = mol->nextTorsion(torsionIter)) {
544          RealType angle;
545 <        torsion->calcForce(angle);
545 >        torsion->calcForce(angle, doParticlePot_);
546          RealType currTorsionPot = torsion->getPotential();
547          torsionPotential += torsion->getPotential();
548          map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion);
# Line 563 | Line 566 | namespace OpenMD {
566             inversion != NULL;
567             inversion = mol->nextInversion(inversionIter)) {
568          RealType angle;
569 <        inversion->calcForce(angle);
569 >        inversion->calcForce(angle, doParticlePot_);
570          RealType currInversionPot = inversion->getPotential();
571          inversionPotential += inversion->getPotential();
572          map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion);
# Line 596 | Line 599 | namespace OpenMD {
599    
600    void ForceManager::longRangeInteractions() {
601  
602 +
603      Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
604      DataStorage* config = &(curSnapshot->atomData);
605      DataStorage* cgConfig = &(curSnapshot->cgData);
# Line 619 | Line 623 | namespace OpenMD {
623        // center of mass of the group is the same as position of the atom  
624        // if cutoff group does not exist
625        cgConfig->position = config->position;
626 +      cgConfig->velocity = config->velocity;
627      }
628  
629      fDecomp_->zeroWorkArrays();
630      fDecomp_->distributeData();
631      
632      int cg1, cg2, atom1, atom2, topoDist;
633 <    Vector3d d_grp, dag, d;
633 >    Vector3d d_grp, dag, d, gvel2, vel2;
634      RealType rgrpsq, rgrp, r2, r;
635      RealType electroMult, vdwMult;
636      RealType vij;
# Line 640 | Line 645 | namespace OpenMD {
645      RealType mf;
646      RealType lrPot;
647      RealType vpair;
648 +    RealType dVdFQ1(0.0);
649 +    RealType dVdFQ2(0.0);
650      potVec longRangePotential(0.0);
651      potVec workPot(0.0);
652 +    vector<int>::iterator ia, jb;
653  
654      int loopStart, loopEnd;
655  
# Line 650 | Line 658 | namespace OpenMD {
658      idat.pot = &workPot;
659      sdat.pot = fDecomp_->getEmbeddingPotential();
660      idat.vpair = &vpair;
661 +    idat.dVdFQ1 = &dVdFQ1;
662 +    idat.dVdFQ2 = &dVdFQ2;
663      idat.f1 = &f1;
664      idat.sw = &sw;
665      idat.shiftedPot = (cutoffMethod_ == SHIFTED_POTENTIAL) ? true : false;
# Line 663 | Line 673 | namespace OpenMD {
673      } else {
674        loopStart = PAIR_LOOP;
675      }
666  
676      for (int iLoop = loopStart; iLoop <= loopEnd; iLoop++) {
677      
678        if (iLoop == loopStart) {
# Line 695 | Line 704 | namespace OpenMD {
704            
705            in_switching_region = switcher_->getSwitch(rgrpsq, sw, dswdr,
706                                                       rgrp);
707 <          
707 >
708            atomListRow = fDecomp_->getAtomsInGroupRow(cg1);
709            atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2);
710  
711 <          for (vector<int>::iterator ia = atomListRow.begin();
711 >          if (doHeatFlux_)
712 >            gvel2 = fDecomp_->getGroupVelocityColumn(cg2);
713 >
714 >          for (ia = atomListRow.begin();
715                 ia != atomListRow.end(); ++ia) {            
716              atom1 = (*ia);
717 <            
718 <            for (vector<int>::iterator jb = atomListColumn.begin();
717 >
718 >            for (jb = atomListColumn.begin();
719                   jb != atomListColumn.end(); ++jb) {              
720                atom2 = (*jb);
721  
722 <              if (!fDecomp_->skipAtomPair(atom1, atom2)) {
722 >              if (!fDecomp_->skipAtomPair(atom1, atom2, cg1, cg2)) {
723 >
724                  vpair = 0.0;
725                  workPot = 0.0;
726                  f1 = V3Zero;
727 +                dVdFQ1 = 0.0;
728 +                dVdFQ2 = 0.0;
729  
730                  fDecomp_->fillInteractionData(idat, atom1, atom2);
731 <                
731 >
732                  topoDist = fDecomp_->getTopologicalDistance(atom1, atom2);
733                  vdwMult = vdwScale_[topoDist];
734                  electroMult = electrostaticScale_[topoDist];
# Line 721 | Line 736 | namespace OpenMD {
736                  if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
737                    idat.d = &d_grp;
738                    idat.r2 = &rgrpsq;
739 +                  if (doHeatFlux_)
740 +                    vel2 = gvel2;
741                  } else {
742                    d = fDecomp_->getInteratomicVector(atom1, atom2);
743                    curSnapshot->wrapVector( d );
744                    r2 = d.lengthSquare();
745                    idat.d = &d;
746                    idat.r2 = &r2;
747 +                  if (doHeatFlux_)
748 +                    vel2 = fDecomp_->getAtomVelocityColumn(atom2);
749                  }
750                
751                  r = sqrt( *(idat.r2) );
# Line 739 | Line 758 | namespace OpenMD {
758                    fDecomp_->unpackInteractionData(idat, atom1, atom2);
759                    vij += vpair;
760                    fij += f1;
761 <                  tau -= outProduct( *(idat.d), f1);
761 >                  stressTensor -= outProduct( *(idat.d), f1);
762 >                  if (doHeatFlux_)
763 >                    fDecomp_->addToHeatFlux(*(idat.d) * dot(f1, vel2));
764                  }
765                }
766              }
# Line 752 | Line 773 | namespace OpenMD {
773                fij += fg;
774  
775                if (atomListRow.size() == 1 && atomListColumn.size() == 1) {
776 <                tau -= outProduct( *(idat.d), fg);
776 >                stressTensor -= outProduct( *(idat.d), fg);
777 >                if (doHeatFlux_)
778 >                  fDecomp_->addToHeatFlux(*(idat.d) * dot(fg, vel2));
779 >                
780                }
781            
782 <              for (vector<int>::iterator ia = atomListRow.begin();
782 >              for (ia = atomListRow.begin();
783                     ia != atomListRow.end(); ++ia) {            
784                  atom1 = (*ia);                
785                  mf = fDecomp_->getMassFactorRow(atom1);
# Line 768 | Line 792 | namespace OpenMD {
792                      // find the distance between the atom
793                      // and the center of the cutoff group:
794                      dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1);
795 <                    tau -= outProduct(dag, fg);
795 >                    stressTensor -= outProduct(dag, fg);
796 >                    if (doHeatFlux_)
797 >                      fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
798                    }
799                  }
800                }
801 <              for (vector<int>::iterator jb = atomListColumn.begin();
801 >              for (jb = atomListColumn.begin();
802                     jb != atomListColumn.end(); ++jb) {              
803                  atom2 = (*jb);
804                  mf = fDecomp_->getMassFactorColumn(atom2);
# Line 786 | Line 812 | namespace OpenMD {
812                      // find the distance between the atom
813                      // and the center of the cutoff group:
814                      dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2);
815 <                    tau -= outProduct(dag, fg);
815 >                    stressTensor -= outProduct(dag, fg);
816 >                    if (doHeatFlux_)
817 >                      fDecomp_->addToHeatFlux( dag * dot(fg, vel2));
818                    }
819                  }
820                }
821              }
822              //if (!info_->usesAtomicVirial()) {
823 <            //  tau -= outProduct(d_grp, fij);
823 >            //  stressTensor -= outProduct(d_grp, fij);
824 >            //  if (doHeatFlux_)
825 >            //     fDecomp_->addToHeatFlux( d_grp * dot(fij, vel2));
826              //}
827            }
828          }
# Line 814 | Line 844 | namespace OpenMD {
844        }
845      }
846      
847 +    // collects pairwise information
848      fDecomp_->collectData();
849          
850      if (info_->requiresSelfCorrection()) {
851 <
821 <      for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {          
851 >      for (int atom1 = 0; atom1 < info_->getNAtoms(); atom1++) {
852          fDecomp_->fillSelfData(sdat, atom1);
853          interactionMan_->doSelfCorrection(sdat);
854        }
825
855      }
856  
857 +    // collects single-atom information
858 +    fDecomp_->collectSelfData();
859 +
860      longRangePotential = *(fDecomp_->getEmbeddingPotential()) +
861        *(fDecomp_->getPairwisePotential());
862  
863      lrPot = longRangePotential.sum();
864  
865 <    //store the tau and long range potential    
865 >    //store the stressTensor and long range potential    
866      curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot;
867      curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY];
868      curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY];
# Line 851 | Line 883 | namespace OpenMD {
883        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
884             rb = mol->nextRigidBody(rbIter)) {
885          Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial();
886 <        tau += rbTau;
886 >        stressTensor += rbTau;
887        }
888      }
889      
890   #ifdef IS_MPI
891 <    Mat3x3d tmpTau(tau);
892 <    MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(),
861 <                  9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
891 >    MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, stressTensor.getArrayPointer(), 9,
892 >                              MPI::REALTYPE, MPI::SUM);
893   #endif
894 <    curSnapshot->setTau(tau);
894 >    curSnapshot->setStressTensor(stressTensor);
895 >    
896    }
897  
898   } //end namespace OpenMD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines