00001 #ifndef OPENTISSUE_DYNAMICS_EDM_FORCES_EDM_SPRING_H 00002 #define OPENTISSUE_DYNAMICS_EDM_FORCES_EDM_SPRING_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 00015 namespace edm 00016 { 00017 00018 template<typename edm_types> 00019 class Spring 00020 : public edm_types::force_type 00021 { 00022 public: 00023 00024 typedef typename edm_types::force_type base_type; 00025 typedef typename edm_types::value_traits value_traits; 00026 typedef typename edm_types::real_type real_type; 00027 typedef typename edm_types::vector3_type vector3_type; 00028 typedef typename edm_types::Particle particle_type; 00029 00030 private: 00031 00032 real_type m_k; 00033 vector3_type m_r0; 00034 00035 public: 00036 00037 Spring() 00038 : base_type() 00039 , m_k(value_traits::zero()) 00040 , m_r0(value_traits::zero()) 00041 {} 00042 00043 virtual ~Spring() {} 00044 00045 void set(real_type const & k, vector3_type const & r0) 00046 { 00047 m_k = k; 00048 m_r0 = r0; 00049 } 00050 00051 private: 00052 00053 vector3_type apply(particle_type const & a) const 00054 { 00055 return vector3_type(m_k*(m_r0-a.r)); 00056 } 00057 00058 }; 00059 00060 } // namespace edm 00061 00062 } // namespace OpenTissue 00063 00064 // OPENTISSUE_DYNAMICS_EDM_FORCES_EDM_SPRING_H 00065 #endif