1 | /*
|
---|
2 | * GaussianThermostat.cpp
|
---|
3 | *
|
---|
4 | * Created on: Aug 18, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "GaussianThermostat.hpp"
|
---|
9 | #include "LinearAlgebra/Vector.hpp"
|
---|
10 | #include "Helpers/Log.hpp"
|
---|
11 | #include "Helpers/Verbose.hpp"
|
---|
12 | #include "AtomSet.hpp"
|
---|
13 | #include "element.hpp"
|
---|
14 | #include "config.hpp"
|
---|
15 | #include <set>
|
---|
16 |
|
---|
17 | GaussianThermostat::GaussianThermostat() : E(0),G(0)
|
---|
18 | {}
|
---|
19 |
|
---|
20 | GaussianThermostat::~GaussianThermostat()
|
---|
21 | {}
|
---|
22 |
|
---|
23 | double GaussianThermostat::scaleAtoms(config &configuration,unsigned int step,ATOMSET(std::list) atoms){
|
---|
24 | return doScaleAtoms(configuration,step,atoms.begin(),atoms.end());
|
---|
25 | }
|
---|
26 |
|
---|
27 | double GaussianThermostat::scaleAtoms(config &configuration,unsigned int step,ATOMSET(std::vector) atoms){
|
---|
28 | return doScaleAtoms(configuration,step,atoms.begin(),atoms.end());
|
---|
29 | }
|
---|
30 |
|
---|
31 | double GaussianThermostat::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 GaussianThermostat::doScaleAtoms(config &configuration,unsigned int step,ForwardIterator begin, ForwardIterator end){
|
---|
37 | DoLog(2) && (Log() << Verbose(2) << "Applying Gaussian thermostat..." << endl);
|
---|
38 | init(step,begin,end);
|
---|
39 | double G_over_E = G/E;
|
---|
40 | DoLog(1) && (Log() << Verbose(1) << "Gaussian Least Constraint constant is " << G_over_E << "." << endl);
|
---|
41 | double ekin =0;
|
---|
42 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
43 | Vector &U = (*iter)->Trajectory.U.at(step);
|
---|
44 | if ((*iter)->FixedIon == 0) {// even FixedIon moves, only not by other's forces
|
---|
45 | U += configuration.Deltat * G_over_E * U;
|
---|
46 | ekin += (*iter)->getType()->mass * U.NormSquared();
|
---|
47 | }
|
---|
48 | }
|
---|
49 | return ekin;
|
---|
50 | }
|
---|
51 |
|
---|
52 | template <class ForwardIterator>
|
---|
53 | void GaussianThermostat::init(unsigned int step,ForwardIterator begin, ForwardIterator end){
|
---|
54 | E=0;
|
---|
55 | G=0;
|
---|
56 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
57 | Vector &U = (*iter)->Trajectory.U.at(step);
|
---|
58 | Vector &F = (*iter)->Trajectory.F.at(step);
|
---|
59 | if ((*iter)->FixedIon == 0){ // even FixedIon moves, only not by other's forces
|
---|
60 | G += U.ScalarProduct(F);
|
---|
61 | E += U.NormSquared()*(*iter)->getType()->mass;
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | double GaussianThermostat::getE() const{
|
---|
67 | return E;
|
---|
68 | }
|
---|
69 |
|
---|
70 | double GaussianThermostat::getG() const{
|
---|
71 | return G;
|
---|
72 | }
|
---|