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