| Home | Libraries | People | FAQ | More

## Class template velocity_verlet

boost::numeric::odeint::velocity_verlet — The Velocity-Verlet algorithm.

## Synopsis

    // In header: <boost/numeric/odeint/stepper/velocity_verlet.hpp>

    template<typename Coor, typename Velocity = Coor, typename Value = double,
             typename Acceleration = Coor, typename Time = Value,
             typename TimeSq = Time,
             typename Algebra = typename algebra_dispatcher< Coor >::algebra_type,
             typename Operations = typename operations_dispatcher< Coor >::operations_type,
             typename Resizer = initially_resizer>
    class velocity_verlet : public algebra_stepper_base< Algebra, Operations > {
    public:
      // types
      typedef algebra_stepper_base< Algebra, Operations >   algebra_stepper_base_type;
      typedef algebra_stepper_base_type::algebra_type       algebra_type;
      typedef algebra_stepper_base_type::operations_type    operations_type;
      typedef Coor                                          coor_type;
      typedef Velocity                                      velocity_type;
      typedef Acceleration                                  acceleration_type;
      typedef std::pair< coor_type, velocity_type >         state_type;
      typedef std::pair< velocity_type, acceleration_type > deriv_type;
      typedef state_wrapper< acceleration_type >            wrapped_acceleration_type;
      typedef Value                                         value_type;
      typedef Time                                          time_type;
      typedef TimeSq                                        time_square_type;
      typedef Resizer                                       resizer_type;
      typedef stepper_tag                                   stepper_category;
      typedef unsigned short                                order_type;

      // construct/copy/destruct
      velocity_verlet(const algebra_type & = algebra_type());

      // public member functions
      order_type order(void) const;
      template<typename System, typename StateInOut>
        void do_step(System, StateInOut &, time_type, time_type);
      template<typename System, typename StateInOut>
        void do_step(System, const StateInOut &, time_type, time_type);
      template<typename System, typename CoorIn, typename VelocityIn,
               typename AccelerationIn, typename CoorOut, typename VelocityOut,
               typename AccelerationOut>
        void do_step(System, CoorIn const &, VelocityIn const &,
                     AccelerationIn const &, CoorOut &, VelocityOut &,
                     AccelerationOut &, time_type, time_type);
      template<typename StateIn> void adjust_size(const StateIn &);
      void reset(void);
      template<typename AccelerationIn> void initialize(const AccelerationIn &);
      template<typename System, typename CoorIn, typename VelocityIn>
        void initialize(System, const CoorIn &, const VelocityIn &, time_type);
      bool is_initialized(void) const;

      // private member functions
      template<typename System, typename CoorIn, typename VelocityIn>
        void initialize_acc(System, const CoorIn &, const VelocityIn &, time_type);
      template<typename System, typename StateInOut>
        void do_step_v1(System, StateInOut &, time_type, time_type);
      template<typename StateIn> bool resize_impl(const StateIn &);
      acceleration_type & get_current_acc(void);
      const acceleration_type & get_current_acc(void) const;
      acceleration_type & get_old_acc(void);
      const acceleration_type & get_old_acc(void) const;
      void toggle_current_acc(void);

      // public data members
      static const order_type order_value;
    };

## Description

