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

5
extern "C" __global__ void applyAndersenThermostat(float collisionFrequency, float kT, mixed4* velm, const mixed4* __restrict__ stepSize, const float4* __restrict__ random,
6
        unsigned int randomIndex, const int* __restrict__ atomGroups) {
7
    float collisionProbability = 1.0f-expf(-(float) (collisionFrequency*stepSize[0].y));
8
9
    float randomRange = erff(collisionProbability/sqrtf(2.0f));
    for (int index = blockIdx.x*blockDim.x+threadIdx.x; index < NUM_ATOMS; index += blockDim.x*gridDim.x) {
10
        mixed4 velocity = velm[index];
11
12
13
14
15
16
17
18
19
20
        float4 selectRand = random[randomIndex+atomGroups[index]];
        float4 velRand = random[randomIndex+index];
        real scale = (selectRand.w > -randomRange && selectRand.w < randomRange ? 0 : 1);
        real add = (1-scale)*SQRT(kT*velocity.w);
        velocity.x = scale*velocity.x + add*velRand.x;
        velocity.y = scale*velocity.y + add*velRand.y;
        velocity.z = scale*velocity.z + add*velRand.z;
        velm[index] = velocity;
    }
}