source: src/Thermostats/Langevin.cpp@ aec098

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since aec098 was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 4.2 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 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * Langevin.cpp
10 *
11 * Created on: Aug 20, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "Langevin.hpp"
23
24#include "CodePatterns/Log.hpp"
25#include "Parser/PcpParser_helper.hpp"
26#include "Element/element.hpp"
27#include "Helpers/defs.hpp"
28#include "Thermostats/ThermoStatContainer.hpp"
29
30#include <boost/random/mersenne_twister.hpp>
31#include <boost/random/normal_distribution.hpp>
32#include <boost/random/variate_generator.hpp>
33
34#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
35#include "RandomNumbers/RandomNumberGenerator.hpp"
36
37Langevin::Langevin(double _TempFrequency,double _alpha) :
38 TempFrequency(_TempFrequency),
39 alpha(_alpha),
40 rng_engine(new boost::mt19937),
41 rng_distribution(NULL)
42{}
43
44Langevin::Langevin() :
45 TempFrequency(2.5),
46 alpha(0.),
47 rng_engine(new boost::mt19937),
48 rng_distribution(NULL)
49{}
50
51Langevin::~Langevin()
52{
53 delete rng_engine;
54 delete rng_distribution;
55}
56
57const char *ThermostatTraits<Langevin>::name = "Langevin";
58
59std::string ThermostatTraits<Langevin>::getName(){
60 return ThermostatTraits<Langevin>::name;
61}
62
63Thermostat *ThermostatTraits<Langevin>::make(class ConfigFileBuffer * const fb){
64 double TempFrequency;
65 double alpha;
66 const int verbose = 0;
67 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma
68 if (ParseForParameter(verbose,fb,"Thermostat", 0, 3, 1, double_type, &alpha, 1, optional)) {
69 LOG(2, "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << ".");
70 } else {
71 alpha = 1.;
72 }
73 return new Langevin(TempFrequency,alpha);
74}
75
76double Langevin::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
77 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
78}
79
80double Langevin::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
81 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
82}
83
84double Langevin::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
85 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
86}
87
88template <class ForwardIterator>
89double Langevin::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
90 LOG(2, "Applying Langevin thermostat...");
91 RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator("mt19937", "normal_distribution");
92 const double rng_min = random.min();
93 const double rng_max = random.max();
94 double ekin=0;
95 for(ForwardIterator iter=begin;iter!=end;++iter){
96 double sigma = sqrt(getContainer().TargetTemp/(*iter)->getType()->getMass()); // sigma = (k_b T)/m (Hartree/atomicmass = atomiclength/atomictime)
97 rng_distribution = new boost::normal_distribution<>(0,sigma);
98 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > rng(*rng_engine, *rng_distribution);
99 Vector U = (*iter)->getAtomicVelocityAtStep(step);
100 if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
101 // throw a dice to determine whether it gets hit by a heat bath particle
102 if (((((random()/(rng_max-rng_min)))*TempFrequency) < 1.)) {
103 // pick three random numbers from a Boltzmann distribution around the desired temperature T for each momenta axis
104 const double oldNorm = U.Norm();
105 for (int d=0; d<NDIM; d++)
106 U[d] = rng();
107 LOG(3, "Particle " << (**iter) << " was hit (sigma " << sigma << "): " << oldNorm << " -> " << U.Norm());
108 }
109 ekin += 0.5*(*iter)->getType()->getMass() * U.NormSquared();
110 }
111 (*iter)->setAtomicVelocityAtStep(step, U);
112 delete rng_distribution;
113 rng_distribution = NULL;
114 }
115 return ekin;
116}
117
118std::string Langevin::name(){
119 return ThermostatTraits<Langevin>::name;
120}
121
122std::string Langevin::writeParams(){
123 stringstream sstr;
124 sstr << TempFrequency << "\t" << alpha;
125 return sstr.str();
126}
Note: See TracBrowser for help on using the repository browser.