--- trunk/src/restraints/ThermoIntegrationForceManager.cpp 2005/04/15 22:04:00 507 +++ trunk/src/restraints/ThermoIntegrationForceManager.cpp 2014/02/26 14:14:50 1969 @@ -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,124 +28,140 @@ * 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). */ -#include +#ifdef IS_MPI +#include +#endif + #include "restraints/ThermoIntegrationForceManager.hpp" -#include "integrators/Integrator.hpp" -#include "math/SquareMatrix3.hpp" -#include "primitives/Molecule.hpp" -#include "utils/simError.h" -#include "utils/OOPSEConstant.hpp" -#include "utils/StringUtils.hpp" -namespace oopse { +namespace OpenMD { ThermoIntegrationForceManager::ThermoIntegrationForceManager(SimInfo* info): - ForceManager(info){ - currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); - simParam = info_->getSimParams(); + RestraintForceManager(info){ + currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); + simParam = info_->getSimParams(); - if (simParam->haveThermIntLambda()){ - tIntLambda_ = simParam->getThermIntLambda(); - } - else{ - tIntLambda_ = 1.0; - sprintf(painCave.errMsg, - "ThermoIntegration error: the transformation parameter (lambda) was\n" - "\tnot specified. OOPSE will use a default value of %f. To set\n" - "\tlambda, use the thermodynamicIntegrationLambda variable.\n", - tIntLambda_); - painCave.isFatal = 0; - simError(); - } + if (simParam->haveThermodynamicIntegrationLambda()){ + tIntLambda_ = simParam->getThermodynamicIntegrationLambda(); + } + else{ + tIntLambda_ = 1.0; + sprintf(painCave.errMsg, + "ThermoIntegration error: the transformation parameter\n" + "\t(lambda) was not specified. OpenMD will use a default\n" + "\tvalue of %f. To set lambda, use the \n" + "\tthermodynamicIntegrationLambda variable.\n", + tIntLambda_); + painCave.isFatal = 0; + simError(); + } - if (simParam->haveThermIntK()){ - tIntK_ = simParam->getThermIntK(); - } - else{ - tIntK_ = 1.0; - sprintf(painCave.errMsg, - "ThermoIntegration Warning: the tranformation parameter exponent\n" - "\t(k) was not specified. OOPSE will use a default value of %f.\n" - "\tTo set k, use the thermodynamicIntegrationK variable.\n", - tIntK_); - painCave.isFatal = 0; - simError(); - } - - if (simParam->getUseSolidThermInt()) { - // build a restraint object - restraint_ = new Restraints(info_, tIntLambda_, tIntK_); - - } - - // build the scaling factor used to modulate the forces and torques - factor_ = pow(tIntLambda_, tIntK_); - + if (simParam->haveThermodynamicIntegrationK()){ + tIntK_ = simParam->getThermodynamicIntegrationK(); } + else{ + tIntK_ = 1.0; + sprintf(painCave.errMsg, + "ThermoIntegration Warning: the tranformation parameter\n" + "\texponent (k) was not specified. OpenMD will use a default\n" + "\tvalue of %f. To set k, use the thermodynamicIntegrationK\n" + "\tvariable.\n", + tIntK_); + painCave.isFatal = 0; + simError(); + } + + // build the scaling factor used to modulate the forces and torques + factor_ = pow(tIntLambda_, tIntK_); + } ThermoIntegrationForceManager::~ThermoIntegrationForceManager(){ } - void ThermoIntegrationForceManager::calcForces(bool needPotential, - bool needStress){ + void ThermoIntegrationForceManager::calcForces(){ Snapshot* curSnapshot; SimInfo::MoleculeIterator mi; Molecule* mol; Molecule::IntegrableObjectIterator ii; - StuntDouble* integrableObject; + StuntDouble* sd; Vector3d frc; Vector3d trq; Mat3x3d tempTau; // perform the standard calcForces first - ForceManager::calcForces(needPotential, needStress); + ForceManager::calcForces(); curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); - // now scale forces and torques of all the integrableObjects + // now scale forces and torques of all the sds for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { - for (integrableObject = mol->beginIntegrableObject(ii); - integrableObject != NULL; - integrableObject = mol->nextIntegrableObject(ii)) { - frc = integrableObject->getFrc(); + + for (sd = mol->beginIntegrableObject(ii); sd != NULL; + sd = mol->nextIntegrableObject(ii)) { + + frc = sd->getFrc(); frc *= factor_; - integrableObject->setFrc(frc); + sd->setFrc(frc); - if (integrableObject->isDirectional()){ - trq = integrableObject->getTrq(); + if (sd->isDirectional()){ + trq = sd->getTrq(); trq *= factor_; - integrableObject->setTrq(trq); + sd->setTrq(trq); } } } - - // set vraw to be the unmodulated potential - lrPot_ = curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL]; - curSnapshot->statData[Stats::VRAW] = lrPot_; + // set rawPotential to be the unmodulated potential + lrPot_ = curSnapshot->getLongRangePotential(); + curSnapshot->setRawPotential(lrPot_); + // modulate the potential and update the snapshot lrPot_ *= factor_; - curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot_; + curSnapshot->setLongRangePotential(lrPot_); // scale the pressure tensor - tempTau = curSnapshot->statData.getTau(); + tempTau = curSnapshot->getStressTensor(); tempTau *= factor_; - curSnapshot->statData.setTau(tempTau); + curSnapshot->setStressTensor(tempTau); - // do crystal restraint forces for thermodynamic integration - if (simParam->getUseSolidThermInt()) { - - lrPot_ += restraint_->Calc_Restraint_Forces(); - curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot_; - - vHarm_ = restraint_->getVharm(); - curSnapshot->statData[Stats::VHARM] = vHarm_; - } + // now, on to the applied restraining potentials (if needed): + RealType restPot_local = 0.0; + RealType vHarm_local = 0.0; - } - + if (simParam->getUseRestraints()) { + // do restraints from RestraintForceManager: + restPot_local = doRestraints(1.0 - factor_); + vHarm_local = getUnscaledPotential(); + } + +#ifdef IS_MPI + RealType restPot; + MPI_Allreduce(&restPot_local, &restPot, 1, + MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&vHarm_local, &vHarm_, 1, + MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); + lrPot_ += restPot; +#else + lrPot_ += restPot_local; + vHarm_ = vHarm_local; +#endif + + // give the final values to stats + curSnapshot->setLongRangePotential(lrPot_); + curSnapshot->setRestraintPotential(vHarm_); + } }