00001 #ifndef OPENTISSUE_DYNAMICS_SPH_INTEGRATORS_SPH_VERLET_H 00002 #define OPENTISSUE_DYNAMICS_SPH_INTEGRATORS_SPH_VERLET_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/dynamics/sph/sph_integrator.h> 00013 00014 namespace OpenTissue 00015 { 00016 namespace sph 00017 { 00018 00022 template< typename Types > 00023 class Verlet : public Integrator<Types> 00024 { 00025 public: 00026 typedef Integrator<Types> base_type; 00027 typedef typename Types::real_type real_type; 00028 typedef typename Types::vector vector; 00029 typedef typename Types::particle particle; 00030 typedef typename Types::particle_container particle_container; 00031 typedef typename base_type::collision_detection collision_detection; 00032 public: 00036 Verlet(const real_type& timestep, const real_type& restitution) 00037 : base_type(timestep, restitution) 00038 {} 00039 00043 ~Verlet() 00044 {} 00045 00049 Verlet& operator=(Verlet const &) { return *this; } 00050 00051 private: 00052 00058 void integrate(particle& par) const 00059 { 00060 vector &x = par.position(); 00061 vector &ox = par.position_old(); 00062 const vector bak = x; 00063 00064 const vector &a = par.force()/par.density(); 00065 00066 // move particle 00067 x += 0.98*(x-ox)+a*base_type::m_dt2; 00068 ox = bak; 00069 00070 // COLLISION TEST 00071 if (base_type::m_colisys) { 00072 typename collision_detection::collision_type coli; 00073 if (base_type::m_colisys->collision(coli, par)) { 00074 00075 //vector proj(coli.normal()*coli.penetration()); 00076 00077 // project particle out from obstacle and reflect the velocity 00078 //x += proj; 00079 //ox -= (1+m_r)*proj; 00080 x = coli.contact(); 00081 ox -= (1+base_type::m_r)*((x-ox)*coli.normal())*coli.normal(); 00082 //ox -= ((x-ox)*coli.normal()+base_type::m_r)*coli.normal(); 00083 //ox = x; 00084 //ox = x-m_r*coli.normal(); 00085 } 00086 } 00087 00088 // calculate velocity 00089 par.velocity() = 0.98*base_type::m_invdt*(x-ox); 00090 } 00091 00092 }; // End class Verlet 00093 00094 } // namespace sph 00095 } // namespace OpenTissue 00096 00097 // OPENTISSUE_DYNAMICS_SPH_INTEGRATORS_SPH_VERLET_H 00098 #endif