MatrixMass.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_MATRIXMASS_H
00026 #define SOFA_COMPONENT_MASS_MATRIXMASS_H
00027
00028
00029
00030 #include <sofa/defaulttype/VecTypes.h>
00031 #include <sofa/core/componentmodel/behavior/Mass.h>
00032 #include <sofa/core/objectmodel/Event.h>
00033 #include <sofa/component/topology/PointData.h>
00034 #include <sofa/helper/vector.h>
00035
00036 namespace sofa
00037 {
00038
00039
00040
00041 namespace component
00042 {
00043
00044 namespace mass
00045 {
00046
00047
00053 template <class DataTypes, class MassType>
00054 class MatrixMass : public core::componentmodel::behavior::Mass<DataTypes>
00055 {
00056 public:
00057 typedef core::componentmodel::behavior::Mass<DataTypes> Inherited;
00058 typedef typename DataTypes::VecCoord VecCoord;
00059 typedef typename DataTypes::VecDeriv VecDeriv;
00060 typedef typename DataTypes::Coord Coord;
00061 typedef typename DataTypes::Deriv Deriv;
00062 typedef typename DataTypes::Real Real;
00063
00064 typedef helper::vector<MassType> VecMass;
00065
00066
00067 Data< VecMass > f_mass;
00068 Data< bool > _lumped;
00069 Data< Real > _defaultValue;
00070
00071 VecMass _lumpedMasses;
00072
00073 const VecMass* _usedMassMatrices;
00074
00075
00076
00077 MatrixMass()
00078 : f_mass( initData(&f_mass, "massMatrices", "values of the particles masses") )
00079 , _defaultValue( initData(&_defaultValue, (Real)1.0,"defaultValue", "real default value") )
00080 ,_usingDefaultDiagonalMatrices(false)
00081 {
00082 _lumped = initData( &this->_lumped, false, "lumped", "");
00083 };
00084
00085 ~MatrixMass();
00086
00087
00088 void clear();
00089
00090 void resize(int vsize);
00091
00092
00093 virtual void init();
00094 virtual void reinit();
00095
00096
00097
00098 void addMDx(VecDeriv& f, const VecDeriv& dx, double factor = 1.0);
00099
00100 void accFromF(VecDeriv& a, const VecDeriv& f);
00101
00102 void addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00103
00104 void addGravityToV(double dt);
00105
00106 double getKineticEnergy(const VecDeriv& v);
00107
00108 double getPotentialEnergy(const VecCoord& x);
00109
00111 void addMToMatrix(defaulttype::BaseMatrix * mat, double mFact, unsigned int &offset);
00112
00113 double getElementMass(unsigned int index);
00114
00115 protected:
00116 MassType diagonalMass( const Real& m );
00117 MassType lump( const MassType& m );
00118 void lumpMatrices( );
00119 void defaultDiagonalMatrices( );
00120 bool _usingDefaultDiagonalMatrices;
00121
00122 };
00123
00124 }
00125
00126 }
00127
00128 }
00129
00130 #endif