MONC
diagnostics.F90
Go to the documentation of this file.
5  use grids_mod, only : z_index, y_index, x_index
7  use state_mod, only : model_state_type
9 
10  implicit none
11 
12 #ifndef TEST_MODE
13  private
14 #endif
15 
17  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: tempfac, theta_tot
18  real(kind=DEFAULT_PRECISION) :: totqv, totql, totqz, wmax, wmin, qlmax, qlcrit, cltop_av, clbas_av, cltop, clbas
19 
21 
22 contains
23 
27  diagnostics_get_descriptor%name="diagnostics"
28  diagnostics_get_descriptor%version=0.1
29 
32 
35  allocate(diagnostics_get_descriptor%published_fields(15))
36 
37  diagnostics_get_descriptor%published_fields(1)="totpnts"
38  diagnostics_get_descriptor%published_fields(2)="zn_top"
39  diagnostics_get_descriptor%published_fields(3)="wmax_local"
40  diagnostics_get_descriptor%published_fields(4)="wmin_local"
41  diagnostics_get_descriptor%published_fields(5)="totqv_local"
42  diagnostics_get_descriptor%published_fields(6)="totql_local"
43  diagnostics_get_descriptor%published_fields(7)="totqz_local"
44  diagnostics_get_descriptor%published_fields(8)="qlmax_local"
45  diagnostics_get_descriptor%published_fields(9)="hqlmax_local"
46  diagnostics_get_descriptor%published_fields(10)="cltop_local"
47  diagnostics_get_descriptor%published_fields(11)="clbas_local"
48  diagnostics_get_descriptor%published_fields(12)="cltop_av_local"
49  diagnostics_get_descriptor%published_fields(13)="clbas_av_local"
50  diagnostics_get_descriptor%published_fields(14)="ncl_col_local"
51  diagnostics_get_descriptor%published_fields(15)="thdiag_local"
52  end function diagnostics_get_descriptor
53 
54  subroutine initialisation_callback(current_state)
55  type(model_state_type), target, intent(inout) :: current_state
56 
57  integer :: k
58 
59  qlcrit=options_get_real(current_state%options_database, "qlcrit")
60 
61  total_points=current_state%global_grid%size(z_index) * current_state%global_grid%size(y_index) * &
62  current_state%global_grid%size(x_index)
63 
64  allocate(tempfac(current_state%local_grid%size(z_index)), theta_tot(current_state%local_grid%size(z_index)))
65  do k=2, current_state%local_grid%size(z_index)
66  tempfac(k)=current_state%global_grid%configuration%vertical%dz(k)*&
67  current_state%global_grid%configuration%vertical%rhon(k)/total_points
68  end do
69  end subroutine initialisation_callback
70 
71  subroutine timestep_callback(current_state)
72  type(model_state_type), target, intent(inout) :: current_state
73 
74  integer :: k, i
75  real(kind=DEFAULT_PRECISION) :: cltop_col, clbas_col
76 
77  if (current_state%first_timestep_column) then
78  totqv=0.0_default_precision
79  totql=0.0_default_precision
80  totqz=0.0_default_precision
81  wmax=0.0_default_precision
82  wmin=0.0_default_precision
83  qlmax=0.0_default_precision
84  cltop_av=0.0_default_precision
85  clbas_av=0.0_default_precision
86  cltop=0.0_default_precision
87  clbas=0.0_default_precision
88  ncl_col=0
89  end if
90  if (.not. current_state%halo_column) then
91  cltop_col=0.0_default_precision
92  clbas_col=0.0_default_precision
93  do k=2, current_state%local_grid%size(z_index)
94  wmax=max(wmax, current_state%w%data(k, current_state%column_local_y, current_state%column_local_x))
95  wmin=min(wmin, current_state%w%data(k, current_state%column_local_y, current_state%column_local_x))
96 
97  if (current_state%number_q_fields .gt. 0) then
98  if (current_state%liquid_water_mixing_ratio_index .gt. 0 .and. &
99  current_state%number_q_fields .ge. current_state%liquid_water_mixing_ratio_index) then
100  if (qlmax .lt. current_state%q(current_state%liquid_water_mixing_ratio_index)%data(k, &
101  current_state%column_local_y, current_state%column_local_x)) then
102  qlmax=max(qlmax, current_state%q(current_state%liquid_water_mixing_ratio_index)%data(k, &
103  current_state%column_local_y, current_state%column_local_x))
104  hqlmax=k
105  end if
106 
107  if (current_state%q(current_state%liquid_water_mixing_ratio_index)%data(k, &
108  current_state%column_local_y, current_state%column_local_x) .gt. qlcrit) then
109  cltop_col=current_state%global_grid%configuration%vertical%zn(k)
110  cltop=max(cltop, current_state%global_grid%configuration%vertical%zn(k))
111  clbas=min(clbas, current_state%global_grid%configuration%vertical%zn(k))
112  end if
113 
114  if (current_state%q(current_state%liquid_water_mixing_ratio_index)%data(current_state%local_grid%size(z_index)+1-k, &
115  current_state%column_local_y, current_state%column_local_x) .gt. qlcrit) then
116  clbas_col=current_state%global_grid%configuration%vertical%zn(current_state%local_grid%size(z_index)+1-k)
117  end if
118 
119  !tql_loc(J,I)=tql_loc(J,I)+DZ(K)*RHON(K)*Q(J,K,IQL,current_state%liquid_water_mixing_ratio_index)
120  totqz=totqz+tempfac(k)*current_state%q(current_state%liquid_water_mixing_ratio_index)%data(k, &
121  current_state%column_local_y, current_state%column_local_x)*current_state%global_grid%configuration%vertical%zn(k)
122  end if
123 
124  if (current_state%water_vapour_mixing_ratio_index .gt. 0 .and. &
125  current_state%number_q_fields .ge. current_state%water_vapour_mixing_ratio_index) then
126  totqv=totqv+tempfac(k)*current_state%q(current_state%water_vapour_mixing_ratio_index)%data(k, &
127  current_state%column_local_y, current_state%column_local_x)
128  totql=totql+tempfac(k)*current_state%q(current_state%liquid_water_mixing_ratio_index)%data(k, &
129  current_state%column_local_y, current_state%column_local_x)
130  end if
131  end if
132  end do
133  if (cltop_col .gt. 0.0_default_precision) ncl_col=ncl_col+1
134  cltop_av=cltop_av+cltop_col
135  clbas_av=clbas_av+clbas_col
136 
137  end if
138  end subroutine timestep_callback
139 
144  subroutine field_information_retrieval_callback(current_state, name, field_information)
145  type(model_state_type), target, intent(inout) :: current_state
146  character(len=*), intent(in) :: name
147  type(component_field_information_type), intent(out) :: field_information
148 
149  field_information%field_type=component_scalar_field_type
150  field_information%data_type=component_double_data_type
151  field_information%enabled=.true.
152  if (name .eq. "thdiag_local") then
153  field_information%field_type=component_array_field_type
154  field_information%number_dimensions=1
155  field_information%dimension_sizes(1)=current_state%local_grid%size(z_index)
156  endif
157 
158  if (name .eq. "totpnts" .or. name .eq. "hqlmax_local" .or. name .eq. "ncl_col_local") then
159  field_information%data_type=component_integer_data_type
160  else
161  field_information%data_type=component_double_data_type
162  end if
164 
169  subroutine field_value_retrieval_callback(current_state, name, field_value)
170  type(model_state_type), target, intent(inout) :: current_state
171  character(len=*), intent(in) :: name
172  type(component_field_value_type), intent(out) :: field_value
173 
174  integer :: i
175 
176  if (name .eq. "totpnts") then
177  field_value%scalar_int=total_points
178  else if (name .eq. "zn_top") then
179  field_value%scalar_real=current_state%global_grid%configuration%vertical%zn(current_state%global_grid%size(z_index))
180  else if (name .eq. "wmax_local") then
181  field_value%scalar_real=wmax
182  else if (name .eq. "wmin_local") then
183  field_value%scalar_real=wmin
184  else if (name .eq. "totqv_local") then
185  field_value%scalar_real=totqv
186  else if (name .eq. "totql_local") then
187  field_value%scalar_real=totql
188  else if (name .eq. "totqz_local") then
189  field_value%scalar_real=totqz
190  else if (name .eq. "qlmax_local") then
191  field_value%scalar_real=qlmax
192  else if (name .eq. "hqlmax_local") then
193  field_value%scalar_int=hqlmax
194  else if (name .eq. "cltop_local") then
195  field_value%scalar_real=cltop
196  else if (name .eq. "clbas_local") then
197  field_value%scalar_real=clbas
198  else if (name .eq. "cltop_av_local") then
199  field_value%scalar_real=cltop_av
200  else if (name .eq. "clbas_av_local") then
201  field_value%scalar_real=clbas_av
202  else if (name .eq. "ncl_col_local") then
203  field_value%scalar_int=ncl_col
204  else if (name .eq. "thdiag_local") then
205  allocate(field_value%real_1d_array(current_state%local_grid%size(z_index)))
206  do i=1, current_state%local_grid%size(z_index)
207  field_value%real_1d_array(i)=maxval(current_state%th%data(i,:,:) + current_state%thref0)
208  enddo
209  end if
210  end subroutine field_value_retrieval_callback
211 end module diagnostics_mod
real(kind=default_precision) clbas
Definition: diagnostics.F90:18
integer, parameter, public component_scalar_field_type
subroutine field_information_retrieval_callback(current_state, name, field_information)
Field information retrieval callback, this returns information for a specific components published fi...
Wrapper type for the value returned for a published field from a component.
real(kind=default_precision) cltop_av
Definition: diagnostics.F90:18
subroutine initialisation_callback(current_state)
Definition: diagnostics.F90:55
real(kind=default_precision) qlmax
Definition: diagnostics.F90:18
real(kind=default_precision) wmax
Definition: diagnostics.F90:18
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
type(component_descriptor_type) function, public diagnostics_get_descriptor()
Provides the component descriptor for the core to register.
Definition: diagnostics.F90:27
real(kind=default_precision) cltop
Definition: diagnostics.F90:18
real(kind=default_precision), dimension(:), allocatable tempfac
Definition: diagnostics.F90:17
integer, parameter, public component_array_field_type
real(kind=default_precision) totqv
Definition: diagnostics.F90:18
real(kind=default_precision) qlcrit
Definition: diagnostics.F90:18
Interfaces and types that MONC components must specify.
real(kind=default_precision) totql
Definition: diagnostics.F90:18
real(kind=default_precision) wmin
Definition: diagnostics.F90:18
real(kind=default_precision), dimension(:), allocatable theta_tot
Definition: diagnostics.F90:17
integer, parameter, public component_integer_data_type
subroutine timestep_callback(current_state)
Definition: diagnostics.F90:72
real(kind=default_precision) function, public options_get_real(options_database, key, index)
Retrieves a real value from the database that matches the provided key.
Functionality to support the different types of grid and abstraction between global grids and local o...
Definition: grids.F90:5
real(kind=default_precision) clbas_av
Definition: diagnostics.F90:18
Manages the options database. Contains administration functions and deduce runtime options from the c...
real(kind=default_precision) totqz
Definition: diagnostics.F90:18
integer total_points
Definition: diagnostics.F90:16
The model state which represents the current state of a run.
Definition: state.F90:2
integer, parameter, public y_index
Definition: grids.F90:14
integer, parameter, public x_index
Definition: grids.F90:14
subroutine field_value_retrieval_callback(current_state, name, field_value)
Field value retrieval callback, this returns the value of a specific published field.
integer, parameter, public component_double_data_type