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