@@ -5,6 +5,8 @@ module test_drive_poisson
5
5
6
6
implicit none
7
7
8
+ public
9
+
8
10
! > Scalar values which define a mesh
9
11
type :: mesh_scalars_t
10
12
integer :: num_nodes, num_elements, num_boundary_points, num_sets, num_dirichlet_boundary_conditions, &
@@ -50,7 +52,7 @@ module test_drive_poisson
50
52
contains
51
53
52
54
! > Collect all test in this module into a single test suite
53
- ! !
55
+ ! !
54
56
! ! @param testsuite - An array of unittest_types in which to store this suite's tests
55
57
subroutine collect_poisson_testsuite (testsuite )
56
58
type (unittest_type), allocatable , intent (out ) :: testsuite(:)
@@ -64,11 +66,12 @@ end subroutine collect_poisson_testsuite
64
66
! > Define the values of a mesh with box_size = 10 and edge_size = 5
65
67
subroutine get_15_05_mesh_values (data_filename , mesh_scalars , mesh_vectors )
66
68
implicit none
67
- character (len= :), allocatable :: data_filename
69
+ character (len= :), allocatable , intent ( inout ) :: data_filename
68
70
type (mesh_scalars_t), intent (out ) :: mesh_scalars
69
71
type (mesh_vectors_t), intent (out ) :: mesh_vectors
70
-
71
- character (len= 100 ) :: data_filename_fixed = " testing/data/square_mesh_15_5"
72
+
73
+ character (len= 100 ) :: data_filename_fixed
74
+ data_filename_fixed = " testing/data/square_mesh_15_5"
72
75
73
76
allocate (character (len (trim (data_filename_fixed))) :: data_filename)
74
77
data_filename = trim (data_filename_fixed)
@@ -81,8 +84,12 @@ subroutine get_15_05_mesh_values(data_filename, mesh_scalars, mesh_vectors)
81
84
mesh_scalars% num_neumann_boundary_conditions = 0
82
85
83
86
mesh_vectors% element_to_node(1 ,1 :mesh_scalars% num_elements) = [1 , 2 , 3 , 1 , 2 , 3 , 5 , 6 , 7 , 5 , 6 , 7 , 9 , 10 , 11 , 9 , 10 , 11 ]
84
- mesh_vectors% element_to_node(2 ,1 :mesh_scalars% num_elements) = [2 , 3 , 4 , 6 , 7 , 8 , 6 , 7 , 8 , 10 , 11 , 12 , 10 , 11 , 12 , 14 , 15 , 16 ]
85
- mesh_vectors% element_to_node(3 ,1 :mesh_scalars% num_elements) = [6 , 7 , 8 , 5 , 6 , 7 , 10 , 11 , 12 , 9 , 10 , 11 , 14 , 15 , 16 , 13 , 14 , 15 ]
87
+ mesh_vectors% element_to_node(2 ,1 :mesh_scalars% num_elements) = [ &
88
+ 2 , 3 , 4 , 6 , 7 , 8 , 6 , 7 , 8 , 10 , 11 , 12 , 10 , 11 , 12 , 14 , 15 , 16 &
89
+ ]
90
+ mesh_vectors% element_to_node(3 ,1 :mesh_scalars% num_elements) = [ &
91
+ 6 , 7 , 8 , 5 , 6 , 7 , 10 , 11 , 12 , 9 , 10 , 11 , 14 , 15 , 16 , 13 , 14 , 15 &
92
+ ]
86
93
mesh_vectors% vb_index(1 :mesh_scalars% num_elements) = [1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]
87
94
mesh_vectors% boundary_node_num(1 ,1 :mesh_scalars% num_boundary_points) = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ]
88
95
mesh_vectors% boundary_node_num(2 ,1 :mesh_scalars% num_boundary_points) = [1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]
@@ -94,8 +101,12 @@ subroutine get_15_05_mesh_values(data_filename, mesh_scalars, mesh_vectors)
94
101
mesh_vectors% vb(1 :3 ,mesh_scalars% num_sets) = [1 , 1 , 1 ]
95
102
mesh_vectors% vb1(1 :mesh_scalars% num_dirichlet_boundary_conditions) = 0
96
103
mesh_vectors% vb1(1 :mesh_scalars% num_neumann_boundary_conditions) = 0
97
- mesh_vectors% coordinates(1 ,1 :mesh_scalars% num_nodes) = [1.0 , 1.0 , 1.0 , 1.0 , 2.0 , 2.0 , 2.0 , 2.0 , 3.0 , 3.0 , 3.0 , 3.0 , 4.0 , 4.0 , 4.0 , 4.0 ]
98
- mesh_vectors% coordinates(2 ,1 :mesh_scalars% num_nodes) = [1.0 , 2.0 , 3.0 , 4.0 , 1.0 , 2.0 , 3.0 , 4.0 , 1.0 , 2.0 , 3.0 , 4.0 , 1.0 , 2.0 , 3.0 , 4.0 ]
104
+ mesh_vectors% coordinates(1 ,1 :mesh_scalars% num_nodes) = [ &
105
+ 1.0 , 1.0 , 1.0 , 1.0 , 2.0 , 2.0 , 2.0 , 2.0 , 3.0 , 3.0 , 3.0 , 3.0 , 4.0 , 4.0 , 4.0 , 4.0 &
106
+ ]
107
+ mesh_vectors% coordinates(2 ,1 :mesh_scalars% num_nodes) = [ &
108
+ 1.0 , 2.0 , 3.0 , 4.0 , 1.0 , 2.0 , 3.0 , 4.0 , 1.0 , 2.0 , 3.0 , 4.0 , 1.0 , 2.0 , 3.0 , 4.0 &
109
+ ]
99
110
end subroutine get_15_05_mesh_values
100
111
101
112
! > Verification code for the read_input_file subroutine
@@ -107,12 +118,14 @@ subroutine verify_inp(error, inputs, expected_outputs)
107
118
108
119
integer :: actual_num_nodes, actual_num_elements, actual_num_boundary_points, &
109
120
actual_element_to_node(3 ,mxp), actual_vb_index(mxe), actual_boundary_node_num(2 ,mxb), &
110
- actual_num_side_nodes(4 ,mxb), file_io = 123 , i, j
111
- real :: actual_vb(3 ,mxc), actual_vb1(mxc), actual_vb2(mxc), actual_coordinates(2 , mxp)
121
+ actual_num_side_nodes(4 ,mxb), file_io, i, j
122
+ real :: actual_vb(3 ,mxc), actual_vb1(mxc), actual_vb2(mxc), actual_coordinates(2 , mxp), threshold
112
123
character (len= 200 ) :: failure_message
113
- real :: threshold = 1e-06
124
+
125
+ threshold = 1e-06
114
126
115
127
! Open the file ready to be read
128
+ file_io = 123
116
129
call open_file(inputs% data_filename, ' old' , file_io)
117
130
118
131
call read_input_file( &
@@ -141,54 +154,65 @@ subroutine verify_inp(error, inputs, expected_outputs)
141
154
142
155
do i = 1 , expected_outputs% mesh_scalars% num_elements
143
156
do j = 1 , 3
144
- write (failure_message,' (a,i1,a,i1,a,i2,a,i2)' ) " Unexpected value for element_to_node(" , j, " ," , i, " ), got " , actual_element_to_node(j, i), " expected " , expected_outputs% mesh_vectors% element_to_node(j, i)
145
- call check(error, actual_element_to_node(j, i), expected_outputs% mesh_vectors% element_to_node(j, i), failure_message)
157
+ write (failure_message,' (a,i1,a,i1,a,i2,a,i2)' ) " Unexpected value for element_to_node(" , j, " ," , i, " ), got " , &
158
+ actual_element_to_node(j, i), " expected " , expected_outputs% mesh_vectors% element_to_node(j, i)
159
+ call check(error, actual_element_to_node(j, i), expected_outputs% mesh_vectors% element_to_node(j, i), &
160
+ failure_message)
146
161
if (allocated (error)) return
147
- end do
162
+ end do
148
163
149
- write (failure_message,' (a,i1,a,i2,a,i2)' ) " Unexpected value for vb_index(" , i, " ), got " , actual_vb_index(i), " expected " , expected_outputs% mesh_vectors% vb_index(i)
164
+ write (failure_message,' (a,i1,a,i2,a,i2)' ) " Unexpected value for vb_index(" , i, " ), got " , &
165
+ actual_vb_index(i), " expected " , expected_outputs% mesh_vectors% vb_index(i)
150
166
call check(error, actual_vb_index(i), expected_outputs% mesh_vectors% vb_index(i), failure_message)
151
167
if (allocated (error)) return
152
168
end do
153
169
154
170
do i = 1 , expected_outputs% mesh_scalars% num_nodes
155
171
do j = 1 , 2
156
- write (failure_message,' (a,i1,a,i1,a,f5.2,a,f5.2)' ) " Unexpected value for coordinates(" , j, " ," , i, " ), got " , actual_coordinates(j, i), " expected " , expected_outputs% mesh_vectors% coordinates(j, i)
157
- call check(error, actual_coordinates(j, i), expected_outputs% mesh_vectors% coordinates(j, i), failure_message, thr= threshold)
172
+ write (failure_message,' (a,i1,a,i1,a,f5.2,a,f5.2)' ) " Unexpected value for coordinates(" , j, " ," , i, " ), got " , &
173
+ actual_coordinates(j, i), " expected " , expected_outputs% mesh_vectors% coordinates(j, i)
174
+ call check(error, actual_coordinates(j, i), expected_outputs% mesh_vectors% coordinates(j, i), &
175
+ failure_message, thr= threshold)
158
176
if (allocated (error)) return
159
- end do
177
+ end do
160
178
end do
161
179
162
180
do i = 1 , expected_outputs% mesh_scalars% num_boundary_points
163
181
do j = 1 , 2
164
- write (failure_message,' (a,i1,a,i1,a,i2,a,i2)' ) " Unexpected value for boundary_node_num(" , j, " ," , i, " ), got " , actual_boundary_node_num(j, i), " expected " , expected_outputs% mesh_vectors% boundary_node_num(j, i)
165
- call check(error, actual_boundary_node_num(j, i), expected_outputs% mesh_vectors% boundary_node_num(j, i), failure_message)
182
+ write (failure_message,' (a,i1,a,i1,a,i2,a,i2)' ) " Unexpected value for boundary_node_num(" , j, " ," , i, " ), got " , &
183
+ actual_boundary_node_num(j, i), " expected " , expected_outputs% mesh_vectors% boundary_node_num(j, i)
184
+ call check(error, actual_boundary_node_num(j, i), expected_outputs% mesh_vectors% boundary_node_num(j, i), &
185
+ failure_message)
166
186
if (allocated (error)) return
167
- end do
187
+ end do
168
188
169
189
do j = 1 , 4
170
- write (failure_message,' (a,i1,a,i1,a,i2,a,i2)' ) " Unexpected value for num_side_nodes(" , j, " ," , i, " ), got " , actual_num_side_nodes(j, i), " expected " , expected_outputs% mesh_vectors% num_side_nodes(j, i)
190
+ write (failure_message,' (a,i1,a,i1,a,i2,a,i2)' ) " Unexpected value for num_side_nodes(" , j, " ," , i, " ), got " , &
191
+ actual_num_side_nodes(j, i), " expected " , expected_outputs% mesh_vectors% num_side_nodes(j, i)
171
192
call check(error, actual_num_side_nodes(j, i), expected_outputs% mesh_vectors% num_side_nodes(j, i), failure_message)
172
193
if (allocated (error)) return
173
194
end do
174
195
end do
175
196
176
197
do i = 1 , expected_outputs% mesh_scalars% num_sets
177
198
do j = 1 , 3
178
- write (failure_message,' (a,i1,a,i1,a,f5.2,a,f5.2)' ) " Unexpected value for vb(" , j, " ," , i, " ), got " , actual_vb(j, i), " expected " , expected_outputs% mesh_vectors% vb(j, i)
199
+ write (failure_message,' (a,i1,a,i1,a,f5.2,a,f5.2)' ) " Unexpected value for vb(" , j, " ," , i, " ), got " , &
200
+ actual_vb(j, i), " expected " , expected_outputs% mesh_vectors% vb(j, i)
179
201
call check(error, actual_vb(j, i), expected_outputs% mesh_vectors% vb(j, i), failure_message, thr= threshold)
180
202
if (allocated (error)) return
181
203
end do
182
204
end do
183
205
184
206
do i = 1 , expected_outputs% mesh_scalars% num_dirichlet_boundary_conditions
185
- write (failure_message,' (a,i1,a,f5.2,a,f5.2)' ) " Unexpected value for vb1(" , i, " ), got " , actual_vb1(i), " expected " , expected_outputs% mesh_vectors% vb1(i)
207
+ write (failure_message,' (a,i1,a,f5.2,a,f5.2)' ) " Unexpected value for vb1(" , i, " ), got " , &
208
+ actual_vb1(i), " expected " , expected_outputs% mesh_vectors% vb1(i)
186
209
call check(error, actual_vb1(i), expected_outputs% mesh_vectors% vb1(i), failure_message, thr= threshold)
187
210
if (allocated (error)) return
188
211
end do
189
212
190
213
do i = 1 , expected_outputs% mesh_scalars% num_neumann_boundary_conditions
191
- write (failure_message,' (a,i1,a,f5.2,a,f5.2)' ) " Unexpected value for vb2(" , i, " ), got " , actual_vb2(i), " expected " , expected_outputs% mesh_vectors% vb2(i)
214
+ write (failure_message,' (a,i1,a,f5.2,a,f5.2)' ) " Unexpected value for vb2(" , i, " ), got " , &
215
+ actual_vb2(i), " expected " , expected_outputs% mesh_vectors% vb2(i)
192
216
call check(error, actual_vb2(i), expected_outputs% mesh_vectors% vb2(i), failure_message, thr= threshold)
193
217
if (allocated (error)) return
194
218
end do
@@ -214,12 +238,13 @@ subroutine verify_pcg(error, inputs, expected_outputs)
214
238
215
239
type (pcg_inputs_t), intent (in ) :: inputs
216
240
type (pcg_expected_outputs_t), intent (in ) :: expected_outputs
217
-
218
- real :: actual_nodal_value_of_f(mxp)
241
+
242
+ real :: actual_nodal_value_of_f(mxp), threshold
219
243
character (len= 200 ) :: failure_message
220
- real :: threshold = 1e-06
221
244
integer :: i
222
245
246
+ threshold = 1e-06
247
+
223
248
call pcg(&
224
249
inputs% mesh_scalars% num_nodes, &
225
250
inputs% mesh_scalars% num_elements, &
@@ -237,7 +262,8 @@ subroutine verify_pcg(error, inputs, expected_outputs)
237
262
238
263
! verify outputs
239
264
do i = 1 , inputs% mesh_scalars% num_nodes
240
- write (failure_message,' (a,i3,a,f9.7,a,f9.7)' ) " Unexpected value for coordinates(" , i, " ), got " , actual_nodal_value_of_f(i), " expected " , expected_outputs% nodal_value_of_f(i)
265
+ write (failure_message,' (a,i3,a,f9.7,a,f9.7)' ) " Unexpected value for coordinates(" , i, " ), got " , &
266
+ actual_nodal_value_of_f(i), " expected " , expected_outputs% nodal_value_of_f(i)
241
267
call check(error, actual_nodal_value_of_f(i), expected_outputs% nodal_value_of_f(i), failure_message, thr= threshold)
242
268
if (allocated (error)) return
243
269
end do
@@ -252,10 +278,12 @@ subroutine test_pcg_15_05(error)
252
278
type (pcg_expected_outputs_t) :: expected_outputs
253
279
254
280
call get_15_05_mesh_values(inputs% data_filename, inputs% mesh_scalars, inputs% mesh_vectors)
255
- expected_outputs% nodal_value_of_f(1 :inputs% mesh_scalars% num_nodes) = [0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.407407 , 0.481481 , 0.518518 , 0.592592 ]
281
+ expected_outputs% nodal_value_of_f(1 :inputs% mesh_scalars% num_nodes) = [ &
282
+ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.407407 , 0.481481 , 0.518518 , 0.592592 &
283
+ ]
256
284
257
285
call verify_pcg(error, inputs, expected_outputs)
258
286
259
287
deallocate (inputs% data_filename)
260
288
end subroutine test_pcg_15_05
261
- end module
289
+ end module test_drive_poisson
0 commit comments