Skip to content

Instantly share code, notes, and snippets.

@saifthe1
Created October 29, 2013 11:01
Show Gist options
  • Save saifthe1/7212579 to your computer and use it in GitHub Desktop.
Save saifthe1/7212579 to your computer and use it in GitHub Desktop.
Velocity Verlet Integrator called from Velocity Verlet Integrator class
#ifdef SUPPORTS_DOUBLE_PRECISION
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#endif
/**
* Perform the first step of velocity verlet integration.
*/
__kernel void velocityVerletPart1(int numAtoms,
__global const float* deltaT,
__global float4* restrict posq,
__global float4* restrict velm,
__global const float4* restrict forces
) {
float dtPos = deltaT[0];
float dtVel = 0.5f*deltaT[0];
unsigned int index = get_global_id(0);
if(index < numAtoms)
{
//store the velocity locally
float4 velocity = velm[index];
if(velocity.w != 0.0)
{
float4 pos = posq[index];
velocity.xyz += forces[index].xyz*dtVel*velocity.w;
pos.xyz += velocity.xyz * dtPos;
velm[index] = velocity;
posq[index] = pos;
}
}
}
/**
* Perform the second step of velocity verlet integration.
*/
__kernel void velocityVerletPart2(int numAtoms,
__global const float* deltaT,
__global float4* restrict velm,
__global const float4* restrict forces
) {
float dtVel = 0.5f*deltaT[0];
unsigned int index = get_global_id(0);
if(index < numAtoms)
{
//store the velocity locally
float4 velocity = velm[index];
if(velocity.w != 0.0)
{
velocity.xyz += forces[index].xyz*dtVel*velocity.w;
velm[index] = velocity;
}
}//end if
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment