-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirect_sum_grav.f90
48 lines (41 loc) · 1.07 KB
/
direct_sum_grav.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
!!----------------------------------------------------------------------
!! Calculates the gravitational force by a direct summation over the
!! particles.
!!
!! Use this to check the accuracy of the tree code
!!
!!----------------------------------------------------------------------
SUBROUTINE direct_sum_grav
USE dimen_mhd
USE debug
USE loguns
USE part
USE gravity
IMPLICIT NONE
INTEGER :: i,j
REAL, DIMENSION(ndim) :: dx,term
REAL :: rij,rij2,pmassi
!
!--allow for tracing flow
!
IF (trace) WRITE(iprint,*) ' Entering subroutine direct_sum_grav'
!
!--reset forces initially
!
fgrav = 0.
!
!--calculate gravitational force by direct summation
!
DO i=1,npart
pmassi = pmass(i)
DO j=i+1,npart
dx = x(:,i) - x(:,j)
rij2 = DOT_PRODUCT(dx,dx) + 0.01**2
rij = SQRT(rij2)
term(:) = dx(:)/(rij*rij2)
fgrav(:,i) = fgrav(:,i) - pmass(j)*term(:) ! note that fgrav should be
fgrav(:,j) = fgrav(:,j) + pmassi*term(:) ! *added* to the force
ENDDO
ENDDO
RETURN
END SUBROUTINE direct_sum_grav