LennardJonesForceField.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_LENNARDJONESFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_LENNARDJONESFORCEFIELD_H
00027
00028 #include <sofa/core/componentmodel/behavior/ForceField.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00030 #include <vector>
00031
00032 namespace sofa
00033 {
00034
00035 namespace component
00036 {
00037
00038 namespace forcefield
00039 {
00040
00041 template<class DataTypes>
00042 class LennardJonesForceField : public sofa::core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00043 {
00044 public:
00045 typedef sofa::core::componentmodel::behavior::ForceField<DataTypes> Inherit;
00046 typedef typename DataTypes::VecCoord VecCoord;
00047 typedef typename DataTypes::VecDeriv VecDeriv;
00048 typedef typename DataTypes::Coord Coord;
00049 typedef typename DataTypes::Deriv Deriv;
00050 typedef typename Coord::value_type Real;
00051
00052 protected:
00053 Real a,b;
00054 Data<Real> alpha,beta,dmax,fmax;
00055 Data<Real> d0,p0;
00056 Data<Real> damping;
00057
00058 struct DForce
00059 {
00060 unsigned int a,b;
00061 Real df;
00062 };
00063
00064 sofa::helper::vector<DForce> dforces;
00065
00066 public:
00067 LennardJonesForceField()
00068 : a(1)
00069 , b(1)
00070 , alpha (initData(&alpha ,Real(6), "alpha" ,"Alpha"))
00071 , beta (initData(&beta ,Real(12),"beta" ,"Beta"))
00072 , dmax (initData(&dmax ,Real(2), "dmax" ,"DMax"))
00073 , fmax (initData(&fmax ,Real(1), "fmax" ,"FMax"))
00074 , d0 (initData(&d0 ,Real(1), "d0" ,"d0"))
00075 , p0 (initData(&p0 ,Real(1), "p0" ,"p0"))
00076 , damping(initData(&damping,Real(0), "damping","Damping"))
00077 {
00078 }
00079
00080 void setAlpha(Real v) { alpha.setValue(v); }
00081 void setBeta(Real v) { beta.setValue(v); }
00082 void setFMax(Real v) { fmax.setValue(v); }
00083 void setDMax(Real v) { dmax.setValue(v); }
00084 void setD0(Real v) { d0.setValue(v); }
00085 void setP0(Real v) { p0.setValue(v); }
00086 void setDamping(Real v) { damping.setValue(v); }
00087
00088
00089 virtual void init();
00090
00091 virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00092
00093 virtual void addDForce (VecDeriv& df, const VecDeriv& dx);
00094
00095 virtual double getPotentialEnergy(const VecCoord& x);
00096
00097 void draw();
00098
00099 };
00100
00101 }
00102
00103 }
00104
00105 }
00106
00107 #endif