| 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 |  * ThermoStatContainer.cpp
 | 
|---|
| 25 |  *
 | 
|---|
| 26 |  *  Created on: 12.06.2010
 | 
|---|
| 27 |  *      Author: heber
 | 
|---|
| 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 <cstring>
 | 
|---|
| 38 | 
 | 
|---|
| 39 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 40 | #include "Thermostats/ThermoStatContainer.hpp"
 | 
|---|
| 41 | #include "Parser/ConfigFileBuffer.hpp"
 | 
|---|
| 42 | 
 | 
|---|
| 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 | 
 | 
|---|
| 50 | /** Constructor for class ThermoStatContainer.
 | 
|---|
| 51 |  *
 | 
|---|
| 52 |  */
 | 
|---|
| 53 | ThermoStatContainer::ThermoStatContainer() :
 | 
|---|
| 54 |   activeThermostat(0),
 | 
|---|
| 55 |   TargetTemp(0.00095004455)
 | 
|---|
| 56 | {
 | 
|---|
| 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;
 | 
|---|
| 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 | 
 | 
|---|
| 77 |   ASSERT(availThermostats.size()==6,"Not all implemented thermostats referenced!\nDid you check the names in the traits?");
 | 
|---|
| 78 |   activeThermostat=new Berendsen();
 | 
|---|
| 79 | }
 | 
|---|
| 80 | 
 | 
|---|
| 81 | ThermostatTraits<Thermostat> *ThermoStatContainer::getTraitByName(const std::string name){
 | 
|---|
| 82 |   if(!availThermostats.count(name))
 | 
|---|
| 83 |     return 0;
 | 
|---|
| 84 |   return availThermostats[name];
 | 
|---|
| 85 | }
 | 
|---|
| 86 | 
 | 
|---|
| 87 | Thermostat *ThermoStatContainer::makeByName(const std::string name,class ConfigFileBuffer * const fb){
 | 
|---|
| 88 |   ThermostatTraits<Thermostat>* trait = getTraitByName(name);
 | 
|---|
| 89 |   if(trait){
 | 
|---|
| 90 |     Thermostat *res = trait->make(fb);
 | 
|---|
| 91 |     res->addToContainer(this);
 | 
|---|
| 92 |     return res;
 | 
|---|
| 93 |   }
 | 
|---|
| 94 |   else{
 | 
|---|
| 95 |     return 0;
 | 
|---|
| 96 |   }
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | void ThermoStatContainer::makeActive(const std::string name,class ConfigFileBuffer * const fb){
 | 
|---|
| 100 |   Thermostat* newThermostat = makeByName(name,fb);
 | 
|---|
| 101 |   if(newThermostat){
 | 
|---|
| 102 |     if(activeThermostat){
 | 
|---|
| 103 |       delete activeThermostat;
 | 
|---|
| 104 |     }
 | 
|---|
| 105 |     activeThermostat = newThermostat;
 | 
|---|
| 106 |   }
 | 
|---|
| 107 | }
 | 
|---|
| 108 | 
 | 
|---|
| 109 | void ThermoStatContainer::chooseNone(){
 | 
|---|
| 110 |   if(activeThermostat){
 | 
|---|
| 111 |     delete activeThermostat;
 | 
|---|
| 112 |   }
 | 
|---|
| 113 |   activeThermostat = new NoThermostat();
 | 
|---|
| 114 | }
 | 
|---|
| 115 | 
 | 
|---|
| 116 | /** Destructor for Class ThermoStatContainer.
 | 
|---|
| 117 |  *
 | 
|---|
| 118 |  */
 | 
|---|
| 119 | ThermoStatContainer::~ThermoStatContainer()
 | 
|---|
| 120 | {
 | 
|---|
| 121 |   if(activeThermostat){
 | 
|---|
| 122 |     delete activeThermostat;
 | 
|---|
| 123 |   }
 | 
|---|
| 124 |   for(traitsMap::iterator iter= availThermostats.begin();iter!=availThermostats.end();++iter){
 | 
|---|
| 125 |     delete (iter->second);
 | 
|---|
| 126 |   }
 | 
|---|
| 127 | }
 | 
|---|
| 128 | 
 | 
|---|
| 129 | 
 | 
|---|