Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_INTEGRATOR_POLICIES_PSYS_VERLET_INTEGRATOR_H
00002 #define OPENTISSUE_DYNAMICS_PSYS_INTEGRATOR_POLICIES_PSYS_VERLET_INTEGRATOR_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014
00015 namespace psys
00016 {
00017
00018 class VerletIntegrator
00019 {
00020 public:
00021
00022 template<typename particle_system_type>
00023 void integrate(particle_system_type & system, double timestep)
00024 {
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 typedef typename particle_system_type::real_type real_type;
00053 typedef typename particle_system_type::vector3_type vector3_type;
00054 typedef typename particle_system_type::particle_iterator particle_iterator;
00055
00056 system.compute_forces();
00057 system.compute_accelerations();
00058
00059 static real_type zero = boost::numeric_cast<real_type>(0.0);
00060 static real_type one = boost::numeric_cast<real_type>(1.0);
00061 real_type dt = boost::numeric_cast < real_type > ( timestep );
00062 real_type inv_dt = dt > zero ? one/dt : one;
00063 real_type dt_sqr = dt*dt;
00064
00065 particle_iterator p = system.particle_begin();
00066 particle_iterator end = system.particle_end();
00067 for(;p!=end;++p)
00068 {
00069 vector3_type r_cur = p->position();
00070 vector3_type r_old = p->old_position();
00071 p->old_position() = r_cur;
00072 vector3_type a_cur = p->acceleration();
00073
00074 r_cur += r_cur - r_old + a_cur*dt_sqr;
00075 p->position() = r_cur;
00076
00077 vector3_type v_cur = (r_cur - r_old)*(.5*inv_dt);
00078 p->velocity() = v_cur;
00079 }
00080 }
00081
00082 };
00083
00084 }
00085 }
00086
00087
00088 #endif