-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenergy.f90
57 lines (37 loc) · 1.23 KB
/
energy.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
49
50
51
52
53
54
55
56
!Funtion to calculate potential energy, forces and kinetic energy
subroutine energy
use parameters
use variables, only: nn, xi, fi, vi, energia, en_kinet, box, temp
implicit none
integer(i4b) i, j
real(dp) r2, s_r2, s_r6, s_r12
real(dp),dimension(3)::dx, xo
energia = 0.d0
fi = 0.d0
!forces and potential energy
do i = 1,nn - 1
xo = xi(3*i - 2:3*i)
do j = i + 1,nn
dx = xo - xi(3*j - 2:3*j)
! Minimum image
dx(1) = dx(1) - dnint(dx(1)/box)*box
dx(2) = dx(2) - dnint(dx(2)/box)*box
dx(3) = dx(3) - dnint(dx(3)/box)*box
r2 = dot_product(dx,dx)
! Lennard-Jonnes
s_r2 = 1.d0/r2
s_r6 = s_r2*s_r2*s_r2
s_r12 = s_r6*s_r6
energia = energia + 4.d0*( s_r12 - s_r6 )
fi(3*i - 2:3*i) = fi(3*i - 2:3*i) + 24.d0*( 2.d0*s_r12 - s_r6 )*dx/r2
fi(3*j - 2:3*j) = fi(3*j - 2:3*j) - 24.d0*( 2.d0*s_r12 - s_r6 )*dx/r2
end do
end do
!kinetic energy
en_kinet = 0.d0
do i = 1, nn
en_kinet = en_kinet + vi(3*i - 2)**2 + vi(3*i - 1)**2 + vi(3*i)**2
end do
en_kinet = 0.5d0*en_kinet
temp = 2.d0*en_kinet/(3.d0*nn)
end subroutine energy