00001 #ifndef OPENTISSUE_DYNAMICS_MBD_INTERFACES_MBD_CORE_CONSTRAINT_INTERFACE_H 00002 #define OPENTISSUE_DYNAMICS_MBD_INTERFACES_MBD_CORE_CONSTRAINT_INTERFACE_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 mbd 00015 { 00016 template< typename mbd_types > 00017 class CoreConstraintInterface 00018 : public mbd_types::constraint_traits 00019 { 00020 public: 00021 00022 typedef typename mbd_types::math_policy::index_type size_type; 00023 typedef typename mbd_types::math_policy::real_type real_type; 00024 typedef typename mbd_types::math_policy::value_traits value_traits; 00025 00026 protected: 00027 00028 real_type m_erp; 00029 real_type m_fps; 00030 bool m_active; 00031 bool m_use_erp; 00032 00033 public: 00034 00035 CoreConstraintInterface() 00036 : m_erp(value_traits::zero()) 00037 , m_fps(value_traits::zero()) 00038 , m_active(true) 00039 , m_use_erp(true) 00040 {} 00041 00042 virtual ~CoreConstraintInterface(){}; 00043 00044 public: 00045 00051 void set_frames_per_second(real_type const & fps) 00052 { 00053 assert(fps>=0 || !"CoreConstraintInterface::set_frames_per_second(): fps must be non-negative"); 00054 m_fps = fps; 00055 } 00056 00062 real_type const & get_frames_per_second( )const { return m_fps; } 00063 00069 void set_error_reduction_parameter(real_type const & erp) 00070 { 00071 assert( ( erp>=value_traits::zero() && erp<=value_traits::one() ) || !"CoreConstraintInterface::set_frames_per_second(): erp must be in [0..1]"); 00072 m_erp = erp; 00073 } 00074 00080 virtual real_type get_error_reduction_parameter() const 00081 { 00082 if(this->use_erp()) 00083 return m_erp; 00084 return value_traits::one(); 00085 } 00086 00087 bool & use_erp() { return m_use_erp; } 00088 bool const & use_erp() const { return m_use_erp; } 00089 00098 bool is_active() const 00099 { 00100 if(!get_number_of_jacobian_rows()) 00101 return false; 00102 return m_active; 00103 } 00104 00116 void set_active(bool active) { m_active = active; } 00117 00118 public: 00119 00127 virtual size_type get_number_of_jacobian_rows() const = 0; 00128 00129 }; 00130 00131 } // namespace mbd 00132 } // namespace OpenTissue 00133 // OPENTISSUE_DYNAMICS_MBD_INTERFACES_MBD_CORE_CONSTRAINT_INTERFACE_H 00134 #endif