00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_FORCE_PSYS_VISCOSITY_H 00002 #define OPENTISSUE_DYNAMICS_PSYS_FORCE_PSYS_VISCOSITY_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 psys 00015 { 00016 00017 template<typename types> 00018 class Viscosity 00019 : public types::force_type 00020 { 00021 public: 00022 00023 typedef typename types::math_types math_types; 00024 typedef typename math_types::real_type real_type; 00025 typedef typename math_types::vector3_type vector3_type; 00026 typedef typename types::system_type system_type; 00027 00028 protected: 00029 00030 real_type m_viscosity; 00031 00032 public: 00033 00034 real_type & viscosity() { return m_viscosity; } 00035 real_type const & viscosity() const { return m_viscosity; } 00036 00037 public: 00038 00039 Viscosity() 00040 : m_viscosity(9.81) 00041 {} 00042 00043 ~Viscosity(){} 00044 00045 public: 00046 00047 void apply() 00048 { 00049 typedef typename system_type::particle_iterator particle_iterator; 00050 using std::fabs; 00051 00052 if(!(fabs(m_viscosity) > 0)) 00053 return; 00054 00055 particle_iterator p = this->owner()->particle_begin(); 00056 particle_iterator end = this->owner()->particle_end(); 00057 00058 for(;p!=end;++p) 00059 { 00060 if( p->inv_mass() <= 0 ) 00061 continue; 00062 p->force() -= p->velocity()*m_viscosity; 00063 } 00064 } 00065 00066 }; 00067 00068 } // namespace psys 00069 } // namespace OpenTissue 00070 00071 // OPENTISSUE_DYNAMICS_PSYS_FORCE_PSYS_VISCOSITY_H 00072 #endif