--- trunk/src/integrators/NPTi.cpp 2004/09/24 04:16:43 2 +++ trunk/src/integrators/NPTi.cpp 2006/05/17 21:51:42 963 @@ -1,180 +1,184 @@ -#include -#include "Atom.hpp" -#include "SRI.hpp" -#include "AbstractClasses.hpp" -#include "SimInfo.hpp" -#include "ForceFields.hpp" -#include "Thermo.hpp" -#include "ReadWrite.hpp" -#include "Integrator.hpp" -#include "simError.h" +/* + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. + * + * The University of Notre Dame grants you ("Licensee") a + * non-exclusive, royalty free, license to use, modify and + * 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 + * notice, this list of conditions and the following disclaimer. + * + * 3. 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. + * + * This software is provided "AS IS," without a warranty of any + * kind. All express or implied conditions, representations and + * warranties, including any implied warranty of merchantability, + * fitness for a particular purpose or non-infringement, are hereby + * excluded. The University of Notre Dame and its licensors shall not + * be liable for any damages suffered by licensee as a result of + * using, modifying or distributing the software or its + * derivatives. In no event will the University of Notre Dame or its + * licensors be liable for any lost revenue, profit or data, or for + * direct, indirect, special, consequential, incidental or punitive + * damages, however caused and regardless of the theory of liability, + * 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. + */ + +#include "NPTi.hpp" +#include "brains/SimInfo.hpp" +#include "brains/Thermo.hpp" +#include "integrators/NPT.hpp" +#include "primitives/Molecule.hpp" +#include "utils/OOPSEConstant.hpp" +#include "utils/simError.h" -#ifdef IS_MPI -#include "mpiSimulation.hpp" -#endif +namespace oopse { -// Basic isotropic thermostating and barostating via the Melchionna -// modification of the Hoover algorithm: -// -// Melchionna, S., Ciccotti, G., and Holian, B. L., 1993, -// Molec. Phys., 78, 533. -// -// and -// -// Hoover, W. G., 1986, Phys. Rev. A, 34, 2499. + // Basic isotropic thermostating and barostating via the Melchionna + // modification of the Hoover algorithm: + // + // Melchionna, S., Ciccotti, G., and Holian, B. L., 1993, + // Molec. Phys., 78, 533. + // + // and + // + // Hoover, W. G., 1986, Phys. Rev. A, 34, 2499. -template NPTi::NPTi ( SimInfo *theInfo, ForceFields* the_ff): - T( theInfo, the_ff ) -{ - GenericData* data; - DoubleArrayData * etaValue; - vector etaArray; + NPTi::NPTi ( SimInfo *info) : NPT(info){ - eta = 0.0; - oldEta = 0.0; + } - if( theInfo->useInitXSstate ){ - // retrieve eta from simInfo if - data = info->getProperty(ETAVALUE_ID); - if(data){ - etaValue = dynamic_cast(data); - - if(etaValue){ - etaArray = etaValue->getData(); - eta = etaArray[0]; - oldEta = eta; - } - } + void NPTi::evolveEtaA() { + eta += dt2 * ( instaVol * (instaPress - targetPressure) / + (OOPSEConstant::pressureConvert*NkBT*tb2)); + oldEta = eta; } -} -template NPTi::~NPTi() { - //nothing for now -} + void NPTi::evolveEtaB() { -template void NPTi::resetIntegrator() { - eta = 0.0; - T::resetIntegrator(); -} + prevEta = eta; + eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / + (OOPSEConstant::pressureConvert*NkBT*tb2)); + } -template void NPTi::evolveEtaA() { - eta += dt2 * ( instaVol * (instaPress - targetPressure) / - (p_convert*NkBT*tb2)); - oldEta = eta; -} + void NPTi::calcVelScale() { + vScale = chi + eta; + } -template void NPTi::evolveEtaB() { + void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) { + sc = vel * vScale; + } - prevEta = eta; - eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / - (p_convert*NkBT*tb2)); -} + void NPTi::getVelScaleB(Vector3d& sc, int index ){ + sc = oldVel[index] * vScale; + } -template void NPTi::calcVelScale(void) { - vScale = chi + eta; -} -template void NPTi::getVelScaleA(double sc[3], double vel[3]) { - int i; + void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM, + int index, Vector3d& sc){ + /**@todo*/ + sc = (oldPos[index] + pos)/(RealType)2.0 -COM; + sc *= eta; + } - for(i=0; i<3; i++) sc[i] = vel[i] * vScale; -} + void NPTi::scaleSimBox(){ -template void NPTi::getVelScaleB(double sc[3], int index ){ - int i; + RealType scaleFactor; - for(i=0; i<3; i++) sc[i] = oldVel[index*3 + i] * vScale; -} + scaleFactor = exp(dt*eta); + if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { + sprintf( painCave.errMsg, + "NPTi error: Attempting a Box scaling of more than 10 percent" + " check your tauBarostat, as it is probably too small!\n" + " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor + ); + painCave.isFatal = 1; + simError(); + } else { + Mat3x3d hmat = currentSnapshot_->getHmat(); + hmat *= scaleFactor; + currentSnapshot_->setHmat(hmat); + } -template void NPTi::getPosScale(double pos[3], double COM[3], - int index, double sc[3]){ - int j; + } - for(j=0; j<3; j++) - sc[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j]; + bool NPTi::etaConverged() { - for(j=0; j<3; j++) - sc[j] *= eta; -} - -template void NPTi::scaleSimBox( void ){ - - double scaleFactor; - - scaleFactor = exp(dt*eta); - - if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { - sprintf( painCave.errMsg, - "NPTi error: Attempting a Box scaling of more than 10 percent" - " check your tauBarostat, as it is probably too small!\n" - " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor - ); - painCave.isFatal = 1; - simError(); - } else { - info->scaleBox(scaleFactor); + return ( fabs(prevEta - eta) <= etaTolerance ); } -} + RealType NPTi::calcConservedQuantity(){ -template bool NPTi::etaConverged() { + chi= currentSnapshot_->getChi(); + integralOfChidt = currentSnapshot_->getIntegralOfChiDt(); + loadEta(); + // We need NkBT a lot, so just set it here: This is the RAW number + // of integrableObjects, so no subtraction or addition of constraints or + // orientational degrees of freedom: + NkBT = info_->getNGlobalIntegrableObjects()*OOPSEConstant::kB *targetTemp; - return ( fabs(prevEta - eta) <= etaTolerance ); -} + // fkBT is used because the thermostat operates on more degrees of freedom + // than the barostat (when there are particles with orientational degrees + // of freedom). + fkBT = info_->getNdf()*OOPSEConstant::kB *targetTemp; + + RealType conservedQuantity; + RealType Energy; + RealType thermostat_kinetic; + RealType thermostat_potential; + RealType barostat_kinetic; + RealType barostat_potential; -template double NPTi::getConservedQuantity(void){ + Energy =thermo.getTotalE(); - double conservedQuantity; - double Energy; - double thermostat_kinetic; - double thermostat_potential; - double barostat_kinetic; - double barostat_potential; + thermostat_kinetic = fkBT* tt2 * chi * chi / (2.0 * OOPSEConstant::energyConvert); - Energy = tStats->getTotalE(); + thermostat_potential = fkBT* integralOfChidt / OOPSEConstant::energyConvert; - thermostat_kinetic = fkBT* tt2 * chi * chi / - (2.0 * eConvert); - thermostat_potential = fkBT* integralOfChidt / eConvert; + barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /(2.0 * OOPSEConstant::energyConvert); + barostat_potential = (targetPressure * thermo.getVolume() / OOPSEConstant::pressureConvert) / + OOPSEConstant::energyConvert; - barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta / - (2.0 * eConvert); + conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + + barostat_kinetic + barostat_potential; + + return conservedQuantity; + } - barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / - eConvert; + void NPTi::loadEta() { + Mat3x3d etaMat = currentSnapshot_->getEta(); + eta = etaMat(0,0); + //if (fabs(etaMat(1,1) - eta) >= oopse::epsilon || fabs(etaMat(1,1) - eta) >= oopse::epsilon || !etaMat.isDiagonal()) { + // sprintf( painCave.errMsg, + // "NPTi error: the diagonal elements of eta matrix are not the same or etaMat is not a diagonal matrix"); + // painCave.isFatal = 1; + // simError(); + //} + } - conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + - barostat_kinetic + barostat_potential; - -// cout.width(8); -// cout.precision(8); - -// cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic << -// "\t" << thermostat_potential << "\t" << barostat_kinetic << -// "\t" << barostat_potential << "\t" << conservedQuantity << endl; - return conservedQuantity; + void NPTi::saveEta() { + Mat3x3d etaMat(0.0); + etaMat(0, 0) = eta; + etaMat(1, 1) = eta; + etaMat(2, 2) = eta; + currentSnapshot_->setEta(etaMat); + } } - -template string NPTi::getAdditionalParameters(void){ - string parameters; - const int BUFFERSIZE = 2000; // size of the read buffer - char buffer[BUFFERSIZE]; - - sprintf(buffer,"\t%G\t%G;", chi, integralOfChidt); - parameters += buffer; - - sprintf(buffer,"\t%G\t0\t0;", eta); - parameters += buffer; - - sprintf(buffer,"\t0\t%G\t0;", eta); - parameters += buffer; - - sprintf(buffer,"\t0\t0\t%G;", eta); - parameters += buffer; - - return parameters; - -}