/* * Berendsen.cpp * * Created on: Aug 20, 2010 * Author: crueger */ #include "Berendsen.hpp" #include "element.hpp" #include "config.hpp" #include "Helpers/Verbose.hpp" #include "Helpers/Log.hpp" #include "ThermoStatContainer.hpp" #include "World.hpp" Berendsen::Berendsen(double _TempFrequency) : TempFrequency(_TempFrequency) {} Berendsen::~Berendsen() {} ThermostatTraits::ThermostatTraits() : name("Berendsen") {} 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; 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()->mass * U.NormSquared(); } } return ekin; } std::string Berendsen::name(){ return ThermostatTraits().name; } std::string Berendsen::writeParam(){ stringstream sstr; sstr << TempFrequency; return sstr.str(); }