-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_setup.f90
106 lines (92 loc) · 3.3 KB
/
module_setup.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module setup
use precise
implicit none
interface initialise_fields
module procedure init_single, init_double
end interface initialise_fields
contains
subroutine init_single(nx, ny, old_solution, new_solution, info)
!--------------------------------------------------------------
! Purpose: Initializes single precision solution arrays
! Parameters:
! - nx, ny: dimensions of the data grid
! - old_solution: 2D array (single precision) for the old solution
! - new_solution: 2D array (single precision) for the new solution
! - info: integer status code (optional, for error handling)
!--------------------------------------------------------------
integer :: nx, ny
integer :: i, j, info
real, dimension(:, :), allocatable :: old_solution
real, dimension(:, :), allocatable :: new_solution
! Allocate memory for the solution arrays
allocate(old_solution(nx, ny), stat=info)
allocate(new_solution(nx, ny), stat=info)
! Initialize arrays to zero
DO j = 1, ny
DO i = 1, nx
old_solution(i, j) = 0
new_solution(i, j) = 0
END DO
END DO
! Set up boundary conditions
DO j = 1, ny
DO i = 1, nx
IF (j == 1) THEN
old_solution(i, j) = 1
new_solution(i, j) = 1
ELSE IF (j == ny) THEN
old_solution(i, j) = 1
new_solution(i, j) = 1
ELSE IF (i == 1) THEN
old_solution(i, j) = 1
new_solution(i, j) = 1
ELSE IF (i == nx) THEN
old_solution(i, j) = 1
new_solution(i, j) = 1
END IF
END DO
END DO
end subroutine init_single
subroutine init_double(nx, ny, old_solution, new_solution, info)
!--------------------------------------------------------------
! Purpose: Initializes double precision solution arrays
! Parameters:
! - nx, ny: dimensions of the data grid
! - old_solution: 2D array (double precision) for the old solution
! - new_solution: 2D array (double precision) for the new solution
! - info: integer status code (optional, for error handling)
!--------------------------------------------------------------
integer :: nx, ny
integer :: i, j, info
double precision, dimension(:, :), allocatable :: old_solution
double precision, dimension(:, :), allocatable :: new_solution
! Allocate memory for the solution arrays
allocate(old_solution(nx, ny), stat=info)
allocate(new_solution(nx, ny), stat=info)
! Initialize arrays to zero
DO j = 1, ny
DO i = 1, nx
old_solution(i, j) = 0.
new_solution(i, j) = 0.
END DO
END DO
! Set up boundary conditions
DO j = 1, ny
DO i = 1, nx
IF (j == 1) THEN
old_solution(i, j) = 1.
new_solution(i, j) = 1.
ELSE IF (j == ny) THEN
old_solution(i, j) = 1.
new_solution(i, j) = 1.
ELSE IF (i == 1) THEN
old_solution(i, j) = 1.
new_solution(i, j) = 1.
ELSE IF (i == nx) THEN
old_solution(i, j) = 1.
new_solution(i, j) = 1.
END IF
END DO
END DO
end subroutine init_double
end module setup