MONC
Functions/Subroutines | Variables
gridmanager_mod Module Reference

Manages the grid based upon the model state_mod. More...

Functions/Subroutines

type(component_descriptor_type) function, public gridmanager_get_descriptor ()
 Provides the descriptor back to the caller and is used in component registration. More...
 
subroutine initialise_callback (current_state)
 Called during initialisation and will initialise the horizontal and vertical grid configurations Note that the model state_mod (from a checkpoint or external file) must have been initialised already. More...
 
subroutine finalise_callback (current_state)
 Called as MONC exits, for good practice this will deallocate the memory used for the grids. More...
 
subroutine initialise_verticalgrid_configuration_type (current_state)
 Will initialise the vertical grid configuration. More...
 
subroutine set_vertical_reference_profile (current_state, vertical_grid, kkp)
 Sets up the vertical grid reference profile at each point. More...
 
subroutine calculate_initial_profiles (current_state, vertical_grid)
 Calculates the initial profiles for U, V, TH & Q if required. More...
 
subroutine calculate_mixing_length_for_neutral_case (current_state, vertical_grid, kkp)
 Calculates the mixing length for the neutral case. More...
 
subroutine set_buoyancy_coefficient (current_state, vertical_grid, kkp)
 Sets the buoyancy coefficient from the grid configuration and configuration. More...
 
subroutine setup_reference_state_liquid_water_temperature_and_saturation (current_state, vertical_grid, kkp)
 Setting up reference state liquid water temperature and saturation mixing ratio on main levels. More...
 
subroutine set_up_vertical_reference_properties (current_state, vertical_grid, kkp)
 Sets up the reference properties for the vertical grid at each point. More...
 
subroutine set_up_and_smooth_grid (vertical_grid, kgd, hgd, ninitp, kkp, zztop, nsmth, origional_setup, continuation_run)
 Sets up and smooths the vertical grid. This is based upon the grid configuration already read in. More...
 
subroutine original_vertical_grid_setup (vertical_grid, kgd, hgd, ninitp, kkp, zztop, nsmth)
 The original vertical grid setup and smoothing as per the LEM. More...
 
subroutine new_vertical_grid_setup (vertical_grid, kgd, kkp, zztop)
 The newer vertical grid setup routine. More...
 
subroutine create_linear_grid (vertical_grid, kgd, hgd, ninitp, kkp, zztop)
 Creates the linear vertical grid based upon the configuration properties. More...
 
subroutine allocate_vertical_grid_data (vertical_grid, n, nq)
 Allocates the data required for the vertical grid configuration. More...
 
subroutine initialise_horizontalgrid_configuration_types (current_state)
 Initialises the horizontal grid configurations. More...
 
subroutine set_anelastic_pressure (current_state)
 Set reference profile of potential temperature for the Boussinesq/Anelastic approximation Note that this is not in general the same as the profile defining the initial vertical distribution of potential temperature for the integration. In particular, while the later may contain sharp changes in gradient representing a capping inversion or the tropopause, for example, the reference profile should be smooth. More...
 
subroutine compute_anelastic_pressure_profile_only (current_state)
 Computes the anelastic pressure only - if we are using Boussinesq approximation. More...
 
subroutine compute_anelastic_pressure_profile_and_density (current_state)
 Computes the anelastic pressure and density - if we are using Anelastic approximation. More...
 
subroutine check_top (zztop, z, info)
 

Variables

integer, parameter anelastic_profile_mode =4
 
real, parameter default_spacing = 1.E9
 The default spacing used if no grid is active in a specific dimension. More...
 
real(kind=default_precision), dimension(:,:), allocatable qinit
 

Detailed Description

Manages the grid based upon the model state_mod.

Function/Subroutine Documentation

◆ allocate_vertical_grid_data()

subroutine gridmanager_mod::allocate_vertical_grid_data ( type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, intent(in)  n,
integer, intent(in)  nq 
)
private

Allocates the data required for the vertical grid configuration.

Parameters
vertical_gridThe vertical grid that we are working with
nThe number of grid points in the vertical
nqThe number of q fields

Definition at line 632 of file gridmanager.F90.

632  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
633  integer, intent(in) :: n
634  integer, intent(in) :: nq
635 
636  allocate(vertical_grid%dz(n), vertical_grid%dzn(n),&
637  vertical_grid%czb(n), vertical_grid%cza(n), vertical_grid%czg(n), vertical_grid%czh(n),&
638  vertical_grid%rdz(n), vertical_grid%rdzn(n), vertical_grid%tzc1(n), vertical_grid%tzc2(n),&
639  vertical_grid%tzd1(n), vertical_grid%tzd2(n), vertical_grid%theta_init(n), &
640  vertical_grid%tref(n), vertical_grid%prefn(n), vertical_grid%pdiff(n), vertical_grid%prefrcp(n), &
641  vertical_grid%rprefrcp(n), vertical_grid%rho(n), vertical_grid%rhon(n), vertical_grid%tstarpr(n), &
642  vertical_grid%qsat(n), vertical_grid%dqsatdt(n), vertical_grid%qsatfac(n), vertical_grid%dthref(n), &
643  vertical_grid%rneutml(n), vertical_grid%rneutml_sq(n), vertical_grid%buoy_co(n), &
644  vertical_grid%u_init(n), vertical_grid%v_init(n), vertical_grid%theta_rand(n), vertical_grid%w_rand(n), &
645  vertical_grid%w_subs(n), vertical_grid%u_force(n), vertical_grid%v_force(n), vertical_grid%theta_force(n))
646 
647  if (.not. allocated(vertical_grid%thref)) allocate(vertical_grid%thref(n))
648  if (.not. allocated(vertical_grid%z)) allocate(vertical_grid%z(n))
649  if (.not. allocated(vertical_grid%zn)) allocate(vertical_grid%zn(n))
650 
651  allocate(vertical_grid%q_rand(n,nq), vertical_grid%q_init(n,nq), vertical_grid%q_force(n,nq))
Here is the caller graph for this function:

◆ calculate_initial_profiles()

subroutine gridmanager_mod::calculate_initial_profiles ( type(model_state_type), intent(inout)  current_state,
type(vertical_grid_configuration_type), intent(inout)  vertical_grid 
)
private

Calculates the initial profiles for U, V, TH & Q if required.

Parameters
current_stateThe current model state_mod
vertical_gridThe vertical grid that we are working on
kkpNumber of grid points in a vertical column

Definition at line 161 of file gridmanager.F90.

