-
Notifications
You must be signed in to change notification settings - Fork 182
/
main.F90
82 lines (58 loc) · 2.15 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
! Heat equation solver in 2D.
program heat_solve
use heat
use core
use io
use setup
use utilities
implicit none
real(dp), parameter :: a = 0.5 ! Diffusion constant
type(field) :: current, previous ! Current and previus temperature fields
real(dp) :: dt ! Time step
integer :: nsteps ! Number of time steps
integer, parameter :: image_interval = 100 ! Image output interval
type(parallel_data) :: parallelization
integer :: ierr
integer :: iter
real(dp) :: average_temp ! Average temperature
real(kind=dp) :: start, stop ! Timers
! TODO start: initialize MPI
! TODO end
call initialize(current, previous, nsteps, parallelization)
! Draw the picture of the initial state
call write_field(current, 0, parallelization)
average_temp = average(current, parallelization)
if (parallelization % rank == 0) then
write(*,'(A, I5, A, I5, A, I5)') 'Simulation grid: ', current%nx_full, ' x ', &
& current%ny_full, ' time steps: ', nsteps
write(*,'(A, I5)') 'MPI processes: ', parallelization%size
write(*,'(A,F9.6)') 'Average temperature at start: ', average_temp
end if
! Largest stable time step
dt = current%dx**2 * current%dy**2 / &
& (2.0 * a * (current%dx**2 + current%dy**2))
! Main iteration loop, save a picture every
! image_interval steps
start = mpi_wtime()
do iter = 1, nsteps
call exchange(previous, parallelization)
call evolve(current, previous, a, dt)
if (mod(iter, image_interval) == 0) then
call write_field(current, iter, parallelization)
end if
call swap_fields(current, previous)
end do
stop = mpi_wtime()
! Average temperature for reference
average_temp = average(previous, parallelization)
if (parallelization % rank == 0) then
write(*,'(A,F7.3,A)') 'Iteration took ', stop - start, ' seconds.'
write(*,'(A,F9.6)') 'Average temperature: ', average_temp
if (command_argument_count() == 0) then
write(*,'(A,F9.6)') 'Reference value with default arguments: ', 59.281239
end if
end if
call finalize(current, previous)
! TODO start: finalize MPI
! TODO end
end program heat_solve