15 use mpi,
only: mpi_request_null, mpi_statuses_ignore
25 tolm=1.0e-4_default_precision,
tolt=1.0e-4_default_precision
50 type(model_state_type),
target,
intent(inout) :: current_state
52 real(kind=default_precision) :: bhbc
53 integer :: num_wrapped_fields
57 if (.not. is_component_enabled(current_state%options_database,
"diffusion"))
then
58 call log_master_log(log_error,
"Lowerbc requires the diffusion component to be enabled")
60 if (.not. is_component_enabled(current_state%options_database,
"viscosity"))
then
61 call log_master_log(log_error,
"Lowerbc requires the viscosity component to be enabled")
69 if (current_state%th%active) num_wrapped_fields=1
70 num_wrapped_fields=num_wrapped_fields+current_state%number_q_fields
72 if (num_wrapped_fields .gt. 0)
then
73 if (current_state%parallel%my_coords(y_index) == 0 .or. &
74 current_state%parallel%my_coords(y_index) == current_state%parallel%dim_sizes(y_index)-1)
then
75 if (current_state%parallel%my_coords(y_index) == 0)
then
86 if (current_state%parallel%my_coords(x_index) == 0 .or. &
87 current_state%parallel%my_coords(x_index) == current_state%parallel%dim_sizes(x_index)-1)
then
88 if (current_state%parallel%my_coords(x_index) == 0)
then
101 1.0_default_precision/(current_state%global_grid%configuration%horizontal%dx*&
102 current_state%global_grid%configuration%horizontal%dx)+&
103 1.0_default_precision/(current_state%global_grid%configuration%horizontal%dy*&
104 current_state%global_grid%configuration%horizontal%dy)
106 if ( current_state%use_surface_boundary_conditions .and. &
107 current_state%type_of_surface_boundary_conditions == prescribed_surface_values)
then
109 tstrcona=von_karman_constant/alphah*current_state%global_grid%configuration%vertical%zlogth
110 bhbc=alphah*current_state%global_grid%configuration%vertical%zlogth
111 rhmbc=betah*(current_state%global_grid%configuration%vertical%zn(2)+z0-z0th)/&
112 (betam*current_state%global_grid%configuration%vertical%zn(2))
113 ddbc=current_state%global_grid%configuration%vertical%zlogm*(bhbc-&
114 rhmbc*current_state%global_grid%configuration%vertical%zlogm)
117 eecon=2.0_default_precision*
rhmbc*current_state%global_grid%configuration%vertical%zlogm-bhbc
118 rcmbc=1.0_default_precision/current_state%cmbc
120 x4con=gammam*(current_state%global_grid%configuration%vertical%zn(2)+z0)
122 y2con=gammah*(current_state%global_grid%configuration%vertical%zn(2)+z0)
141 if (.not. current_state%passive_q)
then
142 iqv = get_q_index(standard_q_names%VAPOUR,
'lowerbc')
148 type(model_state_type),
target,
intent(inout) :: current_state
157 type(model_state_type),
target,
intent(inout) :: current_state
159 integer :: z_size, y_size, x_size, i
161 z_size=current_state%local_grid%size(z_index) + current_state%local_grid%halo_size(z_index) * 2
162 y_size=current_state%local_grid%size(y_index) + current_state%local_grid%halo_size(y_index) * 2
163 x_size=current_state%local_grid%size(x_index) + current_state%local_grid%halo_size(x_index) * 2
165 allocate(current_state%dis%data(z_size, y_size, x_size), &
166 current_state%dis_th%data(z_size, y_size, x_size), current_state%disq(current_state%number_q_fields))
168 do i=1,current_state%number_q_fields
169 allocate(current_state%disq(i)%data(z_size, y_size, x_size))
174 type(model_state_type),
target,
intent(inout) :: current_state
176 integer :: current_y_index, current_x_index
178 current_y_index=current_state%column_local_y
179 current_x_index=current_state%column_local_x
181 if (current_state%field_stepping == forward_stepping)
then
183 current_state%u, current_state%v, current_state%th, current_state%th, current_state%q, current_state%q)
185 if (current_state%scalar_stepping == forward_stepping)
then
187 current_state%zu, current_state%zv, current_state%th, current_state%zth, current_state%q, current_state%zq)
190 current_state%zu, current_state%zv, current_state%zth, current_state%zth, current_state%zq, current_state%zq)
196 type(model_state_type),
target,
intent(inout) :: current_state
197 type(prognostic_field_type),
intent(inout) :: zu, zv, th, zth
198 type(prognostic_field_type),
dimension(:),
intent(inout) :: q, zq
199 integer,
intent(in) :: current_y_index, current_x_index
202 real(kind=default_precision) :: horizontal_velocity_at_k2
204 if (.not. current_state%use_viscosity_and_diffusion .or. .not. current_state%use_surface_boundary_conditions)
then
208 if (.not. (current_state%column_local_y .lt. current_state%local_grid%local_domain_start_index(y_index)-1 .or.&
209 current_state%column_local_x .lt. current_state%local_grid%local_domain_start_index(x_index)-1 .or.&
210 current_state%column_local_y .gt. current_state%local_grid%local_domain_end_index(y_index)+1 .or.&
211 current_state%column_local_x .gt. current_state%local_grid%local_domain_end_index(x_index)+1))
then
216 horizontal_velocity_at_k2=0.0_default_precision
218 horizontal_velocity_at_k2=(0.5_default_precision*(current_state%zu%data(2,current_y_index,current_x_index)+&
219 zu%data(2,current_y_index,current_x_index-1))+ current_state%ugal)**2
222 horizontal_velocity_at_k2=horizontal_velocity_at_k2+(0.5_default_precision*(zv%data(&
223 2,current_y_index,current_x_index)+zv%data(2,current_y_index-1,current_x_index))+current_state%vgal)**2
225 horizontal_velocity_at_k2=sqrt(horizontal_velocity_at_k2)+smallp
227 if (current_state%type_of_surface_boundary_conditions == prescribed_surface_fluxes)
then
229 horizontal_velocity_at_k2, th, q)
232 horizontal_velocity_at_k2, zth, th, zq, q)
235 current_state%dis%data(1, current_y_index, current_x_index)=0.0_default_precision
236 current_state%dis_th%data(1, current_y_index, current_x_index)=0.0_default_precision
238 if (current_state%backscatter)
then
239 do n=1, current_state%number_q_fields
240 current_state%disq(n)%data(1,current_y_index,current_x_index)=0.0_default_precision
248 current_state%cvis=max(current_state%cvis,max(current_state%vis_coefficient%data(1, current_y_index, current_x_index),&
251 else if (current_x_index == 1 .and. current_y_index == 1)
then
253 else if (current_x_index == current_state%local_grid%local_domain_end_index(x_index)+&
254 current_state%local_grid%halo_size(x_index) .and. current_y_index == &
255 current_state%local_grid%local_domain_end_index(y_index)+current_state%local_grid%halo_size(y_index))
then
264 type(model_state_type),
target,
intent(inout) :: current_state
283 type(model_state_type),
target,
intent(inout) :: current_state
284 type(prognostic_field_type),
intent(inout) :: zth
285 type(prognostic_field_type),
dimension(:),
intent(inout) :: zq
291 if (current_state%parallel%my_coords(y_index) == 0)
then
293 current_state%local_grid%local_domain_start_index(y_index)+1)
296 current_state%local_grid%local_domain_end_index(y_index))
303 if (current_state%parallel%my_coords(x_index) == 0)
then
305 current_state%local_grid%local_domain_start_index(x_index)+1)
308 current_state%local_grid%local_domain_end_index(x_index))
319 if (current_state%parallel%my_coords(y_index) == 0)
then
323 current_state%local_grid%local_domain_end_index(y_index)+1, &
324 current_state%local_grid%local_domain_end_index(y_index)+2)
328 if (current_state%parallel%my_coords(x_index) == 0)
then
332 current_state%local_grid%local_domain_end_index(x_index)+1, &
333 current_state%local_grid%local_domain_end_index(x_index)+2)
338 if (current_state%th%active)
then
339 zth%data(1,1,:)=zth%data(1, current_state%local_grid%local_domain_end_index(y_index)-1, :)
340 zth%data(1,2,:)=zth%data(1, current_state%local_grid%local_domain_end_index(y_index), :)
341 zth%data(1,current_state%local_grid%local_domain_end_index(y_index)+1,:)=&
342 zth%data(1, current_state%local_grid%local_domain_start_index(y_index), :)
343 zth%data(1,current_state%local_grid%local_domain_end_index(y_index)+2,:)=&
344 zth%data(1, current_state%local_grid%local_domain_start_index(y_index)+1, :)
346 if (current_state%number_q_fields .gt. 0)
then
347 do n=1, current_state%number_q_fields
348 zq(n)%data(1,1,:)=zq(n)%data(1, current_state%local_grid%local_domain_end_index(y_index)-1, :)
349 zq(n)%data(1,2,:)=zq(n)%data(1, current_state%local_grid%local_domain_end_index(y_index), :)
350 zq(n)%data(1,current_state%local_grid%local_domain_end_index(y_index)+1,:)=&
351 zq(n)%data(1, current_state%local_grid%local_domain_start_index(y_index), :)
352 zq(n)%data(1,current_state%local_grid%local_domain_end_index(y_index)+2,:)=&
353 zq(n)%data(1, current_state%local_grid%local_domain_start_index(y_index)+1, :)
359 if (current_state%th%active)
then
360 zth%data(1,:,1)=zth%data(1,:,current_state%local_grid%local_domain_end_index(x_index)-1)
361 zth%data(1,:,2)=zth%data(1,:,current_state%local_grid%local_domain_end_index(x_index))
362 zth%data(1,:,current_state%local_grid%local_domain_end_index(x_index)+1)=&
363 zth%data(1,:,current_state%local_grid%local_domain_start_index(x_index))
364 zth%data(1,:,current_state%local_grid%local_domain_end_index(x_index)+2)=&
365 zth%data(1,:,current_state%local_grid%local_domain_start_index(x_index)+1)
367 if (current_state%number_q_fields .gt. 0)
then
368 do n=1, current_state%number_q_fields
369 zq(n)%data(1,:,1)=zq(n)%data(1,:,current_state%local_grid%local_domain_end_index(x_index)-1)
370 zq(n)%data(1,:,2)=zq(n)%data(1,:,current_state%local_grid%local_domain_end_index(x_index))
371 zq(n)%data(1,:,current_state%local_grid%local_domain_end_index(x_index)+1)=&
372 zq(n)%data(1,:,current_state%local_grid%local_domain_start_index(x_index))
373 zq(n)%data(1,:,current_state%local_grid%local_domain_end_index(x_index)+2)=&
374 zq(n)%data(1,:,current_state%local_grid%local_domain_start_index(x_index)+1)
387 type(model_state_type),
target,
intent(inout) :: current_state
388 type(prognostic_field_type),
intent(inout) :: zth
389 type(prognostic_field_type),
dimension(:),
intent(inout) :: zq
390 integer,
intent(in) :: first_y_index, second_y_index
392 integer :: index_start, n
395 if (current_state%th%active)
then
398 index_start=index_start+1
400 if (current_state%number_q_fields .gt. 0)
then
401 do n=1, current_state%number_q_fields
415 type(model_state_type),
target,
intent(inout) :: current_state
416 type(prognostic_field_type),
intent(inout) :: zth
417 type(prognostic_field_type),
dimension(:),
intent(inout) :: zq
418 integer,
intent(in) :: first_x_index, second_x_index
420 integer :: index_start, n
423 if (current_state%th%active)
then
426 index_start=index_start+1
428 if (current_state%number_q_fields .gt. 0)
then
429 do n=1, current_state%number_q_fields
443 type(model_state_type),
target,
intent(inout) :: current_state
444 type(prognostic_field_type),
intent(inout) :: zth
445 type(prognostic_field_type),
dimension(:),
intent(inout) :: zq
446 integer,
intent(in) :: first_y_index, second_y_index
448 integer :: index_start, n
451 if (current_state%th%active)
then
454 index_start=index_start+1
456 if (current_state%number_q_fields .gt. 0)
then
457 do n=1, current_state%number_q_fields
471 type(model_state_type),
target,
intent(inout) :: current_state
472 type(prognostic_field_type),
intent(inout) :: zth
473 type(prognostic_field_type),
dimension(:),
intent(inout) :: zq
474 integer,
intent(in) :: first_x_index, second_x_index
476 integer :: index_start, n
479 if (current_state%th%active)
then
482 index_start=index_start+1
484 if (current_state%number_q_fields .gt. 0)
then
485 do n=1, current_state%number_q_fields
493 type(model_state_type),
target,
intent(inout) :: current_state
494 type(prognostic_field_type),
intent(inout) :: th
495 type(prognostic_field_type),
dimension(:),
intent(inout) :: q
496 integer,
intent(in) :: current_y_index, current_x_index
497 real(kind=default_precision),
intent(in) :: horizontal_velocity_at_k2
500 real(kind=default_precision) :: ustr
502 ustr=
look(current_state, horizontal_velocity_at_k2)
504 current_state%vis_coefficient%data(1, current_y_index, current_x_index)=&
505 current_state%global_grid%configuration%vertical%czn*ustr**2/ horizontal_velocity_at_k2
506 current_state%diff_coefficient%data(1, current_y_index, current_x_index)=&
507 (von_karman_constant*current_state%global_grid%configuration%vertical%czn*ustr/alphah)/&
508 (current_state%global_grid%configuration%vertical%zlogth- 2.*log(&
509 (1.+sqrt(1.+gammah*von_karman_constant*current_state%fbuoy*(current_state%global_grid%configuration%vertical%zn(2)+z0)&
510 /ustr**3))/ (1.+sqrt(1.+gammah*von_karman_constant*current_state%fbuoy*z0th/ustr**3))))
511 if (current_state%th%active) th%data(1, current_y_index, current_x_index)= &
512 (current_state%surface_temperature_flux*current_state%global_grid%configuration%vertical%dzn(2)/&
513 current_state%diff_coefficient%data(1, current_y_index, current_x_index))+th%data(2, current_y_index, current_x_index)-&
514 current_state%global_grid%configuration%vertical%thref(1)+&
515 current_state%global_grid%configuration%vertical%thref(2)
518 if (current_state%number_q_fields .gt. 0)
then
520 q(n)%data(1, current_y_index, current_x_index)=q(n)%data(2, current_y_index, current_x_index)+&
521 current_state%surface_vapour_flux*current_state%global_grid%configuration%vertical%dzn(2)/&
522 current_state%diff_coefficient%data(1, current_y_index, current_x_index)
526 real(kind=default_precision)
function look(current_state, vel)
527 type(model_state_type),
target,
intent(inout) :: current_state
528 real(kind=default_precision),
intent(in) :: vel
530 real(kind=default_precision) :: lookup_real_posn
531 integer :: lookup_int_posn
533 lookup_real_posn=1.0_default_precision+real(current_state%lookup_table_entries-1)*&
534 log(vel/current_state%velmin)*current_state%aloginv
535 lookup_int_posn=int(lookup_real_posn)
537 if (lookup_int_posn .ge. 1)
then
538 if (lookup_int_posn .lt. current_state%lookup_table_entries)
then
539 look=current_state%lookup_table_ustr(lookup_int_posn)+ (lookup_real_posn-real(lookup_int_posn))*&
540 (current_state%lookup_table_ustr(lookup_int_posn+1)-current_state%lookup_table_ustr(lookup_int_posn))
542 look=vel*current_state%cneut
545 look=vel**(-convective_limit)*current_state%cfc
552 type(model_state_type),
target,
intent(inout) :: current_state
553 type(prognostic_field_type),
intent(inout) :: th
554 type(prognostic_field_type),
dimension(:),
intent(inout) :: q
555 integer,
intent(in) :: current_y_index, current_x_index
556 real(kind=default_precision) :: horizontal_velocity_at_k2
559 real(kind=default_precision) :: ustr
561 ustr=horizontal_velocity_at_k2*current_state%global_grid%configuration%vertical%vk_on_zlogm
562 current_state%vis_coefficient%data(1, current_y_index, current_x_index)=current_state%global_grid%configuration%vertical%czn*&
563 ustr**2/horizontal_velocity_at_k2
564 current_state%diff_coefficient%data(1, current_y_index, current_x_index)=&
565 current_state%vis_coefficient%data(1, current_y_index, current_x_index)*&
566 current_state%global_grid%configuration%vertical%zlogm/(alphah*current_state%global_grid%configuration%vertical%zlogth)
567 if (current_state%th%active) th%data(1, current_y_index, current_x_index)= &
568 (current_state%surface_temperature_flux*current_state%global_grid%configuration%vertical%dzn(2)/&
569 current_state%diff_coefficient%data(1, current_y_index, current_x_index))+th%data(2, current_y_index, current_x_index)-&
570 current_state%global_grid%configuration%vertical%thref(1)+&
571 current_state%global_grid%configuration%vertical%thref(2)
574 if (current_state%number_q_fields .gt. 0)
then
576 q(n)%data(1, current_y_index, current_x_index)=q(n)%data(2, current_y_index, current_x_index)+&
577 current_state%surface_vapour_flux*current_state%global_grid%configuration%vertical%dzn(2)/&
578 current_state%diff_coefficient%data(1, current_y_index, current_x_index)
582 subroutine handle_stable_fluxes(current_state, current_y_index, current_x_index, horizontal_velocity_at_k2, th, q)
583 type(model_state_type),
target,
intent(inout) :: current_state
584 type(prognostic_field_type),
intent(inout) :: th
585 type(prognostic_field_type),
dimension(:),
intent(inout) :: q
586 integer,
intent(in) :: current_y_index, current_x_index
587 real(kind=default_precision) :: horizontal_velocity_at_k2
589 real(kind=default_precision) :: ustr
592 ustr=horizontal_velocity_at_k2*current_state%global_grid%configuration%vertical%vk_on_zlogm
593 if((current_state%fbuoy - 1.e-9_default_precision) .lt. -4.0_default_precision*&
594 von_karman_constant**2*horizontal_velocity_at_k2**3/ (27.0_default_precision*betam*&
595 current_state%global_grid%configuration%vertical%zn(2)*current_state%global_grid%configuration%vertical%zlogm**2))
then
597 current_state%vis_coefficient%data(1, current_y_index, current_x_index)=0.0_default_precision
598 current_state%diff_coefficient%data(1, current_y_index, current_x_index)=0.0_default_precision
600 if (current_state%th%active) th%data(1, current_y_index, current_x_index)=th%data(2, current_y_index, current_x_index)
601 if (current_state%number_q_fields .gt. 0)
then
602 do n=1, current_state%number_q_fields
603 q(n)%data(1, current_y_index, current_x_index)=q(n)%data(2, current_y_index, current_x_index)
607 ustr=ustr/3.0_default_precision*(1.0_default_precision-2.0_default_precision*&
608 cos((acos(-27.0_default_precision*betam*von_karman_constant*current_state%global_grid%configuration%vertical%zn(2)*&
609 current_state%fbuoy/(current_state%global_grid%configuration%vertical%zlogm*&
610 2.0_default_precision*ustr**3)-1.0_default_precision)+ 2.0_default_precision*pi)/3.0_default_precision))
611 current_state%vis_coefficient%data(1, current_y_index, current_x_index)=&
612 current_state%global_grid%configuration%vertical%czn*ustr**2/horizontal_velocity_at_k2
613 current_state%diff_coefficient%data(1, current_y_index, current_x_index)=&
614 current_state%vis_coefficient%data(1, current_y_index, current_x_index)*&
615 (current_state%global_grid%configuration%vertical%zlogm-betam*current_state%global_grid%configuration%vertical%zn(2)*&
616 von_karman_constant*current_state%fbuoy/ustr**3)/(alphah*current_state%global_grid%configuration%vertical%zlogth-betah*&
617 von_karman_constant*current_state%fbuoy* (current_state%global_grid%configuration%vertical%zn(2)+ z0-z0th)/ustr**3)
618 if (current_state%th%active) th%data(1, current_y_index, current_x_index)= &
619 (current_state%surface_temperature_flux*current_state%global_grid%configuration%vertical%dzn(2)/&
620 current_state%diff_coefficient%data(1, current_y_index, current_x_index))+th%data(2, current_y_index, current_x_index)-&
621 current_state%global_grid%configuration%vertical%thref(1)+&
622 current_state%global_grid%configuration%vertical%thref(2)
626 if (current_state%number_q_fields .gt. 0)
then
628 q(n)%data(1, current_y_index, current_x_index)=q(n)%data(2, current_y_index, current_x_index)+&
629 current_state%surface_vapour_flux*current_state%global_grid%configuration%vertical%dzn(2)/&
630 current_state%diff_coefficient%data(1, current_y_index, current_x_index)
637 type(model_state_type),
target,
intent(inout) :: current_state
638 type(prognostic_field_type),
intent(inout) :: th
639 type(prognostic_field_type),
dimension(:),
intent(inout) :: q
640 integer,
intent(in) :: current_y_index, current_x_index
641 real(kind=default_precision) :: horizontal_velocity_at_k2
643 if (current_state%fbuoy .gt. 0.0_default_precision)
then
645 else if (current_state%fbuoy .eq. 0.0_default_precision)
then
646 call handle_neutral_fluxes(current_state, current_y_index, current_x_index, horizontal_velocity_at_k2, th, q)
648 call handle_stable_fluxes(current_state, current_y_index, current_x_index, horizontal_velocity_at_k2, th, q)
655 type(model_state_type),
target,
intent(inout) :: current_state
656 type(prognostic_field_type),
intent(inout) :: th, zth
657 type(prognostic_field_type),
dimension(:),
intent(inout) :: q, zq
658 real(kind=default_precision),
intent(in) :: horizontal_velocity_at_k2
659 integer,
intent(in) :: current_y_index, current_x_index
661 real(kind=default_precision) :: dthv_surf, ustr, thvstr
662 integer :: convergence_status, n
664 if (current_state%passive_q)
then
666 dthv_surf = zth%data(2, current_y_index, current_x_index) + &
667 current_state%global_grid%configuration%vertical%thref(2) - current_state%theta_virtual_surf
669 dthv_surf=zth%data(2, current_y_index, current_x_index) + current_state%global_grid%configuration%vertical%thref(2)&
670 *(1.0_default_precision + current_state%cq(current_state%water_vapour_mixing_ratio_index)*&
671 zq(current_state%water_vapour_mixing_ratio_index)%data(2,current_y_index,current_x_index)) - &
672 current_state%theta_virtual_surf
674 convergence_status =
mostbc(current_state, horizontal_velocity_at_k2, dthv_surf,&
675 current_state%global_grid%configuration%vertical%zn(2), ustr, thvstr)
677 current_state%vis_coefficient%data(1, current_y_index, current_x_index)=&
678 current_state%global_grid%configuration%vertical%czn*ustr**2/horizontal_velocity_at_k2
679 current_state%diff_coefficient%data(1, current_y_index, current_x_index)=&
680 current_state%global_grid%configuration%vertical%czn*ustr*thvstr/(dthv_surf+smallp)
681 zth%data(1, current_y_index, current_x_index)=2.0*current_state%theta_surf-zth%data(2, current_y_index, current_x_index)-&
682 (current_state%global_grid%configuration%vertical%thref(2)+current_state%global_grid%configuration%vertical%thref(1))
683 th%data(1, current_y_index, current_x_index)=2.0*current_state%theta_surf-th%data(2, current_y_index, current_x_index)-&
684 (current_state%global_grid%configuration%vertical%thref(2)+current_state%global_grid%configuration%vertical%thref(1))
686 if (current_state%number_q_fields .gt. 0)
then
688 zq(n)%data(1, current_y_index, current_x_index)=zq(n)%data(2, current_y_index, current_x_index)
689 q(n)%data(1, current_y_index, current_x_index)=q(n)%data(2, current_y_index, current_x_index)
690 if (.not. current_state%passive_q)
then
691 zq(current_state%water_vapour_mixing_ratio_index)%data(1,current_y_index,current_x_index)=&
692 2.0_default_precision*current_state%surface_vapour_mixing_ratio-&
693 zq(current_state%water_vapour_mixing_ratio_index)%data(2,current_y_index,current_x_index)
694 q(current_state%water_vapour_mixing_ratio_index)%data(1,current_y_index,current_x_index)=&
695 2.0_default_precision*current_state%surface_vapour_mixing_ratio-&
696 q(current_state%water_vapour_mixing_ratio_index)%data(2,current_y_index,current_x_index)
702 type(model_state_type),
target,
intent(inout) :: current_state
703 type(prognostic_field_type),
intent(inout) :: th
704 type(prognostic_field_type),
dimension(:),
intent(inout) :: q
705 integer,
intent(in) :: current_y_index, current_x_index
709 current_state%vis_coefficient%data(1, current_y_index, current_x_index)=0.0_default_precision
710 current_state%diff_coefficient%data(1, current_y_index, current_x_index)=0.0_default_precision
711 if(current_state%backscatter) current_state%dis%data(1, current_y_index, current_x_index)=0.0_default_precision
712 if(current_state%backscatter .and. current_state%th%active) &
713 current_state%dis_th%data(1, current_y_index, current_x_index)=0.0_default_precision
714 if (current_state%th%active)
then
715 th%data(1, current_y_index, current_x_index) = th%data(2, current_y_index, current_x_index)
717 if (current_state%number_q_fields .gt. 0)
then
718 do n=1, current_state%number_q_fields
719 q(n)%data(1, current_y_index, current_x_index) = q(n)%data(2, current_y_index, current_x_index)
720 if (current_state%backscatter) current_state%disq(n)%data(1, current_y_index, current_x_index) = 0.0_default_precision
740 integer function mostbc(current_state, delu, delt, z1, ustrdg, tstrdg)
741 type(model_state_type),
target,
intent(inout) :: current_state
742 real(kind=default_precision),
intent(in) :: delu, delt, z1
743 real(kind=default_precision),
intent(out) :: ustrdg, tstrdg
745 if (delt .lt. 0.0_default_precision)
then
746 if (delu .le. smallp)
then
747 ustrdg=0.0_default_precision
752 ustrdg, tstrdg, current_state%global_grid%configuration%vertical)
754 else if (delt .gt. 0.0_default_precision)
then
757 current_state%cmbc, ustrdg, tstrdg)
760 ustrdg=current_state%global_grid%configuration%vertical%vk_on_zlogm*delu
761 tstrdg=0.0_default_precision
769 call log_log(log_error,
"Convergence failure after 200 iterations")
775 real(kind=default_precision),
intent(in) :: delu, delt, ellmocon
776 real(kind=default_precision),
intent(out) :: ustrdg, tstrdg
777 type(vertical_grid_configuration_type),
intent(inout) :: vertical_grid
780 real(kind=default_precision) :: ellmo, psim, psih, x4, xx, xx0, y2, yy, yy0, err_ustr, err_tstr, &
785 ustrl=vertical_grid%vk_on_zlogm*delu
790 ellmo=ustrl*ustrl*ellmocon/tstrl
793 x4=1.0_default_precision-
x4con/ellmo
794 if (x4 .lt. 0.0_default_precision)
call log_log(log_error,
"Negative square root in x4")
797 xx0=sqrt(sqrt(1.0_default_precision-
xx0con / ellmo))
798 psim=2.*( log((xx+1.0_default_precision)/(xx0+1.0_default_precision))-atan(xx)+atan(xx0) )+&
799 log((xx*xx+1.0_default_precision)/(xx0*xx0+1.0_default_precision))
800 ustrpl=von_karman_constant*delu/(vertical_grid%zlogm-psim)
804 if (y2 .lt. 0.0_default_precision)
call log_log(log_error,
"Negative square root in y2")
806 yy0=sqrt(1.0_default_precision-
yy0con/ellmo)
807 psih=2.*log((1.0_default_precision+yy)/(1.0_default_precision+yy0))
808 tstrpl=
tstrconb*delt/(vertical_grid%zlogth-psih)
809 err_ustr=abs((ustrpl-ustrl)/ ustrl)
810 err_tstr=abs((tstrpl-tstrl)/ tstrl)
811 if ((err_tstr .lt.
tolt) .and. (err_ustr .lt.
tolm))
then
817 ustrl=(1.0_default_precision-
smth)*ustrpl+
smth*ustrl
818 tstrl=(1.0_default_precision-
smth)*tstrpl+
smth*tstrl
825 real(kind=default_precision),
intent(in) :: delu, delt, zlogm, cmbc
826 real(kind=default_precision),
intent(out) :: ustrdg, tstrdg
828 real(kind=default_precision) :: am, ah, ee, ff, det
830 am=von_karman_constant*delu
831 ah=von_karman_constant*delt
833 ff=ah*cmbc-
rhmbc*am*am
837 if (ff .gt. 0.0_default_precision)
then
838 if ((ee .lt. 0.0_default_precision).and.(det .gt. 0.0_default_precision))
then
839 ustrdg=(-ee+sqrt(det))*
r2ddbc
840 tstrdg=ustrdg*(am-zlogm*ustrdg)*
rcmbc
843 ustrdg=0.0_default_precision
844 tstrdg=0.0_default_precision
846 else if (
ddbc .eq. 0.0_default_precision)
then
849 tstrdg=delt*ustrdg/delu
852 ustrdg=(-ee+sqrt(det))*
r2ddbc
853 tstrdg=ustrdg*(am-zlogm*ustrdg)*
rcmbc