"plugins/drude/platforms/common/src/kernels/drudeLangevin.cc" did not exist on "38beeefe8d134e8dbf8c37f0a2814eba92627a3a"
ccma.cl 5.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
mixed4 loadPos(__global const real4* restrict posq, __global const real4* restrict posqCorrection, int index) {
#ifdef USE_MIXED_PRECISION
    real4 pos1 = posq[index];
    real4 pos2 = posqCorrection[index];
    return (mixed4) (pos1.x+(mixed)pos2.x, pos1.y+(mixed)pos2.y, pos1.z+(mixed)pos2.z, pos1.w);
#else
    return posq[index];
#endif
}
10
11
12
/**
 * Compute the direction each constraint is pointing in.  This is called once at the beginning of constraint evaluation.
 */
13
14
__kernel void computeConstraintDirections(__global const int2* restrict constraintAtoms, __global mixed4* restrict constraintDistance,
        __global const real4* restrict atomPositions, __global const real4* restrict posCorrection, __global int* restrict converged) {
15
16
17
18
    for (int index = get_global_id(0); index < NUM_CONSTRAINTS; index += get_global_size(0)) {
        // Compute the direction for this constraint.

        int2 atoms = constraintAtoms[index];
19
20
21
        mixed4 dir = constraintDistance[index];
        mixed4 oldPos1 = loadPos(atomPositions, posCorrection, atoms.x);
        mixed4 oldPos2 = loadPos(atomPositions, posCorrection, atoms.y);
22
23
24
25
26
        dir.x = oldPos1.x-oldPos2.x;
        dir.y = oldPos1.y-oldPos2.y;
        dir.z = oldPos1.z-oldPos2.z;
        constraintDistance[index] = dir;
    }
27
28
29
30
    if (get_global_id(0) == 0) {
        converged[0] = 1;
        converged[1] = 0;
    }
31
32
33
34
35
}

/**
 * Compute the force applied by each constraint.
 */
36
__kernel void computeConstraintForce(__global const int2* restrict constraintAtoms, __global const mixed4* restrict constraintDistance, __global const mixed4* restrict atomPositions,
Peter Eastman's avatar
Peter Eastman committed
37
        __global const mixed* restrict reducedMass, __global mixed* restrict delta1, __global int* restrict converged, __global int* restrict hostConvergedFlag, mixed tol, int iteration) {
38
    __local int groupConverged;
Peter Eastman's avatar
Peter Eastman committed
39
    if (converged[1-iteration%2]) {
Peter Eastman's avatar
Peter Eastman committed
40
        if (get_global_id(0) == 0) {
Peter Eastman's avatar
Peter Eastman committed
41
            converged[iteration%2] = 1;
Peter Eastman's avatar
Peter Eastman committed
42
43
            hostConvergedFlag[0] = 1;
        }
Peter Eastman's avatar
Peter Eastman committed
44
45
        return; // The constraint iteration has already converged.
    }
46
47
48
    if (get_local_id(0) == 0)
        groupConverged = 1;
    barrier(CLK_LOCAL_MEM_FENCE);
49
50
    mixed lowerTol = 1-2*tol+tol*tol;
    mixed upperTol = 1+2*tol+tol*tol;
51
52
53
54
    for (int index = get_global_id(0); index < NUM_CONSTRAINTS; index += get_global_size(0)) {
        // Compute the force due to this constraint.

        int2 atoms = constraintAtoms[index];
55
56
        mixed4 dir = constraintDistance[index];
        mixed4 rp_ij = atomPositions[atoms.x]-atomPositions[atoms.y];
57
#ifndef CONSTRAIN_VELOCITIES
58
        rp_ij.xyz += dir.xyz;
59
#endif
60
61
        mixed rrpr = rp_ij.x*dir.x + rp_ij.y*dir.y + rp_ij.z*dir.z;
        mixed d_ij2 = dir.x*dir.x + dir.y*dir.y + dir.z*dir.z;
62
#ifdef CONSTRAIN_VELOCITIES
63
        delta1[index] = -2*reducedMass[index]*rrpr/d_ij2;
64
65
66
67
68
69
70
71

        // See whether it has converged.

        if (groupConverged && fabs(delta1[index]) > tol) {
            groupConverged = 0;
            converged[iteration%2] = 0;
        }
#else
72
73
74
        mixed rp2 = rp_ij.x*rp_ij.x + rp_ij.y*rp_ij.y + rp_ij.z*rp_ij.z;
        mixed dist2 = dir.w*dir.w;
        mixed diff = dist2 - rp2;
75
76
77
78
        delta1[index] = (rrpr > d_ij2*1e-6f ? reducedMass[index]*diff/rrpr : 0.0f);

        // See whether it has converged.

79
80
        if (groupConverged && (rp2 < lowerTol*dist2 || rp2 > upperTol*dist2)) {
            groupConverged = 0;
Peter Eastman's avatar
Peter Eastman committed
81
            converged[iteration%2] = 0;
82
        }
83
#endif
84
85
86
87
88
89
    }
}

