00001 #ifndef OPENTISSUE_DYNAMICS_SPH_KERNELS_SPH_POLY6_H 00002 #define OPENTISSUE_DYNAMICS_SPH_KERNELS_SPH_POLY6_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_kernel.h> 00013 #include <OpenTissue/core/math/math_constants.h> 00014 00015 namespace OpenTissue 00016 { 00017 namespace sph 00018 { 00019 00026 template< typename Types, 00027 struct OpenTissue::utility::RuntimeType<typename Types::real_type>* Radius, 00028 bool CheckRange > 00029 class WPoly6 : public FixedSmoothingKernel<Types, CheckRange> 00030 { 00031 public: 00032 typedef FixedSmoothingKernel<Types, CheckRange> base_type; 00033 typedef typename Types::real_type real_type; 00034 typedef typename Types::vector vector; 00035 public: 00039 WPoly6() : base_type(*Radius) 00040 { 00041 m_k = 315./(64.*math::detail::pi<real_type>()*pow(base_type::m_radius, 9)); 00042 m_l = -945./(32.*math::detail::pi<real_type>()*pow(base_type::m_radius, 9)); 00043 m_m = -945./(32.*math::detail::pi<real_type>()*pow(base_type::m_radius, 9)); 00044 } 00045 00046 public: 00047 00052 real_type evaluate(const vector& r) const 00053 { 00054 if (!checkRange(r)) 00055 return 0.; 00056 register real_type res = base_type::m_radiusSqr-r*r; 00057 res *= res*res*m_k; 00058 return res; 00059 } 00060 00065 vector gradient(const vector& r) const 00066 { 00067 if (!checkRange(r)) 00068 return vector(0); 00069 register real_type tmp = base_type::m_radiusSqr-r*r; 00070 tmp *= tmp*m_l; 00071 return vector(tmp*r); 00072 } 00073 00078 real_type laplacian(const vector& r) const 00079 { 00080 if (!checkRange(r)) 00081 return 0.; 00082 const real_type tmp = r*r; 00083 register real_type res = (base_type::m_radiusSqr-tmp)*(3*base_type::m_radiusSqr-7*tmp); 00084 res *= m_m; 00085 return res; 00086 } 00087 00088 protected: 00089 real_type m_k; 00090 real_type m_l; 00091 real_type m_m; 00092 00093 }; // End class WPoly6 00094 00095 } // namespace sph 00096 } // namespace OpenTissue 00097 00098 // OPENTISSUE_DYNAMICS_SPH_KERNELS_SPH_POLY6_H 00099 #endif