Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_JACOBIAN_MATRIX_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_JACOBIAN_MATRIX_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace mbd
00015 {
00016 namespace detail
00017 {
00034 template<typename group_type,typename matrix_type>
00035 void get_jacobian_matrix(
00036 group_type const & group
00037 , size_t const & m
00038 , matrix_type& J
00039 )
00040 {
00041 typedef typename group_type::math_policy math_policy;
00042 typedef typename group_type::const_indirect_constraint_iterator const_indirect_constraint_iterator;
00043 typedef typename group_type::const_indirect_contact_iterator const_indirect_contact_iterator;
00044 typedef typename group_type::const_indirect_body_iterator const_indirect_body_iterator;
00045 typedef typename math_policy::matrix_range matrix_range;
00046 typedef typename matrix_type::size_type size_type;
00047
00048 size_type n = group.size_bodies();
00049
00050 math_policy::resize(J,m,6*n);
00051
00052 J.clear();
00053
00054 size_type tag = 0;
00055 for(const_indirect_body_iterator body = group.body_begin();body!=group.body_end();++body)
00056 {
00057 assert(body->is_active() || !"get_jacobian(): body was not active");
00058 body->m_tag = tag++;
00059 }
00060
00061 for(const_indirect_constraint_iterator constraint = group.constraint_begin();constraint!=group.constraint_end();++constraint)
00062 {
00063 if(constraint->is_active())
00064 {
00065 size_type start_row = constraint->get_jacobian_index();
00066 size_type end_row = start_row + constraint->get_number_of_jacobian_rows();
00067
00068 size_type start_column = 6*constraint->get_body_A()->m_tag;
00069 size_type end_column = start_column + 3;
00070 matrix_range linear_matrix_range_A = math_policy::subrange(J,start_row,end_row,start_column,end_column);
00071 constraint->get_linear_jacobian_A( linear_matrix_range_A );
00072
00073 start_column += 3;
00074 end_column += 3;
00075 matrix_range angular_matrix_range_A = math_policy::subrange(J,start_row,end_row,start_column,end_column);
00076 constraint->get_angular_jacobian_A( angular_matrix_range_A );
00077
00078 start_column = 6*constraint->get_body_B()->m_tag;
00079 end_column = start_column + 3;
00080 matrix_range linear_matrix_range_B = math_policy::subrange(J,start_row,end_row,start_column,end_column);
00081 constraint->get_linear_jacobian_B(linear_matrix_range_B);
00082
00083 start_column += 3;
00084 end_column += 3;
00085 matrix_range angular_matrix_range_B = math_policy::subrange(J,start_row,end_row,start_column,end_column);
00086 constraint->get_angular_jacobian_B(angular_matrix_range_B);
00087 }
00088 }
00089 for(const_indirect_contact_iterator contact = group.contact_begin();contact!=group.contact_end();++contact)
00090 {
00091 if(contact->is_active())
00092 {
00093 size_type start_row = contact->get_jacobian_index();
00094 size_type end_row = start_row + contact->get_number_of_jacobian_rows();
00095
00096 size_type start_column = 6*contact->get_body_A()->m_tag;
00097 size_type end_column = start_column + 3;
00098 matrix_range linear_matrix_range_A = math_policy::subrange(J,start_row,end_row,start_column,end_column);
00099 contact->get_linear_jacobian_A( linear_matrix_range_A );
00100
00101 start_column += 3;
00102 end_column += 3;
00103 matrix_range angular_matrix_range_A = math_policy::subrange(J,start_row,end_row,start_column,end_column);
00104 contact->get_angular_jacobian_A( angular_matrix_range_A );
00105
00106 start_column = 6*contact->get_body_B()->m_tag;
00107 end_column = start_column + 3;
00108 matrix_range linear_matrix_range_B = math_policy::subrange(J,start_row,end_row,start_column,end_column);
00109 contact->get_linear_jacobian_B( linear_matrix_range_B );
00110
00111 start_column += 3;
00112 end_column += 3;
00113 matrix_range angular_matrix_range_B = math_policy::subrange(J,start_row,end_row,start_column,end_column);
00114 contact->get_angular_jacobian_B( angular_matrix_range_B );
00115 }
00116 }
00117 }
00118
00119 }
00120 }
00121 }
00122
00123 #endif