- /* because we compute the softcore normally,
- we have to remove the ewald short range portion. Done outside of
- the states loop because this part doesn't depend on the scaled R */
-
-#ifdef GMX_DOUBLE
- /* Relative accuracy at R_ERF_R_INACC of 3e-10 */
-#define R_ERF_R_INACC 0.006
-#else
- /* Relative accuracy at R_ERF_R_INACC of 2e-5 */
-#define R_ERF_R_INACC 0.1
-#endif
- if (ewc*r > R_ERF_R_INACC)
- {
- VV = gmx_erf(ewc*r)*rinv;
- FF = rinv*rinv*(VV - ewc*M_2_SQRTPI*exp(-ewc*ewc*rsq));
- }
- else
- {
- VV = ewc*M_2_SQRTPI;
- FF = ewc*ewc*ewc*M_2_SQRTPI*(2.0/3.0 - 0.4*ewc*ewc*rsq);
- }
+ /* Because we compute the soft-core normally,
+ * we have to remove the Ewald short range portion.
+ * Done outside of the states loop because this part
+ * doesn't depend on the scaled R.
+ */
+ real rs, frac, f_lr;
+ int ri;
+
+ rs = rsq*rinv*tab_ewald_scale;
+ ri = (int)rs;
+ frac = rs - ri;
+ f_lr = (1 - frac)*tab_ewald_F[ri] + frac*tab_ewald_F[ri+1];
+ FF = f_lr*rinv;
+ VV = tab_ewald_V[ri] - tab_ewald_halfsp*frac*(tab_ewald_F[ri] + f_lr);