CudaEllipsoidForceField.inl

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_CUDAELLIPSOIDFORCEFIELD_INL
00026 #define SOFA_GPU_CUDA_CUDAELLIPSOIDFORCEFIELD_INL
00027 
00028 #include "CudaEllipsoidForceField.h"
00029 #include <sofa/component/forcefield/EllipsoidForceField.inl>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace gpu
00035 {
00036 
00037 namespace cuda
00038 {
00039 
00040 extern "C"
00041 {
00042 void EllipsoidForceFieldCuda3f_addForce(unsigned int size, GPUEllipsoid* ellipsoid, void* tmp, void* f, const void* x, const void* v);
00043 void EllipsoidForceFieldCuda3f_addDForce(unsigned int size, GPUEllipsoid* ellipsoid, const void* tmp, void* f, const void* dx, double factor); //, const void* dfdx);
00044 
00045 void EllipsoidForceFieldCuda3f1_addForce(unsigned int size, GPUEllipsoid* ellipsoid, void* tmp, void* f, const void* x, const void* v);
00046 void EllipsoidForceFieldCuda3f1_addDForce(unsigned int size, GPUEllipsoid* ellipsoid, const void* tmp, void* f, const void* dx, double factor); //, const void* dfdx);
00047 
00048 int EllipsoidForceFieldCuda3f_getNTmp();
00049 }
00050 
00051 } // namespace cuda
00052 
00053 } // namespace gpu
00054 
00055 namespace component
00056 {
00057 
00058 namespace forcefield
00059 {
00060 
00061 using namespace gpu::cuda;
00062 
00063 
00064 template <>
00065 void EllipsoidForceField<gpu::cuda::CudaVec3fTypes>::addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v)
00066 {
00067     const Coord center = this->center.getValue();
00068     const Coord r = this->vradius.getValue();
00069     const Real stiffness = this->stiffness.getValue();
00070     const Real damping = this->damping.getValue();
00071     data.ellipsoid.center = center;
00072     for (int i=0;i<3;++i)
00073         data.ellipsoid.inv_r2[i] = 1/(r[i]*r[i]);
00074     data.ellipsoid.stiffness = stiffness;
00075     data.ellipsoid.damping = damping;
00076     f.resize(x.size());
00077     data.tmp.resize((x.size()+BSIZE*2)*EllipsoidForceFieldCuda3f_getNTmp());
00078     EllipsoidForceFieldCuda3f_addForce(x.size(), &data.ellipsoid, data.tmp.deviceWrite(), f.deviceWrite(), x.deviceRead(), v.deviceRead());
00079 }
00080 
00081 template <>
00082 void EllipsoidForceField<gpu::cuda::CudaVec3fTypes>::addDForce(VecDeriv& df, const VecCoord& dx, double kFactor, double /*bFactor*/)
00083 {
00084     df.resize(dx.size());
00085     EllipsoidForceFieldCuda3f_addDForce(dx.size(), &data.ellipsoid, data.tmp.deviceRead(), df.deviceWrite(), dx.deviceRead(), kFactor);
00086 }
00087 
00088 
00089 template <>
00090 void EllipsoidForceField<gpu::cuda::CudaVec3f1Types>::addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v)
00091 {
00092     const Coord center = this->center.getValue();
00093     const Coord r = this->vradius.getValue();
00094     const Real stiffness = this->stiffness.getValue();
00095     const Real damping = this->damping.getValue();
00096     data.ellipsoid.center = center;
00097     for (int i=0;i<3;++i)
00098         data.ellipsoid.inv_r2[i] = 1/(r[i]*r[i]);
00099     data.ellipsoid.stiffness = stiffness;
00100     data.ellipsoid.damping = damping;
00101     f.resize(x.size());
00102     data.tmp.resize((x.size()+BSIZE*2)*EllipsoidForceFieldCuda3f_getNTmp());
00103     EllipsoidForceFieldCuda3f1_addForce(x.size(), &data.ellipsoid, data.tmp.deviceWrite(), f.deviceWrite(), x.deviceRead(), v.deviceRead());
00104 }
00105 
00106 template <>
00107 void EllipsoidForceField<gpu::cuda::CudaVec3f1Types>::addDForce(VecDeriv& df, const VecCoord& dx, double kFactor, double /*bFactor*/)
00108 {
00109     df.resize(dx.size());
00110     EllipsoidForceFieldCuda3f1_addDForce(dx.size(), &data.ellipsoid, data.tmp.deviceRead(), df.deviceWrite(), dx.deviceRead(), kFactor);
00111 }
00112 
00113 } // namespace forcefield
00114 
00115 } // namespace component
00116 
00117 } // namespace sofa
00118 
00119 #endif

Generated on Sun Nov 23 03:58:24 2008 for Sofa by  doxygen 1.5.7.1