1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
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/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * NoseHoover.cpp
|
---|
25 | *
|
---|
26 | * Created on: Aug 20, 2010
|
---|
27 | * Author: crueger
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "CodePatterns/MemDebug.hpp"
|
---|
36 |
|
---|
37 | #include "NoseHoover.hpp"
|
---|
38 |
|
---|
39 | #include "CodePatterns/Log.hpp"
|
---|
40 | #include "config.hpp"
|
---|
41 | #include "Element/element.hpp"
|
---|
42 | #include "Helpers/defs.hpp"
|
---|
43 | #include "Parser/PcpParser_helper.hpp"
|
---|
44 | #include "Thermostats/ThermoStatContainer.hpp"
|
---|
45 | #include "World.hpp"
|
---|
46 |
|
---|
47 | NoseHoover::NoseHoover(double _HooverMass) :
|
---|
48 | HooverMass(_HooverMass),
|
---|
49 | alpha(0)
|
---|
50 | {}
|
---|
51 |
|
---|
52 | NoseHoover::NoseHoover() :
|
---|
53 | HooverMass(0.)
|
---|
54 | {}
|
---|
55 |
|
---|
56 | NoseHoover::~NoseHoover()
|
---|
57 | {}
|
---|
58 |
|
---|
59 | const char *ThermostatTraits<NoseHoover>::name = "NoseHoover";
|
---|
60 |
|
---|
61 | std::string ThermostatTraits<NoseHoover>::getName(){
|
---|
62 | return ThermostatTraits<NoseHoover>::name;
|
---|
63 | }
|
---|
64 |
|
---|
65 | Thermostat *ThermostatTraits<NoseHoover>::make(class ConfigFileBuffer * const fb){
|
---|
66 | double HooverMass;
|
---|
67 | const int verbose = 0;
|
---|
68 | ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass
|
---|
69 | return new NoseHoover(HooverMass);
|
---|
70 | }
|
---|
71 |
|
---|
72 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
|
---|
73 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
74 | }
|
---|
75 |
|
---|
76 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
|
---|
77 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
78 | }
|
---|
79 |
|
---|
80 | double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
|
---|
81 | return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
|
---|
82 | }
|
---|
83 |
|
---|
84 | template <class ForwardIterator>
|
---|
85 | double NoseHoover::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
|
---|
86 | LOG(2, "Applying Nose-Hoover thermostat...");
|
---|
87 | init(step,begin,end);
|
---|
88 | delta_alpha = (delta_alpha - (3.*count+1.) * getContainer().TargetTemp)/(HooverMass*Units2Electronmass);
|
---|
89 | alpha += delta_alpha*World::getInstance().getConfig()->Deltat;
|
---|
90 | LOG(3, "alpha = " << delta_alpha << " * " << World::getInstance().getConfig()->Deltat << " = " << alpha << ".");
|
---|
91 | double ekin =0;
|
---|
92 | for(ForwardIterator iter=begin;iter!=end;++iter){
|
---|
93 | Vector U = (*iter)->getAtomicVelocityAtStep(step);
|
---|
94 | if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
|
---|
95 | U += World::getInstance().getConfig()->Deltat/(*iter)->getType()->getMass() * (alpha * (U * (*iter)->getType()->getMass()));
|
---|
96 | ekin += (0.5*(*iter)->getType()->getMass()) * U.NormSquared();
|
---|
97 | }
|
---|
98 | (*iter)->setAtomicVelocityAtStep(step, U);
|
---|
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){
|
---|
108 | const Vector &U = (*iter)->getAtomicVelocityAtStep(step);
|
---|
109 | if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
|
---|
110 | delta_alpha += U.NormSquared()*(*iter)->getType()->getMass();
|
---|
111 | }
|
---|
112 | ++count;
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | std::string NoseHoover::name(){
|
---|
117 | return ThermostatTraits<NoseHoover>::name;
|
---|
118 | }
|
---|
119 |
|
---|
120 | std::string NoseHoover::writeParams(){
|
---|
121 | std::stringstream sstr;
|
---|
122 | sstr << HooverMass;
|
---|
123 | return sstr.str();
|
---|
124 | }
|
---|