-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsetup.F90
More file actions
121 lines (93 loc) · 3.17 KB
/
Copy pathsetup.F90
File metadata and controls
121 lines (93 loc) · 3.17 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
! Setup routines for heat equation solver
module setup
contains
subroutine initialize(previous, current, nsteps)
use heat
use utilities
use io
implicit none
type(field), intent(out) :: previous, current
integer, intent(out) :: nsteps
integer :: rows, cols
logical :: using_input_file
character(len=85) :: input_file, arg ! Input file name and command line arguments
! Default values for grid size and time steps
rows = 200
cols = 200
nsteps = 500
using_input_file = .false.
! Read in the command line arguments and
! set up the needed variables
select case(command_argument_count())
case(0) ! No arguments -> default values
case(1) ! One argument -> input file name
using_input_file = .true.
call get_command_argument(1, input_file)
case(2) ! Two arguments -> input file name and number of steps
using_input_file = .true.
call get_command_argument(1, input_file)
call get_command_argument(2, arg)
read(arg, *) nsteps
case(3) ! Three arguments -> rows, cols and nsteps
call get_command_argument(1, arg)
read(arg, *) rows
call get_command_argument(2, arg)
read(arg, *) cols
call get_command_argument(3, arg)
read(arg, *) nsteps
case default
call usage()
stop
end select
! Initialize the fields according the command line arguments
if (using_input_file) then
call read_field(previous, input_file)
call copy_fields(previous, current)
else
call set_field_dimensions(previous, rows, cols)
call set_field_dimensions(current, rows, cols)
call generate_field(previous)
call generate_field(current)
end if
end subroutine initialize
! Generate initial the temperature field. Pattern is x**2 + y**2
! with the origo in the center of the grid.
subroutine generate_field(field0)
use heat
implicit none
type(field), intent(inout) :: field0
real(dp) :: x, y
integer :: i, j
! The arrays for field contain also a halo region
allocate(field0%data(0:field0%nx+1, 0:field0%ny+1))
do j = 0, field0%ny + 1
y = (j - (field0%ny + 1) / 2.0) * field0%dy
do i = 0, field0%nx + 1
x = (i - (field0%nx + 1) / 2.0) * field0%dx
field0%data(i,j) = 100 - (x**2 + y**2)*50
end do
end do
end subroutine generate_field
! Clean up routine for field type
! Arguments:
! field0 (type(field)): field variable to be cleared
subroutine finalize(field0, field1)
use heat
implicit none
type(field), intent(inout) :: field0, field1
deallocate(field0%data)
deallocate(field1%data)
end subroutine finalize
! Helper routine that prints out a simple usage if
! user gives more than three arguments
subroutine usage()
implicit none
character(len=256) :: buf
call get_command_argument(0, buf)
write (*,'(A)') 'Usage:'
write (*,'(A, " (default values will be used)")') trim(buf)
write (*,'(A, " <filename>")') trim(buf)
write (*,'(A, " <filename> <nsteps>")') trim(buf)
write (*,'(A, " <rows> <cols> <nsteps>")') trim(buf)
end subroutine usage
end module setup