forked from vegalorena24/simulacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforces_initialize.f90
69 lines (52 loc) · 1.41 KB
/
forces_initialize.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
57
58
59
60
61
62
63
64
65
66
67
68
69
program initilize
implicit none
real*8 :: L
real*8, dimension(:,:), allocatable :: pos
integer :: i, N
N = 1000
L = 40
allocate(pos(N,3))
call initialize(L,pos)
open(unit=123, file="forces_positions.xyz", status="replace", action="write")
write(unit=123,fmt='(i10,f20.10)') N, L
do i = 1, N
write(unit=123, fmt='(3f20.10)') pos(i,:)
end do
close(unit=123)
contains
subroutine initialize(L,mat)
real*8, intent(in) :: L
real*8, dimension(:,:), intent(out) :: mat
integer :: n, i
real*8 :: min_distance
n = size(mat,1)
mat = 0.0
do i = 1, n
min_distance = -1.0 ! Any number smaller than T
do while (min_distance < 1.0)
call random_number(mat(i,:))
mat(i,:) = L*mat(i,:) - L/2.0d0
min_distance = distancemin(mat,i)
enddo
enddo
end subroutine
function distancemin(mat,i) result(em)
! This function calculates the distances between all atoms and
! returns the value of the smaller distance.
real*8, dimension(:,:), intent(out) :: mat
integer, intent(in) :: i
integer :: j
real*8, dimension(3) :: vec
real*8 :: em, distance
em = 1000.0
do j = 1, i
if (i /= j) then
vec = mat(i,:) - mat(j,:)
distance = sqrt(sum(vec**2))
if (distance < em) then
em = distance
endif
endif
enddo
end function
end program