TriangularBiquadraticSpringsForceField.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_TRIANGULARBIQUADRATICSPRINGSFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TRIANGULARBIQUADRATICSPRINGSFORCEFIELD_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 TriangularBiquadraticSpringsForceField : 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         Real  restSquareLength; // the rest length  
00088         Real  currentSquareLength;  // the current edge length 
00089         Real  deltaL2;  // the current unit direction
00090         Real stiffness;
00091         
00092         EdgeRestInformation() {
00093         }
00094     };
00095 
00096    class TriangleRestInformation
00097     {
00098     public:
00099         Real  gamma[3]; // the angular stiffness 
00100         Real stiffness[3]; // the elongation stiffness
00101         Mat3 DfDx[3]; 
00102 
00103         TriangleRestInformation() {
00104         }
00105     };
00106     
00107     TriangleData<TriangleRestInformation> triangleInfo;
00108     EdgeData<EdgeRestInformation> edgeInfo;
00109         
00110     sofa::core::componentmodel::topology::BaseMeshTopology* _topology;
00111     Data < VecCoord >  _initialPoints;                                      
00112 
00113     bool updateMatrix;
00114 
00115     Data<Real> f_poissonRatio;
00116     Data<Real> f_youngModulus;
00117     Data<Real> f_dampingRatio;
00118     Data<bool> f_useAngularSprings; // whether angular springs should be included
00119 
00120     Real lambda;  
00121     Real mu;    
00122 public:
00123 
00124     TriangularBiquadraticSpringsForceField();
00125 
00126     virtual ~TriangularBiquadraticSpringsForceField();
00127 
00128     virtual double getPotentialEnergy(const VecCoord& x);
00129 
00130     virtual void init();
00131     virtual void addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00132     virtual void addDForce(VecDeriv& df, const VecDeriv& dx);
00133 
00134     virtual Real getLambda() const { return lambda;}
00135     virtual Real getMu() const { return mu;}
00136 
00137     // handle topological changes
00138     virtual void handleTopologyChange();
00139 
00140     void setYoungModulus(const double modulus) {
00141         f_youngModulus.setValue((Real)modulus);
00142     }
00143     void setPoissonRatio(const double ratio) {
00144         f_poissonRatio.setValue((Real)ratio);
00145     }
00146 
00147     void draw();
00149     void updateLameCoefficients();
00150 
00151 
00152 
00153 protected :
00154 
00155     EdgeData<EdgeRestInformation> &getEdgeInfo() {return edgeInfo;}
00156 
00157     static void TRBSEdgeCreationFunction(int edgeIndex, void* param, EdgeRestInformation &ei,
00158                                          const Edge& ,  const sofa::helper::vector< unsigned int > &,
00159                                          const sofa::helper::vector< double >&);
00160     static void TRBSTriangleCreationFunction (int , void* , 
00161                             TriangleRestInformation &,
00162                             const Triangle& , const sofa::helper::vector< unsigned int > &, const sofa::helper::vector< double >&);
00163                                     
00164 
00165     static void TRBSTriangleDestroyFunction ( int , void* , TriangleRestInformation &);
00166 
00167 };
00168 } //namespace forcefield
00169 
00170 } // namespace Components
00171 
00172 
00173 } // namespace Sofa
00174 
00175 
00176 
00177 #endif /* _TriangularBiquadraticSpringsForceField_H_ */

Generated on Sun Nov 23 03:18:07 2008 for Sofa by  doxygen 1.5.7.1