coulombLennardJones.cl 2.02 KB
Newer Older
1
#if USE_EWALD
2
3
4
5
6
7
8
9
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;
    float erfcAlphaR = erfc(alphaR);
    float tempForce = 0.0f;
    if (needCorrection) {
        // Subtract off the part of this interaction that was included in the reciprocal space contribution.
10

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