Next: Complementary Error Function Up: Appendix A: Code Previous: Self Interaction Term   Contents

Real Space Term

```c **********************************************************************
c     selfTerm.F
c **********************************************************************
subroutine  CalcReal
c **********************************************************************
use global_parameters
use scalars
use serial_arrays
use pmeVar

implicit none
integer i, j, k
real dX, dY, dZ, dsq, d
real derfc

pi = two*asin(one)
rtPi = sqrt(pi)
rcutsq = rcut*rcut
realTerm = zero

c     calculate real sum using only terms within rcut
do i = 1, numa(0)
do j = 0, numa(0)
if (i .ne. j) then
c     nested ifs are used to reduce the array iterations that must be computed
c     if the difference in x, y, or z coordinate alone is greater than rcut

c     minimum image is handled peacewise as each term is evaluated to be less
c     than rcut

dX = atom(1, i) - atom(1, j)
dX = dX - anint(dX)
if (abs(dX) < rcut) then
dY = atom(2, i) - atom(2, j)
dY = dY - anint(dY)
if (abs(dY) < rcut) then
dZ = atom(3, i) - atom(3, j)
dZ = dZ - anint(dZ)
if (abs(dZ) < rcut) then
dsq = dX*dX + dY*dY + dZ*dZ
if (dsq < rcutsq) then
d = sqrt(dsq)
if (d .ne. 0) then
realTerm = realTerm + derfc(alpha*d)/d

end if
endif
endif
endif
endif
end if
end do
end do

return

end
```

Subsections

Thomas G Dimiduk 2004-04-15