DiagonalMass.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_DIAGONALMASS_H
00026 #define SOFA_COMPONENT_MASS_DIAGONALMASS_H
00027 
00028 #if !defined(__GNUC__) || (__GNUC__ > 3 || (_GNUC__ == 3 && __GNUC_MINOR__ > 3))
00029 #pragma once
00030 #endif
00031 
00032 #include <sofa/defaulttype/VecTypes.h>
00033 #include <sofa/core/componentmodel/behavior/Mass.h>
00034 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00035 #include <sofa/core/objectmodel/Event.h>
00036 #include <sofa/component/topology/PointData.h>
00037 #include <sofa/helper/vector.h>
00038 
00039 #include <sofa/component/topology/EdgeSetGeometryAlgorithms.h>
00040 #include <sofa/component/topology/TriangleSetGeometryAlgorithms.h>
00041 #include <sofa/component/topology/TetrahedronSetGeometryAlgorithms.h>
00042 #include <sofa/component/topology/QuadSetGeometryAlgorithms.h>
00043 #include <sofa/component/topology/HexahedronSetGeometryAlgorithms.h>
00044 
00045 namespace sofa
00046 {
00047 
00048 namespace component
00049 {
00050 
00051 namespace mass
00052 {
00053 
00054 // template<class Vec> void readVec1(Vec& vec, const char* str);
00055 
00056 template <class DataTypes, class MassType>
00057 class DiagonalMass : public core::componentmodel::behavior::Mass<DataTypes>, public virtual core::objectmodel::BaseObject
00058 {
00059 public:
00060     typedef core::componentmodel::behavior::Mass<DataTypes> Inherited;
00061     typedef typename DataTypes::VecCoord VecCoord;
00062     typedef typename DataTypes::VecDeriv VecDeriv;
00063     typedef typename DataTypes::Coord Coord;
00064     typedef typename DataTypes::Deriv Deriv;
00065     typedef typename DataTypes::Real Real;
00066 
00067     typedef sofa::component::topology::PointData<MassType> VecMass;
00068     typedef helper::vector<MassType> MassVector;
00069 
00070 
00071     typedef enum {
00072         TOPOLOGY_UNKNOWN=0,
00073         TOPOLOGY_EDGESET=1,
00074         TOPOLOGY_TRIANGLESET=2,
00075         TOPOLOGY_TETRAHEDRONSET=3,
00076         TOPOLOGY_QUADSET=4,
00077         TOPOLOGY_HEXAHEDRONSET=5
00078     } TopologyType;
00079 
00080     Data< VecMass > f_mass;
00082     Data< Real > m_massDensity;
00083 
00085     Data< bool > showCenterOfGravity;
00086     Data< float > showAxisSize;
00087 
00088 protected:
00089     //VecMass masses;
00090 
00091     class Loader;
00093     TopologyType topologyType;  
00094 
00095 public:
00096 
00097     sofa::core::componentmodel::topology::BaseMeshTopology* _topology;
00098 
00099     sofa::component::topology::EdgeSetGeometryAlgorithms<DataTypes>* edgeGeo;   
00100     sofa::component::topology::TriangleSetGeometryAlgorithms<DataTypes>* triangleGeo; 
00101     sofa::component::topology::QuadSetGeometryAlgorithms<DataTypes>* quadGeo; 
00102     sofa::component::topology::TetrahedronSetGeometryAlgorithms<DataTypes>* tetraGeo; 
00103     sofa::component::topology::HexahedronSetGeometryAlgorithms<DataTypes>* hexaGeo; 
00104 
00105     DiagonalMass();
00106 
00107     ~DiagonalMass();
00108 
00109     //virtual const char* getTypeName() const { return "DiagonalMass"; }
00110     
00111     bool load(const char *filename);
00112 
00113     void clear();
00114 
00115     virtual void reinit();
00116     virtual void init();
00117     virtual void parse(core::objectmodel::BaseObjectDescription* arg);
00118 
00119     TopologyType getMassTopologyType() const {
00120         return topologyType;
00121     }
00122      Real getMassDensity() const {
00123          return m_massDensity.getValue();
00124      }
00125 
00126 
00127    // handle topological changes
00128    virtual void handleTopologyChange();
00129 
00130    void setMassDensity(Real m) {
00131        m_massDensity.setValue(m);
00132    }
00133 
00134 
00135     void addMass(const MassType& mass);
00136 
00137     void resize(int vsize);
00138 
00139     // -- Mass interface
00140     void addMDx(VecDeriv& f, const VecDeriv& dx, double factor = 1.0);
00141 
00142     void accFromF(VecDeriv& a, const VecDeriv& f);
00143 
00144     void addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00145 
00146     double getKineticEnergy(const VecDeriv& v);  
00147 
00148     double getPotentialEnergy(const VecCoord& x);   
00149 
00150     void addGravityToV(double dt/*, defaulttype::BaseVector& v*/);
00151 
00153     void addMToMatrix(defaulttype::BaseMatrix * mat, double mFact, unsigned int &offset);
00154 
00155     double getElementMass(unsigned int index);
00156 
00157     void draw();
00158 
00159     bool addBBox(double* minBBox, double* maxBBox);
00160 };
00161 
00162 } // namespace mass
00163 
00164 } // namespace component
00165 
00166 } // namespace sofa
00167 
00168 #endif

Generated on Sun Nov 23 03:36:24 2008 for Sofa by  doxygen 1.5.7.1