Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_INTEGRATOR_POLICIES_PSYS_EULER_INTEGRATOR_H
00002 #define OPENTISSUE_DYNAMICS_PSYS_INTEGRATOR_POLICIES_PSYS_EULER_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 EulerIntegrator
00019 {
00020 public:
00021
00022 template<typename particle_system_type>
00023 void integrate(particle_system_type & system, double timestep)
00024 {
00025 typedef typename particle_system_type::real_type real_type;
00026 typedef typename particle_system_type::vector3_type vector3_type;
00027 typedef typename particle_system_type::particle_iterator particle_iterator;
00028
00029 system.compute_forces();
00030 system.compute_accelerations();
00031
00032 real_type dt = boost::numeric_cast < real_type > ( timestep );
00033
00034 particle_iterator p = system.particle_begin();
00035 particle_iterator end = system.particle_end();
00036 for(;p!=end;++p)
00037 {
00038 vector3_type r_cur = p->position();
00039 p->old_position() = r_cur;
00040 vector3_type v_cur = p->velocity();
00041 vector3_type a_cur = p->acceleration();
00042
00043 r_cur += v_cur*dt;
00044 v_cur += a_cur*dt;
00045
00046 p->position() = r_cur;
00047 p->velocity() = v_cur;
00048 }
00049 }
00050
00051 };
00052
00053 }
00054 }
00055
00056
00057 #endif