00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_DRIVING_FORCE_H 00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_DRIVING_FORCE_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 namespace OpenTissue 00012 { 00013 namespace mbd 00014 { 00030 template<typename mbd_types> 00031 class DrivingForce 00032 : public ForceInterface<mbd_types> 00033 { 00034 public: 00035 00036 typedef typename mbd_types::body_type body_type; 00037 typedef typename mbd_types::math_policy::vector3_type vector3_type; 00038 typedef typename mbd_types::math_policy::real_type real_type; 00039 typedef typename mbd_types::math_policy::value_traits value_traits; 00040 00041 protected: 00042 00043 vector3_type m_G; 00044 real_type m_frequency; 00045 real_type m_phase; 00046 real_type m_time; 00047 00048 public: 00049 00050 DrivingForce() 00051 : m_G(value_traits::zero(),9.81,value_traits::zero()) 00052 , m_frequency(value_traits::two()*value_traits::pi()) 00053 , m_phase(value_traits::zero()) 00054 , m_time(value_traits::zero()) 00055 {} 00056 00057 virtual ~DrivingForce(){} 00058 00059 public: 00060 00061 void compute(body_type const & body,vector3_type & force,vector3_type & torque) 00062 { 00063 using std::cos; 00064 00065 torque.clear(); 00066 if(body.is_fixed()) 00067 { 00068 force.clear(); 00069 return; 00070 } 00071 force = body.get_mass() * m_G * cos(m_frequency*m_time + m_phase); 00072 } 00073 00080 void set_global_simulation_time(real_type const & time){ m_time = time; } 00081 00082 }; 00083 00084 } // namespace mbd 00085 } // namespace OpenTissue 00086 // OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_DRIVING_FORCE_H 00087 #endif