MONC
meanprofiles.F90
Go to the documentation of this file.
1 
4  use state_mod, only : model_state_type
5  use grids_mod, only : x_index, y_index, z_index
7  use mpi, only : mpi_sum, mpi_in_place
8  implicit none
9 
10 #ifndef TEST_MODE
11  private
12 #endif
13 
15 
16  real(kind=DEFAULT_PRECISION) :: rnhpts
17  real(kind=DEFAULT_PRECISION), dimension(:,:), allocatable :: bartmp
18 
20 contains
21 
25  meanprofiles_get_descriptor%name="mean_profiles"
26  meanprofiles_get_descriptor%version=0.1
30  end function meanprofiles_get_descriptor
31 
34  subroutine init_callback(current_state)
35  type(model_state_type), target, intent(inout) :: current_state
36 
37  bar_fields=0
38 
39  rnhpts=1.0_default_precision/real(current_state%global_grid%size(x_index)*current_state%global_grid%size(y_index))
40 
41  start_x=current_state%local_grid%local_domain_start_index(x_index)
42  end_x=current_state%local_grid%local_domain_end_index(X_INDEX)
43  start_y=current_state%local_grid%local_domain_start_index(y_index)
44  end_y=current_state%local_grid%local_domain_end_index(Y_INDEX)
45 
46 #ifdef U_ACTIVE
47  if (.not. current_state%continuation_run) then
48  allocate(current_state%global_grid%configuration%vertical%olubar(current_state%local_grid%size(z_index)),&
49  current_state%global_grid%configuration%vertical%olzubar(current_state%local_grid%size(z_index)))
50  end if
51  allocate(current_state%global_grid%configuration%vertical%savolubar(current_state%local_grid%size(z_index)))
53 #endif
54 #ifdef V_ACTIVE
55  if (.not. current_state%continuation_run) then
56  allocate(current_state%global_grid%configuration%vertical%olvbar(current_state%local_grid%size(z_index)),&
57  current_state%global_grid%configuration%vertical%olzvbar(current_state%local_grid%size(z_index)))
58  end if
59  allocate(current_state%global_grid%configuration%vertical%savolvbar(current_state%local_grid%size(z_index)))
61 #endif
62  if (current_state%th%active) then
63  if (.not. current_state%continuation_run) then
64  allocate(current_state%global_grid%configuration%vertical%olthbar(current_state%local_grid%size(z_index)),&
65  current_state%global_grid%configuration%vertical%olzthbar(current_state%local_grid%size(z_index)))
66  end if
68  end if
69  if (current_state%number_q_fields .gt. 0) then
70  bar_fields=bar_fields+(current_state%number_q_fields*2)
71  if (.not. current_state%continuation_run) then
72  allocate(current_state%global_grid%configuration%vertical%olqbar(current_state%local_grid%size(z_index), &
73  current_state%number_q_fields), current_state%global_grid%configuration%vertical%olzqbar(&
74  current_state%local_grid%size(z_index), current_state%number_q_fields))
75  end if
76  end if
77  allocate(bartmp(current_state%local_grid%size(z_index), bar_fields))
78 
79  ! Do the initial calculation for the first timestep
80  if (.not. current_state%continuation_run) call calculate_mean_profiles(current_state)
81  end subroutine init_callback
82 
85  subroutine timestep_callback(current_state)
86  type(model_state_type), target, intent(inout) :: current_state
87 
88  current_state%global_grid%configuration%vertical%savolubar=current_state%global_grid%configuration%vertical%olubar
89  current_state%global_grid%configuration%vertical%savolvbar=current_state%global_grid%configuration%vertical%olvbar
90 
91  call calculate_mean_profiles(current_state)
92  end subroutine timestep_callback
93 
96  subroutine finalisation_callback(current_state)
97  type(model_state_type), target, intent(inout) :: current_state
98 
99  if (allocated(bartmp)) deallocate(bartmp)
100  end subroutine finalisation_callback
101 
104  subroutine calculate_mean_profiles(current_state)
105  type(model_state_type), target, intent(inout) :: current_state
106 
107  integer :: bar_index, i
108 
109  call calculate_sum_profiles(current_state)
110 
111  bar_index=1
112 #ifdef U_ACTIVE
113  current_state%global_grid%configuration%vertical%olubar(:)=bartmp(:, bar_index)*rnhpts
114  current_state%global_grid%configuration%vertical%olzubar(:)=bartmp(:, bar_index+1)*rnhpts
115  bar_index=bar_index+2
116 #endif
117 #ifdef V_ACTIVE
118  current_state%global_grid%configuration%vertical%olvbar(:)=bartmp(:, bar_index)*rnhpts
119  current_state%global_grid%configuration%vertical%olzvbar(:)=bartmp(:, bar_index+1)*rnhpts
120  bar_index=bar_index+2
121 #endif
122  if (current_state%th%active) then
123  current_state%global_grid%configuration%vertical%olthbar(:)=bartmp(:, bar_index)*rnhpts
124  current_state%global_grid%configuration%vertical%olzthbar(:)=bartmp(:, bar_index+1)*rnhpts
125  bar_index=bar_index+2
126  end if
127  do i=1,current_state%number_q_fields
128  if (current_state%q(i)%active) then
129  current_state%global_grid%configuration%vertical%olqbar(:, i)=bartmp(:, bar_index)*rnhpts
130  current_state%global_grid%configuration%vertical%olzqbar(:, i)=bartmp(:, bar_index+1)*rnhpts
131  bar_index=bar_index+2
132  end if
133  end do
134 
135  end subroutine calculate_mean_profiles
136 
139  subroutine calculate_sum_profiles(current_state)
140  type(model_state_type), intent(inout) :: current_state
141 
142  integer :: k, n, bar_index, ierr
143 
144  do k=current_state%local_grid%local_domain_start_index(z_index), current_state%local_grid%local_domain_end_index(z_index)
145  bar_index=1
146 #ifdef U_ACTIVE
147  bartmp(k, bar_index)=sum(current_state%u%data(k, start_y:end_y, start_x:end_x))
148  bartmp(k, bar_index+1)=sum(current_state%zu%data(k, start_y:end_y, start_x:end_x))
149  bar_index=bar_index+2
150 #endif
151 #ifdef V_ACTIVE
152  bartmp(k, bar_index)=sum(current_state%v%data(k, start_y:end_y, start_x:end_x))
153  bartmp(k, bar_index+1)=sum(current_state%zv%data(k, start_y:end_y, start_x:end_x))
154  bar_index=bar_index+2
155 #endif
156  if (current_state%th%active) then
157  bartmp(k, bar_index)=sum(current_state%th%data(k, start_y:end_y, start_x:end_x))
158  bartmp(k, bar_index+1)=sum(current_state%zth%data(k, start_y:end_y, start_x:end_x))
159  bar_index=bar_index+2
160  end if
161  do n=1,current_state%number_q_fields
162  if (current_state%q(n)%active) then
163  bartmp(k, bar_index)=sum(current_state%q(n)%data(k, start_y:end_y, start_x:end_x))
164  bartmp(k, bar_index+1)=sum(current_state%zq(n)%data(k, start_y:end_y, start_x:end_x))
165  bar_index=bar_index+2
166  end if
167  end do
168  end do
169 
170  call mpi_allreduce(mpi_in_place, bartmp, bar_fields*current_state%local_grid%size(z_index), precision_type, mpi_sum, &
171  current_state%parallel%monc_communicator, ierr)
172  end subroutine calculate_sum_profiles
173 end module meanprofiles_mod
subroutine calculate_mean_profiles(current_state)
Calculates the global mean profiles and stores these in the ol bar arrays.
integer, public precision_type
Definition: datadefn.F90:19
real(kind=default_precision), dimension(:,:), allocatable bartmp
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Definition: datadefn.F90:17
integer, parameter, public z_index
Grid index parameters.
Definition: grids.F90:14
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
The ModelState which represents the current state of a run.
Definition: state.F90:39
subroutine init_callback(current_state)
Called on MONC initialisation, will allocate appropriate data structures.
Calculates the mean profiles of prognostic variables which are then used in smoothing and other areas...
Definition: meanprofiles.F90:2
Interfaces and types that MONC components must specify.
type(component_descriptor_type) function, public meanprofiles_get_descriptor()
Returns the component descriptor of the mean profiles module.
subroutine timestep_callback(current_state)
Will recalculate the mean profiles of each prognostic when called (for the entire local domain) ...
Functionality to support the different types of grid and abstraction between global grids and local o...
Definition: grids.F90:5
subroutine calculate_sum_profiles(current_state)
Calculates the sum profiles for the bars for each level globally.
subroutine finalisation_callback(current_state)
Frees up the temporary data for the bars.
The model state which represents the current state of a run.
Definition: state.F90:2
integer, parameter, public y_index
Definition: grids.F90:14
real(kind=default_precision) rnhpts
integer, parameter, public x_index
Definition: grids.F90:14