baoab.cl 4.97 KB
Newer Older
1
enum {VelScale, NoiseScale};
2
3

/**
peastman's avatar
peastman committed
4
 * Perform the first part of BAOAB integration: velocity half step, then position half step.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 */

__kernel void integrateBAOABPart1(__global mixed4* restrict velm, __global const real4* restrict force, __global mixed4* restrict posDelta,
        __global mixed4* restrict oldDelta, __global const mixed2* restrict dt) {
    mixed halfdt = 0.5*dt[0].y;
    for (int index = get_global_id(0); index < NUM_ATOMS; index += get_global_size(0)) {
        mixed4 velocity = velm[index];
        if (velocity.w != 0.0) {
            velocity.x += halfdt*velocity.w*force[index].x;
            velocity.y += halfdt*velocity.w*force[index].y;
            velocity.z += halfdt*velocity.w*force[index].z;
            velm[index] = velocity;
            mixed4 delta = halfdt*velocity;
            posDelta[index] = delta;
            oldDelta[index] = delta;
        }
    }
}

/**
peastman's avatar
peastman committed
25
26
 * Perform the second part of BAOAB integration: apply constraint forces to velocities, then interact with heat bath,
 * then position half step.
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 */

__kernel void integrateBAOABPart2(__global real4* restrict posq, __global real4* restrict posqCorrection, __global mixed4* restrict velm, __global mixed4* restrict posDelta,
        __global mixed4* restrict oldDelta, __global const mixed* restrict paramBuffer, __global const mixed2* restrict dt, __global const float4* restrict random, unsigned int randomIndex) {
    mixed vscale = paramBuffer[VelScale];
    mixed noisescale = paramBuffer[NoiseScale];
    mixed halfdt = 0.5*dt[0].y;
    mixed invHalfdt = 1/halfdt;
    int index = get_global_id(0);
    randomIndex += index;
    while (index < NUM_ATOMS) {
        mixed4 velocity = velm[index];
        if (velocity.w != 0.0) {
            mixed4 delta = posDelta[index];
41
            mixed sqrtInvMass = SQRT(velocity.w);
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
            velocity.xyz += (delta.xyz-oldDelta[index].xyz)*invHalfdt;
            velocity.x = vscale*velocity.x + noisescale*sqrtInvMass*random[randomIndex].x;
            velocity.y = vscale*velocity.y + noisescale*sqrtInvMass*random[randomIndex].y;
            velocity.z = vscale*velocity.z + noisescale*sqrtInvMass*random[randomIndex].z;
            velm[index] = velocity;
#ifdef USE_MIXED_PRECISION
            real4 pos1 = posq[index];
            real4 pos2 = posqCorrection[index];
            mixed4 pos = (mixed4) (pos1.x+(mixed)pos2.x, pos1.y+(mixed)pos2.y, pos1.z+(mixed)pos2.z, pos1.w);
#else
            real4 pos = posq[index];
#endif
            pos.xyz += delta.xyz;
#ifdef USE_MIXED_PRECISION
            posq[index] = convert_real4(pos);
            posqCorrection[index] = (real4) (pos.x-(real) pos.x, pos.y-(real) pos.y, pos.z-(real) pos.z, 0);
#else
            posq[index] = pos;
#endif
            delta = halfdt*velocity;
            posDelta[index] = delta;
            oldDelta[index] = delta;
        }
        randomIndex += get_global_size(0);
        index += get_global_size(0);
    }
}

/**
peastman's avatar
peastman committed
71
72
 * Perform the third part of BAOAB integration: apply constraint forces to velocities, then record
 * the constrained positions in preparation for computing forces.
73
74
75
 */

__kernel void integrateBAOABPart3(__global real4* restrict posq, __global real4* restrict posqCorrection, __global mixed4* restrict velm,
76
         __global mixed4* restrict posDelta, __global mixed4* restrict oldDelta, __global const mixed2* restrict dt) {
77
78
79
80
81
82
    mixed halfdt = 0.5*dt[0].y;
    mixed invHalfdt = 1/halfdt;
    for (int index = get_global_id(0); index < NUM_ATOMS; index += get_global_size(0)) {
        mixed4 velocity = velm[index];
        if (velocity.w != 0.0) {
            mixed4 delta = posDelta[index];
83
84
85
            velocity.x += (delta.x-oldDelta[index].x)*invHalfdt;
            velocity.y += (delta.y-oldDelta[index].y)*invHalfdt;
            velocity.z += (delta.z-oldDelta[index].z)*invHalfdt;
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
            velm[index] = velocity;
#ifdef USE_MIXED_PRECISION
            real4 pos1 = posq[index];
            real4 pos2 = posqCorrection[index];
            mixed4 pos = (mixed4) (pos1.x+(mixed)pos2.x, pos1.y+(mixed)pos2.y, pos1.z+(mixed)pos2.z, pos1.w);
#else
            real4 pos = posq[index];
#endif
            pos.xyz += delta.xyz;
#ifdef USE_MIXED_PRECISION
            posq[index] = convert_real4(pos);
            posqCorrection[index] = (real4) (pos.x-(real) pos.x, pos.y-(real) pos.y, pos.z-(real) pos.z, 0);
#else
            posq[index] = pos;
#endif
        }
    }
}
104
105

/**
peastman's avatar
peastman committed
106
 * Perform the fourth part of BAOAB integration: velocity half step.
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 */

__kernel void integrateBAOABPart4(__global mixed4* restrict velm, __global const real4* restrict force, __global const mixed2* restrict dt) {
    mixed halfdt = 0.5*dt[0].y;
    for (int index = get_global_id(0); index < NUM_ATOMS; index += get_global_size(0)) {
        mixed4 velocity = velm[index];
        if (velocity.w != 0.0) {
            velocity.x += halfdt*velocity.w*force[index].x;
            velocity.y += halfdt*velocity.w*force[index].y;
            velocity.z += halfdt*velocity.w*force[index].z;
            velm[index] = velocity;
        }
    }
}