/* [auto_generated] libs/numeric/odeint/examples/molecular_dynamics.cpp [begin_description] Molecular dynamics example. [end_description] Copyright 2009-2012 Karsten Ahnert Copyright 2009-2012 Mario Mulansky Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #include #include #include #include using namespace boost::numeric::odeint; using namespace std; #define tab "\t" const size_t n1 = 16; const size_t n2 = 16; struct md_system { static const size_t n = n1 * n2; typedef std::vector< double > vector_type; md_system( double a = 0.0 , // strength of harmonic oscillator double gamma = 0.0 , // friction double eps = 0.1 , // interaction strenght double sigma = 1.0 , // interaction radius double xmax = 150.0 , double ymax = 150.0 ) : m_a( a ) , m_gamma( gamma ) , m_eps( eps ) , m_sigma( sigma ) , m_xmax( xmax ) , m_ymax( ymax ) { } static void init_vector_type( vector_type &x ) { x.resize( 2 * n ); } void operator()( vector_type const& x , vector_type const& v , vector_type &a , double t ) const { for( size_t i=0 ; i xmax ) ? x - xmax : x ; } double m_a; double m_gamma; double m_eps ; double m_sigma ; double m_xmax , m_ymax; }; int main( int argc , char *argv[] ) { const size_t n = md_system::n; typedef md_system::vector_type vector_type; std::mt19937 rng; std::normal_distribution<> dist( 0.0 , 1.0 ); vector_type x , v; md_system::init_vector_type( x ); md_system::init_vector_type( v ); for( size_t i=0 ; i stepper; const double dt = 0.025; double t = 0.0; md_system sys; for( size_t oi=0 ; oi<100000 ; ++oi ) { for( size_t ii=0 ; ii<100 ; ++ii,t+=dt ) stepper.do_step( sys , std::make_pair( std::ref( x ) , std::ref( v ) ) , t , dt ); sys.bc( x ); std::cout << "set size square" << "\n"; std::cout << "unset key" << "\n"; std::cout << "p [0:" << sys.m_xmax << "][0:" << sys.m_ymax << "] '-' pt 7 ps 0.5" << "\n"; for( size_t i=0 ; i