Skip to content

Commit

Permalink
complete
Browse files Browse the repository at this point in the history
  • Loading branch information
dorchard committed Oct 15, 2012
1 parent 7c66a68 commit db97a72
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 40 deletions.
29 changes: 20 additions & 9 deletions fortran/boundary.f90
Expand Up @@ -131,15 +131,26 @@ subroutine apply_boundary_conditions (u, v, flag, t)
u(0, 1:jmax) = ui
v(0, 1:jmax) = 2*vi-v(1,1:jmax)

! silly tricks to drop pieces of high flow in at certain points during the sim - fun for
if (mod(t, 4.0) < 0.4 .and. t > 0.5) then
do i = -1, 1, 1
do j = -1, 1, 1
u(mod(floor(t*10.0+i),imax),mod(floor(t*5+j),jmax)) = 1
v(mod(floor(t*10.0+i),imax),mod(floor(t*5+j),jmax)) = 1
end do
end do
end if
! code for a conflicting flow coming in from the opposite side
!if (t < 45) then
! u(imax, 1:jmax) = -ui
! u(imax-1, 1:jmax) = -ui
! u(imax+1, 1:jmax) = -ui
!else
! u(imax,0:jmax+1) = u(imax-1,0:jmax+1)
!end if


! silly tricks to drop pieces of high flow in at certain points during the sim - for fun
!if (mod(t, 4.0) < 0.4 .and. t > 0.5) then
! do i = -1, 1, 1
! do j = -1, 1, 1
! u(mod(floor(t*10.0+i),imax),mod(floor(t*5+j),jmax)) = 1
! v(mod(floor(t*10.0+i),imax),mod(floor(t*5+j),jmax)) = 1
! end do
! end do
!end if

end subroutine


Expand Down
14 changes: 14 additions & 0 deletions fortran/build-vid
@@ -0,0 +1,14 @@
#!/bin/bash
cd $1
for f in *.ppm
do
if [ ! -e "`basename $f ppm`jpg" ]
then
echo Converting $f
convert -quality 100 $f `basename $f ppm`jpg
fi
done
ffmpeg -f image2 -i %06d.jpg -b 800k $1.mpeg
mv $1.mpeg ../.
cd ../.

2 changes: 1 addition & 1 deletion fortran/helpers.f90
Expand Up @@ -15,7 +15,7 @@ module helpers
real, parameter :: Re = 150.0, ui = 1.0, vi = 0.0

integer, parameter :: imax = 660, jmax = 120, outputFlag = 1, output_freq = 10, itermax = 10
real, parameter :: output_freqt = 0.04
real, parameter :: output_freqt = 0.05
real, parameter :: xlength = 22.0, ylength = 4.1
real, parameter :: delx = xlength/imax, dely = ylength/jmax

Expand Down
23 changes: 12 additions & 11 deletions fortran/init.f90
Expand Up @@ -29,17 +29,18 @@ subroutine initFlag(delx, dely, flag, ibound)
flag(i,j) = C_B
end if

x1 = (i-0.5)*delx - mx*4
y1 = (j-0.5)*dely - my*1.25
if (x1*x1 + y1*y1 <= rad1*rad1) then
flag(i,j) = C_B
end if

x1 = (i-0.5)*delx - mx*3
y1 = (j-0.5)*dely - my*0.5
if (x1*x1 + y1*y1 <= rad1*rad1) then
flag(i,j) = C_B
end if
! Some code for adding a few more circular masks near-by
!x1 = (i-0.5)*delx - mx*4
!y1 = (j-0.5)*dely - my*1.25
!if (x1*x1 + y1*y1 <= rad1*rad1) then
! flag(i,j) = C_B
!end if
!
!x1 = (i-0.5)*delx - mx*3
!y1 = (j-0.5)*dely - my*0.5
!if (x1*x1 + y1*y1 <= rad1*rad1) then
! flag(i,j) = C_B
!end if

