source: src/Thermostats/NoseHoover.cpp

Candidate_v1.6.1
Last change on this file was 9eb71b3, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Commented out MemDebug include and Memory::ignore.

  • MemDebug clashes with various allocation operators that use a specific placement in memory. It is so far not possible to wrap new/delete fully. Hence, we stop this effort which so far has forced us to put ever more includes (with clashes) into MemDebug and thereby bloat compilation time.
  • MemDebug does not add that much usefulness which is not also provided by valgrind.
  • Property mode set to 100644
File size: 4.0 KB
Line 
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
47NoseHoover::NoseHoover(double _HooverMass) :
48 HooverMass(_HooverMass),
49 alpha(0)
50{}
51
52NoseHoover::NoseHoover() :
53 HooverMass(0.)
54{}
55
56NoseHoover::~NoseHoover()
57{}
58
59const char *ThermostatTraits<NoseHoover>::name = "NoseHoover";
60
61std::string ThermostatTraits<NoseHoover>::getName(){
62 return ThermostatTraits<NoseHoover>::name;
63}
64
65Thermostat *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
72double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
73 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
74}
75
76double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
77 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
78}
79
80double NoseHoover::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
81 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
82}
83
84template <class ForwardIterator>
85double 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
103template <class ForwardIterator>
104void 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
116std::string NoseHoover::name(){
117 return ThermostatTraits<NoseHoover>::name;
118}
119
120std::string NoseHoover::writeParams(){
121 std::stringstream sstr;
122 sstr << HooverMass;
123 return sstr.str();
124}
Note: See TracBrowser for help on using the repository browser.