161  type(model_state_type), intent(inout) :: current_state
162  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
163 
164  integer :: nq_init ! The number of q fields to initialize
165  integer :: nzq ! The number of input levels for q_init
166  integer :: i,j,n ! loop counters
167  integer :: iq ! temporary q varible index
168 
169  real(kind=DEFAULT_PRECISION), dimension(:,:), allocatable :: f_init_pl_q ! Initial node values for q variables
170  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: z_init_pl_q ! Initial node height values for q variables
171  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: f_init_pl_theta ! Initial node values for theta variable
172  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: z_init_pl_theta ! Initial node height values for theta variable
173  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: f_init_pl_u ! Initial node values for u variable
174  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: z_init_pl_u ! Initial node height values for u variable
175  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: f_init_pl_v ! Initial node values for v variable
176  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: z_init_pl_v ! Initial node height values for v variable
177 
178  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: f_thref ! Initial node values for thref
179  real(kind=DEFAULT_PRECISION), dimension(:), allocatable :: z_thref ! Initial node height values for thref
180 
181  logical :: l_init_pl_u ! if .true. then initialize u field
182  logical :: l_init_pl_v ! if .true. then initialize v field
183  logical :: l_init_pl_theta ! if .true. then initialize theta field
184  logical :: l_init_pl_q ! if .true. then initialize q fields
185  logical :: l_thref ! if .true. then initialize thref profile (overrides thref0)
186  logical :: l_matchthref ! if .true. then initialize thref to be the same as theta_init
187 
188  character(len=STRING_LENGTH), dimension(:), allocatable :: names_init_pl_q ! names of q variables to initialize
189 
190  real(kind=DEFAULT_PRECISION), allocatable :: f_init_pl_q_tmp(:) !temporary 1D storage of initial q field
191  real(kind=DEFAULT_PRECISION), allocatable :: zgrid(:) ! z grid to use in interpolation
192 
193  real(kind=DEFAULT_PRECISION) :: zztop ! top of the domain
194 
195  allocate(zgrid(current_state%local_grid%local_domain_end_index(z_index)))
196 
197  zztop = current_state%global_grid%top(z_index)
198 
199  ! Initialize everything to zero. This won't make sense for theta.
200  vertical_grid%q_init = 0.0_default_precision
201  vertical_grid%u_init = 0.0_default_precision
202  vertical_grid%v_init = 0.0_default_precision
203  vertical_grid%theta_init = 0.0_default_precision
204 
205  l_init_pl_theta=options_get_logical(current_state%options_database, "l_init_pl_theta")
206  l_init_pl_q=options_get_logical(current_state%options_database, "l_init_pl_q")
207  if (l_init_pl_q) then
208  allocate(names_init_pl_q(options_get_array_size(current_state%options_database, "names_init_pl_q")))
209  call options_get_string_array(current_state%options_database, "names_init_pl_q", names_init_pl_q)
210  end if
211  l_init_pl_u=options_get_logical(current_state%options_database, "l_init_pl_u")
212  l_init_pl_v=options_get_logical(current_state%options_database, "l_init_pl_v")
213 
214  l_thref=options_get_logical(current_state%options_database, "l_thref")
215  l_matchthref=options_get_logical(current_state%options_database, "l_matchthref")
216 
217  if (l_thref)then
218  if (.not. l_matchthref)then
219  allocate(z_thref(options_get_array_size(current_state%options_database, "z_thref")), &
220  f_thref(options_get_array_size(current_state%options_database, "f_thref")))
221  call options_get_real_array(current_state%options_database, "z_thref", z_thref)
222  call options_get_real_array(current_state%options_database, "f_thref", f_thref)
223  call check_top(zztop, z_thref(size(z_thref)), 'z_thref')
224  zgrid=current_state%global_grid%configuration%vertical%zn(:)
225  call piecewise_linear_1d(z_thref(1:size(z_thref)), f_thref(1:size(f_thref)), zgrid, &
226  current_state%global_grid%configuration%vertical%thref)
227  deallocate(z_thref, f_thref)
228  end if
229  else
230  current_state%global_grid%configuration%vertical%thref(:)=current_state%thref0
231  end if
232 
233  if (l_init_pl_theta)then
234  allocate(z_init_pl_theta(options_get_array_size(current_state%options_database, "z_init_pl_theta")), &
235  f_init_pl_theta(options_get_array_size(current_state%options_database, "f_init_pl_theta")))
236  call options_get_real_array(current_state%options_database, "z_init_pl_theta", z_init_pl_theta)
237  call options_get_real_array(current_state%options_database, "f_init_pl_theta", f_init_pl_theta)
238  call check_top(zztop, z_init_pl_theta(size(z_init_pl_theta)), 'z_init_pl_theta')
239  zgrid=current_state%global_grid%configuration%vertical%zn(:)
240  call piecewise_linear_1d(z_init_pl_theta(1:size(z_init_pl_theta)), f_init_pl_theta(1:size(f_init_pl_theta)), zgrid, &
241  current_state%global_grid%configuration%vertical%theta_init)
242  if (l_matchthref) then
243  if(.not. current_state%use_anelastic_equations) then
244  call log_master_log(log_error, "Non-anelastic equation set and l_maththref are incompatible")
245  end if
246  current_state%global_grid%configuration%vertical%thref = current_state%global_grid%configuration%vertical%theta_init
247  end if
248  if (.not. current_state%continuation_run) then
249  do i=current_state%local_grid%local_domain_start_index(x_index), current_state%local_grid%local_domain_end_index(x_index)
250  do j=current_state%local_grid%local_domain_start_index(y_index), current_state%local_grid%local_domain_end_index(y_index)
251  current_state%th%data(:,j,i) = current_state%global_grid%configuration%vertical%theta_init(:) - &
252  current_state%global_grid%configuration%vertical%thref(:)
253  end do
254  end do
255  end if
256  deallocate(z_init_pl_theta, f_init_pl_theta)
257  end if
258 
259  if (l_init_pl_u)then
260  allocate(z_init_pl_u(options_get_array_size(current_state%options_database, "z_init_pl_u")), &
261  f_init_pl_u(options_get_array_size(current_state%options_database, "f_init_pl_u")))
262  call options_get_real_array(current_state%options_database, "z_init_pl_u", z_init_pl_u)
263  call options_get_real_array(current_state%options_database, "f_init_pl_u", f_init_pl_u)
264  call check_top(zztop, z_init_pl_u(size(z_init_pl_u)), 'z_init_pl_u')
265  zgrid=current_state%global_grid%configuration%vertical%zn(:)
266  call piecewise_linear_1d(z_init_pl_u(1:size(z_init_pl_u)), f_init_pl_u(1:size(f_init_pl_u)), &
267  zgrid, current_state%global_grid%configuration%vertical%u_init)
268  if (.not. current_state%continuation_run) then
269  do i=current_state%local_grid%local_domain_start_index(x_index), current_state%local_grid%local_domain_end_index(x_index)
270  do j=current_state%local_grid%local_domain_start_index(y_index), current_state%local_grid%local_domain_end_index(y_index)
271  current_state%u%data(:,j,i) = current_state%global_grid%configuration%vertical%u_init(:)
272  end do
273  end do
274  end if
275  deallocate(z_init_pl_u, f_init_pl_u)
276  end if
277 
278  if (l_init_pl_v)then
279  allocate(z_init_pl_v(options_get_array_size(current_state%options_database, "z_init_pl_v")), &
280  f_init_pl_v(options_get_array_size(current_state%options_database, "f_init_pl_v")))
281  call options_get_real_array(current_state%options_database, "z_init_pl_v", z_init_pl_v)
282  call options_get_real_array(current_state%options_database, "f_init_pl_v", f_init_pl_v)
283  call check_top(zztop, z_init_pl_v(size(z_init_pl_v)), 'z_init_pl_v')
284  zgrid=current_state%global_grid%configuration%vertical%zn(:)
285  call piecewise_linear_1d(z_init_pl_v(1:size(z_init_pl_v)), f_init_pl_v(1:size(f_init_pl_v)), &
286  zgrid, current_state%global_grid%configuration%vertical%v_init)
287  if (.not. current_state%continuation_run) then
288  do i=current_state%local_grid%local_domain_start_index(x_index), current_state%local_grid%local_domain_end_index(x_index)
289  do j=current_state%local_grid%local_domain_start_index(y_index), current_state%local_grid%local_domain_end_index(y_index)
290  current_state%v%data(:,j,i) = current_state%global_grid%configuration%vertical%v_init(:)
291  end do
292  end do
293  end if
294  deallocate(z_init_pl_v, f_init_pl_v)
295  end if
296 
297  if (l_init_pl_q)then
298  nq_init=size(names_init_pl_q)
299  allocate(z_init_pl_q(options_get_array_size(current_state%options_database, "z_init_pl_q")))
300  call options_get_real_array(current_state%options_database, "z_init_pl_q", z_init_pl_q)
301  nzq=size(z_init_pl_q)
302  call check_top(zztop, z_init_pl_q(nzq), 'z_init_pl_q')
303  zgrid=current_state%global_grid%configuration%vertical%zn(:)
304  allocate(f_init_pl_q_tmp(nq_init*nzq))
305  call options_get_real_array(current_state%options_database, "f_init_pl_q", f_init_pl_q_tmp)
306  allocate(f_init_pl_q(nzq, nq_init))
307  f_init_pl_q(1:nzq, 1:nq_init)=reshape(f_init_pl_q_tmp, (/nzq, nq_init/))
308  do n=1, nq_init
309  iq=get_q_index(trim(names_init_pl_q(n)), 'piecewise_initialization')
310  call piecewise_linear_1d(z_init_pl_q(1:nzq), f_init_pl_q(1:nzq,n), zgrid, &
311  current_state%global_grid%configuration%vertical%q_init(:,iq))
312  if (.not. current_state%continuation_run) then
313  do i=current_state%local_grid%local_domain_start_index(x_index), &
314  current_state%local_grid%local_domain_end_index(x_index)
315  do j=current_state%local_grid%local_domain_start_index(y_index), &
316  current_state%local_grid%local_domain_end_index(y_index)
317  current_state%q(iq)%data(:,j,i) = current_state%global_grid%configuration%vertical%q_init(:, iq)
318  end do
319  end do
320  end if
321  end do
322  deallocate(f_init_pl_q_tmp, z_init_pl_q, f_init_pl_q, names_init_pl_q)
323  end if
324  deallocate(zgrid)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_mixing_length_for_neutral_case()

