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

Comparing trunk/src/constraints/ZconstraintForceManager.cpp (file contents):
Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
Revision 1442 by gezelter, Mon May 10 17:28:26 2010 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
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).          
39 + * [4]  Vardeman & Gezelter, in progress (2009).                        
40   */
41  
42   #include <cmath>
43   #include "constraints/ZconstraintForceManager.hpp"
44   #include "integrators/Integrator.hpp"
45   #include "utils/simError.h"
46 < #include "utils/OOPSEConstant.hpp"
46 > #include "utils/PhysicalConstants.hpp"
47   #include "utils/StringUtils.hpp"
48 < namespace oopse {
48 > namespace OpenMD {
49    ZconstraintForceManager::ZconstraintForceManager(SimInfo* info): ForceManager(info), infiniteTime(1e31) {
50      currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
51      Globals* simParam = info_->getSimParams();
# Line 77 | Line 77 | namespace oopse {
77        zconsTol_ = 0.01;
78        sprintf(painCave.errMsg,
79                "ZConstraint Warning: Tolerance for z-constraint method is not specified.\n"
80 <              "\tOOPSE will use a default value of %f.\n"
80 >              "\tOpenMD will use a default value of %f.\n"
81                "\tTo set the tolerance, use the zconsTol variable.\n",
82                zconsTol_);
83        painCave.isFatal = 0;
# Line 111 | Line 111 | namespace oopse {
111  
112      //estimate the force constant of harmonical potential
113      Mat3x3d hmat = currSnapshot_->getHmat();
114 <    double halfOfLargestBox = std::max(hmat(0, 0), std::max(hmat(1, 1), hmat(2, 2))) /2;        
115 <    double targetTemp;
114 >    RealType halfOfLargestBox = std::max(hmat(0, 0), std::max(hmat(1, 1), hmat(2, 2))) /2;      
115 >    RealType targetTemp;
116      if (simParam->haveTargetTemp()) {
117        targetTemp = simParam->getTargetTemp();
118      } else {
119        targetTemp = 298.0;
120      }
121 <    double zforceConstant = OOPSEConstant::kb * targetTemp / (halfOfLargestBox * halfOfLargestBox);
121 >    RealType zforceConstant = PhysicalConstants::kb * targetTemp / (halfOfLargestBox * halfOfLargestBox);
122          
123      int nZconstraints = simParam->getNZconsStamps();
124      std::vector<ZConsStamp*> stamp = simParam->getZconsStamps();
# Line 148 | Line 148 | namespace oopse {
148      update();
149      
150      //calculate masss of unconstraint molecules in the whole system (never change during the simulation)
151 <    double totMassUnconsMols_local = 0.0;    
151 >    RealType totMassUnconsMols_local = 0.0;    
152      std::vector<Molecule*>::iterator j;
153      for ( j = unzconsMols_.begin(); j !=  unzconsMols_.end(); ++j) {
154        totMassUnconsMols_local += (*j)->getMass();
# Line 156 | Line 156 | namespace oopse {
156   #ifndef IS_MPI
157      totMassUnconsMols_ = totMassUnconsMols_local;
158   #else
159 <    MPI_Allreduce(&totMassUnconsMols_local, &totMassUnconsMols_, 1, MPI_DOUBLE,
159 >    MPI_Allreduce(&totMassUnconsMols_local, &totMassUnconsMols_, 1, MPI_REALTYPE,
160                    MPI_SUM, MPI_COMM_WORLD);  
161   #endif
162  
# Line 194 | Line 194 | namespace oopse {
194          zmol.param = i->second;
195          zmol.cantPos = zmol.param.zTargetPos; /**@todo fixed me when zmol migrate, it is incorrect*/
196          Vector3d com = zmol.mol->getCom();
197 <        double diff = fabs(zmol.param.zTargetPos - com[whichDirection]);
197 >        RealType diff = fabs(zmol.param.zTargetPos - com[whichDirection]);
198          if (diff < zconsTol_) {
199            fixedZMols_.push_back(zmol);
200          } else {
# Line 299 | Line 299 | namespace oopse {
299  
300      // calculate the vz of center of mass of moving molecules(include unconstrained molecules
301      // and moving z-constrained molecules)  
302 <    double pzMovingMols_local = 0.0;
303 <    double pzMovingMols;
302 >    RealType pzMovingMols_local = 0.0;
303 >    RealType pzMovingMols;
304      
305      for ( i = movingZMols_.begin(); i !=  movingZMols_.end(); ++i) {
306        mol = i->mol;        
# Line 318 | Line 318 | namespace oopse {
318   #ifndef IS_MPI
319      pzMovingMols = pzMovingMols_local;
320   #else
321 <    MPI_Allreduce(&pzMovingMols_local, &pzMovingMols, 1, MPI_DOUBLE,
321 >    MPI_Allreduce(&pzMovingMols_local, &pzMovingMols, 1, MPI_REALTYPE,
322                    MPI_SUM, MPI_COMM_WORLD);
323   #endif
324  
325 <    double vzMovingMols = pzMovingMols / (totMassMovingZMols_ + totMassUnconsMols_);
325 >    RealType vzMovingMols = pzMovingMols / (totMassMovingZMols_ + totMassUnconsMols_);
326  
327      //modify the velocities of moving z-constrained molecuels
328      for ( i = movingZMols_.begin(); i !=  movingZMols_.end(); ++i) {
# Line 352 | Line 352 | namespace oopse {
352  
353  
354    void ZconstraintForceManager::doZconstraintForce(){
355 <    double totalFZ;
356 <    double totalFZ_local;
355 >    RealType totalFZ;
356 >    RealType totalFZ_local;
357      Vector3d com;
358      Vector3d force(0.0);
359  
# Line 383 | Line 383 | namespace oopse {
383  
384      //calculate total z-constraint force
385   #ifdef IS_MPI
386 <    MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
386 >    MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
387   #else
388      totalFZ = totalFZ_local;
389   #endif
# Line 427 | Line 427 | namespace oopse {
427  
428  
429    void ZconstraintForceManager::doHarmonic(){
430 <    double totalFZ;
430 >    RealType totalFZ;
431      Vector3d force(0.0);
432      Vector3d com;
433 <    double totalFZ_local = 0;
433 >    RealType totalFZ_local = 0;
434      std::list<ZconstraintMol>::iterator i;
435      StuntDouble* integrableObject;
436      Molecule::IntegrableObjectIterator ii;
# Line 438 | Line 438 | namespace oopse {
438      for ( i = movingZMols_.begin(); i !=  movingZMols_.end(); ++i) {
439        mol = i->mol;
440        com = mol->getCom();  
441 <      double resPos = usingSMD_? i->cantPos : i->param.zTargetPos;
442 <      double diff = com[whichDirection] - resPos;
443 <      double harmonicU = 0.5 * i->param.kz * diff * diff;
441 >      RealType resPos = usingSMD_? i->cantPos : i->param.zTargetPos;
442 >      RealType diff = com[whichDirection] - resPos;
443 >      RealType harmonicU = 0.5 * i->param.kz * diff * diff;
444        currSnapshot_->statData[Stats::LONG_RANGE_POTENTIAL] += harmonicU;
445 <      double harmonicF = -i->param.kz * diff;
445 >      RealType harmonicF = -i->param.kz * diff;
446        totalFZ_local += harmonicF;
447  
448        //adjust force
# Line 457 | Line 457 | namespace oopse {
457   #ifndef IS_MPI
458      totalFZ = totalFZ_local;
459   #else
460 <    MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);  
460 >    MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);  
461   #endif
462  
463      //modify the forces of unconstrained molecules
# Line 476 | Line 476 | namespace oopse {
476  
477    bool ZconstraintForceManager::checkZConsState(){
478      Vector3d com;
479 <    double diff;
479 >    RealType diff;
480      int changed_local = 0;
481  
482      std::list<ZconstraintMol>::iterator i;
# Line 566 | Line 566 | namespace oopse {
566  
567    void ZconstraintForceManager::calcTotalMassMovingZMols(){
568  
569 <    double totMassMovingZMols_local = 0.0;
569 >    RealType totMassMovingZMols_local = 0.0;
570      std::list<ZconstraintMol>::iterator i;
571      for ( i = movingZMols_.begin(); i !=  movingZMols_.end(); ++i) {
572        totMassMovingZMols_local += i->mol->getMass();
573      }
574      
575   #ifdef IS_MPI
576 <    MPI_Allreduce(&totMassMovingZMols_local, &totMassMovingZMols_, 1, MPI_DOUBLE,
576 >    MPI_Allreduce(&totMassMovingZMols_local, &totMassMovingZMols_, 1, MPI_REALTYPE,
577                    MPI_SUM, MPI_COMM_WORLD);
578   #else
579      totMassMovingZMols_ = totMassMovingZMols_local;
# Line 581 | Line 581 | namespace oopse {
581  
582    }
583  
584 <  double ZconstraintForceManager::getZFOfFixedZMols(Molecule* mol, StuntDouble* sd, double totalForce){
584 >  RealType ZconstraintForceManager::getZFOfFixedZMols(Molecule* mol, StuntDouble* sd, RealType totalForce){
585      return totalForce * sd->getMass() / mol->getMass();
586    }
587  
588 <  double ZconstraintForceManager::getZFOfMovingMols(Molecule* mol, double totalForce){
588 >  RealType ZconstraintForceManager::getZFOfMovingMols(Molecule* mol, RealType totalForce){
589      return totalForce * mol->getMass() / (totMassUnconsMols_ + totMassMovingZMols_);
590    }
591  
592 <  double ZconstraintForceManager::getHFOfFixedZMols(Molecule* mol, StuntDouble*sd, double totalForce){
592 >  RealType ZconstraintForceManager::getHFOfFixedZMols(Molecule* mol, StuntDouble*sd, RealType totalForce){
593      return totalForce * sd->getMass() / mol->getMass();
594    }
595  
596 <  double ZconstraintForceManager::getHFOfUnconsMols(Molecule* mol, double totalForce){
596 >  RealType ZconstraintForceManager::getHFOfUnconsMols(Molecule* mol, RealType totalForce){
597      return totalForce * mol->getMass() / totMassUnconsMols_;
598    }
599  
600    void ZconstraintForceManager::updateZPos(){
601 <    double curTime = currSnapshot_->getTime();
601 >    RealType curTime = currSnapshot_->getTime();
602      std::list<ZconstraintMol>::iterator i;
603      for ( i = fixedZMols_.begin(); i !=  fixedZMols_.end(); ++i) {
604        i->param.zTargetPos += zconsGap_;    
# Line 612 | Line 612 | namespace oopse {
612      }
613    }
614  
615 <  double ZconstraintForceManager::getZTargetPos(int index){
616 <    double zTargetPos;
615 >  RealType ZconstraintForceManager::getZTargetPos(int index){
616 >    RealType zTargetPos;
617   #ifndef IS_MPI    
618      Molecule* mol = info_->getMoleculeByGlobalIndex(index);
619      assert(mol);
# Line 621 | Line 621 | namespace oopse {
621      zTargetPos = com[whichDirection];
622   #else
623      int whicProc = info_->getMolToProc(index);
624 <    MPI_Bcast(&zTargetPos, 1, MPI_DOUBLE, whicProc, MPI_COMM_WORLD);
624 >    MPI_Bcast(&zTargetPos, 1, MPI_REALTYPE, whicProc, MPI_COMM_WORLD);
625   #endif
626      return zTargetPos;
627    }

Comparing trunk/src/constraints/ZconstraintForceManager.cpp (property svn:keywords):
Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
Revision 1442 by gezelter, Mon May 10 17:28:26 2010 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines