29 real(kind=DEFAULT_PRECISION),
dimension(:,:),
allocatable ::
qinit 48 type(model_state_type),
target,
intent(inout) :: current_state
52 if (.not. current_state%initialised)
then 53 call log_log(log_error,
"Must initialise the model state_mod before constructing the grid properties")
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))))
70 type(model_state_type),
target,
intent(inout) :: current_state
72 type(vertical_grid_configuration_type) :: vertical_grid
74 vertical_grid=current_state%global_grid%configuration%vertical
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 &
91 type(model_state_type),
intent(inout) :: current_state
94 current_state%global_grid%size(z_index), current_state%number_q_fields )
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)
101 current_state%global_grid%size(z_index))
109 type(model_state_type),
intent(inout) :: current_state
110 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
111 integer,
intent(in) :: kkp
121 vertical_grid%czb(k)=(vertical_grid%rho(k-1)/vertical_grid%rhon(k))/(vertical_grid%dz(k)*vertical_grid%dzn(k))
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)
129 vertical_grid%tzc1(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k-1)/vertical_grid%rhon(k)
131 vertical_grid%tzc2(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k)/vertical_grid%rhon(k)
135 vertical_grid%tzd1(k)=0.25_default_precision*vertical_grid%rdzn(k+1)*vertical_grid%rhon(k)/vertical_grid%rho(k)
137 vertical_grid%tzd2(k)=0.25_default_precision*vertical_grid%rdzn(k+1)*vertical_grid%rhon(k+1)/vertical_grid%rho(k)
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
151 current_state, vertical_grid, current_state%global_grid%size(z_index))
161 type(model_state_type),
intent(inout) :: current_state
162 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
169 real(kind=DEFAULT_PRECISION),
dimension(:,:),
allocatable :: f_init_pl_q
170 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: z_init_pl_q
171 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: f_init_pl_theta
172 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: z_init_pl_theta
173 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: f_init_pl_u
174 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: z_init_pl_u
175 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: f_init_pl_v
176 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: z_init_pl_v
178 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: f_thref
179 real(kind=DEFAULT_PRECISION),
dimension(:),
allocatable :: z_thref
181 logical :: l_init_pl_u
182 logical :: l_init_pl_v
183 logical :: l_init_pl_theta
184 logical :: l_init_pl_q
186 logical :: l_matchthref
188 character(len=STRING_LENGTH),
dimension(:),
allocatable :: names_init_pl_q
190 real(kind=DEFAULT_PRECISION),
allocatable :: f_init_pl_q_tmp(:)
191 real(kind=DEFAULT_PRECISION),
allocatable :: zgrid(:)
193 real(kind=DEFAULT_PRECISION) :: zztop
195 allocate(zgrid(current_state%local_grid%local_domain_end_index(z_index)))
197 zztop = current_state%global_grid%top(z_index)
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
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)
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")
214 l_thref=options_get_logical(current_state%options_database,
"l_thref")
215 l_matchthref=options_get_logical(current_state%options_database,
"l_matchthref")
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)
230 current_state%global_grid%configuration%vertical%thref(:)=current_state%thref0
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")
246 current_state%global_grid%configuration%vertical%thref = current_state%global_grid%configuration%vertical%theta_init
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(:)
256 deallocate(z_init_pl_theta, f_init_pl_theta)
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(:)
275 deallocate(z_init_pl_u, f_init_pl_u)
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(:)
294 deallocate(z_init_pl_v, f_init_pl_v)
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/))
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)
322 deallocate(f_init_pl_q_tmp, z_init_pl_q, f_init_pl_q, names_init_pl_q)
332 type(model_state_type),
intent(inout) :: current_state
333 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
334 integer,
intent(in) :: kkp
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)
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
356 if (.not. current_state%passive_th)
then 357 if(current_state%use_anelastic_equations)
then 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))
363 vertical_grid%buoy_co(1:kkp-1)=g/current_state%thref0
366 vertical_grid%buoy_co(kkp)=0.
368 vertical_grid%buoy_co(:)=0.
377 type(model_state_type),
intent(inout) :: current_state
378 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
379 integer,
intent(in) :: kkp
381 real(kind=DEFAULT_PRECISION) :: delta_t=1.0_default_precision, qlinit, tinit, qsatin, dqsatdtin, dsatfacin
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
388 if (current_state%th%active)
then 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)
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))
400 if (current_state%calculate_th_and_q_init)
then 405 qlinit=
qinit(k, current_state%liquid_water_mixing_ratio_index)
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)
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
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 ) )
436 type(model_state_type),
intent(inout) :: current_state
437 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
438 integer,
intent(in) :: kkp
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
451 vertical_grid%dthref(k)=vertical_grid%thref(k+1)-vertical_grid%thref(k)
453 vertical_grid%dthref(kkp)=0.0_default_precision
464 subroutine set_up_and_smooth_grid(vertical_grid, kgd, hgd, ninitp, kkp, zztop, nsmth, origional_setup, continuation_run)
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
474 if (.not. continuation_run)
then 475 if (origional_setup)
then 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)
489 vertical_grid%dzn(1)=0.d0
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
510 vertical_grid%z(1)=0.0_default_precision
511 vertical_grid%z(kkp)=zztop
514 vertical_grid%zn(k)=0.5_default_precision*(vertical_grid%z(k)+vertical_grid%z(k-1))
517 vertical_grid%z(k)=0.5_default_precision*(vertical_grid%zn(k)+vertical_grid%zn(k+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))
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))
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
541 real(kind=DEFAULT_PRECISION) :: a(2*kkp), r1, d1, dd, d0, a0
542 logical :: first_gt=.true.
545 r1=1.10_default_precision
546 d1=10.0_default_precision
548 dd=0.5_default_precision*d1
551 a(2)=0.0_default_precision
553 if (d0 .gt. dd .or. k==3)
then 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 559 dd=dd*(1.0_default_precision+(r1-1.0_default_precision)/1.5_default_precision)
562 d0=(zztop-a(k))/
real(kkp*2-k, kind=default_precision)
569 a(k)=a0+
real(k-k0, kind=default_precision)*d0
574 vertical_grid%z(k)=a(k*2)
575 vertical_grid%zn(k)=a(2*k-1)
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
596 integer :: kmax, k, i
597 real(kind=DEFAULT_PRECISION) :: zmax
599 vertical_grid%z(1) = 0.0_default_precision
601 zmax=0.0_default_precision
602 if (kgd(1) .gt. 1)
then 605 vertical_grid%z(k)=
real(k-1, kind=default_precision)*hgd(1)/
real(kgd(1)-1, kind=default_precision)
608 if(kgd(i) .gt. 0)
then 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)
619 if(kmax .lt. kkp)
then 622 vertical_grid%z(k)=zmax+(zztop-zmax)*
real(k-kmax, kind=default_precision)/
real(kkp-kmax, kind=default_precision)
632 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
633 integer,
intent(in) :: n
634 integer,
intent(in) :: nq
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))
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))
651 allocate(vertical_grid%q_rand(n,nq), vertical_grid%q_init(n,nq), vertical_grid%q_force(n,nq))
657 type(model_state_type),
intent(inout) :: current_state
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))
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
682 type(model_state_type),
intent(inout) :: current_state
684 if (current_state%use_anelastic_equations)
then 687 if (current_state%passive_th)
then 688 current_state%global_grid%configuration%vertical%prefn=0.0_default_precision
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
701 type(model_state_type),
intent(inout) :: current_state
704 real(kind=DEFAULT_PRECISION) :: p0 &
706 , thprof(current_state%local_grid%size(z_index))
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
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)))
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)
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)
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")
739 ptop=ptop**(1.0_default_precision/r_over_cp)
747 type(model_state_type),
intent(inout) :: current_state
750 real(kind=DEFAULT_PRECISION) :: p0 &
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
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)))
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)
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)
776 p0=0.5_default_precision*(current_state%global_grid%configuration%vertical%prefn(1)+&
777 current_state%global_grid%configuration%vertical%prefn(2))
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
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")
804 ptop=ptop**(1.0_default_precision/r_over_cp)
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)
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))
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)
826 real(kind=DEFAULT_PRECISION),
intent(in) :: zztop
827 real(kind=DEFAULT_PRECISION),
intent(in) :: z
828 character(*),
intent(in) :: info
831 call log_master_log(log_error,
"Top of input profile is below the top of the domain:"//trim(info))
subroutine initialise_verticalgrid_configuration_type(current_state)
Will initialise the vertical grid configuration.
real(kind=default_precision), public z0th
integer function, public options_get_array_size(options_database, key)
Gets the size of the array held in the options database corresponding to a specific key...
subroutine set_vertical_reference_profile(current_state, vertical_grid, kkp)
Sets up the vertical grid reference profile at each point.
subroutine set_buoyancy_coefficient(current_state, vertical_grid, kkp)
Sets the buoyancy coefficient from the grid configuration and configuration.
type(standard_q_names_type), public standard_q_names
real(kind=default_precision), public r_over_cp
subroutine original_vertical_grid_setup(vertical_grid, kgd, hgd, ninitp, kkp, zztop, nsmth)
The original vertical grid setup and smoothing as per the LEM.
subroutine initialise_callback(current_state)
Called during initialisation and will initialise the horizontal and vertical grid configurations Note...
type(component_descriptor_type) function, public gridmanager_get_descriptor()
Provides the descriptor back to the caller and is used in component registration. ...
real(kind=default_precision), public cp
integer, parameter, public log_error
Only log ERROR messages.
subroutine calculate_mixing_length_for_neutral_case(current_state, vertical_grid, kkp)
Calculates the mixing length for the neutral case.
real(kind=default_precision) function, public dqwsatdt(saturation_mixing_ratio, temperature)
Calculated the rate of change with temperature of saturation mixing ratio over liquid water...
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
integer, parameter, public z_index
Grid index parameters.
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...
real(kind=default_precision), public g
subroutine allocate_vertical_grid_data(vertical_grid, n, nq)
Allocates the data required for the vertical grid configuration.
Manages the grid based upon the model state_mod.
Contains common definitions for the data and datatypes used by MONC.
The ModelState which represents the current state of a run.
subroutine, public log_master_log(level, message)
Will log just from the master process.
Conversion between common inbuilt FORTRAN data types.
subroutine initialise_horizontalgrid_configuration_types(current_state)
Initialises the horizontal grid configurations.
real(kind=default_precision), public z0
Converts data types to strings.
Description of a component.
Saturation physics functionality which is used throughout the code.
subroutine compute_anelastic_pressure_profile_and_density(current_state)
Computes the anelastic pressure and density - if we are using Anelastic approximation.
real(kind=default_precision), public von_karman_constant
The configuration of the grid vertically.
subroutine, public log_log(level, message, str)
Logs a message at the specified level. If the level is above the current level then the message is ig...
subroutine set_up_vertical_reference_properties(current_state, vertical_grid, kkp)
Sets up the reference properties for the vertical grid at each point.
Scientific constant values used throughout simulations. Each has a default value and this can be over...
This manages the Q variables and specifically the mapping between names and the index that they are s...
subroutine compute_anelastic_pressure_profile_only(current_state)
Computes the anelastic pressure only - if we are using Boussinesq approximation.
Interfaces and types that MONC components must specify.
subroutine piecewise_linear_1d(zvals, vals, zgrid, field)
Does a simple 1d piecewise linear interpolation.
integer, parameter anelastic_profile_mode
subroutine set_anelastic_pressure(current_state)
Set reference profile of potential temperature for the Boussinesq/Anelastic approximation Note that t...
subroutine, public options_get_logical_array(options_database, key, array_data, from, to)
Retrieves an entire (or subset) logical array.
integer, parameter, public string_length
Default length of strings.
subroutine calculate_initial_profiles(current_state, vertical_grid)
Calculates the initial profiles for U, V, TH & Q if required.
subroutine create_linear_grid(vertical_grid, kgd, hgd, ninitp, kkp, zztop)
Creates the linear vertical grid based upon the configuration properties.
subroutine finalise_callback(current_state)
Called as MONC exits, for good practice this will deallocate the memory used for the grids...
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...
real(kind=default_precision) function, public qsaturation(temperature, pressure)
Function to return the saturation mixing ratio over water based on tetans formular QS=3...
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...
real(kind=default_precision), dimension(:,:), allocatable qinit
integer function, public options_get_integer(options_database, key, index)
Retrieves an integer value from the database that matches the provided key.
Manages the options database. Contains administration functions and deduce runtime options from the c...
integer, parameter, public log_info
Log INFO, WARNING and ERROR messages.
logical function, public options_get_logical(options_database, key, index)
Retrieves a logical value from the database that matches the provided key.
real, parameter default_spacing
The default spacing used if no grid is active in a specific dimension.
real(kind=default_precision), public r
subroutine, public options_get_string_array(options_database, key, array_data, from, to)
Retrieves an entire (or subset) string array.
subroutine check_top(zztop, z, info)
subroutine, public options_get_real_array(options_database, key, array_data, from, to)
Retrieves an entire (or subset) real array.
subroutine new_vertical_grid_setup(vertical_grid, kgd, kkp, zztop)
The newer vertical grid setup routine.
real(kind=default_precision), public rlvap_over_cp
The model state which represents the current state of a run.
integer, parameter, public y_index
integer, parameter, public x_index
integer function, public get_q_index(name, assigning_component)
Add in a new entry into the register if the name does not already exist or return the index of the pr...