mcpele  1.0.0
The Monte Carlo Python Energy Landscape Explorer
random_coords_displacement.cpp
00001 #include "mcpele/random_coords_displacement.h"
00002 
00003 namespace mcpele {
00004 
00005 /*RandomCoordsDisplacement*/
00006 
00007 RandomCoordsDisplacement::RandomCoordsDisplacement(const size_t rseed, const double stepsize)
00008     : m_seed(rseed),
00009       m_generator(rseed),
00010       m_real_distribution(0.0, 1.0),
00011       m_stepsize(stepsize),
00012       m_count(0)
00013 {
00014     #ifdef DEBUG
00015         std::cout<<"seed TakeStep:"<<_seed<< "\n";
00016     #endif
00017 }
00018 
00019 /*RandomCoordsDisplacementAll*/
00020 
00021 RandomCoordsDisplacementAll::RandomCoordsDisplacementAll(const size_t rseed, const double stepsize)
00022     : RandomCoordsDisplacement(rseed, stepsize){}
00023 
00024 void RandomCoordsDisplacementAll::displace(pele::Array<double>& coords, MC* mc)
00025 {
00026     for (size_t i = 0; i < coords.size(); ++i) {
00027         double rand = m_real_distribution(m_generator);
00028         coords[i] += (0.5 - rand) * m_stepsize;
00029     }
00030     ++m_count;
00031 }
00032 
00033 /*RandomCoordsDisplacementSingle*/
00034 
00035 RandomCoordsDisplacementSingle::RandomCoordsDisplacementSingle(const size_t rseed, const size_t nparticles, const size_t ndim, const double stepsize)
00036     : RandomCoordsDisplacement(rseed, stepsize),
00037       m_nparticles(nparticles),
00038       m_ndim(ndim),
00039       m_rand_particle(0),
00040       m_int_distribution(0, m_nparticles-1){}
00041 
00042 void RandomCoordsDisplacementSingle::displace(pele::Array<double>& coords, MC* mc)
00043 {
00044     m_rand_particle = m_int_distribution(m_generator);
00045     size_t rand_particle_dof = m_rand_particle * m_ndim;
00046     for (size_t i = rand_particle_dof; i < rand_particle_dof + m_ndim; ++i) {
00047         double rand = m_real_distribution(m_generator);
00048         coords[i] += (0.5 - rand) * m_stepsize;
00049     }
00050     ++m_count;
00051 }
00052 
00053 } // namespace mcpele
 All Classes Namespaces Functions Variables Typedefs