[194649] | 1 | /*
|
---|
| 2 | * Berendsen.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 20, 2010
|
---|
| 5 | * Author: crueger
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[d2b28f] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[ad011c] | 13 | #include "CodePatterns/MemDebug.hpp"
|
---|
[d2b28f] | 14 |
|
---|
[194649] | 15 | #include "Berendsen.hpp"
|
---|
| 16 | #include "element.hpp"
|
---|
| 17 | #include "config.hpp"
|
---|
[ad011c] | 18 | #include "CodePatterns/Verbose.hpp"
|
---|
| 19 | #include "CodePatterns/Log.hpp"
|
---|
[194649] | 20 | #include "ThermoStatContainer.hpp"
|
---|
[579a81] | 21 | #include "World.hpp"
|
---|
[194649] | 22 |
|
---|
[579a81] | 23 | Berendsen::Berendsen(double _TempFrequency) :
|
---|
| 24 | TempFrequency(_TempFrequency)
|
---|
[194649] | 25 | {}
|
---|
| 26 |
|
---|
[3e4162] | 27 | Berendsen::Berendsen() :
|
---|
| 28 | TempFrequency(2.5)
|
---|
| 29 | {}
|
---|
| 30 |
|
---|
[194649] | 31 | Berendsen::~Berendsen()
|
---|
| 32 | {}
|
---|
| 33 |
|
---|
[14c57a] | 34 | const char *ThermostatTraits<Berendsen>::name = "Berendsen";
|
---|
| 35 |
|
---|
| 36 | std::string ThermostatTraits<Berendsen>::getName(){
|
---|
| 37 | return ThermostatTraits<Berendsen>::name;
|
---|
| 38 | }
|
---|
[579a81] | 39 |
|
---|
[14c57a] | 40 | Thermostat *ThermostatTraits<Berendsen>::make(class ConfigFileBuffer * const fb){
|
---|
[c0c650] | 41 | double TempFrequency;
|
---|
| 42 | const int verbose = 0;
|
---|
| 43 | ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
|
---|
[14c57a] | 44 | return new Berendsen(TempFrequency);
|
---|
[c0c650] | 45 | }
|
---|
[579a81] | 46 |
|
---|
| 47 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
|
---|
| 48 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 49 | }
|
---|
| 50 |
|
---|
[579a81] | 51 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
|
---|
| 52 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 53 | }
|
---|
| 54 |
|
---|
[579a81] | 55 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
|
---|
| 56 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 57 | }
|
---|
| 58 |
|
---|
| 59 | template <class ForwardIterator>
|
---|
[579a81] | 60 | double Berendsen::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
|
---|
[194649] | 61 | DoLog(2) && (Log() << Verbose(2) << "Applying Berendsen-VanGunsteren thermostat..." << endl);
|
---|
[14c57a] | 62 | double ekin=0;
|
---|
[579a81] | 63 | double ScaleTempFactor = getContainer().TargetTemp/ActualTemp;
|
---|
[194649] | 64 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
| 65 | Vector &U = (*iter)->Trajectory.U.at(step);
|
---|
| 66 | if ((*iter)->FixedIon == 0) { // even FixedIon moves, only not by other's forces
|
---|
[579a81] | 67 | U *= sqrt(1+(World::getInstance().getConfig()->Deltat/TempFrequency)*(ScaleTempFactor-1));
|
---|
[51c3e4] | 68 | ekin += 0.5*(*iter)->getType()->getMass() * U.NormSquared();
|
---|
[194649] | 69 | }
|
---|
| 70 | }
|
---|
| 71 | return ekin;
|
---|
| 72 | }
|
---|
[579a81] | 73 |
|
---|
| 74 | std::string Berendsen::name(){
|
---|
[14c57a] | 75 | return ThermostatTraits<Berendsen>::name;
|
---|
[579a81] | 76 | }
|
---|
| 77 |
|
---|
[c0c650] | 78 | std::string Berendsen::writeParams(){
|
---|
[579a81] | 79 | stringstream sstr;
|
---|
| 80 | sstr << TempFrequency;
|
---|
| 81 | return sstr.str();
|
---|
| 82 | }
|
---|