00001 #ifndef OPENTISSUE_DYNAMICS_SPH_SPH_PARTICLE_H 00002 #define OPENTISSUE_DYNAMICS_SPH_SPH_PARTICLE_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/utility/utility_runtime_type.h> 00013 00014 namespace OpenTissue 00015 { 00016 namespace sph 00017 { 00018 00025 template< 00026 typename real_ 00027 , template<typename> class Vector 00028 , struct OpenTissue::utility::RuntimeType<real_> * Radius 00029 > 00030 class Particle 00031 { 00032 public: 00033 typedef real_ real_type; 00034 typedef Vector<real_type> vector; 00035 typedef vector point_type; 00036 00037 public: 00038 Particle() 00039 : m_radius(*Radius) 00040 , m_radiusSqr(*Radius**Radius) 00041 , m_m(1) 00042 , m_r(1) 00043 , m_p(0) 00044 , m_fixed(false) 00045 {} 00046 00047 virtual ~Particle() 00048 {} 00049 00050 public: 00051 00055 point_type min() const 00056 { 00057 return point_type(m_x - point_type(m_radius)); 00058 // return m_x-m_radius; 00059 } 00060 00064 point_type max() const 00065 { 00066 return point_type(m_x+point_type(m_radius)); 00067 // return m_x+m_radius; 00068 } 00069 00073 bool check(const point_type& candidate) const 00074 { 00075 return m_radiusSqr >= sqr_length(point_type(m_x-candidate)); 00076 // point_type diff(m_x-candidate); 00077 // return m_radiusSqr >= diff*diff; 00078 // return m_radiusSqr >= (m_x[0]-candidate[0])*(m_x[0]-candidate[0])+(m_x[1]-candidate[1])*(m_x[1]-candidate[1])+(m_x[2]-candidate[2])*(m_x[2]-candidate[2]); 00079 } 00080 00086 const point_type& position() const 00087 { 00088 return m_x; 00089 } 00090 00096 point_type& position() 00097 { 00098 return m_x; 00099 } 00100 00106 const point_type& position_old() const 00107 { 00108 return m_o; 00109 } 00110 00116 point_type& position_old() 00117 { 00118 return m_o; 00119 } 00120 00126 const vector &velocity() const 00127 { 00128 return m_v; 00129 } 00130 00136 vector &velocity() 00137 { 00138 return m_v; 00139 } 00140 00146 const vector &acceleration() const 00147 { 00148 return m_a; 00149 } 00150 00156 vector &acceleration() 00157 { 00158 return m_a; 00159 } 00160 00166 const vector &force() const 00167 { 00168 return m_f; 00169 } 00170 00176 vector &force() 00177 { 00178 return m_f; 00179 } 00180 00186 const real_type &mass() const 00187 { 00188 return m_m; 00189 } 00190 00196 real_type &mass() 00197 { 00198 return m_m; 00199 } 00200 00206 const real_type &density() const 00207 { 00208 return m_r; 00209 } 00210 00216 real_type &density() 00217 { 00218 return m_r; 00219 } 00220 00226 const real_type &pressure() const 00227 { 00228 return m_p; 00229 } 00230 00236 real_type &pressure() 00237 { 00238 return m_p; 00239 } 00240 00246 const vector &normal() const 00247 { 00248 return m_n; 00249 } 00250 00256 vector &normal() 00257 { 00258 return m_n; 00259 } 00260 00266 const bool &fixed() const 00267 { 00268 return m_fixed; 00269 } 00270 00276 bool &fixed() 00277 { 00278 return m_fixed; 00279 } 00280 00286 const real_type &radius() const 00287 { 00288 return m_radius; 00289 } 00290 00291 protected: 00292 //point_type m_radius; ///< Radius point 00293 real_type m_radius; 00294 real_type m_radiusSqr; 00295 point_type m_x; 00296 point_type m_o; 00297 vector m_v; 00298 vector m_a; 00299 vector m_f; 00300 vector m_n; 00301 real_type m_m; 00302 real_type m_r; 00303 real_type m_p; 00304 bool m_fixed; 00305 00306 }; // End class Particle 00307 00308 } // namespace sph 00309 } // namespace OpenTissue 00310 00311 // OPENTISSUE_DYNAMICS_SPH_SPH_PARTICLE_H 00312 #endif