coulombLennardJones.cl 2.37 KB
Newer Older
1
#if USE_EWALD
2
3
4
5
bool needCorrection = isExcluded && atom1 != atom2 && atom1 < NUM_ATOMS && atom2 < NUM_ATOMS;
if (!isExcluded || needCorrection) {
    const float prefactor = 138.935456f*posq1.w*posq2.w*invR;
    float alphaR = EWALD_ALPHA*r;
6
7
8
9
10
11
12
#ifdef USE_TABULATED_ERFC
    float normalized = ERFC_TABLE_SCALE*alphaR;
    int tableIndex = (int) normalized;
    float fract2 = normalized-tableIndex;
    float fract1 = 1.0f-fract2;
    float erfcAlphaR = fract1*read_imagef(erfcTable, sampler, (int2)(tableIndex, 0)).x + fract2*read_imagef(erfcTable, sampler, (int2)(tableIndex+1, 0)).x;
#else
13
    float erfcAlphaR = erfc(alphaR);
14
#endif
15
16
17
    float tempForce = 0.0f;
    if (needCorrection) {
        // Subtract off the part of this interaction that was included in the reciprocal space contribution.
18

19
20
21
22
        tempForce = -prefactor*((1.0f-erfcAlphaR)-alphaR*exp(-alphaR*alphaR)*TWO_OVER_SQRT_PI);
        tempEnergy += -prefactor*(1.0f-erfcAlphaR);
    }
    else if (r2 < CUTOFF_SQUARED) {
23
#if HAS_LENNARD_JONES
24
25
26
27
28
29
30
        float sig = sigmaEpsilon1.x + sigmaEpsilon2.x;
        float sig2 = invR*sig;
        sig2 *= sig2;
        float sig6 = sig2*sig2*sig2;
        float eps = sigmaEpsilon1.y*sigmaEpsilon2.y;
        tempForce = eps*(12.0f*sig6 - 6.0f)*sig6 + prefactor*(erfcAlphaR+alphaR*exp(-alphaR*alphaR)*TWO_OVER_SQRT_PI);
        tempEnergy += eps*(sig6 - 1.0f)*sig6 + prefactor*erfcAlphaR;
31
#else
32
33
        tempForce = prefactor*(erfcAlphaR+alphaR*exp(-alphaR*alphaR)*TWO_OVER_SQRT_PI);
        tempEnergy += prefactor*erfcAlphaR;
34
#endif
35
    }
36
    dEdR += tempForce*invR*invR;
37
38
}
#else
39
#ifdef USE_CUTOFF
40
if (!isExcluded && r2 < CUTOFF_SQUARED) {
41
42
43
#else
if (!isExcluded) {
#endif
44
45
    float tempForce = 0.0f;
  #if HAS_LENNARD_JONES
46
47
48
49
50
    float sig = sigmaEpsilon1.x + sigmaEpsilon2.x;
    float sig2 = invR*sig;
    sig2 *= sig2;
    float sig6 = sig2*sig2*sig2;
    float eps = sigmaEpsilon1.y*sigmaEpsilon2.y;
51
    tempForce = eps*(12.0f*sig6 - 6.0f)*sig6;
52
    tempEnergy += eps*(sig6 - 1.0f)*sig6;
53
54
55
  #endif
#if HAS_COULOMB
  #ifdef USE_CUTOFF
56
    const float prefactor = 138.935456f*posq1.w*posq2.w;
57
58
    tempForce += prefactor*(invR - 2.0f*REACTION_FIELD_K*r2);
    tempEnergy += prefactor*(invR + REACTION_FIELD_K*r2 - REACTION_FIELD_C);
59
  #else
60
    const float prefactor = 138.935456f*posq1.w*posq2.w*invR;
61
62
    tempForce += prefactor;
    tempEnergy += prefactor;
63
  #endif
64
65
66
#endif
    dEdR += tempForce*invR*invR;
}
67
#endif