--- trunk/src/constraints/ZconstraintForceManager.cpp 2005/04/15 22:04:00 507 +++ trunk/src/constraints/ZconstraintForceManager.cpp 2009/11/25 20:02:06 1390 @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,15 +28,24 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Vardeman & Gezelter, in progress (2009). */ #include #include "constraints/ZconstraintForceManager.hpp" #include "integrators/Integrator.hpp" #include "utils/simError.h" -#include "utils/OOPSEConstant.hpp" +#include "utils/PhysicalConstants.hpp" #include "utils/StringUtils.hpp" -namespace oopse { +namespace OpenMD { ZconstraintForceManager::ZconstraintForceManager(SimInfo* info): ForceManager(info), infiniteTime(1e31) { currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); Globals* simParam = info_->getSimParams(); @@ -59,7 +59,7 @@ namespace oopse { simError(); } - if (simParam->haveZconstraintTime()){ + if (simParam->haveZconsTime()){ zconsTime_ = simParam->getZconsTime(); } else{ @@ -77,7 +77,7 @@ namespace oopse { zconsTol_ = 0.01; sprintf(painCave.errMsg, "ZConstraint Warning: Tolerance for z-constraint method is not specified.\n" - "\tOOPSE will use a default value of %f.\n" + "\tOpenMD will use a default value of %f.\n" "\tTo set the tolerance, use the zconsTol variable.\n", zconsTol_); painCave.isFatal = 0; @@ -85,7 +85,7 @@ namespace oopse { } //set zcons gap - if (simParam->haveZConsGap()){ + if (simParam->haveZconsGap()){ usingZconsGap_ = true; zconsGap_ = simParam->getZconsGap(); }else { @@ -94,14 +94,14 @@ namespace oopse { } //set zcons fixtime - if (simParam->haveZConsFixTime()){ + if (simParam->haveZconsFixtime()){ zconsFixingTime_ = simParam->getZconsFixtime(); } else { zconsFixingTime_ = infiniteTime; } //set zconsUsingSMD - if (simParam->haveZConsUsingSMD()){ + if (simParam->haveZconsUsingSMD()){ usingSMD_ = simParam->getZconsUsingSMD(); }else { usingSMD_ =false; @@ -111,17 +111,17 @@ namespace oopse { //estimate the force constant of harmonical potential Mat3x3d hmat = currSnapshot_->getHmat(); - double halfOfLargestBox = std::max(hmat(0, 0), std::max(hmat(1, 1), hmat(2, 2))) /2; - double targetTemp; + RealType halfOfLargestBox = std::max(hmat(0, 0), std::max(hmat(1, 1), hmat(2, 2))) /2; + RealType targetTemp; if (simParam->haveTargetTemp()) { targetTemp = simParam->getTargetTemp(); } else { targetTemp = 298.0; } - double zforceConstant = OOPSEConstant::kb * targetTemp / (halfOfLargestBox * halfOfLargestBox); + RealType zforceConstant = PhysicalConstants::kb * targetTemp / (halfOfLargestBox * halfOfLargestBox); - int nZconstraints = simParam->getNzConstraints(); - ZconStamp** stamp = simParam->getZconStamp(); + int nZconstraints = simParam->getNZconsStamps(); + std::vector stamp = simParam->getZconsStamps(); // for (int i = 0; i < nZconstraints; i++){ @@ -148,7 +148,7 @@ namespace oopse { update(); //calculate masss of unconstraint molecules in the whole system (never change during the simulation) - double totMassUnconsMols_local = 0.0; + RealType totMassUnconsMols_local = 0.0; std::vector::iterator j; for ( j = unzconsMols_.begin(); j != unzconsMols_.end(); ++j) { totMassUnconsMols_local += (*j)->getMass(); @@ -156,7 +156,7 @@ namespace oopse { #ifndef IS_MPI totMassUnconsMols_ = totMassUnconsMols_local; #else - MPI_Allreduce(&totMassUnconsMols_local, &totMassUnconsMols_, 1, MPI_DOUBLE, + MPI_Allreduce(&totMassUnconsMols_local, &totMassUnconsMols_, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #endif @@ -194,7 +194,7 @@ namespace oopse { zmol.param = i->second; zmol.cantPos = zmol.param.zTargetPos; /**@todo fixed me when zmol migrate, it is incorrect*/ Vector3d com = zmol.mol->getCom(); - double diff = fabs(zmol.param.zTargetPos - com[whichDirection]); + RealType diff = fabs(zmol.param.zTargetPos - com[whichDirection]); if (diff < zconsTol_) { fixedZMols_.push_back(zmol); } else { @@ -299,8 +299,8 @@ namespace oopse { // calculate the vz of center of mass of moving molecules(include unconstrained molecules // and moving z-constrained molecules) - double pzMovingMols_local = 0.0; - double pzMovingMols; + RealType pzMovingMols_local = 0.0; + RealType pzMovingMols; for ( i = movingZMols_.begin(); i != movingZMols_.end(); ++i) { mol = i->mol; @@ -318,11 +318,11 @@ namespace oopse { #ifndef IS_MPI pzMovingMols = pzMovingMols_local; #else - MPI_Allreduce(&pzMovingMols_local, &pzMovingMols, 1, MPI_DOUBLE, + MPI_Allreduce(&pzMovingMols_local, &pzMovingMols, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #endif - double vzMovingMols = pzMovingMols / (totMassMovingZMols_ + totMassUnconsMols_); + RealType vzMovingMols = pzMovingMols / (totMassMovingZMols_ + totMassUnconsMols_); //modify the velocities of moving z-constrained molecuels for ( i = movingZMols_.begin(); i != movingZMols_.end(); ++i) { @@ -352,8 +352,8 @@ namespace oopse { void ZconstraintForceManager::doZconstraintForce(){ - double totalFZ; - double totalFZ_local; + RealType totalFZ; + RealType totalFZ_local; Vector3d com; Vector3d force(0.0); @@ -383,7 +383,7 @@ namespace oopse { //calculate total z-constraint force #ifdef IS_MPI - MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #else totalFZ = totalFZ_local; #endif @@ -427,10 +427,10 @@ namespace oopse { void ZconstraintForceManager::doHarmonic(){ - double totalFZ; + RealType totalFZ; Vector3d force(0.0); Vector3d com; - double totalFZ_local = 0; + RealType totalFZ_local = 0; std::list::iterator i; StuntDouble* integrableObject; Molecule::IntegrableObjectIterator ii; @@ -438,11 +438,11 @@ namespace oopse { for ( i = movingZMols_.begin(); i != movingZMols_.end(); ++i) { mol = i->mol; com = mol->getCom(); - double resPos = usingSMD_? i->cantPos : i->param.zTargetPos; - double diff = com[whichDirection] - resPos; - double harmonicU = 0.5 * i->param.kz * diff * diff; + RealType resPos = usingSMD_? i->cantPos : i->param.zTargetPos; + RealType diff = com[whichDirection] - resPos; + RealType harmonicU = 0.5 * i->param.kz * diff * diff; currSnapshot_->statData[Stats::LONG_RANGE_POTENTIAL] += harmonicU; - double harmonicF = -i->param.kz * diff; + RealType harmonicF = -i->param.kz * diff; totalFZ_local += harmonicF; //adjust force @@ -457,7 +457,7 @@ namespace oopse { #ifndef IS_MPI totalFZ = totalFZ_local; #else - MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #endif //modify the forces of unconstrained molecules @@ -476,7 +476,7 @@ namespace oopse { bool ZconstraintForceManager::checkZConsState(){ Vector3d com; - double diff; + RealType diff; int changed_local = 0; std::list::iterator i; @@ -566,14 +566,14 @@ namespace oopse { void ZconstraintForceManager::calcTotalMassMovingZMols(){ - double totMassMovingZMols_local = 0.0; + RealType totMassMovingZMols_local = 0.0; std::list::iterator i; for ( i = movingZMols_.begin(); i != movingZMols_.end(); ++i) { totMassMovingZMols_local += i->mol->getMass(); } #ifdef IS_MPI - MPI_Allreduce(&totMassMovingZMols_local, &totMassMovingZMols_, 1, MPI_DOUBLE, + MPI_Allreduce(&totMassMovingZMols_local, &totMassMovingZMols_, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #else totMassMovingZMols_ = totMassMovingZMols_local; @@ -581,24 +581,24 @@ namespace oopse { } - double ZconstraintForceManager::getZFOfFixedZMols(Molecule* mol, StuntDouble* sd, double totalForce){ + RealType ZconstraintForceManager::getZFOfFixedZMols(Molecule* mol, StuntDouble* sd, RealType totalForce){ return totalForce * sd->getMass() / mol->getMass(); } - double ZconstraintForceManager::getZFOfMovingMols(Molecule* mol, double totalForce){ + RealType ZconstraintForceManager::getZFOfMovingMols(Molecule* mol, RealType totalForce){ return totalForce * mol->getMass() / (totMassUnconsMols_ + totMassMovingZMols_); } - double ZconstraintForceManager::getHFOfFixedZMols(Molecule* mol, StuntDouble*sd, double totalForce){ + RealType ZconstraintForceManager::getHFOfFixedZMols(Molecule* mol, StuntDouble*sd, RealType totalForce){ return totalForce * sd->getMass() / mol->getMass(); } - double ZconstraintForceManager::getHFOfUnconsMols(Molecule* mol, double totalForce){ + RealType ZconstraintForceManager::getHFOfUnconsMols(Molecule* mol, RealType totalForce){ return totalForce * mol->getMass() / totMassUnconsMols_; } void ZconstraintForceManager::updateZPos(){ - double curTime = currSnapshot_->getTime(); + RealType curTime = currSnapshot_->getTime(); std::list::iterator i; for ( i = fixedZMols_.begin(); i != fixedZMols_.end(); ++i) { i->param.zTargetPos += zconsGap_; @@ -612,8 +612,8 @@ namespace oopse { } } - double ZconstraintForceManager::getZTargetPos(int index){ - double zTargetPos; + RealType ZconstraintForceManager::getZTargetPos(int index){ + RealType zTargetPos; #ifndef IS_MPI Molecule* mol = info_->getMoleculeByGlobalIndex(index); assert(mol); @@ -621,7 +621,7 @@ namespace oopse { zTargetPos = com[whichDirection]; #else int whicProc = info_->getMolToProc(index); - MPI_Bcast(&zTargetPos, 1, MPI_DOUBLE, whicProc, MPI_COMM_WORLD); + MPI_Bcast(&zTargetPos, 1, MPI_REALTYPE, whicProc, MPI_COMM_WORLD); #endif return zTargetPos; }