source: src/Thermostats/Langevin.cpp@ 7d1b6a

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 7d1b6a 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
RevLine 
[abae35]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[abae35]5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[194649]8/*
9 * Langevin.cpp
10 *
11 * Created on: Aug 20, 2010
12 * Author: crueger
13 */
14
[d2b28f]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[ad011c]20#include "CodePatterns/MemDebug.hpp"
[d2b28f]21
[194649]22#include "Langevin.hpp"
[41a467]23
[ad011c]24#include "CodePatterns/Log.hpp"
[41a467]25#include "Parser/PcpParser_helper.hpp"
26#include "Element/element.hpp"
[255829]27#include "Helpers/defs.hpp"
[ab26c3]28#include "Thermostats/ThermoStatContainer.hpp"
[194649]29
[6625c3]30#include <boost/random/mersenne_twister.hpp>
31#include <boost/random/normal_distribution.hpp>
32#include <boost/random/variate_generator.hpp>
33
[a5028f]34#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
35#include "RandomNumbers/RandomNumberGenerator.hpp"
36
[c0c650]37Langevin::Langevin(double _TempFrequency,double _alpha) :
38 TempFrequency(_TempFrequency),
[6625c3]39 alpha(_alpha),
40 rng_engine(new boost::mt19937),
41 rng_distribution(NULL)
42{}
[194649]43
[3e4162]44Langevin::Langevin() :
45 TempFrequency(2.5),
[6625c3]46 alpha(0.),
47 rng_engine(new boost::mt19937),
48 rng_distribution(NULL)
[3e4162]49{}
50
[194649]51Langevin::~Langevin()
52{
[6625c3]53 delete rng_engine;
54 delete rng_distribution;
[194649]55}
56
[14c57a]57const char *ThermostatTraits<Langevin>::name = "Langevin";
58
59std::string ThermostatTraits<Langevin>::getName(){
60 return ThermostatTraits<Langevin>::name;
61}
[579a81]62
[14c57a]63Thermostat *ThermostatTraits<Langevin>::make(class ConfigFileBuffer * const fb){
[c0c650]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)) {
[47d041]69 LOG(2, "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << ".");
[c0c650]70 } else {
71 alpha = 1.;
72 }
[14c57a]73 return new Langevin(TempFrequency,alpha);
[c0c650]74}
75
[579a81]76double Langevin::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::list) atoms){
77 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
[194649]78}
79
[579a81]80double Langevin::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::vector) atoms){
81 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
[194649]82}
83
[579a81]84double Langevin::scaleAtoms(unsigned int step,double ActualTemp,ATOMSET(std::set) atoms){
85 return doScaleAtoms(step,ActualTemp,atoms.begin(),atoms.end());
[194649]86}
87
88template <class ForwardIterator>
[579a81]89double Langevin::doScaleAtoms(unsigned int step,double ActualTemp,ForwardIterator begin, ForwardIterator end){
[47d041]90 LOG(2, "Applying Langevin thermostat...");
[6625c3]91 RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator("mt19937", "normal_distribution");
[a5028f]92 const double rng_min = random.min();
93 const double rng_max = random.max();
[194649]94 double ekin=0;
95 for(ForwardIterator iter=begin;iter!=end;++iter){
[51c3e4]96 double sigma = sqrt(getContainer().TargetTemp/(*iter)->getType()->getMass()); // sigma = (k_b T)/m (Hartree/atomicmass = atomiclength/atomictime)
[6625c3]97 rng_distribution = new boost::normal_distribution<>(0,sigma);
98 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > rng(*rng_engine, *rng_distribution);
[056e70]99 Vector U = (*iter)->getAtomicVelocityAtStep(step);
[6625c3]100 if ((*iter)->getFixedIon() == 0) { // even FixedIon moves, only not by other's forces
[194649]101 // throw a dice to determine whether it gets hit by a heat bath particle
[a5028f]102 if (((((random()/(rng_max-rng_min)))*TempFrequency) < 1.)) {
[194649]103 // pick three random numbers from a Boltzmann distribution around the desired temperature T for each momenta axis
[47d041]104 const double oldNorm = U.Norm();
105 for (int d=0; d<NDIM; d++)
[6625c3]106 U[d] = rng();
[47d041]107 LOG(3, "Particle " << (**iter) << " was hit (sigma " << sigma << "): " << oldNorm << " -> " << U.Norm());
[194649]108 }
[51c3e4]109 ekin += 0.5*(*iter)->getType()->getMass() * U.NormSquared();
[194649]110 }
[056e70]111 (*iter)->setAtomicVelocityAtStep(step, U);
[6625c3]112 delete rng_distribution;
113 rng_distribution = NULL;
[194649]114 }
115 return ekin;
116}
[579a81]117
118std::string Langevin::name(){
[14c57a]119 return ThermostatTraits<Langevin>::name;
[579a81]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.