subroutine gridmanager_mod::calculate_mixing_length_for_neutral_case ( type(model_state_type), intent(inout)  current_state,
type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, intent(in)  kkp 
)
private

Calculates the mixing length for the neutral case.

Parameters
current_stateThe current model state_mod
vertical_gridThe vertical grid that we are working on
kkpNumber of grid points in a vertical column

Definition at line 332 of file gridmanager.F90.

332  type(model_state_type), intent(inout) :: current_state
333  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
334  integer, intent(in) :: kkp
335 
336  integer :: k
337 
338  do k=2, kkp-1
339  vertical_grid%rneutml(k)=sqrt(1.0_default_precision/(1.0_default_precision/(von_karman_constant*&
340  (vertical_grid%z(k)+z0))**2+1.0_default_precision/current_state%rmlmax**2) )
341  vertical_grid%rneutml_sq(k)=vertical_grid%rneutml(k)*vertical_grid%rneutml(k)
342  end do
Here is the caller graph for this function:

◆ check_top()

subroutine gridmanager_mod::check_top ( real(kind=default_precision), intent(in)  zztop,
real(kind=default_precision), intent(in)  z,
character(*), intent(in)  info 
)
private

Definition at line 826 of file gridmanager.F90.

826  real(kind=DEFAULT_PRECISION), intent(in) :: zztop
827  real(kind=DEFAULT_PRECISION), intent(in) :: z
828  character(*), intent(in) :: info
829 
830  if (z<zztop)then
831  call log_master_log(log_error, "Top of input profile is below the top of the domain:"//trim(info))
832  end if
833 
Here is the caller graph for this function:

◆ compute_anelastic_pressure_profile_and_density()

subroutine gridmanager_mod::compute_anelastic_pressure_profile_and_density ( type(model_state_type), intent(inout)  current_state)
private

Computes the anelastic pressure and density - if we are using Anelastic approximation.

Parameters
current_stateThe current model state

Definition at line 747 of file gridmanager.F90.

747  type(model_state_type), intent(inout) :: current_state
748 
749  integer :: ipass, k
750  real(kind=DEFAULT_PRECISION) :: p0 &!pressure at z=0 adjustments made after 1st iteration so P0=PSF after 2nd iteration
751  , ptop &!pressure at z=ZN(KKP)
752  , thfactor !factor for multiplying TH profile (if IADJANELP=2)
753 
754  ptop=0.0_default_precision
755  current_state%global_grid%configuration%vertical%pdiff(current_state%local_grid%size(z_index))=0.0_default_precision
756  do ipass=1,2 ! _after first pass, may adjust basic states
757  if (ipass .eq. 1 .or. anelastic_profile_mode .gt. 1) then
758  current_state%global_grid%configuration%vertical%prefn(current_state%local_grid%size(z_index))=&
759  (ptop/current_state%surface_reference_pressure)**r_over_cp
760  do k=current_state%local_grid%size(z_index)-1,1,-1
761  current_state%global_grid%configuration%vertical%pdiff(k)=g*&
762  current_state%global_grid%configuration%vertical%dzn(k+1)/(0.5_default_precision*cp*&
763  (current_state%global_grid%configuration%vertical%thref(k)+&
764  current_state%global_grid%configuration%vertical%thref(k+1)))
765  end do
766  do k=current_state%local_grid%size(z_index)-1,1,-1
767  current_state%global_grid%configuration%vertical%prefn(k)=&
768  current_state%global_grid%configuration%vertical%prefn(k+1)+&
769  current_state%global_grid%configuration%vertical%pdiff(k)
770  end do
771  do k=current_state%local_grid%size(z_index),1,-1
772  current_state%global_grid%configuration%vertical%prefn(k)=current_state%surface_reference_pressure*&
773  current_state%global_grid%configuration%vertical%prefn(k)**(1.0_default_precision/r_over_cp)
774  end do
775  end if
776  p0=0.5_default_precision*(current_state%global_grid%configuration%vertical%prefn(1)+&
777  current_state%global_grid%configuration%vertical%prefn(2))
778  ! !-------------------------------------------------------------
779  ! ! _If IADJANELP>1 we adjust the basic states to ensure P0=PSF,
780  ! ! as follows:
781  ! ! IADJANELP=2 adjust THREF profile by constant factor
782  ! ! IADJANELP=3 adjust PSF
783  ! ! IADJANELP=4 adjust PTOP
784  ! ! _Option 3 tends to give rather large changes in PSF, so
785  ! ! I prefer 2 or 4 for most purposes
786  ! !-------------------------------------------------------------
787  if (ipass .eq. 1 .and. anelastic_profile_mode .eq. 2) then
788  ! ! _adjust THREF profile by constant factor to enforce
789  ! ! P0 = (fixed) PSF
790  thfactor=((p0/current_state%surface_reference_pressure)**r_over_cp-(ptop/current_state%surface_reference_pressure)**&
791  r_over_cp)/((current_state%surface_pressure/current_state%surface_reference_pressure)**r_over_cp-&
792  (ptop/current_state%surface_reference_pressure)**r_over_cp)
793  do k=1,current_state%local_grid%size(z_index)
794  current_state%global_grid%configuration%vertical%thref(k)=&
795  current_state%global_grid%configuration%vertical%thref(k)*thfactor
796  end do
797  end if
798  if (ipass .eq. 1 .and. anelastic_profile_mode .eq. 4) then
799  ! ! _adjust PTOP so that P0 = (fixed) PSF
800  ptop=current_state%surface_pressure**r_over_cp+ptop**r_over_cp-p0**r_over_cp
801  if (ptop .le. 0.0_default_precision .and. current_state%parallel%my_rank==0) then
802  call log_log(log_error, "Negative ptop in setup of anelastic. Need a warmer THREF or different setup options")
803  end if
804  ptop=ptop**(1.0_default_precision/r_over_cp)
805  end if
806  end do
807  ! !---------------------------------------
808  ! ! _Finally compute density from pressure
809  ! !---------------------------------------
810  do k=1,current_state%local_grid%size(z_index)
811  current_state%global_grid%configuration%vertical%rhon(k)=current_state%global_grid%configuration%vertical%prefn(k)&
812  /(r*current_state%global_grid%configuration%vertical%thref(k)*&
813  (current_state%global_grid%configuration%vertical%prefn(k)/current_state%surface_reference_pressure)**r_over_cp)
814  end do
815  do k=1,current_state%local_grid%size(z_index)-1
816  current_state%global_grid%configuration%vertical%rho(k)=sqrt(current_state%global_grid%configuration%vertical%rhon(k)*&
817  current_state%global_grid%configuration%vertical%rhon(k+1))
818  end do
819  current_state%global_grid%configuration%vertical%rho(current_state%local_grid%size(z_index))=&
820  current_state%global_grid%configuration%vertical%rhon(current_state%local_grid%size(z_index))**2/&
821  current_state%global_grid%configuration%vertical%rhon(current_state%local_grid%size(z_index)-1)
Here is the caller graph for this function:

◆ compute_anelastic_pressure_profile_only()

subroutine gridmanager_mod::compute_anelastic_pressure_profile_only ( type(model_state_type), intent(inout)  current_state)
private

Computes the anelastic pressure only - if we are using Boussinesq approximation.

Parameters
current_stateThe current model state

Definition at line 701 of file gridmanager.F90.

701  type(model_state_type), intent(inout) :: current_state
702 
703  integer :: ipass, k
704  real(kind=DEFAULT_PRECISION) :: p0 &!pressure at z=0 adjustments made after 1st iteration so P0=PSF after 2nd iteration
705  , ptop &!pressure at z=ZN(KKP)
706  , thprof(current_state%local_grid%size(z_index))
707 
708 
709  ! TODO: NOTE - we are mocking in thprof at the moment, this should be read from a configuration and used here instead
710  thprof=0.0_default_precision
711  ptop=0.0_default_precision
712  current_state%global_grid%configuration%vertical%pdiff(current_state%local_grid%size(z_index))=0.0_default_precision
713 
714  do ipass=1,2 ! _after first pass adjust PTOP
715  current_state%global_grid%configuration%vertical%prefn(current_state%local_grid%size(z_index))=&
716  (ptop/current_state%surface_reference_pressure)**r_over_cp
717  do k=current_state%local_grid%size(z_index)-1,1,-1
718  current_state%global_grid%configuration%vertical%pdiff(k)=g*&
719  current_state%global_grid%configuration%vertical%dzn(k+1)/(0.5_default_precision*cp*&
720  (current_state%global_grid%configuration%vertical%thref(k)+&
721  current_state%global_grid%configuration%vertical%thref(k+1)))
722  end do
723  do k=current_state%local_grid%size(z_index)-1,1,-1
724  current_state%global_grid%configuration%vertical%prefn(k)=&
725  current_state%global_grid%configuration%vertical%prefn(k+1)+&
726  current_state%global_grid%configuration%vertical%pdiff(k)
727  end do
728  do k=current_state%local_grid%size(z_index),1,-1
729  current_state%global_grid%configuration%vertical%prefn(k)=current_state%surface_reference_pressure*&
730  current_state%global_grid%configuration%vertical%prefn(k)**(1.0_default_precision/r_over_cp)
731  end do
732  p0=0.5_default_precision*(current_state%global_grid%configuration%vertical%prefn(1)+&
733  current_state%global_grid%configuration%vertical%prefn(2))
734  if (ipass .eq. 1) then
735  ptop=current_state%surface_pressure**r_over_cp+ptop**r_over_cp-p0**r_over_cp
736  if (ptop .le. 0.0_default_precision .and. current_state%parallel%my_rank==0) then
737  call log_log(log_error, "Negative ptop in setup of anelastic. Need a warmer THREF or different setup options")
738  end if
739  ptop=ptop**(1.0_default_precision/r_over_cp)
740  end if
741  end do
Here is the caller graph for this function:

◆ create_linear_grid()

subroutine gridmanager_mod::create_linear_grid ( type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, dimension(:), intent(in)  kgd,
real(kind=default_precision), dimension(:), intent(in)  hgd,
integer, intent(in)  ninitp,
integer, intent(in)  kkp,
real(kind=default_precision), intent(in)  zztop 
)
private

Creates the linear vertical grid based upon the configuration properties.

This will correspond the vertical k grid points to the configuration which might be only a few reference properties.

Parameters
vertical_gridThe vertical grid
kgdThe grid heights per division
hgdThe real world (m) heights per division
kkpNumber of points in the vertical domain
zztopThe real world (m) height of the top of the column
nsmthNumber of smoothing iterations to run on the grid

Definition at line 590 of file gridmanager.F90.

590  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
591  integer, dimension(:), intent(in) :: kgd
592  real(kind=DEFAULT_PRECISION), dimension(:), intent(in) :: hgd
593  integer, intent(in) :: ninitp, kkp
594  real(kind=DEFAULT_PRECISION), intent(in) :: zztop
595 
596  integer :: kmax, k, i
597  real(kind=DEFAULT_PRECISION) :: zmax
598 
599  vertical_grid%z(1) = 0.0_default_precision
600  kmax=kgd(1)
601  zmax=0.0_default_precision
602  if (kgd(1) .gt. 1) then
603  do k=1,kgd(1)
604  ! Loop up to first division point
605  vertical_grid%z(k)=real(k-1, kind=default_precision)*hgd(1)/real(kgd(1)-1, kind=default_precision)
606  end do
607  do i=2,ninitp
608  if(kgd(i) .gt. 0) then
609  kmax=kgd(i)
610  zmax=hgd(i)
611 
612  do k=kgd(i-1)+1,kgd(i)
613  vertical_grid%z(k)=hgd(i-1)+(hgd(i)-hgd(i-1))*real(k-kgd(i-1), kind=default_precision)&
614  /real(kgd(i)-kgd(i-1), kind=default_precision)
615  end do
616  end if
617  end do
618  end if
619  if(kmax .lt. kkp)then
620  do k=kmax,kkp
621  ! Handle any points above the kth max division
622  vertical_grid%z(k)=zmax+(zztop-zmax)*real(k-kmax, kind=default_precision)/real(kkp-kmax, kind=default_precision)
623  end do
624  end if
Here is the caller graph for this function:

◆ finalise_callback()

subroutine gridmanager_mod::finalise_callback ( type(model_state_type), intent(inout), target  current_state)
private

Called as MONC exits, for good practice this will deallocate the memory used for the grids.

Parameters
current_stateThe current model state_mod

Definition at line 70 of file gridmanager.F90.

70  type(model_state_type), target, intent(inout) :: current_state
71 
72  type(vertical_grid_configuration_type) :: vertical_grid
73 
74  vertical_grid=current_state%global_grid%configuration%vertical
75 
76  deallocate(vertical_grid%z, vertical_grid%zn, vertical_grid%dz, vertical_grid%dzn, vertical_grid%czb, vertical_grid%cza, &
77  vertical_grid%czg, vertical_grid%czh, vertical_grid%rdz, vertical_grid%rdzn, vertical_grid%tzc1, vertical_grid%tzc2,&
78  vertical_grid%tzd1, vertical_grid%tzd2, vertical_grid%thref, vertical_grid%theta_init, vertical_grid%tref, &
79  vertical_grid%prefn, vertical_grid%pdiff, vertical_grid%prefrcp, vertical_grid%rprefrcp, vertical_grid%rho, &
80  vertical_grid%rhon, vertical_grid%tstarpr, vertical_grid%qsat, vertical_grid%dqsatdt, vertical_grid%qsatfac, &
81  vertical_grid%dthref, vertical_grid%rneutml, vertical_grid%rneutml_sq, vertical_grid%buoy_co, &
82  vertical_grid%u_init, vertical_grid%v_init, vertical_grid%q_init, &
83  vertical_grid%q_rand, vertical_grid%theta_rand, vertical_grid%w_subs, vertical_grid%w_rand, &
84  vertical_grid%q_force, vertical_grid%theta_force, vertical_grid%u_force, vertical_grid%v_force &
85  )
Here is the caller graph for this function:

◆ gridmanager_get_descriptor()

type(component_descriptor_type) function, public gridmanager_mod::gridmanager_get_descriptor ( )

Provides the descriptor back to the caller and is used in component registration.

Returns
The GridManager component descriptor

Definition at line 38 of file gridmanager.F90.

38  gridmanager_get_descriptor%name="grid_manager"
39  gridmanager_get_descriptor%version=0.1
40  gridmanager_get_descriptor%initialisation=>initialise_callback
41  gridmanager_get_descriptor%finalisation=>finalise_callback
Here is the call graph for this function:

◆ initialise_callback()

subroutine gridmanager_mod::initialise_callback ( type(model_state_type), intent(inout), target  current_state)
private

Called during initialisation and will initialise the horizontal and vertical grid configurations Note that the model state_mod (from a checkpoint or external file) must have been initialised already.

Parameters
current_stateThe current model state_mod

Definition at line 48 of file gridmanager.F90.

48  type(model_state_type), target, intent(inout) :: current_state
49 
50  integer :: dimensions
51 
52  if (.not. current_state%initialised) then
53  call log_log(log_error, "Must initialise the model state_mod before constructing the grid properties")
54  end if
55 
56  call initialise_horizontalgrid_configuration_types(current_state)
57  call initialise_verticalgrid_configuration_type(current_state)
58  dimensions=1
59  if (current_state%global_grid%active(x_index)) dimensions = dimensions+1
60  if (current_state%global_grid%active(y_index)) dimensions = dimensions+1
61  call log_master_log(log_info, trim(conv_to_string(dimensions))//"D system; z="//&
62  trim(conv_to_string(current_state%global_grid%size(z_index)))//", y="//&
63  trim(conv_to_string(current_state%global_grid%size(y_index)))//", x="//&
64  trim(conv_to_string(current_state%global_grid%size(x_index))))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialise_horizontalgrid_configuration_types()

subroutine gridmanager_mod::initialise_horizontalgrid_configuration_types ( type(model_state_type), intent(inout)  current_state)
private

Initialises the horizontal grid configurations.

Parameters
current_stateThe current model state_mod

Definition at line 657 of file gridmanager.F90.

657  type(model_state_type), intent(inout) :: current_state
658 
659  current_state%global_grid%configuration%horizontal%dx = merge(real(current_state%global_grid%resolution(X_INDEX)), &
660  default_spacing, current_state%global_grid%active(x_index))
661  current_state%global_grid%configuration%horizontal%dy = merge(real(current_state%global_grid%resolution(Y_INDEX)), &
662  default_spacing, current_state%global_grid%active(y_index))
663 
664  current_state%global_grid%configuration%horizontal%cx=1./current_state%global_grid%configuration%horizontal%dx
665  current_state%global_grid%configuration%horizontal%cy=1./current_state%global_grid%configuration%horizontal%dy
666  current_state%global_grid%configuration%horizontal%cx2=current_state%global_grid%configuration%horizontal%cx ** 2
667  current_state%global_grid%configuration%horizontal%cy2=current_state%global_grid%configuration%horizontal%cy ** 2
668  current_state%global_grid%configuration%horizontal%cxy=current_state%global_grid%configuration%horizontal%cx * &
669  current_state%global_grid%configuration%horizontal%cy
670  current_state%global_grid%configuration%horizontal%tcx=&
671  0.25_default_precision/current_state%global_grid%configuration%horizontal%dx
672  current_state%global_grid%configuration%horizontal%tcy=&
673  0.25_default_precision/current_state%global_grid%configuration%horizontal%dy
Here is the caller graph for this function:

◆ initialise_verticalgrid_configuration_type()

subroutine gridmanager_mod::initialise_verticalgrid_configuration_type ( type(model_state_type), intent(inout)  current_state)
private

Will initialise the vertical grid configuration.

Parameters
current_stateThe current model state_mod

Definition at line 91 of file gridmanager.F90.

91  type(model_state_type), intent(inout) :: current_state
92 
93  call allocate_vertical_grid_data(current_state%global_grid%configuration%vertical, &
94  current_state%global_grid%size(z_index), current_state%number_q_fields )
95  call set_up_and_smooth_grid(current_state%global_grid%configuration%vertical, &
96  current_state%global_grid%configuration%vertical%kgd, current_state%global_grid%configuration%vertical%hgd, &
97  size(current_state%global_grid%configuration%vertical%kgd), current_state%global_grid%size(z_index), &
98  current_state%global_grid%top(z_index), options_get_integer(current_state%options_database, "nsmth"), &
99  current_state%origional_vertical_grid_setup, current_state%continuation_run)
100  call set_vertical_reference_profile(current_state, current_state%global_grid%configuration%vertical, &
101  current_state%global_grid%size(z_index))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ new_vertical_grid_setup()

subroutine gridmanager_mod::new_vertical_grid_setup ( type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, dimension(:), intent(in)  kgd,
integer, intent(in)  kkp,
real(kind=default_precision), intent(in)  zztop 
)
private

The newer vertical grid setup routine.

Parameters
vertical_gridThe vertical grid
kgdThe grid heights per division
kkpNumber of points in the vertical domain
zztopThe real world (m) height of the top of the column

Definition at line 536 of file gridmanager.F90.

536  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
537  integer, dimension(:), intent(in) :: kgd
538  integer, intent(in) :: kkp
539  real(kind=DEFAULT_PRECISION), intent(in) :: zztop
540 
541  real(kind=DEFAULT_PRECISION) :: a(2*kkp), r1, d1, dd, d0, a0
542  logical :: first_gt=.true.
543  integer :: k, k0
544 
545  r1=1.10_default_precision
546  d1=10.0_default_precision
547 
548  dd=0.5_default_precision*d1
549  d0=dd
550  a(1)=-dd
551  a(2)=0.0_default_precision
552  do k=3, kkp*2
553  if (d0 .gt. dd .or. k==3) then
554  a(k)=a(k-1)+dd
555  if (.not. (dd .gt. 25.0_default_precision .and. a(k) .lt. 2000.0_default_precision)) then
556  if (a(k) .lt. 2000.0_default_precision) then
557  dd=dd*r1
558  else
559  dd=dd*(1.0_default_precision+(r1-1.0_default_precision)/1.5_default_precision)
560  end if
561  end if
562  d0=(zztop-a(k))/real(kkp*2-k, kind=default_precision)
563  else
564  if (first_gt) then
565  k0=k
566  a0=a(k-1)+d0
567  first_gt=.false.
568  end if
569  a(k)=a0+real(k-k0, kind=default_precision)*d0
570  end if
571  end do
572 
573  do k=1, kkp
574  vertical_grid%z(k)=a(k*2)
575  vertical_grid%zn(k)=a(2*k-1)
576  end do
Here is the caller graph for this function:

◆ original_vertical_grid_setup()

subroutine gridmanager_mod::original_vertical_grid_setup ( type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, dimension(:), intent(in)  kgd,
real(kind=default_precision), dimension(:), intent(in)  hgd,
integer, intent(in)  ninitp,
integer, intent(in)  kkp,
real(kind=default_precision), intent(in)  zztop,
integer, intent(in)  nsmth 
)
private

The original vertical grid setup and smoothing as per the LEM.

Parameters
vertical_gridThe vertical grid
kgdThe grid heights per division
hgdThe real world (m) heights per division
kkpNumber of points in the vertical domain
zztopThe real world (m) height of the top of the column
nsmthNumber of smoothing iterations to run on the grid

Definition at line 500 of file gridmanager.F90.

500  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
501  integer, dimension(:), intent(in) :: kgd
502  real(kind=DEFAULT_PRECISION), dimension(:), intent(in) :: hgd
503  integer, intent(in) :: ninitp, kkp, nsmth
504  real(kind=DEFAULT_PRECISION), intent(in) :: zztop
505 
506  integer :: n, k
507 
508  call create_linear_grid(vertical_grid, kgd, hgd, ninitp, kkp, zztop)
509  ! Smooth grid
510  vertical_grid%z(1)=0.0_default_precision
511  vertical_grid%z(kkp)=zztop
512  do n=1,nsmth
513  do k=2,kkp
514  vertical_grid%zn(k)=0.5_default_precision*(vertical_grid%z(k)+vertical_grid%z(k-1))
515  end do
516  do k=2,kkp-1
517  vertical_grid%z(k)=0.5_default_precision*(vertical_grid%zn(k)+vertical_grid%zn(k+1))
518  end do
519  end do
520  ! Fourth order interpolation
521  do k=3,kkp-1
522  vertical_grid%zn(k)=0.0625_default_precision*(9.0_default_precision*&
523  (vertical_grid%z(k-1)+vertical_grid%z(k))-vertical_grid%z(k+1)-vertical_grid%z(k-2))
524  end do
525  vertical_grid%zn(2)=0.5_default_precision*(vertical_grid%z(1)+vertical_grid%z(2))
526  vertical_grid%zn(1)=-vertical_grid%zn(2)
527  vertical_grid%zn(kkp)=0.5_default_precision*(vertical_grid%z(kkp-1)+vertical_grid%z(kkp))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_anelastic_pressure()

subroutine gridmanager_mod::set_anelastic_pressure ( type(model_state_type), intent(inout)  current_state)
private

Set reference profile of potential temperature for the Boussinesq/Anelastic approximation Note that this is not in general the same as the profile defining the initial vertical distribution of potential temperature for the integration. In particular, while the later may contain sharp changes in gradient representing a capping inversion or the tropopause, for example, the reference profile should be smooth.

Parameters
current_stateThe current model state

Definition at line 682 of file gridmanager.F90.

682  type(model_state_type), intent(inout) :: current_state
683 
684  if (current_state%use_anelastic_equations) then
685  call compute_anelastic_pressure_profile_and_density(current_state)
686  else
687  if (current_state%passive_th) then
688  current_state%global_grid%configuration%vertical%prefn=0.0_default_precision
689  else
690  call compute_anelastic_pressure_profile_only(current_state)
691  end if
692  current_state%global_grid%configuration%vertical%rho=current_state%rhobous
693  current_state%global_grid%configuration%vertical%rhon=current_state%rhobous
694  current_state%global_grid%configuration%vertical%pdiff=0.0_default_precision
695  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_buoyancy_coefficient()

subroutine gridmanager_mod::set_buoyancy_coefficient ( type(model_state_type), intent(inout), target  current_state,
type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, intent(in)  kkp 
)
private

Sets the buoyancy coefficient from the grid configuration and configuration.

Parameters
current_stateThe current model state_mod
vertical_gridThe vertical grid that we are working on
kkpNumber of grid points in a vertical column

Definition at line 350 of file gridmanager.F90.

350  type(model_state_type), intent(inout), target :: current_state
351  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
352  integer, intent(in) :: kkp
353 
354  integer :: k
355 
356  if (.not. current_state%passive_th) then
357  if(current_state%use_anelastic_equations)then
358  do k=1, kkp-1
359  vertical_grid%buoy_co(k)=cp*(vertical_grid%prefn(k)**r_over_cp-vertical_grid%prefn(k+1)**r_over_cp)/&
360  ((current_state%surface_reference_pressure**r_over_cp)*vertical_grid%dzn(k+1))
361  end do
362  else
363  vertical_grid%buoy_co(1:kkp-1)=g/current_state%thref0 ! _Boussinesq
364  end if
365  ! Dummy value at top level
366  vertical_grid%buoy_co(kkp)=0.
367  else
368  vertical_grid%buoy_co(:)=0.
369  end if
Here is the caller graph for this function:

◆ set_up_and_smooth_grid()

subroutine gridmanager_mod::set_up_and_smooth_grid ( type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, dimension(:), intent(in)  kgd,
real(kind=default_precision), dimension(:), intent(in)  hgd,
integer, intent(in)  ninitp,
integer, intent(in)  kkp,
real(kind=default_precision), intent(in)  zztop,
integer, intent(in)  nsmth,
logical, intent(in)  origional_setup,
logical, intent(in)  continuation_run 
)
private

Sets up and smooths the vertical grid. This is based upon the grid configuration already read in.

Parameters
vertical_gridThe vertical grid
kgdThe grid heights per division
hgdThe real world (m) heights per division
kkpNumber of points in the vertical domain
zztopThe real world (m) height of the top of the column
nsmthNumber of smoothing iterations to run on the grid
origional_setupTo use the origional vertical grid setup routine or the new one

Definition at line 465 of file gridmanager.F90.

465  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
466  integer, dimension(:), intent(in) :: kgd
467  real(kind=DEFAULT_PRECISION), dimension(:), intent(in) :: hgd
468  integer, intent(in) :: ninitp, kkp, nsmth
469  real(kind=DEFAULT_PRECISION),intent(in) :: zztop
470  logical, intent(in) :: origional_setup, continuation_run
471 
472  integer :: k
473 
474  if (.not. continuation_run) then
475  if (origional_setup) then
476  call original_vertical_grid_setup(vertical_grid, kgd, hgd, ninitp, kkp, zztop, nsmth)
477  else
478  call new_vertical_grid_setup(vertical_grid, kgd, kkp, zztop)
479  end if
480  end if
481 
482  ! Regardless of the vertical grid computation method, set the level deltas
483  do k=2,kkp
484  vertical_grid%dz(k)=vertical_grid%z(k)-vertical_grid%z(k-1)
485  vertical_grid%dzn(k)= vertical_grid%zn(k)-vertical_grid%zn(k-1)
486  vertical_grid%rdz(k)=1./vertical_grid%dz(k)
487  vertical_grid%rdzn(k)=1./vertical_grid%dzn(k)
488  end do
489  vertical_grid%dzn(1)=0.d0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_up_vertical_reference_properties()

subroutine gridmanager_mod::set_up_vertical_reference_properties ( type(model_state_type), intent(inout)  current_state,
type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, intent(in)  kkp 
)
private

Sets up the reference properties for the vertical grid at each point.

Parameters
current_stateThe current model state_mod
vertical_gridThe vertical grid that we are working on
kkpThe number of grid points in a vertical column

Definition at line 436 of file gridmanager.F90.

436  type(model_state_type), intent(inout) :: current_state
437  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
438  integer, intent(in) :: kkp
439 
440  integer :: k
441 
442  do k=1,kkp
443 ! vertical_grid%thref(k)=current_state%thref0
444 ! vertical_grid%theta_init(k)=vertical_grid%thref(k) ! In LEM this can also be set from configuration (TODO)
445  vertical_grid%prefn(k)=0.0_default_precision
446  vertical_grid%pdiff(k)=0.0_default_precision
447  vertical_grid%rho(k)=current_state%rhobous
448  vertical_grid%rhon(k)=current_state%rhobous
449  end do
450  do k=1,kkp-1
451  vertical_grid%dthref(k)=vertical_grid%thref(k+1)-vertical_grid%thref(k)
452  end do
453  vertical_grid%dthref(kkp)=0.0_default_precision
Here is the caller graph for this function:

◆ set_vertical_reference_profile()

subroutine gridmanager_mod::set_vertical_reference_profile ( type(model_state_type), intent(inout)  current_state,
type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, intent(in)  kkp 
)
private

Sets up the vertical grid reference profile at each point.

Parameters
current_stateThe current model state_mod
vertical_gridThe vertical grid that we are working on
kkpNumber of grid points in a vertical column

Definition at line 109 of file gridmanager.F90.

109  type(model_state_type), intent(inout) :: current_state
110  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
111  integer, intent(in) :: kkp
112 
113  integer :: k
114 
115  call calculate_initial_profiles(current_state, vertical_grid)
116  call set_up_vertical_reference_properties(current_state, vertical_grid, current_state%global_grid%size(z_index))
117  call set_anelastic_pressure(current_state)
118 
119  do k=2,kkp-1
120  ! for diffusion onto p-level from below
121  vertical_grid%czb(k)=(vertical_grid%rho(k-1)/vertical_grid%rhon(k))/(vertical_grid%dz(k)*vertical_grid%dzn(k))
122  ! for diffusion onto p-level from above
123  vertical_grid%cza(k)=(vertical_grid%rho(k)/vertical_grid%rhon(k))/(vertical_grid%dz(k)*vertical_grid%dzn(k+1))
124  vertical_grid%czg(k)=-vertical_grid%czb(k)-vertical_grid%cza(k)
125  if (k .gt. 2) vertical_grid%czh(k)=vertical_grid%czb(k)*vertical_grid%cza(k-1)
126  end do
127  do k=2,kkp-1
128  ! advection onto p-level from below
129  vertical_grid%tzc1(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k-1)/vertical_grid%rhon(k)
130  ! advection onto p-level from above
131  vertical_grid%tzc2(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k)/vertical_grid%rhon(k)
132  end do
133  do k=2,kkp-1
134  ! advection onto w-level (K) from below
135  vertical_grid%tzd1(k)=0.25_default_precision*vertical_grid%rdzn(k+1)*vertical_grid%rhon(k)/vertical_grid%rho(k)
136  ! advection onto w-level (K) from above
137  vertical_grid%tzd2(k)=0.25_default_precision*vertical_grid%rdzn(k+1)*vertical_grid%rhon(k+1)/vertical_grid%rho(k)
138  end do
139  k=kkp
140  vertical_grid%czb(k)=(vertical_grid%rho(k-1)/vertical_grid%rhon(k))/(vertical_grid%dz(k)*vertical_grid%dzn(k))
141  vertical_grid%cza(k)=0.0_default_precision
142  vertical_grid%czg(k)=-vertical_grid%czb(k)
143  vertical_grid%czh(k)=vertical_grid%czb(k)*vertical_grid%cza(k-1)
144  vertical_grid%tzc2(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k)/vertical_grid%rhon(k)
145  vertical_grid%tzc1(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k-1)/vertical_grid%rhon(k)
146  vertical_grid%czn=vertical_grid%dzn(2)*0.5_default_precision
147  vertical_grid%zlogm=log(1.0_default_precision+vertical_grid%zn(2)/z0)
148  vertical_grid%zlogth=log((vertical_grid%zn(2)+z0)/z0th)
149  vertical_grid%vk_on_zlogm=von_karman_constant/vertical_grid%zlogm
150  call setup_reference_state_liquid_water_temperature_and_saturation(&
151  current_state, vertical_grid, current_state%global_grid%size(z_index))
152  call calculate_mixing_length_for_neutral_case(current_state, vertical_grid, current_state%global_grid%size(z_index))
153  call set_buoyancy_coefficient(current_state, vertical_grid, current_state%global_grid%size(z_index))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_reference_state_liquid_water_temperature_and_saturation()

subroutine gridmanager_mod::setup_reference_state_liquid_water_temperature_and_saturation ( type(model_state_type), intent(inout)  current_state,
type(vertical_grid_configuration_type), intent(inout)  vertical_grid,
integer, intent(in)  kkp 
)
private

Setting up reference state liquid water temperature and saturation mixing ratio on main levels.

Parameters
current_stateThe current model state_mod
vertical_gridThe vertical grid that we are working on
kkpNumber of grid points in a vertical column

Definition at line 377 of file gridmanager.F90.

377  type(model_state_type), intent(inout) :: current_state
378  type(vertical_grid_configuration_type), intent(inout) :: vertical_grid
379  integer, intent(in) :: kkp
380 
381  real(kind=DEFAULT_PRECISION) :: delta_t=1.0_default_precision, qlinit, tinit, qsatin, dqsatdtin, dsatfacin
382  integer :: iter, k
383 
384  do k=1,kkp
385  vertical_grid%tref(k)=vertical_grid%thref(k)*(vertical_grid%prefn(k)/current_state%surface_reference_pressure)**r_over_cp
386  vertical_grid%tstarpr(k)=0.0_default_precision
387  end do
388  if (current_state%th%active) then
389  ! PREFRCP is used and hence calculated if theta is active
390  do k = 1,kkp
391  vertical_grid%prefrcp(k)=(current_state%surface_reference_pressure/vertical_grid%prefn(k))**r_over_cp
392  vertical_grid%rprefrcp(k)=1.0_default_precision/vertical_grid%prefrcp(k)
393  ! Denotion between setup run and chain run in LEM - need to consider here too
394  vertical_grid%qsat(k)=qsaturation(vertical_grid%tref(k), 0.01_default_precision*vertical_grid%prefn(k))
395  vertical_grid%dqsatdt(k)=(qsaturation(vertical_grid%tref(k)+delta_t, 0.01_default_precision*vertical_grid%prefn(k)) -&
396  qsaturation(vertical_grid%tref(k)-delta_t, 0.01_default_precision*vertical_grid%prefn(k)))/&
397  (2.0_default_precision*delta_t)
398  vertical_grid%qsatfac(k)=1.0_default_precision/(1.0_default_precision+rlvap_over_cp*vertical_grid%dqsatdt(k))
399  end do
400  if (current_state%calculate_th_and_q_init) then
401  do k=1,kkp
402  ! !Note that at this point THETA_INIT and QINIT(IQ=1) are still
403  ! !theta_l and q_t, as read in from configuration.
404  ! ! start from input QL profile
405  qlinit=qinit(k, current_state%liquid_water_mixing_ratio_index)
406  do iter=1,5
407  ! ! calculate T and thence new q_l from Taylor expansion
408  ! ! keeping theta_l and q_t fixed
409  ! ! Note theta_l = theta - (L/c_p)*q_l here
410  tinit = vertical_grid%theta_init(k)*vertical_grid%rprefrcp(k) + rlvap_over_cp*qlinit
411  qsatin = qsaturation(tinit, 0.01_default_precision*vertical_grid%prefn(k))
412  dqsatdtin = dqwsatdt(qsatin, tinit)
413  dsatfacin=( 1.0_default_precision/(1.0_default_precision + rlvap_over_cp*dqsatdtin*vertical_grid%rprefrcp(k)))
414  qlinit=max(0.0_default_precision, (qinit(k, current_state%water_vapour_mixing_ratio_index)-&
415  (qsatin+dqsatdtin*(vertical_grid%theta_init(k)*vertical_grid%rprefrcp(k)-tinit) ))*dsatfacin)
416  end do
417  qinit(k, current_state%liquid_water_mixing_ratio_index)=qlinit
418  qinit(k, current_state%water_vapour_mixing_ratio_index)=qinit(k,current_state%water_vapour_mixing_ratio_index)-qlinit
419  vertical_grid%theta_init(k)=vertical_grid%theta_init(k)+rlvap_over_cp*qlinit
420 
421  ! Denotion between setup run and chain run in LEM - need to consider here too
422  vertical_grid%tstarpr(k)= tinit-vertical_grid%tref(k)
423  vertical_grid%qsat(k)=qsatin
424  vertical_grid%dqsatdt(k)=dqsatdtin
425  vertical_grid%qsatfac(k)= ( 1.0_default_precision/ ( 1.0_default_precision + rlvap_over_cp*dqsatdtin ) )
426  end do
427  endif
428  end if
Here is the caller graph for this function:

Variable Documentation

◆ anelastic_profile_mode

integer, parameter gridmanager_mod::anelastic_profile_mode =4
private

Definition at line 27 of file gridmanager.F90.

27  integer, parameter :: anelastic_profile_mode=4

◆ default_spacing

real, parameter gridmanager_mod::default_spacing = 1.E9
private

The default spacing used if no grid is active in a specific dimension.

Definition at line 28 of file gridmanager.F90.

28  real, parameter :: default_spacing = 1.e9

◆ qinit

real(kind=default_precision), dimension(:,:), allocatable gridmanager_mod::qinit
private

Definition at line 29 of file gridmanager.F90.

29  real(kind=DEFAULT_PRECISION), dimension(:,:), allocatable :: qinit