MONC
test_stencil.F90
Go to the documentation of this file.
1 ! Tests the logging_mod utility functions
3  use fruit, only : assert_equals, assert_not_equals, assert_true
11  implicit none
12 
13 contains
14 
15  ! Test random produces a non zero value
17  type(model_state_type), target :: current_state
18  type(grid_stencil_type) :: star_stencil
19  type(prognostic_field_ptr_type), dimension(3) :: fields
20  integer, dimension(3, 2) :: sizes
21  type(prognostic_field_type), dimension(:), allocatable :: interpolated_fields
22  integer :: i,num_fields,max_y_point
23 
24  call assert_equals(0,star_stencil%nfields,"Test a stencil has been created")
25  current_state%global_grid%size(z_index) = 2
26  num_fields = 15
27  current_state%local_grid%size(y_index) = 3
28  current_state%local_grid%halo_size(y_index) = 4
29 
30  fields(num_fields)%ptr => current_state%u
31  sizes(num_fields,:) = (/ 2, 2 /)
32 
33  allocate(interpolated_fields(0:num_fields))
34  allocate(interpolated_fields(num_fields)%data(current_state%global_grid%size(z_index),&
35  -1:3, -1:3))
36  max_y_point = (current_state%local_grid%size(y_index)+ &
37  current_state%local_grid%halo_size(y_index) *2)-1
38 
39  interpolated_fields(num_fields)%active=.true.
40  star_stencil = create_stencil(current_state%local_grid, fields, num_fields, 3, &
41  sizes,.true., .false.)
42  call assert_equals(max_y_point,star_stencil%max_y_point,"Test max Y point within the stencil")
43  call assert_equals(-1,star_stencil%max_x_point,"Test max X point within the stencil")
44  call assert_equals(num_fields+1,size(interpolated_fields),"Test size of interpolated_fields")
45  call assert_equals(num_fields,star_stencil%nfields,"Test a stencil has been created")
46  end subroutine test_create_stencil
47 
48  ! Test calculate interpolated cell value
50  type(model_state_type), target :: current_state
51  type(grid_stencil_type) :: star_stencil
52  type(prognostic_field_ptr_type), dimension(3) :: fields
53  integer, dimension(3, 2) :: sizes
54  type(prognostic_field_type), dimension(:), allocatable :: interpolated_fields
55  integer :: i,num_fields,max_y_point
56  logical, dimension(3) :: interpolate_in_dimension
57  real(kind=default_precision) :: r_value
58  real(kind=default_precision) :: e_value
59 
60 
61  current_state%global_grid%size(z_index) = 2
62  num_fields = 15
63  current_state%local_grid%size(z_index)= 0
64  current_state%local_grid%size(y_index) = 3
65  current_state%local_grid%halo_size(y_index) = 4
66 
67  fields(num_fields)%ptr => current_state%u
68  sizes(num_fields,:) = (/ 2, 2 /)
69 
70  allocate(interpolated_fields(0:num_fields))
71  allocate(interpolated_fields(num_fields)%data(current_state%global_grid%size(z_index),&
72  -1:3, -1:3))
73  max_y_point = (current_state%local_grid%size(y_index)+ &
74  current_state%local_grid%halo_size(y_index) *2)-1
75 
76  interpolated_fields(num_fields)%active=.true.
77  star_stencil = create_stencil(current_state%local_grid, fields, num_fields, 3, &
78  sizes,.true., .false.)
79  e_value = 10_default_precision
80  star_stencil%interpolated_fields(1,1)%data(1,1,1) = e_value
81 
82  call calculate_interpolated_cell_value(current_state%local_grid, 1, 1, (/.true.,.true.,.true./),&
83  star_stencil%fields(1), star_stencil%interpolated_fields(1,1)%data(:,1,1))
84 
85  r_value = star_stencil%interpolated_fields(1,1)%data(1,1,1)
86 
87  call assert_equals(e_value, r_value,"Test")
89 
90  end module test_stencil_mod
91 
92 
93 
94  ! Driver for maths_mod utility tests
96  use fruit, only : init_fruit, run_test_case, fruit_summary
97  use maths_mod, only : random
99 
100  implicit none
101 
102  call init_fruit
103  call run_test_case(test_create_stencil, "Test maths_mod random function produces output")
104  call run_test_case(test_calculate_interpolated_cell_value, &
105  "Test the calculation of interpolated cell values")
106 
107  call fruit_summary
108  end program test_stencil_driver
prognostics_mod
Contains prognostic field definitions and functions.
Definition: prognostics.F90:2
stencil_mod::grid_stencil_type
Configuration for a specific stencil interpolation to perform.
Definition: stencil.F90:18
stencil_mod::create_stencil
type(grid_stencil_type) function, public create_stencil(local_grid, fields, nfields, interpolations_to_perform, sizes, xdim, ydim)
Creates a stencil configuration which will then be used for interpolation.
Definition: stencil.F90:37
grids_mod::x_index
integer, parameter, public x_index
Definition: grids.F90:14
grids_mod::y_index
integer, parameter, public y_index
Definition: grids.F90:14
state_mod::parallel_state_type
Information about the parallel aspects of the system.
Definition: state.F90:21
test_stencil_mod
Definition: test_stencil.F90:2
test_stencil_mod::test_create_stencil
subroutine test_create_stencil
Definition: test_stencil.F90:17
test_stencil_driver
program test_stencil_driver
Definition: test_stencil.F90:95
stencil_mod::interpolate_to_dual
subroutine, public interpolate_to_dual(local_grid, field, stencil, x, y, interpolated_fields, interpolation_id)
Interpolates the (vector) flow fields from the primal to dual grid based upon a specific field interp...
Definition: stencil.F90:88
stencil_mod::calculate_interpolated_cell_value
subroutine calculate_interpolated_cell_value(local_grid, j, i, interpolate_in_dimension, field, column_stencil_values)
Calculates the interpolated values for each point in a column. The exact method of interpolation depe...
Definition: stencil.F90:148
maths_mod::random
real(kind=default_precision) function, public random(idum)
returns a scalar random number, the initial seed idum must be negative usage: idum = -k !...
Definition: maths.F90:23
grids_mod::z_index
integer, parameter, public z_index
Grid index parameters.
Definition: grids.F90:14
test_stencil_mod::test_calculate_interpolated_cell_value
subroutine test_calculate_interpolated_cell_value
Definition: test_stencil.F90:50
state_mod::model_state_type
The ModelState which represents the current state of a run.
Definition: state.F90:39
stencil_mod
Performs the interpolation between the primal and dual grids via a stencil approach....
Definition: stencil.F90:7
state_mod::forward_stepping
integer, parameter, public forward_stepping
Definition: state.F90:15
prognostics_mod::prognostic_field_ptr_type
A pointer to the prognostic field. This is so we can wrap prognostics up in an array and still refer ...
Definition: prognostics.F90:24
grids_mod::local_grid_type
Defined the local grid, i.e. the grid held on this process after decomposition.
Definition: grids.F90:118
prognostics_mod::get_field_interpolation_index
logical function, dimension(3), public get_field_interpolation_index(field)
Retrieves the index(s) that require interpolation to go from the primal the dual grid.
Definition: prognostics.F90:34
prognostics_mod::prognostic_field_type
A prognostic field which is assumed to be 3D.
Definition: prognostics.F90:13
datadefn_mod
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
stencil_mod::free_stencil
subroutine, public free_stencil(stencil)
Frees up the memory allocated to a stencil.
Definition: stencil.F90:64
grids_mod
Functionality to support the different types of grid and abstraction between global grids and local o...
Definition: grids.F90:5
maths_mod
Definition: maths.F90:1
datadefn_mod::default_precision
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Definition: datadefn.F90:17
state_mod
The model state which represents the current state of a run.
Definition: state.F90:2