end do
end do
Expand Down
28 changes: 11 additions & 17 deletions fortran/main.f90
Expand Up @@ -15,10 +15,6 @@ program navier

implicit none

type::data_t
integer::d
end type

character(10) :: outname = "output"

real :: t = 0, res = 0, del_t = 0.003, t_count = 0.0
Expand All @@ -29,11 +25,6 @@ program navier
real rhs(0:imax+1, 0:jmax+1), f(0:imax+1, 0:jmax+1), g(0:imax+1, 0:jmax+1)
integer flag(0:imax+1, 0:jmax+1)

!do i = 0, imax+1, 1
! do j = 0, jmax+1, 1
! u
! end do
!end do
u = ui
v = vi
p = 0.0
Expand Down Expand Up @@ -68,15 +59,18 @@ program navier

call apply_boundary_conditions(u, v, flag, t)

if (toLogical(outputFlag) .and. (t >= t_count)) then
call write_ppm(u, v, p, flag, output_counter, outname)
output_counter = output_counter + 1
t_count = t_count + output_freqt
end if

!if (toLogical(outputFlag) .and. (mod(iters, output_freq) == 0)) then
! call write_ppm(u, v, p, flag, iters, outname)
! An alternate way to print output using the simulation time
!if (toLogical(outputFlag) .and. (t >= t_count)) then
! call write_ppm(u, v, p, flag, output_counter, outname)
! output_counter = output_counter + 1
! t_count = t_count + output_freqt
!end if

if (toLogical(outputFlag) .and. (mod(iters, output_freq) == 0)) then
call write_ppm(u, v, p, flag, iters, outname)
output_counter = output_counter + 1
t_count = t_count + output_freqt
end if

t = t + del_t
iters = iters + 1
Expand Down
11 changes: 11 additions & 0 deletions fortran/output.f90
Expand Up @@ -47,6 +47,17 @@ subroutine write_ppm (u, v, p, flag, iters, outname)
r = (abs(zval/12.6)**0.4) * 255
g = r
b = r
if (r > 255) then
if (r < 510) then
g = 255 - (r - 255)
b = 255 - (r - 255)
r = 255
else
b = 255 - (r - 510)
g = 255
r = 255
end if
end if
end if
write(8,"(A1,A1,A1,$)") char(r), char(g), char(b)
end do
Expand Down
4 changes: 2 additions & 2 deletions fortran/simulation.f90
Expand Up @@ -15,7 +15,7 @@ subroutine compute_tentative_velocity(u, v, f, g, flag, del_t)
do i = 1, (imax-1)
do j = 1, jmax
! only if both adjacent cells are fluid cells */
if (toLogical(iand(flag(i,j), C_F)) .and. toLogical(iand(flag(i,j), C_F))) then
if (toLogical(iand(flag(i,j), C_F)) .and. toLogical(iand(flag(i+1,j), C_F))) then

du2dx = ((u(i,j)+u(i+1,j))*(u(i,j)+u(i+1,j))+ &
gamma*abs(u(i,j)+u(i+1,j))*(u(i,j)-u(i+1,j))- &
Expand All @@ -40,7 +40,7 @@ subroutine compute_tentative_velocity(u, v, f, g, flag, del_t)
do i = 1, imax
do j = 1, (jmax-1)
! only if both adjacent cells are fluid cells
if (toLogical(iand(flag(i,j), C_F)) .and. toLogical(iand(flag(i,j), C_F))) then
if (toLogical(iand(flag(i,j), C_F)) .and. toLogical(iand(flag(i,j+1), C_F))) then

duvdx = ((u(i,j)+u(i,j+1))*(v(i,j)+v(i+1,j))+ &
gamma*abs(u(i,j)+u(i,j+1))*(v(i,j)-v(i+1,j))- &
Expand Down

0 comments on commit db97a72

Please sign in to comment.