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

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 1627 by gezelter, Tue Sep 13 22:05:04 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines