/* * Berendsen.cpp * * Created on: Aug 20, 2010 * Author: crueger */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Berendsen.hpp" #include "element.hpp" #include "config.hpp" #include "CodePatterns/Verbose.hpp" #include "CodePatterns/Log.hpp" #include "ThermoStatContainer.hpp" #include "World.hpp" Berendsen::Berendsen(double _TempFrequency) : TempFrequency(_TempFrequency) {} Berendsen::Berendsen() : TempFrequency(2.5) {} Berendsen::~Berendsen() {} const char *ThermostatTraits::name = "Berendsen"; std::string ThermostatTraits::getName(){ return ThermostatTraits::name; } Thermostat *ThermostatTraits::make(class ConfigFileBuffer * const fb){ double TempFrequency; const int verbose = 0; ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T return new Berendsen(TempFrequency); } double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){ return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end()); } double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){ return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end()); } double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){ return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end()); } template double Berendsen::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){ DoLog(2) && (Log() << Verbose(2) << "Applying Berendsen-VanGunsteren thermostat..." << endl); double ekin=0; double ScaleTempFactor = getContainer().TargetTemp/ActualTemp; for(ForwardIterator iter=begin;iter!=end;++iter){ Vector &U = (*iter)->Trajectory.U.at(step); if ((*iter)->FixedIon == 0) { // even FixedIon moves, only not by other's forces U *= sqrt(1+(World::getInstance().getConfig()->Deltat/TempFrequency)*(ScaleTempFactor-1)); ekin += 0.5*(*iter)->getType()->getMass() * U.NormSquared(); } } return ekin; } std::string Berendsen::name(){ return ThermostatTraits::name; } std::string Berendsen::writeParams(){ stringstream sstr; sstr << TempFrequency; return sstr.str(); }