/**
 * Multiply the vector of constraint forces by the constraint matrix.
 */
90
91
__kernel void multiplyByConstraintMatrix(__global const mixed* restrict delta1, __global mixed* restrict delta2, __global const int* restrict constraintMatrixColumn,
        __global const mixed* restrict constraintMatrixValue, __global const int* restrict converged, int iteration) {
Peter Eastman's avatar
Peter Eastman committed
92
    if (converged[iteration%2])
93
94
95
96
97
        return; // The constraint iteration has already converged.

    // Multiply by the inverse constraint matrix.

    for (int index = get_global_id(0); index < NUM_CONSTRAINTS; index += get_global_size(0)) {
98
        mixed sum = 0;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
        for (int i = 0; ; i++) {
            int element = index+i*NUM_CONSTRAINTS;
            int column = constraintMatrixColumn[element];
            if (column >= NUM_CONSTRAINTS)
                break;
            sum += delta1[column]*constraintMatrixValue[element];
        }
        delta2[index] = sum;
    }
}

/**
 * Update the atom positions based on constraint forces.
 */
113
114
__kernel void updateAtomPositions(__global const int* restrict numAtomConstraints, __global const int* restrict atomConstraints, __global const mixed4* restrict constraintDistance,
        __global mixed4* restrict atomPositions, __global const mixed4* restrict velm, __global const mixed* restrict delta1, __global const mixed* restrict delta2, __global int* restrict converged, int iteration) {
Peter Eastman's avatar
Peter Eastman committed
115
116
117
    if (get_global_id(0) == 0)
        converged[1-iteration%2] = 1;
    if (converged[iteration%2])
118
        return; // The constraint iteration has already converged.
119
    mixed damping = (iteration < 2 ? 0.5f : 1.0f);
120
121
122
    for (int index = get_global_id(0); index < NUM_ATOMS; index += get_global_size(0)) {
        // Compute the new position of this atom.

123
124
        mixed4 atomPos = atomPositions[index];
        mixed invMass = velm[index].w;
125
126
127
128
129
        int num = numAtomConstraints[index];
        for (int i = 0; i < num; i++) {
            int constraint = atomConstraints[index+i*NUM_ATOMS];
            bool forward = (constraint > 0);
            constraint = (forward ? constraint-1 : -constraint-1);
130
            mixed constraintForce = damping*invMass*delta2[constraint];
131
            constraintForce = (forward ? constraintForce : -constraintForce);
132
            mixed4 dir = constraintDistance[constraint];
133
134
135
136
137
138
139
            atomPos.x += constraintForce*dir.x;
            atomPos.y += constraintForce*dir.y;
            atomPos.z += constraintForce*dir.z;
        }
        atomPositions[index] = atomPos;
    }
}