00001 #ifndef OPENTISSUE_DYNAMICS_SPH_SPH_KERNEL_H 00002 #define OPENTISSUE_DYNAMICS_SPH_SPH_KERNEL_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 00021 template< typename Types > 00022 class SmoothingKernel 00023 { 00024 public: 00025 typedef typename Types::real_type real_type; 00026 typedef typename Types::vector vector; 00027 00028 public: 00032 SmoothingKernel() 00033 { 00034 } 00035 00039 virtual ~SmoothingKernel() 00040 { 00041 } 00042 00043 public: 00044 00052 virtual real_type evaluate(const vector& r, const real_type& h) const = 0; 00053 00061 virtual vector gradient(const vector& r, const real_type& h) const = 0; 00062 00070 virtual real_type laplacian(const vector& r, const real_type& h) const = 0; 00071 00072 protected: 00080 bool checkRange(const vector& r, const real_type& h) const 00081 { 00082 return h*h >= r*r; 00083 } 00084 00085 }; // End class SmoothingKernel 00086 00087 00092 template< typename Types, bool CheckRange > 00093 class FixedSmoothingKernel 00094 { 00095 public: 00096 typedef SmoothingKernel<Types> Base; 00097 typedef typename Types::real_type real_type; 00098 typedef typename Types::vector vector; 00099 00100 public: 00104 FixedSmoothingKernel(const real_type& radius) : m_radius(radius), m_radiusSqr(radius*radius) 00105 { 00106 } 00107 00111 virtual ~FixedSmoothingKernel() 00112 { 00113 } 00114 00115 public: 00116 00122 const real_type& radius() const 00123 { 00124 return m_radius; 00125 } 00126 00133 virtual real_type evaluate(const vector& r) const = 0; 00134 00141 virtual vector gradient(const vector& r) const = 0; 00142 00149 virtual real_type laplacian(const vector& r) const = 0; 00150 00151 // protected: 00152 public: 00159 bool checkRange(const vector& r) const 00160 { 00161 if (!CheckRange) return true; //--- ToDo KE 2006-01-21: DAmn it, use partial specialization for such things:-) 00162 return m_radiusSqr >= r*r; 00163 } 00164 00165 protected: 00166 real_type m_radius; 00167 real_type m_radiusSqr; 00168 00169 }; // End class SmoothingKernel 00170 00171 00172 } // namespace sph 00173 } // namespace OpenTissue 00174 00175 // OPENTISSUE_DYNAMICS_SPH_SPH_KERNEL_H 00176 #endif