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