• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/dynamics/mbd/mbd_get_mass_matrix.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_MASS_MATRIX_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_MASS_MATRIX_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 #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_mass_matrix(indirect_body_iterator begin, indirect_body_iterator end, matrix_type & M)
00027     {
00028       typedef typename indirect_body_iterator::value_type  body_type;
00029       typedef typename body_type::math_policy              math_policy;
00030       typedef typename body_type::matrix3x3_type           matrix3x3_type;
00031       typedef typename matrix_type::size_type              size_type;
00032       typedef typename matrix_type::value_type             real_type;
00033 
00034       matrix3x3_type I;
00035 
00036       size_type n = std::distance(begin,end);
00037 
00038       math_policy::resize( M, 6*n,6*n);      
00039       M.clear();
00040       size_type tag=0;
00041 
00042       for(indirect_body_iterator body = begin;body!=end;++body)
00043       {
00044         assert(body->is_active() || !"get_mass_matrix(): body was not active");
00045 
00046         size_type offset = tag*6;
00047         body->m_tag = tag++;
00048 
00049         real_type mass = body->get_mass();
00050 
00051         body->get_inertia_wcs(I);
00052 
00053         assert(is_number(mass)   || !"get_mass_matrix(): non number encountered");
00054         assert(is_number(I(0,0)) || !"get_mass_matrix(): non number encountered");
00055         assert(is_number(I(0,1)) || !"get_mass_matrix(): non number encountered");
00056         assert(is_number(I(0,2)) || !"get_mass_matrix(): non number encountered");
00057         assert(is_number(I(1,0)) || !"get_mass_matrix(): non number encountered");
00058         assert(is_number(I(1,1)) || !"get_mass_matrix(): non number encountered");
00059         assert(is_number(I(1,2)) || !"get_mass_matrix(): non number encountered");
00060         assert(is_number(I(2,0)) || !"get_mass_matrix(): non number encountered");
00061         assert(is_number(I(2,1)) || !"get_mass_matrix(): non number encountered");
00062         assert(is_number(I(2,2)) || !"get_mass_matrix(): non number encountered");
00063 
00064         M(offset,offset)     = mass;
00065         M(offset+1,offset+1) = mass;
00066         M(offset+2,offset+2) = mass;
00067         offset += 3;      
00068         M(offset,offset)     = I(0,0);
00069         M(offset,offset+1)   = I(0,1);
00070         M(offset,offset+2)   = I(0,2);
00071         M(offset+1,offset)   = I(1,0);
00072         M(offset+1,offset+1) = I(1,1);
00073         M(offset+1,offset+2) = I(1,2);
00074         M(offset+2,offset)   = I(2,0);
00075         M(offset+2,offset+1) = I(2,1);
00076         M(offset+2,offset+2) = I(2,2);
00077       }
00078     }
00079 
00080     template<typename group_type,typename matrix_type>
00081     void get_mass_matrix(group_type const & group, matrix_type & M)
00082     {
00083       get_mass_matrix(group.body_begin(),group.body_end(),M);
00084     }
00085 
00086   } //--- End of namespace mbd
00087 } //--- End of namespace OpenTissue
00088 // OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_GET_MASS_MATRIX_H
00089 #endif

Generated on Thu Dec 1 2011 12:52:42 for HUMIM Tracker by  doxygen 1.7.1