TriangleFEMForceField.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_TRIANGLEFEMFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TRIANGLEFEMFORCEFIELD_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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 namespace sofa
00053 {
00054
00055 namespace component
00056 {
00057
00058 namespace forcefield
00059 {
00060
00061 using namespace sofa::defaulttype;
00062
00063
00064 template<class DataTypes>
00065 class TriangleFEMForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00066 {
00067 public:
00068 typedef core::componentmodel::behavior::ForceField<DataTypes> Inherited;
00069 typedef typename DataTypes::VecCoord VecCoord;
00070 typedef typename DataTypes::VecDeriv VecDeriv;
00071 typedef typename DataTypes::Coord Coord ;
00072 typedef typename DataTypes::Deriv Deriv ;
00073 typedef typename Coord::value_type Real ;
00074
00075 typedef sofa::core::componentmodel::topology::BaseMeshTopology::index_type Index;
00076 typedef sofa::core::componentmodel::topology::BaseMeshTopology::Triangle Element;
00077 typedef sofa::core::componentmodel::topology::BaseMeshTopology::SeqTriangles VecElement;
00078
00079 static const int SMALL = 1;
00080 static const int LARGE = 0;
00081
00082 protected:
00083
00084
00085 typedef Vec<6, Real> Displacement;
00086
00087 typedef Mat<3, 3, Real> MaterialStiffness;
00088 typedef sofa::helper::vector<MaterialStiffness> VecMaterialStiffness;
00089 VecMaterialStiffness _materialsStiffnesses;
00090
00091 typedef Mat<6, 3, Real> StrainDisplacement;
00092 typedef sofa::helper::vector<StrainDisplacement> VecStrainDisplacement;
00093 VecStrainDisplacement _strainDisplacements;
00094
00095 typedef Mat<3, 3, Real > Transformation;
00096
00097
00098 sofa::core::componentmodel::topology::BaseMeshTopology* _mesh;
00099 const VecElement *_indexedElements;
00100 Data< VecCoord > _initialPoints;
00101
00102
00103
00104
00105
00106 public:
00107
00108 TriangleFEMForceField();
00109
00110
00111
00112 virtual ~TriangleFEMForceField();
00113
00114
00115 virtual void init();
00116 virtual void reinit();
00117 virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00118
00119 virtual void addDForce (VecDeriv& df, const VecDeriv& dx);
00120
00121 virtual double getPotentialEnergy(const VecCoord& x);
00122
00123
00124 void draw();
00125
00126 int method;
00127 Data<std::string> f_method;
00128 Data<Real> f_poisson;
00129 Data<Real> f_young;
00130 Data<Real> f_damping;
00131
00132 Real getPoisson() { return f_poisson.getValue(); }
00133 void setPoisson(Real val) { f_poisson.setValue(val); }
00134 Real getYoung() { return f_young.getValue(); }
00135 void setYoung(Real val) { f_young.setValue(val); }
00136 Real getDamping() { return f_damping.getValue(); }
00137 void setDamping(Real val) { f_damping.setValue(val); }
00138 int getMethod() { return method; }
00139 void setMethod(int val) { method = val; }
00140
00141
00142
00143
00144
00145
00146 protected :
00147
00149 virtual void applyStiffness( VecCoord& f, Real h, const VecCoord& x );
00150 void computeStrainDisplacement( StrainDisplacement &J, Coord a, Coord b, Coord c);
00151 void computeMaterialStiffnesses();
00152 void computeForce( Displacement &F, const Displacement &Depl, const MaterialStiffness &K, const StrainDisplacement &J );
00153
00155 void initSmall();
00156 void accumulateForceSmall( VecCoord& f, const VecCoord & p, Index elementIndex, bool implicit = false );
00157 void accumulateDampingSmall( VecCoord& f, Index elementIndex );
00158 void applyStiffnessSmall( VecCoord& f, Real h, const VecCoord& x );
00159
00161 sofa::helper::vector< helper::fixed_array <Coord, 3> > _rotatedInitialElements;
00162 sofa::helper::vector< Transformation > _rotations;
00163 void initLarge();
00164 void computeRotationLarge( Transformation &r, const VecCoord &p, const Index &a, const Index &b, const Index &c);
00165 void accumulateForceLarge( VecCoord& f, const VecCoord & p, Index elementIndex, bool implicit=false );
00166 void accumulateDampingLarge( VecCoord& f, Index elementIndex );
00167 void applyStiffnessLarge( VecCoord& f, Real h, const VecCoord& x );
00168 };
00169
00170
00171 }
00172
00173 }
00174
00175 }
00176
00177 #endif