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%temp_init, &
79 vertical_grid%rh_init, vertical_grid%tref, &
80 vertical_grid%prefn, vertical_grid%pdiff, vertical_grid%prefrcp, vertical_grid%rprefrcp, vertical_grid%rho, &
81 vertical_grid%rhon, vertical_grid%tstarpr, vertical_grid%qsat, vertical_grid%dqsatdt, vertical_grid%qsatfac, &
82 vertical_grid%dthref, vertical_grid%rneutml, vertical_grid%rneutml_sq, vertical_grid%buoy_co, &
83 vertical_grid%u_init, vertical_grid%v_init, vertical_grid%q_init, &
84 vertical_grid%q_rand, vertical_grid%theta_rand, vertical_grid%w_subs, vertical_grid%w_rand, &
85 vertical_grid%q_force, vertical_grid%theta_force, vertical_grid%u_force, vertical_grid%v_force &
92 type(model_state_type),
intent(inout) :: current_state
95 current_state%global_grid%size(z_index), current_state%number_q_fields )
97 current_state%global_grid%configuration%vertical%kgd, current_state%global_grid%configuration%vertical%hgd, &
98 size(current_state%global_grid%configuration%vertical%kgd), current_state%global_grid%size(z_index), &
99 current_state%global_grid%top(z_index), options_get_integer(current_state%options_database,
"nsmth"), &
100 current_state%origional_vertical_grid_setup, current_state%continuation_run)
102 current_state%global_grid%size(z_index))
111 type(model_state_type),
intent(inout) :: current_state
112 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
113 integer,
intent(in) :: kkp
125 vertical_grid%czb(k)=(vertical_grid%rho(k-1)/vertical_grid%rhon(k))/(vertical_grid%dz(k)*vertical_grid%dzn(k))
127 vertical_grid%cza(k)=(vertical_grid%rho(k)/vertical_grid%rhon(k))/(vertical_grid%dz(k)*vertical_grid%dzn(k+1))
128 vertical_grid%czg(k)=-vertical_grid%czb(k)-vertical_grid%cza(k)
129 if (k .gt. 2) vertical_grid%czh(k)=vertical_grid%czb(k)*vertical_grid%cza(k-1)
133 vertical_grid%tzc1(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k-1)/vertical_grid%rhon(k)
135 vertical_grid%tzc2(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k)/vertical_grid%rhon(k)
139 vertical_grid%tzd1(k)=0.25_default_precision*vertical_grid%rdzn(k+1)*vertical_grid%rhon(k)/vertical_grid%rho(k)
141 vertical_grid%tzd2(k)=0.25_default_precision*vertical_grid%rdzn(k+1)*vertical_grid%rhon(k+1)/vertical_grid%rho(k)
144 vertical_grid%czb(k)=(vertical_grid%rho(k-1)/vertical_grid%rhon(k))/(vertical_grid%dz(k)*vertical_grid%dzn(k))
145 vertical_grid%cza(k)=0.0_default_precision
146 vertical_grid%czg(k)=-vertical_grid%czb(k)
147 vertical_grid%czh(k)=vertical_grid%czb(k)*vertical_grid%cza(k-1)
148 vertical_grid%tzc2(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k)/vertical_grid%rhon(k)
149 vertical_grid%tzc1(k)=0.25_default_precision*vertical_grid%rdz(k)*vertical_grid%rho(k-1)/vertical_grid%rhon(k)
150 vertical_grid%czn=vertical_grid%dzn(2)*0.5_default_precision
151 vertical_grid%zlogm=log(1.0_default_precision+vertical_grid%zn(2)/z0)
152 vertical_grid%zlogth=log((vertical_grid%zn(2)+z0)/z0th)
153 vertical_grid%vk_on_zlogm=von_karman_constant/vertical_grid%zlogm
155 current_state, vertical_grid, current_state%global_grid%size(z_index))
165 type(model_state_type),
intent(inout) :: current_state
166 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
173 real(kind=default_precision),
dimension(:,:),
allocatable :: f_init_pl_q
174 real(kind=default_precision),
dimension(:),
allocatable :: z_init_pl_q
175 real(kind=default_precision),
dimension(:),
allocatable :: f_init_pl_theta
176 real(kind=default_precision),
dimension(:),
allocatable :: z_init_pl_theta
177 real(kind=default_precision),
dimension(:),
allocatable :: f_init_pl_u
178 real(kind=default_precision),
dimension(:),
allocatable :: z_init_pl_u
179 real(kind=default_precision),
dimension(:),
allocatable :: f_init_pl_v
180 real(kind=default_precision),
dimension(:),
allocatable :: z_init_pl_v
182 real(kind=default_precision),
dimension(:),
allocatable :: f_thref
183 real(kind=default_precision),
dimension(:),
allocatable :: z_thref
185 logical :: l_init_pl_u
186 logical :: l_init_pl_v
187 logical :: l_init_pl_theta
188 logical :: l_init_pl_rh
189 logical :: l_init_pl_q
191 logical :: l_matchthref
193 character(len=STRING_LENGTH),
dimension(:),
allocatable :: names_init_pl_q
195 real(kind=default_precision),
allocatable :: f_init_pl_q_tmp(:)
196 real(kind=default_precision),
allocatable :: zgrid(:)
198 real(kind=default_precision) :: zztop
199 real(kind=default_precision) :: qsat
201 allocate(zgrid(current_state%local_grid%local_domain_end_index(z_index)))
203 zztop = current_state%global_grid%top(z_index)
206 vertical_grid%q_init = 0.0_default_precision
207 vertical_grid%u_init = 0.0_default_precision
208 vertical_grid%v_init = 0.0_default_precision
209 vertical_grid%theta_init = 0.0_default_precision
211 l_init_pl_theta=options_get_logical(current_state%options_database,
"l_init_pl_theta")
212 l_init_pl_rh=options_get_logical(current_state%options_database,
"l_init_pl_rh")
213 l_init_pl_q=options_get_logical(current_state%options_database,
"l_init_pl_q")
214 if (l_init_pl_q)
then
215 allocate(names_init_pl_q(options_get_array_size(current_state%options_database,
"names_init_pl_q")))
216 call options_get_string_array(current_state%options_database,
"names_init_pl_q", names_init_pl_q)
217 do n = 1,
size(names_init_pl_q)
218 if (trim(names_init_pl_q(n)) .eq.
'vapour' .and. l_init_pl_rh)
then
219 call log_master_log(log_error,
"Initialisation of vapour and RH - STOP")
223 l_init_pl_u=options_get_logical(current_state%options_database,
"l_init_pl_u")
224 l_init_pl_v=options_get_logical(current_state%options_database,
"l_init_pl_v")
226 l_thref=options_get_logical(current_state%options_database,
"l_thref")
227 l_matchthref=options_get_logical(current_state%options_database,
"l_matchthref")
230 if (.not. l_matchthref)
then
231 allocate(z_thref(options_get_array_size(current_state%options_database,
"z_thref")), &
232 f_thref(options_get_array_size(current_state%options_database,
"f_thref")))
233 call options_get_real_array(current_state%options_database,
"z_thref", z_thref)
234 call options_get_real_array(current_state%options_database,
"f_thref", f_thref)
235 call check_top(zztop, z_thref(
size(z_thref)),
'z_thref')
236 zgrid=current_state%global_grid%configuration%vertical%zn(:)
237 call piecewise_linear_1d(z_thref(1:
size(z_thref)), f_thref(1:
size(f_thref)), zgrid, &
238 current_state%global_grid%configuration%vertical%thref)
239 deallocate(z_thref, f_thref)
242 current_state%global_grid%configuration%vertical%thref(:)=current_state%thref0
245 if (l_init_pl_theta)
then
246 allocate(z_init_pl_theta(options_get_array_size(current_state%options_database,
"z_init_pl_theta")), &
247 f_init_pl_theta(options_get_array_size(current_state%options_database,
"f_init_pl_theta")))
248 call options_get_real_array(current_state%options_database,
"z_init_pl_theta", z_init_pl_theta)
249 call options_get_real_array(current_state%options_database,
"f_init_pl_theta", f_init_pl_theta)
250 call check_top(zztop, z_init_pl_theta(
size(z_init_pl_theta)),
'z_init_pl_theta')
251 call check_input_levels(
size(z_init_pl_theta),
size(f_init_pl_theta),
"f_init_pl_theta")
252 zgrid=current_state%global_grid%configuration%vertical%zn(:)
253 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, &
254 current_state%global_grid%configuration%vertical%theta_init)
255 if (l_matchthref)
then
256 if(.not. current_state%use_anelastic_equations)
then
257 call log_master_log(log_error,
"Non-anelastic equation set and l_maththref are incompatible")
259 current_state%global_grid%configuration%vertical%thref = current_state%global_grid%configuration%vertical%theta_init
261 if (.not. current_state%continuation_run)
then
262 do i=current_state%local_grid%local_domain_start_index(x_index), current_state%local_grid%local_domain_end_index(x_index)
263 do j=current_state%local_grid%local_domain_start_index(y_index), current_state%local_grid%local_domain_end_index(y_index)
264 current_state%th%data(:,j,i) = current_state%global_grid%configuration%vertical%theta_init(:) - &
265 current_state%global_grid%configuration%vertical%thref(:)
269 deallocate(z_init_pl_theta, f_init_pl_theta)
273 allocate(z_init_pl_u(options_get_array_size(current_state%options_database,
"z_init_pl_u")), &
274 f_init_pl_u(options_get_array_size(current_state%options_database,
"f_init_pl_u")))
275 call options_get_real_array(current_state%options_database,
"z_init_pl_u", z_init_pl_u)
276 call options_get_real_array(current_state%options_database,
"f_init_pl_u", f_init_pl_u)
277 call check_top(zztop, z_init_pl_u(
size(z_init_pl_u)),
'z_init_pl_u')
279 zgrid=current_state%global_grid%configuration%vertical%zn(:)
280 call piecewise_linear_1d(z_init_pl_u(1:
size(z_init_pl_u)), f_init_pl_u(1:
size(f_init_pl_u)), &
281 zgrid, current_state%global_grid%configuration%vertical%u_init)
282 if (.not. current_state%continuation_run)
then
283 do i=current_state%local_grid%local_domain_start_index(x_index), current_state%local_grid%local_domain_end_index(x_index)
284 do j=current_state%local_grid%local_domain_start_index(y_index), current_state%local_grid%local_domain_end_index(y_index)
285 current_state%u%data(:,j,i) = current_state%global_grid%configuration%vertical%u_init(:)
289 deallocate(z_init_pl_u, f_init_pl_u)
293 allocate(z_init_pl_v(options_get_array_size(current_state%options_database,
"z_init_pl_v")), &
294 f_init_pl_v(options_get_array_size(current_state%options_database,
"f_init_pl_v")))
295 call options_get_real_array(current_state%options_database,
"z_init_pl_v", z_init_pl_v)
296 call options_get_real_array(current_state%options_database,
"f_init_pl_v", f_init_pl_v)
297 call check_top(zztop, z_init_pl_v(
size(z_init_pl_v)),
'z_init_pl_v')
299 zgrid=current_state%global_grid%configuration%vertical%zn(:)
300 call piecewise_linear_1d(z_init_pl_v(1:
size(z_init_pl_v)), f_init_pl_v(1:
size(f_init_pl_v)), &
301 zgrid, current_state%global_grid%configuration%vertical%v_init)
302 if (.not. current_state%continuation_run)
then
303 do i=current_state%local_grid%local_domain_start_index(x_index), current_state%local_grid%local_domain_end_index(x_index)
304 do j=current_state%local_grid%local_domain_start_index(y_index), current_state%local_grid%local_domain_end_index(y_index)
305 current_state%v%data(:,j,i) = current_state%global_grid%configuration%vertical%v_init(:)
309 deallocate(z_init_pl_v, f_init_pl_v)
313 nq_init=
size(names_init_pl_q)
314 allocate(z_init_pl_q(options_get_array_size(current_state%options_database,
"z_init_pl_q")))
315 call options_get_real_array(current_state%options_database,
"z_init_pl_q", z_init_pl_q)
316 nzq=
size(z_init_pl_q)
317 call check_top(zztop, z_init_pl_q(nzq),
'z_init_pl_q')
318 zgrid=current_state%global_grid%configuration%vertical%zn(:)
319 allocate(f_init_pl_q_tmp(nq_init*nzq))
320 call options_get_real_array(current_state%options_database,
"f_init_pl_q", f_init_pl_q_tmp)
322 allocate(f_init_pl_q(nzq, nq_init))
323 f_init_pl_q(1:nzq, 1:nq_init)=reshape(f_init_pl_q_tmp, (/nzq, nq_init/))
325 iq=get_q_index(trim(names_init_pl_q(n)),
'piecewise_initialization')
327 call piecewise_linear_1d(z_init_pl_q(1:nzq), f_init_pl_q(1:nzq,n), zgrid, &
328 current_state%global_grid%configuration%vertical%q_init(:,iq))
329 if (.not. current_state%continuation_run)
then
330 do i=current_state%local_grid%local_domain_start_index(x_index), &
331 current_state%local_grid%local_domain_end_index(x_index)
332 do j=current_state%local_grid%local_domain_start_index(y_index), &
333 current_state%local_grid%local_domain_end_index(y_index)
334 current_state%q(iq)%data(:,j,i) = current_state%global_grid%configuration%vertical%q_init(:, iq)
339 deallocate(f_init_pl_q_tmp, z_init_pl_q, f_init_pl_q, names_init_pl_q)
349 type(model_state_type),
intent(inout) :: current_state
350 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
351 integer,
intent(in) :: kkp
356 vertical_grid%rneutml(k)=sqrt(1.0_default_precision/(1.0_default_precision/(von_karman_constant*&
357 (vertical_grid%z(k)+z0))**2+1.0_default_precision/current_state%rmlmax**2) )
358 vertical_grid%rneutml_sq(k)=vertical_grid%rneutml(k)*vertical_grid%rneutml(k)
367 type(model_state_type),
intent(inout),
target :: current_state
368 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
369 integer,
intent(in) :: kkp
373 if (.not. current_state%passive_th)
then
374 if(current_state%use_anelastic_equations)
then
376 vertical_grid%buoy_co(k)=cp*(vertical_grid%prefn(k)**r_over_cp-vertical_grid%prefn(k+1)**r_over_cp)/&
377 ((current_state%surface_reference_pressure**r_over_cp)*vertical_grid%dzn(k+1))
380 vertical_grid%buoy_co(1:kkp-1)=g/current_state%thref0
383 vertical_grid%buoy_co(kkp)=0.
385 vertical_grid%buoy_co(:)=0.
394 type(model_state_type),
intent(inout) :: current_state
395 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
396 integer,
intent(in) :: kkp
398 real(kind=default_precision) :: delta_t=1.0_default_precision, qlinit, tinit, qsatin, dqsatdtin, dsatfacin
402 vertical_grid%tref(k)=vertical_grid%thref(k)*(vertical_grid%prefn(k)/current_state%surface_reference_pressure)**r_over_cp
403 vertical_grid%tstarpr(k)=0.0_default_precision
405 if (current_state%th%active)
then
408 vertical_grid%prefrcp(k)=(current_state%surface_reference_pressure/vertical_grid%prefn(k))**r_over_cp
409 vertical_grid%rprefrcp(k)=1.0_default_precision/vertical_grid%prefrcp(k)
411 vertical_grid%qsat(k)=qsaturation(vertical_grid%tref(k), 0.01_default_precision*vertical_grid%prefn(k))
412 vertical_grid%dqsatdt(k)=(qsaturation(vertical_grid%tref(k)+delta_t, 0.01_default_precision*vertical_grid%prefn(k)) -&
413 qsaturation(vertical_grid%tref(k)-delta_t, 0.01_default_precision*vertical_grid%prefn(k)))/&
414 (2.0_default_precision*delta_t)
415 vertical_grid%qsatfac(k)=1.0_default_precision/(1.0_default_precision+rlvap_over_cp*vertical_grid%dqsatdt(k))
417 if (current_state%calculate_th_and_q_init)
then
422 qlinit=
qinit(k, current_state%liquid_water_mixing_ratio_index)
427 tinit = vertical_grid%theta_init(k)*vertical_grid%rprefrcp(k) + rlvap_over_cp*qlinit
428 qsatin = qsaturation(tinit, 0.01_default_precision*vertical_grid%prefn(k))
429 dqsatdtin = dqwsatdt(qsatin, tinit)
430 dsatfacin=( 1.0_default_precision/(1.0_default_precision + rlvap_over_cp*dqsatdtin*vertical_grid%rprefrcp(k)))
431 qlinit=max(0.0_default_precision, (
qinit(k, current_state%water_vapour_mixing_ratio_index)-&
432 (qsatin+dqsatdtin*(vertical_grid%theta_init(k)*vertical_grid%rprefrcp(k)-tinit) ))*dsatfacin)
434 qinit(k, current_state%liquid_water_mixing_ratio_index)=qlinit
435 qinit(k, current_state%water_vapour_mixing_ratio_index)=
qinit(k,current_state%water_vapour_mixing_ratio_index)-qlinit
436 vertical_grid%theta_init(k)=vertical_grid%theta_init(k)+rlvap_over_cp*qlinit
439 vertical_grid%tstarpr(k)= tinit-vertical_grid%tref(k)
440 vertical_grid%qsat(k)=qsatin
441 vertical_grid%dqsatdt(k)=dqsatdtin
442 vertical_grid%qsatfac(k)= ( 1.0_default_precision/ ( 1.0_default_precision + rlvap_over_cp*dqsatdtin ) )
453 type(model_state_type),
intent(inout) :: current_state
454 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
455 integer,
intent(in) :: kkp
462 vertical_grid%prefn(k)=0.0_default_precision
463 vertical_grid%pdiff(k)=0.0_default_precision
464 vertical_grid%rho(k)=current_state%rhobous
465 vertical_grid%rhon(k)=current_state%rhobous
468 vertical_grid%dthref(k)=vertical_grid%thref(k+1)-vertical_grid%thref(k)
470 vertical_grid%dthref(kkp)=0.0_default_precision
482 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
483 integer,
dimension(:),
intent(in) :: kgd
484 real(kind=default_precision),
dimension(:),
intent(in) :: hgd
485 integer,
intent(in) :: ninitp, kkp, nsmth
486 real(kind=default_precision),
intent(in) :: zztop
487 logical,
intent(in) :: origional_setup, continuation_run
491 if (.not. continuation_run)
then
492 if (origional_setup)
then
501 vertical_grid%dz(k)=vertical_grid%z(k)-vertical_grid%z(k-1)
502 vertical_grid%dzn(k)= vertical_grid%zn(k)-vertical_grid%zn(k-1)
503 vertical_grid%rdz(k)=1./vertical_grid%dz(k)
504 vertical_grid%rdzn(k)=1./vertical_grid%dzn(k)
506 vertical_grid%dzn(1)=0.d0
517 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
518 integer,
dimension(:),
intent(in) :: kgd
519 real(kind=default_precision),
dimension(:),
intent(in) :: hgd
520 integer,
intent(in) :: ninitp, kkp, nsmth
521 real(kind=default_precision),
intent(in) :: zztop
527 vertical_grid%z(1)=0.0_default_precision
528 vertical_grid%z(kkp)=zztop
531 vertical_grid%zn(k)=0.5_default_precision*(vertical_grid%z(k)+vertical_grid%z(k-1))
534 vertical_grid%z(k)=0.5_default_precision*(vertical_grid%zn(k)+vertical_grid%zn(k+1))
539 vertical_grid%zn(k)=0.0625_default_precision*(9.0_default_precision*&
540 (vertical_grid%z(k-1)+vertical_grid%z(k))-vertical_grid%z(k+1)-vertical_grid%z(k-2))
542 vertical_grid%zn(2)=0.5_default_precision*(vertical_grid%z(1)+vertical_grid%z(2))
543 vertical_grid%zn(1)=-vertical_grid%zn(2)
544 vertical_grid%zn(kkp)=0.5_default_precision*(vertical_grid%z(kkp-1)+vertical_grid%z(kkp))
553 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
554 integer,
dimension(:),
intent(in) :: kgd
555 integer,
intent(in) :: kkp
556 real(kind=default_precision),
intent(in) :: zztop
558 real(kind=default_precision) :: a(2*kkp), r1, d1, dd, d0, a0
559 logical :: first_gt=.true.
562 r1=1.10_default_precision
563 d1=10.0_default_precision
565 dd=0.5_default_precision*d1
568 a(2)=0.0_default_precision
570 if (d0 .gt. dd .or. k==3)
then
572 if (.not. (dd .gt. 25.0_default_precision .and. a(k) .lt. 2000.0_default_precision))
then
573 if (a(k) .lt. 2000.0_default_precision)
then
576 dd=dd*(1.0_default_precision+(r1-1.0_default_precision)/1.5_default_precision)
579 d0=(zztop-a(k))/real(kkp*2-k, kind=default_precision)
586 a(k)=a0+real(k-k0, kind=default_precision)*d0
591 vertical_grid%z(k)=a(k*2)
592 vertical_grid%zn(k)=a(2*k-1)
607 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
608 integer,
dimension(:),
intent(in) :: kgd
609 real(kind=default_precision),
dimension(:),
intent(in) :: hgd
610 integer,
intent(in) :: ninitp, kkp
611 real(kind=default_precision),
intent(in) :: zztop
613 integer :: kmax, k, i
614 real(kind=default_precision) :: zmax
616 vertical_grid%z(1) = 0.0_default_precision
618 zmax=0.0_default_precision
619 if (kgd(1) .gt. 1)
then
622 vertical_grid%z(k)=real(k-1, kind=default_precision)*hgd(1)/real(kgd(1)-1, kind=default_precision)
625 if(kgd(i) .gt. 0)
then
629 do k=kgd(i-1)+1,kgd(i)
630 vertical_grid%z(k)=hgd(i-1)+(hgd(i)-hgd(i-1))*real(k-kgd(i-1), kind=default_precision)&
631 /real(kgd(i)-kgd(i-1), kind=default_precision)
636 if(kmax .lt. kkp)
then
639 vertical_grid%z(k)=zmax+(zztop-zmax)*real(k-kmax, kind=default_precision)/real(kkp-kmax, kind=default_precision)
649 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
650 integer,
intent(in) :: n
651 integer,
intent(in) :: nq
653 allocate(vertical_grid%dz(n), vertical_grid%dzn(n),&
654 vertical_grid%czb(n), vertical_grid%cza(n), vertical_grid%czg(n), vertical_grid%czh(n),&
655 vertical_grid%rdz(n), vertical_grid%rdzn(n), vertical_grid%tzc1(n), vertical_grid%tzc2(n),&
656 vertical_grid%tzd1(n), vertical_grid%tzd2(n), vertical_grid%theta_init(n), vertical_grid%temp_init(n), &
657 vertical_grid%rh_init(n), &
658 vertical_grid%tref(n), vertical_grid%prefn(n), vertical_grid%pdiff(n), vertical_grid%prefrcp(n), &
659 vertical_grid%rprefrcp(n), vertical_grid%rho(n), vertical_grid%rhon(n), vertical_grid%tstarpr(n), &
660 vertical_grid%qsat(n), vertical_grid%dqsatdt(n), vertical_grid%qsatfac(n), vertical_grid%dthref(n), &
661 vertical_grid%rneutml(n), vertical_grid%rneutml_sq(n), vertical_grid%buoy_co(n), &
662 vertical_grid%u_init(n), vertical_grid%v_init(n), vertical_grid%theta_rand(n), vertical_grid%w_rand(n), &
663 vertical_grid%w_subs(n), vertical_grid%u_force(n), vertical_grid%v_force(n), vertical_grid%theta_force(n))
665 if (.not.
allocated(vertical_grid%thref))
allocate(vertical_grid%thref(n))
666 if (.not.
allocated(vertical_grid%z))
allocate(vertical_grid%z(n))
667 if (.not.
allocated(vertical_grid%zn))
allocate(vertical_grid%zn(n))
669 allocate(vertical_grid%q_rand(n,nq), vertical_grid%q_init(n,nq), vertical_grid%q_force(n,nq))
675 type(model_state_type),
intent(inout) :: current_state
677 current_state%global_grid%configuration%horizontal%dx = merge(real(current_state%global_grid%resolution(x_index)), &
679 current_state%global_grid%configuration%horizontal%dy = merge(real(current_state%global_grid%resolution(y_index)), &
682 current_state%global_grid%configuration%horizontal%cx=1./current_state%global_grid%configuration%horizontal%dx
683 current_state%global_grid%configuration%horizontal%cy=1./current_state%global_grid%configuration%horizontal%dy
684 current_state%global_grid%configuration%horizontal%cx2=current_state%global_grid%configuration%horizontal%cx ** 2
685 current_state%global_grid%configuration%horizontal%cy2=current_state%global_grid%configuration%horizontal%cy ** 2
686 current_state%global_grid%configuration%horizontal%cxy=current_state%global_grid%configuration%horizontal%cx * &
687 current_state%global_grid%configuration%horizontal%cy
688 current_state%global_grid%configuration%horizontal%tcx=&
689 0.25_default_precision/current_state%global_grid%configuration%horizontal%dx
690 current_state%global_grid%configuration%horizontal%tcy=&
691 0.25_default_precision/current_state%global_grid%configuration%horizontal%dy
700 type(model_state_type),
intent(inout) :: current_state
702 if (current_state%use_anelastic_equations)
then
705 if (current_state%passive_th)
then
706 current_state%global_grid%configuration%vertical%prefn=0.0_default_precision
710 current_state%global_grid%configuration%vertical%rho=current_state%rhobous
711 current_state%global_grid%configuration%vertical%rhon=current_state%rhobous
712 current_state%global_grid%configuration%vertical%pdiff=0.0_default_precision
719 type(model_state_type),
intent(inout) :: current_state
722 real(kind=default_precision) :: p0 &
724 , thprof(current_state%local_grid%size(z_index))
728 thprof=0.0_default_precision
729 ptop=0.0_default_precision
730 current_state%global_grid%configuration%vertical%pdiff(current_state%local_grid%size(z_index))=0.0_default_precision
733 current_state%global_grid%configuration%vertical%prefn(current_state%local_grid%size(z_index))=&
734 (ptop/current_state%surface_reference_pressure)**r_over_cp
735 do k=current_state%local_grid%size(z_index)-1,1,-1
736 current_state%global_grid%configuration%vertical%pdiff(k)=g*&
737 current_state%global_grid%configuration%vertical%dzn(k+1)/(0.5_default_precision*cp*&
738 (current_state%global_grid%configuration%vertical%thref(k)+&
739 current_state%global_grid%configuration%vertical%thref(k+1)))
741 do k=current_state%local_grid%size(z_index)-1,1,-1
742 current_state%global_grid%configuration%vertical%prefn(k)=&
743 current_state%global_grid%configuration%vertical%prefn(k+1)+&
744 current_state%global_grid%configuration%vertical%pdiff(k)
746 do k=current_state%local_grid%size(z_index),1,-1
747 current_state%global_grid%configuration%vertical%prefn(k)=current_state%surface_reference_pressure*&
748 current_state%global_grid%configuration%vertical%prefn(k)**(1.0_default_precision/r_over_cp)
750 p0=0.5_default_precision*(current_state%global_grid%configuration%vertical%prefn(1)+&
751 current_state%global_grid%configuration%vertical%prefn(2))
752 if (ipass .eq. 1)
then
753 ptop=current_state%surface_pressure**r_over_cp+ptop**r_over_cp-p0**r_over_cp
754 if (ptop .le. 0.0_default_precision .and. current_state%parallel%my_rank==0)
then
755 call log_log(log_error,
"Negative ptop in setup of anelastic. Need a warmer THREF or different setup options")
757 ptop=ptop**(1.0_default_precision/r_over_cp)
765 type(model_state_type),
intent(inout) :: current_state
768 real(kind=default_precision) :: p0 &
772 ptop=0.0_default_precision
773 current_state%global_grid%configuration%vertical%pdiff(current_state%local_grid%size(z_index))=0.0_default_precision
776 current_state%global_grid%configuration%vertical%prefn(current_state%local_grid%size(z_index))=&
777 (ptop/current_state%surface_reference_pressure)**r_over_cp
778 do k=current_state%local_grid%size(z_index)-1,1,-1
779 current_state%global_grid%configuration%vertical%pdiff(k)=g*&
780 current_state%global_grid%configuration%vertical%dzn(k+1)/(0.5_default_precision*cp*&
781 (current_state%global_grid%configuration%vertical%thref(k)+&
782 current_state%global_grid%configuration%vertical%thref(k+1)))
784 do k=current_state%local_grid%size(z_index)-1,1,-1
785 current_state%global_grid%configuration%vertical%prefn(k)=&
786 current_state%global_grid%configuration%vertical%prefn(k+1)+&
787 current_state%global_grid%configuration%vertical%pdiff(k)
789 do k=current_state%local_grid%size(z_index),1,-1
790 current_state%global_grid%configuration%vertical%prefn(k)=current_state%surface_reference_pressure*&
791 current_state%global_grid%configuration%vertical%prefn(k)**(1.0_default_precision/r_over_cp)
794 p0=0.5_default_precision*(current_state%global_grid%configuration%vertical%prefn(1)+&
795 current_state%global_grid%configuration%vertical%prefn(2))
808 thfactor=((p0/current_state%surface_reference_pressure)**r_over_cp-(ptop/current_state%surface_reference_pressure)**&
809 r_over_cp)/((current_state%surface_pressure/current_state%surface_reference_pressure)**r_over_cp-&
810 (ptop/current_state%surface_reference_pressure)**r_over_cp)
811 do k=1,current_state%local_grid%size(z_index)
812 current_state%global_grid%configuration%vertical%thref(k)=&
813 current_state%global_grid%configuration%vertical%thref(k)*thfactor
818 ptop=current_state%surface_pressure**r_over_cp+ptop**r_over_cp-p0**r_over_cp
819 if (ptop .le. 0.0_default_precision .and. current_state%parallel%my_rank==0)
then
820 call log_log(log_error,
"Negative ptop in setup of anelastic. Need a warmer THREF or different setup options")
822 ptop=ptop**(1.0_default_precision/r_over_cp)
828 do k=1,current_state%local_grid%size(z_index)
829 current_state%global_grid%configuration%vertical%rhon(k)=current_state%global_grid%configuration%vertical%prefn(k)&
830 /(r*current_state%global_grid%configuration%vertical%thref(k)*&
831 (current_state%global_grid%configuration%vertical%prefn(k)/current_state%surface_reference_pressure)**r_over_cp)
833 do k=1,current_state%local_grid%size(z_index)-1
834 current_state%global_grid%configuration%vertical%rho(k)=sqrt(current_state%global_grid%configuration%vertical%rhon(k)*&
835 current_state%global_grid%configuration%vertical%rhon(k+1))
837 current_state%global_grid%configuration%vertical%rho(current_state%local_grid%size(z_index))=&
838 current_state%global_grid%configuration%vertical%rhon(current_state%local_grid%size(z_index))**2/&
839 current_state%global_grid%configuration%vertical%rhon(current_state%local_grid%size(z_index)-1)
844 real(kind=default_precision),
intent(in) :: zztop
845 real(kind=default_precision),
intent(in) :: z
846 character(*),
intent(in) :: info
849 call log_master_log(log_error,
"Top of input profile is below the top of the domain:"//trim(info))
855 integer,
intent(in) :: z_levels
856 integer,
intent(in) :: field_levels
857 character(*),
intent(in) :: field
859 if (z_levels /= field_levels)
then
860 call log_master_log(log_error,
"Input levels not equal for "//trim(field)//
", z_levels = "// &
861 trim(conv_to_string(z_levels))//
" field_levels = "//conv_to_string(field_levels))
868 type(model_state_type),
intent(inout) :: current_state
870 logical :: l_init_pl_rh
871 real(kind=default_precision) :: zztop
872 real(kind=default_precision) :: qsat
873 real(kind=default_precision),
dimension(:),
allocatable :: f_init_pl_rh
874 real(kind=default_precision),
dimension(:),
allocatable :: z_init_pl_rh
875 real(kind=default_precision),
allocatable :: zgrid(:)
876 real(kind=default_precision),
allocatable :: tdegk(:)
880 type(vertical_grid_configuration_type) :: vertical_grid
882 vertical_grid=current_state%global_grid%configuration%vertical
884 allocate(zgrid(current_state%local_grid%local_domain_end_index(z_index)))
886 zztop = current_state%global_grid%top(z_index)
888 l_init_pl_rh=options_get_logical(current_state%options_database,
"l_init_pl_rh")
890 if (l_init_pl_rh)
then
891 allocate(z_init_pl_rh(options_get_array_size(current_state%options_database,
"z_init_pl_rh")), &
892 f_init_pl_rh(options_get_array_size(current_state%options_database,
"f_init_pl_rh")))
893 call options_get_real_array(current_state%options_database,
"z_init_pl_rh", z_init_pl_rh)
894 call options_get_real_array(current_state%options_database,
"f_init_pl_rh", f_init_pl_rh)
895 call check_top(zztop, z_init_pl_rh(
size(z_init_pl_rh)),
'z_init_pl_rh')
897 zgrid=current_state%global_grid%configuration%vertical%zn(:)
898 call piecewise_linear_1d(z_init_pl_rh(1:
size(z_init_pl_rh)), f_init_pl_rh(1:
size(f_init_pl_rh)), zgrid, &
899 current_state%global_grid%configuration%vertical%rh_init)
901 if (.not. current_state%passive_q .and. current_state%th%active)
then
902 iq=get_q_index(
'vapour',
'piecewise_initialization')
903 allocate(tdegk(current_state%local_grid%local_domain_end_index(z_index)))
904 tdegk(:) = current_state%global_grid%configuration%vertical%theta_init(:)* &
905 (vertical_grid%prefn(:)/current_state%surface_reference_pressure)**r_over_cp
906 do k = current_state%local_grid%local_domain_start_index(z_index), &
907 current_state%local_grid%local_domain_end_index(z_index)
908 qsat=qsaturation(tdegk(k), current_state%global_grid%configuration%vertical%prefn(k)/100.)
909 current_state%global_grid%configuration%vertical%q_init(k, iq) = &
910 (current_state%global_grid%configuration%vertical%rh_init(k)/100.0)*qsat
915 if (.not. current_state%continuation_run)
then
916 do i=current_state%local_grid%local_domain_start_index(x_index), &
917 current_state%local_grid%local_domain_end_index(x_index)
918 do j=current_state%local_grid%local_domain_start_index(y_index), &
919 current_state%local_grid%local_domain_end_index(y_index)
920 current_state%q(iq)%data(:,j,i) = current_state%global_grid%configuration%vertical%q_init(:, iq)
927 call log_master_log(log_error,
"Initialising with RH but q and/or theta passive")
930 deallocate(z_init_pl_rh, f_init_pl_rh)