00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_DAMPING_H 00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_DAMPING_H 00003 // 00004 // OpenTissue, A toolbox for physical based simulation and animation. 00005 // Copyright (C) 2007 Department of Computer Science, University of Copenhagen 00006 // 00007 #include <OpenTissue/configuration.h> 00008 00009 #include <OpenTissue/dynamics/mbd/interfaces/mbd_force_interface.h> 00010 00011 #include <boost/cast.hpp> // needed for boost::numeric_cast 00012 00013 namespace OpenTissue 00014 { 00015 namespace mbd 00016 { 00017 00018 template<typename mbd_types> 00019 class Damping 00020 : public ForceInterface<mbd_types> 00021 { 00022 public: 00023 00024 typedef typename mbd_types::body_type body_type; 00025 typedef typename mbd_types::math_policy::real_type real_type; 00026 typedef typename mbd_types::math_policy::vector3_type vector3_type; 00027 00028 protected: 00029 00030 real_type m_linear_viscosity; 00031 real_type m_angular_viscosity; 00032 00033 public: 00034 00035 Damping() 00036 : m_linear_viscosity(boost::numeric_cast<real_type>( .001) ) 00037 , m_angular_viscosity(boost::numeric_cast<real_type>( .001 ) ) 00038 {} 00039 00040 virtual ~Damping(){} 00041 00042 public: 00043 00051 void compute(body_type const & body,vector3_type & force,vector3_type & torque) 00052 { 00053 if(body.is_fixed()) 00054 { 00055 force.clear(); 00056 torque.clear(); 00057 } 00058 else 00059 { 00060 vector3_type V,W; 00061 body.get_velocity(V); 00062 body.get_spin(W); 00063 force = -V*m_linear_viscosity; 00064 torque = -W*m_angular_viscosity; 00065 } 00066 } 00067 00073 void set_linear_viscosity(real_type const & viscosity) 00074 { 00075 assert(viscosity>=0 || !"Damping::set_linear_viscosity(): value must be non-negative"); 00076 m_linear_viscosity = viscosity; 00077 } 00078 00084 void set_angular_viscosity(real_type const & viscosity) 00085 { 00086 assert(viscosity>=0 || !"Damping::set_angular_viscosity(): value must be non-negative"); 00087 m_angular_viscosity = viscosity; 00088 } 00089 00095 real_type const & get_linear_viscosity() const { return m_linear_viscosity; } 00096 00102 real_type const & get_angular_viscosity() const { return m_angular_viscosity; } 00103 00104 }; 00105 00106 } // namespace mbd 00107 } // namespace OpenTissue 00108 // OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_DAMPING_H 00109 #endif