mcpele  1.0.0
The Monte Carlo Python Energy Landscape Explorer
metropolis_test.cpp
00001 #include "mcpele/metropolis_test.h"
00002 
00003 #include <cmath>
00004 //#include <chrono>
00005 
00006 using pele::Array;
00007 
00008 namespace mcpele {
00009 
00010 MetropolisTest::MetropolisTest(const size_t rseed)
00011     : m_seed(rseed),
00012       m_generator(rseed),
00013       m_distribution(0.0, 1.0)
00014 {
00015     #ifdef DEBUG
00016         std::cout << "seed Metropolis:" << _seed << "\n";
00017         //std::chrono::system_clock::now().time_since_epoch().count()
00018     #endif
00019 }
00020 
00021 bool MetropolisTest::test(Array<double> &trial_coords, double trial_energy,
00022         Array<double>& old_coords, double old_energy, double temperature,
00023         MC * mc)
00024 {
00025     double rand;
00026     double w;
00027     double wcomp;
00028     bool success = true;
00029     wcomp = (trial_energy - old_energy) / temperature;
00030     w = exp(-wcomp);
00031     if (w < 1.0) {
00032         rand = m_distribution(m_generator);
00033         if (rand > w) {
00034             success = false;
00035         }
00036     }
00037     return success;
00038 }
00039 
00040 } // namespace mcpele
 All Classes Namespaces Functions Variables Typedefs