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