AddMToMatrixFunctor.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #ifndef SOFA_COMPONENT_MASS_ADDMTOMATRIXFUNCTOR_H
00026 #define SOFA_COMPONENT_MASS_ADDMTOMATRIXFUNCTOR_H
00027 
00028 #include <sofa/defaulttype/RigidTypes.h>
00029 #include <sofa/defaulttype/DataTypeInfo.h>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace mass
00038 {
00039 
00040 template<class Deriv, class MassType>
00041 class AddMToMatrixFunctor
00042 //;
00043 //template<int N, typename Real>
00044 //class AddMToMatrixFunctor< defaulttype::Vec<N,Real>, Real >
00045 {
00046 public:
00047     //void operator()(defaulttype::BaseMatrix * mat, const Real& mass, int pos, double fact)
00048     void operator()(defaulttype::BaseMatrix * mat, const MassType& mass, int pos, double fact)
00049     {
00050         const double m = mass*fact;
00051         for (unsigned int i=0;i<Deriv::size();++i)
00052             mat->add(pos+i, pos+i, m);
00053     }
00054 };
00055 
00056 template<int N, typename Real>
00057 class AddMToMatrixFunctor< defaulttype::Vec<N,Real>, defaulttype::Mat<N,N,Real> >
00058 {
00059 public:
00060     void operator()(defaulttype::BaseMatrix * mat, const defaulttype::Mat<N,N,Real>& mass, int pos, double fact)
00061     {
00062         for (int i=0;i<N;++i)
00063             for (int j=0;j<N;++j)
00064         {
00065             mat->add(pos+i, pos+j, mass[i][j]*fact);
00066         }
00067     }
00068 };
00069 
00070 template<typename Real>
00071 class AddMToMatrixFunctor< defaulttype::RigidDeriv<3,Real>, defaulttype::RigidMass<3,Real> >
00072 {
00073 public:
00074     enum { N=3 };
00075     void operator()(defaulttype::BaseMatrix * mat, const defaulttype::RigidMass<N,Real>& mass, int pos, double fact)
00076     {
00077         const double m = mass.mass*fact;
00078         for (int i=0;i<N;++i)
00079             mat->add(pos+i, pos+i, m);
00080         for (int i=0;i<N;++i)
00081             for (int j=0;j<N;++j)
00082         {
00083             mat->add(pos+N+i, pos+N+j, mass.inertiaMassMatrix[i][j]*fact);
00084         }
00085     }
00086 };
00087 
00088 template<typename Real>
00089 class AddMToMatrixFunctor< defaulttype::RigidDeriv<2,Real>, defaulttype::RigidMass<2,Real> >
00090 {
00091 public:
00092     enum { N=2 };
00093     void operator()(defaulttype::BaseMatrix * mat, const defaulttype::RigidMass<N,Real>& mass, int pos, double fact)
00094     {
00095         const double m = mass.mass*fact;
00096         for (int i=0;i<N;++i)
00097             mat->add(pos+i, pos+i, m);
00098         mat->add(pos+N, pos+N, mass.inertiaMassMatrix*fact);
00099     }
00100 };
00101 
00102 } // namespace mass
00103 
00104 } // namespace component
00105 
00106 } // namespace sofa
00107 
00108 #endif

Generated on Sun Nov 23 03:35:04 2008 for Sofa by  doxygen 1.5.7.1