LennardJonesForceField.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_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   } // namespace forcefield
00102 
00103 } // namespace component
00104 
00105 } // namespace sofa
00106 
00107 #endif

Generated on Sun Nov 23 03:00:21 2008 for Sofa by  doxygen 1.5.7.1