TriangularTensorMassForceField.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_FORCEFIELD_TRIANGULARTENSORMASSFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TRIANGULARTENSORMASSFORCEFIELD_H
00027 
00028 #if !defined(__GNUC__) || (__GNUC__ > 3 || (_GNUC__ == 3 && __GNUC_MINOR__ > 3))
00029 #pragma once
00030 #endif
00031 
00032 #include <sofa/core/componentmodel/behavior/ForceField.h>
00033 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00034 #include <sofa/defaulttype/Vec.h>
00035 #include <sofa/defaulttype/Mat.h>
00036 #include <sofa/component/topology/TriangleData.h>
00037 #include <sofa/component/topology/EdgeData.h>
00038 
00039 
00040 namespace sofa
00041 {
00042 
00043 namespace component
00044 {
00045 
00046 
00047 namespace forcefield
00048 {
00049 using namespace sofa::helper;
00050 using namespace sofa::defaulttype;
00051 using namespace sofa::component::topology;
00052 
00053 
00054 template<class DataTypes>
00055 class TriangularTensorMassForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00056 {
00057 public:
00058     typedef core::componentmodel::behavior::ForceField<DataTypes> Inherited;
00059     typedef typename DataTypes::VecCoord VecCoord;
00060     typedef typename DataTypes::VecDeriv VecDeriv;
00061     typedef typename DataTypes::Coord    Coord   ;
00062     typedef typename DataTypes::Deriv    Deriv   ;
00063     typedef typename Coord::value_type   Real    ;
00064 
00065 
00066     class Mat3 : public fixed_array<Deriv,3>
00067     {
00068     public:
00069         Deriv operator*(const Deriv& v)
00070         {
00071             return Deriv((*this)[0]*v,(*this)[1]*v,(*this)[2]*v);
00072         }
00073         Deriv transposeMultiply(const Deriv& v) 
00074         {
00075             return Deriv(v[0]*((*this)[0])[0]+v[1]*((*this)[1])[0]+v[2]*((*this)[2][0]),
00076                 v[0]*((*this)[0][1])+v[1]*((*this)[1][1])+v[2]*((*this)[2][1]),
00077                 v[0]*((*this)[0][2])+v[1]*((*this)[1][2])+v[2]*((*this)[2][2]));
00078         }
00079     };
00080 
00081 protected: 
00082 
00083 
00084   class EdgeRestInformation
00085     {
00086     public:
00087         Mat3 DfDx; 
00088 
00089         EdgeRestInformation() {
00090         }
00091     };
00092 
00093     EdgeData<EdgeRestInformation> edgeInfo;
00094         
00095     sofa::core::componentmodel::topology::BaseMeshTopology* _topology;
00096     VecCoord  _initialPoints;
00097 
00098     bool updateMatrix;
00099 
00100     Data<Real> f_poissonRatio;
00101     Data<Real> f_youngModulus;
00102 
00103     Real lambda;  
00104     Real mu;    
00105 public:
00106 
00107     TriangularTensorMassForceField();
00108 
00109     virtual ~TriangularTensorMassForceField();
00110 
00111     virtual double getPotentialEnergy(const VecCoord& x);
00112 
00113     virtual void init();
00114     virtual void addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00115     virtual void addDForce(VecDeriv& df, const VecDeriv& dx);
00116 
00117     virtual Real getLambda() const { return lambda;}
00118     virtual Real getMu() const { return mu;}
00119 
00120     void setYoungModulus(const double modulus) {
00121         f_youngModulus.setValue((Real)modulus);
00122     }
00123     void setPoissonRatio(const double ratio) {
00124         f_poissonRatio.setValue((Real)ratio);
00125     }
00126 
00127     // handle topological changes
00128     virtual void handleTopologyChange();
00129 
00130     void draw();
00132     void updateLameCoefficients();
00133 
00134 
00135 
00136 protected :
00137 
00138     EdgeData<EdgeRestInformation> &getEdgeInfo() {return edgeInfo;}
00139 
00140     static void TriangularTMEdgeCreationFunction(int edgeIndex, void* param, 
00141         EdgeRestInformation &ei,
00142         const Edge& ,  const sofa::helper::vector< unsigned int > &,
00143         const sofa::helper::vector< double >&);
00144 
00145     static void TriangularTMTriangleCreationFunction(const sofa::helper::vector<unsigned int> &triangleAdded, 
00146         void* param, vector<EdgeRestInformation> &edgeData);
00147     static void TriangularTMTriangleDestructionFunction ( const sofa::helper::vector<unsigned int> &triangleAdded, 
00148         void* param, vector<EdgeRestInformation> &edgeData);
00149 
00150 };
00151 } //namespace forcefield
00152 
00153 } // namespace Components
00154 
00155 
00156 } // namespace Sofa
00157 
00158 
00159 
00160 #endif /* _TriangularTensorMassForceField_H_ */

Generated on Sun Nov 23 03:20:51 2008 for Sofa by  doxygen 1.5.7.1