CudaTestForceField.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_CUDATESTFORCEFIELD_H
00026 #define SOFA_GPU_CUDA_CUDATESTFORCEFIELD_H
00027 
00028 #include "CudaTypes.h"
00029 #include <sofa/core/componentmodel/behavior/ForceField.h>
00030 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace gpu
00036 {
00037 
00038 namespace cuda
00039 {
00040 
00041 using namespace sofa::defaulttype;
00042 
00043 class CudaTestForceField : public core::componentmodel::behavior::ForceField<CudaVec3fTypes>
00044 {
00045 public:
00046     typedef CudaVec3fTypes::Real Real;
00047     typedef CudaVec3fTypes::Coord Coord;
00048 #ifdef SOFA_NEW_HEXA    
00049     typedef sofa::core::componentmodel::topology::BaseMeshTopology::Hexa Element;
00050     typedef sofa::core::componentmodel::topology::BaseMeshTopology::SeqHexas VecElement;
00051 #else    
00052     typedef sofa::core::componentmodel::topology::BaseMeshTopology::Cube Element;
00053     typedef sofa::core::componentmodel::topology::BaseMeshTopology::SeqCubes VecElement;
00054 #endif
00055 
00057     struct GPUElement
00058     {
00061     int v[8];
00065         float Kvol, Kr;
00069         float initvol, initr;
00071     };
00072 
00073     CudaVector<GPUElement> elems;
00074 
00076     struct GPUElementState
00077     {
00079     Coord center;
00081     float dv;
00082     float r,Kr;
00083     float dummy1,dummy2;
00084     };
00085 
00086     CudaVector<GPUElementState> state;
00087 
00088     int nbVertex; 
00089     int nbElementPerVertex; 
00090 
00091 
00092     CudaVector<int> velems;
00093 
00094     CudaTestForceField();
00095     void init();
00096     void reinit();
00097     void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& /*v*/);
00098     void addDForce (VecDeriv& df, const VecDeriv& dx);
00099     double getPotentialEnergy(const VecCoord&) { return 0.0; }
00100 
00101 protected:
00102 
00103     void init(int nbe, int nbv, int nbelemperv)
00104     {
00105         elems.resize(nbe);
00106         state.resize(nbe);
00107         nbVertex = nbv;
00108         nbElementPerVertex = nbelemperv;
00109         int nbloc = (nbVertex+BSIZE-1)/BSIZE;
00110         velems.resize(nbloc*nbElementPerVertex*BSIZE);
00111         for (unsigned int i=0;i<velems.size();i++)
00112             velems[i] = 0;
00113     }
00114     void setV(int vertex, int num, int index)
00115     {
00116         int bloc = vertex/BSIZE;
00117         int b_x  = vertex%BSIZE;
00118         velems[ bloc*BSIZE*nbElementPerVertex // start of the bloc
00119               + num*BSIZE                     // offset to the element
00120               + b_x                           // offset to the vertex
00121               ] = index+1;
00122     }
00123 
00124     void setE(int i, const Element& indices, Real vol, Real r, Real Kvol, Real Kr) //, const MaterialStiffness& K, const StrainDisplacement& /*J*/)
00125     {
00126         GPUElement& e = elems[i];
00127     for (unsigned int i=0;i<indices.size();i++)
00128         e.v[i] = indices[i];
00129         e.initvol = vol;
00130     e.initr = r;
00131     e.Kvol = Kvol;
00132     e.Kr = Kr;
00133     }
00134 };
00135 
00136 } // namespace cuda
00137 
00138 } // namespace gpu
00139 
00140 } // namespace sofa
00141 
00142 #endif

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