| 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 "World.hpp"
|
|---|
| 16 |
|
|---|
| 17 | #include <set>
|
|---|
| 18 |
|
|---|
| 19 | GaussianThermostat::GaussianThermostat(int _ScaleTempStep) :
|
|---|
| 20 | E(0),G(0),
|
|---|
| 21 | ScaleTempStep(_ScaleTempStep)
|
|---|
| 22 | {}
|
|---|
| 23 |
|
|---|
| 24 | GaussianThermostat::GaussianThermostat() :
|
|---|
| 25 | E(0),G(0),
|
|---|
| 26 | ScaleTempStep(25)
|
|---|
| 27 | {}
|
|---|
| 28 |
|
|---|
| 29 | GaussianThermostat::~GaussianThermostat()
|
|---|
| 30 | {}
|
|---|
| 31 |
|
|---|
| 32 | ThermostatTraits<GaussianThermostat>::ThermostatTraits() :
|
|---|
| 33 | name("Gaussian")
|
|---|
| 34 | {}
|
|---|
| 35 |
|
|---|
| 36 | Thermostat *ThermostatTraits<GaussianThermostat>::make(class ConfigFileBuffer * const fb){
|
|---|
| 37 | int ScaleTempStep;
|
|---|
| 38 | const int verbose = 0;
|
|---|
| 39 | ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate
|
|---|
| 40 | return new class GaussianThermostat(ScaleTempStep);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | double GaussianThermostat::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
|
|---|
| 44 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | double GaussianThermostat::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
|
|---|
| 48 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | double GaussianThermostat::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
|
|---|
| 52 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | template <class ForwardIterator>
|
|---|
| 56 | double GaussianThermostat::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
|
|---|
| 57 | DoLog(2) && (Log() << Verbose(2) << "Applying Gaussian thermostat..." << endl);
|
|---|
| 58 | init(step,begin,end);
|
|---|
| 59 | double G_over_E = G/E;
|
|---|
| 60 | DoLog(1) && (Log() << Verbose(1) << "Gaussian Least Constraint constant is " << G_over_E << "." << endl);
|
|---|
| 61 | double ekin =0;
|
|---|
| 62 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
|---|
| 63 | Vector &U = (*iter)->Trajectory.U.at(step);
|
|---|
| 64 | if ((*iter)->FixedIon == 0) {// even FixedIon moves, only not by other's forces
|
|---|
| 65 | U += World::getInstance().getConfig()->Deltat * G_over_E * U;
|
|---|
| 66 | ekin += (*iter)->getType()->mass * U.NormSquared();
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 | return ekin;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | template <class ForwardIterator>
|
|---|
| 73 | void GaussianThermostat::init(unsigned int step,ForwardIterator begin, ForwardIterator end){
|
|---|
| 74 | E=0;
|
|---|
| 75 | G=0;
|
|---|
| 76 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
|---|
| 77 | Vector &U = (*iter)->Trajectory.U.at(step);
|
|---|
| 78 | Vector &F = (*iter)->Trajectory.F.at(step);
|
|---|
| 79 | if ((*iter)->FixedIon == 0){ // even FixedIon moves, only not by other's forces
|
|---|
| 80 | G += U.ScalarProduct(F);
|
|---|
| 81 | E += U.NormSquared()*(*iter)->getType()->mass;
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | double GaussianThermostat::getE() const{
|
|---|
| 87 | return E;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | double GaussianThermostat::getG() const{
|
|---|
| 91 | return G;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | std::string GaussianThermostat::name(){
|
|---|
| 95 | return ThermostatTraits<GaussianThermostat>().name;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | std::string GaussianThermostat::writeParams(){
|
|---|
| 99 | std::stringstream sstr;
|
|---|
| 100 | sstr << ScaleTempStep;
|
|---|
| 101 | return sstr.str();
|
|---|
| 102 | }
|
|---|