afivo-streamer 1.1
1D/2D/3D streamer simulations with AMR
Loading...
Searching...
No Matches
test_lookup_table_2d.f90
Go to the documentation of this file.
1program test
3 implicit none
4
5 integer, parameter :: dp = kind(0.0d0)
6 integer, parameter :: in_size(2) = [53, 39]
7 integer, parameter :: tbl_size(2) = [64, 8]
8
9 integer :: i, j
10 type(lt2_t) :: lkp_tbl
11 real(dp) :: x1(in_size(1))
12 real(dp) :: x2(in_size(2))
13 real(dp) :: y_values(in_size(1), in_size(2))
14 real(dp) :: diff, mean_diff, xy(2)
15
16 print *, 'Start test_lookup_table_2d'
17 print *, 'Here, the input data has a different shape than the table,'
18 print *, 'so linear interpolation is used to create the 2D table.'
19
20 do i = 1, in_size(1)
21 x1(i) = (i-1) * acos(-1.0_dp) / (in_size(1) - 1)
22 end do
23
24 do i = 1, in_size(2)
25 x2(i) = (i-1) * acos(-1.0_dp) / (in_size(2) - 1)
26 end do
27
28
29 ! Create some testing data
30 do j = 1, in_size(2)
31 do i = 1, in_size(1)
32 y_values(i, j) = sol(x1(i), x2(j))
33 end do
34 end do
35
36 lkp_tbl = lt2_create([x1(1), x2(1)], &
37 [x1(in_size(1)), x2(in_size(2))], tbl_size, 1)
38 call lt2_set_col(lkp_tbl, 1, x1, x2, y_values)
39
40 mean_diff = 0.0_dp
41
42 do j = 1, in_size(2)
43 do i = 1, in_size(1)
44 diff = abs(y_values(i, j) - &
45 lt2_get_col(lkp_tbl, 1, x1(i), x2(j)))
46 mean_diff = mean_diff + diff / product(in_size)
47 end do
48 end do
49
50 print *, "Mean difference at input points: ", mean_diff
51
52 mean_diff = 0.0_dp
53
54 do j = 1, in_size(2)
55 do i = 1, in_size(1)
56 call random_number(xy)
57 xy = xy * acos(-1.0_dp)
58 diff = abs(sol(xy(1), xy(2)) - &
59 lt2_get_col(lkp_tbl, 1, xy(1), xy(2)))
60 mean_diff = mean_diff + diff / product(in_size)
61 end do
62 end do
63
64 print *, "Mean difference at random points: ", mean_diff
65
66contains
67
68 real(dp) function sol(x, y)
69 real(dp), intent(in) :: x, y
70 sol = 2 * x**2 + 3 * y
71 end function sol
72
73end program test
A Fortran 90 module for creating lookup tables. These tables can be used to efficiently interpolate o...
pure real(dp) function, public lt2_get_col(my_lt, col_ix, x1, x2)
Get the value of a single column at x.
subroutine, public lt2_set_col(my_lt, col_ix, x1, x2, y)
Fill the column with index col_ix using linearly interpolated data.
type(lt2_t) function, public lt2_create(x_min, x_max, n_points, n_cols, xspacing)
This function returns a new lookup table.
The 2D lookup table type.
real(dp) function sol(x, y)
program test