AddMToMatrixFunctor.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00044
00045 {
00046 public:
00047
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 }
00103
00104 }
00105
00106 }
00107
00108 #endif