Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.mrao.cam.ac.uk/~rachael/compphys/examples/cell_list.f90
Дата изменения: Fri Sep 30 14:20:14 2005
Дата индексирования: Tue Oct 2 11:39:41 2012
Кодировка:

Поисковые слова: р п р п р п р п р п р п р п р п р п
program simulation

implicit none

integer, parameter :: dp = kind(1.0d0)
integer, parameter :: npart = 100000 ! number of particles
integer, parameter :: max_list = 100 ! max number of particles per cell
integer, parameter :: ncell = 20 ! number of cells in one direction
real(dp) cell_size ! cell size
real(dp) posn(3, npart) ! particle positions
integer cell_num(ncell, ncell, ncell) ! number of particles in each cell
integer cell_list(max_list, ncell, ncell, ncell)
! index of particles in each cell

! set cell size
cell_size = 0.1d0

! randomise particle positions
call random_number(posn)
posn = posn * cell_size * ncell ! this is an array operation

! initialise cell list
call init_cell_list(npart, ncell, max_list, cell_size, posn, &
cell_num, cell_list)

! now go and do something interesting with it...

contains

subroutine init_cell_list(npart, ncell, max_list, cell_size, posn, &
cell_num, cell_list)

implicit none

integer, parameter :: dp = kind(1.0d0)

integer npart ! number of particles
integer ncell ! number of cells in one direction
integer max_list ! max number of particles per cell
real(dp) cell_size ! cell size
real(dp) posn(3, npart) ! particle positions
integer cell_num(ncell, ncell, ncell) ! number of particles in each cell
integer cell_list(max_list, ncell, ncell, ncell)
! index of particles in each cell

integer i, part, k, cell(3) ! local variables

! initialise the cell_num array
cell_num = 0

! loop over all particles
do part = 1, npart
do i = 1, 3
cell(i) = 1 + posn(i, part) / cell_size

! check for edges
cell(i) = min(cell(i), ncell)
cell(i) = max(cell(i), 1)

end do

! k is the number of particles already in this cell
k = cell_num(cell(1), cell(2), cell(3))

! check we don't exceed the array bounds
if (k == max_list) stop 'Increase max_list!'

! add the new particle to the list
k = k + 1
cell_list(k, cell(1), cell(2), cell(3)) = part
cell_num(cell(1), cell(2), cell(3)) = k

end do

end subroutine init_cell_list

end program simulation