MatrixMass.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_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     //void addMass(const MassType& mass);
00090     void resize(int vsize);
00091     
00092     
00093     virtual void init();
00094     virtual void reinit();
00095     
00096     
00097     // -- Mass interface
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/*, defaulttype::BaseVector& v*/);
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 } // namespace mass
00125 
00126 } // namespace component
00127 
00128 } // namespace sofa
00129 
00130 #endif

Generated on Sun Nov 23 03:37:46 2008 for Sofa by  doxygen 1.5.7.1