[194649] | 1 | /*
|
---|
| 2 | * GaussianThermostat.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 18, 2010
|
---|
| 5 | * Author: crueger
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[d2b28f] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[ad011c] | 13 | #include "CodePatterns/MemDebug.hpp"
|
---|
[d2b28f] | 14 |
|
---|
[194649] | 15 | #include "GaussianThermostat.hpp"
|
---|
| 16 | #include "LinearAlgebra/Vector.hpp"
|
---|
[ad011c] | 17 | #include "CodePatterns/Log.hpp"
|
---|
| 18 | #include "CodePatterns/Verbose.hpp"
|
---|
[194649] | 19 | #include "AtomSet.hpp"
|
---|
| 20 | #include "element.hpp"
|
---|
| 21 | #include "config.hpp"
|
---|
[579a81] | 22 | #include "World.hpp"
|
---|
| 23 |
|
---|
[194649] | 24 | #include <set>
|
---|
| 25 |
|
---|
[579a81] | 26 | GaussianThermostat::GaussianThermostat(int _ScaleTempStep) :
|
---|
| 27 | E(0),G(0),
|
---|
| 28 | ScaleTempStep(_ScaleTempStep)
|
---|
[194649] | 29 | {}
|
---|
| 30 |
|
---|
[3e4162] | 31 | GaussianThermostat::GaussianThermostat() :
|
---|
| 32 | E(0),G(0),
|
---|
| 33 | ScaleTempStep(25)
|
---|
| 34 | {}
|
---|
| 35 |
|
---|
[194649] | 36 | GaussianThermostat::~GaussianThermostat()
|
---|
| 37 | {}
|
---|
| 38 |
|
---|
[14c57a] | 39 | const char *ThermostatTraits<GaussianThermostat>::name = "Gaussian";
|
---|
| 40 |
|
---|
| 41 | std::string ThermostatTraits<GaussianThermostat>::getName(){
|
---|
| 42 | return ThermostatTraits<GaussianThermostat>::name;
|
---|
| 43 | }
|
---|
[579a81] | 44 |
|
---|
[c0c650] | 45 | Thermostat *ThermostatTraits<GaussianThermostat>::make(class ConfigFileBuffer * const fb){
|
---|
| 46 | int ScaleTempStep;
|
---|
| 47 | const int verbose = 0;
|
---|
| 48 | ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate
|
---|
| 49 | return new class GaussianThermostat(ScaleTempStep);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[579a81] | 52 | double GaussianThermostat::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
|
---|
| 53 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 54 | }
|
---|
| 55 |
|
---|
[579a81] | 56 | double GaussianThermostat::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
|
---|
| 57 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 58 | }
|
---|
| 59 |
|
---|
[579a81] | 60 | double GaussianThermostat::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
|
---|
| 61 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
[194649] | 62 | }
|
---|
| 63 |
|
---|
| 64 | template <class ForwardIterator>
|
---|
[579a81] | 65 | double GaussianThermostat::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
|
---|
[194649] | 66 | DoLog(2) && (Log() << Verbose(2) << "Applying Gaussian thermostat..." << endl);
|
---|
| 67 | init(step,begin,end);
|
---|
| 68 | double G_over_E = G/E;
|
---|
| 69 | DoLog(1) && (Log() << Verbose(1) << "Gaussian Least Constraint constant is " << G_over_E << "." << endl);
|
---|
| 70 | double ekin =0;
|
---|
| 71 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
| 72 | Vector &U = (*iter)->Trajectory.U.at(step);
|
---|
| 73 | if ((*iter)->FixedIon == 0) {// even FixedIon moves, only not by other's forces
|
---|
[579a81] | 74 | U += World::getInstance().getConfig()->Deltat * G_over_E * U;
|
---|
[51c3e4] | 75 | ekin += (*iter)->getType()->getMass() * U.NormSquared();
|
---|
[194649] | 76 | }
|
---|
| 77 | }
|
---|
| 78 | return ekin;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | template <class ForwardIterator>
|
---|
| 82 | void GaussianThermostat::init(unsigned int step,ForwardIterator begin, ForwardIterator end){
|
---|
| 83 | E=0;
|
---|
| 84 | G=0;
|
---|
| 85 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
| 86 | Vector &U = (*iter)->Trajectory.U.at(step);
|
---|
| 87 | Vector &F = (*iter)->Trajectory.F.at(step);
|
---|
| 88 | if ((*iter)->FixedIon == 0){ // even FixedIon moves, only not by other's forces
|
---|
| 89 | G += U.ScalarProduct(F);
|
---|
[51c3e4] | 90 | E += U.NormSquared()*(*iter)->getType()->getMass();
|
---|
[194649] | 91 | }
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | double GaussianThermostat::getE() const{
|
---|
| 96 | return E;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | double GaussianThermostat::getG() const{
|
---|
| 100 | return G;
|
---|
| 101 | }
|
---|
[579a81] | 102 |
|
---|
| 103 | std::string GaussianThermostat::name(){
|
---|
[14c57a] | 104 | return ThermostatTraits<GaussianThermostat>::name;
|
---|
[579a81] | 105 | }
|
---|
| 106 |
|
---|
| 107 | std::string GaussianThermostat::writeParams(){
|
---|
| 108 | std::stringstream sstr;
|
---|
| 109 | sstr << ScaleTempStep;
|
---|
| 110 | return sstr.str();
|
---|
| 111 | }
|
---|