Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_INVERSE_MASS_MATRIX_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_INVERSE_MASS_MATRIX_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_is_number.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mbd
00017 {
00025 template<typename indirect_body_iterator,typename matrix_type>
00026 void get_inverse_mass_matrix(indirect_body_iterator begin, indirect_body_iterator end, matrix_type & invM)
00027 {
00028 typedef typename indirect_body_iterator::value_type body_type;
00029 typedef typename body_type::matrix3x3_type matrix3x3_type;
00030 typedef typename body_type::math_policy math_policy;
00031 typedef typename matrix_type::size_type size_type;
00032 typedef typename matrix_type::value_type real_type;
00033
00034 matrix3x3_type invI;
00035
00036 size_type n = std::distance(begin,end);
00037
00038 math_policy::resize(invM,6*n,6*n);
00039 invM.clear();
00040 size_type tag=0;
00041
00042 for(indirect_body_iterator body = begin;body!=end;++body)
00043 {
00044 assert(body->is_active() || !"get_inverse_mass_matrix(): body was not active");
00045
00046 size_type offset = tag*6;
00047 body->m_tag = tag++;
00048
00049 real_type inv_mass = body->get_inverse_mass();
00050
00051 body->get_inverse_inertia_wcs(invI);
00052
00053 assert(is_number(inv_mass) || !"get_inverse_mass_matrix(): non number encountered");
00054 assert(is_number(invI(0,0)) || !"get_inverse_mass_matrix(): non number encountered");
00055 assert(is_number(invI(0,1)) || !"get_inverse_mass_matrix(): non number encountered");
00056 assert(is_number(invI(0,2)) || !"get_inverse_mass_matrix(): non number encountered");
00057 assert(is_number(invI(1,0)) || !"get_inverse_mass_matrix(): non number encountered");
00058 assert(is_number(invI(1,1)) || !"get_inverse_mass_matrix(): non number encountered");
00059 assert(is_number(invI(1,2)) || !"get_inverse_mass_matrix(): non number encountered");
00060 assert(is_number(invI(2,0)) || !"get_inverse_mass_matrix(): non number encountered");
00061 assert(is_number(invI(2,1)) || !"get_inverse_mass_matrix(): non number encountered");
00062 assert(is_number(invI(2,2)) || !"get_inverse_mass_matrix(): non number encountered");
00063
00064 invM(offset,offset) = inv_mass;
00065 invM(offset+1,offset+1) = inv_mass;
00066 invM(offset+2,offset+2) = inv_mass;
00067 offset += 3;
00068 invM(offset,offset) = invI(0,0);
00069 invM(offset,offset+1) = invI(0,1);
00070 invM(offset,offset+2) = invI(0,2);
00071 invM(offset+1,offset) = invI(1,0);
00072 invM(offset+1,offset+1) = invI(1,1);
00073 invM(offset+1,offset+2) = invI(1,2);
00074 invM(offset+2,offset) = invI(2,0);
00075 invM(offset+2,offset+1) = invI(2,1);
00076 invM(offset+2,offset+2) = invI(2,2);
00077 }
00078 }
00079
00080 template<typename group_type,typename matrix_type>
00081 void get_inverse_mass_matrix(group_type const & group, matrix_type & invM)
00082 {
00083 get_inverse_mass_matrix(group.body_begin(),group.body_end(),invM);
00084 }
00085
00086 }
00087 }
00088
00089 #endif