| [bcf653] | 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/>. | 
|---|
| [bcf653] | 21 | */ | 
|---|
|  | 22 |  | 
|---|
| [a3fded] | 23 | /* | 
|---|
|  | 24 | * ThermoStatContainer.cpp | 
|---|
|  | 25 | * | 
|---|
|  | 26 | *  Created on: 12.06.2010 | 
|---|
|  | 27 | *      Author: heber | 
|---|
|  | 28 | */ | 
|---|
|  | 29 |  | 
|---|
| [bf3817] | 30 | // include config.h | 
|---|
|  | 31 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 32 | #include <config.h> | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 |  | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| [bbbad5] | 36 |  | 
|---|
| [a3fded] | 37 | #include <cstring> | 
|---|
|  | 38 |  | 
|---|
| [ad011c] | 39 | #include "CodePatterns/Log.hpp" | 
|---|
| [ab26c3] | 40 | #include "Thermostats/ThermoStatContainer.hpp" | 
|---|
| [41a467] | 41 | #include "Parser/ConfigFileBuffer.hpp" | 
|---|
| [a3fded] | 42 |  | 
|---|
| [14c57a] | 43 | #include <Thermostats/Berendsen.hpp> | 
|---|
|  | 44 | #include <Thermostats/GaussianThermostat.hpp> | 
|---|
|  | 45 | #include <Thermostats/Langevin.hpp> | 
|---|
|  | 46 | #include <Thermostats/NoseHoover.hpp> | 
|---|
|  | 47 | #include <Thermostats/NoThermostat.hpp> | 
|---|
|  | 48 | #include <Thermostats/Woodcock.hpp> | 
|---|
|  | 49 |  | 
|---|
| [a3fded] | 50 | /** Constructor for class ThermoStatContainer. | 
|---|
|  | 51 | * | 
|---|
|  | 52 | */ | 
|---|
| [97b825] | 53 | ThermoStatContainer::ThermoStatContainer() : | 
|---|
| [14c57a] | 54 | activeThermostat(0), | 
|---|
|  | 55 | TargetTemp(0.00095004455) | 
|---|
| [a3fded] | 56 | { | 
|---|
| [14c57a] | 57 | ThermostatTraits<Thermostat> *BerendsenTrait = new ThermostatTraits<Berendsen>(); | 
|---|
|  | 58 | availThermostats[BerendsenTrait->getName()] = BerendsenTrait; | 
|---|
|  | 59 | ThermostatTraits<Thermostat> *GaussianTrait = new ThermostatTraits<GaussianThermostat>(); | 
|---|
|  | 60 | availThermostats[GaussianTrait->getName()] = GaussianTrait; | 
|---|
|  | 61 | ThermostatTraits<Thermostat> *LangevinTrait = new ThermostatTraits<Langevin>(); | 
|---|
|  | 62 | availThermostats[LangevinTrait->getName()] = LangevinTrait; | 
|---|
|  | 63 | ThermostatTraits<Thermostat> *NoseHooverTrait = new ThermostatTraits<NoseHoover>(); | 
|---|
|  | 64 | availThermostats[NoseHooverTrait->getName()] = NoseHooverTrait; | 
|---|
|  | 65 | ThermostatTraits<Thermostat> *NoThermostatTrait = new ThermostatTraits<NoThermostat>(); | 
|---|
|  | 66 | availThermostats[NoThermostatTrait->getName()] = NoThermostatTrait; | 
|---|
|  | 67 | ThermostatTraits<Thermostat> *WoodcockTrait = new ThermostatTraits<Woodcock>(); | 
|---|
|  | 68 | availThermostats[WoodcockTrait->getName()] = WoodcockTrait; | 
|---|
| [ad7270] | 69 |  | 
|---|
|  | 70 | // for debugging: list all thermostats | 
|---|
|  | 71 | //  cout << "List of known thermostats: "; | 
|---|
|  | 72 | //  for(traitsMap::iterator iter = availThermostats.begin();iter!=availThermostats.end();++iter){ | 
|---|
|  | 73 | //    cout << iter->first << " "; | 
|---|
|  | 74 | //  } | 
|---|
|  | 75 | //  cout << endl; | 
|---|
|  | 76 |  | 
|---|
| [14c57a] | 77 | ASSERT(availThermostats.size()==6,"Not all implemented thermostats referenced!\nDid you check the names in the traits?"); | 
|---|
| [f73351] | 78 | activeThermostat=new NoThermostat(); | 
|---|
| [5251af] | 79 | activeThermostat->addToContainer(this); | 
|---|
| [14c57a] | 80 | } | 
|---|
|  | 81 |  | 
|---|
|  | 82 | ThermostatTraits<Thermostat> *ThermoStatContainer::getTraitByName(const std::string name){ | 
|---|
|  | 83 | if(!availThermostats.count(name)) | 
|---|
|  | 84 | return 0; | 
|---|
|  | 85 | return availThermostats[name]; | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | Thermostat *ThermoStatContainer::makeByName(const std::string name,class ConfigFileBuffer * const fb){ | 
|---|
|  | 89 | ThermostatTraits<Thermostat>* trait = getTraitByName(name); | 
|---|
|  | 90 | if(trait){ | 
|---|
|  | 91 | Thermostat *res = trait->make(fb); | 
|---|
|  | 92 | res->addToContainer(this); | 
|---|
|  | 93 | return res; | 
|---|
|  | 94 | } | 
|---|
|  | 95 | else{ | 
|---|
|  | 96 | return 0; | 
|---|
|  | 97 | } | 
|---|
|  | 98 | } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | void ThermoStatContainer::makeActive(const std::string name,class ConfigFileBuffer * const fb){ | 
|---|
|  | 101 | Thermostat* newThermostat = makeByName(name,fb); | 
|---|
|  | 102 | if(newThermostat){ | 
|---|
|  | 103 | if(activeThermostat){ | 
|---|
|  | 104 | delete activeThermostat; | 
|---|
|  | 105 | } | 
|---|
|  | 106 | activeThermostat = newThermostat; | 
|---|
|  | 107 | } | 
|---|
|  | 108 | } | 
|---|
| [a3fded] | 109 |  | 
|---|
| [14c57a] | 110 | void ThermoStatContainer::chooseNone(){ | 
|---|
|  | 111 | if(activeThermostat){ | 
|---|
|  | 112 | delete activeThermostat; | 
|---|
|  | 113 | } | 
|---|
|  | 114 | activeThermostat = new NoThermostat(); | 
|---|
| [a3fded] | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 | /** Destructor for Class ThermoStatContainer. | 
|---|
|  | 118 | * | 
|---|
|  | 119 | */ | 
|---|
|  | 120 | ThermoStatContainer::~ThermoStatContainer() | 
|---|
|  | 121 | { | 
|---|
| [14c57a] | 122 | if(activeThermostat){ | 
|---|
|  | 123 | delete activeThermostat; | 
|---|
|  | 124 | } | 
|---|
|  | 125 | for(traitsMap::iterator iter= availThermostats.begin();iter!=availThermostats.end();++iter){ | 
|---|
|  | 126 | delete (iter->second); | 
|---|
|  | 127 | } | 
|---|
| [a3fded] | 128 | } | 
|---|
|  | 129 |  | 
|---|
|  | 130 |  | 
|---|