customBondForce.cl 1.09 KB
Newer Older
1
2
3
4
5
/**
 * Compute custom bond forces.
 */

__kernel void computeCustomBondForces(int numAtoms, int numBonds, __global float4* forceBuffers, __global float* energyBuffer,
6
        __global float4* posq, __global int4* indices
7
8
        EXTRA_ARGUMENTS) {
    float energy = 0.0f;
9
10
    for (int index = get_global_id(0); index < numBonds; index += get_global_size(0)) {
        // Look up the data for this bond.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

        int4 atoms = indices[index];
        float4 delta = posq[atoms.y]-posq[atoms.x];

        // Compute the force.

        float r = sqrt(delta.x*delta.x + delta.y*delta.y + delta.z*delta.z);
        COMPUTE_FORCE
        delta.xyz *= -dEdR/r;

        // Record the force on each of the two atoms.

        unsigned int offsetA = atoms.x+atoms.z*numAtoms;
        unsigned int offsetB = atoms.y+atoms.w*numAtoms;
        float4 forceA = forceBuffers[offsetA];
        float4 forceB = forceBuffers[offsetB];
        forceA.xyz -= delta.xyz;
        forceB.xyz += delta.xyz;
        forceBuffers[offsetA] = forceA;
        forceBuffers[offsetB] = forceB;
    }
    energyBuffer[get_global_id(0)] += energy;
}