Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ program tcell
double precision, allocatable :: y(:,:)
double precision, allocatable :: z(:,:)

allocate(random_number_table(ncells,npositions,nveldim))
associate(nsteps => npositions-1)
allocate(random_number_table(ncells,nsteps,nveldim))
end associate
allocate(random_positions(ncells,ndim))
allocate(x(ncells,npositions))
allocate(y(ncells,npositions))
Expand All @@ -25,10 +27,10 @@ program tcell

call initialize_positions(x(:,1),y(:,1),z(:,1),random_positions)

call create_distribution(vel,cumulative_distribution,nintervals)
call create_distribution(vel,cumulative_distribution)

call random_number(random_number_table)

call move_tcells(x,y,z,vel,cumulative_distribution,random_number_table,ncells,npositions,nintervals)
call move_tcells(x,y,z,vel,cumulative_distribution,random_number_table)

end program
3 changes: 1 addition & 2 deletions src/tcelsim/distribution_m.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ module distribution_m

interface

module subroutine create_distribution(vel,cumulative_distribution,nintervals)
module subroutine create_distribution(vel,cumulative_distribution)

implicit none
integer, intent(in) :: nintervals
double precision, intent(out) :: cumulative_distribution(:)
double precision, intent(out) :: vel(:)

Expand Down
33 changes: 9 additions & 24 deletions src/tcelsim/distribution_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,16 @@

! Local variables
integer i
double precision sum,rr1
double precision, allocatable :: sample_distribution(:)

allocate(sample_distribution(nintervals))

! Create a distribution
sum = 0.d0
do i = 1,nintervals
call random_number(rr1)
sample_distribution(i) = rr1
sum = sum + sample_distribution(i)
end do

do i = 1,nintervals
sample_distribution(i) = sample_distribution(i)/sum
! Assign speeds to each distribution bin
vel(i) = dble(i)
end do

! Form the cumulative distribution
cumulative_distribution(1) = 0.d0
do i = 2,nintervals+1
cumulative_distribution(i) = cumulative_distribution(i-1) + &
sample_distribution(i-1)
end do

! Create a distribution
associate(nintervals => size(cumulative_distribution,1)-1)
allocate(sample_distribution(nintervals))
call random_number(sample_distribution)
sample_distribution = sample_distribution/ sum(sample_distribution)
vel = [(dble(i), i =1, nintervals)] ! Assign speeds to each distribution bin
cumulative_distribution = [(0.D0, sum(sample_distribution(1:i)), i=1,nintervals)] ! Form the cumulative distribution
end associate

end procedure create_distribution

Expand Down
3 changes: 1 addition & 2 deletions src/tcelsim/move_m.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module move_m

interface

module subroutine move_tcells(x,y,z,vel,cumulative_distribution,random_number_table,ncells,npositions,nintervals)
module subroutine move_tcells(x,y,z,vel,cumulative_distribution,random_number_table)
implicit none
integer, intent(in) :: ncells,npositions,nintervals
double precision, intent(in) :: random_number_table(:,:,:)
double precision, intent(inout) :: x(:,:)
double precision, intent(inout) :: y(:,:)
Expand Down
59 changes: 31 additions & 28 deletions src/tcelsim/move_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,43 @@

module procedure move_tcells
! Local variables
integer i,j,k
double precision dt
double precision, dimension(ncells,npositions-1) :: speed,rr2,rr3,rr4,sum

! Time step
dt = .1
integer i, j
double precision, allocatable, dimension(:,:) :: speed

rr2(:,:) = random_number_table(:,2:,2)
rr3(:,:) = random_number_table(:,2:,3)
rr4(:,:) = random_number_table(:,2:,4)
associate(ncells => size(random_number_table,1), nsteps => size(random_number_table,2) )
allocate(speed(ncells, nsteps))

do i = 1,ncells
do j = 2,npositions
! Sample from the distribution
do k = 1,nintervals
if (random_number_table(i,j,1) .ge. cumulative_distribution(k) .and. &
random_number_table(i,j,1) .lt. cumulative_distribution(k+1)) then
speed(i,j) = vel(k)
end if
end do
! Sample from the distribution
do concurrent(i = 1:ncells, j = 1:nsteps)
associate(k => findloc(random_number_table(i,j,1) >= cumulative_distribution, value=.true., dim=1))
speed(i,j) = vel(k)
end associate
end do
end do

! Create a random unit vector
block
! Time step
double precision, allocatable, dimension(:,:,:) :: dir
double precision, parameter :: dt = .1

! Create a random unit vector
dir = random_number_table(:, 1:nsteps, 2:4)

sum(:,:) = rr2(:,:) + rr3(:,:) + rr4(:,:)
rr2(:,:) = rr2(:,:)/sum(:,:)
rr3(:,:) = rr3(:,:)/sum(:,:)
rr4(:,:) = rr4(:,:)/sum(:,:)
associate(dir_mag => sqrt(dir(:,:,1)**2 +dir(:,:,2)**2 + dir(:,:,3)**2))
associate(dir_mag_ => merge(dir_mag, epsilon(dir_mag), dir_mag/=0.))
dir(:,:,1) = dir(:,:,1)/dir_mag_
dir(:,:,2) = dir(:,:,2)/dir_mag_
dir(:,:,3) = dir(:,:,3)/dir_mag_
end associate
end associate

! Use a forward Euler to advance the cell position
x(:,2:) = x(:,:) + dt*speed(:,:)*rr2(:,:)
y(:,2:) = y(:,:) + dt*speed(:,:)*rr3(:,:)
z(:,2:) = z(:,:) + dt*speed(:,:)*rr4(:,:)
! Use a forward Euler to advance the cell position
do i=1,nsteps
x(:,i+1) = x(:,i) + dt*speed(:,i)*dir(:,i,1)
y(:,i+1) = y(:,i) + dt*speed(:,i)*dir(:,i,2)
z(:,i+1) = z(:,i) + dt*speed(:,i)*dir(:,i,3)
end do
end block
end associate

end procedure move_tcells

Expand Down
3 changes: 1 addition & 2 deletions src/tcelsim/t_cell_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

module procedure initialize_positions

! Local variables
double precision, parameter :: scaling_factor = 100.

! Assign initial positions to T cells randomly in a [100x100x100] grid
! Assign initial positions to T cells randomly in a cube with sides of length scaling_factor
x = random_positions(:,1)*scaling_factor
y = random_positions(:,2)*scaling_factor
z = random_positions(:,3)*scaling_factor
Expand Down