TriangularQuadraticSpringsForceField.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_FORCEFIELD_TRIANGULARQUADRATICSPRINGSFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TRIANGULARQUADRATICSPRINGSFORCEFIELD_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 TriangularQuadraticSpringsForceField : 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 restLength;
00088 Real currentLength;
00089 Real dl;
00090 Real stiffness;
00091
00092 EdgeRestInformation() {
00093 }
00094 };
00095
00096 class TriangleRestInformation
00097 {
00098 public:
00099 Real gamma[3];
00100 Real stiffness[3];
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;
00119
00120 Real lambda;
00121 Real mu;
00122 public:
00123
00124 TriangularQuadraticSpringsForceField();
00125
00126 virtual ~TriangularQuadraticSpringsForceField();
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 void setYoungModulus(const double modulus) {
00138 f_youngModulus.setValue((Real)modulus);
00139 }
00140 void setPoissonRatio(const double ratio) {
00141 f_poissonRatio.setValue((Real)ratio);
00142 }
00143 void includeAngularSprings(const bool useAngularSprings) {
00144 f_useAngularSprings.setValue(useAngularSprings);
00145 }
00146
00147
00148
00149 virtual void handleTopologyChange();
00150
00151 void draw();
00153 void updateLameCoefficients();
00154
00155
00156
00157 protected :
00158
00159 EdgeData<EdgeRestInformation> &getEdgeInfo() {return edgeInfo;}
00160
00161 static void TRQSEdgeCreationFunction(int edgeIndex, void* param, EdgeRestInformation &ei,
00162 const Edge& , const sofa::helper::vector< unsigned int > &,
00163 const sofa::helper::vector< double >&);
00164 static void TRQSTriangleCreationFunction (int , void* ,
00165 TriangleRestInformation &,
00166 const Triangle& , const sofa::helper::vector< unsigned int > &, const sofa::helper::vector< double >&);
00167
00168
00169 static void TRQSTriangleDestroyFunction ( int , void* , TriangleRestInformation &);
00170
00171 };
00172 }
00173
00174 }
00175
00176
00177 }
00178
00179
00180
00181 #endif