--- trunk/src/constraints/ZconstraintForceManager.cpp 2006/05/17 21:51:42 963 +++ trunk/src/constraints/ZconstraintForceManager.cpp 2015/03/05 15:35:37 2067 @@ -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,29 @@ * 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, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ +#ifdef IS_MPI +#include +#endif #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(); @@ -77,7 +82,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; @@ -118,7 +123,7 @@ namespace oopse { } else { targetTemp = 298.0; } - RealType zforceConstant = OOPSEConstant::kb * targetTemp / (halfOfLargestBox * halfOfLargestBox); + RealType zforceConstant = PhysicalConstants::kb * targetTemp / (halfOfLargestBox * halfOfLargestBox); int nZconstraints = simParam->getNZconsStamps(); std::vector stamp = simParam->getZconsStamps(); @@ -156,8 +161,8 @@ namespace oopse { #ifndef IS_MPI totMassUnconsMols_ = totMassUnconsMols_local; #else - MPI_Allreduce(&totMassUnconsMols_local, &totMassUnconsMols_, 1, MPI_REALTYPE, - MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&totMassUnconsMols_local, &totMassUnconsMols_, 1, + MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #endif // creat zconsWriter @@ -240,8 +245,8 @@ namespace oopse { currZconsTime_ = currSnapshot_->getTime(); } - void ZconstraintForceManager::calcForces(bool needPotential, bool needStress){ - ForceManager::calcForces(needPotential, needStress); + void ZconstraintForceManager::calcForces(){ + ForceManager::calcForces(); if (usingZconsGap_){ updateZPos(); @@ -282,18 +287,21 @@ namespace oopse { Vector3d vel; std::list::iterator i; Molecule* mol; - StuntDouble* integrableObject; + StuntDouble* sd; Molecule::IntegrableObjectIterator ii; //zero out the velocities of center of mass of fixed z-constrained molecules for(i = fixedZMols_.begin(); i != fixedZMols_.end(); ++i) { + mol = i->mol; comVel = mol->getComVel(); - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - vel = integrableObject->getVel(); + + for(sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + + vel = sd->getVel(); vel[whichDirection] -= comVel[whichDirection]; - integrableObject->setVel(vel); + sd->setVel(vel); } } @@ -318,33 +326,37 @@ namespace oopse { #ifndef IS_MPI pzMovingMols = pzMovingMols_local; #else - MPI_Allreduce(&pzMovingMols_local, &pzMovingMols, 1, MPI_REALTYPE, - MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&pzMovingMols_local, &pzMovingMols, 1, + MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #endif RealType vzMovingMols = pzMovingMols / (totMassMovingZMols_ + totMassUnconsMols_); //modify the velocities of moving z-constrained molecuels for ( i = movingZMols_.begin(); i != movingZMols_.end(); ++i) { + mol = i->mol; - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - vel = integrableObject->getVel(); + for(sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + + vel = sd->getVel(); vel[whichDirection] -= vzMovingMols; - integrableObject->setVel(vel); + sd->setVel(vel); } } //modify the velocites of unconstrained molecules for ( j = unzconsMols_.begin(); j != unzconsMols_.end(); ++j) { + mol =*j; - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - vel = integrableObject->getVel(); + for(sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + + vel = sd->getVel(); vel[whichDirection] -= vzMovingMols; - integrableObject->setVel(vel); + sd->setVel(vel); } } @@ -366,16 +378,18 @@ namespace oopse { //calculate the total z-contrained force of fixed z-contrained molecules std::list::iterator i; Molecule* mol; - StuntDouble* integrableObject; + StuntDouble* sd; Molecule::IntegrableObjectIterator ii; for ( i = fixedZMols_.begin(); i != fixedZMols_.end(); ++i) { + mol = i->mol; i->fz = 0.0; - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - force = integrableObject->getFrc(); + for( sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + + force = sd->getFrc(); i->fz += force[whichDirection]; } totalFZ_local += i->fz; @@ -383,7 +397,8 @@ namespace oopse { //calculate total z-constraint force #ifdef IS_MPI - MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&totalFZ_local, &totalFZ, 1, + MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #else totalFZ = totalFZ_local; #endif @@ -391,35 +406,41 @@ namespace oopse { // apply negative to fixed z-constrained molecues; for ( i = fixedZMols_.begin(); i != fixedZMols_.end(); ++i) { + mol = i->mol; - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - force[whichDirection] = -getZFOfFixedZMols(mol, integrableObject, i->fz); - integrableObject->addFrc(force); + for(sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + + force[whichDirection] = -getZFOfFixedZMols(mol, sd, i->fz); + sd->addFrc(force); } } //modify the forces of moving z-constrained molecules for ( i = movingZMols_.begin(); i != movingZMols_.end(); ++i) { + mol = i->mol; - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { + for(sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + force[whichDirection] = -getZFOfMovingMols(mol,totalFZ); - integrableObject->addFrc(force); + sd->addFrc(force); } } //modify the forces of unconstrained molecules std::vector::iterator j; for ( j = unzconsMols_.begin(); j != unzconsMols_.end(); ++j) { + mol =*j; - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { + for(sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + force[whichDirection] = -getZFOfMovingMols(mol, totalFZ); - integrableObject->addFrc(force); + sd->addFrc(force); } } @@ -431,8 +452,9 @@ namespace oopse { Vector3d force(0.0); Vector3d com; RealType totalFZ_local = 0; + RealType lrPot; std::list::iterator i; - StuntDouble* integrableObject; + StuntDouble* sd; Molecule::IntegrableObjectIterator ii; Molecule* mol; for ( i = movingZMols_.begin(); i != movingZMols_.end(); ++i) { @@ -441,34 +463,39 @@ namespace oopse { 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; + lrPot = currSnapshot_->getLongRangePotential(); + lrPot += harmonicU; + currSnapshot_->setLongRangePotential(lrPot); RealType harmonicF = -i->param.kz * diff; totalFZ_local += harmonicF; //adjust force - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { + for(sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { - force[whichDirection] = getHFOfFixedZMols(mol, integrableObject, harmonicF); - integrableObject->addFrc(force); + force[whichDirection] = getHFOfFixedZMols(mol, sd, harmonicF); + sd->addFrc(force); } } #ifndef IS_MPI totalFZ = totalFZ_local; #else - MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_REALTYPE, 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 std::vector::iterator j; for ( j = unzconsMols_.begin(); j != unzconsMols_.end(); ++j) { + mol = *j; - for(integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { + for(sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + force[whichDirection] = getHFOfUnconsMols(mol, totalFZ); - integrableObject->addFrc(force); + sd->addFrc(force); } } @@ -540,8 +567,8 @@ namespace oopse { #ifndef IS_MPI havingFixed = havingFixed_local; #else - MPI_Allreduce(&havingFixed_local, &havingFixed, 1, MPI_INT, MPI_SUM, - MPI_COMM_WORLD); + MPI_Allreduce(&havingFixed_local, &havingFixed, 1, + MPI_INT, MPI_SUM, MPI_COMM_WORLD); #endif return havingFixed > 0; @@ -557,8 +584,8 @@ namespace oopse { #ifndef IS_MPI havingMoving = havingMoving_local; #else - MPI_Allreduce(&havingMoving_local, &havingMoving, 1, MPI_INT, MPI_SUM, - MPI_COMM_WORLD); + MPI_Allreduce(&havingMoving_local, &havingMoving, 1, + MPI_INT, MPI_SUM, MPI_COMM_WORLD); #endif return havingMoving > 0; @@ -573,8 +600,8 @@ namespace oopse { } #ifdef IS_MPI - MPI_Allreduce(&totMassMovingZMols_local, &totMassMovingZMols_, 1, MPI_REALTYPE, - MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&totMassMovingZMols_local, &totMassMovingZMols_, + 1, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); #else totMassMovingZMols_ = totMassMovingZMols_local; #endif @@ -598,7 +625,6 @@ namespace oopse { } void ZconstraintForceManager::updateZPos(){ - RealType curTime = currSnapshot_->getTime(); std::list::iterator i; for ( i = fixedZMols_.begin(); i != fixedZMols_.end(); ++i) { i->param.zTargetPos += zconsGap_;