The Velocity-Verlet algorithm is a method for simulation of molecular dynamics systems. It solves the ODE a=f(r,v',t) where r are the coordinates, v are the velocities and a are the accelerations, hence v = dr/dt, a=dv/dt.

### Template Parameters

1.     typename Coor

   The type representing the coordinates.

2.     typename Velocity = Coor

   The type representing the velocities.

3.     typename Value = double

   The type value type.

4.     typename Acceleration = Coor

   The type representing the acceleration.

5.     typename Time = Value

   The time representing the independent variable - the time.

6.     typename TimeSq = Time

   The time representing the square of the time.

7.     typename Algebra = typename algebra_dispatcher< Coor >::algebra_type

   The algebra.

8.     typename Operations = typename operations_dispatcher< Coor >::operations_type

   The operations type.

9.     typename Resizer = initially_resizer

   The resizer policy type.

### `velocity_verlet` public construct/copy/destruct

1.     velocity_verlet(const algebra_type & algebra = algebra_type());

   Constructs the `velocity_verlet` class. This constructor can be used as a default constructor if the algebra has a default constructor.

   Parameters:

   `algebra` | A copy of algebra is made and stored.

### `velocity_verlet` public member functions

1.     order_type order(void) const;

   Returns: | Returns the order of the stepper.

2.     template<typename System, typename StateInOut>
         void do_step(System system, StateInOut & x, time_type t, time_type dt);

   This method performs one step. It transforms the result in-place.

   It can be used like

       pair< coordinates , velocities > state;
       stepper.do_step( sys , x , t , dt );

   Parameters:

   `dt` | The step size.
   `system` | The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the Second Order System concept.
   `t` | The value of the time, at which the step should be performed.
   `x` | The state of the ODE which should be solved. The state is pair of Coor and Velocity.

3.     template<typename System, typename StateInOut>
         void do_step(System system, const StateInOut & x, time_type t, time_type dt);

   This method performs one step. It transforms the result in-place.

   It can be used like

       pair< coordinates , velocities > state;
       stepper.do_step( sys , x , t , dt );

   Parameters:

   `dt` | The step size.
   `system` | The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the Second Order System concept.
   `t` | The value of the time, at which the step should be performed.
   `x` | The state of the ODE which should be solved. The state is pair of Coor and Velocity.

4.     template<typename System, typename CoorIn, typename VelocityIn,
                typename AccelerationIn, typename CoorOut, typename VelocityOut,
                typename AccelerationOut>
         void do_step(System system, CoorIn const & qin, VelocityIn const & pin,
                      AccelerationIn const & ain, CoorOut & qout,
                      VelocityOut & pout, AccelerationOut & aout, time_type t,
                      time_type dt);

   This method performs one step. It transforms the result in-place. Additionally to the other methods the coordinates, velocities and accelerations are passed directly to do_step and they are transformed out-of-place.

   It can be used like

       coordinates qin , qout;
       velocities pin , pout;
       accelerations ain, aout;
       stepper.do_step( sys , qin , pin , ain , qout , pout , aout , t , dt );

   Parameters:

   `dt` | The step size.
   `system` | The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the Second Order System concept.
   `t` | The value of the time, at which the step should be performed.

5.     template<typename StateIn> void adjust_size(const StateIn & x);

   Adjust the size of all temporaries in the stepper manually.

   Parameters:

   `x` | A state from which the size of the temporaries to be resized is deduced.

6.     void reset(void);

   Resets the internal state of this stepper. After calling this method it is safe to use all `do_step` method without explicitly initializing the stepper.

7.     template<typename AccelerationIn> void initialize(const AccelerationIn & ain);

   Initializes the internal state of the stepper.

8.     template<typename System, typename CoorIn, typename VelocityIn>
         void initialize(System system, const CoorIn & qin, const VelocityIn & pin,
                         time_type t);

   Initializes the internal state of the stepper.

   This method is equivalent to

       Acceleration a;
       system( qin , pin , a , t );
       stepper.initialize( a );

   Parameters:

   `pin` | The current velocities of the ODE.
   `qin` | The current coordinates of the ODE.
   `system` | The system function for the next calls of `do_step`.
   `t` | The current time of the ODE.

9.     bool is_initialized(void) const;

   Returns: | Returns if the stepper is initialized.

### `velocity_verlet` private member functions

1.     template<typename System, typename CoorIn, typename VelocityIn>
         void initialize_acc(System system, const CoorIn & qin,
                             const VelocityIn & pin, time_type t);

2.     template<typename System, typename StateInOut>
         void do_step_v1(System system, StateInOut & x, time_type t, time_type dt);

3.     template<typename StateIn> bool resize_impl(const StateIn & x);

4.     acceleration_type & get_current_acc(void);

5.     const acceleration_type & get_current_acc(void) const;

6.     acceleration_type & get_old_acc(void);

7.     const acceleration_type & get_old_acc(void) const;

8.     void toggle_current_acc(void);