MONC
pressuresource.F90
Go to the documentation of this file.
1 
9  use grids_mod, only : z_index, y_index, x_index
10  use state_mod, only : model_state_type
14  use mpi, only : mpi_request_null
15  implicit none
16 
17 #ifndef TEST_MODE
18  private
19 #endif
20 
21  real(kind=default_precision), dimension(:,:), allocatable :: send_buffer_x, send_buffer_y
22 
24 contains
25 
35 
38  subroutine initialisation_callback(current_state)
39  type(model_state_type), target, intent(inout) :: current_state
40 
41  if (.not. is_component_enabled(current_state%options_database, "diverr")) then
42  call log_master_log(log_error, "The pressure source component requires the diverr component to be enabled")
43  end if
44 
45 #ifdef U_ACTIVE
46  allocate(send_buffer_x(current_state%local_grid%size(z_index)-1, current_state%local_grid%size(y_index)), &
47  current_state%psrce_recv_buffer_x(current_state%local_grid%size(z_index)-1, current_state%local_grid%size(y_index)))
48 #endif
49 #ifdef V_ACTIVE
50  allocate(send_buffer_y(current_state%local_grid%size(z_index)-1, current_state%local_grid%size(x_index)), &
51  current_state%psrce_recv_buffer_y(current_state%local_grid%size(z_index)-1, current_state%local_grid%size(x_index)))
52 #endif
53  current_state%psrce_x_hs_send_request=mpi_request_null
54  current_state%psrce_y_hs_send_request=mpi_request_null
55  current_state%psrce_x_hs_recv_request=mpi_request_null
56  current_state%psrce_y_hs_recv_request=mpi_request_null
57  end subroutine initialisation_callback
58 
61  subroutine timestep_callback(current_state)
62  type(model_state_type), target, intent(inout) :: current_state
63 
64  if (current_state%first_timestep_column) call register_neighbouring_pressure_data_recv(current_state)
65  if (.not. current_state%halo_column) call calculate_psrce(current_state)
66  if (current_state%last_timestep_column) call send_neighbouring_pressure_data(current_state)
67  end subroutine timestep_callback
68 
71  subroutine finalisation_callback(current_state)
72  type(model_state_type), target, intent(inout) :: current_state
73 
74  if (allocated(send_buffer_x)) deallocate(send_buffer_x)
75  if (allocated(current_state%psrce_recv_buffer_x)) deallocate(current_state%psrce_recv_buffer_x)
76  if (allocated(send_buffer_y)) deallocate(send_buffer_y)
77  if (allocated(current_state%psrce_recv_buffer_y)) deallocate(current_state%psrce_recv_buffer_y)
78  end subroutine finalisation_callback
79 
84  subroutine calculate_psrce(current_state)
85  type(model_state_type), target, intent(inout) :: current_state
86 
87  integer :: k, local_y, local_x, corrected_y, corrected_x
88  logical :: last_x, last_y
89 
90  local_y=current_state%column_local_y
91  local_x=current_state%column_local_x
92  last_y = local_y == current_state%local_grid%local_domain_end_index(y_index)
93  last_x = local_x == current_state%local_grid%local_domain_end_index(x_index)
94  if (last_x .or. last_y) then
95  corrected_x=local_x-current_state%local_grid%halo_size(x_index)
96  corrected_y=local_y-current_state%local_grid%halo_size(y_index)
97  end if
98  do k=2,current_state%local_grid%size(z_index)
99 #ifdef W_ACTIVE
100  current_state%p%data(k, local_y, local_x)=current_state%p%data(k, local_y, local_x)+&
101  4.0_default_precision*(current_state%global_grid%configuration%vertical%tzc2(k)*&
102  current_state%sw%data(k, local_y, local_x)-&
103  current_state%global_grid%configuration%vertical%tzc1(k)*current_state%sw%data(k-1, local_y, local_x))
104 #endif
105 #ifdef U_ACTIVE
106  current_state%p%data(k, local_y, local_x)=current_state%p%data(k, local_y, local_x)+&
107  current_state%global_grid%configuration%horizontal%cx * current_state%su%data(k, local_y, local_x)
108 #endif
109 #ifdef V_ACTIVE
110  current_state%p%data(k, local_y, local_x)=current_state%p%data(k, local_y, local_x)+&
111  current_state%global_grid%configuration%horizontal%cy * current_state%sv%data(k, local_y, local_x)
112 #endif
113 #ifdef U_ACTIVE
114  if (local_x .gt. 3) then
115  current_state%p%data(k, local_y, local_x)=current_state%p%data(k, local_y, local_x)-&
116  current_state%global_grid%configuration%horizontal%cx * current_state%su%data(k, local_y, local_x-1)
117  end if
118 
119  if (last_x) then
120  send_buffer_x(k-1, corrected_y)=&
121  current_state%global_grid%configuration%horizontal%cx * current_state%su%data(k, local_y, local_x)
122  end if
123 #endif
124 #ifdef V_ACTIVE
125  if (local_y .gt. 3 .and. local_x .gt. 3) then
126  current_state%p%data(k, local_y, local_x)=current_state%p%data(k, local_y, local_x)-&
127  current_state%global_grid%configuration%horizontal%cy * current_state%sv%data(k, local_y-1, local_x)
128  end if
129  if (last_y) then
130  send_buffer_y(k-1, corrected_x)=&
131  current_state%global_grid%configuration%horizontal%cy * current_state%sv%data(k, local_y, local_x)
132  end if
133 #endif
134  end do
135  end subroutine calculate_psrce
136 
139  subroutine send_neighbouring_pressure_data(current_state)
140  type(model_state_type), target, intent(inout) :: current_state
141 
142  integer :: ierr
143 
144 #ifdef U_ACTIVE
145  if (current_state%local_grid%neighbours(x_index,3) .eq. current_state%parallel%my_rank) then
146  current_state%psrce_recv_buffer_x=send_buffer_x
147  else
148  call mpi_isend(send_buffer_x, size(send_buffer_x), precision_type, current_state%local_grid%neighbours(x_index,3), &
149  10, current_state%parallel%neighbour_comm, current_state%psrce_x_hs_send_request, ierr)
150  end if
151 #endif
152 #ifdef V_ACTIVE
153  if (current_state%local_grid%neighbours(y_index,3) .eq. current_state%parallel%my_rank) then
154  current_state%psrce_recv_buffer_y=send_buffer_y
155  else
156  call mpi_isend(send_buffer_y, size(send_buffer_y), precision_type, current_state%local_grid%neighbours(y_index,3), &
157  10, current_state%parallel%neighbour_comm, current_state%psrce_y_hs_send_request, ierr)
158  end if
159 #endif
160  end subroutine send_neighbouring_pressure_data
161 
165  type(model_state_type), target, intent(inout) :: current_state
166 
167  integer :: ierr
168 
169 #ifdef U_ACTIVE
170  if (current_state%local_grid%neighbours(x_index,2) .ne. current_state%parallel%my_rank) then
171  call mpi_irecv(current_state%psrce_recv_buffer_x, size(current_state%psrce_recv_buffer_x), precision_type, &
172  current_state%local_grid%neighbours(x_index,2), 10, current_state%parallel%neighbour_comm, &
173  current_state%psrce_x_hs_recv_request, ierr)
174  end if
175 #endif
176 #ifdef V_ACTIVE
177  if (current_state%local_grid%neighbours(y_index,2) .ne. current_state%parallel%my_rank) then
178  call mpi_irecv(current_state%psrce_recv_buffer_y, size(current_state%psrce_recv_buffer_y), precision_type, &
179  current_state%local_grid%neighbours(y_index,2), 10, current_state%parallel%neighbour_comm, &
180  current_state%psrce_y_hs_recv_request, ierr)
181  end if
182 #endif
184 end module pressuresource_mod
registry_mod::is_component_enabled
logical function, public is_component_enabled(options_database, component_name)
Determines whether or not a specific component is registered and enabled.
Definition: registry.F90:334
logging_mod::log_error
integer, parameter, public log_error
Only log ERROR messages.
Definition: logging.F90:11
pressuresource_mod::initialisation_callback
subroutine initialisation_callback(current_state)
On initialisation this will allocate the buffer areas required and set communication handles to null.
Definition: pressuresource.F90:39
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
datadefn_mod::precision_type
integer, public precision_type
Definition: datadefn.F90:19
pressuresource_mod::send_buffer_x
real(kind=default_precision), dimension(:,:), allocatable send_buffer_x
Definition: pressuresource.F90:21
monc_component_mod
Interfaces and types that MONC components must specify.
Definition: monc_component.F90:6
pressuresource_mod::finalisation_callback
subroutine finalisation_callback(current_state)
Frees up the allocated buffers (if such were allocated)
Definition: pressuresource.F90:72
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
pressuresource_mod
Calculates the gradient of the source flow fields (SU, SV, SW.) This is based upon the P field values...
Definition: pressuresource.F90:7
pressuresource_mod::pressuresource_get_descriptor
type(component_descriptor_type) function, public pressuresource_get_descriptor()
Descriptor of this component for registration.
Definition: pressuresource.F90:29
pressuresource_mod::send_neighbouring_pressure_data
subroutine send_neighbouring_pressure_data(current_state)
Sends the computed source pressure data terms to the p+1 process.
Definition: pressuresource.F90:140
logging_mod
Logging utility.
Definition: logging.F90:2
datadefn_mod
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
logging_mod::log_master_log
subroutine, public log_master_log(level, message)
Will log just from the master process.
Definition: logging.F90:47
registry_mod
MONC component registry.
Definition: registry.F90:5
pressuresource_mod::timestep_callback
subroutine timestep_callback(current_state)
The timestep callback will update the values of P for each column.
Definition: pressuresource.F90:62
grids_mod
Functionality to support the different types of grid and abstraction between global grids and local o...
Definition: grids.F90:5
pressuresource_mod::send_buffer_y
real(kind=default_precision), dimension(:,:), allocatable send_buffer_y
Definition: pressuresource.F90:21
pressuresource_mod::calculate_psrce
subroutine calculate_psrce(current_state)
Combines the source fields with the pressure values. For U and V, if this is on the low boundary then...
Definition: pressuresource.F90:85
pressuresource_mod::register_neighbouring_pressure_data_recv
subroutine register_neighbouring_pressure_data_recv(current_state)
Registers the receive requests for each neighbouring process if that is not local,...
Definition: pressuresource.F90:165
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