[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"
|
---|
[255829] | 20 | #include "Helpers/defs.hpp"
|
---|
[194649] | 21 | #include "ThermoStatContainer.hpp"
|
---|
[579a81] | 22 | #include "World.hpp"
|
---|
[194649] | 23 |
|
---|
[579a81] | 24 | Berendsen::Berendsen(double _TempFrequency) :
|
---|
| 25 | TempFrequency(_TempFrequency)
|
---|
[194649] | 26 | {}
|
---|
| 27 |
|
---|
[3e4162] | 28 | Berendsen::Berendsen() :
|
---|
| 29 | TempFrequency(2.5)
|
---|
| 30 | {}
|
---|
| 31 |
|
---|
[194649] | 32 | Berendsen::~Berendsen()
|
---|
| 33 | {}
|
---|
| 34 |
|
---|
[14c57a] | 35 | const char *ThermostatTraits<Berendsen>::name = "Berendsen";
|
---|
| 36 |
|
---|
| 37 | std::string ThermostatTraits<Berendsen>::getName(){
|
---|
| 38 | return ThermostatTraits<Berendsen>::name;
|
---|
| 39 | }
|
---|
[579a81] | 40 |
|
---|
[14c57a] | 41 | Thermostat *ThermostatTraits<Berendsen>::make(class ConfigFileBuffer * const fb){
|
---|
[c0c650] | 42 | double TempFrequency;
|
---|
| 43 | const int verbose = 0;
|
---|
| 44 | ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
|
---|
[14c57a] | 45 | return new Berendsen(TempFrequency);
|
---|
[c0c650] | 46 | }
|
---|
[579a81] | 47 |
|
---|
| 48 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
|
---|
| 49 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 50 | }
|
---|
| 51 |
|
---|
[579a81] | 52 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
|
---|
| 53 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 54 | }
|
---|
| 55 |
|
---|
[579a81] | 56 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
|
---|
| 57 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 58 | }
|
---|
| 59 |
|
---|
| 60 | template <class ForwardIterator>
|
---|
[579a81] | 61 | double Berendsen::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
|
---|
[194649] | 62 | DoLog(2) && (Log() << Verbose(2) << "Applying Berendsen-VanGunsteren thermostat..." << endl);
|
---|
[14c57a] | 63 | double ekin=0;
|
---|
[579a81] | 64 | double ScaleTempFactor = getContainer().TargetTemp/ActualTemp;
|
---|
[194649] | 65 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
[056e70] | 66 | Vector U = (*iter)->getAtomicVelocityAtStep(step);
|
---|
[6625c3] | 67 | if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
|
---|
[579a81] | 68 | U *= sqrt(1+(World::getInstance().getConfig()->Deltat/TempFrequency)*(ScaleTempFactor-1));
|
---|
[51c3e4] | 69 | ekin += 0.5*(*iter)->getType()->getMass() * U.NormSquared();
|
---|
[194649] | 70 | }
|
---|
[056e70] | 71 | (*iter)->setAtomicVelocityAtStep(step, U);
|
---|
[194649] | 72 | }
|
---|
| 73 | return ekin;
|
---|
| 74 | }
|
---|
[579a81] | 75 |
|
---|
| 76 | std::string Berendsen::name(){
|
---|
[14c57a] | 77 | return ThermostatTraits<Berendsen>::name;
|
---|
[579a81] | 78 | }
|
---|
| 79 |
|
---|
[c0c650] | 80 | std::string Berendsen::writeParams(){
|
---|
[579a81] | 81 | stringstream sstr;
|
---|
| 82 | sstr << TempFrequency;
|
---|
| 83 | return sstr.str();
|
---|
| 84 | }
|
---|