| [abae35] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [94d5ac6] | 5 |  * 
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [abae35] | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
| [194649] | 23 | /*
 | 
|---|
 | 24 |  * NoseHoover.cpp
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  *  Created on: Aug 20, 2010
 | 
|---|
 | 27 |  *      Author: crueger
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | 
 | 
|---|
| [d2b28f] | 30 | // include config.h
 | 
|---|
 | 31 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 32 | #include <config.h>
 | 
|---|
 | 33 | #endif
 | 
|---|
 | 34 | 
 | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [d2b28f] | 36 | 
 | 
|---|
| [194649] | 37 | #include "NoseHoover.hpp"
 | 
|---|
 | 38 | 
 | 
|---|
| [ad011c] | 39 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [41a467] | 40 | #include "config.hpp"
 | 
|---|
 | 41 | #include "Element/element.hpp"
 | 
|---|
| [255829] | 42 | #include "Helpers/defs.hpp"
 | 
|---|
| [41a467] | 43 | #include "Parser/PcpParser_helper.hpp"
 | 
|---|
| [ab26c3] | 44 | #include "Thermostats/ThermoStatContainer.hpp"
 | 
|---|
| [579a81] | 45 | #include "World.hpp"
 | 
|---|
| [194649] | 46 | 
 | 
|---|
| [579a81] | 47 | NoseHoover::NoseHoover(double _HooverMass) :
 | 
|---|
| [c0c650] | 48 |   HooverMass(_HooverMass),
 | 
|---|
 | 49 |   alpha(0)
 | 
|---|
| [194649] | 50 | {}
 | 
|---|
 | 51 | 
 | 
|---|
| [3e4162] | 52 | NoseHoover::NoseHoover() :
 | 
|---|
 | 53 |   HooverMass(0.)
 | 
|---|
 | 54 | {}
 | 
|---|
 | 55 | 
 | 
|---|
| [194649] | 56 | NoseHoover::~NoseHoover()
 | 
|---|
 | 57 | {}
 | 
|---|
 | 58 | 
 | 
|---|
| [14c57a] | 59 | const char *ThermostatTraits<NoseHoover>::name = "NoseHoover";
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | std::string ThermostatTraits<NoseHoover>::getName(){
 | 
|---|
 | 62 |   return ThermostatTraits<NoseHoover>::name;
 | 
|---|
 | 63 | }
 | 
|---|
| [579a81] | 64 | 
 | 
|---|
| [14c57a] | 65 | Thermostat *ThermostatTraits<NoseHoover>::make(class ConfigFileBuffer * const fb){
 | 
|---|
| [c0c650] | 66 |   double HooverMass;
 | 
|---|
 | 67 |   const int verbose = 0;
 | 
|---|
 | 68 |   ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass
 | 
|---|
| [14c57a] | 69 |   return new NoseHoover(HooverMass);
 | 
|---|
| [c0c650] | 70 | }
 | 
|---|
| [194649] | 71 | 
 | 
|---|
| [579a81] | 72 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
 | 
|---|
 | 73 |   return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
 | 
|---|
| [194649] | 74 | }
 | 
|---|
 | 75 | 
 | 
|---|
| [579a81] | 76 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
 | 
|---|
 | 77 |   return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
 | 
|---|
| [194649] | 78 | }
 | 
|---|
 | 79 | 
 | 
|---|
| [579a81] | 80 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
 | 
|---|
 | 81 |   return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
 | 
|---|
| [194649] | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | template <class ForwardIterator>
 | 
|---|
| [579a81] | 85 | double NoseHoover::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
 | 
|---|
| [47d041] | 86 |   LOG(2,  "Applying Nose-Hoover thermostat...");
 | 
|---|
| [194649] | 87 |   init(step,begin,end);
 | 
|---|
| [579a81] | 88 |   delta_alpha = (delta_alpha - (3.*count+1.) * getContainer().TargetTemp)/(HooverMass*Units2Electronmass);
 | 
|---|
| [c0c650] | 89 |   alpha += delta_alpha*World::getInstance().getConfig()->Deltat;
 | 
|---|
| [47d041] | 90 |   LOG(3, "alpha = " << delta_alpha << " * " << World::getInstance().getConfig()->Deltat << " = " << alpha << ".");
 | 
|---|
| [194649] | 91 |   double ekin =0;
 | 
|---|
 | 92 |   for(ForwardIterator iter=begin;iter!=end;++iter){
 | 
|---|
| [056e70] | 93 |     Vector U = (*iter)->getAtomicVelocityAtStep(step);
 | 
|---|
| [6625c3] | 94 |     if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
 | 
|---|
| [51c3e4] | 95 |       U += World::getInstance().getConfig()->Deltat/(*iter)->getType()->getMass() * (alpha * (U * (*iter)->getType()->getMass()));
 | 
|---|
 | 96 |       ekin += (0.5*(*iter)->getType()->getMass()) * U.NormSquared();
 | 
|---|
| [194649] | 97 |     }
 | 
|---|
| [056e70] | 98 |     (*iter)->setAtomicVelocityAtStep(step, U);
 | 
|---|
| [194649] | 99 |   }
 | 
|---|
 | 100 |   return ekin;
 | 
|---|
 | 101 | }
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 | template <class ForwardIterator>
 | 
|---|
 | 104 | void NoseHoover::init(unsigned int step,ForwardIterator begin, ForwardIterator end){
 | 
|---|
 | 105 |   delta_alpha=0;
 | 
|---|
 | 106 |   count=0;
 | 
|---|
 | 107 |   for(ForwardIterator iter = begin;iter!=end;++iter){
 | 
|---|
| [056e70] | 108 |     const Vector &U = (*iter)->getAtomicVelocityAtStep(step);
 | 
|---|
| [6625c3] | 109 |     if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
 | 
|---|
| [51c3e4] | 110 |       delta_alpha += U.NormSquared()*(*iter)->getType()->getMass();
 | 
|---|
| [194649] | 111 |     }
 | 
|---|
 | 112 |     ++count;
 | 
|---|
 | 113 |   }
 | 
|---|
 | 114 | }
 | 
|---|
| [579a81] | 115 | 
 | 
|---|
 | 116 | std::string NoseHoover::name(){
 | 
|---|
| [14c57a] | 117 |   return ThermostatTraits<NoseHoover>::name;
 | 
|---|
| [579a81] | 118 | }
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 | std::string NoseHoover::writeParams(){
 | 
|---|
 | 121 |   std::stringstream sstr;
 | 
|---|
 | 122 |   sstr << HooverMass;
 | 
|---|
 | 123 |   return sstr.str();
 | 
|---|
 | 124 | }
 | 
|---|