coulombLennardJones.cl 2.36 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
13
14
15
    float erfcAlphaR = 0.0f;
    if (r2 < CUTOFF_SQUARED) {
        float normalized = ERFC_TABLE_SCALE*alphaR;
        int tableIndex = (int) normalized;
        float fract2 = normalized-tableIndex;
        float fract1 = 1.0f-fract2;
        erfcAlphaR = fract1*erfcTable[tableIndex] + fract2*erfcTable[tableIndex+1];
    }
    else if (needCorrection)
        erfcAlphaR = erfc(alphaR);
16
17
18
    float tempForce = 0.0f;
    if (needCorrection) {
        // Subtract off the part of this interaction that was included in the reciprocal space contribution.
19

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