MONC
diverr.F90
Go to the documentation of this file.
1 
2 module diverr_mod
4  use grids_mod, only : z_index, y_index, x_index
8  implicit none
9 
10 #ifndef TEST_MODE
11  private
12 #endif
13 
15 contains
16 
20  diverr_get_descriptor%name="diverr"
21  diverr_get_descriptor%version=0.1
22  diverr_get_descriptor%initialisation=>init_callback
25  end function diverr_get_descriptor
26 
29  subroutine init_callback(current_state)
30  type(model_state_type), target, intent(inout) :: current_state
31 
32  if (.not. allocated(current_state%p%data)) then
33  ! If we are loading from a checkpoint file then this is already present
34  allocate(current_state%p%data(current_state%local_grid%size(z_index) + current_state%local_grid%halo_size(z_index) * 2, &
35  current_state%local_grid%size(y_index) + current_state%local_grid%halo_size(y_index) * 2, &
36  current_state%local_grid%size(x_index) + current_state%local_grid%halo_size(x_index) * 2))
37  current_state%p%data=0.0_default_precision
38  current_state%p%active=.true.
39  end if
40  end subroutine init_callback
41 
44  subroutine timestep_callback(current_state)
45  type(model_state_type), target, intent(inout) :: current_state
46 
47  current_state%p%data(:, current_state%column_local_y, current_state%column_local_x) = 0.0_default_precision
48 
49  if (current_state%halo_column) return
50 
51  if (current_state%field_stepping == forward_stepping) then
52  call handle_forward_stepping(current_state)
53  else
54  call handle_centred_stepping(current_state)
55  end if
56  call find_max_divergence_error(current_state)
57  end subroutine timestep_callback
58 
61  subroutine finalisation_callback(current_state)
62  type(model_state_type), target, intent(inout) :: current_state
63 
64  current_state%p%active=.false.
65  deallocate(current_state%p%data)
66  end subroutine finalisation_callback
67 
70  subroutine find_max_divergence_error(current_state)
71  type(model_state_type), target, intent(inout) :: current_state
72 
73  integer :: k
74 
75  if (current_state%first_timestep_column) current_state%local_divmax=0.0_default_precision
76 
77  do k=2,current_state%local_grid%size(z_index)
78  if (abs(current_state%p%data(k, current_state%column_local_y, current_state%column_local_x)) .gt. &
79  current_state%local_divmax) then
80  current_state%local_divmax=abs(current_state%p%data(k,current_state%column_local_y, current_state%column_local_x))
81  end if
82  end do
83  end subroutine find_max_divergence_error
84 
87  subroutine handle_forward_stepping(current_state)
88  type(model_state_type), target, intent(inout) :: current_state
89 
90  real(kind=default_precision) :: timec
91 
92  timec=1.0_default_precision/current_state%dtm
93 
94  call calculate_p(current_state, current_state%p, current_state%u, current_state%v, current_state%w, timec, &
95  current_state%column_local_y, current_state%column_local_x)
96  end subroutine handle_forward_stepping
97 
100  subroutine handle_centred_stepping(current_state)
101  type(model_state_type), target, intent(inout) :: current_state
102 
103  real(kind=default_precision) :: timec
104 
105  timec=1.0_default_precision/(2.0_default_precision*current_state%dtm)
106 
107  call calculate_p(current_state, current_state%p, current_state%zu, current_state%zv, current_state%zw, timec, &
108  current_state%column_local_y, current_state%column_local_x)
109  end subroutine handle_centred_stepping
110 
120  subroutine calculate_p(current_state, p, u, v, w, timec, y_local, x_local)
121  type(model_state_type), target, intent(inout) :: current_state
122  type(prognostic_field_type), intent(inout) :: u, v, w, p
123  real(kind=default_precision), intent(in) :: timec
124  integer, intent(in) :: y_local, x_local
125 
126  integer :: k
127 
128  p%data(:, y_local, x_local)=0.0_default_precision
129  do k=2,current_state%local_grid%size(z_index)
130 #ifdef U_ACTIVE
131  p%data(k, y_local, x_local)= p%data(k, y_local, x_local)+ &
132  current_state%global_grid%configuration%horizontal%cx*(u%data(k, y_local, x_local)-u%data(k, y_local, x_local-1))
133 #endif
134 #ifdef V_ACTIVE
135  p%data(k, y_local, x_local)= p%data(k, y_local, x_local)+ &
136  current_state%global_grid%configuration%horizontal%cy*(v%data(k, y_local, x_local)-v%data(k, y_local-1, x_local))
137 #endif
138 #ifdef W_ACTIVE
139  p%data(k, y_local, x_local)= p%data(k, y_local, x_local)+ &
140  4.0_default_precision*(current_state%global_grid%configuration%vertical%tzc2(k)*w%data(k, y_local, x_local)-&
141  current_state%global_grid%configuration%vertical%tzc1(k)* w%data(k-1, y_local, x_local))
142 #endif
143  p%data(k, y_local, x_local)=p%data(k, y_local, x_local) * timec
144  end do
145  end subroutine calculate_p
146 end module diverr_mod
prognostics_mod
Contains prognostic field definitions and functions.
Definition: prognostics.F90:2
diverr_mod::find_max_divergence_error
subroutine find_max_divergence_error(current_state)
Finds the maximum divergence error locally and writes this into the local variable.
Definition: diverr.F90:71
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
diverr_mod::calculate_p
subroutine calculate_p(current_state, p, u, v, w, timec, y_local, x_local)
Calculates P based upon flow fields and the stepping.
Definition: diverr.F90:121
diverr_mod::diverr_get_descriptor
type(component_descriptor_type) function, public diverr_get_descriptor()
Descriptor of this component for registration.
Definition: diverr.F90:20
diverr_mod::timestep_callback
subroutine timestep_callback(current_state)
Called each timestep this will initialise P and update the local divergence error for the current col...
Definition: diverr.F90:45
monc_component_mod
Interfaces and types that MONC components must specify.
Definition: monc_component.F90:6
diverr_mod::handle_centred_stepping
subroutine handle_centred_stepping(current_state)
Handles the calculation of P when the model is centred stepping.
Definition: diverr.F90:101
diverr_mod
Calculates the local divergence error.
Definition: diverr.F90:2
grids_mod::z_index
integer, parameter, public z_index
Grid index parameters.
Definition: grids.F90:14
state_mod::model_state_type
The ModelState which represents the current state of a run.
Definition: state.F90:39
state_mod::forward_stepping
integer, parameter, public forward_stepping
Definition: state.F90:15
diverr_mod::handle_forward_stepping
subroutine handle_forward_stepping(current_state)
Handles the calculation of P when the model is forward stepping.
Definition: diverr.F90:88
diverr_mod::finalisation_callback
subroutine finalisation_callback(current_state)
Called at finalisation this will deallocate the P field as the model shuts down.
Definition: diverr.F90:62
diverr_mod::init_callback
subroutine init_callback(current_state)
The initialisation callback will allocate memory for the P field and initialise it.
Definition: diverr.F90:30
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
grids_mod
Functionality to support the different types of grid and abstraction between global grids and local o...
Definition: grids.F90:5
monc_component_mod::component_descriptor_type
Description of a component.
Definition: monc_component.F90:42
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