00001 #ifndef OPENTISSUE_DYNAMICS_SPH_SPH_INTEGRATOR_H 00002 #define OPENTISSUE_DYNAMICS_SPH_SPH_INTEGRATOR_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 namespace OpenTissue 00013 { 00014 namespace sph 00015 { 00016 00020 template< typename Types > 00021 class Integrator 00022 { 00023 public: 00024 typedef typename Types::real_type real_type; 00025 typedef typename Types::vector vector; 00026 typedef typename Types::particle particle; 00027 typedef typename Types::particle_container particle_container; 00028 typedef typename Types::collision_detection collision_detection; 00029 00030 public: 00034 Integrator(const real_type& timestep = 0.01, const real_type& restitution = 0.) 00035 : m_dt(timestep) 00036 , m_dt2(timestep*timestep) 00037 , m_invdt(1./timestep) 00038 , m_invdt2(1./(timestep*timestep)) 00039 , m_r(restitution) 00040 , m_colisys(NULL) 00041 { 00042 } 00043 00047 virtual ~Integrator() 00048 { 00049 } 00050 00051 public: 00057 void setCollisionSystem(collision_detection* colisys) 00058 { 00059 m_colisys = colisys; 00060 } 00061 00067 void initialize_particles(typename particle_container::iterator begin, typename particle_container::iterator end) const 00068 { 00069 for (typename particle_container::iterator par = begin; par != end; ++par) 00070 initialize(*par); 00071 } 00072 00078 void integrate_particles(typename particle_container::iterator begin, typename particle_container::iterator end) const 00079 { 00080 for (typename particle_container::iterator par = begin; par != end; ++par) { 00081 particle& p = *par; 00082 if (!p.fixed()) 00083 integrate(p); 00084 } 00085 } 00086 00087 virtual void initialize(particle& /*par*/) const {} 00088 00089 virtual void integrate(particle& par) const = 0; 00090 00091 protected: 00092 real_type m_dt; 00093 real_type m_dt2; 00094 real_type m_invdt; 00095 real_type m_invdt2; 00096 real_type m_r; 00097 00098 collision_detection* m_colisys; 00099 00100 }; // End class Integrator 00101 00102 } // namespace sph 00103 } // namespace OpenTissue 00104 00105 // OPENTISSUE_DYNAMICS_SPH_SPH_INTEGRATOR_H 00106 #endif