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

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