CudaPenalityContactForceField.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_GPU_CUDA_CUDAPENALITYCONTACTFORCEFIELD_H
00026 #define SOFA_GPU_CUDA_CUDAPENALITYCONTACTFORCEFIELD_H
00027 
00028 #include "CudaTypes.h"
00029 #include <sofa/component/forcefield/PenalityContactForceField.h>
00030 #include <sofa/gpu/cuda/CudaCollisionDetection.h>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace gpu
00036 {
00037 
00038 namespace cuda
00039 {
00040 
00041 } // namespace cuda
00042 
00043 } // namespace gpu
00044 
00045 namespace component
00046 {
00047 
00048 namespace forcefield
00049 {
00050 
00051 using sofa::gpu::cuda::CudaVec3fTypes;
00052 
00053 template<>
00054 class PenalityContactForceField<CudaVec3fTypes> : public core::componentmodel::behavior::PairInteractionForceField<CudaVec3fTypes>
00055 {
00056 public:
00057     typedef CudaVec3fTypes DataTypes;
00058     typedef core::componentmodel::behavior::PairInteractionForceField<DataTypes> Inherit;
00059     typedef DataTypes DataTypes1;
00060     typedef DataTypes DataTypes2;
00061     typedef DataTypes::VecCoord VecCoord;
00062     typedef DataTypes::VecDeriv VecDeriv;
00063     typedef DataTypes::Coord Coord;
00064     typedef DataTypes::Deriv Deriv;
00065     typedef Coord::value_type Real;
00066     typedef core::componentmodel::behavior::MechanicalState<DataTypes> MechanicalState;
00067     
00068 //protected:
00069     /*
00070     struct Contact
00071     {
00072         int m1, m2;   ///< the two extremities of the spring: masses m1 and m2 
00073         Deriv norm;   ///< contact normal, from m1 to m2
00074         Real dist;    ///< minimum distance between the points
00075         Real ks;      ///< spring stiffness
00076         Real mu_s;    ///< coulomb friction coefficient (currently unused)
00077         Real mu_v;    ///< viscous friction coefficient
00078         Real pen;     ///< current penetration
00079         int age;      ///< how old is this contact
00080     };
00081 */
00082     sofa::gpu::cuda::CudaVector<sofa::defaulttype::Vec4f> contacts;
00083     sofa::gpu::cuda::CudaVector<float> pen;
00084 
00085     // contacts from previous frame
00086     //std::vector<Contact> prevContacts;
00087     
00088 //public:
00089 
00090     PenalityContactForceField(MechanicalState* object1, MechanicalState* object2)
00091     : Inherit(object1, object2)
00092     {
00093     }
00094     
00095     PenalityContactForceField()
00096     {
00097     }
00098     
00099     void clear(int reserve = 0);
00100 
00101     void addContact(int m1, int m2, const Deriv& norm, Real dist, Real ks, Real mu_s = 0.0f, Real mu_v = 0.0f, int oldIndex = 0);
00102 
00103     void setContacts(Real distance, Real ks, sofa::core::componentmodel::collision::GPUDetectionOutputVector* outputs, bool useDistance, defaulttype::Mat3x3f* normXForm = NULL);
00104     
00105     virtual void addForce(VecDeriv& f1, VecDeriv& f2, const VecCoord& x1, const VecCoord& x2, const VecDeriv& v1, const VecDeriv& v2);
00106     
00107     virtual void addDForce(VecDeriv& df1, VecDeriv& df2, const VecDeriv& dx1, const VecDeriv& dx2, double kFactor, double bFactor);
00108     
00109         virtual double getPotentialEnergy(const VecCoord&, const VecCoord&);
00110     
00111     void draw();
00112 };
00113 
00114 } // namespace forcefield
00115 
00116 } // namespace component
00117 
00118 } // namespace sofa
00119 
00120 #endif

Generated on Sun Nov 23 04:00:08 2008 for Sofa by  doxygen 1.5.7.1