CudaPlaneForceField.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_CUDAPLANEFORCEFIELD_INL
00026 #define SOFA_GPU_CUDA_CUDAPLANEFORCEFIELD_INL
00027 
00028 #include "CudaPlaneForceField.h"
00029 #include <sofa/component/forcefield/PlaneForceField.inl>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace gpu
00035 {
00036 
00037 namespace cuda
00038 {
00039 
00040 extern "C"
00041 {
00042 
00043 void PlaneForceFieldCuda3f_addForce(unsigned int size, GPUPlane<float>* plane, void* penetration, void* f, const void* x, const void* v);
00044 void PlaneForceFieldCuda3f_addDForce(unsigned int size, GPUPlane<float>* plane, const void* penetration, void* f, const void* dx); //, const void* dfdx);
00045 
00046 void PlaneForceFieldCuda3f1_addForce(unsigned int size, GPUPlane<float>* plane, void* penetration, void* f, const void* x, const void* v);
00047 void PlaneForceFieldCuda3f1_addDForce(unsigned int size, GPUPlane<float>* plane, const void* penetration, void* f, const void* dx); //, const void* dfdx);
00048 
00049 
00050 }
00051 
00052 } // namespace cuda
00053 
00054 } // namespace gpu
00055 
00056 namespace component
00057 {
00058 
00059 namespace forcefield
00060 {
00061 
00062 using namespace gpu::cuda;
00063 
00064 
00065 template <>
00066 void PlaneForceField<gpu::cuda::CudaVec3fTypes>::addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v)
00067 {
00068     data.plane.normal = planeNormal.getValue();
00069     data.plane.d = planeD.getValue();
00070     data.plane.stiffness = stiffness.getValue();
00071     data.plane.damping = damping.getValue();
00072     f.resize(x.size());
00073     data.penetration.resize(x.size());
00074     PlaneForceFieldCuda3f_addForce(x.size(), &data.plane, data.penetration.deviceWrite(), f.deviceWrite(), x.deviceRead(), v.deviceRead());
00075 }
00076 
00077 template <>
00078 void PlaneForceField<gpu::cuda::CudaVec3fTypes>::addDForce(VecDeriv& df, const VecCoord& dx, double kFactor, double /*bFactor*/)
00079 {
00080     df.resize(dx.size());
00081     double stiff = data.plane.stiffness;
00082     data.plane.stiffness *= kFactor;
00083     PlaneForceFieldCuda3f_addDForce(dx.size(), &data.plane, data.penetration.deviceRead(), df.deviceWrite(), dx.deviceRead());
00084     data.plane.stiffness = stiff;
00085 }
00086 
00087 
00088 template <>
00089 void PlaneForceField<gpu::cuda::CudaVec3f1Types>::addForce(VecDeriv& f, const VecCoord& x, const VecDeriv& v)
00090 {
00091     data.plane.normal = planeNormal.getValue();
00092     data.plane.d = planeD.getValue();
00093     data.plane.stiffness = stiffness.getValue();
00094     data.plane.damping = damping.getValue();
00095     f.resize(x.size());
00096     data.penetration.resize(x.size());
00097     PlaneForceFieldCuda3f1_addForce(x.size(), &data.plane, data.penetration.deviceWrite(), f.deviceWrite(), x.deviceRead(), v.deviceRead());
00098 }
00099 
00100 template <>
00101 void PlaneForceField<gpu::cuda::CudaVec3f1Types>::addDForce(VecDeriv& df, const VecCoord& dx, double kFactor, double /*bFactor*/)
00102 {
00103     df.resize(dx.size());
00104     double stiff = data.plane.stiffness;
00105     data.plane.stiffness *= kFactor;
00106     PlaneForceFieldCuda3f1_addDForce(dx.size(), &data.plane, data.penetration.deviceRead(), df.deviceWrite(), dx.deviceRead());
00107     data.plane.stiffness = stiff;
00108 }
00109 
00110 
00111 } // namespace forcefield
00112 
00113 } // namespace component
00114 
00115 } // namespace sofa
00116 
00117 #endif

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