00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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);
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);
00048
00049
00050 }
00051
00052 }
00053
00054 }
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 )
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 )
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 }
00112
00113 }
00114
00115 }
00116
00117 #endif