1 | /*
|
---|
2 | * NoseHoover.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 "NoseHoover.hpp"
|
---|
16 |
|
---|
17 | #include "element.hpp"
|
---|
18 | #include "config.hpp"
|
---|
19 | #include "CodePatterns/Verbose.hpp"
|
---|
20 | #include "CodePatterns/Log.hpp"
|
---|
21 | #include "ThermoStatContainer.hpp"
|
---|
22 | #include "World.hpp"
|
---|
23 |
|
---|
24 | NoseHoover::NoseHoover(double _HooverMass) :
|
---|
25 | HooverMass(_HooverMass),
|
---|
26 | alpha(0)
|
---|
27 | {}
|
---|
28 |
|
---|
29 | NoseHoover::NoseHoover() :
|
---|
30 | HooverMass(0.)
|
---|
31 | {}
|
---|
32 |
|
---|
33 | NoseHoover::~NoseHoover()
|
---|
34 | {}
|
---|
35 |
|
---|
36 | const char *ThermostatTraits<NoseHoover>::name = "NoseHoover";
|
---|
37 |
|
---|
38 | std::string ThermostatTraits<NoseHoover>::getName(){
|
---|
39 | return ThermostatTraits<NoseHoover>::name;
|
---|
40 | }
|
---|
41 |
|
---|
42 | Thermostat *ThermostatTraits<NoseHoover>::make(class ConfigFileBuffer * const fb){
|
---|
43 | double HooverMass;
|
---|
44 | const int verbose = 0;
|
---|
45 | ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass
|
---|
46 | return new NoseHoover(HooverMass);
|
---|
47 | }
|
---|
48 |
|
---|
49 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
|
---|
50 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
51 | }
|
---|
52 |
|
---|
53 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
|
---|
54 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
55 | }
|
---|
56 |
|
---|
57 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
|
---|
58 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
59 | }
|
---|
60 |
|
---|
61 | template <class ForwardIterator>
|
---|
62 | double NoseHoover::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
|
---|
63 | DoLog(2) && (Log() << Verbose(2) << "Applying Nose-Hoover thermostat..." << endl);
|
---|
64 | init(step,begin,end);
|
---|
65 | delta_alpha = (delta_alpha - (3.*count+1.) * getContainer().TargetTemp)/(HooverMass*Units2Electronmass);
|
---|
66 | alpha += delta_alpha*World::getInstance().getConfig()->Deltat;
|
---|
67 | DoLog(3) && (Log() << Verbose(3) << "alpha = " << delta_alpha << " * " << World::getInstance().getConfig()->Deltat << " = " << alpha << "." << endl);
|
---|
68 | double ekin =0;
|
---|
69 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
70 | Vector U = (*iter)->getAtomicVelocityAtStep(step);
|
---|
71 | if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
|
---|
72 | U += World::getInstance().getConfig()->Deltat/(*iter)->getType()->getMass() * (alpha * (U * (*iter)->getType()->getMass()));
|
---|
73 | ekin += (0.5*(*iter)->getType()->getMass()) * U.NormSquared();
|
---|
74 | }
|
---|
75 | (*iter)->setAtomicVelocityAtStep(step, U);
|
---|
76 | }
|
---|
77 | return ekin;
|
---|
78 | }
|
---|
79 |
|
---|
80 | template <class ForwardIterator>
|
---|
81 | void NoseHoover::init(unsigned int step,ForwardIterator begin, ForwardIterator end){
|
---|
82 | delta_alpha=0;
|
---|
83 | count=0;
|
---|
84 | for(ForwardIterator iter = begin;iter!=end;++iter){
|
---|
85 | const Vector &U = (*iter)->getAtomicVelocityAtStep(step);
|
---|
86 | if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
|
---|
87 | delta_alpha += U.NormSquared()*(*iter)->getType()->getMass();
|
---|
88 | }
|
---|
89 | ++count;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | std::string NoseHoover::name(){
|
---|
94 | return ThermostatTraits<NoseHoover>::name;
|
---|
95 | }
|
---|
96 |
|
---|
97 | std::string NoseHoover::writeParams(){
|
---|
98 | std::stringstream sstr;
|
---|
99 | sstr << HooverMass;
|
---|
100 | return sstr.str();
|
---|
101 | }
|
---|