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

Comparing:
trunk/src/constraints/ZconstraintForceManager.cpp (file contents), Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
branches/development/src/constraints/ZconstraintForceManager.cpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 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]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include <cmath>
44   #include "constraints/ZconstraintForceManager.hpp"
45   #include "integrators/Integrator.hpp"
46   #include "utils/simError.h"
47 < #include "utils/OOPSEConstant.hpp"
47 > #include "utils/PhysicalConstants.hpp"
48   #include "utils/StringUtils.hpp"
49 < namespace oopse {
49 > #ifdef IS_MPI
50 > #include <mpi.h>
51 > #endif
52 >
53 > namespace OpenMD {
54    ZconstraintForceManager::ZconstraintForceManager(SimInfo* info): ForceManager(info), infiniteTime(1e31) {
55      currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
56      Globals* simParam = info_->getSimParams();
# Line 59 | Line 64 | namespace oopse {
64        simError();    
65      }
66  
67 <    if (simParam->haveZconstraintTime()){
67 >    if (simParam->haveZconsTime()){
68        zconsTime_ = simParam->getZconsTime();
69      }
70      else{
# Line 77 | Line 82 | namespace oopse {
82        zconsTol_ = 0.01;
83        sprintf(painCave.errMsg,
84                "ZConstraint Warning: Tolerance for z-constraint method is not specified.\n"
85 <              "\tOOPSE will use a default value of %f.\n"
85 >              "\tOpenMD will use a default value of %f.\n"
86                "\tTo set the tolerance, use the zconsTol variable.\n",
87                zconsTol_);
88        painCave.isFatal = 0;
# Line 85 | Line 90 | namespace oopse {
90      }
91  
92      //set zcons gap
93 <    if (simParam->haveZConsGap()){
93 >    if (simParam->haveZconsGap()){
94        usingZconsGap_ = true;
95        zconsGap_ = simParam->getZconsGap();
96      }else {
# Line 94 | Line 99 | namespace oopse {
99      }
100  
101      //set zcons fixtime
102 <    if (simParam->haveZConsFixTime()){
102 >    if (simParam->haveZconsFixtime()){
103        zconsFixingTime_ = simParam->getZconsFixtime();
104      } else {
105        zconsFixingTime_ = infiniteTime;
106      }
107  
108      //set zconsUsingSMD
109 <    if (simParam->haveZConsUsingSMD()){
109 >    if (simParam->haveZconsUsingSMD()){
110        usingSMD_ = simParam->getZconsUsingSMD();
111      }else {
112        usingSMD_ =false;
# Line 111 | Line 116 | namespace oopse {
116  
117      //estimate the force constant of harmonical potential
118      Mat3x3d hmat = currSnapshot_->getHmat();
119 <    double halfOfLargestBox = std::max(hmat(0, 0), std::max(hmat(1, 1), hmat(2, 2))) /2;        
120 <    double targetTemp;
119 >    RealType halfOfLargestBox = std::max(hmat(0, 0), std::max(hmat(1, 1), hmat(2, 2))) /2;      
120 >    RealType targetTemp;
121      if (simParam->haveTargetTemp()) {
122        targetTemp = simParam->getTargetTemp();
123      } else {
124        targetTemp = 298.0;
125      }
126 <    double zforceConstant = OOPSEConstant::kb * targetTemp / (halfOfLargestBox * halfOfLargestBox);
126 >    RealType zforceConstant = PhysicalConstants::kb * targetTemp / (halfOfLargestBox * halfOfLargestBox);
127          
128 <    int nZconstraints = simParam->getNzConstraints();
129 <    ZconStamp** stamp = simParam->getZconStamp();
128 >    int nZconstraints = simParam->getNZconsStamps();
129 >    std::vector<ZConsStamp*> stamp = simParam->getZconsStamps();
130      //
131      for (int i = 0; i < nZconstraints; i++){
132  
# Line 148 | Line 153 | namespace oopse {
153      update();
154      
155      //calculate masss of unconstraint molecules in the whole system (never change during the simulation)
156 <    double totMassUnconsMols_local = 0.0;    
156 >    RealType totMassUnconsMols_local = 0.0;    
157      std::vector<Molecule*>::iterator j;
158      for ( j = unzconsMols_.begin(); j !=  unzconsMols_.end(); ++j) {
159        totMassUnconsMols_local += (*j)->getMass();
# Line 156 | Line 161 | namespace oopse {
161   #ifndef IS_MPI
162      totMassUnconsMols_ = totMassUnconsMols_local;
163   #else
164 <    MPI_Allreduce(&totMassUnconsMols_local, &totMassUnconsMols_, 1, MPI_DOUBLE,
164 >    MPI_Allreduce(&totMassUnconsMols_local, &totMassUnconsMols_, 1, MPI_REALTYPE,
165                    MPI_SUM, MPI_COMM_WORLD);  
166   #endif
167  
# Line 194 | Line 199 | namespace oopse {
199          zmol.param = i->second;
200          zmol.cantPos = zmol.param.zTargetPos; /**@todo fixed me when zmol migrate, it is incorrect*/
201          Vector3d com = zmol.mol->getCom();
202 <        double diff = fabs(zmol.param.zTargetPos - com[whichDirection]);
202 >        RealType diff = fabs(zmol.param.zTargetPos - com[whichDirection]);
203          if (diff < zconsTol_) {
204            fixedZMols_.push_back(zmol);
205          } else {
# Line 240 | Line 245 | namespace oopse {
245      currZconsTime_ = currSnapshot_->getTime();
246    }
247  
248 <  void ZconstraintForceManager::calcForces(bool needPotential, bool needStress){
249 <    ForceManager::calcForces(needPotential, needStress);
248 >  void ZconstraintForceManager::calcForces(){
249 >    ForceManager::calcForces();
250      
251      if (usingZconsGap_){
252        updateZPos();
# Line 299 | Line 304 | namespace oopse {
304  
305      // calculate the vz of center of mass of moving molecules(include unconstrained molecules
306      // and moving z-constrained molecules)  
307 <    double pzMovingMols_local = 0.0;
308 <    double pzMovingMols;
307 >    RealType pzMovingMols_local = 0.0;
308 >    RealType pzMovingMols;
309      
310      for ( i = movingZMols_.begin(); i !=  movingZMols_.end(); ++i) {
311        mol = i->mol;        
# Line 318 | Line 323 | namespace oopse {
323   #ifndef IS_MPI
324      pzMovingMols = pzMovingMols_local;
325   #else
326 <    MPI_Allreduce(&pzMovingMols_local, &pzMovingMols, 1, MPI_DOUBLE,
326 >    MPI_Allreduce(&pzMovingMols_local, &pzMovingMols, 1, MPI_REALTYPE,
327                    MPI_SUM, MPI_COMM_WORLD);
328   #endif
329  
330 <    double vzMovingMols = pzMovingMols / (totMassMovingZMols_ + totMassUnconsMols_);
330 >    RealType vzMovingMols = pzMovingMols / (totMassMovingZMols_ + totMassUnconsMols_);
331  
332      //modify the velocities of moving z-constrained molecuels
333      for ( i = movingZMols_.begin(); i !=  movingZMols_.end(); ++i) {
# Line 352 | Line 357 | namespace oopse {
357  
358  
359    void ZconstraintForceManager::doZconstraintForce(){
360 <    double totalFZ;
361 <    double totalFZ_local;
360 >    RealType totalFZ;
361 >    RealType totalFZ_local;
362      Vector3d com;
363      Vector3d force(0.0);
364  
# Line 383 | Line 388 | namespace oopse {
388  
389      //calculate total z-constraint force
390   #ifdef IS_MPI
391 <    MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
391 >    MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);
392   #else
393      totalFZ = totalFZ_local;
394   #endif
# Line 427 | Line 432 | namespace oopse {
432  
433  
434    void ZconstraintForceManager::doHarmonic(){
435 <    double totalFZ;
435 >    RealType totalFZ;
436      Vector3d force(0.0);
437      Vector3d com;
438 <    double totalFZ_local = 0;
438 >    RealType totalFZ_local = 0;
439      std::list<ZconstraintMol>::iterator i;
440      StuntDouble* integrableObject;
441      Molecule::IntegrableObjectIterator ii;
# Line 438 | Line 443 | namespace oopse {
443      for ( i = movingZMols_.begin(); i !=  movingZMols_.end(); ++i) {
444        mol = i->mol;
445        com = mol->getCom();  
446 <      double resPos = usingSMD_? i->cantPos : i->param.zTargetPos;
447 <      double diff = com[whichDirection] - resPos;
448 <      double harmonicU = 0.5 * i->param.kz * diff * diff;
446 >      RealType resPos = usingSMD_? i->cantPos : i->param.zTargetPos;
447 >      RealType diff = com[whichDirection] - resPos;
448 >      RealType harmonicU = 0.5 * i->param.kz * diff * diff;
449        currSnapshot_->statData[Stats::LONG_RANGE_POTENTIAL] += harmonicU;
450 <      double harmonicF = -i->param.kz * diff;
450 >      RealType harmonicF = -i->param.kz * diff;
451        totalFZ_local += harmonicF;
452  
453        //adjust force
# Line 457 | Line 462 | namespace oopse {
462   #ifndef IS_MPI
463      totalFZ = totalFZ_local;
464   #else
465 <    MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);  
465 >    MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD);  
466   #endif
467  
468      //modify the forces of unconstrained molecules
# Line 476 | Line 481 | namespace oopse {
481  
482    bool ZconstraintForceManager::checkZConsState(){
483      Vector3d com;
484 <    double diff;
484 >    RealType diff;
485      int changed_local = 0;
486  
487      std::list<ZconstraintMol>::iterator i;
# Line 566 | Line 571 | namespace oopse {
571  
572    void ZconstraintForceManager::calcTotalMassMovingZMols(){
573  
574 <    double totMassMovingZMols_local = 0.0;
574 >    RealType totMassMovingZMols_local = 0.0;
575      std::list<ZconstraintMol>::iterator i;
576      for ( i = movingZMols_.begin(); i !=  movingZMols_.end(); ++i) {
577        totMassMovingZMols_local += i->mol->getMass();
578      }
579      
580   #ifdef IS_MPI
581 <    MPI_Allreduce(&totMassMovingZMols_local, &totMassMovingZMols_, 1, MPI_DOUBLE,
581 >    MPI_Allreduce(&totMassMovingZMols_local, &totMassMovingZMols_, 1, MPI_REALTYPE,
582                    MPI_SUM, MPI_COMM_WORLD);
583   #else
584      totMassMovingZMols_ = totMassMovingZMols_local;
# Line 581 | Line 586 | namespace oopse {
586  
587    }
588  
589 <  double ZconstraintForceManager::getZFOfFixedZMols(Molecule* mol, StuntDouble* sd, double totalForce){
589 >  RealType ZconstraintForceManager::getZFOfFixedZMols(Molecule* mol, StuntDouble* sd, RealType totalForce){
590      return totalForce * sd->getMass() / mol->getMass();
591    }
592  
593 <  double ZconstraintForceManager::getZFOfMovingMols(Molecule* mol, double totalForce){
593 >  RealType ZconstraintForceManager::getZFOfMovingMols(Molecule* mol, RealType totalForce){
594      return totalForce * mol->getMass() / (totMassUnconsMols_ + totMassMovingZMols_);
595    }
596  
597 <  double ZconstraintForceManager::getHFOfFixedZMols(Molecule* mol, StuntDouble*sd, double totalForce){
597 >  RealType ZconstraintForceManager::getHFOfFixedZMols(Molecule* mol, StuntDouble*sd, RealType totalForce){
598      return totalForce * sd->getMass() / mol->getMass();
599    }
600  
601 <  double ZconstraintForceManager::getHFOfUnconsMols(Molecule* mol, double totalForce){
601 >  RealType ZconstraintForceManager::getHFOfUnconsMols(Molecule* mol, RealType totalForce){
602      return totalForce * mol->getMass() / totMassUnconsMols_;
603    }
604  
605    void ZconstraintForceManager::updateZPos(){
606 <    double curTime = currSnapshot_->getTime();
606 >    RealType curTime = currSnapshot_->getTime();
607      std::list<ZconstraintMol>::iterator i;
608      for ( i = fixedZMols_.begin(); i !=  fixedZMols_.end(); ++i) {
609        i->param.zTargetPos += zconsGap_;    
# Line 612 | Line 617 | namespace oopse {
617      }
618    }
619  
620 <  double ZconstraintForceManager::getZTargetPos(int index){
621 <    double zTargetPos;
620 >  RealType ZconstraintForceManager::getZTargetPos(int index){
621 >    RealType zTargetPos;
622   #ifndef IS_MPI    
623      Molecule* mol = info_->getMoleculeByGlobalIndex(index);
624      assert(mol);
# Line 621 | Line 626 | namespace oopse {
626      zTargetPos = com[whichDirection];
627   #else
628      int whicProc = info_->getMolToProc(index);
629 <    MPI_Bcast(&zTargetPos, 1, MPI_DOUBLE, whicProc, MPI_COMM_WORLD);
629 >    MPI_Bcast(&zTargetPos, 1, MPI_REALTYPE, whicProc, MPI_COMM_WORLD);
630   #endif
631      return zTargetPos;
632    }

Comparing:
trunk/src/constraints/ZconstraintForceManager.cpp (property svn:keywords), Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
branches/development/src/constraints/ZconstraintForceManager.cpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines