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"
|
---|
14 | #include "World.hpp"
|
---|
15 |
|
---|
16 | Berendsen::Berendsen(double _TempFrequency) :
|
---|
17 | TempFrequency(_TempFrequency)
|
---|
18 | {}
|
---|
19 |
|
---|
20 | Berendsen::~Berendsen()
|
---|
21 | {}
|
---|
22 |
|
---|
23 | ThermostatTraits<class Berendsen>::ThermostatTraits() :
|
---|
24 | name("Berendsen")
|
---|
25 | {}
|
---|
26 |
|
---|
27 | Thermostat *ThermostatTraits<class Berendsen>::make(class ConfigFileBuffer * const fb){
|
---|
28 | double TempFrequency;
|
---|
29 | const int verbose = 0;
|
---|
30 | ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
|
---|
31 | return new class Berendsen(TempFrequency);
|
---|
32 | }
|
---|
33 |
|
---|
34 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
|
---|
35 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
36 | }
|
---|
37 |
|
---|
38 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
|
---|
39 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
40 | }
|
---|
41 |
|
---|
42 | double Berendsen::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
|
---|
43 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
44 | }
|
---|
45 |
|
---|
46 | template <class ForwardIterator>
|
---|
47 | double Berendsen::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
|
---|
48 | DoLog(2) && (Log() << Verbose(2) << "Applying Berendsen-VanGunsteren thermostat..." << endl);
|
---|
49 | double ekin;
|
---|
50 | double ScaleTempFactor = getContainer().TargetTemp/ActualTemp;
|
---|
51 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
52 | Vector &U = (*iter)->Trajectory.U.at(step);
|
---|
53 | if ((*iter)->FixedIon == 0) { // even FixedIon moves, only not by other's forces
|
---|
54 | U *= sqrt(1+(World::getInstance().getConfig()->Deltat/TempFrequency)*(ScaleTempFactor-1));
|
---|
55 | ekin += 0.5*(*iter)->getType()->mass * U.NormSquared();
|
---|
56 | }
|
---|
57 | }
|
---|
58 | return ekin;
|
---|
59 | }
|
---|
60 |
|
---|
61 | std::string Berendsen::name(){
|
---|
62 | return ThermostatTraits<Berendsen>().name;
|
---|
63 | }
|
---|
64 |
|
---|
65 | std::string Berendsen::writeParams(){
|
---|
66 | stringstream sstr;
|
---|
67 | sstr << TempFrequency;
|
---|
68 | return sstr.str();
|
---|
69 | }
|
---|