Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_SIMULATORS_MBD_IMPLICIT_FIXED_STEP_SIMULATOR_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_SIMULATORS_MBD_IMPLICIT_FIXED_STEP_SIMULATOR_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/dynamics/mbd/interfaces/mbd_simulator_interface.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mbd
00017 {
00023 template< typename mbd_types >
00024 class ImplicitFixedStepSimulator
00025 : public SimulatorInterface<mbd_types>
00026 {
00027 protected:
00028
00029 typedef typename mbd_types::math_policy math_policy;
00030 typedef typename mbd_types::math_policy::real_type real_type;
00031 typedef typename mbd_types::math_policy::vector_type vector_type;
00032 typedef typename mbd_types::math_policy::matrix_type matrix_type;
00033 typedef typename mbd_types::group_type group_type;
00034 typedef typename mbd_types::group_ptr_container group_ptr_container;
00035
00036 public:
00037
00038 class node_traits{};
00039 class edge_traits{};
00040 class constraint_traits{};
00041
00042 protected:
00043
00044 vector_type m_s;
00045 vector_type m_ss;
00046 vector_type m_u;
00047 vector_type m_f_ext;
00048 matrix_type m_invM;
00049 group_type * m_all;
00050 group_ptr_container m_groups;
00051
00052
00053 public:
00054
00055 ImplicitFixedStepSimulator(){}
00056
00057 virtual ~ImplicitFixedStepSimulator(){}
00058
00059 public:
00060
00061 void run(real_type const & time_step)
00062 {
00063 m_all = this->get_configuration()->get_all_body_group();
00064
00065 mbd::compute_scripted_motions(*m_all,this->time());
00066 mbd::get_position_vector(*m_all, m_s);
00067 mbd::get_velocity_vector(*m_all, m_u);
00068 mbd::get_external_force_vector(*m_all,m_f_ext,true);
00069 mbd::get_inverse_mass_matrix(*m_all,m_invM);
00070
00071
00072
00073 math_policy::prod_add(m_invM, m_f_ext, m_u, time_step);
00074
00075
00076 mbd::compute_position_update(*m_all,m_s,m_u,time_step,m_ss);
00077 mbd::set_position_vector(*m_all,m_ss);
00078 mbd::compute_scripted_motions(*m_all,this->time() + time_step);
00079
00080 this->get_collision_detection()->run( m_groups );
00081 for(typename group_ptr_container::iterator tmp=m_groups.begin();tmp!=m_groups.end();++tmp)
00082 {
00083 group_type * group = (*tmp);
00084 this->get_sleepy()->evaluate(group->body_begin(),group->body_end());
00085 this->get_stepper()->run(*group,time_step);
00086 }
00087
00088
00089 mbd::get_velocity_vector(*m_all, m_u);
00090
00091 mbd::compute_position_update(*m_all,m_s,m_u,time_step,m_ss);
00092 mbd::set_position_vector(*m_all,m_ss);
00093 update_time(time_step);
00094 }
00095
00096 };
00097
00098 }
00099 }
00100
00101 #endif