andersenThermostat.cl 1.05 KB
Newer Older
1
2
3
4
/**
 * Apply the Andersen thermostat to adjust particle velocities.
 */

5
__kernel void applyAndersenThermostat(float collisionFrequency, float kT, __global mixed4* velm, __global const mixed2* restrict stepSize, __global const float4* restrict random,
6
        unsigned int randomIndex, __global const int* restrict atomGroups) {
7
8
    float collisionProbability = (float) (1.0f-exp(-collisionFrequency*stepSize[0].y));
    float randomRange = (float) erf(collisionProbability/exp(2.0f));
9
    for (int index = get_global_id(0); index < NUM_ATOMS; index += get_global_size(0)) {
10
        mixed4 velocity = velm[index];
11
12
        float4 selectRand = random[randomIndex+atomGroups[index]];
        float4 velRand = random[randomIndex+index];
13
        real scale = (selectRand.w > -randomRange && selectRand.w < randomRange ? 0 : 1);
14
        real add = (1-scale)*sqrt(kT*velocity.w);
15
16
17
        velocity.x = scale*velocity.x + add*velRand.x;
        velocity.y = scale*velocity.y + add*velRand.y;
        velocity.z = scale*velocity.z + add*velRand.z;
18
19
20
        velm[index] = velocity;
    }
}