1 | /*
|
---|
2 | * NoseHoover.cpp
|
---|
3 | *
|
---|
4 | * Created on: Aug 20, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "NoseHoover.hpp"
|
---|
9 |
|
---|
10 | #include "element.hpp"
|
---|
11 | #include "config.hpp"
|
---|
12 | #include "Helpers/Verbose.hpp"
|
---|
13 | #include "Helpers/Log.hpp"
|
---|
14 | #include "ThermoStatContainer.hpp"
|
---|
15 |
|
---|
16 | NoseHoover::NoseHoover()
|
---|
17 | {}
|
---|
18 |
|
---|
19 | NoseHoover::~NoseHoover()
|
---|
20 | {}
|
---|
21 |
|
---|
22 |
|
---|
23 | double NoseHoover::scaleAtoms(config &configuration,unsigned int step,ATOMSET(std::list) atoms){
|
---|
24 | return doScaleAtoms(configuration,step,atoms.begin(),atoms.end());
|
---|
25 | }
|
---|
26 |
|
---|
27 | double NoseHoover::scaleAtoms(config &configuration,unsigned int step,ATOMSET(std::vector) atoms){
|
---|
28 | return doScaleAtoms(configuration,step,atoms.begin(),atoms.end());
|
---|
29 | }
|
---|
30 |
|
---|
31 | double NoseHoover::scaleAtoms(config &configuration,unsigned int step,ATOMSET(std::set) atoms){
|
---|
32 | return doScaleAtoms(configuration,step,atoms.begin(),atoms.end());
|
---|
33 | }
|
---|
34 |
|
---|
35 | template <class ForwardIterator>
|
---|
36 | double NoseHoover::doScaleAtoms(config &configuration,unsigned int step,ForwardIterator begin, ForwardIterator end){
|
---|
37 | DoLog(2) && (Log() << Verbose(2) << "Applying Nose-Hoover thermostat..." << endl);
|
---|
38 | init(step,begin,end);
|
---|
39 | delta_alpha = (delta_alpha - (3.*count+1.) * configuration.Thermostats->TargetTemp)/(configuration.Thermostats->HooverMass*Units2Electronmass);
|
---|
40 | configuration.Thermostats->alpha += delta_alpha*configuration.Deltat;
|
---|
41 | DoLog(3) && (Log() << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.Thermostats->alpha << "." << endl);
|
---|
42 | double ekin =0;
|
---|
43 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
44 | Vector &U = (*iter)->Trajectory.U.at(step);
|
---|
45 | if ((*iter)->FixedIon == 0) { // even FixedIon moves, only not by other's forces
|
---|
46 | U += configuration.Deltat/(*iter)->getType()->mass * (configuration.Thermostats->alpha * (U * (*iter)->getType()->mass));
|
---|
47 | ekin += (0.5*(*iter)->getType()->mass) * U.NormSquared();
|
---|
48 | }
|
---|
49 | }
|
---|
50 | return ekin;
|
---|
51 | }
|
---|
52 |
|
---|
53 | template <class ForwardIterator>
|
---|
54 | void NoseHoover::init(unsigned int step,ForwardIterator begin, ForwardIterator end){
|
---|
55 | delta_alpha=0;
|
---|
56 | count=0;
|
---|
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
|
---|
60 | delta_alpha += U.NormSquared()*(*iter)->getType()->mass;
|
---|
61 | }
|
---|
62 | ++count;
|
---|
63 | }
|
---|
64 | }
|
---|