00001 #ifndef OPENTISSUE_DYNAMICS_SPH_INTEGRATORS_SPH_EULER_H 00002 #define OPENTISSUE_DYNAMICS_SPH_INTEGRATORS_SPH_EULER_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 Euler : 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 Types::collision_detection collision_detection; 00032 00033 public: 00037 Euler(const real_type& timestep, const real_type& restitution) 00038 : base_type(timestep, restitution) 00039 {} 00040 00044 ~Euler() 00045 {} 00046 00047 public: 00048 00054 void integrate(particle& par) const 00055 { 00056 const vector &a = par.force()/par.density(); 00057 vector &x = par.position(); 00058 vector &v = par.velocity(); 00059 00060 // advance velocity 00061 v += a*base_type::m_dt; 00062 00063 // move particle (semi-implicit, as v is at time n+1) 00064 x += v*base_type::m_dt; 00065 00066 // COLLISION TEST 00067 if (base_type::m_colisys) { 00068 typename collision_detection::collision_type coli; 00069 if (base_type::m_colisys->collision(coli, par)) { 00070 x = coli.contact(); 00071 const real_type r = base_type::m_r>0?base_type::m_r*coli.penetration()/(base_type::m_dt*(length(v))):0; 00072 v -= (1+r)*(v*coli.normal())*coli.normal(); 00073 //const real_type l = base_type::m_dt*(length(v)); 00074 //v -= (1.+(l>0?(base_type::m_r*coli.penetration()/l):0))*(v*coli.normal())*coli.normal(); 00075 //v -= (1+base_type::m_r)*(v*coli.normal())*coli.normal(); 00076 } 00077 } 00078 } 00079 00080 }; // End class Euler 00081 00082 } // namespace sph 00083 } // namespace OpenTissue 00084 00085 // OPENTISSUE_DYNAMICS_SPH_INTEGRATORS_SPH_EULER_H 00086 #endif