verlet.cl 1.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
 * Perform the first step of verlet integration.
 */

__kernel void integrateVerletPart1(int numAtoms, float dt, __global float4* posq, __global float4* velm, __global float4* force, __global float4* posDelta, __global float4* oldPos) {
    int index = get_global_id(0);
    while (index < numAtoms) {
        float4 pos = posq[index];
        float4 velocity = velm[index];
        oldPos[index] = pos;
        velocity.xyz += force[index].xyz*dt*velocity.w;
        pos.xyz = velocity.xyz*dt;
        posDelta[index] = pos;
        velm[index] = velocity;
        index += get_global_size(0);
    }
}

/**
 * Perform the second step of verlet integration.
 */

__kernel void integrateVerletPart2(int numAtoms, float dt, __global float4* posq, __global float4* velm, __global float4* posDelta) {
    int index = get_global_id(0);
    float oneOverDt = 1.0f/dt;
    while (index < numAtoms) {
        float4 pos = posq[index];
        float4 delta = posDelta[index];
        float4 velocity = velm[index];
        pos.xyz += delta.xyz;
        velocity.xyz = delta.xyz*oneOverDt;
        posq[index] = pos;
        velm[index] = velocity;
        index += get_global_size(0);
    }
}